Esempio n. 1
0
        // Update is called once per frame
        public void Update()
        {
            FPlatform.IncrementFrameCounter();

            if (FPlatform.IsWindowResized())
            {
                FUtil.SafeSendAnyEvent(OnWindowResized);
            }

            // update our wrappers around various different Input modes
            InputExtension.Get.Update();

            // update cockpit tracking and let UI do per-frame rendering computations
            if (options.EnableCockpit)
            {
                ActiveCockpit.Update();
            }

            // hardcoded Q key quits app
            if (Input.GetKeyUp(KeyCode.Q))
            {
                Cursor.lockState = CursorLockMode.None;
                GlobalControl.Quit();
            }

            // run per-frame actions
            Action execActions = nextFrameActions.GetRunnable();

            nextFrameActions.Clear();
            execActions();


            // can either use spacecontrols or mouse, but not both at same time
            // [TODO] ask spatial input controller instead, it knows better (?)
            if (FPlatform.IsUsingVR() && SpatialController.CheckForSpatialInputActive())
            {
                Configure_SpaceControllers();
                HandleInput_SpaceControllers();
            }
            else if (FPlatform.IsTouchDevice())
            {
                Configure_TouchInput();
                HandleInput_Touch();
            }
            else
            {
                Configure_MouseOrGamepad();
                HandleInput_MouseOrGamepad();
            }

            // after we have handled input, do per-frame rendering computations
            if (options.EnableCockpit)
            {
                ActiveCockpit.PreRender();
            }
            ToolManager.PreRender();
            Scene.PreRender();
        }
Esempio n. 2
0
        void HandleInput_SpaceControllers()
        {
            // update cursors
            SpatialController.Update();
            MouseController.HideCursor();

            // have to do this after cursor update in case hotkey uses mouse position
            HandleKeyboardInput();

            // create our super-input object  (wraps all supported input types)
            InputState input = new InputState();

            input.Initialize_SpatialController(this);
            lastInputState = input;

            // run override behaviors
            overrideBehaviors.SendOverrideInputs(input);


            input.LeftCaptureActive  = (captureLeft != null);
            input.RightCaptureActive = (captureRight != null);

            // update left-capture
            if (captureLeft != null)
            {
                Capture cap = captureLeft.element.UpdateCapture(input, captureLeft.data);
                if (cap.state == CaptureState.Continue)
                {
                    // (carry on)
                }
                else if (cap.state == CaptureState.End)
                {
                    DebugUtil.Log(10, "[SceneController] released left capture " + captureLeft.element.CaptureIdentifier);
                    if (captureRight == captureLeft)
                    {
                        captureRight = null;        // if we are doing a dual-capture, we only want to end once!!
                    }
                    captureLeft = null;
                }
            }

            // update right-capture
            // if we are doing a both-capture, we only want to send update once
            if (captureRight != null && captureRight != captureLeft)
            {
                Capture cap = captureRight.element.UpdateCapture(input, captureRight.data);
                if (cap.state == CaptureState.Continue)
                {
                    // (carry on)
                }
                else if (cap.state == CaptureState.End)
                {
                    DebugUtil.Log(10, "[SceneController] released right capture " + captureRight.element.CaptureIdentifier);
                    captureRight = null;
                }
            }

            // if we have a free device, check for capture.
            bool bCanCapture = (bInCameraControl == false);

            if (bCanCapture && (captureLeft == null || captureRight == null))
            {
                // collect up capture requests
                List <CaptureRequest> vRequests = new List <CaptureRequest>();
                inputBehaviors.CollectWantsCapture(input, vRequests);
                if (vRequests.Count > 0)
                {
                    // end outstanding hovers
                    TerminateHovers(input);

                    // select one of the capture requests. technically we could end
                    //  up with none successfully Begin'ing, but behaviors should be
                    //  doing those checks in WantCapture, not BeginCapture !!
                    vRequests.OrderBy(x => x.element.Priority);
                    Capture capReq = null;
                    for (int i = 0; i < vRequests.Count && capReq == null; ++i)
                    {
                        // filter out invalid requests
                        CaptureSide eUseSide = vRequests[i].side;
                        if (eUseSide == CaptureSide.Any)        // replace Any with Both. Does that make sense??
                        {
                            eUseSide = CaptureSide.Both;
                        }
                        if ((eUseSide == CaptureSide.Left || eUseSide == CaptureSide.Both) &&
                            captureLeft != null)
                        {
                            continue;
                        }
                        if ((eUseSide == CaptureSide.Right || eUseSide == CaptureSide.Both) &&
                            captureRight != null)
                        {
                            continue;
                        }

                        Capture c = vRequests[i].element.BeginCapture(input, eUseSide);
                        if (c.state == CaptureState.Begin)
                        {
                            capReq = c;
                        }
                    }

                    if (capReq != null)
                    {
                        // technically we only should terminate hover on capture controller,
                        // but that seems really hard. This will clear hovers but they will
                        // come back next frame. Perhaps revisit if this is causing flicker...
                        TerminateHovers(input);

                        // [RMS] most of this checking is redundant now, but leaving because of debug logging
                        if (capReq.data.which == CaptureSide.Left)
                        {
                            if (captureLeft != null)
                            {
                                DebugUtil.Warning("[SceneController.HandleInput_SpaceControllers] received Capture request for Left side from {0}, but already capturing! Ignoring.", capReq.element.CaptureIdentifier);
                            }
                            else
                            {
                                captureLeft = capReq;
                                DebugUtil.Log(10, "[SceneController] began left-capture" + captureLeft.element.CaptureIdentifier);
                            }
                        }
                        else if (capReq.data.which == CaptureSide.Right)
                        {
                            if (captureRight != null)
                            {
                                DebugUtil.Warning("[SceneController.HandleInput_SpaceControllers] received Capture request for Right side from {0}, but already capturing! Ignoring.", capReq.element.CaptureIdentifier);
                            }
                            else
                            {
                                captureRight = capReq;
                                DebugUtil.Log(10, "[SceneController] began right-capture" + captureRight.element.CaptureIdentifier);
                            }
                        }
                        else if (capReq.data.which == CaptureSide.Both || capReq.data.which == CaptureSide.Any)
                        {
                            if (captureLeft != null || captureRight != null)
                            {
                                DebugUtil.Warning("[SceneController.HandleInput_SpaceControllers] received Capture request for both sides from {0}, but already capturing! Ignoring.", capReq.element.CaptureIdentifier);
                            }
                            else
                            {
                                captureLeft = captureRight = capReq;
                                DebugUtil.Log(10, "[SceneController] began both-capture " + captureLeft.element.CaptureIdentifier);
                            }
                        }
                    }
                }
            }

            // update hover if we have a free device
            if (captureLeft == null || captureRight == null)
            {
                inputBehaviors.UpdateHover(input);
            }
        }
Esempio n. 3
0
        // Use this for initialization
        public void Start(SceneOptions options)
        {
            this.options = options;

            DebugUtil.LogLevel = options.LogLevel;
            FPlatform.InitializeMainThreadID();

            // initialize VR platform if VR is active
            if (gs.VRPlatform.VREnabled)
            {
                if (options.Use2DCockpit)
                {
                    throw new Exception("FContext.Start: cannot use 2D Orthographic Cockpit with VR!");
                }
                if (options.SpatialCameraRig != null)
                {
                    gs.VRPlatform.Initialize(options.SpatialCameraRig);
                }
            }

            InputExtension.Get.Start();

            nextFrameActions = new ActionSet();

            // intialize camera stuff
            camTracker = new CameraTracking();
            camTracker.Initialize(this);

            GetScene();
            if (options.SceneInitializer != null)
            {
                options.SceneInitializer.Initialize(GetScene());
            }

            if (options.DefaultGizmoBuilder != null)
            {
                transformManager = new TransformManager(options.DefaultGizmoBuilder);
            }
            else
            {
                transformManager = new TransformManager(new AxisTransformGizmoBuilder());
            }
            if (options.EnableTransforms)
            {
                transformManager.Initialize(this);
            }

            toolManager = new ToolManager();
            toolManager.Initialize(this);
            toolManager.OnToolActivationChanged += OnToolActivationChanged;

            MouseController.Start();
            SpatialController.Start();

            // [RMS] hardcode starting cam target point to origin
            ActiveCamera.SetTarget(Vector3f.Zero);

            if (options.MouseCameraControls != null)
            {
                MouseCameraController = options.MouseCameraControls;
            }

            // apply initial transformation to scene
            ActiveCamera.Manipulator().SceneTranslate(Scene, SceneGraphConfig.InitialSceneTranslate, true);

            // create behavior sets
            inputBehaviors    = new InputBehaviorSet();
            overrideBehaviors = new InputBehaviorSet();

            // cockpit needs to go last because UI setup may depend on above
            cockpitStack = new Stack <Cockpit>();
            if (options.EnableCockpit)
            {
                PushCockpit(options.CockpitInitializer);
            }


            captureMouse     = null;
            captureTouch     = null;
            captureLeft      = captureRight = null;
            bInCameraControl = false;

            // [RMS] this locks cursor to game unless user presses escape or exits
            if (FPlatform.IsUsingVR() || options.UseSystemMouseCursor == false)
            {
                Cursor.lockState = CursorLockMode.Locked;
            }

            // set hacky hackenstein global
            ActiveContext_HACK = this;

            startup_checks();
        }