Rapid Render API
    Preparing search index...

    Class MatrixStack

    A highly performant MatrixStack useful for hierarchal scene graphs. Handles both local and world transformations automatically.

    Index

    Constructors

    Properties

    curLocalM: number = -1

    The index of the current local matrix in the matrix store.

    currStack: DynamicArrayBuffer = ...
    curWorldM: number = -1

    The index of the current world matrix in the matrix store.

    matrix: MatrixStore = ...

    The underlying store for matrices.

    rapid: Rapid
    stack: DynamicArrayBuffer = ...

    Internal stack maintaining structural information.

    Methods

    • Parameters

      • transform: ITransformOptions
      • Optionalwidth: number
      • Optionalheight: number
      • OptionalcustomMatrix: number
      • OptionalworldMatrix: number
      • OptionallocalMatrix: number

      Returns void

    • Parameters

      • x: number
      • y: number
      • OptionalscaleX: number
      • OptionalscaleY: number
      • Optionalrotation: number
      • OptionaloriginX: number
      • OptionaloriginY: number
      • Optionalwidth: number
      • Optionalheight: number
      • OptionaloffsetX: number
      • OptionaloffsetY: number
      • OptionalcustomMatrix: number
      • OptionalworldMatrix: number
      • OptionallocalMatrix: number

      Returns void

    • Extracts the global position (translation) from the current world matrix.

      Returns { x: number; y: number }

      An object containing x and y global coordinates.

    • Extracts the global rotation (in radians) from the current world matrix.

      Returns number

      The global rotation in radians.

    • Extracts the global scale from the current world matrix.

      Returns { x: number; y: number }

      An object containing x and y global scale factors.

    • Returns the current world matrix as Float32Array [a, b, c, d, tx, ty].

      Returns Float32Array

    • Sets the current local and world matrices to the identity matrix.

      Returns void

    • Transforms a point from local coordinates to world coordinates. Uses the current world matrix to apply the transformation.

      Parameters

      • x: number

        Local x coordinate.

      • y: number

        Local y coordinate.

      Returns { x: number; y: number }

      The transformed point in world coordinates.

    • Resets the entire stack state context, clearing matrices and step actions.

      Returns void

    • Restores the matrix state from the top of the stack. Equivalent to context.restore().

      Returns void

    • Removes a matrix from the frame recycle queue so it remains valid across reset() calls.

      Passing a MatrixSaveState retains its local and world matrices; parent is not retained because it belongs to the parent stack state. Retained matrices must eventually be released with matrix.free().

      Type Parameters

      Parameters

      • matrix: T

        A matrix ID or the state returned by save().

      Returns T

      The supplied ID or state, preserving its input type.

    • Rotates the current local and world matrices by the given radians.

      Parameters

      • radians: number

        The rotation angle in radians.

      Returns void

    • Rotates the current local and world matrices around a pivot point that is offset from the matrix origin by (offsetX, offsetY).

      This is a convenience wrapper around the common translate → rotate → translate-back pattern, avoiding manual coordinate juggling at the call site.

      Parameters

      • radians: number

        The rotation angle in radians.

      • offsetX: number

        The x component of the pivot point in local space.

      • offsetY: number

        The y component of the pivot point in local space.

      Returns void

      // Rotate a 64×64 sprite around its centre
      stack.rotateWithOffset(angle, 32, 32);
    • Saves the current matrix state and pushes it onto the stack. Equivalent to context.save(). Provided matrix IDs are used directly and remain caller-owned; only matrices created by this call are queued for recycling by reset().

      Parameters

      • OptionalmatrixWorld: number | MatrixSaveState

        Optional world matrix ID or saved state from this store; defaults to parent * local.

      • OptionalmatrixLocal: number

        Optional local matrix ID from this store; defaults to identity.

      Returns MatrixSaveState

      Matrix IDs for the saved parent, local, and world transforms.

    • Scales the current local and world matrices by scaleX and scaleY.

      Parameters

      • scaleX: number

        Scaling factor along the x-axis.

      • scaleY: number = scaleX

        Scaling factor along the y-axis.

      Returns void

    • Directly overwrites the current world matrix with the given 6-element 2D transform.

      Parameters

      • f: Float32Array

      Returns void

    • Parameters

      • x: number
      • y: number

      Returns { x: number; y: number }

    • Translates the current local and world matrices by x and y.

      Parameters

      • x: number

        Translation along the x-axis.

      • y: number

        Translation along the y-axis.

      Returns void

    • Transforms a point from world coordinates to local coordinates. Useful for hit testing against objects placed in world space.

      Parameters

      • x: number

        World x coordinate.

      • y: number

        World y coordinate.

      Returns { x: number; y: number }

      The transformed point in local coordinates.