Making sure I got this right.
Posted: Wed Feb 29, 2012 9:24 pm
So, if I'm not mistaken, if I'm using entity.CollisionInformation.LocalOffset I need to use a world transform of entity.CollisionInformation.WorldTransform.Matrix when rendering, right? Recently, I noticed that all my models using offset seem to be drawing without the offset, even though I am using entity.CollisionInformation.WorldTransform.Matrix and my models are all centered at the origin in the modeling program, so I wanted to make sure I wasn't forgetting something. My drawing code looks something like this:
If I am doing it right, then I can go look for the problem elsewhere. I don't remember it doing this before, so it could be caused by a number of things.
Code: Select all
private void drawSingleModel(BaseModel model, List<Texture2D> textures, string tech)
{
Matrix[] modelTransforms = new Matrix[model.Model.Bones.Count];
Matrix entityWorld = Matrix.Identity;
if(model.Ent != null)
entityWorld = model.Ent.CollisionInformation.WorldTransform.Matrix;
model.Model.CopyAbsoluteBoneTransformsTo(modelTransforms);
int i = 0;
foreach(ModelMesh mesh in model.Model.Meshes)
{
foreach(Effect currentEffect in mesh.Effects)
{
currentEffect.CurrentTechnique = currentEffect.Techniques[tech];
currentEffect.Parameters["xCamerasViewProjection"].SetValue(Camera.ViewProj);
currentEffect.Parameters["xLightsViewProjection"].SetValue(lights.ViewProjection);
if(textures != null)
currentEffect.Parameters["xTexture"].SetValue(textures[i++]);
currentEffect.Parameters["xWorld"].SetValue(modelTransforms[mesh.ParentBone.Index] * entityWorld * Camera.World);
currentEffect.Parameters["xLightPos"].SetValue(lights.LightPosition);
currentEffect.Parameters["xLightPower"].SetValue(lights.LightPower);
currentEffect.Parameters["xAmbient"].SetValue(lights.AmbientPower);
currentEffect.Parameters["xShadowMap"].SetValue(shadowMap);
currentEffect.Parameters["xCarLightTexture"].SetValue(lights.LightMap);
currentEffect.Parameters["xColor"].SetValue(lights.LightColor);
}
mesh.Draw();
}
}