rapid-render
    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.

    curWorldM: number = -1

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

    matrix: MatrixStore = ...

    The underlying store for matrices.

    parentStack: DynamicArrayBuffer = ...

    Buffer used during hierarchy traversal updates.

    rapid: Rapid
    stack: DynamicArrayBuffer = ...

    Internal stack maintaining structural information.

    step: number = 0

    The current step or depth in the transformation hierarchy.

    stepAction: DynamicArrayBuffer = ...

    Records actions (push/pop) taken during the traversal.

    stepParentM: DynamicArrayBuffer = ...

    Records the parent world matrix for each step (used by updateMatrix).

    stepWorldM: DynamicArrayBuffer = ...

    Records the world matrices generated at each step.

    Methods

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

    • 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

    • 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().

      Returns { local: number; step: number; world: number }

      The current step counter before saving.

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

      Parameters

      • scaleX: number

        Scaling factor along the x-axis.

      • scaleY: number

        Scaling factor along the y-axis.

      Returns void

    • 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

    • Evaluates and updates matrices from the given step. Used primarily for deferred transformation.

      Parameters

      • step: number | { step: number }

        The initial step to update matrices from.

      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.