Archived

This topic is now archived and is closed to further replies.

CactusLime

Rotate around point ala Cinema4D problem!

Recommended Posts

CactusLime    122
Hi! I have a small problem! I am building a camera control that should work like the one in Cinema4D. It should be able to rotate around the selected object in the scene. The rotation around the selected object works just fine. But when I am selecting a different object the camera "jumps" to a another position. I want the camera to stand still just change the circle the the camera should rotate around. Here is some code
private Quaternion m_qX;
private Quaternion m_qY
private matrix m_rotation;
private matrix m_view;
private Vector3 m_rotationPoint;
private Vector3 m_camPosition;

public void RotateAxisWithAngle(Vector3 axis, float angle)
{
  float cosA = (float)Math.Cos(angle/2.0f);
  float sinA = (float)Math.Sin(-angle/2.0f);
  
  m_qX *= new Quaternion(axis.X*sinA, 0, cosA)
  m_qY *= new Quaternion(0, axis.Y*sinA, cosA)
 
  Quaternion q = m_qY * m_qX;
  q.Normalize()
  m_rotation = matrix.RotationQuaternion(q)
}
public void RecalculateViewMatrix()
{
  m_view = Matrix.Translate(-m_rotationPoint.X, -m_rotationPoint.Y, -m_rotationPoint.Z);
  m_view *= m_rotation;
  m_view *= Matrix.Translate(m_rotationPoint);
  m_view *= Matrix.Translate(-m_camPosition.X, -m_camPosition.Y, -m_camPosition.Z);
}
ok its in the RecalculateViewMatrix() code where the problem lies. It make the camera "jump" when i change the rotationPoint. Is there any simple solution to this? I have tried all kinds of matrix multiplications. ((P)^-1*R*P*T, ....) but nothing worked! Thanks! Magnus Stålberg

Share this post


Link to post
Share on other sites