Beispiel #1
0
 private static CollisionResult CollideWithInstance(Vector3 origin, Vector3 destination, Vector3 impulse, TrileInstance instance, QueryOptions options, float elasticity, Viewpoint viewpoint, bool invertedGravity)
 {
   CollisionResult collisionResult = new CollisionResult();
   Vector3 normal = -FezMath.Sign(impulse);
   FaceOrientation faceOrientation = FezMath.VisibleOrientation(viewpoint);
   if ((options & QueryOptions.Background) == QueryOptions.Background)
     faceOrientation = FezMath.GetOpposite(faceOrientation);
   CollisionType rotatedFace = instance.GetRotatedFace(faceOrientation);
   if (rotatedFace != CollisionType.None)
   {
     collisionResult.Destination = instance;
     collisionResult.NearestDistance = instance.Center;
     collisionResult.Response = CollisionManager.SolidCollision(normal, instance, origin, destination, impulse, elasticity);
     if (collisionResult.Response != Vector3.Zero)
       collisionResult.Collided = rotatedFace == CollisionType.AllSides || (rotatedFace == CollisionType.TopNoStraightLedge || rotatedFace == CollisionType.TopOnly) && (invertedGravity ? (double) normal.Y < 0.0 : (double) normal.Y > 0.0);
   }
   return collisionResult;
 }
Beispiel #2
0
 public CollisionResult CollidePoint(Vector3 position, Vector3 impulse, QueryOptions options, float elasticity, Viewpoint viewpoint)
 {
   CollisionResult collisionResult = new CollisionResult();
   Vector3 vector3 = position + impulse;
   TrileInstance instance = (TrileInstance) null;
   if ((options & QueryOptions.Background) != QueryOptions.None)
     instance = this.LevelManager.ActualInstanceAt(vector3);
   if (instance == null)
   {
     NearestTriles nearestTriles = this.LevelManager.NearestTrile(vector3, options, new Viewpoint?(viewpoint));
     instance = nearestTriles.Deep ?? nearestTriles.Surface;
   }
   bool invertedGravity = (double) this.GravityFactor < 0.0;
   if (instance != null)
     collisionResult = CollisionManager.CollideWithInstance(position, vector3, impulse, instance, options, elasticity, viewpoint, invertedGravity);
   if (collisionResult.Collided && (invertedGravity ? ((double) impulse.Y > 0.0 ? 1 : 0) : ((double) impulse.Y < 0.0 ? 1 : 0)) != 0)
   {
     if ((double) vector3.X % 0.25 == 0.0)
       vector3.X += 1.0 / 1000.0;
     if ((double) vector3.Z % 0.25 == 0.0)
       vector3.Z += 1.0 / 1000.0;
     TrileInstance trileInstance = this.LevelManager.ActualInstanceAt(vector3);
     CollisionType rotatedFace;
     collisionResult.ShouldBeClamped = trileInstance == null || !trileInstance.Enabled || (rotatedFace = trileInstance.GetRotatedFace(this.CameraManager.VisibleOrientation)) == CollisionType.None || rotatedFace == CollisionType.Immaterial;
   }
   return collisionResult;
 }