Jump to content
  • Advertisement
Sign in to follow this  
lglabc

When use D3DXMatrixOrthoLH, why mesh disappeared?

This topic is 4537 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 use D3DXMatrixOrthoLH to render some meshes to force them to keep their size. [As I mentioned in http://www.gamedev.net/community/forums/topic.asp?topic_id=370287] The function is as follows: D3DXMatrixOrthoLH(&matProject, width, height, 0.0f, 100000.0f); The problem is when I zoom the view, the mesh will disappear. If I change the zf to larger one, the mesh will be rendered weird. If I change the zf to smaller one, then the mesh will disappear. Why? I saw someone set the D3DXMatrixOrthoLH like this: D3DXMatrixOrthoLH(&matProject, width, height, 0.0f, 1.0f); It doesn’t work for me. Help!

Share this post


Link to post
Share on other sites
Advertisement
You need to understand what the near and far planes are actually doing. Values of 0.0f and 100000.0f are unlikely to be appropriate. The only case I can think of where they would be valid is for large scale terrain rendering.

Check out this classic. Plugging in your values generates some really odd results - in fact, it's really not too surprising you're getting unexpected results [smile]

The choice of a near/far distance is context sensitive - it depends on the size of your objects and the general scale of your world. You ideally want to choose them so that zNear is in front of the closest object to the camera and zFar is just behind the furthest object from the camera (that you actually render of course!).

Arbitrarily choosing 0.0f and 1.0f like your later example would only work if you had objects that were within 1.0 units of the camera.

Take a look at the actual matrix you're constructing:

2/w  0    0           0
0 2/h 0 0
0 0 1/(zf-zn) 0
0 0 zn/(zn-zf) 1


Your values will cause you to scale objects to 0.00001 of their Z dimension - which would pretty much flatten them [lol]

hth
Jack

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!