Jump to content
• Advertisement

#### Archived

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

# d3d matrix question

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

If you intended to correct an error in the post then please contact us.

## Recommended Posts

please look at the picture: Now in the top left screen I have a simple scene (ball and grid) and the ball moves arround some using two matrix transformations. I included a form that displays the data (top right). As you can see the ball''s world transformation is a rotate (y axis) and a translation (x,z) (it is based on sin/cos of tickcount). I wanted to see what the whole scene looked like (inc camera). So I made a duplicate, added the camea object and made another data window (this time set up to display the camera''s world transformation matrix). Note that the ball uses the same transformation as the top one. (the view in bottom left you see now is from (3, 1, 0) so you look to the negative x axis, positive z is right) The camera object is a simple cube with an extra line to indicate positive z axis. The camera''s world transform is the view transform of the top view, so I figured it would represent the camera''s position in 3d space. It allmost fully checks out. the camera is at (0, 0, 1) which is correct with respect to it''s transformation matrix. But take a closer look at the camera, according to the perspective view, the camera is looking away from the ball. But in the world view the ball is visible! after some animation it becomes apparent that the view is actually consistent with a camera at position (0,0,-1)? how can this be? I have moved the camera to various other places and it doesn''t make any sense... it there someting I am missing here? Does DX do something to the view transform matrix before it apply''s it to the geometry?

#### Share this post

##### Share on other sites
Advertisement
The view matrix is the inverse of the camera position/rotation matrix.

ie: If your camera was at 0,0,20, your viewmatrix would contain 0,0,-20. If you rotate your camera clockwise, your viewmatrix would contain a counterclockwise rotation.

Why is it backwards? How does it work mathematically?

Imagine you have a point at 0,0,30, and your camera at 0,0,20. The viewmatrix will have 0,0,-20. Consider what happens when you multiply your vertex that matrix... 0,0,30 becomes 0,0,10. Using the inverse of the camera position/rotation creates a matrix that moves vectors to be relative to the camera.

I know this description isn''t the best, but I hope you get the idea.

#### Share this post

##### Share on other sites
Think of it like this, perspective transforms don''t move the camera, they move the world. That''s why you need to apply inverse camera motion. The camera is always locked in position and orientation, you apply perspective transforms to move the world around it.

If the camera is pointed at an object and you want to back the camera away you would apply a forward motion perspective transform because you arn''t moving the camera forward, you are moving the world forward, away from the camera.

Make sense?

#### Share this post

##### Share on other sites
Thanks you lot... its working fine now

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
Rutin
64
2. 2
3. 3
4. 4
5. 5
• Advertisement

• 16
• 10
• 29
• 20
• 9
• ### Forum Statistics

• Total Topics
633414
• Total Posts
3011764
• ### Who's Online (See full list)

There are no registered users currently online

×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!