Recommended Posts

Greetings. I''m a relatively new OpenGL programmer, and I thought I knew for the most part what was going on but lately the behavior of gluLookAt has me doubting myself.
I''ve created a scene graph structure, so every renderable object inherits its parent''s transformations. Each object has a method called getResultantTransform that recursively multiplies the matrices from the root node down, until you have the resultant matrix for the desired object. This all works fine, and to test this I created a sphere (which represents Earth), and a plane, the plane is the child of the earth, so if I apply transforms to the earth, they inherently get applied to the plane, etc.
I wanted to be able to put the "eye" on the tip of the nose of the plane so the user could see what the plane saw as it flew. I decided to use gluLookAt to accomplish this, however I''m having some serious issues. To run gluLookAt, I take the current *world* coordinates of the plane as my "eye" point. I then take the plane''s initial "up" vector (in it''s own, local coordinate system) and apply the planes current resultant transformation to this vector. I also apply the plane''s resultant vector to the original point that corresponded to the tip of the nose (so that the direction gluLookAt would be looking is the front of the plane).
When I run the code, I output the 3 points/vectors:
Plane''s location: (the eye part of gluLookAt)
0.0, 6.3069E-14, -2380.00
View point (after applying plane''s resultant transform):
0.0, 6.208E-14, -2363.87
Up vector (after applying transform):
0.0, 1.0, 6.1E-17
if you assume the very small numbers are 0, then the resulting values are:
Plane''s location: (the eye part of gluLookAt)
0.0, 0, -2380.00
View point (after applying plane''s resultant transform):
0.0, 0, -2363.87
Up vector (after applying transform):
0.0, 1.0, 0
So the view point is closer to the origin on the z axis than the plane''s position, which means that eye should be looking at the origin after my call to gluLookAt, but in fact it''s looking in the opposite direction. If I put a 0 in the z coordinate of the view point, it works fine (it looks at the origin), even if I put a -2300 in, it works fine. It seems that between -2349 and -2350 something gets all screwed up. Am I missing something here?
Thanks in advance!
Rick