private bool detectSphereCollision(SphereCollisionHandler other) { float distance = Vector3.Dot(other.Position, normal) - Vector3.Dot(Position, normal); if (distance < other.Radius) { return(true); } else { return(false); } }
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"); } }
//BasicEffect basicEffect; public GOSphere(int tessilation = 20, bool colored = false, float myMass = 1.0f) { //create all required objects collisionHandler = new SphereCollisionHandler(this); //set details Position = Vector3.Zero; Colored = colored; if (colored) { CreateVerteciesColored(tessilation); } else { CreateVertecies(tessilation); } Radius = 1.0f; mass = myMass; physicsHandler.mass = myMass; }
//TODO:: make this fire an event for sound ect. private bool checkSphereCollision(SphereCollisionHandler other) { bool retVal = false; float xDiff = Math.Abs(this.Position.X - other.Position.X); float yDiff = Math.Abs(this.Position.Y - other.Position.Y); float zDiff = Math.Abs(this.Position.Z - other.Position.Z); float sumRadius = this.Radius + other.Radius; float distance = (xDiff * xDiff) + (yDiff * yDiff) + (zDiff * zDiff); distance = (float)Math.Sqrt(distance); lastDistanceCheck = distance; if (distance < sumRadius) { retVal = true; } return(retVal); }
private float spherePenDepth(SphereCollisionHandler other) { return(Radius + other.Radius - lastDistanceCheck); }