Shpooke
Shpooke

Reputation: 60

OpenGL. gluLookAt function not working

This is an image which I draw with my program:

[IMG] http://i62.tinypic.com/j163j8.png [/IMG]

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

GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);  
GL.glLoadIdentity();
GL.glMatrixMode(GL.GL_MODELVIEW);

glu.gluLookAt(
5.0, 2.0, 2.0,
0.0, 0.0, 0.0,
0.0, 0.0, 0.0);

figura(drawable);   //Drawing figure 
GL.glFlush();

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.

Upvotes: 0

Views: 301

Answers (1)

schmop
schmop

Reputation: 1440

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".

Upvotes: 1

Related Questions