public void UpdateProfile() { MojingLog.LogTrace("Mojing.Lens.UpdateProfile"); FOV = MojingSDK.Unity_GetGlassesFOV(); Separation = MojingSDK.Unity_GetGlassesSeparation(); DistortionR = MojingSDK.Unity_GetDistortionR(); }
void Awake() { #if DEBUG MojingLog.LogTrace("MojingSDK Unity Build in DEBUG Mode"); #else MojingLog.LogTrace("MojingSDK Unity Build in RELEASE Mode"); #endif Screen.orientation = ScreenOrientation.LandscapeLeft; //UnityEditor.PlayerSettings.MTRendering = true; MojingLog.LogTrace("Enter MojingVRHead.Awake"); gameObject.SetActive(ConfigItem.MojingSDKActive); sdk = Mojing.SDK; if (MojingSDK.cur_GlassKey == "") { //sdk.GlassesKey = Mojing.glassesKeyList[1]; GetsdkGlassKey(GlassesType); } else { sdk.GlassesKey = MojingSDK.cur_GlassKey; } MojingLog.LogTrace("MojingSDK Glasses KEY: " + sdk.GlassesKey + ", Glasses FOV:" + MojingSDK.Unity_GetGlassesFOV() + ",MojingSDK Version: " + MojingSDK.GetSDKVersion()); if (ConfigItem.ScreenNeverSleep) { Screen.sleepTimeout = SleepTimeout.NeverSleep; } else { Screen.sleepTimeout = SleepTimeout.SystemSetting; } MojingLog.LogTrace("Leave MojingVRHead.Awake"); }
public void EnableEye(bool enable) { MojingLog.LogTrace("Enable Camera " + eye.ToString() + ": " + enable.ToString()); enabled = enable; if (eye == Mojing.Eye.Left || eye == Mojing.Eye.Right) { // Setup FOV GetComponent <Camera>().fieldOfView = MojingSDK.Unity_GetGlassesFOV(); //*****Solve the problem of splash screen when start up if (enable) { if (Mojing.SDK.NeedDistortion) { #if UNITY_EDITOR_OSX #elif UNITY_EDITOR || UNITY_STANDALONE_WIN if (SystemInfo.graphicsDeviceType == UnityEngine.Rendering.GraphicsDeviceType.OpenGL2) { SetTargetTex(eye); } #else SetTargetTex(eye); #endif } else { GetComponent <Camera>().targetTexture = null; } } //***** if ((!Mojing.SDK.bWaitForMojingWord) && Mojing.SDK.VRModeEnabled && Mojing.SDK.NeedDistortion) { GetComponent <Camera>().enabled = false; } else { GetComponent <Camera>().enabled = enable; } } else { GetComponent <Camera>().enabled = enable; } }
public void EnableEye(bool enable) { MojingLog.LogTrace("Enable Camera " + eye + ": " + enable); enabled = enable; //if (eye == Mojing.Eye.Left || eye == Mojing.Eye.Right) { // Setup FOV CurrentCamera.fieldOfView = MojingSDK.Unity_GetGlassesFOV(); //*****Solve the problem of splash screen when start up if (enable) { if (Mojing.SDK.NeedDistortion) { SetTargetTex(eye); } else { CurrentCamera.targetTexture = null; // SetUpEye(); } } } CurrentCamera.enabled = enable; }
public void EnableEye(bool enable) { MojingLog.LogTrace("Enable Camera " + eye.ToString() + ": " + enable.ToString()); enabled = enable; if (eye == Mojing.Eye.Left || eye == Mojing.Eye.Right) { // Setup FOV GetComponent <Camera>().fieldOfView = MojingSDK.Unity_GetGlassesFOV(); //*****Solve the problem of splash screen when start up if (enable) { if (Mojing.SDK.NeedDistortion) { #if !UNITY_EDITOR switch (eye) { case Mojing.Eye.Left: GetComponent <Camera>().targetTexture = MojingRender.StereoScreen[0]; break; case Mojing.Eye.Right: GetComponent <Camera>().targetTexture = MojingRender.StereoScreen[1]; break; } #endif } else { GetComponent <Camera>().targetTexture = null; } } //***** } GetComponent <Camera>().enabled = enable; }
// float[] offSet_L = new float[4]; // float[] offSet_R = new float[4]; Matrix4x4 CreateMatrix() { Matrix4x4 m = new Matrix4x4(); near = CurrentCamera.nearClipPlane; far = CurrentCamera.farClipPlane; widthSize = Mojing.SDK.mobile.width; heightSize = Mojing.SDK.mobile.height; Debug.Log("Screen Size = " + widthSize + " * " + heightSize); Separation = Mojing.SDK.lens.Separation; // 瞳距,物理尺寸,以米为单位 float Angle = MojingSDK.Unity_GetGlassesFOV(); // FOV,以角度为单位 Debug.Log("Fov = " + Angle); float DistortionR = Mojing.SDK.lens.DistortionR;// 成象尺寸 Debug.Log("DistortionR = " + DistortionR); if (DistortionR <= 0) { // DistortionR = near * Mathf.Tan(Angle / 180f * Mathf.PI / 2); DistortionR = widthSize / 4; } Debug.Log("Fixd.DistortionR = " + DistortionR); /*1 理想情况下,屏幕能够放下整个畸变图形*/ float fLeft = -DistortionR; float fTop = DistortionR; float fRight = DistortionR; float fBottom = -DistortionR; float fNear = DistortionR / Mathf.Tan(Angle / 180f * Mathf.PI / 2);// 通过FOV和畸变框的大小,算出来近平面的距离。依然是以米为单位的。 float fZoom = fNear / near; Debug.Log("fNear = " + fNear + " , near = " + near + " , Zoom = " + fNear / near); /*2 处理屏幕的剪裁*/ // 2.1 内测剪裁 - 畸变图像比瞳距大 if (DistortionR > Separation / 2) { Debug.Log("Fix Inside"); if (eye == Mojing.Eye.Left) { fRight = Separation / 2; } else { fLeft = -Separation / 2; } } // 2.2 屏幕对上、下边界剪裁 if (heightSize < 2 * Separation) { Debug.Log("Fix UP/BOTTOM"); fTop = heightSize / 2; fBottom = -heightSize / 2; } // 2.3 屏幕对外侧边界的剪裁?? if (Separation + 2 * DistortionR > widthSize) { Debug.Log("Fix Outside"); float fOutside = (widthSize - Separation) / 2; if (eye == Mojing.Eye.Left) { fLeft = -fOutside; } else { fRight = fOutside; } } if (eye == Mojing.Eye.Left) { float fFOV_Inside = Mathf.Abs(Mathf.Atan(fRight / fNear) * 180f / Mathf.PI); float fFOV_Outside = Mathf.Abs(Mathf.Atan(fLeft / fNear) * 180f / Mathf.PI); float fFOV_Upside = Mathf.Abs(Mathf.Atan(fTop / fNear) * 180f / Mathf.PI); float fFOV_Lowside = Mathf.Abs(Mathf.Atan(fBottom / fNear) * 180f / Mathf.PI); Debug.Log("FOV.H = " + (fFOV_Inside + fFOV_Outside) + " , FOV.V = " + (fFOV_Upside + fFOV_Lowside)); } Rect rcView = new Rect(fLeft / fZoom, fBottom / fZoom, (fRight - fLeft) / fZoom, (fTop - fBottom) / fZoom); m = PerspectiveOffCenter(rcView, near, far); /* * * switch (eye) * { * case Mojing.Eye.Left: * offSet_L[0] = -(widthSize - separation) * 2.0f; * offSet_L[1] = separation * 2.0f; * offSet_L[2] = -heightSize * 2.0f; * offSet_L[3] = -offSet_L[2]; * // float dist = separation / 2.0f * near; * // double rangle = Mathf.Atan(dist); * // rangle = (180 / Math.PI) * rangle; * // float langle = Angle - (float)rangle; * // offSet_L[0] = Mathf.Tan(langle) * near; * // offSet_L[1] = separation /2.0f; * // offSet_L[2] = (offSet_L[0] + offSet_L[1]) / 2.0f; * // offSet_L[3] = offSet_L[2]; * m = PerspectiveOffCenter(offSet_L[0], offSet_L[1], offSet_L[2], offSet_L[3], near, far); * break; * case Mojing.Eye.Right: * offSet_R[0] = -separation * 2.0f; * offSet_R[1] = (widthSize - separation) * 2.0f; * offSet_R[2] = -heightSize * 2.0f; * offSet_R[3] = -offSet_R[2]; * // double angle2 = Mathf.Atan((-separation) / 2.0f * near); * // angle2 = (180 / Math.PI) * angle2; * // float langle2 = Angle - (float)angle2; * // offSet_R[0] = -separation / 2.0f * near; * // offSet_R[1] = -(Mathf.Tan(langle2) * near); * // offSet_R[2] = -((offSet_R[0]+ offSet_R[1]) / 2.0f);//(offSet_R[0]+ offSet_R[1]) / 2.0f; * // offSet_R[3] = offSet_R[2]; * m = PerspectiveOffCenter(offSet_R[0], offSet_R[1], offSet_R[2], offSet_R[3], near, far); * break; * } */ return(m); }