#### Archived

This topic is now archived and is closed to further replies.

# D3D: Moving the camera

This topic is 6681 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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

##### Share on other sites
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.

##### Share on other sites
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

##### Share on other sites
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"

##### Share on other sites
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

##### Share on other sites
Hey, thanks Witchlord! This way very helpful.

VBMaster

##### Share on other sites
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"

##### Share on other sites
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

1. 1
2. 2
Rutin
20
3. 3
khawk
16
4. 4
A4L
14
5. 5

• 11
• 16
• 26
• 10
• 11
• ### Forum Statistics

• Total Topics
633756
• Total Posts
3013707
×