I want to track an object and follow its orientations as well.
So for translation I know -x, -y, -z is the same as moving the camera +x, +y, +z. And rotations are backwards as well?
If I have the UP, FORWARD, RIGHT unit vectors of the object I want to follow and imitate its orientation, how do I use these vectors?
Remember that moving the camera in a direction is the same as moving everything in the world the opposite direction. You do the matrix transformation for the camera just like you would for your objects, except in reverse. Here is a little class I just made up to help solve the problem. It stores the orientation as a forward, up, and right vector. LookAt() just modifies the vectors. DoTransformation modifies the modelview matrix.
void LookAt(Point3D * point);
void Camera::LookAt(Point3D * point)
m_forward = *point - morigin;
m_right = CrossProduct(m_up,m_forward);
m_up = CrossProduct(m_forward, m_right);
void Camera: :DoTransformation()
//make a matrix with the 3x3 part being the //camera’s 3 orientation vectors.
//using some custom matrix functions
viewtransform.MakeFromVectors(m_right, m_up, m_forward);
viewtransform.Translate(m_origin.x, m_origin.y, morigin.z);
[This message has been edited by ioquan (edited 07-19-2002).]
That didn’t work for some reason.
“that didn’t work” doesn’t describe the problem
yeah I know what you mean, but its hard to describe goofy rotations. I got a solution going on another thread that works. I think this approach will/should work and I might need it for some tracking stuff I’m doing, so I’ll keep you posted if I get it working. On thing that won’t work at least when I tried it is the combination of the translation into the matrix at the same time. I found that this translation for the camera has to come after the rotation for some reason. Other 3d world objects its fine to combine the translation and the rotation in the same matrix and I do that in practice.