D3D: Moving the camera

Started by
6 comments, last by VBMaster 23 years, 7 months ago
Hi, I just started learning Direct3D, so i need your help. I made a small "room" composed of 4 walls. Now, i want to be able to move the camera with the arrow keys. The question is quite simple: how do I transform the walls when moving the camera? Right now i''m just changing the view matrix based on the camera orientation, and leave the world matrix and projection matrix unchanged. Is this the right way to do it? You see, i''m a little bit confused with all that matrix stuff... Thanks, VBMaster
Advertisement
If your walls do not have to be moved (un likely) and are defined in world space coordinates then adjusting the View matrix is all you need to do.

An attempt to clarify the whole business with the matrices.

The world matrix should be used to place and transform objects into your world. This would include rotation, translation, scaling, and so on. This matrix is normally changed between each object to be rendered. After you vertices have been transformed with the world matrix they are in world coordinates.

The view matrix should be used to rotate and translate the world so that the camera that is placed in the world resides in origo and looking down the positive z axis. This is the matrix that defines what part of the world you are looking at. This matrix is only changed when the camera moves. After transform with this matrix the vertices are defined in view coordinates.

The projection matrix is used to project the view coordinates onto the screen plane. This can be an orthogonal or perspective projection. This is the matrix you use if you want to zoom in on something. After the transform with the projection matrix the vertices are in normalized screen coordinates, i.e the screen is represented with a rectangle from (-1,-1) to (1,1).

The viewport matrix is the matrix that defines where the normalized screen coordinates will be shown on the screen. Note that you define this matrix with SetViewport() and not with SetTransform(), it''s only an internal matrix to D3D. After transformation with the viewport matrix the vertices are in screen coordinates that can then be rendered directly.

All vertices you send through the Direct3D pipeline will be transformed with these four matrices, although before they are transformed the matrices are concatenated into one matrix so only one matrix multiplication occurs per vertex.

Does this clear things up?

- WitchLord

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Do you do all 4 for every frame? What about for software rendering? This is the part I''m having trouble understanding. Can''t you skip the world transformation under some circumstances? Or is the logic to decide what those circumstances are not worth the trouble?

"things are more like they are now than they ever have been"
"It's obvious isn't it Miller? Curiosity killed these cats!"
If you want to skip a transform in the pipeline you simply set that matrix to the identity matrix. Then it will not change your vertices.

If you send in pre transformed vertices they will not be transformed by any of the matrices. So that is a way to skip them.

- WitchLord

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Hey, thanks Witchlord! This way very helpful.

VBMaster
Yes, thank you. Your summary of matrices really helped me understand the big picture a lot better.

"things are more like they are now than they ever have been"
"It's obvious isn't it Miller? Curiosity killed these cats!"
Perhaps a book by Witchlord?
He knows his stuff and can explain it in down to earth terms.

Edited by - Gorky on September 2, 2000 9:05:50 PM

This topic is closed to new replies.

Advertisement