Skip to main content
gamedev.net
🔒 Locked

Camera Rotation

Started by idloco 6 replies 1k views
Original Post
idloco
idloco
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]
------------------------------------ IDLoco Game Studios
crucifer
crucifer
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
crucifer
crucifer
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
SnprBoB86
SnprBoB86
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?
Brocketino
Brocketino
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);}
SnprBoB86
SnprBoB86
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)
idloco
idloco
Thanks to all , i i finally make the camera rotate :D :D :D :D
------------------------------------ IDLoco Game Studios

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.