Пример #1
0
 private void ApplyCreationActions()
 {
     foreach (InputBindings.CreationBinding ca in WorldViewModel.Bindings.CreationBindings
              .Where(ca => ca.KeyCombo.All(k => _keyPressed(k))))
     {
         _actionState = InputBindings.ActionState.KeyAction;
         if (ca.Action == InputBindings.CreationAction.Item)
         {
             CreateEntity.Execute(null);
         }
         else if (ca.Action == InputBindings.CreationAction.Mobile)
         {
             CreateEntity.Execute(null);
         }
         else if (ca.Action == InputBindings.CreationAction.Factory)
         {
             CreateEntity.Execute(null);
         }
         else
         {
             throw new Exception("Unexpected creation binding " + ca.Action);
         }
     }
 }
 private void ApplyCreationActions()
 {
     foreach (InputBindings.CreationBinding ca in WorldViewModel.InputBindings.CreationBindings
         .Where(ca => ca.KeyCombo.All(k => _keyPressed(k))))
     {
         _actionState = InputBindings.ActionState.KeyAction;
         if (ca.Action == InputBindings.CreationAction.Item)
             CreateEntity.Execute(null);
         else if (ca.Action == InputBindings.CreationAction.Mobile)
             CreateMobile.Execute(null);
         else if (ca.Action == InputBindings.CreationAction.Factory)
             CreateFactory.Execute(null);
         else if (ca.Action == InputBindings.CreationAction.Mission)
             CreateMission.Execute(null);
         else
             throw new Exception("Unexpected creation binding " + ca.Action);
     }
 }
        private void ApplyKeyBindings(double deltaT)
        {
            int movementPerpendicular = 0;
            int movementForward = 0;
            int movementUp = 0;
            double speedModifier = 1;
            foreach (InputBindings.KeyBinding kb in WorldViewModel.InputBindings.KeyBindings
                .Where(kb => kb.KeyCombo.All(k => _keyPressed(k))))
            {
                UnFollow();

                if (kb.Action == InputBindings.KeyAction.Up)
                    movementUp++;
                else if (kb.Action == InputBindings.KeyAction.Down)
                    movementUp--;
                else if (kb.Action == InputBindings.KeyAction.Left)
                    movementPerpendicular++;
                else if (kb.Action == InputBindings.KeyAction.Right)
                    movementPerpendicular--;
                else if (kb.Action == InputBindings.KeyAction.TurnLeft)
                    Heading += deltaT * 200;
                else if (kb.Action == InputBindings.KeyAction.TurnRight)
                    Heading -= deltaT * 200;
                else if (kb.Action == InputBindings.KeyAction.TiltUp)
                    Tilt += deltaT * (AngleRangeHigh - AngleRangeLow) / 2.0;
                else if (kb.Action == InputBindings.KeyAction.TiltDown)
                    Tilt -= deltaT * (AngleRangeHigh - AngleRangeLow) / 2.0;
                else if (kb.Action == InputBindings.KeyAction.Walk)
                    speedModifier = 0.2;
                else if (kb.Action == InputBindings.KeyAction.Forward)
                    movementForward++;
                else if (kb.Action == InputBindings.KeyAction.Back)
                    movementForward--;
                else if (kb.Action == InputBindings.KeyAction.Home)
                    Home.Execute(null);
                else if (kb.Action == InputBindings.KeyAction.FollowSelected)
                    FollowSelected.Execute(null);

                else if (kb.Action == InputBindings.KeyAction.Possess)
                    PossessEntity.Execute(null);
                else if (kb.Action == InputBindings.KeyAction.Create)
                    _actionState = InputBindings.ActionState.CreateAction;

                else
                    throw new Exception("Unexpected keyboard binding " + kb.Action);
            }

            // Set Position and Rotation
            Rotation = new Quaternion(ZAxis, Heading) * new Quaternion(YAxis, -Tilt);

            if (movementPerpendicular == 0 && movementForward == 0 && movementUp == 0)
            {
                MobileState = EnumMobileState.Standing;
                return;
            }
            if (speedModifier < 1)
                MobileState = EnumMobileState.Walking;
            else
                MobileState = EnumMobileState.Running;

            var transformHeading = new Matrix3D();
            transformHeading.Rotate(new Quaternion(ZAxis, Heading));

            var changeInPosition = new Vector3D(
                movementForward * _landSpeed,
                movementPerpendicular * _landSpeed,
                movementUp * (DistanceRangeHigh - DistanceRangeLow) / 10.0);

            Position += changeInPosition * transformHeading * deltaT * speedModifier;

            if (Position.Z < DistanceRangeLow)
                Position.Z = DistanceRangeLow;
            else if (Position.Z > DistanceRangeHigh)
                Position.Z = DistanceRangeHigh;
        }
Пример #4
0
        private void ApplyKeyBindings(double deltaT)
        {
            int    movementPerpendicular = 0;
            int    movementForward       = 0;
            int    movementUp            = 0;
            double speedModifier         = 1;

            foreach (InputBindings.KeyBinding kb in WorldViewModel.Bindings.KeyBindings
                     .Where(kb => kb.KeyCombo.All(k => _keyPressed(k))))
            {
                UnFollow();

                if (kb.Action == InputBindings.KeyAction.Up)
                {
                    movementUp++;
                }
                else if (kb.Action == InputBindings.KeyAction.Down)
                {
                    movementUp--;
                }
                else if (kb.Action == InputBindings.KeyAction.Left)
                {
                    movementPerpendicular++;
                }
                else if (kb.Action == InputBindings.KeyAction.Right)
                {
                    movementPerpendicular--;
                }
                else if (kb.Action == InputBindings.KeyAction.TurnLeft)
                {
                    Heading += deltaT * 200;
                }
                else if (kb.Action == InputBindings.KeyAction.TurnRight)
                {
                    Heading -= deltaT * 200;
                }
                else if (kb.Action == InputBindings.KeyAction.TiltUp)
                {
                    Tilt += deltaT * (AngleRangeHigh - AngleRangeLow) / 2.0;
                }
                else if (kb.Action == InputBindings.KeyAction.TiltDown)
                {
                    Tilt -= deltaT * (AngleRangeHigh - AngleRangeLow) / 2.0;
                }
                else if (kb.Action == InputBindings.KeyAction.Walk)
                {
                    speedModifier = 0.2;
                }
                else if (kb.Action == InputBindings.KeyAction.Forward)
                {
                    movementForward++;
                }
                else if (kb.Action == InputBindings.KeyAction.Back)
                {
                    movementForward--;
                }
                else if (kb.Action == InputBindings.KeyAction.Home)
                {
                    Home.Execute(null);
                }
                else if (kb.Action == InputBindings.KeyAction.FollowSelected)
                {
                    FollowSelected.Execute(null);
                }

                else if (kb.Action == InputBindings.KeyAction.Possess)
                {
                    PossessEntity.Execute(null);
                }
                else if (kb.Action == InputBindings.KeyAction.Create)
                {
                    _actionState = InputBindings.ActionState.CreateAction;
                }

                else
                {
                    throw new Exception("Unexpected keyboard binding " + kb.Action);
                }
            }

            // Set Position and Rotation
            Rotation = new Quaternion(ZAxis, Heading) * new Quaternion(YAxis, -Tilt);

            if (movementPerpendicular == 0 && movementForward == 0 && movementUp == 0)
            {
                MobileState = EnumMobileState.Standing;
                return;
            }
            if (speedModifier < 1)
            {
                MobileState = EnumMobileState.Walking;
            }
            else
            {
                MobileState = EnumMobileState.Running;
            }

            var transformHeading = new Matrix3D();

            transformHeading.Rotate(new Quaternion(ZAxis, Heading));

            var changeInPosition = new Vector3D(
                movementForward * _landSpeed,
                movementPerpendicular * _landSpeed,
                movementUp * (DistanceRangeHigh - DistanceRangeLow) / 10.0);

            Position += changeInPosition * transformHeading * deltaT * speedModifier;

            if (Position.Z < DistanceRangeLow)
            {
                Position.Z = DistanceRangeLow;
            }
            else if (Position.Z > DistanceRangeHigh)
            {
                Position.Z = DistanceRangeHigh;
            }
        }