private static void CreateFile(string fullPath, CodeCompileUnit compileUnit)
        {
            // Generate the code with the C# code provider.
            CSharpCodeProvider provider = new CSharpCodeProvider();

            // Build the output file name.
            string fullSourceFilePath = fullPath;
            //Debug.Log("[SteamVR] Writing class to: " + fullSourceFilePath);

            string path = GetClassPath();

            string[] parts = path.Split('/');

            for (int partIndex = 0; partIndex < parts.Length - 1; partIndex++)
            {
                string directoryPath = string.Join("/", parts.Take(partIndex + 1).ToArray());
                if (Directory.Exists(directoryPath) == false)
                {
                    Directory.CreateDirectory(directoryPath);
                    //Debug.Log("[SteamVR] Created directory: " + directoryPath);
                }
            }

            string   priorMD5 = null;
            FileInfo file     = new FileInfo(fullSourceFilePath);

            if (file.Exists)
            {
                file.IsReadOnly = false;
                priorMD5        = SteamVR_Utils.GetBadMD5HashFromFile(fullSourceFilePath);
            }

            // Create a TextWriter to a StreamWriter to the output file.
            using (StreamWriter sw = new StreamWriter(fullSourceFilePath, false))
            {
                IndentedTextWriter tw = new IndentedTextWriter(sw, "    ");

                // Generate source code using the code provider.
                provider.GenerateCodeFromCompileUnit(compileUnit, tw,
                                                     new CodeGeneratorOptions()
                {
                    BracingStyle = "C"
                });

                // Close the output file.
                tw.Close();

                string newMD5 = SteamVR_Utils.GetBadMD5HashFromFile(fullSourceFilePath);

                if (priorMD5 != newMD5)
                {
                    fileChanged = true;
                }
            }

            //Debug.Log("[SteamVR] Complete! Input class at: " + fullSourceFilePath);
        }
Exemple #2
0
        private IEnumerator RenderLoop()
        {
            while (Application.isPlaying)
            {
                yield return(this.waitForEndOfFrame);

                if (!SteamVR_Render.pauseRendering)
                {
                    CVRCompositor compositor = OpenVR.Compositor;
                    if (compositor != null)
                    {
                        if (!compositor.CanRenderScene() || cameras.Length < 1)
                        {
                            continue;
                        }
                        compositor.SetTrackingSpace(SteamVR.settings.trackingSpace);
                        SteamVR_Utils.QueueEventOnRenderThread(201510020);
                        SteamVR.Unity.EventWriteString("[UnityMain] GetNativeTexturePtr - Begin");
                        SteamVR_Camera.GetSceneTexture(this.cameras[0].GetComponent <Camera>()).GetNativeTexturePtr();
                        SteamVR.Unity.EventWriteString("[UnityMain] GetNativeTexturePtr - End");
                        compositor.GetLastPoses(this.poses, this.gamePoses);
                        SteamVR_Events.NewPoses.Send(this.poses);
                        SteamVR_Events.NewPosesApplied.Send();
                    }
                    SteamVR_Overlay instance = SteamVR_Overlay.instance;
                    if (instance != null)
                    {
                        instance.UpdateOverlay();
                    }
                    if (this.CheckExternalCamera())
                    {
                        this.RenderExternalCamera();
                    }
                    SteamVR instance2 = SteamVR.instance;
                    this.RenderEye(instance2, EVREye.Eye_Left);
                    this.RenderEye(instance2, EVREye.Eye_Right);
                    foreach (SteamVR_Camera steamVR_Camera in this.cameras)
                    {
                        steamVR_Camera.transform.localPosition = Vector3.zero;
                        steamVR_Camera.transform.localRotation = Quaternion.identity;
                    }
                    if (this.cameraMask != null)
                    {
                        this.cameraMask.Clear();
                    }
                }
            }
            yield break;
        }
Exemple #3
0
        void OnRenderImage(RenderTexture src, RenderTexture dest)
        {
            if (SteamVR_Render.Top() == this)
            {
                int eventID;
                if (SteamVR_Render.eye == EVREye.Eye_Left)
                {
                    // Get gpu started on work early to avoid bubbles at the top of the frame.
                    SteamVR_Utils.QueueEventOnRenderThread(SteamVR.OpenVRMagic.k_nRenderEventID_Flush);

                    eventID = SteamVR.OpenVRMagic.k_nRenderEventID_SubmitL;
                }
                else
                {
                    eventID = SteamVR.OpenVRMagic.k_nRenderEventID_SubmitR;
                }

                // Queue up a call on the render thread to Submit our render target to the compositor.
                SteamVR_Utils.QueueEventOnRenderThread(eventID);
            }
            if (SteamVR_Camera.doomp)
            {
                Debug.Log(Time.frameCount.ToString() + "/Camera_OnRenderImage");
                DumpRenderTexture(src, Application.streamingAssetsPath + "/Camera_OnRenderImage_src.png");
            }

            RenderTexture.active = dest;
            SteamVR_Camera.blitMaterial.mainTexture = src;

            GL.PushMatrix();
            GL.LoadOrtho();
            SteamVR_Camera.blitMaterial.SetPass(0);
            GL.Begin(7);
            GL.TexCoord2(0.0f, 0.0f); GL.Vertex3(-1, 1, 0);
            GL.TexCoord2(1.0f, 0.0f); GL.Vertex3(1, 1, 0);
            GL.TexCoord2(1.0f, 1.0f); GL.Vertex3(1, -1, 0);
            GL.TexCoord2(0.0f, 1.0f); GL.Vertex3(-1, -1, 0);
            GL.End();
            GL.PopMatrix();


            if (SteamVR_Camera.doomp)
            {
                DumpRenderTexture(dest, Application.streamingAssetsPath + "/Camera_OnRenderImage_dst.png");
            }

            RenderTexture.active = null;
        }
        private static MethodInfo GetMethod(string methodName, Type[] parameters = null)
        {
            if (xrMetadataStoreType == null)
            {
                xrMetadataStoreType = SteamVR_Utils.FindType("UnityEditor.XR.Management.Metadata.XRPackageMetadataStore");
            }

            if (parameters == null)
            {
                return(xrMetadataStoreType.GetMethod(methodName, BindingFlags.Static | BindingFlags.NonPublic));
            }
            else
            {
                return(xrMetadataStoreType.GetMethod(methodName, BindingFlags.Static | BindingFlags.NonPublic, null, parameters, null));
            }
        }
        private static void CreateFile(string fullPath, CodeCompileUnit compileUnit)
        {
            // Generate the code with the C# code provider.
            CSharpCodeProvider provider = new CSharpCodeProvider();

            // Build the output file name.
            string fullSourceFilePath = fullPath;
            //Debug.Log("[SteamVR] Writing class to: " + fullSourceFilePath);

            string path = GetClassPath();

            string   priorMD5 = null;
            FileInfo file     = new FileInfo(fullSourceFilePath);

            if (file.Exists)
            {
                file.IsReadOnly = false;
                priorMD5        = SteamVR_Utils.GetBadMD5HashFromFile(fullSourceFilePath);
            }

            // Create a TextWriter to a StreamWriter to the output file.
            using (StreamWriter sw = new StreamWriter(fullSourceFilePath, false))
            {
                IndentedTextWriter tw = new IndentedTextWriter(sw, "    ");

                // Generate source code using the code provider.
                provider.GenerateCodeFromCompileUnit(compileUnit, tw,
                                                     new CodeGeneratorOptions()
                {
                    BracingStyle = "C"
                });

                // Close the output file.
                tw.Close();

                string newMD5 = SteamVR_Utils.GetBadMD5HashFromFile(fullSourceFilePath);

                if (priorMD5 != newMD5)
                {
                    fileChanged = true;
                }
            }

            //Debug.Log("[SteamVR] Complete! Input class at: " + fullSourceFilePath);
        }
Exemple #6
0
        /// <summary>
        /// SteamVR keeps a log of past poses so you can retrieve old poses or estimated poses in the future by passing in a secondsFromNow value that is negative or positive.
        /// </summary>
        /// <param name="secondsFromNow">The time offset in the future (estimated) or in the past (previously recorded) you want to get data from</param>
        /// <returns>true if we successfully returned a pose</returns>
        public bool GetPoseAtTimeOffset(float secondsFromNow, out Vector3 positionAtTime, out Quaternion rotationAtTime, out Vector3 velocityAtTime, out Vector3 angularVelocityAtTime)
        {
            EVRInputError err = OpenVR.Input.GetPoseActionDataRelativeToNow(handle, universeOrigin, secondsFromNow, ref tempPoseActionData, poseActionData_size, inputSourceHandle);

            if (err != EVRInputError.None)
            {
                Debug.LogError("<b>[SteamVR]</b> GetPoseActionData error (" + fullPath + "): " + err.ToString() + " handle: " + handle.ToString()); //todo: this should be an error

                velocityAtTime        = Vector3.zero;
                angularVelocityAtTime = Vector3.zero;
                positionAtTime        = Vector3.zero;
                rotationAtTime        = Quaternion.identity;
                return(false);
            }

            velocityAtTime        = GetUnityCoordinateVelocity(tempPoseActionData.pose.vVelocity);
            angularVelocityAtTime = GetUnityCoordinateAngularVelocity(tempPoseActionData.pose.vAngularVelocity);
            positionAtTime        = SteamVR_Utils.GetPosition(tempPoseActionData.pose.mDeviceToAbsoluteTracking);
            rotationAtTime        = SteamVR_Utils.GetRotation(tempPoseActionData.pose.mDeviceToAbsoluteTracking);

            return(true);
        }
Exemple #7
0
        /// <summary>
        /// Load from disk and deserialize the actions file
        /// </summary>
        /// <param name="force">Force a refresh of this file from disk</param>
        public static bool InitializeFile(bool force = false)
        {
            string projectPath = Application.dataPath;
            int    lastIndex   = projectPath.LastIndexOf("/");

            projectPath     = projectPath.Remove(lastIndex, projectPath.Length - lastIndex);
            actionsFilePath = Path.Combine(projectPath, SteamVR_Settings.instance.actionsFilePath);

            string jsonText = null;

            if (File.Exists(actionsFilePath))
            {
                jsonText = System.IO.File.ReadAllText(actionsFilePath);
            }
            else
            {
                Debug.LogErrorFormat("[SteamVR] Actions file does not exist in project root: {0}", actionsFilePath);
                return(false);
            }

            if (fileInitialized == true || (fileInitialized == true && force == false))
            {
                string newHash = SteamVR_Utils.GetBadMD5Hash(jsonText);

                if (newHash == actionFileHash)
                {
                    return(true);
                }

                actionFileHash = newHash;
            }

            actionFile = Newtonsoft.Json.JsonConvert.DeserializeObject <SteamVR_Input_ActionFile>(jsonText);
            actionFile.InitializeHelperLists();
            fileInitialized = true;
            return(true);
        }
        protected IEnumerator DoRangeOfMotionBlend(EVRSkeletalMotionRange oldRangeOfMotion, EVRSkeletalMotionRange newRangeOfMotion, float overTime)
        {
            float startTime = Time.time;
            float endTime   = startTime + overTime;

            while (Time.time < endTime)
            {
                yield return(null);

                float lerp = (Time.time - startTime) / overTime;

                if (skeletonBlend > 0)
                {
                    skeletonAction.SetRangeOfMotion(oldRangeOfMotion);
                    skeletonAction.UpdateValueWithoutEvents();
                    CopyBonePositions(oldROMPositionBuffer);
                    CopyBoneRotations(oldROMRotationBuffer);

                    skeletonAction.SetRangeOfMotion(newRangeOfMotion);
                    skeletonAction.UpdateValueWithoutEvents();
                    CopyBonePositions(newROMPositionBuffer);
                    CopyBoneRotations(newROMRotationBuffer);

                    for (int boneIndex = 0; boneIndex < bones.Length; boneIndex++)
                    {
                        if (bones[boneIndex] == null)
                        {
                            continue;
                        }

                        if (SteamVR_Utils.IsValid(newROMRotationBuffer[boneIndex]) == false || SteamVR_Utils.IsValid(oldROMRotationBuffer[boneIndex]) == false)
                        {
                            continue;
                        }

                        Vector3    blendedRangeOfMotionPosition = Vector3.Lerp(oldROMPositionBuffer[boneIndex], newROMPositionBuffer[boneIndex], lerp);
                        Quaternion blendedRangeOfMotionRotation = Quaternion.Lerp(oldROMRotationBuffer[boneIndex], newROMRotationBuffer[boneIndex], lerp);

                        if (skeletonBlend < 1)
                        {
                            if (blendPoser != null)
                            {
                                SetBonePosition(boneIndex, Vector3.Lerp(blendSnapshot.bonePositions[boneIndex], blendedRangeOfMotionPosition, skeletonBlend));
                                SetBoneRotation(boneIndex, Quaternion.Lerp(blendSnapshot.boneRotations[boneIndex], blendedRangeOfMotionRotation, skeletonBlend));
                            }
                            else
                            {
                                SetBonePosition(boneIndex, Vector3.Lerp(bones[boneIndex].localPosition, blendedRangeOfMotionPosition, skeletonBlend));
                                SetBoneRotation(boneIndex, Quaternion.Lerp(bones[boneIndex].localRotation, blendedRangeOfMotionRotation, skeletonBlend));
                            }
                        }
                        else
                        {
                            SetBonePosition(boneIndex, blendedRangeOfMotionPosition);
                            SetBoneRotation(boneIndex, blendedRangeOfMotionRotation);
                        }
                    }
                }

                if (onBoneTransformsUpdated != null)
                {
                    onBoneTransformsUpdated.Invoke(this, inputSource);
                }
                if (onBoneTransformsUpdatedEvent != null)
                {
                    onBoneTransformsUpdatedEvent.Invoke(this, inputSource);
                }
            }

            rangeOfMotionBlendRoutine = null;
        }
        public void UpdateComponents(CVRRenderModels renderModels)
        {
            if (renderModels == null)
            {
                return;
            }

            if (transform.childCount == 0)
            {
                return;
            }

            if (nameCache == null)
            {
                nameCache = new Dictionary <int, string>();
            }

            for (int childIndex = 0; childIndex < transform.childCount; childIndex++)
            {
                Transform child = transform.GetChild(childIndex);

                // Cache names since accessing an object's name allocate memory.
                string componentName;
                if (!nameCache.TryGetValue(child.GetInstanceID(), out componentName))
                {
                    componentName = child.name;
                    nameCache.Add(child.GetInstanceID(), componentName);
                }

                var componentState = new RenderModel_ComponentState_t();
                if (!renderModels.GetComponentStateForDevicePath(renderModelName, componentName,
                                                                 SteamVR_Input_Source.GetHandle(inputSource), ref controllerModeState, ref componentState))
                {
                    continue;
                }

                child.localPosition = SteamVR_Utils.GetPosition(componentState.mTrackingToComponentRenderModel);
                child.localRotation = SteamVR_Utils.GetRotation(componentState.mTrackingToComponentRenderModel);

                Transform attach = null;
                for (int childChildIndex = 0; childChildIndex < child.childCount; childChildIndex++)
                {
                    Transform childChild      = child.GetChild(childChildIndex);
                    int       childInstanceID = childChild.GetInstanceID();
                    string    childName;
                    if (!nameCache.TryGetValue(childInstanceID, out childName))
                    {
                        childName = childChild.name;
                        nameCache.Add(childInstanceID, componentName);
                    }

                    if (childName == SteamVR_RenderModel.k_localTransformName)
                    {
                        attach = childChild;
                    }
                }

                if (attach != null)
                {
                    attach.position =
                        transform.TransformPoint(SteamVR_Utils.GetPosition(componentState.mTrackingToComponentLocal));
                    attach.rotation = transform.rotation *
                                      SteamVR_Utils.GetRotation(componentState.mTrackingToComponentLocal);

                    initializedAttachPoints = true;
                }

                bool visible = (componentState.uProperties & (uint)EVRComponentProperty.IsVisible) != 0;
                if (visible != child.gameObject.activeSelf)
                {
                    child.gameObject.SetActive(visible);
                }
            }
        }
Exemple #10
0
 public void Interpolate(RigidTransform to, float t)
 {
     pos = SteamVR_Utils.Lerp(pos, to.pos, t);
     rot = SteamVR_Utils.Slerp(rot, to.rot, t);
 }
        protected IEnumerator DoRangeOfMotionBlend(EVRSkeletalMotionRange oldRangeOfMotion, EVRSkeletalMotionRange newRangeOfMotion, float overTime)
        {
            float startTime = Time.time;
            float endTime   = startTime + overTime;

            Vector3[]    oldBonePositions;
            Quaternion[] oldBoneRotations;

            Vector3[]    newBonePositions;
            Quaternion[] newBoneRotations;

            while (Time.time < endTime)
            {
                yield return(null);

                float lerp = (Time.time - startTime) / overTime;

                if (skeletonBlend > 0)
                {
                    skeletonAction.SetRangeOfMotion(inputSource, oldRangeOfMotion);
                    skeletonAction.UpdateValue(inputSource, true);
                    oldBonePositions = (Vector3[])GetBonePositions(inputSource).Clone();
                    oldBoneRotations = (Quaternion[])GetBoneRotations(inputSource).Clone();

                    skeletonAction.SetRangeOfMotion(inputSource, newRangeOfMotion);
                    skeletonAction.UpdateValue(inputSource, true);
                    newBonePositions = GetBonePositions(inputSource);
                    newBoneRotations = GetBoneRotations(inputSource);

                    for (int boneIndex = 0; boneIndex < bones.Length; boneIndex++)
                    {
                        if (bones[boneIndex] == null)
                        {
                            continue;
                        }

                        if (SteamVR_Utils.IsValid(newBoneRotations[boneIndex]) == false || SteamVR_Utils.IsValid(oldBoneRotations[boneIndex]) == false)
                        {
                            continue;
                        }

                        Vector3    blendedRangeOfMotionPosition = Vector3.Lerp(oldBonePositions[boneIndex], newBonePositions[boneIndex], lerp);
                        Quaternion blendedRangeOfMotionRotation = Quaternion.Lerp(oldBoneRotations[boneIndex], newBoneRotations[boneIndex], lerp);

                        if (skeletonBlend < 1)
                        {
                            SetBonePosition(boneIndex, Vector3.Lerp(bones[boneIndex].localPosition, blendedRangeOfMotionPosition, skeletonBlend));
                            SetBoneRotation(boneIndex, Quaternion.Lerp(bones[boneIndex].localRotation, blendedRangeOfMotionRotation, skeletonBlend));
                        }
                        else
                        {
                            SetBonePosition(boneIndex, blendedRangeOfMotionPosition);
                            SetBoneRotation(boneIndex, blendedRangeOfMotionRotation);
                        }
                    }
                }
            }


            rangeOfMotionBlendRoutine = null;
        }
 /// <summary>The last local rotation of the pose relative to the center of the tracked space.</summary>
 /// <param name="inputSource">The device you would like to get data from. Any if the action is not device specific.</param>
 public Quaternion GetLastLocalRotation(SteamVR_Input_Sources inputSource)
 {
     return(SteamVR_Utils.GetRotation(lastPoseActionData[inputSource].pose.mDeviceToAbsoluteTracking));
 }
Exemple #13
0
        public static Mesh CreateHiddenAreaMesh(HiddenAreaMesh_t src, VRTextureBounds_t bounds)
        {
            if (src.unTriangleCount == 0u)
            {
                return(null);
            }
            float[] array = new float[src.unTriangleCount * 3u * 2u];
            Marshal.Copy(src.pVertexData, array, 0, array.Length);
            Vector3[] array2 = new Vector3[src.unTriangleCount * 3u + 12u];
            int[]     array3 = new int[src.unTriangleCount * 3u + 24u];
            float     num    = 2f * bounds.uMin - 1f;
            float     num2   = 2f * bounds.uMax - 1f;
            float     num3   = 2f * bounds.vMin - 1f;
            float     num4   = 2f * bounds.vMax - 1f;
            int       num5   = 0;
            int       num6   = 0;

            while ((long)num5 < (long)((ulong)(src.unTriangleCount * 3u)))
            {
                float x = SteamVR_Utils.Lerp(num, num2, array[num6++]);
                float y = SteamVR_Utils.Lerp(num3, num4, array[num6++]);
                array2[num5] = new Vector3(x, y, 0f);
                array3[num5] = num5;
                num5++;
            }
            int num7 = (int)(src.unTriangleCount * 3u);
            int num8 = num7;

            array2[num8++] = new Vector3(-1f, -1f, 0f);
            array2[num8++] = new Vector3(num, -1f, 0f);
            array2[num8++] = new Vector3(-1f, 1f, 0f);
            array2[num8++] = new Vector3(num, 1f, 0f);
            array2[num8++] = new Vector3(num2, -1f, 0f);
            array2[num8++] = new Vector3(1f, -1f, 0f);
            array2[num8++] = new Vector3(num2, 1f, 0f);
            array2[num8++] = new Vector3(1f, 1f, 0f);
            array2[num8++] = new Vector3(num, num3, 0f);
            array2[num8++] = new Vector3(num2, num3, 0f);
            array2[num8++] = new Vector3(num, num4, 0f);
            array2[num8++] = new Vector3(num2, num4, 0f);
            int num9 = num7;

            array3[num9++] = num7;
            array3[num9++] = num7 + 1;
            array3[num9++] = num7 + 2;
            array3[num9++] = num7 + 2;
            array3[num9++] = num7 + 1;
            array3[num9++] = num7 + 3;
            array3[num9++] = num7 + 4;
            array3[num9++] = num7 + 5;
            array3[num9++] = num7 + 6;
            array3[num9++] = num7 + 6;
            array3[num9++] = num7 + 5;
            array3[num9++] = num7 + 7;
            array3[num9++] = num7 + 1;
            array3[num9++] = num7 + 4;
            array3[num9++] = num7 + 8;
            array3[num9++] = num7 + 8;
            array3[num9++] = num7 + 4;
            array3[num9++] = num7 + 9;
            array3[num9++] = num7 + 10;
            array3[num9++] = num7 + 11;
            array3[num9++] = num7 + 3;
            array3[num9++] = num7 + 3;
            array3[num9++] = num7 + 11;
            array3[num9++] = num7 + 6;
            return(new Mesh
            {
                vertices = array2,
                triangles = array3,
                bounds = new Bounds(Vector3.zero, new Vector3(float.MaxValue, float.MaxValue, float.MaxValue))
            });
        }
        private IEnumerator RenderLoop()
        {
            while (Application.isPlaying)
            {
                yield return(waitForEndOfFrame);

                if (cameras.Length == 0)
                {
                    continue;
                }

                if (pauseRendering)
                {
                    continue;
                }

                var compositor = OpenVR.Compositor;
                if (compositor != null)
                {
                    if (!compositor.CanRenderScene())
                    {
                        continue;
                    }

                    compositor.SetTrackingSpace(SteamVR.settings.trackingSpace);
                    SteamVR_Utils.QueueEventOnRenderThread(SteamVR.OpenVRMagic.k_nRenderEventID_WaitGetPoses);

                    // Hack to flush render event that was queued in Update (this ensures WaitGetPoses has returned before we grab the new values).
                    SteamVR.OpenVRMagic.EventWriteString("[UnityMain] GetNativeTexturePtr - Begin");
                    SteamVR_Camera.GetSceneTexture(cameras[0].GetComponent <Camera>().allowHDR).GetNativeTexturePtr();
                    SteamVR.OpenVRMagic.EventWriteString("[UnityMain] GetNativeTexturePtr - End");

                    compositor.GetLastPoses(poses, gamePoses);
                    SteamVR_Events.NewPoses.Send(poses);
                    SteamVR_Events.NewPosesApplied.Send();
                }

                var overlay = SteamVR_Overlay.instance;
                if (overlay != null)
                {
                    overlay.UpdateOverlay();
                }

                RenderExternalCamera();


                var vr = SteamVR.instance;
                RenderEye(vr, EVREye.Eye_Left);
                RenderEye(vr, EVREye.Eye_Right);

                // Move cameras back to head position so they can be tracked reliably
                foreach (var c in cameras)
                {
                    c.transform.localPosition = Vector3.zero;
                    c.transform.localRotation = Quaternion.identity;
                }

                if (cameraMask != null)
                {
                    cameraMask.Clear();
                }
            }
        }
Exemple #15
0
 private void FixedUpdate()
 {
     SteamVR_Utils.QueueEventOnRenderThread(201510024);
 }
        void Update()
        {
            if (cameras.Length == 0)
            {
                return;
            }
            this.UpdatePoses();
            // If our FixedUpdate rate doesn't match our render framerate, then catch the handoff here.
            SteamVR_Utils.QueueEventOnRenderThread(SteamVR.OpenVRMagic.k_nRenderEventID_PostPresentHandoff);

            // Force controller update in case no one else called this frame to ensure prevState gets updated.

            // Dispatch any OpenVR events.
            var system = OpenVR.System;

            if (system != null)
            {
                var vrEvent = new VREvent_t();
                var size    = (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(VREvent_t));
                for (int i = 0; i < 64; i++)
                {
                    if (!system.PollNextEvent(ref vrEvent, size))
                    {
                        break;
                    }

                    switch ((EVREventType)vrEvent.eventType)
                    {
                    case EVREventType.VREvent_InputFocusCaptured:     // another app has taken focus (likely dashboard)
                        if (vrEvent.data.process.oldPid == 0)
                        {
                            SteamVR_Events.InputFocus.Send(false);
                        }
                        break;

                    case EVREventType.VREvent_InputFocusReleased:     // that app has released input focus
                        if (vrEvent.data.process.pid == 0)
                        {
                            SteamVR_Events.InputFocus.Send(true);
                        }
                        break;

                    case EVREventType.VREvent_ShowRenderModels:
                        SteamVR_Events.HideRenderModels.Send(false);
                        break;

                    case EVREventType.VREvent_HideRenderModels:
                        SteamVR_Events.HideRenderModels.Send(true);
                        break;

                    default:
                        SteamVR_Events.System((EVREventType)vrEvent.eventType).Send(vrEvent);
                        break;
                    }
                }
            }

            // Ensure various settings to minimize latency.
            Application.targetFrameRate     = -1;
            Application.runInBackground     = true; // don't require companion window focus
            QualitySettings.maxQueuedFrames = -1;
            QualitySettings.vSyncCount      = 0;    // this applies to the companion window
        }
 void FixedUpdate()
 {
     // We want to call this as soon after Present as possible.
     SteamVR_Utils.QueueEventOnRenderThread(SteamVR.OpenVRMagic.k_nRenderEventID_PostPresentHandoff);
 }