Search in sources :

Example 6 with Frame

use of au.gov.asd.tac.constellation.utilities.graphics.Frame in project constellation by constellation-app.

the class CameraUtilities method refocus.

/**
 * Refocuses the camera to look in a specified direction at a specified
 * region.
 *
 * @param camera The camera object to refocus
 * @param unitEye A unit vector pointing in the direction the camera should
 * be looking
 * @param up A vector pointing in the desired up direction
 * @param region The bounding box representing the region the camera should
 * be looking at
 */
public static void refocus(final Camera camera, final Vector3f unitEye, final Vector3f up, final BoundingBox region) {
    // If the graph is very small (for instance, one node), then the bounding box radius will be zero
    // and the graph will be closer than the near clipping plane.
    float cameraDistance = region.getCameraDistance(Camera.FIELD_OF_VIEW, camera.getMix());
    if (cameraDistance < MIN_ZOOM_DISTANCE) {
        cameraDistance = MIN_ZOOM_DISTANCE;
    }
    if (cameraDistance >= Camera.PERSPECTIVE_FAR) {
        cameraDistance = Camera.PERSPECTIVE_FAR - 1;
    }
    final Vector3f centre = region.getCentre(camera.getMix());
    final Vector3f eye = new Vector3f(unitEye);
    eye.scale(cameraDistance);
    eye.add(centre);
    setPreviousToCurrent(camera);
    camera.lookAtEye.set(eye);
    camera.lookAtCentre.set(centre);
    camera.lookAtUp.set(up);
    camera.lookAtRotation.set(centre);
    // the scene has not previously been drawn.
    if (camera.getObjectFrame() == null) {
        camera.setObjectFrame(new Frame());
        camera.getObjectFrame().setForwardVector(0, 0, 1);
    }
}
Also used : Frame(au.gov.asd.tac.constellation.utilities.graphics.Frame) Vector3f(au.gov.asd.tac.constellation.utilities.graphics.Vector3f)

Example 7 with Frame

use of au.gov.asd.tac.constellation.utilities.graphics.Frame in project constellation by constellation-app.

the class CameraUtilities method rotate.

public static void rotate(final Camera camera, final float xDegrees, final float yDegrees, final float zDegrees) {
    // Use a frame to move the eye and centre relative to the rotation point.
    Frame frame = new Frame(camera.lookAtEye, camera.lookAtCentre, camera.lookAtUp);
    frame.setOrigin(camera.lookAtRotation);
    final Vector3f localCentre = new Vector3f();
    final Vector3f localEye = new Vector3f();
    frame.worldToLocal(camera.lookAtCentre, localCentre);
    frame.worldToLocal(camera.lookAtEye, localEye);
    if (xDegrees != 0) {
        frame.rotateLocal((float) Mathf.degToRad(xDegrees), 1.0F, 0.0F, 0.0F);
    }
    if (yDegrees != 0) {
        frame.rotateLocal((float) Mathf.degToRad(yDegrees), 0.0F, 1.0F, 0.0F);
    }
    if (zDegrees != 0) {
        frame.rotateLocal((float) Mathf.degToRad(zDegrees), 0.0F, 0.0F, 1.0F);
    }
    // Retrieve the rotated points from the frame.
    frame.localToWorld(localCentre, camera.lookAtCentre);
    frame.localToWorld(localEye, camera.lookAtEye);
    frame.getUpVector(camera.lookAtUp);
}
Also used : Frame(au.gov.asd.tac.constellation.utilities.graphics.Frame) Vector3f(au.gov.asd.tac.constellation.utilities.graphics.Vector3f)

Example 8 with Frame

use of au.gov.asd.tac.constellation.utilities.graphics.Frame in project constellation by constellation-app.

the class CameraNGTest method assertCamerasEqual.

// helper to assert a Camera object with no other initialise
private void assertCamerasEqual(final Camera c1, final Camera c2) {
    assertEquals(c1.lookAtEye.toString(), c2.lookAtEye.toString());
    assertEquals(c1.lookAtCentre.toString(), c2.lookAtCentre.toString());
    assertEquals(c1.lookAtUp.toString(), c2.lookAtUp.toString());
    assertEquals(c1.lookAtRotation.toString(), c2.lookAtRotation.toString());
    assertEquals(c1.lookAtPreviousEye.toString(), c2.lookAtPreviousEye.toString());
    assertEquals(c1.lookAtPreviousCentre.toString(), c2.lookAtPreviousCentre.toString());
    assertEquals(c1.lookAtPreviousUp.toString(), c2.lookAtPreviousUp.toString());
    assertEquals(c1.lookAtPreviousRotation.toString(), c2.lookAtPreviousRotation.toString());
    assertEquals(c1.getVisibilityLow(), c2.getVisibilityLow());
    assertEquals(c1.getVisibilityHigh(), c2.getVisibilityHigh());
    final BoundingBox bb1 = c1.boundingBox;
    final BoundingBox bb2 = c2.boundingBox;
    assertEquals(bb1.getMin().toString(), bb2.getMin().toString());
    assertEquals(bb1.getMax().toString(), bb2.getMax().toString());
    assertEquals(bb1.getMin2().toString(), bb2.getMin2().toString());
    assertEquals(bb1.getMax2().toString(), bb2.getMax2().toString());
    assertEquals(bb1.isEmpty(), bb2.isEmpty());
    final Frame of1 = c1.getObjectFrame();
    final Frame of2 = c2.getObjectFrame();
    assertEquals(of1.getOrigin().toString(), of2.getOrigin().toString());
    assertEquals(of1.getUpVector().toString(), of2.getUpVector().toString());
    assertEquals(of1.getForwardVector().toString(), of2.getForwardVector().toString());
}
Also used : Frame(au.gov.asd.tac.constellation.utilities.graphics.Frame)

Example 9 with Frame

use of au.gov.asd.tac.constellation.utilities.graphics.Frame in project constellation by constellation-app.

the class CameraUtilities method zoom.

public static void zoom(final Camera camera, final int zoomAmount, final Vector3f zoomDirection, final float distanceToClosestNode) {
    zoomDirection.normalize();
    if (distanceToClosestNode < Float.MAX_VALUE) {
        if (zoomAmount > 0) {
            zoomDirection.scale(Math.max(zoomAmount, zoomAmount * distanceToClosestNode * 0.1F));
        } else {
            zoomDirection.scale(Math.min(zoomAmount, zoomAmount * distanceToClosestNode * 0.1F));
        }
    } else {
        zoomDirection.scale(zoomAmount);
    }
    final Frame frame = new Frame(camera.lookAtEye, camera.lookAtCentre, camera.lookAtUp);
    frame.translateLocal(zoomDirection.getX(), zoomDirection.getY(), zoomDirection.getZ());
    final Vector3f tr = frame.getOrigin();
    camera.lookAtEye.subtract(tr);
    camera.lookAtCentre.subtract(tr);
}
Also used : Frame(au.gov.asd.tac.constellation.utilities.graphics.Frame) Vector3f(au.gov.asd.tac.constellation.utilities.graphics.Vector3f)

Example 10 with Frame

use of au.gov.asd.tac.constellation.utilities.graphics.Frame in project constellation by constellation-app.

the class CameraUtilities method pan.

public static void pan(final Camera camera, final float xShift, final float yShift) {
    final Frame frame = new Frame(camera.lookAtEye, camera.lookAtCentre, camera.lookAtUp);
    frame.translateLocal(xShift, yShift, 0);
    final Vector3f tr = frame.getOrigin();
    camera.lookAtEye.add(tr);
    camera.lookAtCentre.add(tr);
}
Also used : Frame(au.gov.asd.tac.constellation.utilities.graphics.Frame) Vector3f(au.gov.asd.tac.constellation.utilities.graphics.Vector3f)

Aggregations

Frame (au.gov.asd.tac.constellation.utilities.graphics.Frame)19 Vector3f (au.gov.asd.tac.constellation.utilities.graphics.Vector3f)14 Matrix33f (au.gov.asd.tac.constellation.utilities.graphics.Matrix33f)5 Matrix44f (au.gov.asd.tac.constellation.utilities.graphics.Matrix44f)5 Test (org.testng.annotations.Test)5 Camera (au.gov.asd.tac.constellation.utilities.camera.Camera)4 BitSet (java.util.BitSet)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 SetBooleanValuesOperation (au.gov.asd.tac.constellation.graph.operations.SetBooleanValuesOperation)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayList (java.util.ArrayList)1 BeforeClass (org.testng.annotations.BeforeClass)1