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",
org.eclipse.ice.viz.service.geometry.widgets,
org.eclipse.ice.viz.service.javafx.canvas,
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.model,
org.eclipse.ice.viz.service.javafx.viewer,
......
......@@ -11,8 +11,13 @@
package org.eclipse.ice.viz.service.javafx.geometry;
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 javafx.scene.Camera;
/**
* An extension of FX viewer for use with the geometry editor
*
......@@ -28,4 +33,38 @@ public class FXGeometryViewer extends FXViewer {
renderer.register(FXGeometryAttachment.class,
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,
org.eclipse.core.runtime
Bundle-Vendor: Oak Ridge National Laboratory
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.datastructures.VizObject,
org.eclipse.ice.viz.service.geometry.shapes,
......
......@@ -18,6 +18,7 @@ import javafx.scene.Scene;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.MouseEvent;
import javafx.scene.input.ScrollEvent;
import javafx.scene.transform.Affine;
import javafx.scene.transform.Rotate;
/**
......@@ -45,6 +46,11 @@ public class AbstractCameraController implements ICameraController {
*/
protected final Group xform;
/**
* The collected transformation for all movements applied to the camera
*/
protected Affine affine;
/**
* The FXCanvas which is using this camera
*/
......@@ -83,12 +89,12 @@ public class AbstractCameraController implements ICameraController {
/**
* 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.
*/
protected final double FAST_SPEED = 120.0d;
protected final double FAST_SPEED = 2.0d;
/**
* The default amount of X rotation to apply
......@@ -124,7 +130,12 @@ public class AbstractCameraController implements ICameraController {
this.canvas = canvas;
// 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
defaultX = new Rotate();
......@@ -134,6 +145,9 @@ public class AbstractCameraController implements ICameraController {
defaultY.setAxis(Rotate.Y_AXIS);
defaultZ.setAxis(Rotate.Z_AXIS);
// Set the camera to its default position
reset();
// Set the handler for key presses
scene.setOnKeyPressed(new EventHandler<KeyEvent>() {
@Override
......
......@@ -15,13 +15,16 @@ import javafx.scene.Camera;
import javafx.scene.Scene;
import javafx.scene.input.MouseEvent;
import javafx.scene.input.ScrollEvent;
import javafx.scene.transform.Affine;
import javafx.scene.transform.Rotate;
/**
* <p>
* ArcBallController provides 3D editor like features to a camera, by rotating
* around a point and letting the user zoom in and out.
* </p>
* A camera centered around and gazing towards the origin. The user can rotate
* the camera about the origin by dragging the mouse and zoom through scrolling
* the mouse wheel.
*
* @author Robert Smith
*
*/
public class CenteredController extends AbstractCameraController {
......@@ -35,20 +38,6 @@ public class CenteredController extends AbstractCameraController {
*/
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.
*
......@@ -62,65 +51,23 @@ public class CenteredController extends AbstractCameraController {
public CenteredController(Camera camera, Scene scene, FXCanvas canvas) {
super(camera, scene, canvas);
// scene.setOnKeyPressed(new EventHandler<KeyEvent>() {
// @Override
// public void handle(KeyEvent event) {
//
// double speed = NORMAL_SPEED;
//
// if (event.isShiftDown()) {
// speed = FAST_SPEED;
// }
//
// KeyCode keyCode = event.getCode();
//
// 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);
// }
// }
// });
// Set the x axis rotation for the affine transformation
x = new Rotate();
x.setAxis(Rotate.X_AXIS);
xform.getTransforms().add(x);
// Set the y axis rotation for the affine transformation
y = new Rotate();
y.setAxis(Rotate.Y_AXIS);
// Apply the rotations and the affine to the camera
xform.getTransforms().setAll(x, y, affine);
}
/*
* (non-Javadoc)
*
*
* @see org.eclipse.ice.viz.service.javafx.internal.scene.camera.
* AbstractCameraController#handleMouseDragged(javafx.scene.input.
* MouseEvent)
......@@ -140,31 +87,16 @@ public class CenteredController extends AbstractCameraController {
// Apply the change in mouse position to the camera's angle
if (event.isPrimaryButtonDown()) {
y.setAngle(y.getAngle() - mouseDeltaX);
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)
*
*
* @see org.eclipse.ice.viz.service.javafx.internal.scene.camera.
* AbstractCameraController#handleMouseScroll(javafx.scene.input.
* ScrollEvent)
......@@ -182,25 +114,31 @@ public class CenteredController extends AbstractCameraController {
* (non-Javadoc)
*
* @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
public void reset() {
// Reset the camera to its initial angles
x.setAngle(0);
y.setAngle(0);
// Handle the rotations if they exist
if (x != null) {
// Reset the camera to its initial angles
x.setAngle(0);
y.setAngle(0);
}
// 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;
import javafx.embed.swt.FXCanvas;
import javafx.geometry.Point3D;
import javafx.scene.Camera;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
......@@ -29,14 +30,41 @@ import javafx.scene.transform.Transform;
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) {
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)
*
......@@ -87,9 +115,9 @@ public class TopDownController extends AbstractCameraController {
}
if (keyCode == KeyCode.SPACE) {
camera.setTranslateZ(camera.getTranslateZ() - speed);
zoomCamera(-speed);
} else if (keyCode == KeyCode.C) {
camera.setTranslateZ(camera.getTranslateZ() + speed);
zoomCamera(speed);
}
}
......@@ -103,30 +131,9 @@ public class TopDownController extends AbstractCameraController {
@Override
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
double z = affine.getTz();
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();
zoomCamera(event.getDeltaY() * .1);
}
/*
......@@ -138,12 +145,11 @@ public class TopDownController extends AbstractCameraController {
@Override
public void reset() {
// Create a new affine transformation centered above the origin and
// replace the camera's current transformation(s) with it
// Create a new affine transformation, set it to the default position,
// and apply it to the camera
affine = new Affine();
affine.appendTranslation(0, 0, -85);
xform.getTransforms().setAll(affine);
}
}
......@@ -19,7 +19,7 @@ import org.eclipse.ice.viz.service.modeling.ShapeMesh;
/**
* A factory for creating JME3Shapes from MeshComponents.
*
* @author r8s
* @author Robert Smith
*
*/
public class JME3ControllerFactory implements IControllerFactory {
......@@ -34,7 +34,7 @@ public class JME3ControllerFactory implements IControllerFactory {
@Override
public AbstractController createController(AbstractMesh model) {
// If the model is not a shapecomponent, fail silently
// If the model is not a shape mesh, fail silently
if (model instanceof ShapeMesh) {
// Create a JME3 view
......
......@@ -68,6 +68,25 @@ public class AbstractControllerTester {
controller = new TestController(component, view);
}
/**
* Check that the AbstractController is in the correct state after
* construction.
*/
@Test
public void testConstruction() {
TestMesh mesh = new TestMesh(null);
TestView view = new TestView();
TestController controller = new TestController(mesh, view);
// Check that the controller contains the mesh and view
assertTrue(mesh == controller.getModel());
assertTrue(view == controller.getView());
// Check that the model has a reference to the controller
assertTrue(controller == mesh.getController());
}
/**
* Tests the state of the entities list as objects are added and removed, as
* well as whether objects in it are sending propert notifications.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment