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); }
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); } }
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); } }
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"); } }
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"); } }
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); }
public abstract float getSeperatingVelocity(CollisionHandler other);
public abstract float getPenDepth(CollisionHandler other);
public abstract Vector3 getContactNormal(CollisionHandler other);
//TODO:: implement this. remove from collision objects //public virtual void destroy(); public abstract bool DetectCollsion(CollisionHandler other);