use of au.gov.asd.tac.constellation.utilities.graphics.Matrix44f in project constellation by constellation-app.
the class Graphics3DUtilities method unproject.
public static boolean unproject(final Vector4f position, final Matrix44f modelViewProjectionMatrix, final int[] viewport, final Vector3f unprojectedPosition) {
final float winx = position.a[0];
final float winy = position.a[1];
final float winz = position.a[2];
final float w = position.a[3];
// Start unprojecting the window coordinates.
final float[] tr = new float[4];
tr[0] = (winx - viewport[0]) * 2.0F / viewport[2] - 1.0F;
tr[1] = (winy - viewport[1]) * 2.0F / viewport[3] - 1.0F;
tr[2] = winz * 2.0F - 1.0F;
tr[3] = w;
tr[0] *= w;
tr[1] *= w;
tr[2] *= w;
Matrix44f invmat = new Matrix44f();
invmat.invert(modelViewProjectionMatrix);
final float[] untr = invmat.multiply(tr[0], tr[1], tr[2], tr[3]);
// And we're done.
unprojectedPosition.set(untr[0], untr[1], untr[2]);
return true;
}
use of au.gov.asd.tac.constellation.utilities.graphics.Matrix44f in project constellation by constellation-app.
the class Graphics3DUtilitiesNGTest method testGetModelViewMatrix.
/**
* Can get a model view matrix.
*/
@Test
public void testGetModelViewMatrix() {
final Matrix44f expected = new Matrix44f();
expected.setRow(0.010413259F, -0.01803626F, -0.5773502F, 0.0F, 0);
expected.setRow(-0.020826489F, -1.7695129E-8F, -0.57735026F, 0.0F, 1);
expected.setRow(0.010413229F, 0.018036276F, -0.57735026F, 0.0F, 2);
expected.setRow(5.5879354E-9F, -0.0036072508F, 2.078461F, 1.0F, 3);
// using the main method
final Matrix44f m = copyMatrix(M1);
Graphics3DUtilities.getModelViewMatrix(new Vector3f(V3_1), new Vector3f(V3_2), new Vector3f(V3_3), m);
assertEquals(m.toString(), expected.toString());
// using the convenience method passing in a Camera object
final Camera c = new Camera();
c.lookAtEye.set(V3_1);
c.lookAtCentre.set(V3_2);
c.lookAtUp.set(V3_3);
final Matrix44f m2 = Graphics3DUtilities.getModelViewMatrix(c);
assertEquals(m2.toString(), expected.toString());
}
use of au.gov.asd.tac.constellation.utilities.graphics.Matrix44f in project constellation by constellation-app.
the class AnaglyphCameraNGTest method testGetProjectionMatrix.
/**
* Can get the projection matrix from the frustum.
*/
@Test
public void testGetProjectionMatrix() {
final Matrix44f expected = new Matrix44f();
expected.setRow(-0.0014013189F, 0F, 0F, 0F, 0);
expected.setRow(0F, -1.1938678F, 0F, 0F, 1);
expected.setRow(4.1351226E-4F, 0F, -1.5762731F, -1.0F, 2);
expected.setRow(0F, 0F, 271.87408F, 0F, 3);
final AnaglyphCamera sc = new AnaglyphCamera(F6, F5, F4, F3, F2, F1);
sc.applyRightFrustum(copyMatrix(M1));
assertEquals(sc.getProjectionMatrix().toString(), expected.toString());
}
use of au.gov.asd.tac.constellation.utilities.graphics.Matrix44f in project constellation by constellation-app.
the class AnaglyphCameraNGTest method testGetMvPMatrix.
/**
* Can get the model-view-projection matrix for the current eye.
*/
@Test
public void testGetMvPMatrix() {
final Matrix44f expected = new Matrix44f();
expected.setRow(-13.829945F, -6.3021326F, -177848.28F, -174.24F, 0);
expected.setRow(-6.988373F, -4.198501F, -89450.28F, 26.2F, 1);
expected.setRow(-4.6575613F, 5.7916403F, -58868.332F, 764.66F, 2);
expected.setRow(15.206118F, -5.946508F, 193637.56F, -311.68F, 3);
final AnaglyphCamera sc = new AnaglyphCamera(F3, F6, F2, F5, F1, F4);
sc.applyRightFrustum(copyMatrix(M1));
assertEquals(sc.getMvpMatrix(copyMatrix(M2)).toString(), expected.toString());
}
use of au.gov.asd.tac.constellation.utilities.graphics.Matrix44f in project constellation by constellation-app.
the class SelectionBoxRenderable method display.
@Override
public void display(final GLAutoDrawable drawable, final Matrix44f pMatrix) {
if (selectionBoxModel != null && selectionBoxModel.isClear()) {
final Point begin = selectionBoxModel.getStartPoint();
final Point end = selectionBoxModel.getEndPoint();
final GL3 gl = drawable.getGL().getGL3();
// Map the vertex buffer.
gl.glBindBuffer(GL.GL_ARRAY_BUFFER, batch.getBufferName(vertexTarget));
final ByteBuffer bbuf = gl.glMapBuffer(GL.GL_ARRAY_BUFFER, GL.GL_WRITE_ONLY);
final FloatBuffer fbuf = bbuf.asFloatBuffer();
// We should have the same buffer size we started with.
assert fbuf.limit() == NUMBER_OF_VERTICES * 3;
// Find the location of the box in projected coordinates
float left = ((float) begin.x / width) * 2 - 1F;
float right = ((float) end.x / width) * 2 - 1F;
float top = ((float) (height - begin.y) / height) * 2 - 1F;
float bottom = ((float) (height - end.y) / height) * 2 - 1F;
// Update the four TRIANGLE_FAN coordinates in the vertex buffer.
float[] v = new float[] { right, bottom, 0F, left, bottom, 0F, left, top, 0F, right, top, 0F };
fbuf.put(v);
gl.glUnmapBuffer(GL.GL_ARRAY_BUFFER);
// Disable depth so the rectangle is drawn over everything else.
gl.glDisable(GL.GL_DEPTH_TEST);
gl.glDepthMask(false);
Matrix44f mvpMatrix = new Matrix44f();
mvpMatrix.makeIdentity();
// Draw.
gl.glUseProgram(shader);
gl.glUniformMatrix4fv(shaderMvp, 1, false, mvpMatrix.a, 0);
batch.draw(gl);
// Reenable depth.
gl.glEnable(GL.GL_DEPTH_TEST);
gl.glDepthMask(true);
}
}
Aggregations