Hi guys,
I’m new to OpenGL and am have just completed implementing my first 3d environment. However I’m not too sure on how to implement the funtions to allow the user to move around the world using the cursor keys. I’ve been going through the tutorials on nehe and used the system the desribed where you would have a key listener in winmain which would change a variable in the draw() function thus transforming the the entire world. But as I need to implement glLoadIdentity() before drawing each object the viewpoint essentially gets stuck as the transformation is cancelled out e.g.
int DrawGLScene(GLvoid)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
GLfloat xtrans = -xpos;
GLfloat ztrans = -zpos;
GLfloat ytrans = -0.25f;
GLfloat sceneroty = 360.0f - yrot;
glRotatef(lookupdown,1.0f,0,0); //Transform everything to display movement
glRotatef(sceneroty,0,1.0f,0);
glTranslatef(xtrans, ytrans, ztrans);
glLoadIdentity();
drawCube(0.0f, 0.0f, 0.0f);
glLoadIdentity();
drawCube(1.0f, 0.0f, 0.0f);
glLoadIdentity();
drawCube(3.0f, 0.0f, 0.0f);
return TRUE;
}
If anyone could give me any tips on how to resolve this I’d be very grateful
Cheers
Kam