MatrixStack
final class MatrixStack
Package: dev.joid.lib.bridge.render.matrix · Module: core · Source: MatrixStack.java
A 4×4 transformation matrix with a stack that saves and restores it, as the model-view and the projection of the render bridge.
Description
Section titled “Description”getModelView() of the render bridge, BridgeHandler.RENDER.get(), moves, turns and scales what you draw next; getProjection() maps the design canvas to the target.
The calls compose as in OpenGL: the last call applies first to what you draw.
Matrices are 16 floats in column-major order.
Learn more
Section titled “Learn more”Creation
Section titled “Creation”| Returns | Signature | Summary |
|---|---|---|
| MatrixStack() | Creates a stack with the identity matrix and nothing saved. |
Methods
Section titled “Methods”Queries
Section titled “Queries”| Returns | Signature | Summary |
|---|---|---|
int | getDepth() | Returns the number of saved matrices. |
float[] | getMatrix() | Returns a copy of the current matrix. |
float[] | getRawMatrix() | Returns the current matrix itself, without a copy, for a backend that reads it at every draw. |
float[] | getNormalMatrix() | Returns the 3×3 matrix, column-major, that transforms normals for the current matrix: the inverse transpose of its rotation and scale part, all zeros when that part cannot be inverted. |
Actions
Section titled “Actions”| Returns | Signature | Summary |
|---|---|---|
void | push() | Saves a copy of the current matrix. |
void | pop() | Restores the matrix that the last push() saved. |
void | pop(int depth) | Restores saved matrices until depth of them remain; nothing happens when the stack holds depth or fewer. |
void | with(Consumer | Saves the matrix, runs body with the stack, then restores the matrix, even when body throws. |
void | identity() | Replaces the current matrix with the identity: no transformation. |
void | translate(double x, double y, double z) | Moves what you draw next by x, y and z, in design pixels in a UI. |
void | scale(double x, double y, double z) | Scales what you draw next by x, y and z around the current origin; a negative factor mirrors. |
void | rotate(double angle, double x, double y, double z) | Turns what you draw next by angle degrees around the axis x, y, z through the current origin. |
void | ortho(double left, double right, double bottom, double top, double near, double far) | Replaces the current matrix with an orthographic projection that maps left to right and bottom to top onto the target, between the depths near and far. |
void | multiply(float[] other) | Multiplies the current matrix by 16 values in column-major order, applied before the current matrix. |
void | load(float[] matrix) | Replaces the current matrix with a copy of 16 values in column-major order. |
Creation details
Section titled “Creation details”MatrixStack
Section titled “MatrixStack”MatrixStack()
Creates a stack with the identity matrix and nothing saved.
Method details
Section titled “Method details”getDepth
Section titled “getDepth”int getDepth()
Returns the number of saved matrices.
getMatrix
Section titled “getMatrix”float[] getMatrix()
Returns a copy of the current matrix.
getRawMatrix
Section titled “getRawMatrix”float[] getRawMatrix()
Returns the current matrix itself, without a copy, for a backend that reads it at every draw. Never change the array: the next call of the stack can replace it or change it in place.
getNormalMatrix
Section titled “getNormalMatrix”float[] getNormalMatrix()
Returns the 3×3 matrix, column-major, that transforms normals for the current matrix: the inverse transpose of its rotation and scale part, all zeros when that part cannot be inverted.
Shaders receive it as uNormalMatrix.
void push()
Saves a copy of the current matrix.
Prefer with(...), which restores it even when your code throws.
void pop()
Restores the matrix that the last push() saved.
Throws NoSuchElementException when nothing is saved.
void pop(int depth)
Restores saved matrices until depth of them remain; nothing happens when the stack holds depth or fewer.
void with(Consumer<MatrixStack> body)
Saves the matrix, runs body with the stack, then restores the matrix, even when body throws.
identity
Section titled “identity”void identity()
Replaces the current matrix with the identity: no transformation.
translate
Section titled “translate”void translate(double x, double y, double z)
Moves what you draw next by x, y and z, in design pixels in a UI.
void scale(double x, double y, double z)
Scales what you draw next by x, y and z around the current origin; a negative factor mirrors.
rotate
Section titled “rotate”void rotate(double angle, double x, double y, double z)
Turns what you draw next by angle degrees around the axis x, y, z through the current origin.
In a UI, the axis 0D, 0D, 1D turns in the plane of the screen; a zero axis does nothing.
void ortho(double left, double right, double bottom, double top, double near, double far)
Replaces the current matrix with an orthographic projection that maps left to right and bottom to top onto the target, between the depths near and far.
A bottom larger than top puts the origin at the top-left corner, as the projection of a UI does.
multiply
Section titled “multiply”void multiply(float[] other)
Multiplies the current matrix by 16 values in column-major order, applied before the current matrix.
void load(float[] matrix)
Replaces the current matrix with a copy of 16 values in column-major order.
fluent returns the instance, typed for chaining · factory creates an instance · signal also accepts a value that follows signals, as a signal, an expression or a lambda (When does JOID compute this value again?) · hook called by JOID, override it · abstract you implement it · default interface method with a body · static called on the class · protected visible to subclasses
