but how is roll supposed to affect the forward vector if the roll axis is the forward vector?
you want the camera to move in the direction of its forward vector right?
the vector that points outwards from the front of the camera?
If I'm pointing along the x-axis, rz rotates the camera left-right, and it's rx that's roll. But if I'm pointing along the y-axis, it's ry that's roll.
ok what which rotation order do you want? in case you don't know what rotation ordering is, it's in which order these rotation matrices are multiplied to make the object rotated:
i'm assuming you want YXZ since that's what the ordering most applications use for camera rotation. if YXZ is what you want, then basically my code should work. i tested it. i did flip the signs a little bit to make it work but it's still basically my code from before.
x += -sin(ry) * cos(rx)
y += sin(rx)
z += -cos(ry) * cos(rx)
the only problem is that, if the code just simply changes rx and ry like so:
ry += userTurnY() // if up or down arrow is pressed
rx += userTurnX() // if right or left arrow is pressed
and if rz isn't 0, then rotating it is weird. but translating the camera forward works as intended. trust me, i tested it.
i'm gonna figure out how to make rotation work. i'll post it when i'm finished.
so basically, you have a variable rot that is a 4x4 matrix.
to rotate it, you use this:
r = r * rotationY(turnY) * rotationX(turnX) * rotationZ(turnZ)
turnX, turnY, and turnZ are how much it should turn, from user input. rotationX, rotationY, and rotationZ return rotation matrices given the axis and angle.
the order is YXZ
now, the vectors pointing outwards to the back (vector Z), right (vector X), and up (vector Y) of the camera are stored in the rotation matrix
X1 X2 X3 0
Y1 Y2 Y3 0
Z1 Z2 Z3 0
0 0 0 0
so if you add Z to the camera's position, it will move it backward from its orientation.
if you add X to the camera's position, it will move it to the right from its orientation.
and if you add Y to the camera's position, it will move it up from its orientation.
this makes it rotate differently compared to my previous solution, but it works well for any rz value.
three.js might have methods to do these. i don't really know, i haven't used three.js in a long time.
edit: three.js has the following methods: new Euler(x: number, y: number, z: number, order: string) Matrix4.makeRotationFromEuler(euler: Euler): Matrix4 Matrix4.makeRotationX(theta: number): Matrix4 Matrix4.makeRotationY(theta: number): Matrix4 Matrix4.makeRotationZ(theta: number): Matrix4 Matrix4.elements: array
well i mean... you sure that is allowed? it's an offsite meeting... technically
or did they change the rules a bit since i last frequently checked here?
i'm not sure...