Пример #1
0
        /// <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);
            }
        }
Пример #2
0
 public override Vector3 getContactNormal(CollisionHandler other)
 {
     if (other is SphereCollisionHandler)
     {
         Vector3 cNorm;
         cNorm = parent.Position - other.parent.Position;
         cNorm.Normalize();
         return(cNorm);
     }
     if (other is HalfSpaceCollisionHandler)
     {
         return(other.getContactNormal(this));
     }
     else
     {
         throw new Exception("No collision handler for this type exists");
     }
 }