• Advertisement
Sign in to follow this  

[.net] My models are depth perception handicapped!

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

For my own learning experience, I'm writing my own Managed DirectX 9 game engine. Things are going pretty well, the only problem is all the models I render are "inverted" or look like cut-out models. Any ideas on why this would be? The models I'm seeing as inverted are both external .x files, as well as DirectX primitives, such as Mesh.Sphere(...). I'd appreciate any insight on this! [Edited by - Swamii on September 4, 2005 10:35:03 PM]

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Sounds like a problem with normals to me.

Share this post


Link to post
Share on other sites
I didn't change the cull mode. Do I need to?

My gut reaction was that the normals of the models were wrong, but how could they be wrong when the models are created via Managed DirectX's own methods (the Mesh.Box, Mesh.Cylinder, etc.)?

Is there something with my camera/viewport settings I need to do? Currently, when I go to "render" the camera, I do the following


device.Transform.Projection = Matrix.PerspectiveFovLH(fieldOfView, device.Viewport.Width / device.Viewport.Height, frontClipping, backClipping);

device.Transform.View = Matrix.LookAtLH(camPosition, camOrientation, camOrientationUp);


If it'd help, I can post screenshots or post my actual project.

Share this post


Link to post
Share on other sites
Ok, after more investigation (after playing with the cull mode), I've realized that what I'm seeing is not inverted models. So ignore the post title. :-)

Instead, what I'm seeing is depth problems: Model A is in front of Model B. Yet when rendered, I see model B rendered as though it is in front of the other model.

Here is a screenshot of what I'm seeing:

Share this post


Link to post
Share on other sites
Can you explain that a bit further? What do I need to do to get depth buffering working correctly? Currently, I just draw all models in the scene, not in any particular order...

Share this post


Link to post
Share on other sites
for depth buffering all you need is the following in your PresentParameters before you create your device. That should take care of it.


presentParams.AutoDepthStencilFormat = DepthFormat.D16;
presentParams.EnableAutoDepthFormatStencil = true;

Share this post


Link to post
Share on other sites
Ok, I've added the following lines to my code before creation of the device.

presentParams.AutoDepthStencilFormat = DepthFormat.D16;
presentParams.EnableAutoDepthFormatStencil = true;


With only those modifications, my models now look totally screwed! :-p Have a look, rendering the same model as shown above, I get the following:



Any ideas what could be wrong now? Cull modes, depth testing, or anything?

Share this post


Link to post
Share on other sites
Looks like you aren't clearing the depth buffer. You do it with the clear function at the same time you clear the display, just by using | to binary OR the Zbuffer flag to the Target flag.

Share this post


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

  • Advertisement