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;
});
}
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;
}
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)));
}
}
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);
}
}
}
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);
}
}
Aggregations