use of au.gov.asd.tac.constellation.utilities.graphics.Matrix44f in project constellation by constellation-app.
the class FPSRenderable method display.
@Override
public void display(final GLAutoDrawable drawable, final Matrix44f pMatrix) {
if (start == 0) {
start = System.currentTimeMillis();
}
if ((System.currentTimeMillis() - start) >= 500) {
fps = countFps << 1;
start = 0;
countFps = 0;
}
countFps++;
if (enabled) {
final GL3 gl = drawable.getGL().getGL3();
// extract and scale the rotation matrix from the mvp matrix
final Matrix44f scalingMatrix = new Matrix44f();
scalingMatrix.makeScalingMatrix(pxScale, pyScale, 0);
final Matrix44f srMatrix = new Matrix44f();
srMatrix.multiply(scalingMatrix, IDENTITY_44F);
// build the fps matrix by translating the sr matrix
final Matrix44f translationMatrix = new Matrix44f();
translationMatrix.makeTranslationMatrix(bottomRightCorner.getX(), bottomRightCorner.getY(), bottomRightCorner.getZ());
final Matrix44f fpsMatrix = new Matrix44f();
fpsMatrix.multiply(translationMatrix, srMatrix);
// disable depth so the fps counter is drawn on top
gl.glDisable(GL.GL_DEPTH_TEST);
gl.glDepthMask(false);
// draw the fps counter
int[] fpsDigits = Long.toString(fps).chars().map(c -> c -= '0').toArray();
if (fpsDigits.length < 2) {
fpsDigits = new int[] { 0, fpsDigits[0] };
}
fpsBatcher.setPixelDensity(pixelDensity);
fpsBatcher.setProjectionScale(pyScale);
fpsBatcher.updateColors(ConstellationColor.YELLOW).run(gl);
fpsBatcher.updateIcons(fpsDigits).run(gl);
fpsBatcher.drawBatch(gl, CAMERA, fpsMatrix, pMatrix, false);
// re-enable depth
gl.glEnable(GL.GL_DEPTH_TEST);
gl.glDepthMask(true);
}
}
use of au.gov.asd.tac.constellation.utilities.graphics.Matrix44f in project constellation by constellation-app.
the class GLVisualProcessor method getDisplayModelViewProjectionMatrix.
/**
* Retrieve the model view projection matrix currently being used for
* visualisation. The projection matrix component is retrieved from the
* {@link GLRenderer}.
*
* @return The MVP matrix this visual processor is using in its current
* display cycle.
*/
public final Matrix44f getDisplayModelViewProjectionMatrix() {
final Matrix44f mvpMatrix = new Matrix44f();
mvpMatrix.multiply(renderer.getProjectionMatrix(), modelViewMatrix);
return mvpMatrix;
}
use of au.gov.asd.tac.constellation.utilities.graphics.Matrix44f in project constellation by constellation-app.
the class AnaglyphCamera method applyLeftFrustum.
public Matrix44f applyLeftFrustum(final Matrix44f mv) {
final float sep = eyeSeparation / 2F;
final float top = nearClippingDistance * (float) Math.tan(fovRadians / 2F);
final float bottom = -top;
final float a = aspectRatio * (float) Math.tan(fovRadians / 2F) * convergence;
final float b = a - sep;
final float c = a + sep;
final float left = -c * nearClippingDistance / convergence;
final float right = b * nearClippingDistance / convergence;
// Set the projection.
//
frustum = new Frustum(fov, aspectRatio, left, right, bottom, top, nearClippingDistance, farClippingDistance);
// Displace the world to the left.
translation = new Matrix44f();
translation.makeTranslationMatrix(-sep, 0, 0);
Matrix44f t2 = new Matrix44f();
t2.multiply(mv, translation);
return t2;
}
use of au.gov.asd.tac.constellation.utilities.graphics.Matrix44f in project constellation by constellation-app.
the class AnaglyphCamera method getMvpMatrix.
/**
* Returns the model-view-projection matrix for current eye.
*
* @param mv the transformation matrix of the camera.
* @return the model-view-projection matrix for current eye.
*/
public Matrix44f getMvpMatrix(final Matrix44f mv) {
Matrix44f t2 = new Matrix44f();
t2.multiply(translation, mv);
Matrix44f mvp = new Matrix44f();
mvp.multiply(frustum.getProjectionMatrix(), t2);
return mvp;
}
use of au.gov.asd.tac.constellation.utilities.graphics.Matrix44f in project constellation by constellation-app.
the class Graphics3DUtilities method moveByProjection.
/**
* Move a position in window coordinates by projecting the movement vector
* from window coordinates to world coordinates.
*
* @param position
* @param modelViewProjectionMatrix
* @param viewport
* @param movement
* @param newposition
*/
public static void moveByProjection(final Vector3f position, final Matrix44f modelViewProjectionMatrix, final int[] viewport, final Vector3f movement, final Vector3f newposition) {
final float[] cameraMovement = new float[3];
final float w = modelViewProjectionMatrix.multiply(position.getX(), position.getY(), position.getZ(), 1)[3];
cameraMovement[0] = movement.getX() * 2.0F * w / viewport[2];
cameraMovement[1] = -movement.getY() * 2.0F * w / viewport[3];
cameraMovement[2] = movement.getZ() * 2.0F * w;
final Matrix44f invmat = new Matrix44f();
invmat.invert(modelViewProjectionMatrix);
final float[] worldMovement = invmat.multiply(cameraMovement[0], cameraMovement[1], cameraMovement[2], 0);
newposition.set(worldMovement[0], worldMovement[1], worldMovement[2]);
LOGGER.log(Level.FINE, "movement: {0}", movement);
LOGGER.log(Level.FINE, "viewport: {0},{1},{2},{3}", new Object[] { viewport[0], viewport[1], viewport[2], viewport[3] });
LOGGER.log(Level.FINE, "mvp: {0}", modelViewProjectionMatrix);
LOGGER.log(Level.FINE, "w: {0}", w);
LOGGER.log(Level.FINE, "cameraMovement: {0},{1},{2}", new Object[] { cameraMovement[0], cameraMovement[1], cameraMovement[2] });
LOGGER.log(Level.FINE, "invmat: {0}", invmat);
LOGGER.log(Level.FINE, "worldMovement: {0},{1},{2}", new Object[] { worldMovement[0], worldMovement[1], worldMovement[2] });
}
Aggregations