PDA

View Full Version : gluLookAt strange behavior



Vladimir M
01-01-2009, 02:04 PM
I am making a platform game in the glOrtho projection, and when i use gluLookAt, the image is seen well, but when i move it, the glu look at doesent move, instead it just makes part of my game screen black, it cuts it off.

The thing i want to accomplish is the camera GluLookat always looking at my player.

this is the code

//SCREEN_WIDTH=1024 and SCREEN_HEIGHT=768


bool init_GL()
{
glClearColor( 0, 0, 0, 0 );

glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glOrtho( 0, SCREEN_WIDTH, 0, SCREEN_HEIGHT, -1, 1 );

glMatrixMode( GL_MODELVIEW );
glLoadIdentity();

gluLookAt(0,0,0,0,0,-1,0,1,0);




now, the last line of code is gluLookAt, and only with these parameters gluLookAt(0,0,0,0,0,-1,0,1,0);

does the whole screen show, when I, for instance change the reference point

gluLookAt(0,0,0,200,200,-1,0,1,0);

it doesent show anything just a black screen, and when i do something like this

gluLookAt(0.003,0,0,0,0,-1,0,1,0);

than it cuts my viewport in half, and i only see half of my game, the other half is black.

trinitrotoluene
01-01-2009, 06:51 PM
now, the last line of code is gluLookAt, and only with these parameters gluLookAt(0,0,0,0,0,-1,0,1,0);

does the whole screen show, when I, for instance change the reference point

gluLookAt(0,0,0,200,200,-1,0,1,0);

it doesent show anything just a black screen,


This is normal, you have changed your view vector too much: from (0,0,-1) to (0.7071,0.7071,-0.0035). So at the eye position (0,0,0) with view vector (0.7071,0.7071,-0.0035) there is no object to see.



and when i do something like this

gluLookAt(0.003,0,0,0,0,-1,0,1,0);

than it cuts my viewport in half, and i only see half of my game, the other half is black.


I will make a guess here, maybe your object are clipped by the near or the far clipping plane if you draw them with z coordinate equal -1 (near) or 1 (far) which are the limit you give for glOrtho.


See gluLookAt (http://www.opengl.org/sdk/docs/man/xhtml/gluLookAt.xml) documentation for more information.

glavatar
01-02-2009, 04:00 AM
You should try to change the camera orientation:

gluLookAt(0,0,-1, 0,0,0, 0,1,0);

This moves the eyes backward and looks to the axis origin.

Best regards.

Vladimir M
01-02-2009, 05:12 AM
I tried expanding the near and far clipping but the results were even more confusing, everytingh was larger and the clipping was still there.

this code


bool init_GL()
{
glClearColor( 0, 0, 0, 0 );

glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glOrtho( 0, SCREEN_WIDTH, 0, SCREEN_HEIGHT, 0, 0 );



glMatrixMode( GL_MODELVIEW );
glLoadIdentity();

gluLookAt(0,0,0,0,0,1,0,-1,0);


Is at the beggining of each main loop, so that in the future maybe i can update the camera to folow my player through the level.

dletozeun
01-02-2009, 11:51 AM
Please, provide the full code and necessary data so we can check by ourself. It is difficult to help you without the whole source code in this kind of situation.