Commit d4a2ae64 authored by Robert Smith's avatar Robert Smith
Browse files

Changed Geometry Editor camera



Switched the geometry editor camera to always stay centered on the
origin. Also added mouse wheel zooming. 
Signed-off-by: Robert Smith's avatarRobert Smith <SmithRW@ornl.gov>
parent db08efe1
...@@ -135,13 +135,12 @@ public class FXGeometryViewer extends GeometryViewer { ...@@ -135,13 +135,12 @@ public class FXGeometryViewer extends GeometryViewer {
* *
*/ */
private void createDefaultCamera(Group parent) { private void createDefaultCamera(Group parent) {
PerspectiveCamera perspCamera = new PerspectiveCamera(); PerspectiveCamera perspCamera = new PerspectiveCamera(true);
perspCamera.setNearClip(0.1); perspCamera.setNearClip(0.1);
perspCamera.setFarClip(2000.0); perspCamera.setFarClip(4000.0);
perspCamera.setFieldOfView(35); perspCamera.setFieldOfView(35);
perspCamera.setTranslateX(0); perspCamera.setTranslateX(0);
perspCamera.setTranslateY(-100); perspCamera.setTranslateY(0);
perspCamera.setTranslateZ(-1000);
parent.getChildren().add(perspCamera); parent.getChildren().add(perspCamera);
......
...@@ -51,7 +51,7 @@ public class FXCameraAttachment extends CameraAttachment { ...@@ -51,7 +51,7 @@ public class FXCameraAttachment extends CameraAttachment {
super.attach(owner); super.attach(owner);
if (camera == null) { if (camera == null) {
camera = new PerspectiveCamera(); camera = new PerspectiveCamera(true);
} }
Group fxGroup = Util.getFxGroup(owner); Group fxGroup = Util.getFxGroup(owner);
......
...@@ -19,6 +19,7 @@ import javafx.scene.Scene; ...@@ -19,6 +19,7 @@ import javafx.scene.Scene;
import javafx.scene.input.KeyCode; import javafx.scene.input.KeyCode;
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.transform.Affine; import javafx.scene.transform.Affine;
import javafx.scene.transform.Rotate; import javafx.scene.transform.Rotate;
import javafx.scene.transform.Transform; import javafx.scene.transform.Transform;
...@@ -31,165 +32,199 @@ import javafx.scene.transform.Transform; ...@@ -31,165 +32,199 @@ import javafx.scene.transform.Transform;
*/ */
public class FPSController extends CameraController { public class FPSController extends CameraController {
/** */ /** */
Transform xform; Transform xform;
/** */ /** */
Affine transform; Affine transform;
/** */ /** */
private Camera camera; private Camera camera;
/** */ /** */
private Scene scene; private Scene scene;
/** */ /** */
double anchorX; double anchorX;
/** */ /** */
double anchorY; double anchorY;
/** */ /** */
double anchorAngle; double anchorAngle;
/** */ /** */
private double sphereRadius; private double sphereRadius;
/** */ /** */
private double height; private double height;
/** */ /** */
private double width; private double width;
/** */ /** */
protected Point3D currentRot; protected Point3D currentRot;
/** */ /** */
private Point3D startRot; private Point3D startRot;
/** */ /** */
protected boolean activeRotation; protected boolean activeRotation;
/** */ /** */
private FXCanvas canvas; private FXCanvas canvas;
private double mousePosX; private double mousePosX;
private double mousePosY; private double mousePosY;
private double mouseOldX; private double mouseOldX;
private double mouseOldY; private double mouseOldY;
private double mouseDeltaX; private double mouseDeltaX;
private double mouseDeltaY; private double mouseDeltaY;
private Affine affine; private Affine affine;
private final double NORMAL_SPEED = 60.0d; private final double NORMAL_SPEED = 60.0d;
private final double FAST_SPEED = 120.0d; private final double FAST_SPEED = 120.0d;
private double speed; private double speed;
/** /**
* <p> * <p>
* </p> * </p>
*/ */
public FPSController(Camera camera, Scene scene, FXCanvas canvas) { public FPSController(Camera camera, Scene scene, FXCanvas canvas) {
this.camera = camera; this.camera = camera;
this.scene = scene; this.scene = scene;
this.canvas = canvas; this.canvas = canvas;
final Camera finalCamera = camera; final Camera finalCamera = camera;
final Group xform = (Group) camera.getParent(); final Group xform = (Group) camera.getParent();
Rotate x = new Rotate(); Rotate x = new Rotate();
x.setAxis(Rotate.X_AXIS); x.setAxis(Rotate.X_AXIS);
Rotate y = new Rotate(); Rotate y = new Rotate();
y.setAxis(Rotate.Y_AXIS); y.setAxis(Rotate.Y_AXIS);
affine = new Affine(); Rotate z = new Rotate();
camera.getTransforms().setAll(affine); z.setAxis(Rotate.Z_AXIS);
scene.setOnKeyPressed(new EventHandler<KeyEvent>() { final Group camGroup = new Group();
public void handle(KeyEvent event) { camGroup.getTransforms().setAll(x, y, z);
camGroup.getChildren().add(finalCamera);
double speed = NORMAL_SPEED;
finalCamera.setTranslateZ(-2000);
if (event.isShiftDown()) {
speed = FAST_SPEED; // affine = new Affine();
} // camera.getTransforms().setAll(affine);
KeyCode keyCode = event.getCode(); scene.setOnKeyPressed(new EventHandler<KeyEvent>() {
@Override
Transform worldTransform = xform.getLocalToSceneTransform(); public void handle(KeyEvent event) {
double zx = worldTransform.getMzx();
double zy = worldTransform.getMzy(); double speed = NORMAL_SPEED;
double zz = worldTransform.getMzz();
if (event.isShiftDown()) {
double xx = worldTransform.getMxx(); speed = FAST_SPEED;
double xy = worldTransform.getMxy(); }
double xz = worldTransform.getMxz();
KeyCode keyCode = event.getCode();
Point3D zDir = new Point3D(zx, zy, zz).normalize();
Point3D xDir = new Point3D(xx, xy, xz).normalize(); Transform worldTransform = xform.getLocalToSceneTransform();
double zx = worldTransform.getMzx();
if (keyCode == KeyCode.W) { double zy = worldTransform.getMzy();
Point3D moveVec = zDir.multiply(speed); double zz = worldTransform.getMzz();
affine.appendTranslation(moveVec.getX(), moveVec.getY(), moveVec.getZ());
} else if (keyCode == KeyCode.S) { double xx = worldTransform.getMxx();
Point3D moveVec = zDir.multiply(speed); double xy = worldTransform.getMxy();
Point3D invVec = new Point3D(-moveVec.getX(), -moveVec.getY(), -moveVec.getZ()); double xz = worldTransform.getMxz();
affine.appendTranslation(invVec.getX(), invVec.getY(), invVec.getZ());
} else if (keyCode == KeyCode.A) { Point3D zDir = new Point3D(zx, zy, zz).normalize();
Point3D moveVec = xDir.multiply(speed); Point3D xDir = new Point3D(xx, xy, xz).normalize();
affine.appendTranslation(-moveVec.getX(), -moveVec.getY(), -moveVec.getZ());
} else if (keyCode == KeyCode.D) { if (keyCode == KeyCode.W) {
Point3D moveVec = xDir.multiply(speed); Point3D moveVec = zDir.multiply(speed);
affine.appendTranslation(moveVec.getX(), moveVec.getY(), moveVec.getZ()); affine.appendTranslation(moveVec.getX(), moveVec.getY(),
} moveVec.getZ());
} else if (keyCode == KeyCode.S) {
finalCamera.getTransforms().setAll(affine); Point3D moveVec = zDir.multiply(speed);
Point3D invVec = new Point3D(-moveVec.getX(),
if (keyCode == KeyCode.SPACE) { -moveVec.getY(), -moveVec.getZ());
finalCamera.setTranslateY(finalCamera.getTranslateY() - speed); affine.appendTranslation(invVec.getX(), invVec.getY(),
} else if (keyCode == KeyCode.C) { invVec.getZ());
finalCamera.setTranslateY(finalCamera.getTranslateY() + speed); } else if (keyCode == KeyCode.A) {
} Point3D moveVec = xDir.multiply(speed);
} affine.appendTranslation(-moveVec.getX(), -moveVec.getY(),
}); -moveVec.getZ());
} else if (keyCode == KeyCode.D) {
scene.setOnMousePressed(new EventHandler<MouseEvent>() { Point3D moveVec = xDir.multiply(speed);
public void handle(MouseEvent arg0) { affine.appendTranslation(moveVec.getX(), moveVec.getY(),
mousePosX = arg0.getSceneX(); moveVec.getZ());
mousePosY = arg0.getSceneY(); }
mouseOldX = arg0.getSceneX();
mouseOldY = arg0.getSceneY(); if (keyCode == KeyCode.SPACE) {
} finalCamera
}); .setTranslateZ(finalCamera.getTranslateZ() - speed);
} else if (keyCode == KeyCode.C) {
scene.setOnMouseDragged(new EventHandler<MouseEvent>() { finalCamera
public void handle(MouseEvent arg0) { .setTranslateZ(finalCamera.getTranslateZ() + speed);
mouseOldX = mousePosX; }
mouseOldY = mousePosY; }
mousePosX = arg0.getSceneX(); });
mousePosY = arg0.getSceneY();
mouseDeltaX = (mousePosX - mouseOldX); scene.setOnMousePressed(new EventHandler<MouseEvent>() {
mouseDeltaY = (mousePosY - mouseOldY); @Override
public void handle(MouseEvent arg0) {
if (arg0.isPrimaryButtonDown()) { mousePosX = arg0.getSceneX();
affine.appendRotation((-mouseDeltaY % 360) * 0.1f, new Point3D(0, 0, 0), Rotate.X_AXIS); mousePosY = arg0.getSceneY();
affine.appendRotation((mouseDeltaX % 360) * 0.1f, new Point3D(0, 0, 0), Rotate.Y_AXIS); mouseOldX = arg0.getSceneX();
mouseOldY = arg0.getSceneY();
finalCamera.getTransforms().setAll(affine); }
} });
}
}); scene.setOnMouseDragged(new EventHandler<MouseEvent>() {
@Override
} public void handle(MouseEvent arg0) {
mouseOldX = mousePosX;
mouseOldY = mousePosY;
mousePosX = arg0.getSceneX();
mousePosY = arg0.getSceneY();
mouseDeltaX = (mousePosX - mouseOldX);
mouseDeltaY = (mousePosY - mouseOldY);
double modifier = 1.0;
if (arg0.isPrimaryButtonDown()) {
y.setAngle(y.getAngle() - mouseDeltaX);
x.setAngle(x.getAngle() + mouseDeltaY);
}
}
});
// Set the bevaior for mouse scroll events
scene.setOnScroll(new EventHandler<ScrollEvent>() {
@Override
public void handle(ScrollEvent event) {
// Get the current z position and modify it by the amount of
// scrolling
double z = finalCamera.getTranslateZ();
double newZ = z + event.getDeltaY();
finalCamera.setTranslateZ(newZ);
}
});
}
} }
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