Search in sources :

Example 11 with Matrix44f

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);
    }
}
Also used : Vector4f(au.gov.asd.tac.constellation.utilities.graphics.Vector4f) FpsBatcher(au.gov.asd.tac.constellation.visual.opengl.renderer.batcher.FpsBatcher) GL3(com.jogamp.opengl.GL3) Graphics3DUtilities(au.gov.asd.tac.constellation.utilities.camera.Graphics3DUtilities) GLAutoDrawable(com.jogamp.opengl.GLAutoDrawable) ConstellationColor(au.gov.asd.tac.constellation.utilities.color.ConstellationColor) Vector3f(au.gov.asd.tac.constellation.utilities.graphics.Vector3f) InfoTextPanel(au.gov.asd.tac.constellation.utilities.gui.InfoTextPanel) IOException(java.io.IOException) DialogDisplayer(org.openide.DialogDisplayer) Logger(java.util.logging.Logger) Level(java.util.logging.Level) Preferences(java.util.prefs.Preferences) NotifyDescriptor(org.openide.NotifyDescriptor) DeveloperPreferenceKeys(au.gov.asd.tac.constellation.preferences.DeveloperPreferenceKeys) Camera(au.gov.asd.tac.constellation.utilities.camera.Camera) Matrix44f(au.gov.asd.tac.constellation.utilities.graphics.Matrix44f) RenderException(au.gov.asd.tac.constellation.visual.opengl.utilities.RenderException) GL(com.jogamp.opengl.GL) NbPreferences(org.openide.util.NbPreferences) Matrix44f(au.gov.asd.tac.constellation.utilities.graphics.Matrix44f) GL3(com.jogamp.opengl.GL3)

Example 12 with Matrix44f

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

Example 13 with Matrix44f

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

Example 14 with Matrix44f

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

Example 15 with Matrix44f

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

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