using System;
namespace UnityEngine.Rendering.HighDefinition
{
/// Defines how the view matrix is provided to the camera.
[Serializable]
public struct CameraPositionSettings
{
/// Default value.
[Obsolete("Since 2019.3, use CameraPositionSettings.NewDefault() instead.")]
public static readonly CameraPositionSettings @default = default;
/// Default value.
/// The default value.
public static CameraPositionSettings NewDefault() => new CameraPositionSettings
{
mode = Mode.ComputeWorldToCameraMatrix,
position = Vector3.zero,
rotation = Quaternion.identity,
worldToCameraMatrix = Matrix4x4.identity
};
/// Defines the method to use when computing the view matrix.
public enum Mode
{
///
/// Compute the view matrix from and parameters.
///
ComputeWorldToCameraMatrix,
/// Assign the provided matrix.
UseWorldToCameraMatrixField
}
/// Which mode to use for computing the view matrix.
public Mode mode;
/// The world position of the camera during rendering.
public Vector3 position;
/// The world rotation of the camera during rendering.
public Quaternion rotation;
///
/// The world to camera matrix to use.
///
/// Important: This matrix must be in right-hand standard.
/// Take care that Unity's transform system follow left-hand standard.
///
public Matrix4x4 worldToCameraMatrix;
/// Compute the worldToCameraMatrix to use during rendering.
/// The worldToCameraMatrix.
public Matrix4x4 ComputeWorldToCameraMatrix()
{
return GeometryUtils.CalculateWorldToCameraMatrixRHS(position, rotation);
}
///
/// Compute the world to camera matrix to use.
///
/// The world to camera matrix to use.
public Matrix4x4 GetUsedWorldToCameraMatrix()
{
switch (mode)
{
case Mode.ComputeWorldToCameraMatrix: return ComputeWorldToCameraMatrix();
case Mode.UseWorldToCameraMatrixField: return worldToCameraMatrix;
default: throw new ArgumentException();
}
}
}
}