starry-math
    Preparing search index...

    Class Matrix4

    Represents a 4x4 transformation matrix used for 3D transformations. This class provides methods for matrix composition, decomposition, multiplication, inversion, and various transformation operations like translation, rotation, and scaling.

    Implements

    Index

    Constructors

    • Constructs a new Matrix4 instance.

      Parameters

      • Optionalvalue: [
            number,
            number,
            number,
            number,
            number,
            number,
            number,
            number,
            number,
            number,
            number,
            number,
            number,
            number,
            number,
            number,
        ]

        Optional initial matrix values. If not provided, identity matrix is created.

      Returns Matrix4

    Methods

    • Creates a new Matrix4 with the same values as this matrix.

      Returns Matrix4

      A new Matrix4 instance with the same values.

    • Composes this matrix from position, Euler rotation, and scale components.

      Parameters

      • position: Vector3

        The translation component.

      • euler: Euler

        The rotation component as Euler angles.

      • scale: Vector3

        The scaling component.

      Returns this

      This matrix for chaining.

    • Copies the values from another matrix into this matrix.

      Parameters

      • source: Matrix4

        The matrix to copy values from.

      Returns this

      This matrix for chaining.

    • Decomposes this matrix into its position, Euler rotation, and scale components.

      Parameters

      • outPosition: Vector3

        The vector to store the extracted position.

      • outEuler: Euler

        The Euler object to store the extracted rotation.

      • outScale: Vector3

        The vector to store the extracted scale.

      Returns this

      This matrix for chaining.

    • Applies a drop shadow effect by multiplying with a shadow projection matrix.

      Parameters

      • plane: PlaneEquation

        The plane equation representing the surface where the shadow is cast.

      • light: Vector4

        The light position/direction as a homogeneous vector.

      Returns this

      This matrix for chaining.

    • Checks if this matrix is equal to another matrix.

      Parameters

      • matrix: Matrix4

        The matrix to compare with this matrix.

      Returns boolean

      True if the matrices are equal, false otherwise.

    • Sets this matrix to a frustum projection matrix.

      Parameters

      • left: number

        The coordinate for the left clipping plane.

      • right: number

        The coordinate for the right clipping plane.

      • bottom: number

        The coordinate for the bottom clipping plane.

      • top: number

        The coordinate for the top clipping plane.

      • near: number

        The distance to the near clipping plane.

      • far: number

        The distance to the far clipping plane.

      Returns this

      This matrix for chaining.

    • Sets this matrix to the identity matrix.

      Returns this

      This matrix for chaining.

    • Computes the inverse of this matrix and replaces this matrix with the result. If the matrix is singular (not invertible), it remains unchanged.

      Returns this

      This matrix for chaining.

    • Creates a look-at view matrix.

      Parameters

      • eye: Vector3

        Position of the eye/camera.

      • target: Vector3

        Position of the target to look at.

      • up: Vector3

        Up vector defining the camera orientation.

      Returns this

      This matrix for chaining.

    • Multiplies this matrix by another matrix (this = this * other).

      Parameters

      • other: Matrix4

        The matrix to multiply with this matrix.

      Returns this

      This matrix for chaining.

    • Multiplies two matrices (this = a * b) and stores the result in this matrix.

      Parameters

      • a: Matrix4

        The first matrix to multiply.

      • b: Matrix4

        The second matrix to multiply.

      Returns this

      This matrix for chaining.

    • Sets this matrix to an orthographic projection matrix.

      Parameters

      • left: number

        The coordinate for the left clipping plane.

      • right: number

        The coordinate for the right clipping plane.

      • bottom: number

        The coordinate for the bottom clipping plane.

      • top: number

        The coordinate for the top clipping plane.

      • near: number

        The distance to the near clipping plane.

      • far: number

        The distance to the far clipping plane.

      Returns this

      This matrix for chaining.

    • Sets this matrix to a perspective projection matrix.

      Parameters

      • fov: number

        Field of view in degrees.

      • aspect: number

        Aspect ratio (width / height).

      • near: number

        Distance to the near clipping plane.

      • far: number

        Distance to the far clipping plane.

      Returns this

      This matrix for chaining.

    • Premultiplies this matrix by another matrix (this = other * this).

      Parameters

      • other: Matrix4

        The matrix to premultiply with this matrix.

      Returns this

      This matrix for chaining.

    • Rotates this matrix around the specified axis by the given angle.

      Parameters

      • angle: number

        Rotation angle in radians (positive for counter-clockwise).

      • axis: Coordinate3D

        Rotation axis.

      Returns this

      This matrix for chaining.

    • Sets this matrix to a rotation matrix derived from Euler angles.

      Parameters

      • euler: Euler

        Euler angles representing the rotation.

      Returns this

      This matrix for chaining.

    • Scales this matrix by the given factors.

      Parameters

      • x: number

        Scale factor along the X axis.

      • y: number

        Scale factor along the Y axis.

      • z: number

        Scale factor along the Z axis.

      Returns this

      This matrix for chaining.

    • Returns the matrix values as an array.

      Returns [
          number,
          number,
          number,
          number,
          number,
          number,
          number,
          number,
          number,
          number,
          number,
          number,
          number,
          number,
          number,
          number,
      ]

      The 16-element array representing this matrix.

    • Translates this matrix by the given offset.

      Parameters

      • x: number

        Translation along the X axis.

      • y: number

        Translation along the Y axis.

      • z: number

        Translation along the Z axis.

      Returns this

      This matrix for chaining.

    • Transposes this matrix in place.

      Returns this

      This matrix for chaining.