Archived

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

Egelsoft

d3d matrix question

Recommended Posts

Egelsoft    122
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


Link to post
Share on other sites
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


Link to post
Share on other sites
dragon9    122
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


Link to post
Share on other sites