# Camera Rotation

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

## Recommended Posts

i want to rotate a camera around a point. i got StaticPoint x,y,z, And a x,y,z for the camera How can i do this? i dont know the angle, alL i know are the two points. thanks in advance, and sorry for my english [Edited by - idloco on August 25, 2005 9:56:01 PM]

bump

##### Share on other sites
Matrix-CamTranslation-Negative * Matrix-ObjectTranslation-Negative * MatrixRotation * Matrix-ObjectTranslation-Positive * Matrix-CamTranslation-Positive

In other words :

1-you take the position of your camera and substract the position of the point it is observing -> store it into -> Matrix-ObjectTranslation-Positive

2-you negate the translation of Matrix-ObjectTranslation-Positive -> store it into -> Matrix-ObjectTranslation-Negative

3-you take the position of the object -> store it into -> Matrix-CamTranslation-Positive

4-you negate the translation of Matrix-CamTranslation-Positive -> store it into -> Matrix-CamTranslation-Negative

5-you make the rotation you want to apply -> store it into -> MatrixRotation

6-Multiply the current position of you cam by the result matrix

##### Share on other sites
I made an error ... in my formulae, I am substracting the difference of the position from the cam to the object twice ...

Here is the correct version :

Matrix-CamTranslation-Negative * MatrixRotation * Matrix-CamTranslation-Positive

In other words :

1-you take the position of the object -> store it into -> Matrix-CamTranslation-Positive

2-you negate the translation of Matrix-CamTranslation-Positive -> store it into -> Matrix-CamTranslation-Negative

3-you make the rotation you want to apply -> store it into -> MatrixRotation

4-Multiply the current position of you cam by the result matrix

##### Share on other sites
I am not the original poster, but I am also having difficulty with this.

The code below implements your technique (and also transforms the camera up)

public void Tumble(Vector2 vector2){	Vector3 lookDirection = this.LookDirection; // LookDirection is LookAt - Position, not normalized	Matrix transform = Matrix.Translation(-lookDirection) *		Matrix.RotationYawPitchRoll(-vector2.X, -vector2.Y, 0.0f) * Matrix.Translation(lookDirection);		this.Position = Vector3.TransformCoordinate(this.Position, transform);	this.Up = Vector3.TransformCoordinate(this.Up, transform);}

With or without the Up transformation, this behaves strangely. The camera rotates around the LookAt, but the distance from that point to the camera varies wildly.

What could be wrong?

##### Share on other sites
I did something like this to rotate around a point over the y-axis. I think the m_vDirection is the point around wich you want to rotate.

void rotate( const float speed ){  CVector3f v = ( m_vPos - m_vDirection );  m_vPos.z = (float)(m_vDirection.z + sin(speed)*v.x + cos(speed*v.z);  m_vPos.x = (float)(m_vDirection.x + cos(speed)*v.x - sin(speed)*v.z);}

##### Share on other sites
My code isn't correct. It is not that simple.

The Y direction needs to be related to the camera up as the X direction needs to be related to left/right.

Maybe someone else can help with this. (sorry if I am hijacking the thread, but I think this is also what the original poster wants)

##### Share on other sites
Thanks to all , i i finally make the camera rotate :D :D :D :D

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

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

• Total Topics
634091
• Total Posts
3015435
×