Example #1
0
        //Game and editor shares this method
        public void MoveAndRotatePlayerOrCamera()
        {
            MyCameraControllerEnum cce  = MySession.GetCameraControllerEnum();
            bool movementAllowedInPause = cce == MyCameraControllerEnum.Spectator;
            bool rotationAllowedInPause = movementAllowedInPause ||
                                          (cce == MyCameraControllerEnum.ThirdPersonSpectator && MyInput.Static.IsAnyAltKeyPressed());

            bool    allowRoll         = !MySessionComponentVoxelHand.Static.BuildMode;
            bool    allowMove         = !MySessionComponentVoxelHand.Static.BuildMode && !MyCubeBuilder.Static.IsBuildMode;
            float   rollIndicator     = allowRoll ? MyInput.Static.GetRoll() : 0;
            Vector2 rotationIndicator = MyInput.Static.GetRotation();

            VRageMath.Vector3 moveIndicator = allowMove ? MyInput.Static.GetPositionDelta() : Vector3.Zero;

            //////////////////////////////////////////////////////////////////////////////////////////////////////////////
            ////  Decide who is moving
            //////////////////////////////////////////////////////////////////////////////////////////////////////////////

            //First move control objects
            if (MySession.ControlledEntity != null)// && MySession.ControlledObject != MySession.Static.CameraController)
            {
                if (MySandboxGame.IsPaused)
                {
                    if (!movementAllowedInPause && !rotationAllowedInPause)
                    {
                        return;
                    }

                    if (!rotationAllowedInPause)
                    {
                        rotationIndicator = Vector2.Zero;
                    }
                    rollIndicator = 0.0f;
                }
                if (MySession.Static.CameraController is MySpectatorCameraController && MySpectatorCameraController.Static.SpectatorCameraMovement == MySpectatorCameraMovementEnum.UserControlled)
                {
                    MySpectatorCameraController.Static.MoveAndRotate(moveIndicator, rotationIndicator, rollIndicator);
                }
                else
                {
                    if (!MySession.Static.CameraController.IsInFirstPersonView)
                    {
                        MyThirdPersonSpectator.Static.UpdateZoom();
                    }

                    if (!MyInput.Static.IsGameControlPressed(MyControlsSpace.LOOKAROUND))
                    {
                        MySession.ControlledEntity.MoveAndRotate(moveIndicator, rotationIndicator, rollIndicator);
                    }
                    else
                    {
                        MySession.ControlledEntity.MoveAndRotate(moveIndicator, Vector2.Zero, rollIndicator);
                        if (!MySession.Static.CameraController.IsInFirstPersonView)
                        {
                            MyThirdPersonSpectator.Static.SaveSettings();
                        }
                    }
                }
            }
        }
Example #2
0
        //  Sends input (keyboard/mouse) to screen which has focus (top-most)
        public void HandleInputAfterSimulation()
        {
            if (MySession.Static != null)
            {
                bool cameraControllerMovementAllowed = MyScreenManager.GetScreenWithFocus() == MyGuiScreenGamePlay.Static && MyGuiScreenGamePlay.Static != null && !MyScreenManager.InputToNonFocusedScreens;
                bool lookAroundEnabled = MyInput.Static.IsGameControlPressed(MyControlsSpace.LOOKAROUND) || (MySession.Static.ControlledEntity != null && MySession.Static.ControlledEntity.PrimaryLookaround);

                //After respawn, the controlled object might be null
                bool shouldStopControlledObject = MySession.Static.ControlledEntity != null && (!cameraControllerMovementAllowed && m_cameraControllerMovementAllowed != cameraControllerMovementAllowed);

                bool movementAllowedInPause = MySession.Static.GetCameraControllerEnum() == MyCameraControllerEnum.Spectator ||
                                              MySession.Static.GetCameraControllerEnum() == MyCameraControllerEnum.SpectatorDelta ||
                                              MySession.Static.GetCameraControllerEnum() == MyCameraControllerEnum.SpectatorFixed;
                bool rotationAllowedInPause = movementAllowedInPause;   //GK: consider removing if in the future is not different from movementAllowed
                bool devScreenFlag          = MyScreenManager.GetScreenWithFocus() is MyGuiScreenDebugBase && !MyInput.Static.IsAnyAltKeyPressed();
                MyCameraControllerEnum cce  = MySession.Static.GetCameraControllerEnum();

                float             rollIndicator     = MyInput.Static.GetRoll();
                Vector2           rotationIndicator = MyInput.Static.GetRotation();
                VRageMath.Vector3 moveIndicator     = MyInput.Static.GetPositionDelta();

                var focusScreen = MyScreenManager.GetScreenWithFocus();

                if (MySandboxGame.IsPaused && focusScreen is MyGuiScreenGamePlay)
                {
                    if (!movementAllowedInPause && !rotationAllowedInPause)
                    {
                        return;
                    }

                    if (!movementAllowedInPause)
                    {
                        moveIndicator = VRageMath.Vector3.Zero;
                    }
                    if (!rotationAllowedInPause || devScreenFlag)
                    {
                        rollIndicator     = 0.0f;
                        rotationIndicator = Vector2.Zero;
                    }

                    MySession.Static.CameraController.Rotate(rotationIndicator, rollIndicator);
                }
                else if (lookAroundEnabled)
                {
                    if (cameraControllerMovementAllowed)
                    {
                        //Then move camera (because it can be dependent on control object)
                        MySession.Static.CameraController.Rotate(rotationIndicator, rollIndicator);

                        if (!m_lookAroundEnabled && shouldStopControlledObject)
                        {
                            MySession.Static.ControlledEntity.MoveAndRotateStopped();
                        }
                    }

                    if (shouldStopControlledObject)
                    {
                        MySession.Static.CameraController.RotateStopped();
                    }
                }
                //Hack to make spectators work until they are made entities
                else if (MySession.Static.CameraController is MySpectatorCameraController && MySpectatorCameraController.Static.SpectatorCameraMovement == MySpectatorCameraMovementEnum.ConstantDelta)
                {
                    if (cameraControllerMovementAllowed)
                    {
                        MySpectatorCameraController.Static.MoveAndRotate(moveIndicator, rotationIndicator, rollIndicator);
                    }
                }

                if (shouldStopControlledObject)
                {
                    MySession.Static.ControlledEntity.MoveAndRotateStopped();
                }

                m_cameraControllerMovementAllowed = cameraControllerMovementAllowed;
                m_lookAroundEnabled = lookAroundEnabled;
            }
        }
Example #3
0
        public void SetCameraController(MyCameraControllerEnum cameraControllerEnum, IMyEntity cameraEntity = null, Vector3D? position = null)
        {
            //bool wasUserControlled = MySession.Static.CameraController != null ? MySession.Static.CameraController.AllowObjectControl() : false;

            // When spectator is not initialized, initialize it
            if (cameraEntity != null && Spectator.Position == Vector3.Zero)
            {
                var cam = (IMyCameraController)cameraEntity;
                Spectator.Position = cameraEntity.GetPosition() + cameraEntity.WorldMatrix.Forward * 4 + cameraEntity.WorldMatrix.Up * 2;
                Spectator.Target = cameraEntity.GetPosition();
            }

            switch (cameraControllerEnum)
            {
                case MyCameraControllerEnum.Entity:
                    Debug.Assert(cameraEntity != null);
                    if (!MyFinalBuildConstants.IS_OFFICIAL)
                        MySandboxGame.Log.WriteLine("CameraAttachedTo: Entity");
                    Static.CameraController = (IMyCameraController)cameraEntity;
                    Static.CameraController.IsInFirstPersonView = true;
                    break;
                case MyCameraControllerEnum.Spectator:
                    if (!MyFinalBuildConstants.IS_OFFICIAL)
                        MySandboxGame.Log.WriteLine("CameraAttachedTo: Spectator");
                    Static.CameraController = MySpectatorCameraController.Static;
                    MySpectatorCameraController.Static.SpectatorCameraMovement = MySpectatorCameraMovementEnum.UserControlled;
                    if (position.HasValue)
                        MySpectatorCameraController.Static.Position = position.Value;
                    break;

                case MyCameraControllerEnum.SpectatorFixed:
                    if (!MyFinalBuildConstants.IS_OFFICIAL)
                        MySandboxGame.Log.WriteLine("CameraAttachedTo: SpectatorFixed");
                    Static.CameraController = MySpectatorCameraController.Static;
                    MySpectatorCameraController.Static.SpectatorCameraMovement = MySpectatorCameraMovementEnum.None;
                    if (position.HasValue)
                        MySpectatorCameraController.Static.Position = position.Value;
                    break;

                case MyCameraControllerEnum.SpectatorDelta:
                    if (!MyFinalBuildConstants.IS_OFFICIAL)
                        MySandboxGame.Log.WriteLine("CameraAttachedTo: SpectatorDelta");
                    Static.CameraController = MySpectatorCameraController.Static;
                    MySpectatorCameraController.Static.SpectatorCameraMovement = MySpectatorCameraMovementEnum.ConstantDelta;
                    if (position.HasValue)
                        MySpectatorCameraController.Static.Position = position.Value;
                    break;

                case MyCameraControllerEnum.ThirdPersonSpectator:
                    if (!MyFinalBuildConstants.IS_OFFICIAL)
                        MySandboxGame.Log.WriteLine("CameraAttachedTo: ThirdPersonSpectator");

                    if (cameraEntity != null)
                        Static.CameraController = (IMyCameraController)cameraEntity;

                    Static.CameraController.IsInFirstPersonView = false;
                    break;

                default:
                    Debug.Assert(false);
                    break;
            }

            //if (wasUserControlled && !MySession.Static.CameraController.AllowObjectControl())
            //{
            //    if (ControlledObject != null)
            //        ControlledObject.MoveAndRotateStopped();
            //}
        }