That I had problems with drawing models?? Apparently, when the model is exported and processed in the content pipeline, all of it's meshes are positioned on 0, 0, 0 (X, Y, Z). So, if your model had a box at 1, 2, 4, when you draw it, it would draw at 0, 0, 0. So, what's the deal?? Suddenly, I discovered that they can be positioned the way you like, but you have to do something. There is an array of matrices, that will help you to do this. So, let's begin:
private Matrix[] transforms;
You will use that matrix, to alter the world matrix, and set it to the shader. Now, we need to fill it and resize it.
transforms = new Matrix[model.Bones.Count];
model.CopyAbsoluteBoneTransformsTo(transforms);
and when rendering your mesh parts, always set the new world matrix which is equal to the main world matrix multiplied with the transform. Here's a sample:
below, or see this (link)
foreach (ModelMesh modelMesh in model.Meshes)
{
effect.Parameters["World"].SetValue(transforms[modelMesh.ParentBone.Index] * Matrix.Identity);
effect.Begin();
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Begin();
foreach (ModelMeshPart meshPart in modelMesh.Parts)
{
device.VertexDeclaration = meshPart.VertexDeclaration;
device.Vertices[0].SetSource(modelMesh.VertexBuffer,
meshPart.StreamOffset, meshPart.VertexStride);
device.Textures[0] = meshMaterials[i].Texture;
device.DrawIndexedPrimitives(PrimitiveType.TriangleList,
meshPart.BaseVertex, 0, meshPart.NumVertices,
meshPart.StartIndex, meshPart.PrimitiveCount);
}
pass.Begin();
}
effect.End();
}
Note that I multiplied the transform with Matrix.Identity, you should swap that with your object matrix...
btw, you won't get another collision detection tutorial :( It's because you should do a million things besides it, and I'm too booooored to write about them :(
Sorry again
Labels: Tutorials