-
Notifications
You must be signed in to change notification settings - Fork 1
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.
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.
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.
Matrix identity =
Matrix.Identity;
bool isIdentity =
identity.IsIdentity;Matrix translation =
Matrix.CreateTranslation(100, 50);
Matrix fromVector =
Matrix.CreateTranslation(
new Vect2(100, 50));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 uses radians:
Matrix rotation =
Matrix.CreateRotation(
MathHelper.HalfPI);Around an origin:
Matrix rotation =
Matrix.CreateRotation(
radians,
origin);Matrix skew =
Matrix.CreateSkew(
xRadians,
yRadians);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);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 a point, including translation:
Vect2 result =
matrix.TransformPoint(point);Transform a direction without translation:
Vect2 result =
matrix.TransformDirection(direction);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.
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.
Matrix product =
Matrix.Multiply(a, b);
Matrix transposed =
Matrix.Transpose(matrix);
float determinant =
matrix.Determinant();
bool closeEnough =
a.NearlyEquals(b);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:
Home · Getting Started · Rendering · Custom Renderers · GitHub · Report an Issue
Built with VOID Engine · MIT License