Collision Mesh Misaligned

Aug 13, 2012 at 3:47 PM

When using ConvexHullCollisionMove with a model and collision mesh that isn't perfectly centered to 0,0,0 (in the model's space) it would be misaligned.

Aug 14, 2012 at 5:46 PM

I went through this for a while and it took a bit to figure out what is going on, but it's all related to the object center versus the center BEPU calculates based on the mass.

I've updated the ConvexHullCollisionMove class to deal with it (probably should be more generically implemented so all shapes are dealt it).

First, I created a private member variable:

 public Vector3  _localTransform;


Then, in the constructor, I save BEPU's calculated center:

var convexHull = new ConvexHull(vertices, ParentObject.Mass);

_localTransform = convexHull.Position;

Basically, after that, you need to add and remove this value in Begin and End:

        public override void Begin()

            Entity.WorldTransform = Matrix.CreateTranslation(_localTransform * CollisionObjectScale) * CollisionObjectWorldTransform;
        /// <summary>
        /// Applies the current ISpaceObject World matrix changes to the ParentObject.
        /// </summary>
        public override void End()
            ParentObject.World =  Matrix.CreateScale(CollisionObjectScale)  * Matrix.CreateTranslation(-_localTransform * CollisionObjectScale) * Entity.WorldTransform;











Firing up with the BEPU Debug Layer showed the physics object perfectly aligned with the graphic.


Aug 16, 2012 at 9:01 PM

Thanks, I'll try that out.