Page 1 of 1

Making sure I got this right.

Posted: Wed Feb 29, 2012 9:24 pm
by snoozbuster
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:

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();
            }
        }
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.

Re: Making sure I got this right.

Posted: Wed Feb 29, 2012 10:17 pm
by Norbo
if I'm using entity.CollisionInformation.LocalOffset I need to use a world transform of entity.CollisionInformation.WorldTransform.Matrix when rendering, right?
Yes, that's one way to do it.

However, if internal time stepping and state interpolation is used, that method will not be smooth as it references internal state (but it won't cause a completely missing offset). In that case, the local offset can be applied before transforming using the interpolated state to get the interpolated world state.

Re: Making sure I got this right.

Posted: Thu Mar 01, 2012 6:27 am
by snoozbuster
The offset's completely missing, so I'm a little confused there. I'll poke around elsewhere, just wanted to make sure that part is right.