XNA, how to draw two cubes standing in line parallelly?
Posted
by
user3535716
on Game Development
See other posts from Game Development
or by user3535716
Published on 2014-05-29T10:07:13Z
Indexed on
2014/05/29
22:04 UTC
Read the original article
Hit count: 311
I just got a problem with drawing two 3D cubes standing in line. In my code, I made a cube class, and in the game1 class, I built two cubes, A on the right side, B on the left side. I also setup an FPS camera in the 3D world. The problem is if I draw cube B first(Blue), and move the camera to the left side to cube B, A(Red) is still standing in front of B, which is apparently wrong.
I guess some pics can make much sense. Then, I move the camera to the other side, the situation is like: This is wrong.... From this view, the red cube, A should be behind the blue one, B....
Could somebody give me help please?
This is the draw in the Cube class
Matrix center = Matrix.CreateTranslation(
new Vector3(-0.5f, -0.5f, -0.5f));
Matrix scale = Matrix.CreateScale(0.5f);
Matrix translate = Matrix.CreateTranslation(location);
effect.World = center * scale * translate;
effect.View = camera.View;
effect.Projection = camera.Projection;
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Apply();
device.SetVertexBuffer(cubeBuffer);
RasterizerState rs = new RasterizerState();
rs.CullMode = CullMode.None;
rs.FillMode = FillMode.Solid;
device.RasterizerState = rs;
device.DrawPrimitives(
PrimitiveType.TriangleList,
0,
cubeBuffer.VertexCount / 3);
}
This is the Draw method in game1
A.Draw(camera, effect); B.Draw(camera, effect);
**
© Game Development or respective owner