///////////////////////////////////////////////////////////////////////////
// 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;
}
How to correctly handle camera movement with gluLookAt?
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:
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement