/// <summary> /// Computes the effective projection matrix for the given /// camera. /// </summary> public static Matrix3D GetProjectionMatrix(Camera camera, double aspectRatio) { if (camera == null) { throw new ArgumentNullException("camera"); } PerspectiveCamera perspectiveCamera = camera as PerspectiveCamera; if (perspectiveCamera != null) { return GetProjectionMatrix(perspectiveCamera, aspectRatio); } OrthographicCamera orthographicCamera = camera as OrthographicCamera; if (orthographicCamera != null) { return GetProjectionMatrix(orthographicCamera, aspectRatio); } MatrixCamera matrixCamera = camera as MatrixCamera; if (matrixCamera != null) { return matrixCamera.ProjectionMatrix; } throw new ArgumentException(String.Format("Unsupported camera type '{0}'.", camera.GetType().FullName), "camera"); }
/// <summary> /// Computes the effective view matrix for the given /// camera. /// </summary> public static Matrix3D GetViewMatrix(Camera camera) { if (camera == null) throw new ArgumentNullException("camera"); ProjectionCamera projectionCamera = camera as ProjectionCamera; if (projectionCamera != null) { return GetViewMatrix(projectionCamera); } MatrixCamera matrixCamera = camera as MatrixCamera; if (matrixCamera != null) { return matrixCamera.ViewMatrix; } throw new ArgumentException(String.Format("Unsupported camera type '{0}'.", camera.GetType().FullName), "camera"); }
/// <summary> /// Gets an information string about the specified camera. /// </summary> /// <param name="camera"> /// The camera. /// </param> /// <returns> /// The get info. /// </returns> public static string GetInfo(Camera camera) { var matrixCamera = camera as MatrixCamera; var perspectiveCamera = camera as PerspectiveCamera; var projectionCamera = camera as ProjectionCamera; var orthographicCamera = camera as OrthographicCamera; var sb = new StringBuilder(); sb.AppendLine(camera.GetType().Name); if (projectionCamera != null) { sb.AppendLine( string.Format( CultureInfo.InvariantCulture, "LookDirection:\t{0:0.000},{1:0.000},{2:0.000}", projectionCamera.LookDirection.X, projectionCamera.LookDirection.Y, projectionCamera.LookDirection.Z)); sb.AppendLine( string.Format( CultureInfo.InvariantCulture, "UpDirection:\t{0:0.000},{1:0.000},{2:0.000}", projectionCamera.UpDirection.X, projectionCamera.UpDirection.Y, projectionCamera.UpDirection.Z)); sb.AppendLine( string.Format( CultureInfo.InvariantCulture, "Position:\t\t{0:0.000},{1:0.000},{2:0.000}", projectionCamera.Position.X, projectionCamera.Position.Y, projectionCamera.Position.Z)); var target = projectionCamera.Position + projectionCamera.LookDirection; sb.AppendLine( string.Format( CultureInfo.InvariantCulture, "Target:\t\t{0:0.000},{1:0.000},{2:0.000}", target.X, target.Y, target.Z)); sb.AppendLine( string.Format( CultureInfo.InvariantCulture, "NearPlaneDist:\t{0}", projectionCamera.NearPlaneDistance)); sb.AppendLine( string.Format(CultureInfo.InvariantCulture, "FarPlaneDist:\t{0}", projectionCamera.FarPlaneDistance)); } if (perspectiveCamera != null) { sb.AppendLine( string.Format(CultureInfo.InvariantCulture, "FieldOfView:\t{0:0.#}°", perspectiveCamera.FieldOfView)); } if (orthographicCamera != null) { sb.AppendLine( string.Format(CultureInfo.InvariantCulture, "Width:\t{0:0.###}", orthographicCamera.Width)); } if (matrixCamera != null) { sb.AppendLine("ProjectionMatrix:"); sb.AppendLine(matrixCamera.ProjectionMatrix.ToString(CultureInfo.InvariantCulture)); sb.AppendLine("ViewMatrix:"); sb.AppendLine(matrixCamera.ViewMatrix.ToString(CultureInfo.InvariantCulture)); } return sb.ToString().Trim(); }