Hi,
I'm making a fps style camera in a 3d game and was learning about Quaternions. I just want the camera to have pitch and heading, but no bank. And not track euler angles over multiple frames. Whats the best way to do this? The code I have looks like this.
| //Get the change in mouse position
V2 diff = normalize(v2_minus(mouseP, state->lastMouseP));
float sensitivity = 3;
float angleX = sensitivity*diff.y*dt;
float angleY = -sensitivity*diff.x*dt;
Quaternion rot = eulerAnglesToQuaternion(angleY, angleX, 0);
//rotate the camera orientation by the change in rotation
camera.orientation = quaternion_mult(camera.orientation, rot);
|
I was wondering if this looks correct and is it equivalent to the below code, which is tracking Euler angles over frames.
| static V2 eulerXY = {};
float sensitivity = 3;
float angleX = sensitivity*diff.y*dt;
float angleY = -sensitivity*diff.x*dt;
eulerXY.x += angleX;
eulerXY.y += angleY;
camera.orientation = eulerAnglesToQuaternion(eulerXY.y, eulerXY.x, 0);
|
Also in the first code snippet, is:
| camera.orientation = quaternion_mult(camera.orientation, rot);
|
the same as:
| camera.orientation = quaternion_mult(rot, camera.orientation);
|
Thanks for your help, any info about the best way to use Quaternions would be great.