public void PollEventState(ref HeadsetState state)
        {
            GvrErrorType eventType;

            try {
                eventType = (GvrErrorType)gvr_poll_event(gvrContextPtr, gvrEventPtr);
            } catch (EntryPointNotFoundException) {
                Debug.LogError("GvrHeadset not supported by this version of Unity. " +
                               "Support starts in 5.6.3p3 and 2017.1.1p1.");
                throw;
            }
            if (eventType == GvrErrorType.NoEventAvailable)
            {
                state.eventType = GvrEventType.Invalid;
                return;
            }

            Marshal.PtrToStructure(gvrEventPtr, gvrEventHeader);
            state.eventFlags       = gvrEventHeader.flags;
            state.eventTimestampNs = gvrEventHeader.timestamp;
            state.eventType        = (GvrEventType)gvrEventHeader.type;
            // Event data begins after header.
            IntPtr eventDataPtr = new IntPtr(gvrEventPtr.ToInt64() + Marshal.SizeOf(gvrEventHeader));

            if (state.eventType == GvrEventType.Recenter)
            {
                Marshal.PtrToStructure(eventDataPtr, gvrRecenterEventData);
                _HandleRecenterEvent(ref state, gvrRecenterEventData);
                return;
            }
        }
        private void _HandleRecenterEvent(ref HeadsetState state, gvr_recenter_event_data eventData)
        {
            state.recenterEventType  = (GvrRecenterEventType)eventData.recenter_event_type;
            state.recenterEventFlags = eventData.recenter_event_flags;
            Matrix4x4 gvrMatrix = GvrMathHelpers.ConvertFloatArrayToMatrix(eventData.pose_transform);

            GvrMathHelpers.GvrMatrixToUnitySpace(
                gvrMatrix, out state.recenteredPosition, out state.recenteredRotation);
        }
        private void _HandleRecenterEvent(ref HeadsetState state, gvr_recenter_event_data eventData)
        {
            state.recenterEventType  = (GvrRecenterEventType)eventData.recenter_event_type;
            state.recenterEventFlags = eventData.recenter_event_flags;

            Matrix4x4 poseTransform = MATRIX4X4_IDENTITY;

            float[] poseRaw = eventData.pose_transform;
            for (int i = 0; i < 4; i++)
            {
                int     j   = i * 4;
                Vector4 row = new Vector4(poseRaw[j], poseRaw[j + 1], poseRaw[j + 2], poseRaw[j + 3]);
                poseTransform.SetRow(i, row);
            }

            // Invert the matrix to go from row-major (GVR) to column-major (Unity),
            // and change from LHS to RHS coordinates.
            transientRecenteredPose3d.SetRightHanded(poseTransform.transpose);
            state.recenteredPosition = transientRecenteredPose3d.Position;
            state.recenteredRotation = transientRecenteredPose3d.Orientation;
        }
Exemplo n.º 4
0
        public void PollEventState(ref HeadsetState state)
        {
#if UNITY_ANDROID && UNITY_EDITOR
            if (InstantPreview.Instance != null)
            {
                if (InstantPreview.Instance.events.Count > 0)
                {
                    InstantPreview.UnityGvrEvent eventState = InstantPreview.Instance.events.Dequeue();
                    switch (eventState.type)
                    {
                    case InstantPreview.GvrEventType.GVR_EVENT_NONE:
                        state.eventType = GvrEventType.Invalid;
                        break;

                    case InstantPreview.GvrEventType.GVR_EVENT_RECENTER:
                        state.eventType = GvrEventType.Recenter;
                        break;

                    case InstantPreview.GvrEventType.GVR_EVENT_SAFETY_REGION_EXIT:
                        state.eventType = GvrEventType.SafetyRegionExit;
                        break;

                    case InstantPreview.GvrEventType.GVR_EVENT_SAFETY_REGION_ENTER:
                        state.eventType = GvrEventType.SafetyRegionEnter;
                        break;

                    case InstantPreview.GvrEventType.GVR_EVENT_HEAD_TRACKING_RESUMED:
                        // Currently not supported.
                        state.eventType = GvrEventType.Invalid;
                        break;

                    case InstantPreview.GvrEventType.GVR_EVENT_HEAD_TRACKING_PAUSED:
                        // Currently not supported.
                        state.eventType = GvrEventType.Invalid;
                        break;
                    }

                    state.eventFlags       = (int)eventState.flags;
                    state.eventTimestampNs = eventState.timestamp;

                    // Only add recenter-specific fields if this is a recenter event.
                    if (eventState.type == InstantPreview.GvrEventType.GVR_EVENT_RECENTER)
                    {
                        switch (eventState.gvr_recenter_event_data.recenter_type)
                        {
                        case InstantPreview.GvrRecenterEventType.GVR_RECENTER_EVENT_NONE:
                            state.recenterEventType = GvrRecenterEventType.Invalid;
                            break;

                        case InstantPreview.GvrRecenterEventType.GVR_RECENTER_EVENT_RESTART:
                            state.recenterEventType = GvrRecenterEventType.RecenterEventRestart;
                            break;

                        case InstantPreview.GvrRecenterEventType.GVR_RECENTER_EVENT_ALIGNED:
                            state.recenterEventType = GvrRecenterEventType.RecenterEventAligned;
                            break;

                        case InstantPreview.GvrRecenterEventType.GVR_RECENTER_EVENT_DON:
                            // Currently not supported.
                            state.recenterEventType = GvrRecenterEventType.Invalid;
                            break;
                        }

                        state.recenterEventFlags = eventState.gvr_recenter_event_data.recenter_event_flags;
                        GvrMathHelpers.GvrMatrixToUnitySpace(
                            eventState.gvr_recenter_event_data.start_space_from_tracking_space_transform,
                            out state.recenteredPosition,
                            out state.recenteredRotation);
                    }
                }
                else
                {
                    state.eventType = GvrEventType.Invalid;
                }
            }

            return;
#endif // UNITY_ANDROID && UNITY_EDITOR
            // Events are unavailable through emulation.
        }
Exemplo n.º 5
0
 public void PollEventState(ref HeadsetState state)
 {
     // Emulation coming soon.
 }
Exemplo n.º 6
0
 public void PollEventState(ref HeadsetState state)
 {
 }