Hi there, I'm fairly new to 3D-stuff in XNA and unfortunately I have encountered a problem I can't find the solution for. (Don't even know what the problem is).
To cut it short: I am drawing quads in my game using:
effect.World = Matrix.Identity *
Matrix.CreateRotationX(Rotation.X) *
Matrix.CreateRotationY(Rotation.Y) *
Matrix.CreateRotationZ(Rotation.Z) *
Matrix.CreateTranslation(Position);
// Apply camera-matrixes
effect.View = viewMatrix;
effect.Projection = projectionMatrix;
graphics.VertexDeclaration = vertDec;
// Begin effect drawing
effect.Begin();
foreach (EffectPass pass in
effect.CurrentTechnique.Passes)
{
pass.Begin();
graphics.DrawUserIndexedPrimitives
<VertexPositionNormalTexture>(
PrimitiveType.TriangleList,
quad.Vertices, 0, 4,
quad.Indexes, 0, 2);
pass.End();
}
effect.End();
My effect also has these properties:
this.effect.TextureEnabled = true;
this.effect.Texture = texture;
And it works. My quad is drawn nicely and me is happy. However there is one slight problem. If one quad is behind another quad or regular model the way that determines which is drawn on top is the order that I draw them in.
Lets say I draw Quad A before Quad B, then B will be shown as on top of Quad A even if it is 40 units lesser in the Z-axis. Looks very confusing I must say! ;)
Now I haven't had any problem like this with my regular meshes, it is when primitives are involved things get this messy. The very same problem goes for drawing regular lines:
graphics.DrawUserIndexedPrimitives<VertexPositionColor>(
PrimitiveType.LineStrip,
pointList,
0, // vertex buffer offset to add to each element of the index buffer
6, // number of vertices in pointList
new short[] { 0, 1 }, // the index buffer
0, // first index element to read
1 // number of primitives to draw
So what I'm asking really is:
A) Is this normal? Should I build a special engine which decides when to draw what? I can easily work around this in my project by drawing stuff at the right time but I can imagine a game where I could not. A fps for example couldn't draw its billboards all over the place! ;)
B) If this is not normal, what could be the cause and what would be a solution/good way to debug the error.
I would appreciate any help to sort this out! :)