1
\$\begingroup\$

I am learning 3D at the moment. It is going well but I am stuck on the viewing of the camera.

I have two cubes, one next to each other made up of vertices, all the faces/triangles in the cubes are clockwise vertics so that when you move around the box, only 1 or two sides are visible at once. But, here's the problem, if I look at the cubes from the right, I can see a face of the cube that is further away. Like pictured below,

enter image description here

What would be the best way to deal with this, and are there any tutorials that could help me please?

Thanks in advance

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

You can set up your graphics device to do a depth-test to compute which cube is in front of the other cube and to not show parts that should be obstructed.

To do this in XNA add this right before you draw the cubes.

GraphicsDevice.DepthStensilState = DepthStensilState.Default

Note that some XNA components, such as the SpriteBatch change your graphics device states. So you need to make sure your graphics device states are correct each frame before you draw something that depends on it.

Edit: for more info please see this excellent post by our all-time-XNA-god Shawn Hargreaves

\$\endgroup\$
1
  • \$\begingroup\$ Thank you very much for this simple piece of code. Though I will read the post from Shawn Hargreaves for more understanding :) \$\endgroup\$ Aug 1, 2014 at 22:40

You must log in to answer this question.

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