d3d matrix question

Started by
2 comments, last by Egelsoft 20 years, 3 months ago
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?
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.
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?
Thanks you lot... its working fine now

This topic is closed to new replies.

Advertisement