Jump to content
  • Advertisement

Archived

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

dragon9

Rear View Mirror

This topic is 5223 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

I''m working on a DX9 driving simulator that uses a rear view mirror. When I first set the camera up for the rear viewport I just pointed the camera facing backwards. The problem is that this isn''t what you see in a mirror. You also need to flip the image horizontaly. Anyone know how to do this? Is there some way to modify the perspective transform or is there another approach? Thanks...

Share this post


Link to post
Share on other sites
Advertisement
A -1 scale on the x axis would do it, but that can play havok with your winding order for triangles so you''ll have to remember to flip that as well.

Share this post


Link to post
Share on other sites
I am not 100% sure this will work, but its worth a try.

When calling D3DXMatrixPerspectiveFovLH, negate the aspect ratio.

e.g.

D3DXMatrixPerspectiveFovLH(
&matProj,
D3DX_PI/4,
- ((float)window_width / (float)window_height),
0.2f,
2001.0f
);

Nitzan

Share this post


Link to post
Share on other sites
I already tried using a negative aspect ratio, no luck there.

There has to be some other way to rig the perspective transform...

Share this post


Link to post
Share on other sites
Try this..

Negate the Aspect Ration, and ALSO when setting the initial view transformation, make the camera point the opposite way.


For example if your front view is:

D3DXMatrixLookAtLH(&d3d_view_matrix,&D3DXVECTOR3( 0.0f, 0.0f, 1.0f ), &D3DXVECTOR3( 0.0f, 0.0f, 0.0f ), &D3DXVECTOR3( 0.0f, 1.0f, 0.0f ));

Set the rear view to:

D3DXMatrixLookAtLH(&d3d_view_matrix,&D3DXVECTOR3( 0.0f, 0.0f, -1.0f ), &D3DXVECTOR3( 0.0f, 0.0f, 0.0f ), &D3DXVECTOR3( 0.0f, 1.0f, 0.0f ));

or vice-versa.

I converted my code from OpenGL to Direct3D, and when I was rendering it, everything was flipped horizontal (since OpenGL reverse the Z compared to Direct3D). Above is what I did to fix the problem.

Nitzan

Share this post


Link to post
Share on other sites
quote:
Original post by dragon9
I already tried using a negative aspect ratio, no luck there.

What about an actual negative scale though? Set up perspective as normal, then a negative scale on the axis you want to flip around. It *does* work, I''ve used it myself. Dunno how DX does it but you should be able to just bung your scale into the model matrix and it''ll work.

Share this post


Link to post
Share on other sites
Ok, I''ve got it working with a negative aspect ratio. Still some strange behavior though... Thanks for the help folks.

Share this post


Link to post
Share on other sites
You could always render the image from the backward-facing camera to a texture and apply it to, say, a plane mesh (for your mirror) and flip the texture coordinates on the vertices.

[edited by - __Daedalus__ on June 3, 2004 8:57:46 PM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

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!