3d worlds and movement. . .


New member
I've been looking at the various tutorials at nehe.gamedev.net and the one on moving through a 3d world (this one)brings up a very interesting concept. Unless I've read it wrong, the camera doesn't move at all. Instead, the world is simply shifted and rotated around the camera. Is this how it actually works in modern games and other 3d applications? It seems really strange. . .
Well, that's pretty much how everything in 3d works. Basically, the camera is at (0,0,0) and is looking along the Z axis. This never changes. You also don't want to change your geometry according to position, would be very cumbersome. So, you have a matrix which transforms every vertex you pass to the API into the cameras space.

Basically, like this in OpenGL:

glRotatef(0,0,1, angleZ); // Rotate around Z
glRotatef(1,0,0, angleX); // Rotate around X
glRotatef(0,1,0, angleY); // Rotate around Y
glTranslatef(-cameraX, -cameraY, -cameraZ);

From now on you can just pass vertices as they are in your world and it'll be as though the camera has moved. Personally, I just setup the matrix like that and think of it as the camera has moved, it's easier that way.
Ah, thanks. . . I've been coding only from a mod-making perspective with the Unreal Engine for so long that I've gotten used to thinking that it is the camera that is moving. Not only that but in real life it isn't the world that moves, but the person, of course. Heheh, looks like in 3d programming the world -does- revolve around the programmer! ;)
it's all in how you look at it. You can look at it as if only the camera is moving, or as if the world is moving around the camera. You will have to transform the objects differently each way though. (rotate first, then transform or transform then rotate, etc)