Exemplo n.º 1
0
        public override float getSeperatingVelocity(CollisionHandler other)
        {
            float   retVal;
            Vector3 distanceNormal = normal;
            Vector3 velocity       = parent.Velocity - other.parent.Velocity;

            retVal = Vector3.Dot(velocity, distanceNormal);
            return(retVal);
        }
Exemplo n.º 2
0
        public override float getSeperatingVelocity(CollisionHandler other)
        {
            float retVal;
            //TODO:: don't recalculate
            Vector3 distanceNormal = getContactNormal(other);
            Vector3 velocity       = parent.Velocity - other.parent.Velocity;

            retVal = Vector3.Dot(velocity, distanceNormal);
            return(retVal);
        }
Exemplo n.º 3
0
 public override bool DetectCollsion(CollisionHandler other)
 {
     if (other is SphereCollisionHandler)
     {
         return(detectSphereCollision((SphereCollisionHandler)other));
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 4
0
 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");
     }
 }
Exemplo n.º 5
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);
            }
        }
Exemplo n.º 6
0
 public override float getPenDepth(CollisionHandler other)
 {
     if (other is SphereCollisionHandler)
     {
         float distance = Vector3.Dot(other.Position, normal) - Vector3.Dot(Position, normal);
         SphereCollisionHandler pointerObject = (SphereCollisionHandler)other;
         return(distance - pointerObject.Radius);
     }
     if (other is HalfSpaceCollisionHandler)
     {
         throw new NotImplementedException();
     }
     else
     {
         throw new Exception("no pen depth test of this type");
     }
 }
Exemplo n.º 7
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");
     }
 }
Exemplo n.º 8
0
 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");
 }
Exemplo n.º 9
0
 public override Vector3 getContactNormal(CollisionHandler other)
 {
     return(normal);
 }
Exemplo n.º 10
0
 public abstract float getSeperatingVelocity(CollisionHandler other);
Exemplo n.º 11
0
 public abstract float getPenDepth(CollisionHandler other);
Exemplo n.º 12
0
 public abstract Vector3 getContactNormal(CollisionHandler other);
Exemplo n.º 13
0
        //TODO:: implement this. remove from collision objects
        //public virtual void destroy();

        public abstract bool DetectCollsion(CollisionHandler other);