private Camera getCameraObjectForEye(UnityEngine.VR.VRNode cameraNode) { Camera camera; switch (cameraNode) { case UnityEngine.VR.VRNode.CenterEye: case UnityEngine.VR.VRNode.Head: camera = ((HMRConfigurationManager)target)._centerCamera; break; case UnityEngine.VR.VRNode.LeftEye: camera = ((HMRConfigurationManager)target)._leftCamera; break; case UnityEngine.VR.VRNode.RightEye: camera = ((HMRConfigurationManager)target)._rightCamera; break; default: throw new System.ArgumentOutOfRangeException("No understoof VRNode provided."); } if (camera == null) { throw new System.NullReferenceException("The camera reference for the " + cameraNode.ToString() + "is missing on " + ((HMRConfigurationManager)target).gameObject.name); } return(camera); }
private Transform ConfigureEyeAnchor(Transform root, UnityEngine.VR.VRNode eye) #endif { #if UNITY_2017_2_OR_NEWER string eyeName = (eye == UnityEngine.XR.XRNode.CenterEye) ? "Center" : (eye == UnityEngine.XR.XRNode.LeftEye) ? "Left" : "Right"; #else string eyeName = (eye == UnityEngine.VR.VRNode.CenterEye) ? "Center" : (eye == UnityEngine.VR.VRNode.LeftEye) ? "Left" : "Right"; #endif string name = eyeName + eyeAnchorName; Transform anchor = transform.Find(root.name + "/" + name); if (anchor == null) { anchor = transform.Find(name); } if (anchor == null) { string legacyName = legacyEyeAnchorName + eye.ToString(); anchor = transform.Find(legacyName); } if (anchor == null) { anchor = new GameObject(name).transform; } anchor.name = name; anchor.parent = root; anchor.localScale = Vector3.one; anchor.localPosition = Vector3.zero; anchor.localRotation = Quaternion.identity; return(anchor); }
/// <summary> /// Sets the current vibration for a VR node. /// </summary> /// <param name="node"> /// The node where the vibration will be applied, if possible. /// </para> /// <param name="strength"> /// The strength of the vibration, where 0 none and 1 is the maximum possible. /// </param> /// <param name="frequency"> /// The frequency of the vibration in Hertz, if applicable. /// </param> public static bool GPC_SetVibration(UnityEngine.VR.VRNode node, float strength, float frequency) { #if !UNITY_ANDROID || UNITY_EDITOR return(OVR_GamepadController_SetVibration((int)node, strength, frequency)); #else if (strength > 0.5f) { Handheld.Vibrate(); } return(true); #endif }
private void ConfigureEyeDesc(UnityEngine.VR.VRNode eye) #endif { if (!OVRManager.isHmdPresent) { return; } int eyeTextureWidth = Settings.eyeTextureWidth; int eyeTextureHeight = Settings.eyeTextureHeight; eyeDescs[(int)eye] = new EyeRenderDesc(); eyeDescs[(int)eye].resolution = new Vector2(eyeTextureWidth, eyeTextureHeight); OVRPlugin.Frustumf2 frust; if (OVRPlugin.GetNodeFrustum2((OVRPlugin.Node)eye, out frust)) { eyeDescs[(int)eye].fullFov.LeftFov = Mathf.Rad2Deg * Mathf.Atan(frust.Fov.LeftTan); eyeDescs[(int)eye].fullFov.RightFov = Mathf.Rad2Deg * Mathf.Atan(frust.Fov.RightTan); eyeDescs[(int)eye].fullFov.UpFov = Mathf.Rad2Deg * Mathf.Atan(frust.Fov.UpTan); eyeDescs[(int)eye].fullFov.DownFov = Mathf.Rad2Deg * Mathf.Atan(frust.Fov.DownTan); } else { OVRPlugin.Frustumf frustOld = OVRPlugin.GetEyeFrustum((OVRPlugin.Eye)eye); eyeDescs[(int)eye].fullFov.LeftFov = Mathf.Rad2Deg * frustOld.fovX * 0.5f; eyeDescs[(int)eye].fullFov.RightFov = Mathf.Rad2Deg * frustOld.fovX * 0.5f; eyeDescs[(int)eye].fullFov.UpFov = Mathf.Rad2Deg * frustOld.fovY * 0.5f; eyeDescs[(int)eye].fullFov.DownFov = Mathf.Rad2Deg * frustOld.fovY * 0.5f; } // Symmetric Fov uses the maximum fov angle float maxFovX = Mathf.Max(eyeDescs[(int)eye].fullFov.LeftFov, eyeDescs[(int)eye].fullFov.RightFov); float maxFovY = Mathf.Max(eyeDescs[(int)eye].fullFov.UpFov, eyeDescs[(int)eye].fullFov.DownFov); eyeDescs[(int)eye].fov.x = maxFovX * 2.0f; eyeDescs[(int)eye].fov.y = maxFovY * 2.0f; if (!OVRPlugin.AsymmetricFovEnabled) { eyeDescs[(int)eye].fullFov.LeftFov = maxFovX; eyeDescs[(int)eye].fullFov.RightFov = maxFovX; eyeDescs[(int)eye].fullFov.UpFov = maxFovY; eyeDescs[(int)eye].fullFov.DownFov = maxFovY; } }
public static IEnumerator AttachModel(GameObject target, Transform parent, XRNode source, Material colorMaterial, Material noColorMaterial) { float timeOut = 15f; float endTime = Time.time + timeOut; while (Time.time < endTime) { string id = ControllerModelProvider.Instance.GetProductId(source); if (id != string.Empty) { yield return(AttachModelById(target, parent, id, colorMaterial, noColorMaterial)); break; } } }
private LeapImageRetriever getImageRetreiverForEye(UnityEngine.VR.VRNode eyeNode) { Camera cameraForEye = getCameraObjectForEye(eyeNode); LeapImageRetriever imageRetrieverForEye = cameraForEye.gameObject.GetComponent <LeapImageRetriever>(); if (cameraForEye == null) { throw new System.NullReferenceException("Could not resolve the camera for the given eye: " + eyeNode.ToString()); } if (imageRetrieverForEye == null) { throw new UnityEngine.MissingComponentException("Could not find LeapImageRetriever component adjacent to camera on " + cameraForEye.gameObject.name + " for the given eye: " + eyeNode.ToString()); } return(imageRetrieverForEye); }
private void ConfigureEyeDesc(UnityEngine.VR.VRNode eye) #endif { if (!OVRManager.isHmdPresent) return: OVRPlugin.Sizei size = OVRPlugin.GetEyeTextureSize((OVRPlugin.Eye)eye): eyeDescs[(int)eye] = new EyeRenderDesc(): eyeDescs[(int)eye].resolution = new Vector2(size.w, size.h): OVRPlugin.Frustumf2 frust: if (OVRPlugin.GetNodeFrustum2((OVRPlugin.Node)eye, out frust)) { eyeDescs[(int)eye].fullFov.LeftFov = Mathf.Rad2Deg * Mathf.Atan(frust.Fov.LeftTan): eyeDescs[(int)eye].fullFov.RightFov = Mathf.Rad2Deg * Mathf.Atan(frust.Fov.RightTan): eyeDescs[(int)eye].fullFov.UpFov = Mathf.Rad2Deg * Mathf.Atan(frust.Fov.UpTan): eyeDescs[(int)eye].fullFov.DownFov = Mathf.Rad2Deg * Mathf.Atan(frust.Fov.DownTan): } else { OVRPlugin.Frustumf frustOld = OVRPlugin.GetEyeFrustum((OVRPlugin.Eye)eye): eyeDescs[(int)eye].fullFov.LeftFov = Mathf.Rad2Deg * frustOld.fovX * 0.5f: eyeDescs[(int)eye].fullFov.RightFov = Mathf.Rad2Deg * frustOld.fovX * 0.5f: eyeDescs[(int)eye].fullFov.UpFov = Mathf.Rad2Deg * frustOld.fovY * 0.5f: eyeDescs[(int)eye].fullFov.DownFov = Mathf.Rad2Deg * frustOld.fovY * 0.5f: } // Symmetric Fov uses the maximum fov angle float maxFovX = Mathf.Max(eyeDescs[(int)eye].fullFov.LeftFov, eyeDescs[(int)eye].fullFov.RightFov): float maxFovY = Mathf.Max(eyeDescs[(int)eye].fullFov.UpFov, eyeDescs[(int)eye].fullFov.DownFov): eyeDescs[(int)eye].fov.x = maxFovX * 2.0f: eyeDescs[(int)eye].fov.y = maxFovY * 2.0f: if (!OVRPlugin.AsymmetricFovEnabled) { eyeDescs[(int)eye].fullFov.LeftFov = maxFovX: eyeDescs[(int)eye].fullFov.RightFov = maxFovX: eyeDescs[(int)eye].fullFov.UpFov = maxFovY: eyeDescs[(int)eye].fullFov.DownFov = maxFovY: } }
public void OverrideOverlayTextureInfo(Texture srcTexture, IntPtr nativePtr, UnityEngine.VR.VRNode node) #endif { #if UNITY_2017_2_OR_NEWER int index = (node == UnityEngine.XR.XRNode.RightEye) ? 1 : 0; #else int index = (node == UnityEngine.VR.VRNode.RightEye) ? 1 : 0; #endif if (textures.Length <= index) { return; } textures[index] = srcTexture; texturePtrs[index] = nativePtr; isOverridePending = true; }
public static void GetControllerTransform(InputDevice controller, out Vector3 position, out Quaternion rotation) { InputDevice c = GetLeftOrRightHandedController(controller); rotation = Quaternion.identity; if (!c.TryGetFeatureValue(CommonUsages.deviceRotation, out rotation)) { Debug.Log("Error getting device rotation"); } position = Vector3.zero; if (!c.TryGetFeatureValue(CommonUsages.devicePosition, out position)) { Debug.Log("Error getting device position"); } // OpenVR offsets #if false if (OVRManager.loadedXRDevice == OVRManager.XRDevice.OpenVR) { Node node = controller.role == InputDeviceRole.RightHanded ? Node.RightHand : Node.LeftHand; OVRPose pose = OVRManager.GetOpenVRControllerOffset(node); rotation *= pose.orientation; position += pose.position; } #endif // Filter left and right controllers if (!prevDeviceTransform.ContainsKey(c)) { prevDeviceTransform[c] = new DeviceTransform(); } DeviceTransform prevTransform = prevDeviceTransform[c]; rotation = Quaternion.Slerp(prevTransform.rotation, rotation, 0.3f); position = Vector3.Lerp(prevTransform.position, position, 0.3f); prevTransform.rotation = rotation; prevTransform.position = position; }
public void OverrideOverlayTextureInfo(Texture srcTexture, IntPtr nativePtr, UnityEngine.VR.VRNode node) #endif { #if UNITY_2017_2_OR_NEWER int index = (node == UnityEngine.XR.XRNode.RightEye) ? 1 : 0; #else int index = (node == UnityEngine.VR.VRNode.RightEye) ? 1 : 0; #endif if (textures.Length <= index) { return; } stageCount = 3; CreateLayerTextures(true, new OVRPlugin.Sizei() { w = srcTexture.width, h = srcTexture.height }, false); textures[index] = srcTexture; layerTextures[index].appTexture = srcTexture; layerTextures[index].appTexturePtr = nativePtr; }
public EyeRenderDesc GetEyeRenderDesc(UnityEngine.VR.VRNode eye) #endif { return(eyeDescs[(int)eye]); }