• Advertisement
Sign in to follow this  

3d rotation about a vector

This topic is 4929 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm having a problem orientating a camera in 3d space. The camera's position and direction are stored in three vectors: position, direction and an up vector. I want to be able to move the camera freely, like in space simulators such as Elite or Descent. In a first person shooter type game, the camera can be rotated by applying a rotation about the axis, e.g. rotate about the y axis to look left and right. However, I want to be able to move the camera, independent of the axis. I think I need a rotation matrix which works about a vector. Then I can apply this about the up vector to look left and right. I've googled for this topic but I haven't found anything particularly useful. Am I taking the right approach?

Share this post


Link to post
Share on other sites
Advertisement
Arbitrary axis rotation:


void RotateVector(float Angle, Vector3 *VecToRotAbout, Vector3 *VecToRotate)
{
float cosTheta = (float)cos(Angle);
float sinTheta = (float)sin(Angle);
Vector3 proj = *VecToRotAbout * DotProduct(VecToRotAbout,VecToRotate);
*VecToRotate=
(*VecToRotate-proj)*cosTheta+
(CrossProduct(*VecToRotAbout, *VecToRotate)*sinTheta)+
proj;
}


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement