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);
        }
示例#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);
        }
 public override bool DetectCollsion(CollisionHandler other)
 {
     if (other is SphereCollisionHandler)
     {
         return(detectSphereCollision((SphereCollisionHandler)other));
     }
     else
     {
         return(false);
     }
 }
示例#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");
     }
 }
示例#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);
            }
        }
 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");
     }
 }
示例#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");
     }
 }
示例#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");
 }
 public override Vector3 getContactNormal(CollisionHandler other)
 {
     return(normal);
 }
示例#10
0
 public abstract float getSeperatingVelocity(CollisionHandler other);
示例#11
0
 public abstract float getPenDepth(CollisionHandler other);
示例#12
0
 public abstract Vector3 getContactNormal(CollisionHandler other);
示例#13
0
        //TODO:: implement this. remove from collision objects
        //public virtual void destroy();

        public abstract bool DetectCollsion(CollisionHandler other);