public void Pasue() { // stop render HMD StopAllCoroutines(); // all subcamera render to screen not rendertexture ThreeGlassesSubCamera[] cams = GameObject.FindObjectsOfType(typeof(ThreeGlassesSubCamera)) as ThreeGlassesSubCamera[]; foreach (var cam in cams) { Camera tempCamera = cam.gameObject.GetComponent <Camera>(); if (ThreeGlassesSubCamera.CameraTypes.Screen != cam.CameraType) { tempCamera.targetTexture = null; } } // destroy plugin ThreeGlassesDllInterface.SZVRPluginDestroy(); // release rendtexture for (var i = 0; i < CAMERA_NUM; i++) { renderTexture[i].Release(); } }
// no wear headdisplay public static bool GetHMDPresent() { bool status = false; if (0 != ThreeGlassesDllInterface.SZVR_GetHMDPresent(ref status)) { status = false; } return(status); }
void Start() { ThreeGlassesUtils.Log("MainCamera init"); // check hmd status bool result = false; if (0 != ThreeGlassesDllInterface.SZVR_GetHMDConnectionStatus(ref result) || !result) { Debug.LogWarning("The Helmet Mounted Display is not connect"); } // get hmd name strPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(64); if (0 != ThreeGlassesDllInterface.SZVR_GetHMDDevName(strPtr)) { hmdName = Marshal.PtrToStringAnsi(strPtr, 64); } if (hmdName == null || hmdName.Length <= 0) { hmdName = "no name"; Debug.LogWarning("can not get HMD's name"); } // init RenderTexture if (renderTexture[0] == null && renderTexture[1] == null) { for (var i = 0; i < CAMERA_NUM; i++) { renderTexture[i] = new RenderTexture( (int)ThreeGlassesHeadDisplayLife.renderWidth / 2, (int)ThreeGlassesHeadDisplayLife.renderHeight, 24, RenderTextureFormat.Default, RenderTextureReadWrite.Default); renderTexture[i].antiAliasing = (int)hmdAntiAliasingLevel; renderTexture[i].Create(); } } // init camera VRCameraInit(); if (enableJoypad) { // init wand ThreeGlassesUtils.Log("init joypad"); joyPad[0] = new ThreeGlassesWand(InputType.LeftWand); joyPad[1] = new ThreeGlassesWand(InputType.RightWand); } StopAllCoroutines(); StartCoroutine(CallPluginAtEndOfFrames()); }
void Awake() { renderWidth = 2048; renderHeight = 1024; #if !UNITY_EDITOR var threadId = GetCurrentThreadId(); EnumThreadWindows(threadId, (hWnd, lParam) => { var classText = new StringBuilder(UnityWindowClassName.Length + 1); GetClassName(hWnd, classText, classText.Capacity); if (classText.ToString() != UnityWindowClassName) { return(true); } _windowHandle = hWnd; return(false); }, IntPtr.Zero); #endif bool result = false; HMDPresent(ref result); ThreeGlassesUtils.Log("ThreeGlassesHeadDisplayLife init"); uint[] buffsize = { renderWidth, renderHeight }; ThreeGlassesDllInterface.GetNativeRenderSize(buffsize); renderWidth = (uint)(scaleRenderSize * buffsize[0]); renderHeight = (uint)(scaleRenderSize * buffsize[1]); renderWidth = renderWidth - (renderWidth % 16); renderHeight = renderHeight - (renderHeight % 16); ThreeGlassesDllInterface.SZVRPluginInit( (uint)(AsynchronousProjection ? 0 : 1), renderWidth, renderHeight); #if !UNITY_EDITOR if (_windowHandle != IntPtr.Zero) { ShowWindow(_windowHandle, SW_SHOWNORMAL); SetForegroundWindow(_windowHandle); } #endif }
private IEnumerator CallPluginAtEndOfFrames() { while (true) { // after OnRenderImage yield return(new WaitForEndOfFrame()); ThreeGlassesDllInterface.UpdateTextureFromUnity( renderTexture[0].GetNativeTexturePtr(), renderTexture[1].GetNativeTexturePtr()); GL.IssuePluginEvent( ThreeGlassesDllInterface.GetRenderEventFunc(), 1); UpdateHMD(); UpdateWand(); } }
void UpdateHMD() { // update hmd float[] pos = { 0, 0, 0 }; ThreeGlassesDllInterface.SZVR_GetHMDPos(pos); var hmdPosition = new Vector3(pos[0], pos[1], -pos[2]) / 1000f; if (!freezePosition && ThreeGlassesUtils.CheckNaN(hmdPosition)) { thisCam.transform.localPosition = hmdPosition; } float[] rotate = { 0, 0, 0, 1 }; ThreeGlassesDllInterface.SZVR_GetHMDRotate(rotate); hmdRotation = new Quaternion(rotate[0], rotate[1], -rotate[2], -rotate[3]); if (!freezeRotation) { thisCam.transform.localRotation = hmdRotation; } ThreeGlassesDllInterface.StereoRenderBegin(); bool[] button = { false, false }; ThreeGlassesDllInterface.SZVR_GetHMDMenuButton(ref button[0]); ThreeGlassesDllInterface.SZVR_GetHMDExitButton(ref button[1]); for (int i = 0; i < 2; i++) { if (button[i]) { hmdKeyStatus |= 1 << i; } } // touchpad byte[] touchPos = { 0, 0 }; ThreeGlassesDllInterface.SZVR_GetHMDTouchpad(touchPos); hmdTouchPad[0] = ((touchPos[0] / (float)255.0) - 0.5f) * 2.0f; hmdTouchPad[1] = (-(touchPos[1] / (float)255.0) + 0.5f) * 2.0f; }
public void Resume() { // init plugin ThreeGlassesDllInterface.SZVRPluginInit( (uint)(ThreeGlassesHeadDisplayLife.AsynchronousProjection ? 0 : 1), ThreeGlassesHeadDisplayLife.renderWidth, ThreeGlassesHeadDisplayLife.renderHeight); // create rendertexture for (var i = 0; i < CAMERA_NUM; i++) { // renderTexture[i] = new RenderTexture( // (int)renderWidth / 2, // (int)renderHeight, // 24, // RenderTextureFormat.Default, // RenderTextureReadWrite.Default); // renderTexture[i].antiAliasing = (int)hmdAntiAliasingLevel; renderTexture[i].Create(); } // bind rendertexure ThreeGlassesSubCamera[] cams = GameObject.FindObjectsOfType(typeof(ThreeGlassesSubCamera)) as ThreeGlassesSubCamera[]; foreach (var cam in cams) { Camera tempCamera = cam.gameObject.GetComponent <Camera>(); if (ThreeGlassesSubCamera.CameraTypes.Screen == cam.CameraType) { tempCamera.targetTexture = null; continue; } tempCamera.targetTexture = renderTexture[(int)cam.CameraType]; } // resume render HMD StopAllCoroutines(); StartCoroutine(CallPluginAtEndOfFrames()); }
public void Start() { _material = new Material(Shader.Find("ThreeGlasses/DepthComposite")); _camera = GetComponent <Camera>(); _projection = Matrix4x4.zero; var proj = new float[16]; ThreeGlassesDllInterface.SZVRPluginProjection(proj); _projection[0, 0] = proj[0]; _projection[1, 1] = proj[5]; _projection[0, 2] = proj[2]; _projection[1, 2] = proj[6]; _projection[2, 2] = proj[10]; _projection[2, 3] = proj[11]; _projection[3, 2] = proj[14]; var nearClipPlane = _camera.nearClipPlane; var farClipPlane = _camera.farClipPlane; _projection[2, 2] = (nearClipPlane + farClipPlane) / (nearClipPlane - farClipPlane); _projection[2, 3] = 2 * nearClipPlane * farClipPlane / (nearClipPlane - farClipPlane); }
void OnApplicationQuit() { ThreeGlassesUtils.Log("ThreeGlassesHeadDisplayLife application quit"); ThreeGlassesDllInterface.SZVRPluginDestroy(); }
void UpdateWand() { // update wand info if (!enableJoypad) { return; } byte[] connect = { 0, 0 }; if (0 == ThreeGlassesDllInterface.SZVR_GetWandConnectionStatus(connect)) { if (connect[0] != 0 || connect[1] != 0) { bool getRotate = false, getPos = false, getTrigger = false, getStick = false, getButton = false; float[] wandRotate = { 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f }; float[] wandPos = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; byte[] trigger = { 0, 0 }; byte[] stick = { 0, 0, 0, 0 }; byte[] wandButton = new byte[12]; if (0 == ThreeGlassesDllInterface.SZVR_GetWandRotate(wandRotate)) { getRotate = true; } if (0 == ThreeGlassesDllInterface.SZVR_GetWandPos(wandPos)) { getPos = true; } if (0 == ThreeGlassesDllInterface.SZVR_GetWandTriggerProcess(trigger)) { getTrigger = true; } if (0 == ThreeGlassesDllInterface.SZVR_GetWandStick(stick)) { ThreeGlassesUtils.Log("lwand=" + stick[0] + " " + stick[1]); ThreeGlassesUtils.Log("rwand=" + stick[2] + " " + stick[3]); getStick = true; } if (0 == ThreeGlassesDllInterface.SZVR_GetWandButton(wandButton)) { getButton = true; } for (var i = 0; i < JOYPAD_NUM; i++) { if (connect[i] != 0) { if (getRotate) { joyPad[i].UpdateRotate(wandRotate); } if (getPos) { joyPad[i].UpdatePos(wandPos); } if (getTrigger) { joyPad[i].UpdateTrigger(trigger); } if (getStick) { joyPad[i].UpdateStick(stick); } if (getButton) { joyPad[i].UpdateButton(wandButton); } } } } } }