Jump to content
  • Advertisement
Sign in to follow this  
idloco

Camera Rotation

This topic is 4831 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 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]

Share this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!