Exemple #1
0
    public void UpdatePoses(WVR_PoseOriginModel origin, bool isSimulator)
    {
        if (!this.Initialized)
        {
            return;
        }

        Log.gpl.d(LOG_TAG, "UpdatePoses");

#if UNITY_EDITOR
        if (Application.isEditor)
        {
            if (isSimulator)
            {
                WaveVR_Utils.WVR_GetSyncPose_S((int)origin, poses, poses.Length);
            }
        }
        else
#endif
        {
            bool _focusCapturedBySystem = Interop.WVR_IsInputFocusCapturedBySystem();
            if (this.FocusCapturedBySystem != _focusCapturedBySystem)
            {
                this.FocusCapturedBySystem = _focusCapturedBySystem;
                WaveVR_Utils.Event.Send(WaveVR_Utils.Event.SYSTEMFOCUS_CHANGED, this.FocusCapturedBySystem);

                // When getting system focus again, reset button events.
                if (!this.FocusCapturedBySystem)
                {
                    Log.i(LOG_TAG, "UpdatePoses() get system focus, reset button events.");
                    ResetButtonEvents();
                }
                else
                {
                    Log.i(LOG_TAG, "UpdatePoses() lost system focus.");
                }
            }
            Interop.WVR_GetSyncPose(origin, poses, (uint)poses.Length);
        }

        for (uint i = 0; i < DeviceTypes.Length; i++)
        {
            bool _hasType = false;

            for (uint j = 0; j < poses.Length; j++)
            {
                WVR_DevicePosePair_t _pose = poses[j];

                if (_pose.type == DeviceTypes [i])
                {
                    _hasType          = true;
                    deviceIndexMap[i] = j;

                    if (connected [i] != _pose.pose.IsValidPose)
                    {
                        connected [i] = _pose.pose.IsValidPose;
                        Log.i(LOG_TAG, "device " + DeviceTypes [i] + " is " + (connected [i] ? "connected" : "disconnected"));
                        WaveVR_Utils.Event.Send(WaveVR_Utils.Event.DEVICE_CONNECTED, DeviceTypes [i], connected[i]);
                    }

                    if (connected [i])
                    {
                        rtPoses[j].update(_pose.pose.PoseMatrix);
                    }

                    break;
                }
            }

            // no such type
            if (!_hasType)
            {
                if (connected [i] == true)
                {
                    connected [i] = false;
                    Log.i(LOG_TAG, "device " + DeviceTypes [i] + " is disconnected.");
                    WaveVR_Utils.Event.Send(WaveVR_Utils.Event.DEVICE_CONNECTED, DeviceTypes [i], connected[i]);
                }
            }
        }

        for (int i = 0; i < poses.Length; i++)
        {
            WVR_DeviceType _type      = poses [i].type;
            bool           _connected = false;
#if UNITY_EDITOR
            if (isSimulator)
            {
                _connected = WaveVR_Utils.WVR_IsDeviceConnected_S((int)_type);
            }
            else
#endif
            {
                _connected = Interop.WVR_IsDeviceConnected(_type);
            }

            bool _posevalid = poses [i].pose.IsValidPose;

            Log.gpl.d(LOG_TAG, "Device " + _type + " is " + (_connected ? "connected" : "disconnected")
                      + ", pose is " + (_posevalid ? "valid" : "invalid")
                      + ", pos: {" + rtPoses [i].pos.x + ", " + rtPoses [i].pos.y + ", " + rtPoses [i].pos.z + "}"
                      + ", rot: {" + rtPoses [i].rot.x + ", " + rtPoses [i].rot.y + ", " + rtPoses [i].rot.z + ", " + rtPoses [i].rot.w + "}");
        }

        try
        {
            WaveVR_Utils.Event.Send(WaveVR_Utils.Event.NEW_POSES, poses, rtPoses);
        }
        catch (Exception ex)
        {
            Log.e(LOG_TAG, "Send NEW_POSES Event Exception : " + ex);
        }
        Log.gpl.d(LOG_TAG, "after new poses");
        try
        {
            WaveVR_Utils.Event.Send(WaveVR_Utils.Event.AFTER_NEW_POSES);
        }
        catch (Exception ex)
        {
            Log.e(LOG_TAG, "Send AFTER_NEW_POSES Event Exception : " + ex);
        }
    }