コード例 #1
0
        public virtual BoundingBox GetCurrentBoundingBox()
        {
            Matrix transformations = Matrix.CreateScale (Scale) * Matrix.CreateRotationY (Rotation.Y);
            BoundingBox bb = Mesh.UpdateBoundingBox (transformations);
            float modelWidth = bb.Max.X - bb.Min.X;
            float modelHeight = bb.Max.Z - bb.Min.Z;

            Collidable playerCollidable = new Collidable (
                Translation.X - (modelWidth / 2f),
                Translation.Z - (modelHeight / 2f),
                Translation.X + (modelWidth / 2f),
                Translation.Z + (modelHeight / 2f));

            return playerCollidable.Bounds;
        }
コード例 #2
0
 public TriggerZone(Collidable collidable, Action action)
 {
     this.Collision = collidable;
     this.action = action;
 }
コード例 #3
0
 public TriggerZone CreateTrigger(Collidable collidable, Action action)
 {
     return new TriggerZone (collidable, action)
     {
         ID = ++currentID
     };
 }
コード例 #4
0
        public void MoveObject(GameObject obj, GameObject.Direction direction)
        {
            Vector3 lookVector = obj.lastHeading = GetLookVectorFromDirection (direction);
            Vector3 moveAmount = (lookVector * camera.MoveOffset) * 0.9f;
            Vector3 newLocation = CurrentLevel.CurrentCharacter.Translation + moveAmount;

            // Get data needed for the four corners
            BoundingBox bb = CurrentLevel.UpdateBoundingBox (CurrentLevel.CurrentCharacter.Mesh, Matrix.CreateScale(CurrentLevel.CurrentCharacter.Scale));
            float modelWidth = bb.Max.X - bb.Min.X;
            float modelHeight = bb.Max.Z - bb.Min.Z;
            if (obj is PlayerObject)
            {
                PlayerObject po = obj as PlayerObject;
                Vector3 pos, neg;
                switch (direction)
                {
                    case GameObject.Direction.North:
                        po.SphereRotation.X += camera.MoveOffset;

                        pos = new Vector3(0.0f, 0.0f, 0.0f);
                        neg = new Vector3(0.0f, 0.0f, 0.0f);
                        if((pos - po.Rotation).Length() < (neg - po.Rotation).Length())
                            po.Rotation = Vector3.SmoothStep(po.Rotation, pos, 0.05f);
                        else
                            po.Rotation = Vector3.SmoothStep(po.Rotation, neg, 0.05f);
                        break;
                    case GameObject.Direction.South:
                        po.SphereRotation.X -= camera.MoveOffset;

                        pos = new Vector3(0.0f, MathHelper.ToRadians(180.0f), 0.0f);
                        neg = new Vector3(0.0f, -MathHelper.ToRadians(180.0f), 0.0f);
                        if((pos - po.Rotation).Length() < (neg - po.Rotation).Length())
                            po.Rotation = Vector3.SmoothStep(po.Rotation, pos, 0.05f);
                        else
                            po.Rotation = Vector3.SmoothStep(po.Rotation, neg, 0.05f);
                        break;
                    case GameObject.Direction.East:
                        po.SphereRotation.Z -= camera.MoveOffset;

                        po.Rotation = Vector3.SmoothStep(po.Rotation, new Vector3(0.0f, MathHelper.ToRadians(90.0f), 0.0f), 0.05f);
                        break;
                    case GameObject.Direction.West:
                        po.SphereRotation.Z += camera.MoveOffset;

                        po.Rotation = Vector3.SmoothStep(po.Rotation, new Vector3(0.0f, MathHelper.ToRadians(-90.0f), 0.0f), 0.05f);
                        break;
                    default:
                        break;
                }
            }

            // Reenable this!
               // Vector2 collisionLocation = CurrentLevel.WorldToTexel (newLocation);

            Collidable playerCollidable = new Collidable (
                newLocation.X - (modelWidth / 2f),
                newLocation.Z - (modelHeight / 2f),
                newLocation.X + (modelWidth / 2f),
                newLocation.Z + (modelHeight / 2f));

            Collidable sourceCollidable = new Collidable (
                 CurrentLevel.CurrentCharacter.Translation.X - (modelWidth / 2f),
                 CurrentLevel.CurrentCharacter.Translation.Z - (modelHeight / 2f),
                 CurrentLevel.CurrentCharacter.Translation.X + (modelWidth / 2f),
                 CurrentLevel.CurrentCharacter.Translation.Z + (modelHeight / 2f));

            foreach (Collidable collideGeometry in CurrentLevel.CollisionGeometry)
            {
                if (collideGeometry.Bounds.Intersects (playerCollidable.Bounds))
                {
                    if (collideGeometry.Dense)
                        return;
                }
            }

            if (CheckInteractables (CurrentLevel.CurrentCharacter, ref playerCollidable.Bounds, ref sourceCollidable.Bounds, lookVector))
                return;

            if (CurrentLevel.CurrentCharacter != null)
                CurrentLevel.CurrentCharacter.Translation = newLocation;
        }