PDA

View Full Version : Accuracy problems with gluLookAt()?

SilentStrike
05-10-2001, 02:59 PM
First, sorry if this belongs in the beginner's section. It probably deserves something inbetween.

I wrote a camera class. It seemed to work 100% fine until I tried to use it to browse the solar system. The camera acted very unpredictibly.

My call to the function looks something like this...
gluLookAt( position.x(), position.y(), position.z(),
pointOfSight.x(), pointOfSight.y(), pointOfSight.z(),
0.0f, 1.0f, 0.0f);

PointOfSight is the result of vector addition of positon and lineOfSight. lineOfSight is a unit vector in view direction. Is the unpredictible behavior possibly due to the inaccuracy because position and point of sight are so similair? That is, when the position is in 10^11 range, and the difference is in the 10^-1 range, there is accuracy problems with the floating point math involved?

bsenftner
05-10-2001, 07:53 PM
If you are worried about position and pointOfSight being too close, then simply push pointOfSight out a bit further...

Hmmm... I just examined the gluLookAt() source from MESA. All that the position and pointOfSight are used for are to generate a normalized direction vector that points down the Z axis. So, in your case, all you are doing is passing in points that don't need to be normalized.

But then again, your difference is 10^-1 with large floating values. Yeah, that would probably cause precision issues. You could simply projct pointOfSight out further...

Or you could consider that all gluLookAt() is doing is constructing two matrices, one the basis of your view and the other the negative translation of your position and concatenating them together. So your LookAt matrix should look something like this:

basisX.GetX(), basixY.GetX(), basisZ.GetX(), 0.0f
basisX.GetY(), basixY.GetY(), basisZ.GetY(), 0.0f
basisX.GetZ(), basixY.GetZ(), basisZ.GetZ(), 0.0f
-position.GetX(), -position.GetY(), -position.GetZ(), 1.0f

Where the basis vectors are the normalized direction vectors that point down the x, y, and z axies of your view. Most of what gluLookAt() is doing is generating those basic vectors and making sure they are perpendictular (sp?).

Hope that helps.
-Blake

SilentStrike
05-11-2001, 01:10 AM
I've got a fix for it (multilplying line of sight by moveSensativity of the camera before calculating point of sight). Only problem is the that it is being entered in a local high school programming contest... changes the day of the contest definetely is not the surest thing to do. Conversely, when they ask me to make a model of the solar system, I want the camera to actually work.