JPro
JPro

Reputation: 79

How to move my camera in OpenGL

I'm trying to have my camera move in the way games do in first person. I have shapes drawn and oriented to look like a hallway, so I need the camera to move forward as if your moving through the hallway. What lines of code should I use, and where should I put them?

Upvotes: 0

Views: 815

Answers (1)

Jack
Jack

Reputation: 133557

You should see the things from the opposite side, you don't move the camera. Instead you move the world so that its projection changes according to the camera (which doesn't really exist) position.

This is usually done by having a projection matrix which embeds the current camera position and orientation and this matrix is used inside your shaders, after having applied the model matrix (remember it's not symmetric).

Take a look a this good tutorial to get the necessary knowledge. Basically everything reduces to:

 gl_Position = camera * model * vec4(vertex, 1);

Upvotes: 1

Related Questions