View Full Version : help me NOT use gluLookAt()

Junkstyle

07-19-2002, 08:39 AM

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?

ioquan

07-19-2002, 09:42 PM

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.

class Camera

{

public:

void LookAt(Point3D * point);

void DoTransformation()

//camera's origin

Point3D m_origin;

//orientation vectors

Point3D m_right;

Point3D m_up;

Point3D m_forward;

}

void Camera::LookAt(Point3D * point)

{

m_forward = *point - morigin;

m_forward.Normalize();

m_up.Set(0,1,0);

m_right = CrossProduct(m_up,m_forward);

m_up = CrossProduct(m_forward, m_right);

m_up.Normalize();

m_right.Normalize();

}

void Camera: :DoTransformation()

{

//make a matrix with the 3x3 part being the //camera's 3 orientation vectors.

Matrix viewtransform;

//using some custom matrix functions

viewtransform.MakeFromVectors(m_right, m_up, m_forward);

viewtransform.Translate(m_origin.x, m_origin.y, morigin.z);

glMultMatrixd(viewtransform.data);

}

[This message has been edited by ioquan (edited 07-19-2002).]

Junkstyle

07-22-2002, 02:28 PM

That didn't work for some reason.

"that didn't work" doesn't describe the problem

cheers,

John

Junkstyle

07-22-2002, 09:43 PM

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.

Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.