public bool SetupCamera(float nearClipPlane, float farClipPlane, Matrix4x4 projectionMatrix, ref bool opticalOut) { Camera c = this.gameObject.GetComponent <Camera>(); // 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]; opticalSetupOK = PluginFunctions.arwLoadOpticalParams(null, OpticalParamsFileContents, OpticalParamsFileContents.Length, out fovy, out aspect, m, p); if (!opticalSetupOK) { ARController.Log(LogTag + "Error loading optical parameters."); return(false); } m[12] *= 0.001f; m[13] *= 0.001f; m[14] *= 0.001f; ARController.Log(LogTag + "Optical parameters: fovy=" + fovy + ", aspect=" + aspect + ", camera position (m)={" + m[12].ToString("F3") + ", " + m[13].ToString("F3") + ", " + m[14].ToString("F3") + "}"); c.projectionMatrix = ARUtilityFunctions.MatrixFromFloatArray(p); 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); }