0
votes

i'm new to openGL and i'm trying to move the camera as a first person shooter game. i want to use gluLookAt for movement and looking around the scene, but i can't figure out the camera part

gl.glMatrixMode(gl.GL_MODELVIEW)
gl.glLoadIdentity()
glu.gluLookAt(current_player.position[0], current_player.position[1] ,
              current_player.position[2], look_at_position[0], look_at_position[1], 0,
              0, 1 ,0)

the look_at_position is the mouse position but i can't calculate the last value so i put temporarily as 0

i just want to know how to move the player and the camera using the glLookAt.

1

1 Answers

0
votes

Works the same as glm::lookAt(). First argument is the position you are viewing from (you are correct), then the position you are looking at, and then the up vector (also correct). Here's what I invoke:

//this code is in the mouse callback, both yaw and pitch are mouse inputs
glm::vec3 front;
glm::vec3 right;
front.x = cos(glm::radians(yaw)) * cos(glm::radians(pitch));
front.y = sin(glm::radians(pitch));
front.z = sin(glm::radians(yaw)) * cos(glm::radians(pitch));
cameraFront = glm::normalize(front);
front.x = cos(glm::radians(yaw));
front.z = sin(glm::radians(yaw));
movementFront = glm::normalize(front);

//this is in int main()
view = glm::lookAt(cameraPos, cameraPos + cameraFront, cameraUp);