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 {
*
*/
private void createDefaultCamera(Group parent) {
PerspectiveCamera perspCamera = new PerspectiveCamera();
PerspectiveCamera perspCamera = new PerspectiveCamera(true);
perspCamera.setNearClip(0.1);
perspCamera.setFarClip(2000.0);
perspCamera.setFarClip(4000.0);
perspCamera.setFieldOfView(35);
perspCamera.setTranslateX(0);
perspCamera.setTranslateY(-100);
perspCamera.setTranslateZ(-1000);
perspCamera.setTranslateY(0);
parent.getChildren().add(perspCamera);
......
......@@ -51,7 +51,7 @@ public class FXCameraAttachment extends CameraAttachment {
super.attach(owner);
if (camera == null) {
camera = new PerspectiveCamera();
camera = new PerspectiveCamera(true);
}
Group fxGroup = Util.getFxGroup(owner);
......
......@@ -19,6 +19,7 @@ import javafx.scene.Scene;
import javafx.scene.input.KeyCode;
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;
import javafx.scene.transform.Transform;
......@@ -112,10 +113,20 @@ public class FPSController extends CameraController {
Rotate y = new Rotate();
y.setAxis(Rotate.Y_AXIS);
affine = new Affine();
camera.getTransforms().setAll(affine);
Rotate z = new Rotate();
z.setAxis(Rotate.Z_AXIS);
final Group camGroup = new Group();
camGroup.getTransforms().setAll(x, y, z);
camGroup.getChildren().add(finalCamera);
finalCamera.setTranslateZ(-2000);
// affine = new Affine();
// camera.getTransforms().setAll(affine);
scene.setOnKeyPressed(new EventHandler<KeyEvent>() {
@Override
public void handle(KeyEvent event) {
double speed = NORMAL_SPEED;
......@@ -140,30 +151,36 @@ public class FPSController extends CameraController {
if (keyCode == KeyCode.W) {
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) {
Point3D moveVec = zDir.multiply(speed);
Point3D invVec = new Point3D(-moveVec.getX(), -moveVec.getY(), -moveVec.getZ());
affine.appendTranslation(invVec.getX(), invVec.getY(), invVec.getZ());
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());
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());
affine.appendTranslation(moveVec.getX(), moveVec.getY(),
moveVec.getZ());
}
finalCamera.getTransforms().setAll(affine);
if (keyCode == KeyCode.SPACE) {
finalCamera.setTranslateY(finalCamera.getTranslateY() - speed);
finalCamera
.setTranslateZ(finalCamera.getTranslateZ() - speed);
} else if (keyCode == KeyCode.C) {
finalCamera.setTranslateY(finalCamera.getTranslateY() + speed);
finalCamera
.setTranslateZ(finalCamera.getTranslateZ() + speed);
}
}
});
scene.setOnMousePressed(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent arg0) {
mousePosX = arg0.getSceneX();
mousePosY = arg0.getSceneY();
......@@ -173,6 +190,7 @@ public class FPSController extends CameraController {
});
scene.setOnMouseDragged(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent arg0) {
mouseOldX = mousePosX;
mouseOldY = mousePosY;
......@@ -181,13 +199,30 @@ public class FPSController extends CameraController {
mouseDeltaX = (mousePosX - mouseOldX);
mouseDeltaY = (mousePosY - mouseOldY);
if (arg0.isPrimaryButtonDown()) {
affine.appendRotation((-mouseDeltaY % 360) * 0.1f, new Point3D(0, 0, 0), Rotate.X_AXIS);
affine.appendRotation((mouseDeltaX % 360) * 0.1f, new Point3D(0, 0, 0), Rotate.Y_AXIS);
double modifier = 1.0;
finalCamera.getTransforms().setAll(affine);
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