예제 #1
0
        // Use this for initialization
        public void Initialize(FContext controller)
        {
            this.controller = controller;

            // find main camera
            GameObject[] mainCameras = GameObject.FindGameObjectsWithTag("MainCamera");
            if (mainCameras.Length == 0)
            {
                throw new MissingComponentException("CameraTracking.Initialize: could not find camera with tag MainCamera");
            }
            var mainCameraObj = mainCameras[0];

            if (mainCameras.Length > 1)
            {
                DebugUtil.Log(2, "CameraTracking.Initialize: there are multiple objects with tag MainCamera. Using the one named " + mainCameraObj.GetName());
            }
            mainCamera = new fCamera(mainCameraObj.GetComponent <Camera> () as Camera);

            // on Vive the MainCamera will have some child cameras that are a problem,
            // so get rid of them
            if (gs.VRPlatform.CurrentVRDevice == gs.VRPlatform.Device.HTCVive)
            {
                List <GameObject> children = new List <GameObject>(mainCameraObj.Children());
                foreach (var child in children)
                {
                    mainCameraObj.RemoveChild(child);
                    child.Destroy();
                }
            }

            is_orthographic_view = mainCamera.IsOrthographic;

            List <Camera> newCameras = new List <Camera>();

            Vector3f    mainPos = mainCamera.GetPosition();
            Quaternionf mainRot = mainCamera.GetRotation();

            // create camera for 3D widgets layer
            widgetCamera = new fCamera(Camera.Instantiate((Camera)mainCamera, mainPos, mainRot));
            widgetCamera.SetName("WidgetCamera");
            newCameras.Add(widgetCamera);

            // create camera for HUD layer
            hudCamera = new fCamera(Camera.Instantiate((Camera)mainCamera, mainPos, mainRot));
            hudCamera.SetName("HUDCamera");
            newCameras.Add(hudCamera);

            // create camera for UI
            uiCamera = new fCamera(Camera.Instantiate((Camera)mainCamera, mainPos, mainRot));
            uiCamera.SetName("UICamera");
            ((Camera)uiCamera).orthographic     = true;
            ((Camera)uiCamera).orthographicSize = 0.5f;
            newCameras.Add(uiCamera);

            // create camera for cursor
            cursorCamera = new fCamera(Camera.Instantiate((Camera)mainCamera, mainPos, mainRot));
            cursorCamera.SetName("CursorCamera");
            newCameras.Add(cursorCamera);

            // configure these cameras
            //   - must disable audio listener if it exists
            //   - do depth clear so we can draw on top of other layers
            foreach (Camera cam in newCameras)
            {
                AudioListener listener = cam.GetComponent <AudioListener>();
                if (listener != null)
                {
                    listener.enabled = false;
                }

                cam.clearFlags = CameraClearFlags.Depth;

                cam.tag = "Untagged";
            }


            // set up camera masks

            // this camera only renders 3DWidgetOverlay layer, and mainCam does not!
            int nWidgetLayer = FPlatform.WidgetOverlayLayer;
            int nHUDLayer    = FPlatform.HUDLayer;
            int nUILayer     = FPlatform.UILayer;
            int nCursorLayer = FPlatform.CursorLayer;

            ((Camera)widgetCamera).cullingMask = (1 << nWidgetLayer);
            ((Camera)hudCamera).cullingMask    = (1 << nHUDLayer);
            ((Camera)uiCamera).cullingMask     = (1 << nUILayer);
            ((Camera)cursorCamera).cullingMask = (1 << nCursorLayer);

            ((Camera)mainCamera).cullingMask &= ~(1 << nWidgetLayer);
            ((Camera)mainCamera).cullingMask &= ~(1 << nHUDLayer);
            ((Camera)mainCamera).cullingMask &= ~(1 << nUILayer);
            ((Camera)mainCamera).cullingMask &= ~(1 << nCursorLayer);

            // attach camera animation object to main camera
            CameraAnimator anim = mainCamera.AddComponent <CameraAnimator>();

            anim.UseCamera = mainCamera;
            anim.UseScene  = this.controller.Scene;

            // add target point to camera
            CameraTarget target = mainCamera.AddComponent <CameraTarget>();

            target.TargetPoint = new Vector3f(0.0f, mainCamera.GetPosition().y, 0.0f);
            target.context     = this.controller;

            // add camera manipulator to camera
            // TODO: this does not need to be a monobehavior...
            var manipulator = mainCamera.AddComponent <CameraManipulator>();

            manipulator.Camera = mainCamera;


            // initialize FPlatform
            FPlatform.MainCamera    = mainCamera;
            FPlatform.WidgetCamera  = widgetCamera;
            FPlatform.HUDCamera     = hudCamera;
            FPlatform.OrthoUICamera = uiCamera;
            FPlatform.CursorCamera  = cursorCamera;
        }
예제 #2
0
        // for checking things...
        public static void print_compare(string prefix, Quaternion q1, g3.Quaternionf q2)
        {
            double dErr = Math.Abs(q1.x - q2.x) + Math.Abs(q1.y - q2.y) + Math.Abs(q1.z - q2.z) + Math.Abs(q1.w - q2.w);

            DebugUtil.Log(2, "{0} {1} {2} err {3}", prefix, q1.ToString("F8"), q2.ToString(), dErr);
        }
예제 #3
0
        public virtual SceneObject BuildMeshReference(FScene scene, string sSceneFilePath, TypedAttribSet attributes)
        {
            string sAbsPath = "", sRelPath = "";
            bool   bAbsPathOK = safe_set_property_s(attributes, IOStrings.AReferencePath, (str) => { sAbsPath = str; });
            bool   bRelPathOK = safe_set_property_s(attributes, IOStrings.ARelReferencePath, (str) => { sRelPath = str; });

            string sScenePathDir = Path.GetDirectoryName(sSceneFilePath);

            // ok we are going to try really hard to find references...
            string sUsePath      = "";
            string sBaseFilename = "";

            if (bRelPathOK)
            {
                sBaseFilename = Path.GetFileName(sRelPath);

                // first we check if relative path exists
                string sAbsRelPath = Path.Combine(sScenePathDir, sRelPath);
                if (System.IO.File.Exists(sAbsRelPath))
                {
                    DebugUtil.Log(2, "[UnitySerialization.BuildMeshReference] using relative path " + sRelPath);
                    sUsePath = sAbsRelPath;
                }

                // if not, we try appending filename to scene path
                if (sUsePath == "")
                {
                    string sLocalPath = Path.Combine(sScenePathDir, sBaseFilename);
                    if (System.IO.File.Exists(sLocalPath))
                    {
                        DebugUtil.Log(2, "[UnitySerialization.BuildMeshReference] using local path " + sLocalPath);
                        sUsePath = sLocalPath;
                    }
                }

                // if that fails we accumulate relative path segments (from last folder backwards)
                // and see if we can find the file in any of those
                List <string> subdirs    = new List <string>(sRelPath.Split(Path.DirectorySeparatorChar).Reverse());
                int           N          = subdirs.Count;
                string        sAccumPath = "";
                for (int i = 1; i < N && sUsePath == ""; ++i)
                {
                    sAccumPath = Path.Combine(subdirs[i], sAccumPath);
                    string sLocalPath = Path.Combine(Path.Combine(sScenePathDir, sAccumPath), sBaseFilename);
                    DebugUtil.Log(2, "trying " + sLocalPath);
                    if (System.IO.File.Exists(sLocalPath))
                    {
                        DebugUtil.Log(2, "[UnitySerialization.BuildMeshReference] using local path " + sLocalPath);
                        sUsePath = sLocalPath;
                    }
                }
            }

            // ok if all that failed, try absolute path
            if (sUsePath == "" && bAbsPathOK)
            {
                sBaseFilename = Path.GetFileName(sAbsPath);
                if (System.IO.File.Exists(sAbsPath))
                {
                    DebugUtil.Log(2, "[UnitySerialization.BuildMeshReference] using absolute path " + sAbsPath);
                    sUsePath = sAbsPath;
                }

                // try appending filename to scene path in case we didn't have a relative path at all (bRelPathOK = false)
                if (sUsePath == "")
                {
                    string sLocalPath = Path.Combine(sScenePathDir, sBaseFilename);
                    if (System.IO.File.Exists(sLocalPath))
                    {
                        DebugUtil.Log(2, "[UnitySerialization.BuildMeshReference] using local path " + sLocalPath);
                        sUsePath = sLocalPath;
                    }
                }
            }

            if (sUsePath == "")
            {
                emit_message("referenced mesh does not exist at path [" + sAbsPath + "] or [" + sRelPath + "] ");
                return(null);
            }

            SceneMeshImporter import = new SceneMeshImporter();
            bool bOK = import.ReadFile(sUsePath);

            if (bOK == false && import.LastReadResult.code != g3.IOCode.Ok)
            {
                emit_message("import of mesh [" + sUsePath + "] failed: " + import.LastReadResult.message);
                // [TODO] how can we show this message?
                //HUDUtil.ShowCenteredStaticPopupMessage("popups/error_reading_file", activeCockpit);
                return(null);
            }
            MeshReferenceSO refSO = import.GetMeshReference(scene.DefaultMeshSOMaterial);

            safe_set_property_s(attributes, IOStrings.ASOName, (s) => { refSO.Name = s; });
            RestoreTransform(refSO, attributes);
            return(refSO);
        }
예제 #4
0
        // FixedUpdate is called before any Update
        public void Update()
        {
            if (CheckForSpatialInputActive() == false)
            {
                return;
            }

            Vector3 rootPos = spatialCamRig.transform.position;

            SpatialDevice[] hands = { Left, Right };
            for (int i = 0; i < 2; ++i)
            {
                SpatialDevice h = hands[i];

                h.CursorActive = VRPlatform.IsSpatialDeviceTracked(i);
                if (h.CursorActive)
                {
                    h.Hand.Show();
                    h.Cursor.Show();

                    Vector3    handPos = VRPlatform.GetLocalControllerPosition(i);
                    Quaternion handRot = VRPlatform.GetLocalControllerRotation(i);

                    h.AbsoluteHandFrame = new Frame3f(rootPos + handPos, handRot);

                    float fPositionT = 0.2f;
                    float fRotationT = 0.2f;
                    //float fPositionT = 1.0f;
                    //float fRotationT = 1.0f;

                    if (h.SmoothedHandFrame.Origin != Vector3f.Zero)
                    {
                        Vector3 new_origin =
                            Vector3.Lerp(h.SmoothedHandFrame.Origin, h.AbsoluteHandFrame.Origin, fPositionT);
                        Quaternion new_rotation =
                            Quaternion.Slerp(h.SmoothedHandFrame.Rotation, h.AbsoluteHandFrame.Rotation, fRotationT);
                        h.SmoothedHandFrame = new Frame3f(new_origin, new_rotation);
                    }
                    else
                    {
                        h.SmoothedHandFrame = h.AbsoluteHandFrame;
                    }

                    h.Hand.transform.position = h.SmoothedHandFrame.Origin;
                    h.Hand.transform.rotation = h.SmoothedHandFrame.Rotation * (Quaternionf)handGeomRotation;

                    h.CursorRay = new Ray(h.SmoothedHandFrame.Origin,
                                          (h.SmoothedHandFrame.Rotation * Vector3.forward).Normalized);

                    if (Mathf.Abs(h.CursorRay.direction.sqrMagnitude - 1.0f) > 0.001f)
                    {
                        DebugUtil.Log(2, "SpatialInputController.Update - invlaid cursor ray! rotation was {0}", h.SmoothedHandFrame.Rotation);
                        h.CursorRay = new Ray(h.SmoothedHandFrame.Origin, Vector3.up);
                    }

                    // raycast into scene to see if we hit object, UI, bounds, etc.
                    bool bHit = false;
                    if (context != null)
                    {
                        // want to hit-test active gizmo first, because that has hit-priority
                        if (context.TransformManager.HaveActiveGizmo)
                        {
                            UIRayHit uiHit = null;
                            if (context.TransformManager.ActiveGizmo.FindRayIntersection(h.CursorRay, out uiHit))
                            {
                                h.RayHitPos = uiHit.hitPos;
                                bHit        = true;
                            }
                        }
                        // next we tested scene
                        if (bHit == false)
                        {
                            AnyRayHit hit = null;
                            if (context.FindAnyRayIntersection(h.CursorRay, out hit))
                            {
                                h.RayHitPos = hit.hitPos;
                                bHit        = true;
                            }
                        }
                        // finally test worldbounds
                        if (bHit == false)
                        {
                            GameObjectRayHit ghit = null;
                            if (context.GetScene().FindWorldBoundsHit(h.CursorRay, out ghit))
                            {
                                h.RayHitPos = ghit.hitPos;
                            }
                        }
                    }

                    // if not, plane cursor on view-perp plane centered at last hit pos,
                    // otherwise it will be stuck/disappear
                    if (bHit == false)
                    {
                        Frame3f f = new Frame3f(h.RayHitPos, camera.transform.forward);
                        h.RayHitPos = f.RayPlaneIntersection(h.CursorRay.origin, h.CursorRay.direction, 2);
                    }

                    h.Cursor.transform.position = h.RayHitPos;
                    //if (scene.InCapture)
                    //    MaterialUtil.SetMaterial(h.Cursor, h.CursorCapturingMaterial);
                    //else
                    if (bHit)
                    {
                        MaterialUtil.SetMaterial(h.Cursor, h.CursorHitMaterial);
                    }
                    else
                    {
                        MaterialUtil.SetMaterial(h.Cursor, h.CursorDefaultMaterial);
                    }

                    // maintain a consistent visual size for 3D cursor sphere
                    float fScaling = VRUtil.GetVRRadiusForVisualAngle(h.RayHitPos, camera.transform.position, CursorVisualAngleInDegrees);
                    h.Cursor.transform.localScale = fScaling * Vector3.one;

                    // orient cursor so it is tilted like a 2D cursor, but per-hand
                    Vector3 cursor_right = Vector3.Cross(camera.transform.up, h.CursorRay.direction);
                    Vector3 cursor_fw    = Vector3.Cross(cursor_right, camera.transform.up);
                    float   rotSign      = (h == Right) ? 1.0f : -1.0f;
                    Vector3 pointDir     = (camera.transform.up + cursor_fw - 0.5f * rotSign * cursor_right).normalized;
                    h.Cursor.transform.localRotation = Quaternion.FromToRotation(Vector3.up, pointDir);

                    // update laser line
                    if (h.Laser != null)
                    {
                        float   hDist = (h.RayHitPos - h.CursorRay.origin).magnitude;
                        Vector3 p0    = h.RayHitPos - 0.9f * hDist * h.CursorRay.direction;
                        Vector3 p1    = h.RayHitPos + 100.0f * h.CursorRay.direction;
                        float   r0    = VRUtil.GetVRRadiusForVisualAngle(p0, camera.transform.position, 0.5f);
                        h.LaserRen.SetPosition(0, p0);
                        h.LaserRen.SetPosition(1, p1);
                        h.LaserRen.startWidth = h.LaserRen.endWidth = r0;
                    }

                    // udpate cursor
                    Mesh useMesh = context.ToolManager.HasActiveTool(i) ? activeToolCursorMesh : standardCursorMesh;
                    if (h.Cursor.GetSharedMesh() != useMesh)
                    {
                        h.Cursor.SetSharedMesh(useMesh);
                    }
                }
                else
                {
                    h.Hand.Hide();
                    h.Cursor.Hide();
                }
            }
        }
예제 #5
0
        public static void print_compare(string prefix, Vector3 v1, g3.Vector3f v2)
        {
            double dErr = Math.Abs(v1.x - v2.x) + Math.Abs(v1.y - v2.y) + Math.Abs(v1.z - v2.z);

            DebugUtil.Log(2, "{0} {1} {2} err {3}", prefix, v1.ToString("F8"), v2.ToString(), dErr);
        }
예제 #6
0
        void Restore_OnAttribute(string sName, string sValue)
        {
            if (eState != RestoreState.InSceneObject && eState != RestoreState.InStruct)
            {
                throw new FormatException("[Serializer] not in correct state for OnAttrib");
            }

            char[] delimiterChars = { ' ' };

            if (sName == IOStrings.Struct)
            {
            }
            else if (sName[0] == 'i')
            {
                int iValue = 0;
                int.TryParse(sValue, out iValue);
                CurAttribs.Pairs[sName] = iValue;
            }
            else if (sName[0] == 'f')
            {
                float fValue = 0;
                float.TryParse(sValue, out fValue);
                CurAttribs.Pairs[sName] = fValue;
            }
            else if (sName[0] == 'b')
            {
                bool bValue = true;
                if (sValue.Equals("false", StringComparison.InvariantCultureIgnoreCase))
                {
                    bValue = false;
                }
                CurAttribs.Pairs[sName] = bValue;
            }
            else if (sName[0] == 'v')
            {
                float    x = 0, y = 0, z = 0;
                string[] values = sValue.Split(delimiterChars);
                if (values.Length == 3)
                {
                    float.TryParse(values[0], out x);
                    float.TryParse(values[1], out y);
                    float.TryParse(values[2], out z);
                }
                CurAttribs.Pairs[sName] = new Vector3f(x, y, z);
            }
            else if (sName[0] == 'u')
            {
                float    x = 0, y = 0;
                string[] values = sValue.Split(delimiterChars);
                if (values.Length == 2)
                {
                    float.TryParse(values[0], out x);
                    float.TryParse(values[1], out y);
                }
                CurAttribs.Pairs[sName] = new Vector2f(x, y);
            }
            else if (sName[0] == 'q')
            {
                float    x = 0, y = 0, z = 0, w = 0;
                string[] values = sValue.Split(delimiterChars);
                if (values.Length == 4)
                {
                    float.TryParse(values[0], out x);
                    float.TryParse(values[1], out y);
                    float.TryParse(values[2], out z);
                    float.TryParse(values[3], out w);
                }
                CurAttribs.Pairs[sName] = new Quaternionf(x, y, z, w);
            }
            else if (sName[0] == 'c')
            {
                float    r = 0, g = 0, b = 0, a = 0;
                string[] values = sValue.Split(delimiterChars);
                if (values.Length == 4)
                {
                    float.TryParse(values[0], out r);
                    float.TryParse(values[1], out g);
                    float.TryParse(values[2], out b);
                    float.TryParse(values[3], out a);
                }
                CurAttribs.Pairs[sName] = new Colorf(r, g, b, a);
            }
            else if (sName[0] == 'z')
            {
                if (sName[1] == 'd' && sName[2] == '3')
                {
                    CurAttribs.Pairs[sName] = restore_list3d(sValue);
                }
                else if (sName[1] == 'f' && sName[2] == '3')
                {
                    CurAttribs.Pairs[sName] = restore_list3f(sValue);
                }
                else if (sName[1] == 'i' && sName[2] == '3')
                {
                    CurAttribs.Pairs[sName] = restore_list3i(sValue);
                }
                else if (sName[1] == 'd' && sName[2] == '2')
                {
                    CurAttribs.Pairs[sName] = restore_list2d(sValue);
                }
                else if (sName[1] == 'f' && sName[2] == '2')
                {
                    CurAttribs.Pairs[sName] = restore_list2f(sValue);
                }
                else
                {
                    DebugUtil.Warning("[SceneSerializer.Restore_OnAttribute] - unknown array format {0}", sName);
                }
            }
            else if (sName[0] == 'x')
            {
                if (sName[1] == 'd' && sName[2] == '3')
                {
                    CurAttribs.Pairs[sName] = restore_list3d_binary(sValue);
                }
                else if (sName[1] == 'd')
                {
                    CurAttribs.Pairs[sName] = restore_list1d_binary(sValue);
                }
                //else if (sName[1] == 'd' && sName[2] == '2')
                //    CurAttribs.Pairs[sName] = restore_list2d_binary(sValue);
                else if (sName[1] == 'f' && sName[2] == '3')
                {
                    CurAttribs.Pairs[sName] = restore_list3f_binary(sValue);
                }
                else if (sName[1] == 'f')
                {
                    CurAttribs.Pairs[sName] = restore_list1f_binary(sValue);
                }
                else if (sName[1] == 'i' && sName[2] == '3')
                {
                    CurAttribs.Pairs[sName] = restore_list3i_binary(sValue);
                }
                else if (sName[1] == 'i' && sName[2] == '4')
                {
                    CurAttribs.Pairs[sName] = restore_list4i_binary(sValue);
                }
                else if (sName[1] == 'i')
                {
                    CurAttribs.Pairs[sName] = restore_list1i_binary(sValue);
                }
                else if (sName[1] == 'j')
                {
                    CurAttribs.Pairs[sName] = restore_list1s_binary(sValue);
                }
                else if (sName[1] == 'k')
                {
                    CurAttribs.Pairs[sName] = restore_list1b_binary(sValue);
                }
                else
                {
                    DebugUtil.Warning("[SceneSerializer.Restore_OnAttribute] - unknown binary format {0}", sName);
                }
            }
            else if (sName[0] == 'y')
            {
                if (sName[1] == 'd' && sName[2] == '3')
                {
                    CurAttribs.Pairs[sName] = restore_list3d_compressed(sValue);
                }
                else if (sName[1] == 'd')
                {
                    CurAttribs.Pairs[sName] = restore_list1d_compressed(sValue);
                }
                //else if (sName[1] == 'd' && sName[2] == '2')
                //    CurAttribs.Pairs[sName] = restore_list2d_compressed(sValue);
                else if (sName[1] == 'f' && sName[2] == '3')
                {
                    CurAttribs.Pairs[sName] = restore_list3f_compressed(sValue);
                }
                else if (sName[1] == 'f')
                {
                    CurAttribs.Pairs[sName] = restore_list1f_compressed(sValue);
                }
                else if (sName[1] == 'i' && sName[2] == '3')
                {
                    CurAttribs.Pairs[sName] = restore_list3i_compressed(sValue);
                }
                else if (sName[1] == 'i' && sName[2] == '4')
                {
                    CurAttribs.Pairs[sName] = restore_list4i_compressed(sValue);
                }
                else if (sName[1] == 'i')
                {
                    CurAttribs.Pairs[sName] = restore_list1i_compressed(sValue);
                }
                else if (sName[1] == 'j')
                {
                    CurAttribs.Pairs[sName] = restore_list1s_compressed(sValue);
                }
                else if (sName[1] == 'k')
                {
                    CurAttribs.Pairs[sName] = restore_list1b_compressed(sValue);
                }
                else
                {
                    DebugUtil.Warning("[SceneSerializer.Restore_OnAttribute] - unknown compressed format {0}", sName);
                }
            }
            else
            {
                CurAttribs.Pairs[sName] = sValue;
            }
        }
예제 #7
0
        void HandleInput_Touch()
        {
            // update mouse/gamepad cursor
            MouseController.Update();

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

            input.Initialize_TouchInput(this);
            lastInputState = input;

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

            input.TouchCaptureActive = (captureTouch != null);

            // update left-capture
            if (captureTouch != null)
            {
                Capture cap = captureTouch.element.UpdateCapture(input, captureTouch.data);
                if (cap.state == CaptureState.Continue)
                {
                    // (carry on)
                }
                else if (cap.state == CaptureState.End)
                {
                    DebugUtil.Log(10, "[SceneController] released touch capture " + captureTouch.element.CaptureIdentifier);
                    captureTouch = null;
                }
            }

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

            if (bCanCapture && captureTouch == null)
            {
                // collect up capture requests
                List <CaptureRequest> vRequests = new List <CaptureRequest>();
                inputBehaviors.CollectWantsCapture(input, vRequests);
                if (vRequests.Count > 0)
                {
                    // 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
                        //  (??)

                        // before we actually begin capture we will complete any text editing
                        // [RMS] perhaps this should be configurable for behavior? Some behaviors
                        // do not require this (eg view controls...)
                        completeTextEntryOnFocusChange();

                        Capture c = vRequests[i].element.BeginCapture(input, CaptureSide.Any);
                        if (c.state == CaptureState.Begin)
                        {
                            capReq = c;
                        }
                    }
                    if (capReq != null)
                    {
                        captureTouch = capReq;
                    }
                }
            }
        }
예제 #8
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);
            }
        }
예제 #9
0
 private void Context_OnWindowResized()
 {
     DebugUtil.Log(2, "WINDOW RESIZE EVENT");
     FUtil.SafeSendAnyEvent(OnContainerBoundsModified, this);
 }