/// <summary> /// Get projection matrix /// </summary> /// <returns>Matrix4x4 projection matrix</returns> public Matrix4x4 GetProjectionMatrix() { float[] glProjection = new float[16]; NativeAPI.CameraDevice_getProjectionMatrix(glProjection); return(MatrixUtils.ConvertGLProjectionToUnityProjection(glProjection)); }
/// <summary> /// Create sterescopic camera /// </summary> /// <param name="cameraTransform"></param> public void CreateWearableEye(Transform cameraTransform) { if (eyeLeft == null) { eyeLeft = new GameObject("EyeLeft"); eyeLeft.AddComponent <Camera>(); } if (eyeRight == null) { eyeRight = new GameObject("EyeRight"); eyeRight.AddComponent <Camera>(); } eyeLeft.transform.parent = cameraTransform; eyeRight.transform.parent = cameraTransform; eyeLeft.transform.localPosition = Vector3.zero; eyeLeft.transform.localRotation = Quaternion.identity; eyeLeft.transform.localScale = Vector3.one; eyeRight.transform.localPosition = Vector3.zero; eyeRight.transform.localRotation = Quaternion.identity; eyeRight.transform.localScale = Vector3.one; Camera mainCamera = cameraTransform.GetComponent <Camera>(); Camera leftCamera = eyeLeft.GetComponent <Camera>(); Camera rightCamera = eyeRight.GetComponent <Camera>(); CameraClearFlags clearFlags = mainCamera.clearFlags; Color backgroundColor = mainCamera.backgroundColor; float depth = mainCamera.depth + 1; float nearClipPlane = mainCamera.nearClipPlane; float farClipPlane = mainCamera.farClipPlane; float[] projectionMatrixEyeLeftPtr = GetProjectionMatrix(WearableCalibration.EyeType.EYE_LEFT); float[] projectionMatrixEyeRightPtr = GetProjectionMatrix(WearableCalibration.EyeType.EYE_RIGHT); Matrix4x4 projectionEyeLeft = MatrixUtils.ConvertGLProjectionToUnityProjection(projectionMatrixEyeLeftPtr); Matrix4x4 projectionEyeRight = MatrixUtils.ConvertGLProjectionToUnityProjection(projectionMatrixEyeRightPtr); leftCamera.clearFlags = clearFlags; leftCamera.backgroundColor = backgroundColor; leftCamera.depth = depth; leftCamera.nearClipPlane = nearClipPlane; leftCamera.farClipPlane = farClipPlane; leftCamera.rect = new Rect(0.0f, 0.0f, 0.5f, 1.0f); leftCamera.projectionMatrix = projectionEyeLeft; rightCamera.clearFlags = clearFlags; rightCamera.backgroundColor = backgroundColor; rightCamera.depth = depth; rightCamera.nearClipPlane = nearClipPlane; rightCamera.farClipPlane = farClipPlane; rightCamera.rect = new Rect(0.5f, 0.0f, 0.5f, 1.0f); rightCamera.projectionMatrix = projectionEyeRight; }