Saturday, 17 August 2013

Why draws XNA the models in the order of creation?

Why draws XNA the models in the order of creation?

I'm going to simulate the moving of cars on a road-network. First I draw
the roads with userindexedprimitives, and it works fine. After that in
specific moments I add models to the scene. These models are moving on the
road, and it seems to be okay. Looking on them from behind looks like
good, because they follow each other roughly in the order of creation. But
in front view the app draws always the last time added vehicle first, and
so on, thus they are drawn on each other, there is no cover. Perhaps it
can be recognized on the IMAGE. The effect file I'm using is THIS, and the
CurrentTechnique is the "ColoredNoShading". First I thought the problem
could be this setting, but the other possibilities are throwing exceptions
about missing vertex information (COLOR0 or NORMAL etc.) and I didn't cope
with them... perhaps the solution is very simple, just I didn't find
out...
Could someone please help me with this?
Thanks in advance
The code is based on this scheme:
private void DrawModel(Model model, Matrix world, Matrix view, Matrix
projection)
{
foreach (ModelMesh mesh in model.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
effect.World = world;
effect.View = view;
effect.Projection = projection;
}
mesh.Draw();
}
}
Related to the view and projection matrix:
viewMatrix = Matrix.CreateLookAt(new Vector3(0, 170, 0), new Vector3(0, 0,
0), new Vector3(0, 0, -1));
projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4,
graphics.GraphicsDevice.Viewport.AspectRatio, 1.0f, 30000.0f);
effect.CurrentTechnique = effect.Techniques["ColoredNoShading"];
effect.Parameters["xProjection"].SetValue(projectionMatrix);
effect.Parameters["xView"].SetValue(viewMatrix);

No comments:

Post a Comment