Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/ProwlEngine/Prowl.Vector/llms.txt

Use this file to discover all available pages before exploring further.

Double4x4 is a 4×4 double-precision floating-point matrix in the Prowl.Vector namespace. It uses column-major storage — each of the four column fields (c0c3) is a Double4. The struct is marked [Serializable] and is the primary type for world/view/projection transforms when high-precision (64-bit) arithmetic is required.

Declaration

[System.Serializable]
public partial struct Double4x4 : System.IEquatable<Double4x4>, IFormattable

Fields

FieldTypeDescription
c0Double4Column 0 — the X-axis basis vector (and m00, m10, m20, m30).
c1Double4Column 1 — the Y-axis basis vector (and m01, m11, m21, m31).
c2Double4Column 2 — the Z-axis basis vector (and m02, m12, m22, m32).
c3Double4Column 3 — the translation/homogeneous column (and m03, m13, m23, m33).
Because storage is column-major, this[row, col] is equivalent to this[col][row]. The memory layout is c0.X, c0.Y, c0.Z, c0.W, c1.X, ….

Static Constants

ConstantValueDescription
Double4x4.IdentityDiagonal (1,1,1,1)The multiplicative identity — no transform.
Double4x4.ZeroAll zerosA zeroed matrix.
Double4x4 m = Double4x4.Identity;

Constructors

From four column vectors

public Double4x4(Double4 col0, Double4 col1, Double4 col2, Double4 col3)
Constructs the matrix directly from four pre-built column vectors.

From sixteen scalar values (row-major argument order)

public Double4x4(
    double m00, double m01, double m02, double m03,
    double m10, double m11, double m12, double m13,
    double m20, double m21, double m22, double m23,
    double m30, double m31, double m32, double m33)
Arguments are supplied in row-major reading order (m{row}{col}), but stored column-major internally.

Broadcast scalar

public Double4x4(double v)
Sets every element of every column to v.

Widening from Float4x4

public Double4x4(Float4x4 m)
Widens each float column to double. Explicit cast operator also available: (Double4x4)floatMatrix.

From rotation matrix + translation

public Double4x4(Double3x3 rotation, Double3 translation)
Embeds a Double3x3 rotation into the upper-left 3×3 and places translation in column 3, with the bottom row (0, 0, 0, 1).

From quaternion + translation

public Double4x4(Quaternion rotation, Double3 translation)
Converts rotation to a Double3x3 internally, then constructs as above.

Properties

Translation

public Double4 Translation { get; set; }
Aliases column c3. Getting or setting Translation is equivalent to reading or writing c3 directly.

Column indexer

public ref Double4 this[int index]   // index in [0, 3]
Returns a by-reference pointer to the column, enabling direct component mutation without a copy. Throws ArgumentOutOfRangeException for out-of-range indices.

Element indexer

public double this[int row, int column] { get; set; }   // row, column each in [0, 3]
Gets or sets individual scalar elements. Internally resolves to this[column][row].

Instance Methods

Row accessors

public Double4 GetRow0();
public Double4 GetRow1();
public Double4 GetRow2();
public Double4 GetRow3();

public void SetRow0(Double4 value);
public void SetRow1(Double4 value);
public void SetRow2(Double4 value);
public void SetRow3(Double4 value);
Read or write a full row across all four columns. Useful when interoperating with row-major APIs.

Invert (instance)

public Double4x4 Invert()
Convenience wrapper around the static overload. Returns the inverted matrix, or a matrix filled with NaN if the matrix is singular.

Static Factory Methods

CreateTranslation

public static Double4x4 CreateTranslation(Double3 vector)
Returns a pure translation matrix — identity with vector placed in column 3.

CreateScale

public static Double4x4 CreateScale(double s)
public static Double4x4 CreateScale(double x, double y, double z)
public static Double4x4 CreateScale(Double3 scales)
Returns a diagonal scale matrix. The uniform overload places s on the first three diagonal entries; the non-uniform overloads accept per-axis values.

RotateX / RotateY / RotateZ

public static Double4x4 RotateX(double angle)
public static Double4x4 RotateY(double angle)
public static Double4x4 RotateZ(double angle)
Returns a 4×4 rotation matrix for a right-handed rotation around the respective world axis. angle is in radians. These delegate to Double3x3.RotateX/Y/Z and embed the result.

FromAxisAngle

public static Double4x4 FromAxisAngle(Double3 axis, double angle)
Returns a 4×4 rotation matrix for an arbitrary normalized axis by angle radians (Rodrigues’ formula, delegated to Double3x3.FromAxisAngle).

CreateFromQuaternion

public static Double4x4 CreateFromQuaternion(Quaternion quaternion)
Converts a unit quaternion to the equivalent 4×4 rotation matrix using the standard half-angle expansion.

CreateTRS

public static Double4x4 CreateTRS(Double3 translation, Quaternion rotation, Double3 scale)
Combines scale, rotation, and translation into a single transform matrix. Transforms are applied in order: scale → rotate → translate (column-vector convention: T * R * S).

CreateLookAt

public static Double4x4 CreateLookAt(
    Double3 eyePosition,
    Double3 targetPosition,
    Double3 upVector)
Returns a left-handed view matrix. Computes forward = normalize(target − eye), derives the orthonormal right and up axes, then builds the view transform with −dot translation entries.

CreateLookTo

public static Double4x4 CreateLookTo(
    Double3 eyePosition,
    Double3 forwardVector,
    Double3 upVector)
Like CreateLookAt but takes a pre-computed forward direction instead of a target position.

CreatePerspectiveFov

public static Double4x4 CreatePerspectiveFov(
    double verticalFovRadians,
    double aspectRatio,
    double nearPlane,
    double farPlane)
Creates a left-handed perspective projection matrix mapping depth to [0, 1] (DirectX convention). Throws ArgumentOutOfRangeException if:
  • verticalFovRadians is not in (0, π)
  • nearPlane or farPlane ≤ 0
  • nearPlane ≥ farPlane
Pass double.PositiveInfinity for farPlane to get an infinite-far-plane projection (range = 1).

CreateOrtho

public static Double4x4 CreateOrtho(
    double width,
    double height,
    double nearPlane,
    double farPlane)
Creates a left-handed centred orthographic projection mapping depth to [0, 1].

CreateOrthoOffCenter

public static Double4x4 CreateOrthoOffCenter(
    double left, double right,
    double bottom, double top,
    double nearPlane, double farPlane)
Off-centre variant of CreateOrtho, based on the DirectX XMMatrixOrthographicOffCenterLH formula.

Transpose

public static Double4x4 Transpose(Double4x4 m)
Returns the transpose — rows and columns are swapped. Each result column is built from the corresponding row of m.

Determinant

public static double Determinant(Double4x4 m)
Computes the scalar determinant via cofactor expansion along the first row. Returns 0 for singular matrices.

Invert (static)

public static bool Invert(Double4x4 matrix, out Double4x4 result)
Attempts to compute the inverse using the adjugate/determinant method. Returns true on success. If |det| < double.Epsilon, writes a NaN-filled matrix to result and returns false.

TransformPoint

// 3-D point (homogeneous w = 1, perspective divide applied)
public static Double3 TransformPoint(Double3 point, Double4x4 matrix)

// 4-D point (direct multiply)
public static Double4 TransformPoint(Double4 point, Double4x4 matrix)
Transforms a position. The Double3 overload promotes to homogeneous coordinates, multiplies, then divides by w. If |w| ≤ double.Epsilon, the divide is skipped.

TransformNormal

public static Double3 TransformNormal(Double3 normal, Double4x4 matrix)
Transforms a surface normal correctly under non-uniform scale by extracting the upper-left 3×3 and passing it to Double3x3.TransformNormal, which applies the inverse-transpose and normalises.

Operators

OperatorSignatureNotes
*Double4x4 * Double4x4 → Double4x4Matrix product. A * B applies B first, then A (column-vector convention).
*Double4x4 * Double4 → Double4Matrix–vector product.
==Double4x4 == Double4x4 → boolComponent-wise equality via Double4.==.
!=Double4x4 != Double4x4 → boolLogical negation of ==.

Explicit casts

explicit operator Double4x4(Float4x4 m)   // widening: float → double
explicit operator Float4x4(Double4x4 m)   // narrowing: double → float (on Float4x4 side)

Additional Methods

ToArray

public double[] ToArray()
Returns a flat double[16] in row-major order ([row * 4 + col]).

ToString

public override string ToString()
public string ToString(string format)
public string ToString(string format, IFormatProvider formatProvider)
Formats all 16 components grouped by row, e.g. Double4x4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1).

Code Example

using Prowl.Vector;

// 1. Build a TRS matrix for a game object
var position  = new Double3(10.0, 5.0, -3.0);
var rotation  = Quaternion.FromEuler(30f, 45f, 0f);
var scale     = new Double3(2.0, 2.0, 2.0);

Double4x4 model = Double4x4.CreateTRS(position, rotation, scale);

// 2. Build a view matrix (camera looking at origin)
var eye    = new Double3(0.0, 10.0, -20.0);
var target = Double3.Zero;
var up     = Double3.UnitY;

Double4x4 view = Double4x4.CreateLookAt(eye, target, up);

// 3. Build a perspective projection (60° FOV, 16:9, near=0.1, far=1000)
double fov    = Maths.PI / 3.0;   // 60 degrees
double aspect = 16.0 / 9.0;

Double4x4 proj = Double4x4.CreatePerspectiveFov(fov, aspect, 0.1, 1000.0);

// 4. Combine into a model-view-projection matrix
Double4x4 mvp = proj * view * model;

// 5. Transform a world-space position into clip space
var worldPos = new Double3(10.0, 5.0, -3.0);
Double3 clipPos = Double4x4.TransformPoint(worldPos, mvp);

// 6. Invert the model matrix (e.g. for normal transforms)
if (Double4x4.Invert(model, out Double4x4 invModel))
{
    Double3 normal = new Double3(0.0, 1.0, 0.0);
    Double3 worldNormal = Double4x4.TransformNormal(normal, invModel);
}

// 7. Access individual elements
double m22 = mvp[2, 2];   // row 2, column 2

// 8. Narrow to Float4x4 for GPU upload
Float4x4 gpuMvp = (Float4x4)mvp;

Build docs developers (and LLMs) love