private void OnNewPoses(TrackedDevicePose_t[] poses) { // Update eye offsets to account for IPD changes. eyes[0] = new Varjo_SteamVR_Utils.RigidTransform(hmd.GetEyeToHeadTransform(EVREye.Eye_Left)); eyes[1] = new Varjo_SteamVR_Utils.RigidTransform(hmd.GetEyeToHeadTransform(EVREye.Eye_Right)); for (int i = 0; i < poses.Length; i++) { var connected = poses[i].bDeviceIsConnected; if (connected != Varjo_SteamVR.connected[i]) { Varjo_SteamVR_Events.DeviceConnected.Send(i, connected); } } if (poses.Length > OpenVR.k_unTrackedDeviceIndex_Hmd) { var result = poses[OpenVR.k_unTrackedDeviceIndex_Hmd].eTrackingResult; var initializing = result == ETrackingResult.Uninitialized; if (initializing != Varjo_SteamVR.initializing) { Varjo_SteamVR_Events.Initializing.Send(initializing); } var calibrating = result == ETrackingResult.Calibrating_InProgress || result == ETrackingResult.Calibrating_OutOfRange; if (calibrating != Varjo_SteamVR.calibrating) { Varjo_SteamVR_Events.Calibrating.Send(calibrating); } var outOfRange = result == ETrackingResult.Running_OutOfRange || result == ETrackingResult.Calibrating_OutOfRange; if (outOfRange != Varjo_SteamVR.outOfRange) { Varjo_SteamVR_Events.OutOfRange.Send(outOfRange); } } }
private void OnNewPoses(TrackedDevicePose_t[] poses) { if (index == EIndex.None) { return; } var i = (int)index; isValid = false; if (poses.Length <= i) { return; } if (!poses[i].bDeviceIsConnected) { return; } if (!poses[i].bPoseIsValid) { return; } isValid = true; var pose = new Varjo_SteamVR_Utils.RigidTransform(poses[i].mDeviceToAbsoluteTracking); if (origin != null) { transform.position = origin.transform.TransformPoint(pose.pos); transform.rotation = origin.rotation * pose.rot; } else { transform.localPosition = pose.pos; transform.localRotation = pose.rot; } }
private Varjo_SteamVR() { hmd = OpenVR.System; Debug.Log("Connected to " + hmd_TrackingSystemName + ":" + hmd_SerialNumber); //compositor = OpenVR.Compositor; //overlay = OpenVR.Overlay; // Setup render values uint w = 0, h = 0; if (hmd == null) { return; } hmd.GetRecommendedRenderTargetSize(ref w, ref h); sceneWidth = (float)w; sceneHeight = (float)h; float l_left = 0.0f, l_right = 0.0f, l_top = 0.0f, l_bottom = 0.0f; hmd.GetProjectionRaw(EVREye.Eye_Left, ref l_left, ref l_right, ref l_top, ref l_bottom); float r_left = 0.0f, r_right = 0.0f, r_top = 0.0f, r_bottom = 0.0f; hmd.GetProjectionRaw(EVREye.Eye_Right, ref r_left, ref r_right, ref r_top, ref r_bottom); tanHalfFov = new Vector2( Mathf.Max(-l_left, l_right, -r_left, r_right), Mathf.Max(-l_top, l_bottom, -r_top, r_bottom)); textureBounds = new VRTextureBounds_t[2]; textureBounds[0].uMin = 0.5f + 0.5f * l_left / tanHalfFov.x; textureBounds[0].uMax = 0.5f + 0.5f * l_right / tanHalfFov.x; textureBounds[0].vMin = 0.5f - 0.5f * l_bottom / tanHalfFov.y; textureBounds[0].vMax = 0.5f - 0.5f * l_top / tanHalfFov.y; textureBounds[1].uMin = 0.5f + 0.5f * r_left / tanHalfFov.x; textureBounds[1].uMax = 0.5f + 0.5f * r_right / tanHalfFov.x; textureBounds[1].vMin = 0.5f - 0.5f * r_bottom / tanHalfFov.y; textureBounds[1].vMax = 0.5f - 0.5f * r_top / tanHalfFov.y; // Grow the recommended size to account for the overlapping fov sceneWidth = sceneWidth / Mathf.Max(textureBounds[0].uMax - textureBounds[0].uMin, textureBounds[1].uMax - textureBounds[1].uMin); sceneHeight = sceneHeight / Mathf.Max(textureBounds[0].vMax - textureBounds[0].vMin, textureBounds[1].vMax - textureBounds[1].vMin); aspect = tanHalfFov.x / tanHalfFov.y; fieldOfView = 2.0f * Mathf.Atan(tanHalfFov.y) * Mathf.Rad2Deg; eyes = new Varjo_SteamVR_Utils.RigidTransform[] { new Varjo_SteamVR_Utils.RigidTransform(hmd.GetEyeToHeadTransform(EVREye.Eye_Left)), new Varjo_SteamVR_Utils.RigidTransform(hmd.GetEyeToHeadTransform(EVREye.Eye_Right)) }; switch (SystemInfo.graphicsDeviceType) { #if (UNITY_5_4) case UnityEngine.Rendering.GraphicsDeviceType.OpenGL2: #endif case UnityEngine.Rendering.GraphicsDeviceType.OpenGLCore: case UnityEngine.Rendering.GraphicsDeviceType.OpenGLES2: case UnityEngine.Rendering.GraphicsDeviceType.OpenGLES3: textureType = ETextureType.OpenGL; break; #if !(UNITY_5_4) case UnityEngine.Rendering.GraphicsDeviceType.Vulkan: textureType = ETextureType.Vulkan; break; #endif default: textureType = ETextureType.DirectX; break; } Varjo_SteamVR_Events.Initializing.Listen(OnInitializing); Varjo_SteamVR_Events.Calibrating.Listen(OnCalibrating); Varjo_SteamVR_Events.OutOfRange.Listen(OnOutOfRange); Varjo_SteamVR_Events.DeviceConnected.Listen(OnDeviceConnected); Varjo_SteamVR_Events.NewPoses.Listen(OnNewPoses); }