use of au.gov.asd.tac.constellation.utilities.graphics.Vector3f in project constellation by constellation-app.
the class GLTools method toFloatArray.
/**
* Convert a Vector3f[] to a float[].
*
* @param vector The vector to be converted to an array.
*
* @return A float[] containing the same values as the vector.
*/
public static float[] toFloatArray(final Vector3f[] vector) {
final float[] f = new float[vector.length * 3];
int ix = 0;
for (final Vector3f v : vector) {
f[ix] = v.a[0];
f[ix + 1] = v.a[1];
f[ix + 2] = v.a[2];
ix += 3;
}
return f;
}
use of au.gov.asd.tac.constellation.utilities.graphics.Vector3f in project constellation by constellation-app.
the class FPSRenderable method calculateYProjectionScale.
private float calculateYProjectionScale(final int[] viewport) {
// calculate the number of pixels a scene object of y-length 1 projects to.
final Vector4f proj1 = new Vector4f();
Graphics3DUtilities.project(ZERO_3F, IDENTITY_44F, viewport, proj1);
final Vector4f proj2 = new Vector4f();
final Vector3f unitPosition = new Vector3f(0, 1, 0);
Graphics3DUtilities.project(unitPosition, IDENTITY_44F, viewport, proj2);
final float yScale = proj2.getY() - proj1.getY();
return (256.0F / 64) / yScale;
}
use of au.gov.asd.tac.constellation.utilities.graphics.Vector3f 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);
}
}
use of au.gov.asd.tac.constellation.utilities.graphics.Vector3f in project constellation by constellation-app.
the class CameraUtilities method zoomToBoundingBox.
/**
* Zoom so that the bounds of the bounding box are visible.
* <p>
* The direction of the zoom in 3D depends on the current lookat position.
* If the display is in 2D mode, the eye is moved so that eye->centre is
* parallel to the z-axis
*
* @param camera
* @param box
*/
public static void zoomToBoundingBox(final Camera camera, final BoundingBox box) {
if (!box.isEmpty()) {
final Vector3f centre = new Vector3f(box.getCentre(camera.getMix()));
final Vector3f toEye = Vector3f.subtract(camera.lookAtEye, camera.lookAtCentre);
toEye.normalize();
final float cameraDistance = Math.max(box.getCameraDistance(Camera.FIELD_OF_VIEW, camera.getMix()), MIN_ZOOM_DISTANCE);
toEye.scale(cameraDistance);
final Vector3f eye = Vector3f.add(centre, toEye);
setPreviousToCurrent(camera);
camera.lookAtEye.set(eye);
camera.lookAtCentre.set(centre);
camera.lookAtRotation.set(centre);
}
}
use of au.gov.asd.tac.constellation.utilities.graphics.Vector3f 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);
}
Aggregations