Skip to content
FutureBlitz

    Install

    Import std.math.matrix

    Mat4

    std.math.matrix

    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)))

    std/math/matrix.fb, line 132

    • Public Field x: Vec4 field #

      Its first column.

    • Public Field y: Vec4 field #

      Its second column.

    • Public Field z: Vec4 field #

      Its third column.

    • Public Field w: Vec4 field #

      Its fourth column, the translation.

    • Public Static Property Identity: Mat4 property #

      The matrix that changes nothing.

    • Public Static Method Translation(offset: Vec3): Mat4 static method #

      The matrix that moves points by the vector.

    • Public Static Method Scale(scale: Vec3): Mat4 static method #

      The matrix that scales each axis by the vector's component.

    • Public Static Method Rotation(rotation: Quat): Mat4 static method #

      The rotation's matrix.

    • Public Static Method RotationX(angle: Float): Mat4 static method #

      The rotation by the angle, in radians, about the X axis.

    • Public Static Method RotationY(angle: Float): Mat4 static method #

      The rotation by the angle, in radians, about the Y axis.

    • Public Static Method RotationZ(angle: Float): Mat4 static method #

      The rotation by the angle, in radians, about the Z axis.

    • Public Static Method Compose(translation: Vec3, rotation: Quat, scale: Vec3): Mat4 static method #

      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): Mat4 static method #

      The view matrix of a camera at eye looking at target, 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 the eye, or an up along the view, panics.

    • @PanicsAtCaller Public Static Method Perspective(fieldOfView: Float, aspect: Float, near: Float, far: Float): Mat4 static 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 at near to 1 at far. A field of view outside 0 to Pi, an aspect that isn't finite and above 0, or a near and far that 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): Mat4 static method #

      An orthographic projection of the box from left to right, bottom to top, and near to far in front of the camera, to -1 to 1 across and up, and depth from 0 at near to 1 at far. A box whose sides aren't finite, or where two that face each other are at one place, panics.

    • Public Method TransformPoint(point: Vec3): Vec3 method #

      The point transformed, with its w taken as 1, for a matrix that moves, turns, and scales.

    • Public Method TransformVector(direction: Vec3): Vec3 method #

      The direction transformed, with its w taken as 0, so the matrix turns and scales it but doesn't move it.

    • Public Method ProjectPoint(point: Vec3): Vec3 method #

      The point transformed by a projection, divided by the w it gives, as the GPU does.

    • @PanicsAtCaller Public Method Decompose(): (Vec3, Quat, Vec3) method #

      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.

    • Public Method ToMat3(): Mat3 method #

      The upper left 3 by 3, which turns and scales.

    • Public Method ToString(): String method #

      Its four columns, each as a Vec4 shows it.

    • @PanicsAtCaller Operator [](column: Int, row: Int): Float operator #

      The element in a column and a row, each from 0 to 3. Any other panics.

    • Operator *(a: Mat4, b: Mat4): Mat4 operator #

      The transform by b, then by a.

    • Operator *(m: Mat4, v: Vec4): Vec4 operator #

      The vector transformed.

    • Operator *(m: Mat4, scale: Float): Mat4 operator #

      m times scale.

    • Operator *(scale: Float, m: Mat4): Mat4 operator #

      scale times m.

    • Operator /(m: Mat4, scale: Float): Mat4 operator #

      m divided by scale.

    • Operator +(a: Mat4, b: Mat4): Mat4 operator #

      a plus b.

    • Operator -(a: Mat4, b: Mat4): Mat4 operator #

      a minus b.

    Report an issue with this page or with FutureBlitz on GitHub.