Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualgp521

Posted 27 October 2012 - 07:37 AM

Thanks for the advice, I got it working, my ship is flying! I didn't quite go this approach, but it got me to abandon the convert to euler dead end and think about this differently. The answer turned out to be quite simple actually, the rotation matrix contains the direction! Here's my modified code:

// For each frame

// Get worldview rotation matrix from the quaterion.
Matrix4 matrix = QuaternionToMatrix4(quaternion);

// Update the camera position.
Vector3 forward = Vector3(matrix.m[2], matrix.m[6], matrix.m[10]);
forward = Vector3Normalize(forward);

cam_pos.x += forward.x * speed * dt;
cam_pos.y += forward.y * speed * dt;
cam_pos.z += forward.z * speed * dt;

// translate the worldview matrix.
matrix = Matrix4Translate(matrix, cam_pos.x, cam_pos.y, cam_pos.z);

#1gp521

Posted 27 October 2012 - 07:37 AM

Thanks for the advice, I got it working, my ship is flying! I didn't quite go this approach, but it got me to abandon the convert to euler dead end and think about this differently. The answer turned out to be quite simple actually, the rotation matrix contains the direction! Here's my modified code:

// For each frame

// Get worldview rotation matrix from the quaterion.
Matrix4 matrix = QuaternionToMatrix4(quaternion);

// Update the camera position.
Vector3 forward = Vector3(_matrix.m[2], _matrix.m[6], _matrix.m[10]);
forward = Vector3Normalize(forward);

cam_pos.x += forward.x * speed * dt;
cam_pos.y += forward.y * speed * dt;
cam_pos.z += forward.z * speed * dt;

// translate the worldview matrix.
matrix = Matrix4Translate(matrix, cam_pos.x, cam_pos.y, cam_pos.z);

PARTNERS