Skip to content
FutureBlitz

    Install

    Import std.math.matrix

    std.math.matrix

    Mat3 and Mat4: matrices of Floats, column-major, as the GPU takes them. Each column is a Field, x, y, z, and w, a vector of where the matrix takes that axis, and the last of a Mat4 is where it takes the origin. m * v transforms v, and a * b transforms by b, then by a. The projections are right-handed, looking down -Z, with depth from 0 at near to 1 at far, as Vulkan's.

    std/math/matrix.fb

    Types

    Mat3 struct

    Public Struct Mat3 Implements Equatable, Printable

    A 3 by 3 matrix: a rotation, a scale, or both, of 3D vectors.

    std/math/matrix.fb, line 13

    • Public Field x: Vec3 field #

      Its first column.

    • Public Field y: Vec3 field #

      Its second column.

    • Public Field z: Vec3 field #

      Its third column.

    • Public Static Property Identity: Mat3 property #

      The matrix that changes nothing.

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

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

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

      The rotation's matrix.

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

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

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

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

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

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

    • Public Method ToMat4(): Mat4 method #

      The matrix as a Mat4 that moves nothing.

    • Public Method ToString(): String method #

      Its text, as a string interpolation like "{value}" shows it.

      Doc from std.core.interfaces.Printable.ToString.

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

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

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

      The transform by b, then by a.

    • Operator *(m: Mat3, v: Vec3): Vec3 operator #

      The vector transformed.

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

      m times scale.

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

      scale times m.

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

      m divided by scale.

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

      a plus b.

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

      a minus b.

    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.

    std/math/matrix.fb, line 93

    • 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 text, as a string interpolation like "{value}" shows it.

      Doc from std.core.interfaces.Printable.ToString.

    • @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.

    Functions

    Transpose function

    Public Function Transpose(m: Mat3): Mat3

    The matrix with its rows for columns.

    std/math/matrix.fb, line 273

    Transpose function

    Public Function Transpose(m: Mat4): Mat4

    The matrix with its rows for columns.

    std/math/matrix.fb, line 278

    Determinant function

    Public Function Determinant(m: Mat3): Float

    How the matrix scales volume, negative where it flips: 0 for one with no inverse. It's worked out in Doubles, which hold any three Floats' products, and rounded once.

    std/math/matrix.fb, line 285

    Determinant function

    Public Function Determinant(m: Mat4): Float

    How the matrix scales volume, negative where it flips: 0 for one with no inverse. It's worked out in Doubles, which hold any four Floats' products, and rounded once.

    std/math/matrix.fb, line 292

    TryInverse function

    Public Function TryInverse(m: Mat3): Mat3?

    The matrix that undoes this one, or Null for one with no inverse, whose determinant is 0. The inverse's rows are the cross products of the other two columns, over the determinant, worked out in Doubles, so a matrix of a tiny or huge scale inverts too.

    std/math/matrix.fb, line 324

    TryInverse function

    Public Function TryInverse(m: Mat4): Mat4?

    The matrix that undoes this one, or Null for one with no inverse, whose determinant is 0: the cofactors over the determinant, by the minors of the first two columns and the last two, as Geometric Tools expands them, in Doubles, so a matrix of a tiny or huge scale inverts too.

    std/math/matrix.fb, line 341

    Inverse function

    @PanicsAtCaller Public Function Inverse(m: Mat3): Mat3

    The matrix that undoes this one. One with no inverse, whose determinant is 0, panics.

    std/math/matrix.fb, line 367

    Inverse function

    @PanicsAtCaller Public Function Inverse(m: Mat4): Mat4

    The matrix that undoes this one. One with no inverse, whose determinant is 0, panics.

    std/math/matrix.fb, line 375

    IsClose function

    Public Function IsClose(a: Mat3, b: Mat3): Bool

    Whether each element is close to b's, as IsClose tells for Floats.

    std/math/matrix.fb, line 383

    IsClose function

    Public Function IsClose(a: Mat4, b: Mat4): Bool

    Whether each element is close to b's, as IsClose tells for Floats.

    std/math/matrix.fb, line 388

    IsClose function

    Public Function IsClose(a: Mat3, b: Mat3, tolerance: Float): Bool

    Whether each element is no further from b's than tolerance.

    std/math/matrix.fb, line 393

    IsClose function

    Public Function IsClose(a: Mat4, b: Mat4, tolerance: Float): Bool

    Whether each element is no further from b's than tolerance.

    std/math/matrix.fb, line 399

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