kbz
kbz

Reputation: 1006

How would I go about moving in a 3D environment, openGL c++

I'm not quite sure on how I should be making things move using openGL.

Am I supposed to be moving the camera's position around the 3D world, or moving/translating the objects around the camera?

I read online that the camera should stay at the origin and everything else should move around the camera, but wouldn't that be an intensive operation? Like if I have 1000 objects and I'm moving, we'd have to move all of these objects. Would it not be easier to move the camera and keep the world objects where they are?

Upvotes: 2

Views: 537

Answers (2)

Berke Cagkan Toptas
Berke Cagkan Toptas

Reputation: 1034

In Opengl, the camera is always located at the eye space coordinate (0., 0., 0.). To give the appearance of moving the camera, your OpenGL application must move the scene with the inverse of the camera transformation.

You don't need to worry about moving/translating objects in your scene. gluLookAt() function does it for you. This function computes the inverse camera transform according to its parameters and multiplies it onto the current matrix stack.

Upvotes: 0

Blindy
Blindy

Reputation: 67380

The way OpenGL works is, conceptually, the camera is always in the center, Y axis up and Z axis forward. If you want to move or rotate the camera, you actually move everything else the opposite way.

This is opposed to Direct3D for example, where you have a separate camera matrix.

It's a minor detail though because mathematically speaking they're exactly the same. Whether you move everything forward or the camera back, it's exactly the same end result. You could even argue that having only one matrix as opposed to lugging around two and multiplying them is a performance gain, but it's extremely minor and usually you'll separate your camera matrix from your world building matrix anyway.

Upvotes: 2

Related Questions