public static void CalibCamera(Camera camera) { Matrix4x4 projectionMatrix = new Matrix4x4(); float near = camera.nearClipPlane; float far = camera.farClipPlane; var width = 0f; var height = 0f; var focalX = 0f; var focalY = 0f; var centerX = 0f; var centerY = 0f; var row0 = new Vector4(2 * focalX / width, 0, 1 - 2 * centerX / width, 0); var row1 = new Vector4(0, 2 * focalY / height, 2 * centerY / height - 1, 0); var row2 = new Vector4(0, 0, (far + near) / (near - far), 2 * far * near / (near - far)); var row3 = new Vector4(0, 0, -1, 0); projectionMatrix.SetRow(0, row0); projectionMatrix.SetRow(1, row1); projectionMatrix.SetRow(2, row2); projectionMatrix.SetRow(3, row3); camera.fieldOfView = CameraUtility.Focal2Fov(focalX, width); camera.projectionMatrix = projectionMatrix; }
private void OnCalibrate(Sizei resolution, Matrix3x3f intrinsic, Vector5f distorsion) { var fY = intrinsic.coeff(1, 1); var fovY = CameraUtility.Focal2Fov(fY, resolution.height); var fX = intrinsic.coeff(0, 0); var aspect = (fY / resolution.height) / (fX / resolution.width); var projectionMatrix = Matrix4x4.Perspective(fovY, aspect, camera.nearClipPlane, camera.farClipPlane); CameraUtility.ApplyProjectionMatrix(camera, projectionMatrix); }