Search in sources :

Example 1 with Camera

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

the class GatherNodesInGraphPlugin method edit.

@Override
public void edit(final GraphWriteMethods wg, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException {
    final Vector3f xyzp = (Vector3f) parameters.getParameters().get(XYZ_PARAMETER_ID).getObjectValue();
    final BitSet gathers = (BitSet) parameters.getParameters().get(GATHERS_PARAMETER_ID).getObjectValue();
    final int xId = wg.getAttribute(GraphElementType.VERTEX, VisualConcept.VertexAttribute.X.getName());
    final int yId = wg.getAttribute(GraphElementType.VERTEX, VisualConcept.VertexAttribute.Y.getName());
    final int zId = wg.getAttribute(GraphElementType.VERTEX, VisualConcept.VertexAttribute.Z.getName());
    final int cameraAttribute = VisualConcept.GraphAttribute.CAMERA.get(wg);
    final int selectedVertexCount = gathers.cardinality();
    if (selectedVertexCount >= 1) {
        // This is where we want to rotate to: relative to the eye->centre direction.
        final Camera visualState = wg.getObjectValue(cameraAttribute, 0);
        final Vector3f xyz = Vector3f.subtract(visualState.lookAtCentre, visualState.lookAtEye);
        // Create a rotation matrix that will rotate the positions we're about to create.
        final Frame frame = new Frame(xyz, new Vector3f(0, 0, 0), visualState.lookAtUp);
        final Matrix44f rm = new Matrix44f();
        frame.getMatrix(rm, true);
        final Matrix33f rotationMatrix = new Matrix33f();
        rm.getRotationMatrix(rotationMatrix);
        // We want the grid to start at the top left and grow down and right.
        // Choose our up and left vectors accordingly.
        final Vector3f up = new Vector3f();
        up.rotate(new Vector3f(0, -1, 0), rotationMatrix);
        final Vector3f left = new Vector3f();
        left.rotate(new Vector3f(-1, 0, 0), rotationMatrix);
        // If we wanted to be consistent, we'd call the arrange by grid plugin on the selected vertices
        // and rotate the result...
        final int rowLength = (int) Math.ceil(Math.sqrt(selectedVertexCount));
        float x = xyzp.getX();
        float y = xyzp.getY();
        float z = xyzp.getZ();
        int h = 0;
        int v = 0;
        float scalingFactor = 4;
        for (int vxId = gathers.nextSetBit(0); vxId >= 0; vxId = gathers.nextSetBit(vxId + 1)) {
            if (h == 0 && v == 0) {
                // This gathers the selected nodes at the distance the first selected node as measured away from the camera/eye.
                // It does this by using a right hand triangle (hypotenuse = ray to click, adjacent = view from eye to centre,
                // opposite = pane perpendicular to eye) and the approriate triangle properties
                // 
                // Unit vector from eye to click point
                final Vector3f ray = Vector3f.subtract(xyzp, visualState.lookAtEye);
                ray.normalize();
                // Unit vector from eye to centre
                final Vector3f adjacentUnit = Vector3f.subtract(visualState.lookAtCentre, visualState.lookAtEye);
                adjacentUnit.normalize();
                // Vector from eye to node already on graph
                final Vector3f point = new Vector3f(wg.getFloatValue(xId, vxId), wg.getFloatValue(yId, vxId), wg.getFloatValue(zId, vxId));
                point.subtract(visualState.lookAtEye);
                // Determining the distance along the unit vector to the centre that the node will be
                final float adjacentLen = Vector3f.dotProduct(adjacentUnit, point);
                // Determining the length of the hypotenuse of the right hand triangle
                final float cosAngleBetweenVectors = (float) Math.cos(Vector3f.angleBetweenVectors(ray, adjacentUnit));
                // If it does equal 0 we will skip this section and have x,y,z equal the "click point" which was assigned when they were defined
                if (cosAngleBetweenVectors != 0.0) {
                    final float rayScalar = adjacentLen / cosAngleBetweenVectors;
                    ray.scale(rayScalar);
                    final Vector3f destination = Vector3f.add(visualState.lookAtEye, ray);
                    x = destination.getX();
                    y = destination.getY();
                    z = destination.getZ();
                }
            }
            wg.setFloatValue(xId, vxId, x + scalingFactor * (h * left.getX() + v * up.getX()));
            wg.setFloatValue(yId, vxId, y + scalingFactor * (h * left.getY() + v * up.getY()));
            wg.setFloatValue(zId, vxId, z + scalingFactor * (h * left.getZ() + v * up.getZ()));
            if (++h == rowLength) {
                h = 0;
                v++;
            }
        }
    }
}
Also used : Frame(au.gov.asd.tac.constellation.utilities.graphics.Frame) 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) BitSet(java.util.BitSet) Camera(au.gov.asd.tac.constellation.utilities.camera.Camera)

Example 2 with Camera

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

the class GatherNodesPlugin method edit.

@Override
public void edit(final GraphWriteMethods wg, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException {
    final int vxId = parameters.getParameters().get(VXID_PARAMETER_ID).getIntegerValue();
    final BitSet gathers = (BitSet) parameters.getParameters().get(GATHERS_PARAMETER_ID).getObjectValue();
    gathers.set(vxId);
    final int xId = wg.getAttribute(GraphElementType.VERTEX, VisualConcept.VertexAttribute.X.getName());
    final int yId = wg.getAttribute(GraphElementType.VERTEX, VisualConcept.VertexAttribute.Y.getName());
    final int zId = wg.getAttribute(GraphElementType.VERTEX, VisualConcept.VertexAttribute.Z.getName());
    final int cameraAttribute = VisualConcept.GraphAttribute.CAMERA.get(wg);
    final int selectedVertexCount = gathers.cardinality();
    if (selectedVertexCount > 1) {
        // This is where we want to rotate to: relative to the eye->centre direction.
        final Camera visualState = wg.getObjectValue(cameraAttribute, 0);
        final Vector3f xyz = Vector3f.subtract(visualState.lookAtCentre, visualState.lookAtEye);
        // Create a rotation matrix that will rotate the positions we're about to create.
        final Frame frame = new Frame(xyz, new Vector3f(0, 0, 0), visualState.lookAtUp);
        final Matrix44f rm = new Matrix44f();
        frame.getMatrix(rm, true);
        final Matrix33f rotationMatrix = new Matrix33f();
        rm.getRotationMatrix(rotationMatrix);
        // We want the grid to start at the top left and grow down and right.
        // Choose our up and left vectors accordingly.
        final Vector3f up = new Vector3f();
        up.rotate(new Vector3f(0, -1, 0), rotationMatrix);
        final Vector3f left = new Vector3f();
        left.rotate(new Vector3f(-1, 0, 0), rotationMatrix);
        final float x = wg.getFloatValue(xId, vxId);
        final float y = wg.getFloatValue(yId, vxId);
        final float z = wg.getFloatValue(zId, vxId);
        // If we wanted to be consistent, we'd call the arrange by grid plugin on the selected vertices
        // and rotate the result...
        final int rowLength = (int) Math.ceil(Math.sqrt(selectedVertexCount));
        // Skip the first position: when we get to vxId, we don't change it's position.
        int h = 1;
        int v = 0;
        final float scalingFactor = 4;
        for (int vertex = gathers.nextSetBit(0); vertex >= 0; vertex = gathers.nextSetBit(vertex + 1)) {
            if (vertex != vxId) {
                wg.setFloatValue(xId, vertex, x + scalingFactor * (h * left.getX() + v * up.getX()));
                wg.setFloatValue(yId, vertex, y + scalingFactor * (h * left.getY() + v * up.getY()));
                wg.setFloatValue(zId, vertex, z + scalingFactor * (h * left.getZ() + v * up.getZ()));
                if (++h == rowLength) {
                    h = 0;
                    v++;
                }
            }
        }
    }
}
Also used : Frame(au.gov.asd.tac.constellation.utilities.graphics.Frame) 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) BitSet(java.util.BitSet) Camera(au.gov.asd.tac.constellation.utilities.camera.Camera)

Example 3 with Camera

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

the class PanAnimation method animate.

@Override
public List<VisualChange> animate(GraphWriteMethods wg) {
    if (step <= STEPS) {
        final float t = step / (float) STEPS;
        final float mix = reflect(t);
        camera = new Camera(camera);
        camera.lookAtEye.set(Graphics3DUtilities.mix(from.lookAtEye, to.lookAtEye, mix));
        camera.lookAtCentre.set(Graphics3DUtilities.mix(from.lookAtCentre, to.lookAtCentre, mix));
        camera.lookAtUp.set(Graphics3DUtilities.mix(from.lookAtUp, to.lookAtUp, mix));
        camera.lookAtRotation.set(Graphics3DUtilities.mix(from.lookAtRotation, to.lookAtRotation, mix));
        wg.setObjectValue(cameraAttr, 0, camera);
        step++;
        return Arrays.asList(new VisualChangeBuilder(VisualProperty.CAMERA).forItems(1).withId(panAnimationId).build());
    } else {
        setFinished();
        return Collections.emptyList();
    }
}
Also used : VisualChangeBuilder(au.gov.asd.tac.constellation.utilities.visual.VisualChangeBuilder) Camera(au.gov.asd.tac.constellation.utilities.camera.Camera)

Example 4 with Camera

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

the class DefaultInteractionEventHandler method keyPressed.

/**
 * Respond to a key press event on the graph. This will respond to keys that
 * interact directly with the graph's visuals, such as W,A,S,D to pan. Most
 * key presses in CONSTELLATION, for example Ctrl+A, will be picked up by
 * the netbeans framework and cause plugins to be executed.
 * <p>
 * This is called continually whenever a key is held down (at the key repeat
 * rate of the operating system).
 *
 * @param event The KeyEvent related to the key press.
 */
@Override
public void keyPressed(final KeyEvent event) {
    final int keyCode = event.getKeyCode();
    // Avoid the control key so we don't interfere with ^S for save, for example.
    final boolean isCtrl = event.isControlDown();
    final boolean isShift = event.isShiftDown();
    if (keyCode == KeyEvent.VK_PAGE_UP || keyCode == KeyEvent.VK_PAGE_DOWN || (!isCtrl && (keyCode == KeyEvent.VK_A || keyCode == KeyEvent.VK_D || keyCode == KeyEvent.VK_S || keyCode == KeyEvent.VK_W))) {
        queue.add(wg -> {
            if (wg != null) {
                final Camera camera = new Camera(VisualGraphUtilities.getCamera(wg));
                if (keyCode == KeyEvent.VK_PAGE_UP) {
                    CameraUtilities.changeMixRatio(camera, true, isCtrl);
                    eventState.addEventName(MIX_ACTION_NAME);
                } else if (keyCode == KeyEvent.VK_PAGE_DOWN) {
                    CameraUtilities.changeMixRatio(camera, false, isCtrl);
                    eventState.addEventName(MIX_ACTION_NAME);
                } else if (keyCode == KeyEvent.VK_A) {
                    CameraUtilities.pan(camera, -0.5F * (isShift ? 10 : 1), 0);
                    eventState.addEventName(PAN_ACTION_NAME);
                } else if (keyCode == KeyEvent.VK_D) {
                    CameraUtilities.pan(camera, 0.5F * (isShift ? 10 : 1), 0);
                    eventState.addEventName(PAN_ACTION_NAME);
                } else if (keyCode == KeyEvent.VK_S) {
                    CameraUtilities.pan(camera, 0, -0.5F * (isShift ? 10 : 1));
                    eventState.addEventName(PAN_ACTION_NAME);
                } else if (keyCode == KeyEvent.VK_W) {
                    CameraUtilities.pan(camera, 0, 0.5F * (isShift ? 10 : 1));
                    eventState.addEventName(PAN_ACTION_NAME);
                } else {
                // Do nothing
                }
                VisualGraphUtilities.setCamera(wg, camera);
                scheduleCameraChangeOperation();
            }
            return STANDARD_DELAY;
        });
    }
}
Also used : Camera(au.gov.asd.tac.constellation.utilities.camera.Camera) Point(java.awt.Point)

Example 5 with Camera

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

the class DefaultInteractionEventHandler method mouseWheelMoved.

@Override
public void mouseWheelMoved(final MouseWheelEvent event) {
    queue.add(wg -> {
        if (wg != null) {
            final Camera camera = new Camera(VisualGraphUtilities.getCamera(wg));
            final Point wheelPoint = event.getPoint();
            // HACK_DPI: Don't need to scale the wheelPoint.
            eventState.setClosestNode(visualInteraction.closestNodeCameraCoordinates(wg, camera, wheelPoint));
            if (!eventState.isPoint(EventState.WHEEL_POINT) || !wheelPoint.equals(eventState.getPoint(EventState.WHEEL_POINT))) {
                eventState.storePoint(wheelPoint, EventState.WHEEL_POINT);
            }
            final Vector3f zoomReferencePoint = eventState.hasClosestNode() ? eventState.getClosestNode() : CameraUtilities.getFocusVector(camera);
            // reference point for further action, and in some cases simulate a drag.
            if (eventState.isMousePressed() && !wheelPoint.equals(eventState.getPoint(EventState.REFERENCE_POINT))) {
                final Point from;
                switch(eventState.getCurrentAction()) {
                    case PANNING:
                        from = eventState.getFirstValidPoint(EventState.DRAG_POINT, EventState.REFERENCE_POINT);
                        final Vector3f translation = visualInteraction.convertTranslationToPan(from, wheelPoint, zoomReferencePoint);
                        CameraUtilities.pan(camera, translation.getX(), translation.getY());
                        break;
                    case DRAG_NODES:
                        from = eventState.getPoint(EventState.DRAG_POINT);
                        performDrag(wg, camera, from, wheelPoint);
                        break;
                    default:
                        break;
                }
            }
            CameraUtilities.zoom(camera, -event.getWheelRotation(), visualInteraction.convertZoomPointToDirection(wheelPoint), zoomReferencePoint.getLength());
            eventState.addEventName(ZOOM_ACTION_NAME);
            if (eventState.isMousePressed()) {
                eventState.setClosestNode(visualInteraction.closestNodeCameraCoordinates(wg, camera, wheelPoint));
                eventState.storePoint(wheelPoint, EventState.REFERENCE_POINT, EventState.DRAG_POINT);
            }
            updateCameraAndNewLine(wg, wheelPoint, camera, true);
        }
        return STANDARD_DELAY;
    });
}
Also used : Vector3f(au.gov.asd.tac.constellation.utilities.graphics.Vector3f) Camera(au.gov.asd.tac.constellation.utilities.camera.Camera) Point(java.awt.Point)

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