コード例 #1
0
        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);
            }
        }
コード例 #2
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");
     }
 }
コード例 #3
0
        //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;
        }
コード例 #4
0
        //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);
        }
コード例 #5
0
 private float spherePenDepth(SphereCollisionHandler other)
 {
     return(Radius + other.Radius - lastDistanceCheck);
 }