0
votes

I am new to OpenGL and was trying to create a simple maze that i can traverse through using a first person perspective. I have the maze rendering and all that just fine. But my first person camera perspective ends up being more of a third person camera. The camera revolves around a certain point infront of the camera.

My Code for actual rotation and translation

void camera(){
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glRotatef(pitch, 1, 0, 0);
    glRotatef(yaw, 0, 1, 0);
    glTranslatef(player.x, player.y, player.z);
}

This is also the first translations and rotations that happen in rendering. Thanks for any help.

2
"The camera revolves around a certain point infront of the camera." What is it about what you're seeing that makes you say that? The only way that could be possible is if the player location changes when you rotate the view. - Nicol Bolas
I drew a little pyramid at player and the camera when rotating revolves around that position. - Mirza

2 Answers

1
votes

The camera transformation needs to be inverted, so that you are moving the camera position, in this case the position of the player, to the origin:

glTranslatef(-player.x, -player.y, -player.z);
0
votes

I suggest that you build your maze, leave it alone, and then use gluLookAt() to have your first-person perspective. What you're doing now is standing still and moving the maze around you. You're doing it the hard way.