Original Post
🔒 Locked
Camera Rotation
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
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
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
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
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)
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?
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?
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);}
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)
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)
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement