Inheritance: MonoBehaviour
Example #1
0
 static Func <string, string> InverseRotateBasedOn(char x)
 {
     return(s => {
         var rotations = LeftRotationsToInvertBasedOnIndex[s.IndexOf(x)];
         return RotateLeft(rotations)(s);
     });
 }
Example #2
0
    public static List <IMovement> parseMovementList(string line)
    {
        List <IMovement> movementList = new List <IMovement>();

        foreach (var item in line)
        {
            IMovement movement;

            switch (item)
            {
            case 'L':
                movement = new RotateLeft();
                break;

            case 'R':
                movement = new RotateRight();
                break;

            case 'F':
                movement = new MoveForward();
                break;

            case ' ':
                continue;

            default:
                throw new Exception("Invalid movement");
            }

            movementList.Add(movement);
        }

        return(movementList);
    }
Example #3
0
        private void UpdateCameraInput()
        {
            if (MouseCondition.Scrolled())
            {
                int scrollDelta = MouseCondition.ScrollDelta;
                _targetExp = MathHelper.Clamp(_targetExp - scrollDelta * _expDistance, _maxExp, _minExp);
            }

            if (RotateLeft.Pressed())
            {
                _targetRotation += MathHelper.Pi / 8f;
            }
            if (RotateRight.Pressed())
            {
                _targetRotation -= MathHelper.Pi / 8f;
            }

            _mouseWorld = Vector2.Transform(InputHelper.NewMouse.Position.ToVector2(), Matrix.Invert(GetView()));

            if (CameraDrag.Pressed())
            {
                _dragAnchor = _mouseWorld;
                _isDragged  = true;
            }
            if (_isDragged && CameraDrag.HeldOnly())
            {
                _xy        += _dragAnchor - _mouseWorld;
                _mouseWorld = _dragAnchor;
            }
            if (_isDragged && CameraDrag.Released())
            {
                _isDragged = false;
            }
        }
Example #4
0
        private void leftToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IImageFilter filter = new RotateLeft();
            var          img    = pictureBox1.Image;

            filter.Perform(img);
            pictureBox1.Image = img;
        }
Example #5
0
        public void FirstTry_Basic_Test()
        {
            int[] array             = new int[] { 1, 2, 3, 4, 5 };
            int   numberOfRotations = 4;

            array = new RotateLeft().FirstTry(array, numberOfRotations);

            Assert.Equal(new int[] { 5, 1, 2, 3, 4 }, array);
        }
Example #6
0
        public void SecondTry_Other_Test()
        {
            int[] array             = new int[] { 1, 2, 3, 4, 5 };
            int   numberOfRotations = 2;

            array = new RotateLeft().SecondTry(array, numberOfRotations);

            Assert.Equal(new int[] { 3, 4, 5, 1, 2 }, array);
        }
Example #7
0
    public void RotateLeftRobot(float orientation, float expect)
    {
        Robot robot = new Robot(8, 2, orientation);

        RotateLeft movement = new RotateLeft();

        movement.Move(robot);

        Assert.Equal(expect, robot.orientation);
    }
Example #8
0
        public void RotateLeft(int xCoordinate, int yCoordinate, char direction, string expected)
        {
            CompassDirection?compassDirection   = new DirectionFactory().Get(direction);
            IPosition        robotStartPosition = new Position(xCoordinate, yCoordinate, compassDirection);

            IRobotController robotController  = new RobotController(robotStartPosition, pluto);
            IRotate          robotCommand     = new RotateLeft();
            IPosition        robotEndPosition = robotController.Move(robotCommand);

            Assert.AreEqual(expected, robotEndPosition.ToString());
        }
Example #9
0
        public void RotateLeft_Test(int[] srcArr, int rotations, int[] expected)
        {
            var result = RotateLeft.rotLeft(srcArr, rotations);

            Assert.AreEqual(expected.Length, result.Length);

            for (var i = 0; i < result.Length; i++)
            {
                Assert.AreEqual(expected[i], result[i]);
            }
        }
Example #10
0
    public void EnableAiScript(string in_scriptName)
    {
        _RotateRight = GetComponent<RotateRight>();
        _RotateLeft = GetComponent<RotateLeft>();

        if (in_scriptName.Equals("Right", StringComparison.InvariantCultureIgnoreCase) && _RotateRight != null)
        {
            _RotateRight.enabled = true;
            _RotateRight.Speed = Speed;
        }
        if (in_scriptName.Equals("Left", StringComparison.InvariantCultureIgnoreCase) && _RotateLeft != null)
        {
            _RotateLeft.enabled = true;
            _RotateLeft.Speed = Speed;
        }

    }
Example #11
0
        public void FourLeftRotations_ReturnsToTheSamePositionAndDirection(
            int posX,
            int posY,
            int dirX,
            int dirY)
        {
            this.plain.IsPositionValid(Arg.Any <int>(), Arg.Any <int>()).Returns(true);
            var rover   = new Rover(this.plain, (posX, posY), (dirX, dirY));
            var command = new RotateLeft();

            command.Execute(rover);
            command.Execute(rover);
            command.Execute(rover);
            command.Execute(rover);
            Assert.Equal(posX, rover.Position.X);
            Assert.Equal(posY, rover.Position.Y);
            Assert.Equal(dirX, rover.Direction.X);
            Assert.Equal(dirY, rover.Direction.Y);
        }
    private void SetupDefaultBindings()
    {
        MoveLeft.AddDefaultBinding(InputControlType.LeftStickLeft);
        MoveLeft.AddDefaultBinding(InputControlType.DPadLeft);
        MoveRight.AddDefaultBinding(InputControlType.LeftStickRight);
        MoveRight.AddDefaultBinding(InputControlType.DPadRight);

        Jump.AddDefaultBinding(InputControlType.LeftBumper);

        IgniteJetpack.AddDefaultBinding(InputControlType.LeftTrigger);
        RotateLeft.AddDefaultBinding(InputControlType.LeftStickLeft);
        RotateRight.AddDefaultBinding(InputControlType.LeftStickRight);

        Shoot.AddDefaultBinding(InputControlType.RightTrigger);

        AimUp.AddDefaultBinding(InputControlType.RightStickUp);
        AimDown.AddDefaultBinding(InputControlType.RightStickDown);
        AimLeft.AddDefaultBinding(InputControlType.RightStickLeft);
        AimRight.AddDefaultBinding(InputControlType.RightStickRight);
    }
Example #13
0
        void ReleaseDesignerOutlets()
        {
            if (ImageView != null)
            {
                ImageView.Dispose();
                ImageView = null;
            }

            if (LoadButton != null)
            {
                LoadButton.Dispose();
                LoadButton = null;
            }

            if (RotateLeft != null)
            {
                RotateLeft.Dispose();
                RotateLeft = null;
            }

            if (RotateRight != null)
            {
                RotateRight.Dispose();
                RotateRight = null;
            }

            if (SaveButton != null)
            {
                SaveButton.Dispose();
                SaveButton = null;
            }

            if (SettingsButton != null)
            {
                SettingsButton.Dispose();
                SettingsButton = null;
            }
        }
Example #14
0
 public bool GetRotateLeft(HandSide hand)
 {
     return(RotateLeft.GetStateDown(hand == HandSide.Left?SteamVR_Input_Sources.LeftHand: SteamVR_Input_Sources.RightHand));
 }
    // Method for handling global events in the Unity Editor.
    static void GlobalEventHandler()
    {
        // If a reference to the rig exists.
        if (Rig != null)
        {
            // Set Rig movements based on key combinations.
            Rig.MovingForward  = MoveForward.KeyCombinationDown();
            Rig.MovingBackward = MoveBackward.KeyCombinationDown();
            Rig.MovingLeft     = MoveLeft.KeyCombinationDown();
            Rig.MovingRight    = MoveRight.KeyCombinationDown();
            Rig.RotatingLeft   = RotateLeft.KeyCombinationDown();
            Rig.RotatingRight  = RotateRight.KeyCombinationDown();
            Rig.LookingUp      = LookUp.KeyCombinationDown();
            Rig.LookingDown    = LookDown.KeyCombinationDown();
        }

        // If a reference to the lefthand controller exists.
        if (LeftHandController != null)
        {
            // Presses up on the primary 2D axis for the lefthand controller.
            if (LeftAxisUp.KeyCombinationClick())
            {
                LeftHandController.Primary2DAxis.TouchAxisUp();
            }

            // Presses down on the primary 2D axis for the lefthand controller.
            if (LeftAxisDown.KeyCombinationClick())
            {
                LeftHandController.Primary2DAxis.TouchAxisDown();
            }

            // Presses left on the primary 2D axis for the lefthand controller.
            if (LeftAxisLeft.KeyCombinationClick())
            {
                LeftHandController.Primary2DAxis.TouchAxisLeft();
            }

            // Presses right on the primary 2D axis for the lefthand controller.
            if (LeftAxisRight.KeyCombinationClick())
            {
                LeftHandController.Primary2DAxis.TouchAxisRight();
            }

            // Touches or untouhces the primary 2D axis for the lefthand controller.
            if (LeftAxisTouch.KeyCombinationClick())
            {
                LeftHandController.Primary2DAxis.Touch = !LeftHandController.Primary2DAxis.Touch;
            }

            // Clicks or unclicks the primary 2D axis for the lefthand controller.
            if (LeftAxisClick.KeyCombinationClick())
            {
                LeftHandController.Primary2DAxis.Click = !LeftHandController.Primary2DAxis.Click;
            }

            // Clicks or unclicks the trigger button for the lefthand controller.
            if (LeftTriggerButton.KeyCombinationClick())
            {
                LeftHandController.Trigger.Button = !LeftHandController.Trigger.Button;
            }

            // Clicks or unclicks the grip button for the lefthand controller.
            if (LeftGripButton.KeyCombinationClick())
            {
                LeftHandController.Grip.Button = !LeftHandController.Grip.Button;
            }

            // Clicks or unclicks the primary button for the lefthand controller.
            if (LeftPrimaryButton.KeyCombinationClick())
            {
                LeftHandController.PrimaryButton.Button = !LeftHandController.PrimaryButton.Button;
            }
        }

        // If a reference to the righthand controller exists.
        if (RightHandController != null)
        {
            // Presses up on the primary 2D axis for the righthand controller.
            if (RightAxisUp.KeyCombinationClick())
            {
                RightHandController.Primary2DAxis.TouchAxisUp();
            }

            // Presses down on the primary 2D axis for the righthand controller.
            if (RightAxisDown.KeyCombinationClick())
            {
                RightHandController.Primary2DAxis.TouchAxisDown();
            }

            // Presses left on the primary 2D axis for the righthand controller.
            if (RightAxisLeft.KeyCombinationClick())
            {
                RightHandController.Primary2DAxis.TouchAxisLeft();
            }

            // Presses right on the primary 2D axis for the righthand controller.
            if (RightAxisRight.KeyCombinationClick())
            {
                RightHandController.Primary2DAxis.TouchAxisRight();
            }

            // Touches or untouhces the primary 2D axis for the righthand controller.
            if (RightAxisTouch.KeyCombinationClick())
            {
                RightHandController.Primary2DAxis.Touch = !RightHandController.Primary2DAxis.Touch;
            }

            // Clicks or unclicks the primary 2D axis for the righthand controller.
            if (RightAxisClick.KeyCombinationClick())
            {
                RightHandController.Primary2DAxis.Click = !RightHandController.Primary2DAxis.Click;
            }

            // Clicks or unclicks the trigger button for the righthand controller.
            if (RightTriggerButton.KeyCombinationClick())
            {
                RightHandController.Trigger.Button = !RightHandController.Trigger.Button;
            }

            // Clicks or unclicks the grip button for the righthand controller.
            if (RightGripButton.KeyCombinationClick())
            {
                RightHandController.Grip.Button = !RightHandController.Grip.Button;
            }

            // Clicks or unclicks the primary button for the righthand controller.
            if (RightPrimaryButton.KeyCombinationClick())
            {
                RightHandController.PrimaryButton.Button = !RightHandController.PrimaryButton.Button;
            }
        }
    }
Example #16
0
        private void UpdateCameraInput(Camera c, int index)
        {
            int x = InputHelper.NewMouse.X;
            int y = InputHelper.NewMouse.Y;

            if (!_isDragged && CameraContains(c, x, y) || _isDragged && _currentCamera == index)
            {
                _currentCamera = index;
                if (MouseCondition.Scrolled())
                {
                    int scrollDelta = MouseCondition.ScrollDelta;
                    SetZoom(c, MathF.Min(MathF.Max(GetZoom(c) - scrollDelta * 0.001f, 0.2f), 10f));
                }

                if (RotateLeft.Pressed())
                {
                    c.Rotation += MathHelper.PiOver4;
                }
                if (RotateRight.Pressed())
                {
                    c.Rotation -= MathHelper.PiOver4;
                }

                if (Forward.Held())
                {
                    c.Z -= 0.1f;
                }
                if (Backward.Held())
                {
                    c.Z += 0.1f;
                }

                if (IncreaseFocal.Held())
                {
                    var temp = c.Z / c.FocalLength;

                    c.FocalLength += 0.01f;

                    c.Z = c.FocalLength * temp;
                }
                if (DecreaseFocal.Held())
                {
                    var temp = c.Z / c.FocalLength;

                    c.FocalLength -= 0.01f;

                    c.Z = c.FocalLength * temp;
                }

                if (ResetCamera.Pressed())
                {
                    c.Scale       = new Vector2(1f, 1f);
                    c.XY          = new Vector2(0f, 0f);
                    c.Z           = 2f;
                    c.Rotation    = 0f;
                    c.FocalLength = 1f;
                }

                _mouseWorld = c.ScreenToWorld(x, y);

                if (CameraDrag.Pressed())
                {
                    _dragAnchor = _mouseWorld;
                    _isDragged  = true;
                }
                if (_isDragged && CameraDrag.HeldOnly())
                {
                    c.XY       += _dragAnchor - _mouseWorld;
                    _mouseWorld = _dragAnchor;
                }
                if (_isDragged && CameraDrag.Released())
                {
                    _isDragged = false;
                }
            }
        }
 public Playercontroller()
 {
     this.MoveForwardCommand = new MoveForward(this);
     this.RotateLeftCommand  = new RotateLeft(this);
     this.RotateRightCommand = new RotateRight(this);
 }
Example #18
0
    // Update is called once per frame
    void Update()
    {
        // Set opacities initially to 0
        Color UnintrusiveLeftColor = UnintrusiveLeft.GetComponent <MeshRenderer>().material.color;

        UnintrusiveLeft.GetComponent <MeshRenderer>().material.color = new Color(UnintrusiveLeftColor.r, UnintrusiveLeftColor.g, UnintrusiveLeftColor.b, 0);
        Color LeftMaxColor = LeftMax.GetComponent <MeshRenderer>().material.color;

        LeftMax.GetComponent <MeshRenderer>().material.color = new Color(LeftMaxColor.r, LeftMaxColor.g, LeftMaxColor.b, 0);

        Color UnintrusiveRightColor = UnintrusiveRight.GetComponent <MeshRenderer>().material.color;

        UnintrusiveRight.GetComponent <MeshRenderer>().material.color = new Color(UnintrusiveRightColor.r, UnintrusiveRightColor.g, UnintrusiveRightColor.b, 0);
        Color RightMaxColor = RightMax.GetComponent <MeshRenderer>().material.color;

        RightMax.GetComponent <MeshRenderer>().material.color = new Color(RightMaxColor.r, RightMaxColor.g, RightMaxColor.b, 0);

        Color RotateLeftColor = RotateLeft.GetComponent <MeshRenderer>().material.color;

        RotateLeft.GetComponent <MeshRenderer>().material.color = new Color(RotateLeftColor.r, RotateLeftColor.g, RotateLeftColor.b, 0);

        Color RotateRightColor = RotateRight.GetComponent <MeshRenderer>().material.color;

        RotateRight.GetComponent <MeshRenderer>().material.color = new Color(RotateRightColor.r, RotateRightColor.g, RotateRightColor.b, 0);

        if (solution == Solution.Panels)
        {
            float reticleDistanceLeft  = 1 - (Vector3.Distance(RotateLeft.transform.position, reticlePointer.PointerTransform.forward * reticlePointer.maxReticleDistance) - 1.75f);
            float reticleDistanceRight = 1 - (Vector3.Distance(RotateRight.transform.position, reticlePointer.PointerTransform.forward * reticlePointer.maxReticleDistance) - 1.75f);
            reticleDistanceLeft  = Mathf.Clamp(reticleDistanceLeft, 0, 0.25f) * 4;
            reticleDistanceRight = Mathf.Clamp(reticleDistanceRight, 0, 0.25f) * 4;

            if (cameraControl.intrusivePanels) // Activate "intrusive" panels
            {
                Material[] leftMats = RotateLeft.GetComponent <Renderer>().materials;
                leftMats[0] = leftOpaquePanel;
                RotateLeft.GetComponent <Renderer>().materials          = leftMats;
                RotateLeft.GetComponent <MeshRenderer>().material.color = new Color(RotateLeftColor.r, RotateLeftColor.g, RotateLeftColor.b, 0);

                Material[] rightMats = RotateRight.GetComponent <Renderer>().materials;
                rightMats[0] = rightOpaquePanel;
                RotateRight.GetComponent <Renderer>().materials          = rightMats;
                RotateRight.GetComponent <MeshRenderer>().material.color = new Color(RotateRightColor.r, RotateRightColor.g, RotateRightColor.b, 0);
            }
            else
            {
                Material[] leftMats = RotateLeft.GetComponent <Renderer>().materials;
                leftMats[0] = leftPanel;
                RotateLeft.GetComponent <Renderer>().materials          = leftMats;
                RotateLeft.GetComponent <MeshRenderer>().material.color = new Color(RotateLeftColor.r, RotateLeftColor.g, RotateLeftColor.b, 0);

                Material[] rightMats = RotateRight.GetComponent <Renderer>().materials;
                rightMats[0] = rightPanel;
                RotateRight.GetComponent <Renderer>().materials          = rightMats;
                RotateRight.GetComponent <MeshRenderer>().material.color = new Color(RotateRightColor.r, RotateRightColor.g, RotateRightColor.b, 0);
            }

            if (GetComponent <CameraControl>().gradientsOn)
            {
                // Left side
                float LeftMaxOpacity = Mathf.Clamp(RotateLeft.GetComponent <PanelBehavior>().rotationSpeed, 3, 5) - 3;
                if (!greensOff)
                {
                    UnintrusiveLeft.GetComponent <MeshRenderer>().material.color = new Color(UnintrusiveLeftColor.r, UnintrusiveLeftColor.g, UnintrusiveLeftColor.b, RotateLeft.GetComponent <PanelBehavior>().rotationSpeed * 0.2f);
                }
                LeftMax.GetComponent <MeshRenderer>().material.color = new Color(LeftMaxColor.r, LeftMaxColor.g, LeftMaxColor.b, LeftMaxOpacity);

                // Right side
                float RightMaxOpacity = Mathf.Clamp(RotateRight.GetComponent <PanelBehavior>().rotationSpeed, 3, 5) - 3;
                if (!greensOff)
                {
                    UnintrusiveRight.GetComponent <MeshRenderer>().material.color = new Color(UnintrusiveRightColor.r, UnintrusiveRightColor.g, UnintrusiveRightColor.b, RotateRight.GetComponent <PanelBehavior>().rotationSpeed * 0.2f);
                }
                RightMax.GetComponent <MeshRenderer>().material.color = new Color(RightMaxColor.r, RightMaxColor.g, RightMaxColor.b, RightMaxOpacity);
            }
            if (visiblePanels)
            {
                RotateLeft.GetComponent <MeshRenderer>().material.color = new Color(RotateLeftColor.r, RotateLeftColor.g, RotateLeftColor.b, reticleDistanceLeft);

                RotateRight.GetComponent <MeshRenderer>().material.color = new Color(RotateRightColor.r, RotateRightColor.g, RotateRightColor.b, reticleDistanceRight);
            }
        }
        else if (solution == Solution.RotationMapping)
        {
            if (prevOrigin != orientation)
            {
                origin.transform.eulerAngles = new Vector3(origin.transform.eulerAngles.x, orientation, origin.transform.eulerAngles.z);
                transform.eulerAngles        = new Vector3(transform.eulerAngles.x, orientation + Vector3.SignedAngle(transform.forward, origin.transform.forward, transform.up), transform.eulerAngles.z);
                forward = origin.transform.forward;
            }

            //Debug.Log("Head rotation: " + GvrVRHelpers.GetHeadRotation().y);
            Vector3 reticleDirection  = Vector3.Normalize(transform.position + reticlePointer.MaxPointerEndPoint);
            float   orientationAngle  = Vector3.SignedAngle(forward, transform.forward, transform.up);
            float   rotationDirection = Vector3.SignedAngle(prevOrientation, reticleDirection, transform.up);
            //Debug.Log("Orientation angle: " + orientationAngle);
            //Debug.Log("Angle: " + angle);
            //Debug.Log(transform.eulerAngles.y);

            if (orientationAngle > -rotationMappingAngle && rotationDirection < 0)
            {
                if (GvrVRHelpers.GetHeadRotation().y * 360 < rotationMappingAngle)
                {
                    transform.eulerAngles = new Vector3(transform.eulerAngles.x, orientation + GvrVRHelpers.GetHeadRotation().y * 360, transform.eulerAngles.z);
                }
            }
            else if (orientationAngle < rotationMappingAngle && rotationDirection > 0)
            {
                if (GvrVRHelpers.GetHeadRotation().y * 360 > -rotationMappingAngle)
                {
                    transform.eulerAngles = new Vector3(transform.eulerAngles.x, orientation + GvrVRHelpers.GetHeadRotation().y * 360, transform.eulerAngles.z);
                }
            }

            prevOrientation = reticleDirection;
            prevOrigin      = orientation;
        }
    }