Advertisement

Retrieving lookAt vector when using an object/basis system for local co-ords

Started by October 11, 2001 06:44 AM
0 comments, last by aSe 23 years, 4 months ago
Hi folks, Stumped again. I''m using an object/basis representation for objects and the camera, which means that for each object I store the position in world co-ords of the origin of the object''s local co-ord system, and vector u, v and n to map the direction of the three axes in the local co-ord system to the world co-ord system; this makes for easy rotation since each object has .Roll(GLfloat), .Pitch(GLfloat) and .Yaw(GLfloat) methods, which simply affect the u, v and n vectors. To set up the modelview matrix before drawing this object I then just need to do
  
glPushMatrix();
GLfloat m[16];
m[0]=u.x; m[4]=v.x; m[8]=n.x;  m[12]=position.x;
m[1]=u.y; m[5]=v.y; m[9]=n.y;  m[13]=position.y;
m[2]=u.z; m[6]=v.z; m[10]=n.z; m[14]=position.z;
m[3]=0;   m[7]=0;   m[11]=0;  m[15]=1.0;
glMultMatrixf(m);
  
(please note that the credit for most of this goes to Eoin Hennessye of as it''s based on his excellant camera class.) Now, the problem is this. For a particular reason that''s not relevant I need to be able to retrieve two vectors and a point which define the position and orientation of the object in world co-ords - the vectors should represent the up and forward directions of the current object orientation. Getting the position is easy, as it''s just the position in world co-ords of the origin of the object''s local co-ord system, but how can I get the "up" and "forward" vectors by manipulating u, v and n? I think I need to reverse engineer these values to get a lookAt vector, as you''d use in GLULookAt, and then mess with those vectors to transpose them into just an up and a forward, but I''m just not managing it. Any thoughts?
-=aSe=-
got it!!!

I was right about the forward vector being -n, but the up vector is of course a vector that projects onto the v-axis in the uv plain, as given by u/n )

ASEVector3f camForward, camUp;
camForward.Set(-cam.n.x, -cam.n.y, -cam.n.z);
camUp.Set(cam.u.x/cam.n.x, cam.u.y/cam.n.y, cam.u.z/cam.n.z);
camForward.Normalize();
camUp.Normalize();
player.Wav3DSetListenerPosition(&cam.position, &camForward, &camUp);
player.Wav3DSetSourcePosition(&ship.position);

Just in case that helps anyone else. It has applications with the sound library FMOD.
-=aSe=-

This topic is closed to new replies.

Advertisement