Skip to content
shmellyorc edited this page Sep 13, 2026 · 1 revision

Matrix

VOID includes its own 4x4 Matrix structure for the 2D camera and renderer pipeline.

It lives in:

using Void.Engine.Cameras;

The type is intentionally focused on the transforms VOID needs for 2D rendering and can be passed through renderer backends without converting through an external matrix type.

Why VOID Has Its Own Matrix

VOID 2.0 keeps the camera/render path renderer-neutral.

The engine therefore uses its own matrix type for:

  • camera view-projection transforms
  • world/screen conversion
  • 2D translation, rotation, scale, and skew
  • orthographic projection
  • shader matrix uniforms
  • renderer-facing view-projection state

You do not need System.Numerics.Matrix4x4 for the normal VOID camera/render path.

Composition Order

VOID uses row-vector composition.

With:

Matrix combined = a * b;

a point is transformed by a first, then by b.

That is important when building transforms manually.

Example:

Matrix transform =
    Matrix.CreateTranslation(-position) *
    Matrix.CreateRotation(-rotation) *
    Matrix.CreateScale(zoom) *
    Matrix.CreateOrthographic(
        viewport.X,
        viewport.Y);

This is the same overall order used by the standard Camera.

Identity

Matrix identity =
    Matrix.Identity;

bool isIdentity =
    identity.IsIdentity;

Translation

Matrix translation =
    Matrix.CreateTranslation(100, 50);

Matrix fromVector =
    Matrix.CreateTranslation(
        new Vect2(100, 50));

Scale

Uniform scale:

Matrix scale =
    Matrix.CreateScale(2f);

Non-uniform scale:

Matrix scale =
    Matrix.CreateScale(
        new Vect2(2f, 0.5f));

Scale around an origin:

Matrix scale =
    Matrix.CreateScale(
        new Vect2(2f, 2f),
        origin);

Rotation

Rotation uses radians:

Matrix rotation =
    Matrix.CreateRotation(
        MathHelper.HalfPI);

Around an origin:

Matrix rotation =
    Matrix.CreateRotation(
        radians,
        origin);

Skew

Matrix skew =
    Matrix.CreateSkew(
        xRadians,
        yRadians);

Combined 2D Transform

For a common position/rotation/scale transform:

Matrix transform =
    Matrix.CreateTransform(
        position,
        rotation,
        scale);

With an origin:

Matrix transform =
    Matrix.CreateTransform(
        position,
        rotation,
        scale,
        origin);

Orthographic Projection

Centered positive-Y-down projection:

Matrix projection =
    Matrix.CreateOrthographic(
        viewportWidth,
        viewportHeight);

Off-center projection:

Matrix projection =
    Matrix.CreateOrthographicOffCenter(
        left,
        right,
        top,
        bottom);

These are the projection helpers used by VOID's 2D camera pipeline.

Transform Points and Directions

Transform a point, including translation:

Vect2 result =
    matrix.TransformPoint(point);

Transform a direction without translation:

Vect2 result =
    matrix.TransformDirection(direction);

Inversion

Try to invert without throwing:

if (Matrix.TryInvert(
        matrix,
        out Matrix inverse))
{
    // Use inverse.
}

Or require an inverse:

Matrix inverse =
    Matrix.Invert(matrix);

Invert throws when the matrix cannot be inverted.

Camera screen/world conversion depends on an invertible view-projection matrix.

Decomposition

A non-skewed 2D affine matrix can be decomposed:

if (matrix.Decompose(
        out Vect2 translation,
        out float rotation,
        out Vect2 scale))
{
    // Components are available.
}

Decomposition returns false for unsupported/skewed or degenerate transforms.

Other Useful Operations

Matrix product =
    Matrix.Multiply(a, b);

Matrix transposed =
    Matrix.Transpose(matrix);

float determinant =
    matrix.Determinant();

bool closeEnough =
    a.NearlyEquals(b);

Cameras and Renderers

BaseCamera.ViewProjection returns a Matrix.

VOID's built-in batching path carries that matrix to the renderer-neutral render state, and a custom renderer's default 2D shader must preserve VOID's uViewProjection semantics.

See:


Back to Camera

Clone this wiki locally