Jump to content
  • Advertisement
Sign in to follow this  
Sembiance

OpenGL How to correctly handle camera movement with gluLookAt?

This topic is 4665 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I've been doing C/C++ for about 12 years now but I'm new to OpenGL and the 3D world :) I'm using a slightly modified Lesson 3 from NeHE with a simple rotating Pyramid. My goal is to be able to 'fly around' the pyramid by using the mouse. I'm using gluLookAt to successfully get closer to the object, and move further away by changing the z index of the camera position. However changing the X and Y locations appear to have to difference whatsoever. Here is the code with how I am rendering it:
///////////////////////////////////////////////////////////////////////////
// DrawGLScene
void DrawGLScene(void)
{
	static GLfloat		rtri=0.0f;

	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);	// Clear the screen and the depth buffer
	
	glLoadIdentity();									// Reset the view
	gluLookAt(gXLoc, gYLoc, gZLoc, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);

	//glTranslatef(0.0f, 0.0f, 0.0f);					// Move Left 1.5 Units And Into The Screen 6.0

	glRotatef(rtri, 0.0f, 1.0f, 1.0f);

	glBegin(GL_TRIANGLES);
		glColor3f(1.0f, 0.0f, 0.0f);			// Red
		glVertex3f(0.0f, 1.0f, 0.0f);			// Top Of Triangle (Front)
		glColor3f(0.0f, 1.0f, 0.0f);			// Green
		glVertex3f(-1.0f, -1.0f, 1.0f);			// Left Of Triangle (Front)
		glColor3f(0.0f, 0.0f, 1.0f);			// Blue
		glVertex3f(1.0f, -1.0f, 1.0f);			// Right Of Triangle (Front)
		glColor3f(1.0f, 0.0f, 0.0f);			// Red
		glVertex3f(0.0f, 1.0f, 0.0f);			// Top Of Triangle (Right)
		glColor3f(0.0f, 0.0f, 1.0f);			// Blue
		glVertex3f(1.0f, -1.0f, 1.0f);			// Left Of Triangle (Right)
		glColor3f(0.0f, 1.0f, 0.0f);			// Green
		glVertex3f(1.0f, -1.0f, -1.0f);			// Right Of Triangle (Right)
		glColor3f(1.0f,0.0f,0.0f);				// Red
		glVertex3f( 0.0f, 1.0f, 0.0f);			// Top Of Triangle (Back)
		glColor3f(0.0f,1.0f,0.0f);				// Green
		glVertex3f( 1.0f,-1.0f, -1.0f);			// Left Of Triangle (Back)
		glColor3f(0.0f,0.0f,1.0f);				// Blue
		glVertex3f(-1.0f,-1.0f, -1.0f);			// Right Of Triangle (Back)
		glColor3f(1.0f,0.0f,0.0f);				// Red
		glVertex3f( 0.0f, 1.0f, 0.0f);			// Top Of Triangle (Left)
		glColor3f(0.0f,0.0f,1.0f);				// Blue
		glVertex3f(-1.0f,-1.0f,-1.0f);			// Left Of Triangle (Left)
		glColor3f(0.0f,1.0f,0.0f);				// Green
		glVertex3f(-1.0f,-1.0f, 1.0f);			// Right Of Triangle (Left)
	glEnd();
	
	SDL_GL_SwapBuffers();			// Draw it to the screen

	rtri+=0.2f;
}

Share this post


Link to post
Share on other sites
Advertisement
I hate giving stupid advice, but I was about to give even stupider advice (I get OGL/D3D mixed up easily - was going to mention that you should have set the viewmatrix as the active matrix... d'oh @ modelview matrix) . Anyway, are you sure that the values passed to gluLookAt are the ones you want? The code you posted doesn't appear to have any problems with it, and I know gluLookAt does what you're intending it to do.

Share this post


Link to post
Share on other sites
Quote:
Original post by X5-Programmer
Well, check this site.

Link :]

and on the opengl -> third page.

GL.


Cool! Thanks! I see the camera movement tutorial code, bookmarked that site :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!