Example #1
0
    /// <summary>
    /// Called every step of the program to listen to input commands for various features
    /// </summary>
    public override void Update()
    {
        //If the reset button is held down after a certain amount of time, then go into change spawnpoint mode (reset spawnpoint feature)
        //Otherwise, reset the robot normally (quick reset feature)
        if (!activeRobot.IsResetting)
        {
            if (Input.GetKeyDown(KeyCode.U))
            {
                LoadRobot(robotPath);
            }
            if (Input.GetKeyDown(KeyCode.Y))
            {
                SwitchActiveRobot();
            }
        }

        // Toggles between the different camera states if the camera toggle button is pressed
        if ((InputControl.GetButtonDown(Controls.buttons[0].cameraToggle)))
        {
            if (dynamicCameraObject.activeSelf && DynamicCamera.MovingEnabled)
            {
                dynamicCamera.ToggleCameraState(dynamicCamera.cameraState);
            }
        }

        // Switches to replay mode
        if (!activeRobot.IsResetting && Input.GetKeyDown(KeyCode.Tab))
        {
            contactPoints.Add(null);
            StateMachine.Instance.PushState(new ReplayState(fieldPath, robotPath, contactPoints, Trackers));
        }

        UpdateTrackers();
    }
Example #2
0
        /// <summary>
        /// Called every step of the program to listen to input commands for various features
        /// </summary>
        public override void Update()
        {
            if (ActiveRobot == null)
            {
                return;
            }

            // Toggles between the different camera states if the camera toggle button is pressed
            if ((InputControl.GetButtonDown(Controls.buttons[0].cameraToggle)))
            {
                if (DynamicCameraObject.activeSelf && DynamicCamera.ControlEnabled)
                {
                    dynamicCamera.ToggleCameraState(dynamicCamera.ActiveState);
                }
            }
        }
Example #3
0
        /// <summary>
        /// Called every step of the program to listen to input commands for various features
        /// </summary>
        public override void Update()
        {
            if (ActiveRobot == null)
            {
                AppModel.ErrorToMenu("ROBOT_SELECT|Robot instance not valid.");
                return;
            }

            if (ActiveRobot.transform.GetChild(0).transform.position.y < -10 || ActiveRobot.transform.GetChild(0).transform.position.y > 60)
            {
                BeginRobotReset();
                EndRobotReset();
            }

            if (reset)
            {
                BeginRobotReset();
                reset = false;
            }

            //Spawn a new robot from the same path or switch active robot
            if (!ActiveRobot.IsResetting && ActiveRobot.ControlIndex == 0)
            {
                if (InputControl.GetButtonDown(Controls.Players[ActiveRobot.ControlIndex].GetButtons().duplicateRobot))
                {
                    LoadRobot(robotPath, ActiveRobot is MaMRobot);
                }
                if (InputControl.GetButtonDown(Controls.Players[ActiveRobot.ControlIndex].GetButtons().switchActiveRobot))
                {
                    SwitchActiveRobot(SpawnedRobots.IndexOf(ActiveRobot) + 1 < SpawnedRobots.Count() ? SpawnedRobots.IndexOf(ActiveRobot) + 1 : 0);
                }
            }

            // Toggles between the different camera states if the camera toggle button is pressed
            if ((InputControl.GetButtonDown(Controls.Global.GetButtons().cameraToggle)) &&
                DynamicCameraObject.activeSelf && DynamicCamera.ControlEnabled)
            {
                dynamicCamera.ToggleCameraState(dynamicCamera.ActiveState);
            }

            // Switches to replay mode
            if (!ActiveRobot.IsResetting && InputControl.GetButtonDown(Controls.Global.GetButtons().replayMode))
            {
                CollisionTracker.ContactPoints.Add(null);
                StateMachine.PushState(new ReplayState(fieldPath, CollisionTracker.ContactPoints));
            }
        }
Example #4
0
        /// <summary>
        /// Called every step of the program to listen to input commands for various features
        /// </summary>
        public override void Update()
        {
            if (ActiveRobot == null)
            {
                AppModel.ErrorToMenu("Robot instance not valid.");
                return;
            }

            if (reset)
            {
                BeginRobotReset();
                reset = false;
            }

            //Spawn a new robot from the same path or switch active robot
            if (!ActiveRobot.IsResetting && ActiveRobot.ControlIndex == 0)
            {
                if (InputControl.GetButtonDown(Controls.buttons[ActiveRobot.ControlIndex].duplicateRobot))
                {
                    LoadRobot(robotPath, ActiveRobot is MaMRobot);
                }
                if (InputControl.GetButtonDown(Controls.buttons[ActiveRobot.ControlIndex].switchActiveRobot))
                {
                    SwitchActiveRobot();
                }
            }

            // Toggles between the different camera states if the camera toggle button is pressed
            if ((InputControl.GetButtonDown(Controls.buttons[0].cameraToggle)) &&
                DynamicCameraObject.activeSelf && DynamicCamera.ControlEnabled)
            {
                dynamicCamera.ToggleCameraState(dynamicCamera.ActiveState);
            }

            // Switches to replay mode
            if (!ActiveRobot.IsResetting && InputControl.GetButtonDown(Controls.buttons[ActiveRobot.ControlIndex].replayMode))
            {
                CollisionTracker.ContactPoints.Add(null);
                StateMachine.PushState(new ReplayState(fieldPath, CollisionTracker.ContactPoints));
            }
        }
Example #5
0
    /// <summary>
    /// Called every step of the program to listen to input commands for various features
    /// </summary>
    public override void Update()
    {
        if (ActiveRobot == null)
        {
            AppModel.ErrorToMenu("Robot instance not valid.");
            return;
        }

        //Spawn a new robot from the same path or switch active robot
        if (!ActiveRobot.IsResetting)
        {
            if (Input.GetKeyDown(KeyCode.U) && !MixAndMatchMode.setPresetPanelOpen)
            {
                LoadRobot(robotPath, ActiveRobot.RobotIsMixAndMatch);
            }
            if (Input.GetKeyDown(KeyCode.Y))
            {
                SwitchActiveRobot();
            }
        }

        // Toggles between the different camera states if the camera toggle button is pressed
        if ((InputControl.GetButtonDown(Controls.buttons[0].cameraToggle)) && !MixAndMatchMode.setPresetPanelOpen)
        {
            if (DynamicCameraObject.activeSelf && DynamicCamera.MovingEnabled)
            {
                dynamicCamera.ToggleCameraState(dynamicCamera.cameraState);
            }
        }

        // Switches to replay mode
        if (!ActiveRobot.IsResetting && Input.GetKeyDown(KeyCode.Tab))
        //if (!ActiveRobot.IsResetting && InputControl.GetButtonDown(Controls.buttons[controlIndex].replayMode))
        {
            CollisionTracker.ContactPoints.Add(null);
            StateMachine.Instance.PushState(new ReplayState(fieldPath, CollisionTracker.ContactPoints));
        }
    }
Example #6
0
        /// <summary>
        /// Updates the positions and rotations of each tracker's parent object according to the replay time.
        /// </summary>
        public override void LateUpdate()
        {
            if (dynamicCamera == null)
            {
                dynamicCamera = UnityEngine.Object.FindObjectOfType <DynamicCamera>();
                camera        = dynamicCamera.GetComponent <Camera>();
            }

            if (InputControl.GetButtonDown(Controls.buttons[0].cameraToggle))
            {
                dynamicCamera.ToggleCameraState(dynamicCamera.cameraState);
            }

            if (firstFrame)
            {
                firstFrame = false;
            }
            else if (Input.GetKeyDown(KeyCode.Space))
            {
                if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl))
                {
                    rewindTime   = Tracker.Lifetime;
                    playbackMode = PlaybackMode.Play;
                }
                else
                {
                    switch (playbackMode)
                    {
                    case PlaybackMode.Paused:
                        if (rewindTime == 0f)
                        {
                            rewindTime = Tracker.Lifetime;
                        }
                        playbackMode = PlaybackMode.Play;
                        break;

                    case PlaybackMode.Play:
                    case PlaybackMode.Rewind:
                        playbackMode = PlaybackMode.Paused;
                        break;
                    }
                }
            }

            switch (playbackMode)
            {
            case PlaybackMode.Rewind:
                rewindTime += Time.deltaTime;
                break;

            case PlaybackMode.Play:
                rewindTime -= Time.deltaTime;
                break;
            }

            if (Input.GetKey(KeyCode.LeftArrow))
            {
                rewindTime  += Time.deltaTime * (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl) ? 0.05f : 0.25f);
                playbackMode = PlaybackMode.Paused;
            }

            if (Input.GetKey(KeyCode.RightArrow))
            {
                rewindTime  -= Time.deltaTime * (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl) ? 0.05f : 0.25f);
                playbackMode = PlaybackMode.Paused;
            }

            if (rewindTime < 0.0f)
            {
                rewindTime   = 0.0f;
                playbackMode = PlaybackMode.Paused;
            }
            else if (rewindTime > Tracker.Lifetime)
            {
                rewindTime   = Tracker.Lifetime;
                playbackMode = PlaybackMode.Paused;
            }

            foreach (Tracker t in trackers)
            {
                float replayTime   = RewindFrame;
                int   currentIndex = (int)Math.Floor(replayTime);

                StateDescriptor lowerState = t.States[currentIndex];
                StateDescriptor upperState = currentIndex < t.States.Length - 1 ? t.States[currentIndex + 1] : lowerState;

                float percent = replayTime - currentIndex;

                BRigidBody rb = t.GetComponent <BRigidBody>();

                if (!rb.GetCollisionObject().IsActive)
                {
                    rb.GetCollisionObject().Activate();
                }

                rb.SetPosition(BulletSharp.Math.Vector3.Lerp(lowerState.Position, upperState.Position, percent).ToUnity());
                rb.SetRotation(BulletSharp.Math.Matrix.Lerp(lowerState.Rotation, upperState.Rotation, percent).GetOrientation().ToUnity());
            }
        }
Example #7
0
        /// <summary>
        /// Updates the positions and rotations of each tracker's parent object according to the replay time.
        /// </summary>
        public override void Update()
        {
            if (dynamicCamera == null)
            {
                dynamicCamera = UnityEngine.Object.FindObjectOfType <DynamicCamera>();
                camera        = dynamicCamera.GetComponent <Camera>();
            }

            if (InputControl.GetButtonDown(Controls.buttons[0].cameraToggle))
            {
                dynamicCamera.ToggleCameraState(dynamicCamera.cameraState);
            }

            if (firstFrame)
            {
                firstFrame = false;
            }
            else if (Input.GetKeyDown(KeyCode.Space))
            {
                if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl))
                {
                    rewindTime   = Tracker.Lifetime;
                    playbackMode = PlaybackMode.Play;
                }
                else
                {
                    switch (playbackMode)
                    {
                    case PlaybackMode.Paused:
                        if (rewindTime == 0f)
                        {
                            rewindTime = Tracker.Lifetime;
                        }
                        playbackMode = PlaybackMode.Play;
                        break;

                    case PlaybackMode.Play:
                    case PlaybackMode.Rewind:
                        playbackMode = PlaybackMode.Paused;
                        break;
                    }
                }
            }

            switch (playbackMode)
            {
            case PlaybackMode.Rewind:
                rewindTime += Time.smoothDeltaTime * playbackSpeed;
                break;

            case PlaybackMode.Play:
                rewindTime -= Time.smoothDeltaTime * playbackSpeed;
                break;
            }

            if (Input.GetKey(KeyCode.LeftArrow))
            {
                rewindTime  += Time.smoothDeltaTime * 0.25f;
                playbackMode = PlaybackMode.Paused;
            }

            if (Input.GetKey(KeyCode.RightArrow))
            {
                rewindTime  -= Time.smoothDeltaTime * 0.25f;
                playbackMode = PlaybackMode.Paused;
            }

            if (rewindTime < 0.0f)
            {
                rewindTime   = 0.0f;
                playbackMode = PlaybackMode.Paused;
            }
            else if (rewindTime > Tracker.Lifetime)
            {
                rewindTime   = Tracker.Lifetime;
                playbackMode = PlaybackMode.Paused;
            }

            foreach (Tracker t in trackers)
            {
                float replayTime   = RewindFrame;
                int   currentIndex = (int)Math.Floor(replayTime);

                StateDescriptor lowerState = t.States[currentIndex];
                StateDescriptor upperState = currentIndex < t.States.Length - 1 ? t.States[currentIndex + 1] : lowerState;

                float percent = replayTime - currentIndex;

                RigidBody r = (RigidBody)t.GetComponent <BRigidBody>().GetCollisionObject();

                if (!r.IsActive)
                {
                    r.Activate();
                }

                BulletSharp.Math.Matrix worldTransform = r.WorldTransform;

                worldTransform.Origin = BulletSharp.Math.Vector3.Lerp(lowerState.Position, upperState.Position, percent);
                worldTransform.Basis  = BulletSharp.Math.Matrix.Lerp(lowerState.Rotation, upperState.Rotation, percent);

                r.WorldTransform = worldTransform;
            }

            if (Input.GetKeyDown(KeyCode.Tab))
            {
                StateMachine.Instance.PopState();
            }
        }