Import std.math.matrix
Mat4
struct
Public Struct Mat4 Implements Equatable, Printable
A 4 by 4 matrix: an affine transform of 3D points, moving, turning, and scaling them, or a camera's projection.
Examples
Local move = Mat4.Translation(Vec3(1, 2, 3))
Expect(move.TransformPoint(Vec3(0, 0, 0)) == Vec3(1, 2, 3))
// A direction doesn't move.
Expect(move.TransformVector(Vec3(1, 0, 0)) == Vec3(1, 0, 0))
Expect(IsClose(Inverse(move).TransformPoint(Vec3(1, 2, 3)), Vec3(0, 0, 0)))
Local turn = Mat4.RotationY(Deg(90))
Expect(IsClose(turn.TransformPoint(Vec3(1, 0, 0)), Vec3(0, 0, -1)))-
Its first column.
-
Its second column.
-
Its third column.
-
Its fourth column, the translation.
-
The matrix that changes nothing.
-
The matrix that moves points by the vector.
-
The matrix that scales each axis by the vector's component.
-
The
rotation's matrix. -
The rotation by the
angle, in radians, about the X axis. -
The rotation by the
angle, in radians, about the Y axis. -
The rotation by the
angle, in radians, about the Z axis. -
The matrix that scales, then rotates, then moves, as an object's transform does: what Decompose takes apart.
-
@PanicsAtCaller Public Static Method LookAt(eye: Vec3, target: Vec3, up: Vec3): Mat4static method #The view matrix of a camera at
eyelooking attarget, with up toward the top of the view: it takes the world to where the camera, at the origin, looks down -Z. A target at theeye, or an up along the view, panics. -
@PanicsAtCaller Public Static Method Perspective(fieldOfView: Float, aspect: Float, near: Float, far: Float): Mat4static method #A perspective projection, with the field of view from the bottom of the view to its top, in radians, and the
aspect, its width over its height: depth goes from 0 atnearto 1 atfar. A field of view outside 0 to Pi, an aspect that isn't finite and above 0, or a near andfarthat aren't finite with 0 <near<far, panics. -
@PanicsAtCaller Public Static Method Orthographic(left: Float, right: Float, bottom: Float, top: Float, near: Float, far: Float): Mat4static method #An orthographic projection of the box from
lefttoright,bottomtotop, andneartofarin front of the camera, to -1 to 1 across and up, and depth from 0 atnearto 1 atfar. A box whose sides aren't finite, or where two that face each other are at one place, panics. -
The
pointtransformed, with its w taken as 1, for a matrix that moves, turns, and scales. -
The
directiontransformed, with its w taken as 0, so the matrix turns and scales it but doesn't move it. -
The
pointtransformed by a projection, divided by the w it gives, as the GPU does. -
The translation, rotation, and scale that Compose makes the matrix of: a transform that flips gives a negative X scale. A matrix with no inverse, as one that scales to 0 has none, panics; its determinant is worked out in Doubles, so a tiny scale's isn't 0.
-
The upper left 3 by 3, which turns and scales.
-
Its four columns, each as a Vec4 shows it.
-
The element in a column and a row, each from 0 to 3. Any other panics.
-
The transform by
b, then bya. -
The vector transformed.
-
mtimesscale. -
scaletimesm. -
mdivided byscale. -
aplusb. -
aminusb.
Report an issue with this page or with FutureBlitz on GitHub.