Projection
A 4×4 projective-transformation matrix with four Vector4 columns.
A C# struct representing a 4×4 matrix with four Vector4 columns: X, Y, Z and W. Used for projective transformations and camera projection. Assignment copies the matrix value.
Projection.Identity is the identity matrix; default(Projection) has zero coefficients and is not Identity. Neither value is true or false in C#: Projection has no conversion to bool. An explicit Identity comparison tests coefficients, not suitability for a particular camera.
Choose a projection constructor for the task and respect its near/far, angle and size restrictions. Transform3D describes an ordinary object position/rotation/scale transform; it is not automatically a suitable camera projection.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Constructors3
Projection3 overloads
public Projection(Transform3D transform);Constructs a Projection from four Vector4 values (matrix columns).
| Name | Type | Default |
|---|---|---|
transform | Transform3D | — |
transformThe Transform3D.
public Projection(Vector4 x, Vector4 y, Vector4 z, Vector4 w);Constructs a Projection from four Vector4 values (matrix columns).
| Name | Type | Default |
|---|---|---|
x | Vector4 | — |
y | Vector4 | — |
z | Vector4 | — |
w | Vector4 | — |
xThe X column, or column index 0.
yThe Y column, or column index 1.
zThe Z column, or column index 2.
wThe W column, or column index 3.
public Projection(float xx, float xy, float xz, float xw, float yx, float yy, float yz, float yw, float zx, float zy, float zz, float zw, float wx, float wy, float wz, float ww);Constructs a Projection from four Vector4 values (matrix columns).
| Name | Type | Default |
|---|---|---|
xx | float | — |
xy | float | — |
xz | float | — |
xw | float | — |
yx | float | — |
yy | float | — |
yz | float | — |
yw | float | — |
zx | float | — |
zy | float | — |
zz | float | — |
zw | float | — |
wx | float | — |
wy | float | — |
wz | float | — |
ww | float | — |
xxThe X column vector's X component, accessed via p.X.X or [0][0].
xyThe X column vector's Y component, accessed via p.X.Y or [0][1].
xzThe X column vector's Z component, accessed via p.X.Z or [0][2].
xwThe X column vector's W component, accessed via p.X.W or [0][3].
yxThe Y column vector's X component, accessed via p.Y.X or [1][0].
yyThe Y column vector's Y component, accessed via p.Y.Y or [1][1].
yzThe Y column vector's Z component, accessed via p.Y.Z or [1][2].
ywThe Y column vector's W component, accessed via p.Y.W or [1][3].
zxThe Z column vector's X component, accessed via p.Z.X or [2][0].
zyThe Z column vector's Y component, accessed via p.Z.Y or [2][1].
zzThe Z column vector's Z component, accessed via p.Z.Z or [2][2].
zwThe Z column vector's W component, accessed via p.Z.W or [2][3].
wxThe W column vector's X component, accessed via p.W.X or [3][0].
wyThe W column vector's Y component, accessed via p.W.Y or [3][1].
wzThe W column vector's Z component, accessed via p.W.Z or [3][2].
wwThe W column vector's W component, accessed via p.W.W or [3][3].
Properties4
IdentityProperty
public static Projection Identity { get; }A Projection with no transformation defined. When applied to other data structures, no transformation is performed.
Item2 overloads
public Vector4 this[int column] { get; set; }Access whole columns in the form of Vector4.
public float this[int column, int row] { get; set; }Access single values.
ZeroProperty
public static Projection Zero { get; }A Projection with all values initialized to 0. When applied to other data structures, they will be zeroed.
Methods38
CreateDepthCorrectionProjection
public static Projection CreateDepthCorrection(bool flipY);Creates a new Projection that projects positions from a depth range of -1 to 1 to one that ranges from 0 to 1, and flips the projected positions vertically, according to flip_y.
| Name | Type | Default |
|---|---|---|
flipY | bool | — |
flipYIf the projection should be flipped vertically.
ProjectionThe created projection.
CreateFitAabbProjection
public static Projection CreateFitAabb(Aabb aabb);Creates a new Projection that scales a given projection to fit around a given Aabb in projection space.
| Name | Type | Default |
|---|---|---|
aabb | Aabb | — |
aabbThe Aabb to fit the projection around.
ProjectionThe created projection.
CreateForHmdProjection
public static Projection CreateForHmd(int eye, float aspect, float intraocularDist, float displayWidth, float displayToLens, float oversample, float zNear, float zFar);Creates a new Projection for projecting positions onto a head-mounted display with the given X:Y aspect ratio, distance between eyes, display width, distance to lens, oversampling factor, and depth clipping planes.
eye creates the projection for the left eye when set to 1, or the right eye when set to 2.
| Name | Type | Default |
|---|---|---|
eye | int | — |
aspect | float | — |
intraocularDist | float | — |
displayWidth | float | — |
displayToLens | float | — |
oversample | float | — |
zNear | float | — |
zFar | float | — |
eyeThe eye to create the projection for. The left eye when set to 1, the right eye when set to 2.
aspectThe aspect ratio.
intraocularDistThe distance between the eyes.
displayWidthThe display width.
displayToLensThe distance to the lens.
oversampleThe oversampling factor.
zNearThe near clipping distance.
zFarThe far clipping distance.
ProjectionThe created projection.
CreateFrustumProjection
public static Projection CreateFrustum(float left, float right, float bottom, float top, float depthNear, float depthFar);Creates a new Projection that projects positions in a frustum with the given clipping planes.
| Name | Type | Default |
|---|---|---|
left | float | — |
right | float | — |
bottom | float | — |
top | float | — |
depthNear | float | — |
depthFar | float | — |
leftThe left clipping distance.
rightThe right clipping distance.
bottomThe bottom clipping distance.
topThe top clipping distance.
depthNearThe near clipping distance.
depthFarThe far clipping distance.
ProjectionThe created projection.
CreateFrustumAspectProjection
public static Projection CreateFrustumAspect(float size, float aspect, Vector2 offset, float depthNear, float depthFar, bool flipFov);Creates a new Projection that projects positions in a frustum with the given size, X:Y aspect ratio, offset, and clipping planes.
flip_fov determines whether the projection's field of view is flipped over its diagonal.
| Name | Type | Default |
|---|---|---|
size | float | — |
aspect | float | — |
offset | Vector2 | — |
depthNear | float | — |
depthFar | float | — |
flipFov | bool | — |
sizeThe frustum size.
aspectThe aspect ratio.
offsetThe offset to apply.
depthNearThe near clipping distance.
depthFarThe far clipping distance.
flipFovIf the field of view is flipped over the projection's diagonal.
ProjectionThe created projection.
CreateLightAtlasRectProjection
public static Projection CreateLightAtlasRect(Rect2 rect);Creates a new Projection that projects positions into the given Rect2.
| Name | Type | Default |
|---|---|---|
rect | Rect2 | — |
rectThe Rect2 to project positions into.
ProjectionThe created projection.
CreateOrthogonalProjection
public static Projection CreateOrthogonal(float left, float right, float bottom, float top, float zNear, float zFar);Creates a new Projection that projects positions using an orthogonal projection with the given clipping planes.
| Name | Type | Default |
|---|---|---|
left | float | — |
right | float | — |
bottom | float | — |
top | float | — |
zNear | float | — |
zFar | float | — |
leftThe left clipping distance.
rightThe right clipping distance.
bottomThe bottom clipping distance.
topThe top clipping distance.
zNearThe near clipping distance.
zFarThe far clipping distance.
ProjectionThe created projection.
CreateOrthogonalAspectProjection
public static Projection CreateOrthogonalAspect(float size, float aspect, float zNear, float zFar, bool flipFov);Creates a new Projection that projects positions using an orthogonal projection with the given size, X:Y aspect ratio, and clipping planes.
flip_fov determines whether the projection's field of view is flipped over its diagonal.
| Name | Type | Default |
|---|---|---|
size | float | — |
aspect | float | — |
zNear | float | — |
zFar | float | — |
flipFov | bool | — |
sizeThe frustum size.
aspectThe aspect ratio.
zNearThe near clipping distance.
zFarThe far clipping distance.
flipFovIf the field of view is flipped over the projection's diagonal.
ProjectionThe created projection.
CreatePerspectiveProjection
public static Projection CreatePerspective(float fovyDegrees, float aspect, float zNear, float zFar, bool flipFov);Creates a new Projection that projects positions using a perspective projection with the given Y-axis field of view (in degrees), X:Y aspect ratio, and clipping planes.
flip_fov determines whether the projection's field of view is flipped over its diagonal.
| Name | Type | Default |
|---|---|---|
fovyDegrees | float | — |
aspect | float | — |
zNear | float | — |
zFar | float | — |
flipFov | bool | — |
fovyDegreesThe vertical field of view (in degrees).
aspectThe aspect ratio.
zNearThe near clipping distance.
zFarThe far clipping distance.
flipFovIf the field of view is flipped over the projection's diagonal.
ProjectionThe created projection.
CreatePerspectiveHmdProjection
public static Projection CreatePerspectiveHmd(float fovyDegrees, float aspect, float zNear, float zFar, bool flipFov, int eye, float intraocularDist, float convergenceDist);Creates a new Projection that projects positions using a perspective projection with the given Y-axis field of view (in degrees), X:Y aspect ratio, and clipping distances. The projection is adjusted for a head-mounted display with the given distance between eyes and distance to a point that can be focused on.
eye creates the projection for the left eye when set to 1, or the right eye when set to 2.
flip_fov determines whether the projection's field of view is flipped over its diagonal.
| Name | Type | Default |
|---|---|---|
fovyDegrees | float | — |
aspect | float | — |
zNear | float | — |
zFar | float | — |
flipFov | bool | — |
eye | int | — |
intraocularDist | float | — |
convergenceDist | float | — |
fovyDegreesThe vertical field of view (in degrees).
aspectThe aspect ratio.
zNearThe near clipping distance.
zFarThe far clipping distance.
flipFovIf the field of view is flipped over the projection's diagonal.
eyeThe eye to create the projection for. The left eye when set to 1, the right eye when set to 2.
intraocularDistThe distance between the eyes.
convergenceDistThe distance to a point of convergence that can be focused on.
ProjectionThe created projection.
Determinantfloat
public float Determinant();Returns a scalar value that is the signed factor by which areas are scaled by this matrix. If the sign is negative, the matrix flips the orientation of the area. The determinant can be used to calculate the invertibility of a matrix or solve linear systems of equations involving the matrix, among other applications.
floatThe determinant calculated from this projection.
Equals2 overloads
public bool Equals(Projection other);Returns true if the projections are exactly equal.
| Name | Type | Default |
|---|---|---|
other | Projection | — |
otherThe other projection.
boolWhether or not the projections are exactly equal.
public override bool Equals(object? obj);Returns true if the projection is exactly equal
to the given object (obj).
| Name | Type | Default |
|---|---|---|
obj | object | — |
objThe object to compare with.
boolWhether or not the vector and the object are equal.
FlippedYProjection
public Projection FlippedY();Returns a copy of this Projection with the signs of the values of the Y column flipped.
ProjectionThe flipped projection.
GetAspectfloat
public float GetAspect();Returns the X:Y aspect ratio of this Projection's viewport.
floatThe aspect ratio from this projection's viewport.
GetFarPlaneHalfExtentsVector2
public Vector2 GetFarPlaneHalfExtents();Returns the dimensions of the far clipping plane of the projection, divided by two.
Vector2The half extents for this projection's far plane.
GetFovfloat
public float GetFov();Returns the horizontal field of view of the projection (in degrees).
floatThe horizontal field of view of this projection.
GetFovyfloat
public static float GetFovy(float fovx, float aspect);Returns the vertical field of view of the projection (in degrees) associated with the given horizontal field of view (in degrees) and aspect ratio.
Note: Unlike most methods of Projection, aspect is expected to be 1 divided by the X:Y aspect ratio.
| Name | Type | Default |
|---|---|---|
fovx | float | — |
aspect | float | — |
fovxThe horizontal field of view (in degrees).
aspectThe aspect ratio.
floatThe vertical field of view of this projection.
GetHashCodeint
public override int GetHashCode();Serves as the hash function for Projection.
intA hash code for this projection.
GetLodMultiplierfloat
public float GetLodMultiplier();Returns the factor by which the visible level of detail is scaled by this Projection.
floatThe level of detail factor for this projection.
GetPixelsPerMeterint
public int GetPixelsPerMeter(int forPixelWidth);Returns for_pixel_width divided by the viewport's width measured in meters on the near plane, after this Projection is applied.
| Name | Type | Default |
|---|---|---|
forPixelWidth | int | — |
forPixelWidthThe width for each pixel (in meters).
intThe number of pixels per meter.
GetProjectionPlanePlane
public Plane GetProjectionPlane(Projection.Planes plane);Returns the clipping plane of this Projection whose index is given by plane.
plane should be equal to one of Projection.Planes.Near, Projection.Planes.Far, Projection.Planes.Left, Projection.Planes.Top, Projection.Planes.Right, or Projection.Planes.Bottom.
| Name | Type | Default |
|---|---|---|
plane | Projection.Planes | — |
planeThe kind of clipping plane to get from the projection.
PlaneThe clipping plane of this projection.
GetViewportHalfExtentsVector2
public Vector2 GetViewportHalfExtents();Returns the dimensions of the viewport plane that this Projection projects positions onto, divided by two.
Vector2The half extents for this projection's viewport plane.
GetZFarfloat
public float GetZFar();Returns the distance for this Projection beyond which positions are clipped.
floatThe distance beyond which positions are clipped.
GetZNearfloat
public float GetZNear();Returns the distance for this Projection before which positions are clipped.
floatThe distance before which positions are clipped.
InverseProjection
public Projection Inverse();Returns a Projection that performs the inverse of this Projection's projective transformation.
ProjectionThe inverted projection.
IsOrthogonalbool
public bool IsOrthogonal();Returns true if this Projection performs an orthogonal projection.
boolIf the projection performs an orthogonal projection.
JitterOffsetedProjection
public Projection JitterOffseted(Vector2 offset);Returns a Projection with the X and Y values from the given Vector2 added to the first and second values of the final column respectively.
| Name | Type | Default |
|---|---|---|
offset | Vector2 | — |
offsetThe offset to apply to the projection.
ProjectionThe offsetted projection.
PerspectiveZNearAdjustedProjection
public Projection PerspectiveZNearAdjusted(float newZNear);Returns a Projection with the near clipping distance adjusted to be new_znear.
Note: The original Projection must be a perspective projection.
| Name | Type | Default |
|---|---|---|
newZNear | float | — |
newZNearThe near clipping distance to adjust the projection to.
ProjectionThe adjusted projection.
ToString2 overloads
public override string ToString();Converts this Projection to a string.
stringA string representation of this projection.
public string ToString(string? format);Converts this Projection to a string with the given format.
| Name | Type | Default |
|---|---|---|
format | string | — |
stringA string representation of this projection.
op_Equalitybool
public static bool operator ==(Projection left, Projection right);Returns true if the projections are exactly equal.
| Name | Type | Default |
|---|---|---|
left | Projection | — |
right | Projection | — |
leftThe left projection.
rightThe right projection.
boolWhether or not the projections are exactly equal.
op_ExplicitTransform3D
public static explicit operator Transform3D(Projection proj);Constructs a new Transform3D from the Projection.
| Name | Type | Default |
|---|---|---|
proj | Projection | — |
projThe Projection.
Transform3Dop_Inequalitybool
public static bool operator !=(Projection left, Projection right);Returns true if the projections are not exactly equal.
| Name | Type | Default |
|---|---|---|
left | Projection | — |
right | Projection | — |
leftThe left projection.
rightThe right projection.
boolWhether or not the projections are not exactly equal.
op_Multiply4 overloads
public static Projection operator *(Projection left, Projection right);Composes these two projections by multiplying them together. This has the effect of applying the right and then the left projection.
| Name | Type | Default |
|---|---|---|
left | Projection | — |
right | Projection | — |
leftThe parent transform.
rightThe child transform.
ProjectionThe composed projection.
public static Vector3 operator *(Projection proj, Vector3 vector);Returns a Vector3 transformed (multiplied) by the projection.
| Name | Type | Default |
|---|---|---|
proj | Projection | — |
vector | Vector3 | — |
projThe projection to apply.
vectorA Vector3 to transform.
Vector3The transformed Vector3.
public static Vector4 operator *(Projection proj, Vector4 vector);Returns a Vector4 transformed (multiplied) by the projection.
| Name | Type | Default |
|---|---|---|
proj | Projection | — |
vector | Vector4 | — |
projThe projection to apply.
vectorA Vector4 to transform.
Vector4The transformed Vector4.
public static Vector4 operator *(Vector4 vector, Projection proj);Returns a Vector4 transformed (multiplied) by the transpose of the projection.
For transforming by inverse of a projection projection.Inverse() * vector can be used instead. See Projection.Inverse.
| Name | Type | Default |
|---|---|---|
vector | Vector4 | — |
proj | Projection | — |
vectorA Vector4 to transform.
projThe projection to apply.
Vector4The inversely transformed Vector4.
Fields and constants4
WField
public Vector4 W;The projection matrix's W vector (column 3). Equivalent to array index 3.
XField
public Vector4 X;The projection matrix's X vector (column 0). Equivalent to array index 0.
YField
public Vector4 Y;The projection matrix's Y vector (column 1). Equivalent to array index 1.
ZField
public Vector4 Z;The projection matrix's Z vector (column 2). Equivalent to array index 2.
Projection.Planes
| Value | Description |
|---|---|
Bottom = 5 | The index value of the projection bottom clipping plane. |
Far = 1 | The index value of the projection's far clipping plane. |
Left = 2 | The index value of the projection's left clipping plane. |
Near = 0 | The index value of the projection's near clipping plane. |
Right = 4 | The index value of the projection's right clipping plane. |
Top = 3 | The index value of the projection's top clipping plane. |