Search in sources :

Example 26 with Matrix44f

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;
}
Also used : Matrix44f(au.gov.asd.tac.constellation.utilities.graphics.Matrix44f)

Example 27 with Matrix44f

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);
}
Also used : Matrix44f(au.gov.asd.tac.constellation.utilities.graphics.Matrix44f) GL3(com.jogamp.opengl.GL3)

Example 28 with Matrix44f

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;
}
Also used : Matrix44f(au.gov.asd.tac.constellation.utilities.graphics.Matrix44f)

Example 29 with Matrix44f

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]);
    });
}
Also used : Matrix44f(au.gov.asd.tac.constellation.utilities.graphics.Matrix44f) Matrix33f(au.gov.asd.tac.constellation.utilities.graphics.Matrix33f) Vector3f(au.gov.asd.tac.constellation.utilities.graphics.Vector3f)

Example 30 with Matrix44f

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());
}
Also used : Matrix44f(au.gov.asd.tac.constellation.utilities.graphics.Matrix44f) Vector3f(au.gov.asd.tac.constellation.utilities.graphics.Vector3f) Test(org.testng.annotations.Test)

Aggregations

Matrix44f (au.gov.asd.tac.constellation.utilities.graphics.Matrix44f)34 Vector3f (au.gov.asd.tac.constellation.utilities.graphics.Vector3f)15 Matrix33f (au.gov.asd.tac.constellation.utilities.graphics.Matrix33f)6 GL3 (com.jogamp.opengl.GL3)6 Test (org.testng.annotations.Test)6 Frame (au.gov.asd.tac.constellation.utilities.graphics.Frame)5 Camera (au.gov.asd.tac.constellation.utilities.camera.Camera)4 BitSet (java.util.BitSet)4 Vector4f (au.gov.asd.tac.constellation.utilities.graphics.Vector4f)3 ByteBuffer (java.nio.ByteBuffer)3 FloatBuffer (java.nio.FloatBuffer)3 SetBooleanValuesOperation (au.gov.asd.tac.constellation.graph.operations.SetBooleanValuesOperation)2 Frustum (au.gov.asd.tac.constellation.utilities.graphics.Frustum)2 Point (java.awt.Point)2 DeveloperPreferenceKeys (au.gov.asd.tac.constellation.preferences.DeveloperPreferenceKeys)1 AnaglyphCamera (au.gov.asd.tac.constellation.utilities.camera.AnaglyphCamera)1 Graphics3DUtilities (au.gov.asd.tac.constellation.utilities.camera.Graphics3DUtilities)1 ConstellationColor (au.gov.asd.tac.constellation.utilities.color.ConstellationColor)1 InfoTextPanel (au.gov.asd.tac.constellation.utilities.gui.InfoTextPanel)1 FpsBatcher (au.gov.asd.tac.constellation.visual.opengl.renderer.batcher.FpsBatcher)1