use of au.gov.asd.tac.constellation.utilities.graphics.Matrix44f in project constellation by constellation-app.
the class SelectionFreeformRenderable method display.
@Override
public void display(final GLAutoDrawable drawable, final Matrix44f pMatrix) {
if (selectionFreeformModel != null && selectionFreeformModel.isClear()) {
final Point begin = selectionFreeformModel.getStartPoint();
final Point end = selectionFreeformModel.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 Freeform in projected coordinates and update the TRIANGLE_FAN coordinates in the vertex buffer.
final float[] v = new float[150];
for (int i = 0; i < 50; i++) {
v[i * 3] = ((float) selectionFreeformModel.getPoint(i).getX() / width) * 2 - 1F;
v[i * 3 + 1] = ((float) (height - selectionFreeformModel.getPoint(i).getY()) / height) * 2 - 1F;
v[i * 3 + 2] = 0.0F;
}
fbuf.put(v);
gl.glUnmapBuffer(GL.GL_ARRAY_BUFFER);
// Disable depth so the freeform shape is drawn over everything else.
gl.glDisable(GL.GL_DEPTH_TEST);
gl.glDepthMask(false);
final 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);
}
}
use of au.gov.asd.tac.constellation.utilities.graphics.Matrix44f in project constellation by constellation-app.
the class AnaglyphCamera method applyRightFrustum.
public Matrix44f applyRightFrustum(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 = -b * nearClippingDistance / convergence;
final float right = c * nearClippingDistance / convergence;
// Set the projection.
//
frustum = new Frustum(fov, aspectRatio, left, right, bottom, top, nearClippingDistance, farClippingDistance);
// Displace the world to the right.
//
translation = new Matrix44f();
translation.makeTranslationMatrix(sep, 0, 0);
Matrix44f t2 = new Matrix44f();
t2.multiply(translation, mv);
return t2;
}
use of au.gov.asd.tac.constellation.utilities.graphics.Matrix44f in project constellation by constellation-app.
the class Graphics3DUtilities method getModelViewMatrix.
public static Matrix44f getModelViewMatrix(final Camera camera) {
Matrix44f mat = new Matrix44f();
getModelViewMatrix(camera.lookAtEye, camera.lookAtCentre, camera.lookAtUp, mat);
return mat;
}
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, moving, then
* unprojecting.
*
* @param position The position to move.
* @param modelViewProjectionMatrix The model-view-projection matrix for
* projecting/unprojecting.
* @param viewport The current window viewport.
* @param deltaX The window Δx.
* @param deltaY The window Δy.
* @param newposition The returned new position.
*
* @return True if the calculation could be made, false otherwise (eg w==0).
*/
public static boolean moveByProjection(final Vector3f position, final Matrix44f modelViewProjectionMatrix, final int[] viewport, final int deltaX, final int deltaY, final Vector3f newposition) {
// To avoid playing with large numbers, we move the fixed position (0,0,0),
// then add the original position at the end.
final float[] tr = modelViewProjectionMatrix.multiply(0F, 0F, 0F, 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.
// Add the delta from the before and after mouse movement.
// Note that the ydelta is substracted: OpenGL and Windows have opposite y axes.
winx += deltaX;
winy -= deltaY;
// Start unprojecting the window coordinates.
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[0] *= w;
tr[1] *= w;
tr[2] *= w;
final Matrix44f invmat = new Matrix44f();
invmat.invert(modelViewProjectionMatrix);
final float[] untr = invmat.multiply(tr[0], tr[1], tr[2], tr[3]);
untr[0] += position.getX();
untr[1] += position.getY();
untr[2] += position.getZ();
// And we're done.
newposition.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 Graphics3DUtilities method getModelViewMatrix.
public static void getModelViewMatrix(final Vector3f eye, final Vector3f center, final Vector3f up, final Matrix44f result) {
final Vector3f f = Vector3f.subtract(center, eye);
f.normalize();
final Vector3f up2 = new Vector3f(up);
up2.normalize();
final Vector3f s = new Vector3f();
s.crossProduct(f, up2);
final Vector3f u = new Vector3f();
u.crossProduct(s, f);
final Matrix44f modelView = new Matrix44f();
modelView.set(0, 0, s.getX());
modelView.set(1, 0, s.getY());
modelView.set(2, 0, s.getZ());
modelView.set(3, 0, 0);
modelView.set(0, 1, u.getX());
modelView.set(1, 1, u.getY());
modelView.set(2, 1, u.getZ());
modelView.set(3, 1, 0);
modelView.set(0, 2, -f.getX());
modelView.set(1, 2, -f.getY());
modelView.set(2, 2, -f.getZ());
modelView.set(3, 2, 0);
modelView.set(0, 3, 0);
modelView.set(1, 3, 0);
modelView.set(2, 3, 0);
modelView.set(3, 3, 1);
final Matrix44f scaleMatrix = new Matrix44f();
scaleMatrix.makeTranslationMatrix(-eye.getX(), -eye.getY(), -eye.getZ());
result.multiply(modelView, scaleMatrix);
}
Aggregations