public override float getPenDepth(CollisionHandler other) { if (other is SphereCollisionHandler) { return(spherePenDepth((SphereCollisionHandler)other)); } if (other is HalfSpaceCollisionHandler) { return(-other.getPenDepth(this)); } else { throw new Exception("No collision pen depth calculation for this type exists"); } }
/// <summary> /// updates objA and objB post collision over some time /// </summary> /// <param name="collisionA"></param> /// <param name="collisionB"></param> /// <param name="timeStep"></param> public static void ResolveContact(CollisionHandler collisionA, CollisionHandler collisionB, GameTime gameTime) { bool collisionVector = collisionA.DetectCollsion(collisionB); if (collisionVector) { float seperatingVelocity = collisionA.getSeperatingVelocity(collisionB); Vector3 contactNormal = collisionA.getContactNormal(collisionB); float penetrationDepth = collisionA.getPenDepth(collisionB); collisionA.updatePhysics(gameTime, contactNormal, -seperatingVelocity, penetrationDepth, collisionB.parent.mass); collisionB.updatePhysics(gameTime, -contactNormal, -seperatingVelocity, penetrationDepth, collisionA.parent.mass); } }