/// <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); } }
public override bool DetectCollsion(CollisionHandler that) { if (that is SphereCollisionHandler) { if (checkSphereCollision((SphereCollisionHandler)that)) { return(true); } else { return(false); } } if (that is HalfSpaceCollisionHandler) { return(that.DetectCollsion(this)); } throw new ArgumentException("Spheres are not able to detect collision with this handler"); }