/// <summary> /// /// fov范围 [40~90] /// </summary> /// <param name="fov"></param> public void UpdateCameraFov(float fov) { if (fov > 90) { fov = 90; } if (fov < 5) { fov = 5; } // cache左右眼透视矩阵 if (eyeOriginalProjection == null && eyes[0] != null && eyes[1] != null) { eyeOriginalProjection = new Matrix4x4[2]; eyeOriginalProjection[0] = eyes[0].cam.projectionMatrix; eyeOriginalProjection[1] = eyes[1].cam.projectionMatrix; } oldFov = fov; float near = NvrGlobal.fovNear > 0 ? NvrGlobal.fovNear : 0.0305f; float far = NvrGlobal.fovFar > 0 ? NvrGlobal.fovFar : 2000; far = far > 100 ? far : 2000; float fovLeft = near * Mathf.Tan(-fov * Mathf.Deg2Rad); float fovTop = near * Mathf.Tan(fov * Mathf.Deg2Rad); float fovRight = near * Mathf.Tan(fov * Mathf.Deg2Rad); float fovBottom = near * Mathf.Tan(-fov * Mathf.Deg2Rad); Matrix4x4 eyeProjection = BaseVRDevice.MakeProjection(fovLeft, fovTop, fovRight, fovBottom, near, far); if (device != null) { for (int i = 0; i < 2; i++) { NvrEye eye = eyes[i]; if (eye != null) { eye.cam.projectionMatrix = eyeProjection; } } } }
/// <summary> /// 检查初始是否需要更新相机投影矩阵 /// </summary> /// <param name="eye"></param> public void UpdateEyeCameraProjection(Eye eye) { if (oldFov != -1 && eye == Eye.Right) { UpdateCameraFov(oldFov); } if (!Application.isEditor && device != null && eye == Eye.Right) { if (mFar > 0) { float mNear = 0.0305f; if (NvrGlobal.fovNear > -1) { mNear = NvrGlobal.fovNear; } // Debug.Log("new near : " + mNear + "," + NvrGlobal.fovNear+ ",new far : " + mFar + "," + NvrGlobal.fovFar); // 更新camera near far float fovLeft = mNear * Mathf.Tan(-Profile.viewer.maxFOV.outer * Mathf.Deg2Rad); float fovTop = mNear * Mathf.Tan(Profile.viewer.maxFOV.upper * Mathf.Deg2Rad); float fovRight = mNear * Mathf.Tan(Profile.viewer.maxFOV.inner * Mathf.Deg2Rad); float fovBottom = mNear * Mathf.Tan(-Profile.viewer.maxFOV.lower * Mathf.Deg2Rad); //Debug.Log("fov : " +fovLeft+","+fovRight+","+fovTop+","+fovBottom); Matrix4x4 eyeProjection = BaseVRDevice.MakeProjection(fovLeft, fovTop, fovRight, fovBottom, mNear, mFar); for (int i = 0; i < 2; i++) { NvrEye mEye = eyes[i]; if (mEye != null) { mEye.cam.projectionMatrix = eyeProjection; } } } } }