Results 1 to 4 of 4

Thread: Problem with gluLookAt

  1. #1
    Newbie Newbie
    Join Date
    Jan 2013
    Posts
    2

    Problem with gluLookAt

    Hello. I have quite strange problem.

    Code :
    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?

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117
    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.

  3. #3
    Newbie Newbie
    Join Date
    Jan 2013
    Posts
    2
    Quote Originally Posted by tonyo_au View Post
    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?

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117
    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.

Similar Threads

  1. Problem with gluLookAt
    By in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 01-13-2006, 04:55 PM
  2. shadows problem and gluLookAt()
    By MaNDROiD in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 12-03-2004, 07:26 AM
  3. Problem with gluLookAt
    By wazoo in forum OpenGL: Basic Coding
    Replies: 9
    Last Post: 09-24-2004, 06:42 PM
  4. Problem with gluLookAt
    By djavan in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 03-04-2003, 08:18 AM
  5. gluLookAt PROBLEM!
    By in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 04-04-2000, 09:05 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean