# 3d rotation about a vector

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

## 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 on other sites
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 on other sites
Thanks! Just what I was looking for!

1. 1
Rutin
29
2. 2
3. 3
4. 4
5. 5

• 13
• 13
• 11
• 10
• 13
• ### Forum Statistics

• Total Topics
632960
• Total Posts
3009478
• ### Who's Online (See full list)

There are no registered users currently online

×