1
\$\begingroup\$

How can i make my meshes be drawn taking in account which one is in from of another? i.e. if i have a mesh that is farder than another it should be drawn behind the second.

Is there a way to do this in xna that is more standardized or do i have to calculate for each mesh myself? If i have to calculate for each mesh by myself, from which point do i calculate the distance to the mesh? the camera position?

Here is how i draw them :

        Matrix[] transforms = new Matrix[gameobject.model.Bones.Count];
        gameobject.model.CopyAbsoluteBoneTransformsTo(transforms);

        foreach (ModelMesh mesh in gameobject.model.Meshes)
        {
            foreach (BasicEffect effect in mesh.Effects)
            { 
                effect.Projection = camera.projectionMatrix;
                effect.View = camera.viewMatrix;
                effect.World = transforms[mesh.ParentBone.Index] * gameobject.orientation;
           }
            mesh.Draw();
        }
\$\endgroup\$
2
  • \$\begingroup\$ Just drawing them normally should do this for you automatically. Have you actually tried doing it yet? \$\endgroup\$ Jan 18, 2012 at 11:00
  • \$\begingroup\$ i've updated the post with the draw code \$\endgroup\$
    – Alex
    Jan 18, 2012 at 11:13

1 Answer 1

2
\$\begingroup\$

Try putting this before the draw code:

GraphicsDevice.BlendState = BlendState.Opaque;
GraphicsDevice.DepthStencilState = DepthStencilState.Default;
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .