PDA

View Full Version : Up-Vector of gluLookAt( ... );



OGL_PGR
08-28-2005, 11:44 PM
Please help me to resolve the following issue:

Objective:
Trying to make the camera follow an object in 3d space.

For every DrawGLScene() frame, I'm calculating 6 positions w.r.t to the object's coords(x,y,z) for 6 Views of the object. i.e Top, Bottom, Left, Right, Front & Rear Views respectively.

The user can "switch" ( i.e to say jump ) between different views.

I'm trying to interpolate (linear) b/w these jumps so that Camera "softly" shifts b/w 2 camera postions.

Problem is with the "Up-Vector", which I'm trying to calculate for every frame.

Its a bit tilted and "attached" to the object's co-ordinate system.

For TOP & BOTTOM VIEWS, UP-VECTOR = 1,0,0 ;
For the Other 4 views, UP_VECTOR = 0,1,0 ;

I'm performing the following operations for calculating the "Up-Vector" and passing it to gluLookA(...) function :-

Vector Camera(cx,cy,cz);
Vector Object(ox,oy,oz);

// projection of the camera-location on
// object plane ( || to X-Z plane)
Vector Project(cx,oy,cz);

Vector Look = Camera - Object;

// This is from projected point
// to the object.
Vector Base = Project - Object;

// This is from Camera to Projected point.
Vector Height = Camera - Project;

Now after calculating the vectors, I'm first calculating the right vector like this:
( '^' - overloaded for cross - product )
Right = Height^Look;
Up = Right^Look;
Up.Normalize(); ---> Pass this (Up.x, Up.y, Up.z ) to gluLookAt.

Thanks.

Hlz
08-29-2005, 08:25 AM
Have you looked at quaternions?

P.S. Please don't cross post.

dzim77
08-29-2005, 07:40 PM
As it stands, your up-vector calculations fall apart when you are looking along the y-axis through the object, because you are always projecting onto the XZ plane... but I guess you already knew that.

Switching to a different up-vector (1,0,0) as you indicated is the easiest solution. I would just linearly interpolate the up-vectors (from 1,0,0 to 0,1,0) in the same way that you interpolate the camera positions, rather than trying to determine the up-vector from the interpolated camera and object coordinates. Just make sure to normalize the interpolated up-vectors.

Don.