/// <summary> /// Sets the current real-world position of the HMD as the seated origin in IVA. /// </summary> void ResetInitialHmdPosition() { if (hmdIsInitialized) { vrSystem.ResetSeatedZeroPose(); log("Seated pose reset!"); } }
/// <summary> /// Sets the current real-world position of the HMD as the seated origin in IVA. /// </summary> void ResetInitialHmdPosition() { if (hmdIsInitialized) { vrSystem.ResetSeatedZeroPose(); Debug.Log("[KerbalVR] Seated pose reset!"); } }
void Update() { //increase prediction if (Input.GetKeyDown(KeyCode.KeypadPlus)) { predict += 0.01f; log("predict interval set to: " + predict); } //decrease prediction if (Input.GetKeyDown(KeyCode.KeypadMinus)) { predict -= 0.01f; log("predict interval set to: " + predict); } //If Hmd is initialised and key is pressed -> reset position if (Input.GetKeyDown(KeyCode.Keypad0) && HmdOn) { vrSystem.ResetSeatedZeroPose(); log("Seated pose reset!"); } //If Hmd is not initialised and key is pressed -> initialise everything if (Input.GetKeyDown(KeyCode.Keypad0) && !HmdOn) { //get Active Vessel activeVessel = FlightGlobals.ActiveVessel; HmdOn = true; //setup OpenVR setup(); uint renderTextureWidth = 0; uint renderTextureHeight = 0; vrSystem.GetRecommendedRenderTargetSize(ref renderTextureWidth, ref renderTextureHeight); HmdMatrix34_t vrLeftEyeTransform = vrSystem.GetEyeToHeadTransform(EVREye.Eye_Left); HmdMatrix34_t vrRightEyeTransform = vrSystem.GetEyeToHeadTransform(EVREye.Eye_Right); //eyeDiference = (int)(Camera.main.WorldToScreenPoint(new Utils.RigidTransform(vrLeftEyeTransform).pos) - Camera.main.WorldToScreenPoint(new Utils.RigidTransform(vrRightEyeTransform).pos)).magnitude; // skyTexture = new RenderTexture((int)(renderTextureWidth + eyeDiference), (int)renderTextureHeight, 24, RenderTextureFormat.ARGB32); // skyTexture.Create(); hmdLeftEyeRenderTexture = new RenderTexture((int)renderTextureWidth, (int)renderTextureHeight, 24, RenderTextureFormat.ARGB32); hmdLeftEyeRenderTexture.Create(); hmdRightEyeRenderTexture = new RenderTexture((int)renderTextureWidth, (int)renderTextureHeight, 24, RenderTextureFormat.ARGB32); hmdRightEyeRenderTexture.Create(); setupCameras(); //add on vesselchange callback GameEvents.onVesselChange.Add(onVesselChange); } if (HmdOn) { if (!CameraManager.Instance.currentCameraMode.Equals(activeCameraMode)) { if (CameraManager.Instance.currentCameraMode.Equals(CameraManager.CameraMode.Flight) || CameraManager.Instance.currentCameraMode.Equals(CameraManager.CameraMode.External)) { // Camera.main.enabled = true; setRenderTexturesTo(null, null); O_SclaledSpace.enabled = true; O_Galaxy.enabled = true; O_Near.enabled = true; O_Far.enabled = true; //O_Interior.enabled = false; } else { setRenderTexturesTo(null, null); O_SclaledSpace.enabled = false; O_Galaxy.enabled = false; O_Near.enabled = false; O_Far.enabled = false; O_Interior.enabled = false; } } if (CameraManager.Instance.currentCameraMode.Equals(CameraManager.CameraMode.IVA)) { leftStars.Render(); leftSky.Render(); camLeft_Far.Render(); camLeft_Near.Render(); camLeft_Interior.Render(); rightStars.Render(); rightSky.Render(); camRight_Far.Render(); camRight_Near.Render(); camRight_Interior.Render(); } //if someone knows how to fix the other cameras corectly please tell me! else if (CameraManager.Instance.currentCameraMode.Equals(CameraManager.CameraMode.Map)) { O_Galaxy.Render(); O_SclaledSpace.Render(); } else { O_Galaxy.Render(); O_SclaledSpace.Render(); O_Far.Render(); O_Near.Render(); } } }
/*void LateUpdate() * { * if (HmdOn) * { * foreach (int id in leftCameras) * { * * //Left camera position:########################################################## * Camera.allCameras[id].transform.localRotation = hmdTransform.rot; * * // translate the camera to match the position of the left eye, from origin * Camera.allCameras[id].transform.localPosition = new Vector3(0f, 0f, 0f); * Camera.allCameras[id].transform.Translate(hmdLeftEyeTransform.pos); * * // translate the camera to match the position of the HMD * Camera.allCameras[id].transform.localPosition += hmdTransform.pos; * * } * } * }*/ void Update() { if (Input.GetKeyDown(KeyCode.KeypadPlus)) { predict += 0.01f; log("predict interval set to: " + predict); } if (Input.GetKeyDown(KeyCode.KeypadMinus)) { predict -= 0.01f; log("predict interval set to: " + predict); } /* if (Input.GetKeyDown(KeyCode.Keypad5)) * { * log("cameras:"); * foreach (Camera c in Camera.allCameras) * { * log(" " + c.name); * } * }*/ if (Input.GetKeyDown(KeyCode.Keypad0) && HmdOn) { vrSystem.ResetSeatedZeroPose(); log("Seated pose reset!"); } if (Input.GetKeyDown(KeyCode.KeypadMultiply)) { camLeft_Near.cullingMask = camLeft_Near.cullingMask << 1; camRight_Near.cullingMask = camLeft_Near.cullingMask; log(Convert.ToString(camLeft_Near.cullingMask, 2)); if (camLeft_Near.cullingMask == 0) { camLeft_Near.cullingMask = 1; camRight_Near.cullingMask = 1; } } if (Input.GetKeyDown(KeyCode.KeypadDivide)) { camLeft_Near.cullingMask = camLeft_Near.cullingMask >> 1; camRight_Near.cullingMask = camLeft_Near.cullingMask; log(Convert.ToString(camLeft_Near.cullingMask, 2)); if (camLeft_Near.cullingMask == 0) { camLeft_Near.cullingMask = 1; camRight_Near.cullingMask = 1; } } if (Input.GetKeyDown(KeyCode.Keypad2)) { log(" ScaledSpace rot = " + ScaledSpace.Instance.transform.rotation.eulerAngles.ToString()); log(" GalaxyCubeControl rot = " + GalaxyCubeControl.Instance.transform.rotation.eulerAngles.ToString()); log("GalaxyCubeControl tgt rot = " + GalaxyCubeControl.Instance.tgt.transform.rotation.eulerAngles.ToString()); log(" GalaxyCameraControl rot = " + GalaxyCameraControl.Instance.transform.rotation.eulerAngles.ToString()); log(" ScaledCamera rot = " + ScaledCamera.Instance.transform.rotation.eulerAngles.ToString()); } if (HmdOn) { if (Input.GetKeyDown(KeyCode.Keypad1)) { log("L:" + Convert.ToString(camLeft_Near.cullingMask, 2)); log("R:" + Convert.ToString(camRight_Near.cullingMask, 2)); } int tmp = 0; if (Input.GetKey(KeyCode.LeftShift)) { tmp = 10; } else if (Input.GetKey(KeyCode.RightShift)) { tmp = 20; } else if (Input.GetKey(KeyCode.RightControl)) { tmp = 30; } if (Input.GetKeyDown(KeyCode.Alpha0)) { camLeft_Near.cullingMask ^= (1 << 0 + tmp); } if (Input.GetKeyDown(KeyCode.Alpha1)) { camLeft_Near.cullingMask ^= (1 << 1 + tmp); } if (Input.GetKeyDown(KeyCode.Alpha2)) { camLeft_Near.cullingMask ^= (1 << 2 + tmp); } if (Input.GetKeyDown(KeyCode.Alpha3)) { camLeft_Near.cullingMask ^= (1 << 3 + tmp); } if (Input.GetKeyDown(KeyCode.Alpha4)) { camLeft_Near.cullingMask ^= (1 << 4 + tmp); } if (Input.GetKeyDown(KeyCode.Alpha5)) { camLeft_Near.cullingMask ^= (1 << 5 + tmp); } if (Input.GetKeyDown(KeyCode.Alpha6)) { camLeft_Near.cullingMask ^= (1 << 6 + tmp); } if (Input.GetKeyDown(KeyCode.Alpha7)) { camLeft_Near.cullingMask ^= (1 << 7 + tmp); } if (Input.GetKeyDown(KeyCode.Alpha8)) { camLeft_Near.cullingMask ^= (1 << 8 + tmp); } if (Input.GetKeyDown(KeyCode.Alpha9)) { camLeft_Near.cullingMask ^= (1 << 9 + tmp); } camRight_Near.cullingMask = camLeft_Near.cullingMask; if (Input.GetKeyDown(KeyCode.Keypad7)) { if (camRight_Near.transparencySortMode == TransparencySortMode.Default) { camRight_Near.transparencySortMode = TransparencySortMode.Orthographic; camLeft_Near.transparencySortMode = TransparencySortMode.Orthographic; } if (camRight_Near.transparencySortMode == TransparencySortMode.Orthographic) { camRight_Near.transparencySortMode = TransparencySortMode.Perspective; camLeft_Near.transparencySortMode = TransparencySortMode.Perspective; } if (camRight_Near.transparencySortMode == TransparencySortMode.Perspective) { camRight_Near.transparencySortMode = TransparencySortMode.Default; camLeft_Near.transparencySortMode = TransparencySortMode.Default; } } if (Input.GetKeyDown(KeyCode.Keypad8)) { if (camRight_Near.opaqueSortMode == UnityEngine.Rendering.OpaqueSortMode.Default) { camRight_Near.opaqueSortMode = UnityEngine.Rendering.OpaqueSortMode.FrontToBack; camLeft_Near.opaqueSortMode = UnityEngine.Rendering.OpaqueSortMode.FrontToBack; } if (camRight_Near.opaqueSortMode == UnityEngine.Rendering.OpaqueSortMode.FrontToBack) { camRight_Near.opaqueSortMode = UnityEngine.Rendering.OpaqueSortMode.NoDistanceSort; camLeft_Near.opaqueSortMode = UnityEngine.Rendering.OpaqueSortMode.NoDistanceSort; } if (camRight_Near.opaqueSortMode == UnityEngine.Rendering.OpaqueSortMode.NoDistanceSort) { camRight_Near.opaqueSortMode = UnityEngine.Rendering.OpaqueSortMode.Default; camLeft_Near.opaqueSortMode = UnityEngine.Rendering.OpaqueSortMode.Default; } } } if (Input.GetKeyDown(KeyCode.Keypad0) && !HmdOn) { activeVessel = FlightGlobals.ActiveVessel; var goArray = FindObjectsOfType <GameObject>(); /*GameObject tmp = new GameObject(); * tmp.transform.position = activeVessel.transform.position; * tmp.transform.SetParent(activeVessel.transform); * for (var i = 0; i < goArray.Length; i++) * { * if (goArray[i].layer == 16 | goArray[i].layer == 20) * { * log(goArray[i].name); * //Vector3 tmp = goArray[i].transform.position; * * * goArray[i].transform.SetParent(tmp.transform); * interiorModelList.Add(goArray[i]); * } * } * tmp.transform.rotation = activeVessel.transform.rotation; */ HmdOn = true; log("TEST!!!!!!!!!!!!!!!!!!"); log(ScaledSpace.Instance.transform.rotation.eulerAngles.ToString()); //setup OpenVR setup(); int mask = 0; Camera pit = Camera.main; uint renderTextureWidth = 0; uint renderTextureHeight = 0; vrSystem.GetRecommendedRenderTargetSize(ref renderTextureWidth, ref renderTextureHeight); HmdMatrix34_t vrLeftEyeTransform = vrSystem.GetEyeToHeadTransform(EVREye.Eye_Left); HmdMatrix34_t vrRightEyeTransform = vrSystem.GetEyeToHeadTransform(EVREye.Eye_Right); int widthDiference = (int)(Camera.main.WorldToScreenPoint(new Utils.RigidTransform(vrLeftEyeTransform).pos) - Camera.main.WorldToScreenPoint(new Utils.RigidTransform(vrRightEyeTransform).pos)).magnitude; widthDiference = 100; //TODO calculate corectly skyTexture = new RenderTexture((int)(renderTextureWidth + widthDiference), (int)renderTextureHeight, 24, RenderTextureFormat.ARGB32); skyTexture.Create(); hmdLeftEyeRenderTexture = new RenderTexture((int)renderTextureWidth, (int)renderTextureHeight, 24, RenderTextureFormat.ARGB32); hmdLeftEyeRenderTexture.Create(); hmdRightEyeRenderTexture = new RenderTexture((int)renderTextureWidth, (int)renderTextureHeight, 24, RenderTextureFormat.ARGB32); hmdRightEyeRenderTexture.Create(); float max = 0; float[] distances = new float[32]; foreach (string cameraName in cameraNamesToRender) { foreach (Camera camera in Camera.allCameras) { if (cameraName.Equals(camera.name)) { switch (camera.name) { case "GalaxyCamera": O_Galaxy = camera; break; case "Camera ScaledSpace": O_SclaledSpace = camera; break; case "Camera 01": O_Far = camera; break; case "Camera 00": O_Near = camera; break; default: break; } mask |= camera.cullingMask; max = Math.Max(camera.farClipPlane, max); string bitMask = Convert.ToString(camera.cullingMask, 2); for (int i = 0; i < distances.Length; i++) { distances[i] = Math.Max(distances[i], Math.Max(camera.layerCullDistances[i], camera.farClipPlane)); } camera.gameObject.AddOrGetComponent <posTracker>(); log("Camera:"); log(" Name: " + camera.name); log(" mask: " + Convert.ToString(camera.cullingMask, 2)); log(" depth: " + camera.depth); log(""); if (cameraName.Equals("InternalCamera")) { pit = camera; camLeft_Near = camera; //camRight = camera; leftCameras.Add(camera); O_Interior = camera; } if (cameraName.Equals("GalaxyCamera")) { O_Galaxy = camera; } if (cameraName.Equals("Camera ScaledSpace")) { // sky = camera; O_SclaledSpace = camera; log("sky cam rot = " + camera.transform.rotation.eulerAngles.ToString()); } } } } // camRight_Interior = (Camera)Camera.Instantiate(Camera.main, Camera.main.transform.position + new Vector3(0, 0, 0), Camera.main.transform.rotation); // camLeft_Interior = (Camera)Camera.Instantiate(Camera.main, Camera.main.transform.position + new Vector3(0, 0, 0), Camera.main.transform.rotation); camRight_Near = (Camera)Camera.Instantiate(Camera.main, Camera.main.transform.position + new Vector3(0, 0, 0), Camera.main.transform.rotation); camLeft_Near = (Camera)Camera.Instantiate(Camera.main, Camera.main.transform.position + new Vector3(0, 0, 0), Camera.main.transform.rotation); camRight_Far = (Camera)Camera.Instantiate(Camera.main, Camera.main.transform.position + new Vector3(0, 0, 0), Camera.main.transform.rotation); camLeft_Far = (Camera)Camera.Instantiate(Camera.main, Camera.main.transform.position + new Vector3(0, 0, 0), Camera.main.transform.rotation); leftSky = (Camera)Camera.Instantiate(Camera.main, Camera.main.transform.position + new Vector3(0, 0, 0), Camera.main.transform.rotation); rightSky = (Camera)Camera.Instantiate(Camera.main, Camera.main.transform.position + new Vector3(0, 0, 0), Camera.main.transform.rotation); leftStars = (Camera)Camera.Instantiate(Camera.main, Camera.main.transform.position + new Vector3(0, 0, 0), Camera.main.transform.rotation); rightStars = (Camera)Camera.Instantiate(Camera.main, Camera.main.transform.position + new Vector3(0, 0, 0), Camera.main.transform.rotation); leftSky.CopyFrom(O_SclaledSpace); rightSky.CopyFrom(O_SclaledSpace); leftSky.transform.SetParent(activeVessel.transform); rightSky.transform.SetParent(activeVessel.transform); leftStars.CopyFrom(O_Galaxy); rightStars.CopyFrom(O_Galaxy); leftStars.transform.SetParent(activeVessel.transform); rightStars.transform.SetParent(activeVessel.transform); camRight_Near.CopyFrom(O_Near); camLeft_Near.CopyFrom(O_Near); camRight_Near.transform.SetParent(activeVessel.transform); camLeft_Near.transform.SetParent(activeVessel.transform); // camLeft_Interior.CopyFrom(O_Interior); // camRight_Interior.CopyFrom(O_Interior); // camLeft_Interior.transform.SetParent(activeVessel.transform); // camRight_Interior.transform.SetParent(activeVessel.transform); camRight_Far.CopyFrom(O_Far); camLeft_Far.CopyFrom(O_Far); camRight_Far.transform.SetParent(activeVessel.transform); camLeft_Far.transform.SetParent(activeVessel.transform); // stars.clearFlags = CameraClearFlags.Depth; // stars.cullingMask = (1 << 18); //sky.cullingMask = (1 << 9); leftStars.targetTexture = hmdLeftEyeRenderTexture; rightStars.targetTexture = hmdRightEyeRenderTexture; // leftSky.targetTexture = hmdLeftEyeRenderTexture; rightSky.targetTexture = hmdRightEyeRenderTexture; //skyCopySlave = rightSky.gameObject.AddComponent<copySlave>(); // skyCopySlave.leftTarget = hmdLeftEyeRenderTexture; // skyCopySlave.rightTarget = hmdRightEyeRenderTexture; //skyCopySlave.difrence = widthDiference; camLeft_Near.targetTexture = hmdLeftEyeRenderTexture; camRight_Near.targetTexture = hmdRightEyeRenderTexture; // camLeft_Interior.targetTexture = hmdLeftEyeRenderTexture; // camRight_Interior.targetTexture = hmdRightEyeRenderTexture; camLeft_Far.targetTexture = hmdLeftEyeRenderTexture; camRight_Far.targetTexture = hmdRightEyeRenderTexture; leftStars.depth += 4; leftSky.depth += 4; camLeft_Near.depth += 4; camLeft_Far.depth += 4; // camLeft_Interior.depth += 4; // camRight_Interior.depth += 4; //rightSky.depth = -5; // camRight.targetTexture = sky.targetTexture; // camLeft.targetTexture = sky.targetTexture; // camera.targetTexture = hmdLeftEyeRenderTexture; // camRight.cullingMask = (1 << 0) | (1 << 4) | (1 << 10) | (1 << 15) | (1 << 16) | (1 << 20) | (1 << 23); // camLeft.cullingMask = (1 << 0) | (1 << 4) | (1 << 10) | (1 << 15) | (1 << 16) | (1 << 20) | (1 << 23); // 0: ship exterior //15: ground //16: ship interior //TODO change to |= //camRight_Near.cullingMask = 1 << 20 | (1 << 16); //camLeft_Near.cullingMask = 1 << 20 | (1 << 16); // camLeft.clearFlags = CameraClearFlags.Depth; // camRight.clearFlags = CameraClearFlags.Depth; // camLeft_Near.layerCullDistances = distances; // camRight_Near.layerCullDistances = distances; // camLeft.depthTextureMode = DepthTextureMode.Depth; // camRight.depthTextureMode = DepthTextureMode.Depth; //camRight.transparencySortMode = TransparencySortMode.Perspective; //create left slave leftSlave = camLeft_Near.gameObject.AddOrGetComponent <RenderSlave>(); //leftSlave = sky.gameObject.AddOrGetComponent<RenderSlave>(); leftSlave.left = true; // camLeft.cullingMask = (1 << 0) | (1 << 4) | (1 << 9) | (1 << 10) | (1 << 15) | (1 << 16) | (1 << 18) | (1 << 20) | (1 << 23); //camLeft.cullingMask = (1 << 9) | (1 << 15) | (1 << 16) | (1 << 20) | (1 << 32); //camLeft.cullingMask = 0; // camLeft.ResetCullingMatrix(); //camLeft_Near.useOcclusionCulling = true; //camLeft_Near.nearClipPlane = 0.01f; //camLeft_Near.farClipPlane = max; //create right slave rightSlave = camRight_Near.gameObject.AddOrGetComponent <RenderSlave>(); rightSlave.left = false; // camRight.cullingMask = (1 << 0) | (1 << 4) | (1 << 9) | (1 << 10) | (1 << 15) | (1 << 16) | (1 << 18) | (1 << 20) | (1 << 23); // camRight.cullingMask = (1 << 9) | (1 << 15) | (1 << 16) | (1 << 20) | (1 << 32); // camRight.cullingMask = 0; //camRight.ResetCullingMatrix(); // camRight_Near.useOcclusionCulling = true; // // camRight_Near.nearClipPlane = 0.01f; // camRight_Near.farClipPlane = max; //set camera projections: //TODO rewrite HmdMatrix44_t projLeft = vrSystem.GetProjectionMatrix(EVREye.Eye_Left, camLeft_Near.nearClipPlane, camLeft_Near.farClipPlane); HmdMatrix44_t projRight = vrSystem.GetProjectionMatrix(EVREye.Eye_Right, camRight_Near.nearClipPlane, camRight_Near.farClipPlane); camLeft_Near.projectionMatrix = MathUtils.Matrix4x4_OpenVr2UnityFormat(ref projLeft); camRight_Near.projectionMatrix = MathUtils.Matrix4x4_OpenVr2UnityFormat(ref projRight); // HmdMatrix44_t projLeft2 = vrSystem.GetProjectionMatrix(EVREye.Eye_Left, camLeft_Interior.nearClipPlane, camLeft_Interior.farClipPlane); // HmdMatrix44_t projRight2 = vrSystem.GetProjectionMatrix(EVREye.Eye_Right, camRight_Interior.nearClipPlane, camRight_Interior.farClipPlane); // // camLeft_Interior.projectionMatrix = MathUtils.Matrix4x4_OpenVr2UnityFormat(ref projLeft2); // camRight_Interior.projectionMatrix = MathUtils.Matrix4x4_OpenVr2UnityFormat(ref projRight2); HmdMatrix44_t projLeft3 = vrSystem.GetProjectionMatrix(EVREye.Eye_Left, camLeft_Far.nearClipPlane, camLeft_Far.farClipPlane); HmdMatrix44_t projRight3 = vrSystem.GetProjectionMatrix(EVREye.Eye_Right, camRight_Far.nearClipPlane, camRight_Far.farClipPlane); camLeft_Far.projectionMatrix = MathUtils.Matrix4x4_OpenVr2UnityFormat(ref projLeft3); camRight_Far.projectionMatrix = MathUtils.Matrix4x4_OpenVr2UnityFormat(ref projRight3); HmdMatrix44_t projLeft4 = vrSystem.GetProjectionMatrix(EVREye.Eye_Left, leftSky.nearClipPlane, leftSky.farClipPlane); HmdMatrix44_t projRight4 = vrSystem.GetProjectionMatrix(EVREye.Eye_Right, rightSky.nearClipPlane, rightSky.farClipPlane); leftSky.projectionMatrix = MathUtils.Matrix4x4_OpenVr2UnityFormat(ref projLeft4); rightSky.projectionMatrix = MathUtils.Matrix4x4_OpenVr2UnityFormat(ref projRight4); HmdMatrix44_t projLeft5 = vrSystem.GetProjectionMatrix(EVREye.Eye_Left, leftStars.nearClipPlane, leftStars.farClipPlane); HmdMatrix44_t projRight5 = vrSystem.GetProjectionMatrix(EVREye.Eye_Right, rightStars.nearClipPlane, rightStars.farClipPlane); leftStars.projectionMatrix = MathUtils.Matrix4x4_OpenVr2UnityFormat(ref projLeft5); rightStars.projectionMatrix = MathUtils.Matrix4x4_OpenVr2UnityFormat(ref projRight5); // camLeft_Interior.depth = 0; // camLeft_Interior.clearFlags = CameraClearFlags.Skybox; // camLeft_Near.depth = 0; // camLeft_Near.clearFlags = CameraClearFlags.Nothing; // camLeft_Far.depth = -1; // camLeft_Far.clearFlags = CameraClearFlags.Nothing; // leftSky.depth = -2; // leftSky.clearFlags = CameraClearFlags.Nothing; // leftStars.depth = -3; // leftStars.clearFlags = CameraClearFlags.Skybox; // // // // camRight_Interior.depth = 5; // // camRight_Interior.clearFlags = CameraClearFlags.Skybox; // camRight_Near.depth =0; // camRight_Near.clearFlags = CameraClearFlags.Nothing; // camRight_Far.depth = -1; // camRight_Far.clearFlags = CameraClearFlags.Nothing; // rightSky.depth = -2; // rightSky.clearFlags = CameraClearFlags.Nothing; // rightStars.depth = -3; // rightStars.clearFlags = CameraClearFlags.Skybox; //activate slaves posTracker.HmdOn = true; leftSlave.HmdOn = true; rightSlave.HmdOn = true; } }
private void OnGUI() { if (this.overlay == null) { return; } RenderTexture renderTexture = this.overlay.texture as RenderTexture; RenderTexture active = RenderTexture.active; RenderTexture.active = renderTexture; if (Event.current.type == EventType.Repaint) { GL.Clear(false, true, Color.clear); } Rect screenRect = new Rect(0f, 0f, (float)renderTexture.width, (float)renderTexture.height); if (Screen.width < renderTexture.width) { screenRect.width = (float)Screen.width; this.overlay.uvOffset.x = -(float)(renderTexture.width - Screen.width) / (float)(2 * renderTexture.width); } if (Screen.height < renderTexture.height) { screenRect.height = (float)Screen.height; this.overlay.uvOffset.y = (float)(renderTexture.height - Screen.height) / (float)(2 * renderTexture.height); } GUILayout.BeginArea(screenRect); if (this.background != null) { GUI.DrawTexture(new Rect((screenRect.width - (float)this.background.width) / 2f, (screenRect.height - (float)this.background.height) / 2f, (float)this.background.width, (float)this.background.height), this.background); } GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUILayout.FlexibleSpace(); GUILayout.BeginVertical(new GUILayoutOption[0]); if (this.logo != null) { GUILayout.Space(screenRect.height / 2f - this.logoHeight); GUILayout.Box(this.logo, new GUILayoutOption[0]); } GUILayout.Space(this.menuOffset); bool flag = GUILayout.Button("[Esc] - Close menu", new GUILayoutOption[0]); GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUILayout.Label(string.Format("Scale: {0:N4}", this.scale), new GUILayoutOption[0]); float num = GUILayout.HorizontalSlider(this.scale, this.scaleLimits.x, this.scaleLimits.y, new GUILayoutOption[0]); if (num != this.scale) { this.SetScale(num); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUILayout.Label(string.Format("Scale limits:", new object[0]), new GUILayoutOption[0]); string text = GUILayout.TextField(this.scaleLimitX, new GUILayoutOption[0]); if (text != this.scaleLimitX && float.TryParse(text, out this.scaleLimits.x)) { this.scaleLimitX = text; } string text2 = GUILayout.TextField(this.scaleLimitY, new GUILayoutOption[0]); if (text2 != this.scaleLimitY && float.TryParse(text2, out this.scaleLimits.y)) { this.scaleLimitY = text2; } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(new GUILayoutOption[0]); GUILayout.Label(string.Format("Scale rate:", new object[0]), new GUILayoutOption[0]); string text3 = GUILayout.TextField(this.scaleRateText, new GUILayoutOption[0]); if (text3 != this.scaleRateText && float.TryParse(text3, out this.scaleRate)) { this.scaleRateText = text3; } GUILayout.EndHorizontal(); if (SteamVR.active) { SteamVR instance = SteamVR.instance; GUILayout.BeginHorizontal(new GUILayoutOption[0]); float sceneResolutionScale = SteamVR_Camera.sceneResolutionScale; int num2 = (int)(instance.sceneWidth * sceneResolutionScale); int num3 = (int)(instance.sceneHeight * sceneResolutionScale); int num4 = (int)(100f * sceneResolutionScale); GUILayout.Label(string.Format("Scene quality: {0}x{1} ({2}%)", num2, num3, num4), new GUILayoutOption[0]); int num5 = Mathf.RoundToInt(GUILayout.HorizontalSlider((float)num4, 50f, 200f, new GUILayoutOption[0])); if (num5 != num4) { SteamVR_Camera.sceneResolutionScale = (float)num5 / 100f; } GUILayout.EndHorizontal(); } this.overlay.highquality = GUILayout.Toggle(this.overlay.highquality, "High quality", new GUILayoutOption[0]); if (this.overlay.highquality) { this.overlay.curved = GUILayout.Toggle(this.overlay.curved, "Curved overlay", new GUILayoutOption[0]); this.overlay.antialias = GUILayout.Toggle(this.overlay.antialias, "Overlay RGSS(2x2)", new GUILayoutOption[0]); } else { this.overlay.curved = false; this.overlay.antialias = false; } SteamVR_Camera steamVR_Camera = SteamVR_Render.Top(); if (steamVR_Camera != null) { steamVR_Camera.wireframe = GUILayout.Toggle(steamVR_Camera.wireframe, "Wireframe", new GUILayoutOption[0]); SteamVR_Render instance2 = SteamVR_Render.instance; if (instance2.trackingSpace == ETrackingUniverseOrigin.TrackingUniverseSeated) { if (GUILayout.Button("Switch to Standing", new GUILayoutOption[0])) { instance2.trackingSpace = ETrackingUniverseOrigin.TrackingUniverseStanding; } if (GUILayout.Button("Center View", new GUILayoutOption[0])) { CVRSystem system = OpenVR.System; if (system != null) { system.ResetSeatedZeroPose(); } } } else if (GUILayout.Button("Switch to Seated", new GUILayoutOption[0])) { instance2.trackingSpace = ETrackingUniverseOrigin.TrackingUniverseSeated; } } if (GUILayout.Button("Exit", new GUILayoutOption[0])) { Application.Quit(); } GUILayout.Space(this.menuOffset); string environmentVariable = Environment.GetEnvironmentVariable("VR_OVERRIDE"); if (environmentVariable != null) { GUILayout.Label("VR_OVERRIDE=" + environmentVariable, new GUILayoutOption[0]); } GUILayout.Label("Graphics device: " + SystemInfo.graphicsDeviceVersion, new GUILayoutOption[0]); GUILayout.EndVertical(); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.EndArea(); if (this.cursor != null) { float x = Input.mousePosition.x; float top = (float)Screen.height - Input.mousePosition.y; float width = (float)this.cursor.width; float height = (float)this.cursor.height; GUI.DrawTexture(new Rect(x, top, width, height), this.cursor); } RenderTexture.active = active; if (flag) { this.HideMenu(); } }