OpenGL. gluLookAt function not working

Tag: glulookat Author: hyr88 Date: 2014-04-23

This is an image which I draw with my program:

[IMG] [/IMG]

It is supposed to be 3D. When I try to check it with gluLookAt:


5.0, 2.0, 2.0,
0.0, 0.0, 0.0,
0.0, 0.0, 0.0);

figura(drawable);   //Drawing figure 

It only shows white screen, or a messed up figure for a second, then it goes off. If I undestand good first 3 coords shows point of view, second 3 shows viewing destination and third 3 shows rotation axis. But this function only messes everything up.

Thanks for answers.

Third 3 are the "up" vector, try glu.gluLookAt(5.0, 2.0, 2.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
@AnthonyVallée-Dubois That would be a valid up vector if the eye was on the same XZ plane as the target, ie. {5, 0, 2} instead of {5, 2, 2}.
@schmop Maybe I'm wrong as it's been a while but it's my understanding that the up vector is recomputed by gluLookAt() to be perpendicular to the direction vector such as side = cross(dir, up); up = cross(side, dir);. See
@schmop In any case computing it yourself isn't wrong and your answer is spot on.
@AnthonyVallée-Dubois Oh. That's very handy! Haven't used gluLookAt in 10 years myself...

Other Answer1

The last three parameters aren't exactly the rotation, but the "up" vector. If you do not want a distorted view, the up vector should be perpendicular to your direction vector, which here is {-5, -2, -2}. Among all the perpendicular vectors, the one you will choose will define the rotation as you call it.

In your example, the most upward perpendicular vector (the one you would use in a first person game for instance) would be {-.323, .937, -.129} after normalization. I computed it first by finding the "left" vector (cross product between absolute up {0, 1, 0} and the direction), and then as the cross product between the direction and "left".


gluLookAt() ortho-normalizes the up vector relative to the eye vector. There's no need to do that manually. See
@RetoKoradi Okay. That wasn't so clear from the OpenGL reference pages.