use of au.gov.asd.tac.constellation.utilities.graphics.Matrix44f in project constellation by constellation-app.
the class Graphics3DUtilities method project.
/**
* Project a position to the viewing plane.
* <p>
* See 2.13 Coordinate Transformations in "OpenGL 3.3 (Core Profile)".
*
* @param position the position of the eye.
* @param modelViewProjectionMatrix the model view projection matrix.
* @param viewport the viewport.
* @param projectedPosition the projection position.
* @return true if the projection was successful.
*/
public static boolean project(final Vector3f position, final Matrix44f modelViewProjectionMatrix, final int[] viewport, final Vector4f projectedPosition) {
final Matrix44f mvpmat = new Matrix44f();
mvpmat.set(modelViewProjectionMatrix);
final float[] tr = mvpmat.multiply(position.getX(), position.getY(), position.getZ(), 1.0F);
if (tr[3] == 0) {
return false;
}
final float w = tr[3];
tr[0] /= w;
tr[1] /= w;
tr[2] /= w;
// At this point, the projected coordinates (tr) are normalised to the unit cube.
float winx = viewport[0] + (viewport[2] * (tr[0] + 1.0F)) / 2.0F;
float winy = viewport[1] + (viewport[3] * (tr[1] + 1.0F)) / 2.0F;
float winz = (tr[2] + 1.0F) / 2.0F;
// Now we're projected to the window.
projectedPosition.set(winx, winy, winz, w);
return true;
}
use of au.gov.asd.tac.constellation.utilities.graphics.Matrix44f in project constellation by constellation-app.
the class AxesRenderable method display.
@Override
public void display(final GLAutoDrawable drawable, final Matrix44f projectionMatrix) {
final GL3 gl = drawable.getGL().getGL3();
// Extract the rotation matrix from the mvp matrix.
final Matrix44f rotationMatrix = new Matrix44f();
parent.getDisplayModelViewProjectionMatrix().getRotationMatrix(rotationMatrix);
// Scale down to size.
final Matrix44f scalingMatrix = new Matrix44f();
scalingMatrix.makeScalingMatrix(pScale, pScale, 0);
final Matrix44f srMatrix = new Matrix44f();
srMatrix.multiply(scalingMatrix, rotationMatrix);
// Translate to the top right corner.
final Matrix44f translationMatrix = new Matrix44f();
translationMatrix.makeTranslationMatrix(topRightCorner.getX(), topRightCorner.getY(), topRightCorner.getZ());
final Matrix44f axesMatrix = new Matrix44f();
axesMatrix.multiply(translationMatrix, srMatrix);
// Disable depth so the axes are drawn over everything else.
gl.glDisable(GL.GL_DEPTH_TEST);
gl.glDepthMask(false);
// Draw.
gl.glLineWidth(1);
gl.glUseProgram(axesShader);
gl.glUniformMatrix4fv(axesShaderLocMVP, 1, false, axesMatrix.a, 0);
axesBatch.draw(gl);
// Reenable 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 getCameraModelViewProjectionMatrix.
/**
* Get the model view projection matrix corresponding to the supplied
* camera. The projection matrix component is retrieved from the
* {@link GLRenderer}.
*
* @param camera The {@link Camera} from which to calculate the model view
* component of the matrix.
* @return The MVP matrix corresponding to the supplied camera and the
* current projection of the {@link GLRenderer}.
*/
protected Matrix44f getCameraModelViewProjectionMatrix(final Camera camera) {
final Matrix44f mvMatrix = Graphics3DUtilities.getModelViewMatrix(camera);
final Matrix44f mvpMatrix = new Matrix44f();
mvpMatrix.multiply(renderer.getProjectionMatrix(), mvMatrix);
return mvpMatrix;
}
use of au.gov.asd.tac.constellation.utilities.graphics.Matrix44f in project constellation by constellation-app.
the class VisualGraphUtilities method streamVertexSceneLocations.
public static Stream<Vector3f> streamVertexSceneLocations(GraphReadMethods rg, final Camera camera) {
// Get a copy of the current rotation matrix.
final Matrix44f modelViewMatrix = Graphics3DUtilities.getModelViewMatrix(camera);
final Matrix33f rotationMatrix = new Matrix33f();
modelViewMatrix.getRotationMatrix(rotationMatrix);
// Convert from world to scene coordinates
Stream<Vector3f> worldLocations = streamVertexWorldLocations(rg, camera);
return worldLocations.map(worldLocation -> {
final float[] screenLocation = modelViewMatrix.multiply(worldLocation.getX(), worldLocation.getY(), worldLocation.getZ(), 1);
return new Vector3f(screenLocation[0], screenLocation[1], screenLocation[2]);
});
}
use of au.gov.asd.tac.constellation.utilities.graphics.Matrix44f in project constellation by constellation-app.
the class Graphics3DUtilitiesNGTest method testUnsuccessfulMoveByProjectionUnprojection.
/**
* Can move a position in window coordinates.
*/
@Test
public void testUnsuccessfulMoveByProjectionUnprojection() {
final Matrix44f zeroMatrix = new Matrix44f();
for (int i = 0; i < 4; i++) {
zeroMatrix.setRow(0, 0, 0, 0, i);
}
final Vector3f newPosition = new Vector3f(V3_3);
assertFalse(Graphics3DUtilities.moveByProjection(new Vector3f(ZERO_V), zeroMatrix, new int[] { 0, 0, 0, 0 }, 0, 0, newPosition));
assertEquals(newPosition.toString(), V3_3.toString());
}
Aggregations