private Matrix4x4 opticalViewMatrix; // This transform expresses the position and orientation of the physical camera in eye coordinates. public bool SetupCamera(IPluginFunctions pluginFunctions, float nearClipPlane, float farClipPlane, Matrix4x4 projectionMatrix, out bool opticalOut) { Camera c = this.gameObject.GetComponent <Camera>(); opticalOut = false; // A perspective projection matrix from the tracker c.orthographic = false; // Shouldn't really need to set these, because they are part of the custom // projection matrix, but it seems that in the editor, the preview camera view // isn't using the custom projection matrix. c.nearClipPlane = nearClipPlane; c.farClipPlane = farClipPlane; if (Optical) { float fovy; float aspect; float[] m = new float[16]; float[] p = new float[16]; if (OpticalCalibrationMode0 == OpticalCalibrationMode.ARXOpticalParametersFile) { opticalSetupOK = pluginFunctions.arwLoadOpticalParams(null, OpticalParamsFileContents, OpticalParamsFileContents.Length, nearClipPlane, farClipPlane, out fovy, out aspect, m, p); if (!opticalSetupOK) { ARController.Log(LogTag + "Error loading ARX optical parameters."); return(false); } // Convert millimetres to metres. m[12] *= 0.001f; m[13] *= 0.001f; m[14] *= 0.001f; c.projectionMatrix = ARUtilityFunctions.MatrixFromFloatArray(p); ARController.Log(LogTag + "Optical parameters: fovy=" + fovy + ", aspect=" + aspect + ", camera position (m)={" + m[12].ToString("F3") + ", " + m[13].ToString("F3") + ", " + m[14].ToString("F3") + "}"); } else { m[0] = m[5] = m[10] = m[15] = 1.0f; m[1] = m[2] = m[3] = m[4] = m[6] = m[7] = m[8] = m[9] = m[11] = m[12] = m[13] = m[14] = 0.0f; } opticalViewMatrix = ARUtilityFunctions.MatrixFromFloatArray(m); if (OpticalEyeLateralOffsetRight != 0.0f) { opticalViewMatrix = Matrix4x4.TRS(new Vector3(-OpticalEyeLateralOffsetRight, 0.0f, 0.0f), Quaternion.identity, Vector3.one) * opticalViewMatrix; } // Convert to left-hand matrix. opticalViewMatrix = ARUtilityFunctions.LHMatrixFromRHMatrix(opticalViewMatrix); opticalOut = true; } else { c.projectionMatrix = projectionMatrix; } // Don't clear anything or else we interfere with other foreground cameras c.clearFlags = CameraClearFlags.Nothing; // Renders after the clear and background cameras c.depth = 2; c.transform.position = new Vector3(0.0f, 0.0f, 0.0f); c.transform.rotation = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f); c.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f); return(true); }