PDA

View Full Version : Problem with gluLookAt



JunkerKun
01-25-2013, 11:46 AM
Hello. I have quite strange problem.



while( running )
{

glfwGetMousePos( &x, &y );
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT );

glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluPerspective( 75.0f, (GLfloat)640/(GLfloat)480, 1.0f, 300.0f );

glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
gluLookAt(0,-10,10,0,0,10+vdirection,0,1,0);
glPushMatrix();

glPopMatrix();
glBindTexture(GL_TEXTURE_2D,texture);
glTranslatef(0,0,5);
glScalef(5,5,5);
model2.draw();

angle+=1;
if (angle>360) angle-=360;

glfwSwapBuffers();

if(glfwGetKey( GLFW_KEY_LEFT )) {
direction-=1;
};
if(glfwGetKey( GLFW_KEY_RIGHT )) {
direction+=1;
};
if(glfwGetKey( GLFW_KEY_UP )) {
if (vdirection<89) vdirection+=1;
};
if(glfwGetKey( GLFW_KEY_DOWN )) {
if (vdirection>-89) vdirection-=1;
};

running = !glfwGetKey( GLFW_KEY_ESC ) &&
glfwGetWindowParam( GLFW_OPENED );
}
glfwTerminate();
exit( EXIT_SUCCESS );
};


There is a lot of garbage but this is just for experimenting. Now the problem is next:
When xfrom and xto in gluLookAt are equal it doesn't shows anything at all, only a black screen. If xto is larger than xfrom then it just shows everything upside-down! What is going on?

tonyo_au
01-26-2013, 10:34 PM
I think everything is ok - you are underneath something looking up so I would expect it to look upside down. If xFrom == xTo you have no direction to look so I don;t expect anything to work.

JunkerKun
01-28-2013, 06:32 AM
I think everything is ok - you are underneath something looking up so I would expect it to look upside down. If xFrom == xTo you have no direction to look so I don;t expect anything to work.

So, I need to check if xto is above xfrom and then invert upvector?

tonyo_au
01-28-2013, 08:38 PM
The up vector orients you camera around the viewing direction. When look down or up you have to decide what "up" means. Grab a physical camera(or phone) and see what is at the top of the image as you spin the camera.