Class MatrixHandler
- java.lang.Object
-
- nub.core.MatrixHandler
-
public class MatrixHandler extends Object
The matrix handler specifies (and implements) various matrix operations needed by theGraphto 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
Graphobject 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 StringERROR_PUSHMATRIX_OVERFLOWstatic StringERROR_PUSHMATRIX_UNDERFLOWstatic intSTACK_DEPTH
-
Constructor Summary
Constructors Constructor Description MatrixHandler()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidapplyMatrix(Matrix source)Multiplies the currentmodel()matrix by the one specified through the parameters.voidapplyProjection(Matrix source)Multiplies the currentprojection()matrix by the one specified through the parameters.voidapplyTransformation(Node node)Apply the local transformation defined bynode, i.e., respect to itsNode.reference().voidapplyWorldTransformation(Node node)Similar toapplyTransformation(Node), but applies the global transformation defined by thenode.voidbeginHUD(int width, int height)Begins Heads Up Display (HUD).voidbind(Matrix projection, Matrix view)voidendHUD()Ends Heads Up Display (HUD).Matrixmodel()Returns the model matrix.Matrixmodelview()Same asreturn Matrix.multiply(view(), model()).voidpopMatrix()Replace the currentmodel()matrix with the top of the stack.voidpopProjection()Replace the currentprojection()matrix with the top of the stack.Matrixprojection()Returns the projection matrix.voidpushMatrix()Push a copy of themodel()matrix onto the stack.voidpushProjection()Push a copy of theprojection()matrix onto the stack.voidrotate(float angle)Rotate around the Z axis.voidrotate(float angle, float v0, float v1, float v2)Rotate about a vector in space.voidscale(float sx, float sy)Scale in X and Y.voidscale(float sx, float sy, float sz)Scale in X, Y, and Z.Matrixtransform()Returnsprojection()timesmodelview().voidtranslate(float x, float y)Translate in X and Y.voidtranslate(float x, float y, float z)Translate in X, Y, and Z.Matrixview()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(). Thenodeis 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.
-
-