Commit 132780b2 authored by Robert Smith's avatar Robert Smith
Browse files

Fixed cameras



Cameras were broken by the AbstractCameraController refactor. This
commit repairs them.
Signed-off-by: Robert Smith's avatarRobert Smith <SmithRW@ornl.gov>
parent acadfeb9
...@@ -19,6 +19,8 @@ Import-Package: javafx.scene.image;version="2.2.0", ...@@ -19,6 +19,8 @@ Import-Package: javafx.scene.image;version="2.2.0",
org.eclipse.ice.viz.service.geometry.widgets, org.eclipse.ice.viz.service.geometry.widgets,
org.eclipse.ice.viz.service.javafx.canvas, org.eclipse.ice.viz.service.javafx.canvas,
org.eclipse.ice.viz.service.javafx.internal, org.eclipse.ice.viz.service.javafx.internal,
org.eclipse.ice.viz.service.javafx.internal.model,
org.eclipse.ice.viz.service.javafx.internal.scene.camera,
org.eclipse.ice.viz.service.javafx.scene.base, org.eclipse.ice.viz.service.javafx.scene.base,
org.eclipse.ice.viz.service.javafx.scene.model, org.eclipse.ice.viz.service.javafx.scene.model,
org.eclipse.ice.viz.service.javafx.viewer, org.eclipse.ice.viz.service.javafx.viewer,
......
...@@ -11,8 +11,13 @@ ...@@ -11,8 +11,13 @@
package org.eclipse.ice.viz.service.javafx.geometry; package org.eclipse.ice.viz.service.javafx.geometry;
import org.eclipse.ice.viz.service.javafx.canvas.FXViewer; import org.eclipse.ice.viz.service.javafx.canvas.FXViewer;
import org.eclipse.ice.viz.service.javafx.internal.model.FXCameraAttachment;
import org.eclipse.ice.viz.service.javafx.internal.scene.camera.CenteredController;
import org.eclipse.ice.viz.service.javafx.scene.base.ICamera;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
import javafx.scene.Camera;
/** /**
* An extension of FX viewer for use with the geometry editor * An extension of FX viewer for use with the geometry editor
* *
...@@ -28,4 +33,38 @@ public class FXGeometryViewer extends FXViewer { ...@@ -28,4 +33,38 @@ public class FXGeometryViewer extends FXViewer {
renderer.register(FXGeometryAttachment.class, renderer.register(FXGeometryAttachment.class,
new FXGeometryAttachmentManager()); new FXGeometryAttachmentManager());
} }
/*
* (non-Javadoc)
*
* @see org.eclipse.ice.viz.service.javafx.canvas.FXViewer#updateCamera(org.
* eclipse.ice.viz.service.javafx.scene.base.ICamera)
*/
@Override
protected void updateCamera(ICamera camera) {
// Check the camera attachment for validity
if (!(camera instanceof FXCameraAttachment)) {
throw new IllegalArgumentException(
"Invalid camera attached to Mesh Viewer.");
}
// Cast the camera attachment and check that it has a camera
FXCameraAttachment attachment = (FXCameraAttachment) camera;
Camera fxCamera = attachment.getFxCamera();
if (fxCamera == null) {
throw new NullPointerException(
"No camera was attached to Mesh Viewer");
}
// Create a controller
cameraController = new CenteredController(fxCamera, scene, fxCanvas);
// Set the camera on the scene
scene.setCamera(fxCamera);
defaultCamera = fxCamera;
}
} }
...@@ -8,7 +8,9 @@ Require-Bundle: org.eclipse.ui, ...@@ -8,7 +8,9 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime org.eclipse.core.runtime
Bundle-Vendor: Oak Ridge National Laboratory Bundle-Vendor: Oak Ridge National Laboratory
Eclipse-ExtensibleAPI: true Eclipse-ExtensibleAPI: true
Import-Package: javafx.scene.input;version="2.2.0", Import-Package: javafx.geometry;version="2.2.0",
javafx.scene.input;version="2.2.0",
javafx.scene.transform;version="2.2.0",
org.eclipse.ice.viz.service, org.eclipse.ice.viz.service,
org.eclipse.ice.viz.service.datastructures.VizObject, org.eclipse.ice.viz.service.datastructures.VizObject,
org.eclipse.ice.viz.service.geometry.shapes, org.eclipse.ice.viz.service.geometry.shapes,
......
...@@ -18,6 +18,7 @@ import javafx.scene.Scene; ...@@ -18,6 +18,7 @@ import javafx.scene.Scene;
import javafx.scene.input.KeyEvent; import javafx.scene.input.KeyEvent;
import javafx.scene.input.MouseEvent; import javafx.scene.input.MouseEvent;
import javafx.scene.input.ScrollEvent; import javafx.scene.input.ScrollEvent;
import javafx.scene.transform.Affine;
import javafx.scene.transform.Rotate; import javafx.scene.transform.Rotate;
/** /**
...@@ -45,6 +46,11 @@ public class AbstractCameraController implements ICameraController { ...@@ -45,6 +46,11 @@ public class AbstractCameraController implements ICameraController {
*/ */
protected final Group xform; protected final Group xform;
/**
* The collected transformation for all movements applied to the camera
*/
protected Affine affine;
/** /**
* The FXCanvas which is using this camera * The FXCanvas which is using this camera
*/ */
...@@ -83,12 +89,12 @@ public class AbstractCameraController implements ICameraController { ...@@ -83,12 +89,12 @@ public class AbstractCameraController implements ICameraController {
/** /**
* A constant multiplier for the mouse's normal movement speed. * A constant multiplier for the mouse's normal movement speed.
*/ */
protected final double NORMAL_SPEED = 60.0d; protected final double NORMAL_SPEED = 1.0d;
/** /**
* A constant multiplier for the mouse's increased movement speed. * A constant multiplier for the mouse's increased movement speed.
*/ */
protected final double FAST_SPEED = 120.0d; protected final double FAST_SPEED = 2.0d;
/** /**
* The default amount of X rotation to apply * The default amount of X rotation to apply
...@@ -124,7 +130,12 @@ public class AbstractCameraController implements ICameraController { ...@@ -124,7 +130,12 @@ public class AbstractCameraController implements ICameraController {
this.canvas = canvas; this.canvas = canvas;
// Get the camera's parent // Get the camera's parent
xform = (Group) camera.getParent(); xform = new Group();
xform.getChildren().add(camera);
// Set the affine transformation
affine = new Affine();
xform.getTransforms().setAll(affine);
// Initialize the default angles // Initialize the default angles
defaultX = new Rotate(); defaultX = new Rotate();
...@@ -134,6 +145,9 @@ public class AbstractCameraController implements ICameraController { ...@@ -134,6 +145,9 @@ public class AbstractCameraController implements ICameraController {
defaultY.setAxis(Rotate.Y_AXIS); defaultY.setAxis(Rotate.Y_AXIS);
defaultZ.setAxis(Rotate.Z_AXIS); defaultZ.setAxis(Rotate.Z_AXIS);
// Set the camera to its default position
reset();
// Set the handler for key presses // Set the handler for key presses
scene.setOnKeyPressed(new EventHandler<KeyEvent>() { scene.setOnKeyPressed(new EventHandler<KeyEvent>() {
@Override @Override
......
...@@ -15,13 +15,16 @@ import javafx.scene.Camera; ...@@ -15,13 +15,16 @@ import javafx.scene.Camera;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.input.MouseEvent; import javafx.scene.input.MouseEvent;
import javafx.scene.input.ScrollEvent; import javafx.scene.input.ScrollEvent;
import javafx.scene.transform.Affine;
import javafx.scene.transform.Rotate; import javafx.scene.transform.Rotate;
/** /**
* <p> * A camera centered around and gazing towards the origin. The user can rotate
* ArcBallController provides 3D editor like features to a camera, by rotating * the camera about the origin by dragging the mouse and zoom through scrolling
* around a point and letting the user zoom in and out. * the mouse wheel.
* </p> *
* @author Robert Smith
*
*/ */
public class CenteredController extends AbstractCameraController { public class CenteredController extends AbstractCameraController {
...@@ -35,20 +38,6 @@ public class CenteredController extends AbstractCameraController { ...@@ -35,20 +38,6 @@ public class CenteredController extends AbstractCameraController {
*/ */
private Rotate y; private Rotate y;
// /**
// * The default X coordinate for the camera.
// */
// private double defaultXPosition;
//
// /**
// * The default amount of X rotation to apply to the camera.
// */
// private double defaultXRotation;
//
// private double defaultYRotation;
//
// private double
/** /**
* The default constructor. * The default constructor.
* *
...@@ -62,65 +51,23 @@ public class CenteredController extends AbstractCameraController { ...@@ -62,65 +51,23 @@ public class CenteredController extends AbstractCameraController {
public CenteredController(Camera camera, Scene scene, FXCanvas canvas) { public CenteredController(Camera camera, Scene scene, FXCanvas canvas) {
super(camera, scene, canvas); super(camera, scene, canvas);
// scene.setOnKeyPressed(new EventHandler<KeyEvent>() { // Set the x axis rotation for the affine transformation
// @Override x = new Rotate();
// public void handle(KeyEvent event) { x.setAxis(Rotate.X_AXIS);
// xform.getTransforms().add(x);
// double speed = NORMAL_SPEED;
// // Set the y axis rotation for the affine transformation
// if (event.isShiftDown()) { y = new Rotate();
// speed = FAST_SPEED; y.setAxis(Rotate.Y_AXIS);
// }
// // Apply the rotations and the affine to the camera
// KeyCode keyCode = event.getCode(); xform.getTransforms().setAll(x, y, affine);
//
// Transform worldTransform = xform.getLocalToSceneTransform();
// double zx = worldTransform.getMzx();
// double zy = worldTransform.getMzy();
// double zz = worldTransform.getMzz();
//
// double xx = worldTransform.getMxx();
// double xy = worldTransform.getMxy();
// double xz = worldTransform.getMxz();
//
// Point3D zDir = new Point3D(zx, zy, zz).normalize();
// Point3D xDir = new Point3D(xx, xy, xz).normalize();
//
// if (keyCode == KeyCode.W) {
// Point3D moveVec = zDir.multiply(speed);
// affine.appendTranslation(moveVec.getX(), moveVec.getY(),
// moveVec.getZ());
// } else if (keyCode == KeyCode.S) {
// Point3D moveVec = zDir.multiply(speed);
// Point3D invVec = new Point3D(-moveVec.getX(),
// -moveVec.getY(), -moveVec.getZ());
// affine.appendTranslation(invVec.getX(), invVec.getY(),
// invVec.getZ());
// } else if (keyCode == KeyCode.A) {
// Point3D moveVec = xDir.multiply(speed);
// affine.appendTranslation(-moveVec.getX(), -moveVec.getY(),
// -moveVec.getZ());
// } else if (keyCode == KeyCode.D) {
// Point3D moveVec = xDir.multiply(speed);
// affine.appendTranslation(moveVec.getX(), moveVec.getY(),
// moveVec.getZ());
// }
//
// if (keyCode == KeyCode.SPACE) {
// finalCamera
// .setTranslateZ(finalCamera.getTranslateZ() - speed);
// } else if (keyCode == KeyCode.C) {
// finalCamera
// .setTranslateZ(finalCamera.getTranslateZ() + speed);
// }
// }
// });
} }
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
* @see org.eclipse.ice.viz.service.javafx.internal.scene.camera. * @see org.eclipse.ice.viz.service.javafx.internal.scene.camera.
* AbstractCameraController#handleMouseDragged(javafx.scene.input. * AbstractCameraController#handleMouseDragged(javafx.scene.input.
* MouseEvent) * MouseEvent)
...@@ -140,31 +87,16 @@ public class CenteredController extends AbstractCameraController { ...@@ -140,31 +87,16 @@ public class CenteredController extends AbstractCameraController {
// Apply the change in mouse position to the camera's angle // Apply the change in mouse position to the camera's angle
if (event.isPrimaryButtonDown()) { if (event.isPrimaryButtonDown()) {
y.setAngle(y.getAngle() - mouseDeltaX); y.setAngle(y.getAngle() - mouseDeltaX);
x.setAngle(x.getAngle() + mouseDeltaY); x.setAngle(x.getAngle() + mouseDeltaY);
}
}
/* }
* (non-Javadoc)
*
* @see org.eclipse.ice.viz.service.javafx.internal.scene.camera.
* AbstractCameraController#handleMousePressed(javafx.scene.input.
* MouseEvent)
*/
@Override
public void handleMousePressed(MouseEvent event) {
// Get the mouse position for the start of the drag
mousePosX = event.getSceneX();
mousePosY = event.getSceneY();
mouseOldX = event.getSceneX();
mouseOldY = event.getSceneY();
} }
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
* @see org.eclipse.ice.viz.service.javafx.internal.scene.camera. * @see org.eclipse.ice.viz.service.javafx.internal.scene.camera.
* AbstractCameraController#handleMouseScroll(javafx.scene.input. * AbstractCameraController#handleMouseScroll(javafx.scene.input.
* ScrollEvent) * ScrollEvent)
...@@ -182,25 +114,31 @@ public class CenteredController extends AbstractCameraController { ...@@ -182,25 +114,31 @@ public class CenteredController extends AbstractCameraController {
* (non-Javadoc) * (non-Javadoc)
* *
* @see org.eclipse.ice.viz.service.javafx.internal.scene.camera. * @see org.eclipse.ice.viz.service.javafx.internal.scene.camera.
* AbstractCameraController#initCamera() * AbstractCameraController#reset()
*/ */
@Override
public void initCamera() {
super.initCamera();
// Reset the camera to its default position
reset();
}
@Override @Override
public void reset() { public void reset() {
// Reset the camera to its initial angles // Handle the rotations if they exist
x.setAngle(0); if (x != null) {
y.setAngle(0); // Reset the camera to its initial angles
x.setAngle(0);
y.setAngle(0);
}
// Zoom the camera back to a default distance from the origin. // Zoom the camera back to a default distance from the origin.
camera.setTranslateZ(-2000); affine = new Affine();
affine.appendTranslation(0, 0, -2000);
// If x and y exist, apply them to the camera
if (x != null) {
xform.getTransforms().setAll(x, y, affine);
}
// Otherwise only apply the affine to the camera
else {
xform.getTransforms().setAll(affine);
}
} }
......
...@@ -13,6 +13,7 @@ package org.eclipse.ice.viz.service.javafx.internal.scene.camera; ...@@ -13,6 +13,7 @@ package org.eclipse.ice.viz.service.javafx.internal.scene.camera;
import javafx.embed.swt.FXCanvas; import javafx.embed.swt.FXCanvas;
import javafx.geometry.Point3D; import javafx.geometry.Point3D;
import javafx.scene.Camera; import javafx.scene.Camera;
import javafx.scene.Node;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.input.KeyCode; import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent; import javafx.scene.input.KeyEvent;
...@@ -29,14 +30,41 @@ import javafx.scene.transform.Transform; ...@@ -29,14 +30,41 @@ import javafx.scene.transform.Transform;
public class TopDownController extends AbstractCameraController { public class TopDownController extends AbstractCameraController {
/** /**
* The collected transformation for all movements applied to the camera * <p>
* </p>
*/ */
Affine affine = new Affine();
public TopDownController(Camera camera, Scene scene, FXCanvas canvas) { public TopDownController(Camera camera, Scene scene, FXCanvas canvas) {
super(camera, scene, canvas); super(camera, scene, canvas);
} }
/**
* Set a node to move along with the camera, so that it is always displayed
* in the same part of the screen.
*
* @param node
* The node whose position will be set relative to the camera.
*/
public void fixToCamera(Node node) {
xform.getChildren().add(node);
}
/**
* Move the camera along the Z axis by the given distance.
*
* @param deltaZ
* The amount to move the camera by. Positive values move it in
* towards the origin, negative values move it back away from the
* origin.
*/
public void zoomCamera(double deltaZ) {
// Prevent the user from zooming too close to the plane of the x
// and y axis
if (affine.getTz() + deltaZ <= -15) {
affine.appendTranslation(0, 0, deltaZ);
}
}
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
...@@ -87,9 +115,9 @@ public class TopDownController extends AbstractCameraController { ...@@ -87,9 +115,9 @@ public class TopDownController extends AbstractCameraController {
} }
if (keyCode == KeyCode.SPACE) { if (keyCode == KeyCode.SPACE) {
camera.setTranslateZ(camera.getTranslateZ() - speed); zoomCamera(-speed);
} else if (keyCode == KeyCode.C) { } else if (keyCode == KeyCode.C) {
camera.setTranslateZ(camera.getTranslateZ() + speed); zoomCamera(speed);
} }
} }
...@@ -103,30 +131,9 @@ public class TopDownController extends AbstractCameraController { ...@@ -103,30 +131,9 @@ public class TopDownController extends AbstractCameraController {
@Override @Override
public void handleMouseScroll(ScrollEvent event) { public void handleMouseScroll(ScrollEvent event) {
// Get the current z position and modify it by the amount of // Zoom the camera based on the amount and direction of
// scrolling // scrolling
double z = affine.getTz(); zoomCamera(event.getDeltaY() * .1);
double deltaZ = event.getDeltaY() * .1;
// Prevent the user from zooming too close to the plane of the x
// and y axis
if (z + deltaZ <= -15) {
affine.appendTranslation(0, 0, event.getDeltaY() * .1);
}
}
/*
* (non-Javadoc)
*
* @see org.eclipse.ice.viz.service.javafx.internal.scene.camera.
* AbstractCameraController#initCamera()
*/
@Override
protected void initCamera() {
super.initCamera();
// Reset the camera to its initial position
reset();
} }
/* /*
...@@ -138,12 +145,11 @@ public class TopDownController extends AbstractCameraController { ...@@ -138,12 +145,11 @@ public class TopDownController extends AbstractCameraController {
@Override @Override
public void reset() { public void reset() {
// Create a new affine transformation centered above the origin and // Create a new affine transformation, set it to the default position,
// replace the camera's current transformation(s) with it // and apply it to the camera
affine = new Affine(); affine = new Affine();
affine.appendTranslation(0, 0, -85); affine.appendTranslation(0, 0, -85);
xform.getTransforms().setAll(affine); xform.getTransforms().setAll(affine);
} }
} }
...@@ -19,7 +19,7 @@ import org.eclipse.ice.viz.service.modeling.ShapeMesh; ...@@ -19,7 +19,7 @@ import org.eclipse.ice.viz.service.modeling.ShapeMesh;
/** /**
* A factory for creating JME3Shapes from MeshComponents. * A factory for creating JME3Shapes from MeshComponents.
* *
* @author r8s * @author Robert Smith
* *