Example #1
0
        private void RecalculateCollisionMask()
        {
            List <ConvexCollisionMask> collisions = new List <ConvexCollisionMask>();

            switch (_collisionShape)
            {
            case CollisionShape.Capsule:
            case CollisionShape.ChamferCylinder:
            case CollisionShape.Cone:
            case CollisionShape.Cube:
            case CollisionShape.Cylinder:
            case CollisionShape.Sphere:
                throw new ApplicationException("Unsupported CollisionShape: " + _collisionShape.ToString());

            case CollisionShape.UseModel:
                collisions = GetCollisions(Visual, _modifierMatrix);
                break;

            default:
                throw new ApplicationException("Unknown CollisionShape: " + _collisionShape.ToString());
            }

            // Store it
            if (collisions.Count == 0)
            {
                //NOTE: Storing null will get intercepted, and store a NullCollision
                base.CollisionMask = null;              // I can't call this.CollisionMask because it's shadowed
            }
            else if (collisions.Count == 1)
            {
                base.CollisionMask = collisions[0];
            }
            else
            {
                base.CollisionMask = new CompoundCollision(collisions);
            }
        }
Example #2
0
        private void MoveToObject(StreamWriter stream,
                                  CollisionAPI API, CollisionShape collisionShape,
                                  CollisionShape movingShape)
        {
            stream.Write("\n\n\nEntering MoveToObject\n");
            // Create a MovingObject, and add movingShape to it
            MovingObject mo = new MovingObject();

            API.AddPartToMovingObject(mo, movingShape);

            // Move movingObject 1 foot at a time toward the sphere
            Vector3 toShape = collisionShape.center - movingShape.center;

            stream.Write(string.Format("movingShape {0}\n", movingShape.ToString()));
            stream.Write(string.Format("collisionShape {0}\nDisplacement Vector {1}\n",
                                       collisionShape.ToString(), toShape.ToString()));
            // We'll certainly get there before steps expires
            int steps = (int)Math.Ceiling(toShape.Length);
            // 1 foot step in the right direction
            Vector3 stepVector = toShape.ToNormalized();

            stream.Write(string.Format("Steps {0}, stepVector {1}\n", steps, stepVector.ToString()));
            bool hitIt = false;
            // Loop til we smack into something
            CollisionParms parms = new CollisionParms();

            for (int i = 0; i < steps; i++)
            {
                // Move 1 foot; if returns true, we hit something
                hitIt = (API.TestCollision(mo, stepVector, parms));
                stream.Write(string.Format("i = {0}, hitIt = {1}, movingShape.center = {2}\n",
                                           i, hitIt, movingShape.center.ToString()));
                if (hitIt)
                {
                    stream.Write(string.Format("collidingPart {0}\nblockingObstacle {1}\n, normPart {2}, normObstacle {3}\n",
                                               parms.part.ToString(), parms.obstacle.ToString(),
                                               parms.normPart.ToString(), parms.normObstacle.ToString()));
                    return;
                }
                stream.Write("\n");
            }
            Debug.Assert(hitIt, "Didn't hit the obstacle");
        }