Skip to documentation
SLOP

tiny.linear.Mat3

Reference tiny.linear Mat3

Defined in tiny.linear.

API (13)

Actions

Public operations.

Types and contracts

Public types and contracts.

Fields and members

Public fields and members.

No direct callersNo direct callstiny.linearMat3
Static calls · unresolved targets: unknown · external targets: unknown.

Source

Source: lib/linear/src/matrix.zig:16

zig
pub const Mat3 = extern struct {    cols: [3]Vec3 = .{        .{ .x = 1 },        .{ .y = 1 },        .{ .z = 1 },    },    pub const identity: Mat3 = .{};    pub fn fromCols(c0: Vec3, c1: Vec3, c2: Vec3) Mat3 {        return .{ .cols = .{ c0, c1, c2 } };    }    pub fn fromScale(s: Vec3) Mat3 {        return fromCols(.{ .x = s.x }, .{ .y = s.y }, .{ .z = s.z });    }    /// The rotation matrix of the unit quaternion `q`.    pub fn fromQuat(q: Quat) Mat3 {        const xx = q.x * q.x;        const yy = q.y * q.y;        const zz = q.z * q.z;        const xy = q.x * q.y;        const xz = q.x * q.z;        const yz = q.y * q.z;        const wx = q.w * q.x;        const wy = q.w * q.y;        const wz = q.w * q.z;        return fromCols(            .{ .x = 1 - 2 * (yy + zz), .y = 2 * (xy + wz), .z = 2 * (xz - wy) },            .{ .x = 2 * (xy - wz), .y = 1 - 2 * (xx + zz), .z = 2 * (yz + wx) },            .{ .x = 2 * (xz + wy), .y = 2 * (yz - wx), .z = 1 - 2 * (xx + yy) },        );    }    pub fn row(m: Mat3, index: usize) Vec3 {        assert(index < 3);        const lanes = [3][3]f32{ m.cols[0].toArray(), m.cols[1].toArray(), m.cols[2].toArray() };        return .{ .x = lanes[0][index], .y = lanes[1][index], .z = lanes[2][index] };    }    pub fn transpose(m: Mat3) Mat3 {        return fromCols(m.row(0), m.row(1), m.row(2));    }    /// `m v`, summed as `c0 v.x + c1 v.y + c2 v.z`.    pub fn mulVec(m: Mat3, v: Vec3) Vec3 {        return m.cols[0].scale(v.x).add(m.cols[1].scale(v.y)).add(m.cols[2].scale(v.z));    }    /// `a b`: applying `b`, then `a`.    pub fn mul(a: Mat3, b: Mat3) Mat3 {        return fromCols(a.mulVec(b.cols[0]), a.mulVec(b.cols[1]), a.mulVec(b.cols[2]));    }    pub fn scale(m: Mat3, s: f32) Mat3 {        return fromCols(m.cols[0].scale(s), m.cols[1].scale(s), m.cols[2].scale(s));    }    pub fn determinant(m: Mat3) f32 {        return m.cols[0].dot(m.cols[1].cross(m.cols[2]));    }    /// The inverse, or null when the determinant is zero, NaN, or too small    /// for its reciprocal to be a finite nonzero f32.    pub fn inverse(m: Mat3) ?Mat3 {        const inverse_transposed = m.inverseTranspose() orelse return null;        return inverse_transposed.transpose();    }    /// The transpose of the inverse, which carries surface normals through    /// `m`. Null under the same condition as `inverse`.    pub fn inverseTranspose(m: Mat3) ?Mat3 {        const c0 = m.cols[1].cross(m.cols[2]);        const c1 = m.cols[2].cross(m.cols[0]);        const c2 = m.cols[0].cross(m.cols[1]);        const inverse_determinant = reciprocal(m.cols[0].dot(c0)) orelse return null;        return fromCols(c0, c1, c2).scale(inverse_determinant);    }};

Source: lib/linear/src/root.zig:12

zig
pub const Mat3 = matrix.Mat3;
Called byCallsNo direct callstest sourcelib.geometry.src.primitivetest: an oriented box maps points int...test sourcelib.linear.src.matrixtest: inverse undoes an invertible ma...test sourcelib.linear.src.matrixtest: matrices multiply column vector...Mat3fromCols
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsNo direct callsAffinefromScaleRotationTranslationtest sourcelib.linear.src.matrixtest: matrix product composes right t...test sourcelib.linear.src.matrixtest: quaternion matrix agrees with q...Mat3fromQuat
Static calls · unresolved targets: 1 · external targets: 0.
Called byCallsNo direct callsAffinefromScaleRotationTranslationtest sourcelib.linear.src.affinetest: inverse undoes the transform an...test sourcelib.linear.src.matrixtest: identity matrices are the defau...test sourcelib.linear.src.matrixtest: inverse returns null for singul...test sourcelib.linear.src.matrixtest: matrix product composes right t...Mat3fromScale
Static calls · unresolved targets: 1 · external targets: 0.
Called byCallsNo direct callersprivate sourcelib.linear.src.matrixreciprocalMat3inverseTranspose
Static calls · unresolved targets: 1 · external targets: 0.

Audit

Definitions13
Public names13
Members1
Version26.7.0
Revisiondaab053ee433