Search in sources :

Example 6 with Camera

use of au.gov.asd.tac.constellation.utilities.camera.Camera in project constellation by constellation-app.

the class DefaultInteractionEventHandler method mousePressed.

@Override
public void mousePressed(final MouseEvent event) {
    queue.add(wg -> {
        // If the mouse is currently pressed (meaning this event represents pressing multiple buttons) we ignore this event.
        if (!eventState.isMousePressed()) {
            // HACK_DPI - Multiply point by DPI scale factor
            Point point = event.getPoint();
            scaleMousePointByDPIFactor(point);
            // In case we are panning, we must take the distance of the scene from the camera into account,
            // otherwise scenes that are further away will appear to move very slowly.
            eventState.storePoint(point, EventState.PRESSED_POINT, EventState.REFERENCE_POINT);
            eventState.setCurrentButton(event.getButton());
            final Camera camera;
            if (wg != null) {
                camera = VisualGraphUtilities.getCamera(wg);
                // Order a hit test and wait for it to complete.
                orderHitTest(point, HitTestMode.HANDLE_SYNCHRONOUSLY);
                // Now that we have got the results of hit testing we can turn it off until the mouse is released.
                setHitTestingEnabled(false);
                eventState.setClosestNode(visualInteraction.closestNodeCameraCoordinates(wg, camera, point));
            } else {
                camera = null;
            }
            if (SwingUtilities.isMiddleMouseButton(event)) {
                eventState.setCurrentAction(SceneAction.ROTATING);
            } else if ((eventState.getCurrentHitType().equals(HitType.NO_ELEMENT) && SwingUtilities.isRightMouseButton(event)) || (SwingUtilities.isRightMouseButton(event) && event.isControlDown())) {
                eventState.setCurrentAction(SceneAction.PANNING);
            } else if (SwingUtilities.isRightMouseButton(event) && !eventState.getCurrentHitType().equals(HitType.NO_ELEMENT)) {
                eventState.setCurrentAction(SceneAction.DRAG_NODES);
            } else if (SwingUtilities.isLeftMouseButton(event)) {
                if ((wg == null || !VisualGraphUtilities.isDrawingMode(wg)) && event.isAltDown()) {
                    eventState.setCurrentAction(SceneAction.FREEFORM_SELECTING);
                } else if (wg == null || !VisualGraphUtilities.isDrawingMode(wg)) {
                    eventState.setCurrentAction(SceneAction.SELECTING);
                } else {
                    eventState.setCurrentAction(SceneAction.CREATING);
                    // Check if we are on a vertex
                    if (eventState.getCurrentHitType().equals(HitType.VERTEX)) {
                        beginCreateTransaction();
                        scheduleNewLineChangeOperation(wg, null, camera, false);
                    } else {
                        beginCreateVertex();
                        clearNewLineModel(camera);
                    }
                }
            } else {
            // Do nothing
            }
        }
        return 0;
    });
}
Also used : Point(java.awt.Point) Camera(au.gov.asd.tac.constellation.utilities.camera.Camera)

Example 7 with Camera

use of au.gov.asd.tac.constellation.utilities.camera.Camera in project constellation by constellation-app.

the class InteractiveGLVisualProcessor method windowToGraphCoordinates.

@Override
public Vector3f windowToGraphCoordinates(final Camera camera, final Point point) {
    final Camera originCamera = new Camera(camera);
    CameraUtilities.moveEyeToOrigin(originCamera);
    Matrix44f modelViewProjectionMatrix = getCameraModelViewProjectionMatrix(originCamera);
    Vector3f worldPosition = new Vector3f();
    final Vector3f direction = CameraUtilities.getFocusVector(originCamera);
    direction.scale(10);
    Graphics3DUtilities.screenToWorldCoordinates(new Vector3f(point.x, point.y, 0), direction, modelViewProjectionMatrix, getViewport(), worldPosition);
    worldPosition.add(camera.lookAtEye);
    return worldPosition;
}
Also used : Matrix44f(au.gov.asd.tac.constellation.utilities.graphics.Matrix44f) Vector3f(au.gov.asd.tac.constellation.utilities.graphics.Vector3f) Camera(au.gov.asd.tac.constellation.utilities.camera.Camera)

Example 8 with Camera

use of au.gov.asd.tac.constellation.utilities.camera.Camera in project constellation by constellation-app.

the class ResetViewPlugin method edit.

@Override
public void edit(final GraphWriteMethods graph, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
    // Get a copy of the graph's curent camera
    final int cameraAttribute = VisualConcept.GraphAttribute.CAMERA.get(graph);
    if (cameraAttribute != Graph.NOT_FOUND) {
        final Camera oldCamera = graph.getObjectValue(cameraAttribute, 0);
        final Camera camera = new Camera(oldCamera);
        final BoundingBox boundingBox = new BoundingBox();
        BoundingBoxUtilities.recalculateFromGraph(boundingBox, graph, false);
        // Refocus the copied camera appropriately.
        final String axis = parameters.getStringValue(AXIS_PARAMETER_ID);
        final boolean negative = parameters.getBooleanValue(NEGATIVE_PARAMETER_ID);
        switch(axis.toLowerCase()) {
            case "x":
                CameraUtilities.refocusOnXAxis(camera, boundingBox, negative);
                break;
            case "y":
                CameraUtilities.refocusOnYAxis(camera, boundingBox, negative);
                break;
            case "z":
            default:
                CameraUtilities.refocusOnZAxis(camera, boundingBox, negative);
                break;
        }
        // add an animation to the refocused camera so that it pans from the old position.
        Animation.startAnimation(new PanAnimation("Reset View", oldCamera, camera, parameters.getBooleanValue(SIGNIFICANT_PARAMETER_ID)));
    }
}
Also used : PanAnimation(au.gov.asd.tac.constellation.graph.interaction.animation.PanAnimation) BoundingBox(au.gov.asd.tac.constellation.utilities.camera.BoundingBox) Camera(au.gov.asd.tac.constellation.utilities.camera.Camera)

Example 9 with Camera

use of au.gov.asd.tac.constellation.utilities.camera.Camera in project constellation by constellation-app.

the class RotateCameraPlugin method edit.

@Override
public void edit(final GraphWriteMethods graph, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
    final float xrot = parameters.getFloatValue(X_PARAMETER_ID);
    final float yrot = parameters.getFloatValue(Y_PARAMETER_ID);
    final float zrot = parameters.getFloatValue(Z_PARAMETER_ID);
    final boolean animate = parameters.getBooleanValue(ANIMATE_PARAMETER_ID);
    // Get a copy of the graph's current camera.
    final int cameraAttribute = VisualConcept.GraphAttribute.CAMERA.get(graph);
    if (cameraAttribute != Graph.NOT_FOUND) {
        final Camera oldCamera = graph.getObjectValue(cameraAttribute, 0);
        final Camera camera = new Camera(oldCamera);
        CameraUtilities.rotate(camera, xrot, yrot, zrot);
        if (animate) {
            Animation.startAnimation(new PanAnimation("Rotate camera", oldCamera, camera, true));
        } else {
            // Don't do an animation; we don't want to be asynchronous.
            // Just set the camera value back on the graph.
            graph.setObjectValue(cameraAttribute, 0, camera);
        }
    }
}
Also used : PanAnimation(au.gov.asd.tac.constellation.graph.interaction.animation.PanAnimation) Camera(au.gov.asd.tac.constellation.utilities.camera.Camera)

Example 10 with Camera

use of au.gov.asd.tac.constellation.utilities.camera.Camera 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)

Aggregations

Camera (au.gov.asd.tac.constellation.utilities.camera.Camera)32 Vector3f (au.gov.asd.tac.constellation.utilities.graphics.Vector3f)11 Test (org.testng.annotations.Test)8 Point (java.awt.Point)5 PanAnimation (au.gov.asd.tac.constellation.graph.interaction.animation.PanAnimation)4 Frame (au.gov.asd.tac.constellation.utilities.graphics.Frame)4 Matrix44f (au.gov.asd.tac.constellation.utilities.graphics.Matrix44f)4 BoundingBox (au.gov.asd.tac.constellation.utilities.camera.BoundingBox)3 WritableGraph (au.gov.asd.tac.constellation.graph.WritableGraph)2 Matrix33f (au.gov.asd.tac.constellation.utilities.graphics.Matrix33f)2 BitSet (java.util.BitSet)2 StoreGraph (au.gov.asd.tac.constellation.graph.StoreGraph)1 SelectionBoxModel (au.gov.asd.tac.constellation.graph.interaction.visual.renderables.SelectionBoxModel)1 DualGraph (au.gov.asd.tac.constellation.graph.locking.DualGraph)1 Blaze (au.gov.asd.tac.constellation.graph.schema.visual.attribute.objects.Blaze)1 DeveloperPreferenceKeys (au.gov.asd.tac.constellation.preferences.DeveloperPreferenceKeys)1 Graphics3DUtilities (au.gov.asd.tac.constellation.utilities.camera.Graphics3DUtilities)1 ConstellationColor (au.gov.asd.tac.constellation.utilities.color.ConstellationColor)1 Vector4f (au.gov.asd.tac.constellation.utilities.graphics.Vector4f)1 InfoTextPanel (au.gov.asd.tac.constellation.utilities.gui.InfoTextPanel)1