Engine API Reference - v2.23.0-beta.17
    Preparing search index...

    Class Mat3

    A 3x3 matrix. Mat3 is commonly used to represent rotation matrices, 2D transformations or the upper-left portion of a 4x4 matrix for transforming normals.

    A new Mat3 is the identity. Elements live in data, a 9-element Float32Array in column-major order, so the first three entries are the first column. Build one from a rotation with setFromQuat, or take the upper-left 3x3 of a Mat4 with setFromMat4, and apply it to a Vec3 with transformVector. getX, getY and getZ read the columns, which for a rotation matrix are its axes.

    Methods modify the matrix they are called on and return it for chaining. Use clone for an independent copy and copy to overwrite. IDENTITY and ZERO are frozen shared instances.

    // Take the rotation and scale of an entity's world transform and apply it to a direction
    const rotationScale = new Mat3().setFromMat4(entity.getWorldTransform());
    const worldDirection = rotationScale.transformVector(localDirection);
    Index
    data: Float32Array<ArrayBufferLike> = ...

    Matrix elements in the form of a flat array.

    IDENTITY: Mat3 = ...

    A constant matrix set to the identity.

    ZERO: Mat3 = ...

    A constant matrix with all elements set to 0.

    • Creates a duplicate of the specified matrix.

      Returns Mat3

      A duplicate matrix.

      const src = new Mat3().setFromQuat(new Quat(0, 0, 0.383, 0.924));
      const dst = src.clone();
      console.log("The two matrices are " + (src.equals(dst) ? "equal" : "different"));
    • Copies the contents of a source 3x3 matrix to a destination 3x3 matrix.

      Parameters

      • rhs: Mat3

        A 3x3 matrix to be copied.

      Returns Mat3

      Self for chaining.

      const src = new Mat3().setFromQuat(new Quat(0, 0, 0.383, 0.924));
      const dst = new Mat3();
      dst.copy(src);
      console.log("The two matrices are " + (src.equals(dst) ? "equal" : "different"));
    • Reports whether two matrices are equal.

      Parameters

      • rhs: Mat3

        The other matrix.

      Returns boolean

      True if the matrices are equal and false otherwise.

      const a = new Mat3().setFromQuat(new Quat(0, 0, 0.383, 0.924));
      const b = new Mat3();
      console.log("The two matrices are " + (a.equals(b) ? "equal" : "different"));
    • Extracts the x-axis from the specified matrix.

      Parameters

      • Optionalx: Vec3 = ...

        The vector to receive the x axis of the matrix.

      Returns Vec3

      The x-axis of the specified matrix.

      const m = new Mat3();
      const xAxis = m.getX(); // Vec3(1, 0, 0) for identity matrix
    • Extracts the y-axis from the specified matrix.

      Parameters

      • Optionaly: Vec3 = ...

        The vector to receive the y axis of the matrix.

      Returns Vec3

      The y-axis of the specified matrix.

      const m = new Mat3();
      const yAxis = m.getY(); // Vec3(0, 1, 0) for identity matrix
    • Extracts the z-axis from the specified matrix.

      Parameters

      • Optionalz: Vec3 = ...

        The vector to receive the z axis of the matrix.

      Returns Vec3

      The z-axis of the specified matrix.

      const m = new Mat3();
      const zAxis = m.getZ(); // Vec3(0, 0, 1) for identity matrix
    • Reports whether the specified matrix is the identity matrix.

      Returns boolean

      True if the matrix is identity and false otherwise.

      const m = new Mat3();
      console.log("The matrix is " + (m.isIdentity() ? "identity" : "not identity"));
    • Copies the contents of a source array[9] to a destination 3x3 matrix.

      Parameters

      • src: number[]

        An array[9] to be copied.

      Returns Mat3

      Self for chaining.

      const dst = new Mat3();
      dst.set([0, 1, 2, 3, 4, 5, 6, 7, 8]);
    • Converts the specified 4x4 matrix to a Mat3.

      Parameters

      • m: Mat4

        The 4x4 matrix to convert.

      Returns Mat3

      Self for chaining.

      const m4 = new Mat4();
      const m3 = new Mat3().setFromMat4(m4);
    • Sets this matrix to the given quaternion rotation.

      Parameters

      • r: Quat

        A quaternion rotation.

      Returns Mat3

      Self for chaining.

      const r = new Quat(1, 2, 3, 4).normalize();

      const m = new Mat3();
      m.setFromQuat(r);
    • Sets the matrix to the identity matrix.

      Returns Mat3

      Self for chaining.

      m.setIdentity();
      console.log("The matrix is " + (m.isIdentity() ? "identity" : "not identity"));
    • Converts the matrix to string form.

      Returns string

      The matrix in string form.

      const m = new Mat3();
      // Outputs [1, 0, 0, 0, 1, 0, 0, 0, 1]
      console.log(m.toString());
    • Transforms a 3-dimensional vector by a 3x3 matrix.

      Parameters

      • vec: Vec3

        The 3-dimensional vector to be transformed.

      • Optionalres: Vec3 = ...

        An optional 3-dimensional vector to receive the result of the transformation.

      Returns Vec3

      The input vector v transformed by the current instance.

      const m = new Mat3();
      const v = new Vec3(1, 2, 3);
      const result = m.transformVector(v);
    • Generates the transpose of the specified 3x3 matrix.

      Parameters

      • Optionalsrc: Mat3 = ...

        The matrix to transpose. If not set, the matrix is transposed in-place.

      Returns Mat3

      Self for chaining.

      const m = new Mat3();

      // Transpose in place
      m.transpose();