Class MatrixHandler
- java.lang.Object
-
- nub.core.MatrixHandler
-
public class MatrixHandler extends Object
The matrix handler specifies (and implements) various matrix operations needed by theGraph
to properly perform its geometry transformations.To emit the
transform()
matrix to a shader override the_setUniforms()
signal, which is fired automatically by the handler every time one of its matrices change state. See alsoprojection()
,view()
andmodel()
.To bind a
Graph
object to a third party renderer (i.e., that renderer provides its own matrix handling: matrix transformations, shader uniforms transfers, etc), refer to thebind(Matrix, Matrix)
documentation.
-
-
Field Summary
Fields Modifier and Type Field Description static String
ERROR_PUSHMATRIX_OVERFLOW
static String
ERROR_PUSHMATRIX_UNDERFLOW
static int
STACK_DEPTH
-
Constructor Summary
Constructors Constructor Description MatrixHandler()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
applyMatrix(Matrix source)
Multiplies the currentmodel()
matrix by the one specified through the parameters.void
applyProjection(Matrix source)
Multiplies the currentprojection()
matrix by the one specified through the parameters.void
applyTransformation(Node node)
Apply the local transformation defined bynode
, i.e., respect to itsNode.reference()
.void
applyWorldTransformation(Node node)
Similar toapplyTransformation(Node)
, but applies the global transformation defined by thenode
.void
beginHUD(int width, int height)
Begins Heads Up Display (HUD).void
bind(Matrix projection, Matrix view)
void
endHUD()
Ends Heads Up Display (HUD).Matrix
model()
Returns the model matrix.Matrix
modelview()
Same asreturn Matrix.multiply(view(), model())
.void
popMatrix()
Replace the currentmodel()
matrix with the top of the stack.void
popProjection()
Replace the currentprojection()
matrix with the top of the stack.Matrix
projection()
Returns the projection matrix.void
pushMatrix()
Push a copy of themodel()
matrix onto the stack.void
pushProjection()
Push a copy of theprojection()
matrix onto the stack.void
rotate(float angle)
Rotate around the Z axis.void
rotate(float angle, float v0, float v1, float v2)
Rotate about a vector in space.void
scale(float sx, float sy)
Scale in X and Y.void
scale(float sx, float sy, float sz)
Scale in X, Y, and Z.Matrix
transform()
Returnsprojection()
timesmodelview()
.void
translate(float x, float y)
Translate in X and Y.void
translate(float x, float y, float z)
Translate in X, Y, and Z.Matrix
view()
Returns the view matrix.
-
-
-
Method Detail
-
bind
public void bind(Matrix projection, Matrix view)
Updates theprojection()
,view()
andmodel()
matrices and call_setUniforms()
. This method is automatically called byGraph.render()
right at the beginning of the main event loop.If this matrix handler is bound to a third party renderer (i.e., that renderer provides its own matrix matrix handling: matrix transformations, shader uniforms transfers, etc.) override this method together with:
_bindProjection(Matrix)
,_bindMatrix(Matrix)
,model()
,modelview()
,applyMatrix(Matrix)
,pushMatrix()
,popMatrix()
,translate(float, float, float)
,rotate(float)
,rotate(float, float, float, float)
,scale(float, float, float)
,projection()
,_bindProjection(Matrix)
,applyProjection(Matrix)
,pushProjection()
andpopProjection()
by implementing them in terms of that renderer.- See Also:
Graph.render()
,Node.view()
-
projection
public Matrix projection()
Returns the projection matrix.- See Also:
view()
,model()
,modelview()
,transform()
-
view
public Matrix view()
Returns the view matrix.- See Also:
projection()
,model()
,modelview()
,transform()
-
model
public Matrix model()
Returns the model matrix.- See Also:
projection()
,view()
,modelview()
,transform()
-
modelview
public Matrix modelview()
Same asreturn Matrix.multiply(view(), model())
.- See Also:
projection()
,view()
,model()
,transform()
-
transform
public Matrix transform()
Returnsprojection()
timesmodelview()
.- See Also:
projection()
,view()
,model()
,modelview()
-
applyMatrix
public void applyMatrix(Matrix source)
Multiplies the currentmodel()
matrix by the one specified through the parameters. Calls_setUniforms()
.
-
applyProjection
public void applyProjection(Matrix source)
Multiplies the currentprojection()
matrix by the one specified through the parameters. Calls_setUniforms()
.
-
pushMatrix
public void pushMatrix()
Push a copy of themodel()
matrix onto the stack.
-
popMatrix
public void popMatrix()
Replace the currentmodel()
matrix with the top of the stack. Calls_setUniforms()
.
-
translate
public void translate(float x, float y, float z)
Translate in X, Y, and Z. Calls_setUniforms()
.
-
rotate
public void rotate(float angle)
Rotate around the Z axis. Calls_setUniforms()
.
-
rotate
public void rotate(float angle, float v0, float v1, float v2)
Rotate about a vector in space. Calls_setUniforms()
.
-
scale
public void scale(float sx, float sy, float sz)
Scale in X, Y, and Z. Calls_setUniforms()
.
-
pushProjection
public void pushProjection()
Push a copy of theprojection()
matrix onto the stack.
-
popProjection
public void popProjection()
Replace the currentprojection()
matrix with the top of the stack. Calls_setUniforms()
.
-
beginHUD
public void beginHUD(int width, int height)
Begins Heads Up Display (HUD).Binds
Matrix.hudProjection(width, height)
andMatrix.hudView(width, height)
so that so that drawing can be done using 2D screen coordinates. Calls_setUniforms()
.
-
endHUD
public void endHUD()
Ends Heads Up Display (HUD).Restores the
projection()
andmodel()
matrices. SeebeginHUD(int, int)
for details.- See Also:
beginHUD(int, int)
-
applyTransformation
public void applyTransformation(Node node)
Apply the local transformation defined bynode
, i.e., respect to itsNode.reference()
. Thenode
is first translated, then rotated around the new translated origin and then scaled.
-
applyWorldTransformation
public void applyWorldTransformation(Node node)
Similar toapplyTransformation(Node)
, but applies the global transformation defined by thenode
.
-
translate
public void translate(float x, float y)
Translate in X and Y.
-
scale
public void scale(float sx, float sy)
Scale in X and Y. Equivalent to scale(sx, sy, 1).Not recommended for use in 3D, because the z-dimension is just scaled by 1, since there's no way to know what else to scale it by.
-
-