use of javafx.geometry.Point3D in project FXyzLib by Birdasaur.
the class Drag3DObject method loadControls.
private void loadControls(Scene scene) {
//First person shooter keyboard movement
scene.setOnKeyPressed(event -> {
double change = 10.0;
if (event.isShiftDown()) {
change = 50.0;
}
KeyCode keycode = event.getCode();
if (keycode == KeyCode.W) {
camera.setTranslateZ(camera.getTranslateZ() + change);
}
if (keycode == KeyCode.S) {
camera.setTranslateZ(camera.getTranslateZ() - change);
}
if (keycode == KeyCode.A) {
camera.setTranslateX(camera.getTranslateX() - change);
}
if (keycode == KeyCode.D) {
camera.setTranslateX(camera.getTranslateX() + change);
}
});
scene.setOnMousePressed((MouseEvent me) -> {
mousePosX = me.getSceneX();
mousePosY = me.getSceneY();
mouseOldX = me.getSceneX();
mouseOldY = me.getSceneY();
PickResult pr = me.getPickResult();
if (pr != null && pr.getIntersectedNode() != null && pr.getIntersectedNode() instanceof Sphere) {
distance = pr.getIntersectedDistance();
s = (Sphere) pr.getIntersectedNode();
isPicking = true;
vecIni = unProjectDirection(mousePosX, mousePosY, scene.getWidth(), scene.getHeight());
}
});
scene.setOnMouseDragged((MouseEvent me) -> {
mouseOldX = mousePosX;
mouseOldY = mousePosY;
mousePosX = me.getSceneX();
mousePosY = me.getSceneY();
mouseDeltaX = (mousePosX - mouseOldX);
mouseDeltaY = (mousePosY - mouseOldY);
if (RUN_JASON) {
//objPos += mouseMovementx*scale*RightAxis
if (isPicking) {
if (mousePosX < mouseOldX) {
System.out.println("moving left");
Point3D pos = CameraHelper.pickProjectPlane(camera, mousePosX, mousePosY);
s.setTranslateX(s.getTranslateX() + (pos.getX() - mouseOldX) * camera.getNearClip());
return;
} else if (mousePosX > mouseOldX) {
System.err.println("moving right");
Point3D pos = CameraHelper.pickProjectPlane(camera, mousePosX, mousePosY);
s.setTranslateX(s.getTranslateX() - (pos.getX() - mouseOldX) * camera.getNearClip());
return;
}
if (mousePosY < mouseOldY) {
System.out.println("moving up");
} else if (mousePosY > mouseOldY) {
System.err.println("moving down");
}
return;
}
} else {
if (isPicking) {
double modifier = (me.isControlDown() ? 0.2 : me.isAltDown() ? 2.0 : 1) * (30d / camera.getFieldOfView());
modifier *= (30d / camera.getFieldOfView());
vecPos = unProjectDirection(mousePosX, mousePosY, scene.getWidth(), scene.getHeight());
Point3D p = new Point3D(distance * (vecPos.x - vecIni.x), distance * (vecPos.y - vecIni.y), distance * (vecPos.z - vecIni.z));
s.getTransforms().add(new Translate(modifier * p.getX(), 0, modifier * p.getZ()));
vecIni = vecPos;
} else {
double modifier = 10.0;
double modifierFactor = 0.1;
if (me.isControlDown()) {
modifier = 0.1;
}
if (me.isShiftDown()) {
modifier = 50.0;
}
if (me.isPrimaryButtonDown()) {
// +
cameraTransform.ry.setAngle(((cameraTransform.ry.getAngle() + mouseDeltaX * modifierFactor * modifier * 2.0) % 360 + 540) % 360 - 180);
// -
cameraTransform.rx.setAngle(((cameraTransform.rx.getAngle() - mouseDeltaY * modifierFactor * modifier * 2.0) % 360 + 540) % 360 - 180);
} else if (me.isSecondaryButtonDown()) {
double z = camera.getTranslateZ();
double newZ = z + mouseDeltaX * modifierFactor * modifier;
camera.setTranslateZ(newZ);
} else if (me.isMiddleButtonDown()) {
// -
cameraTransform.t.setX(cameraTransform.t.getX() + mouseDeltaX * modifierFactor * modifier * 0.3);
// -
cameraTransform.t.setY(cameraTransform.t.getY() + mouseDeltaY * modifierFactor * modifier * 0.3);
}
}
}
});
scene.setOnMouseReleased((MouseEvent me) -> {
if (isPicking) {
isPicking = false;
}
});
}
use of javafx.geometry.Point3D in project FXyzLib by Birdasaur.
the class Drag3DObject method localToScene.
public Vec3d localToScene(Vec3d pt, Vec3d result) {
Point3D res = camera.localToParentTransformProperty().get().transform(pt.x, pt.y, pt.z);
if (camera.getParent() != null) {
res = camera.getParent().localToSceneTransformProperty().get().transform(res);
}
result.set(res.getX(), res.getY(), res.getZ());
return result;
}
use of javafx.geometry.Point3D in project FXyzLib by Birdasaur.
the class MeshUtils method mesh2STL.
public static void mesh2STL(String fileName, Mesh mesh) throws IOException {
if (!(mesh instanceof TriangleMesh)) {
return;
}
// Get faces
ObservableFaceArray faces = ((TriangleMesh) mesh).getFaces();
int[] f = new int[faces.size()];
faces.toArray(f);
// Get vertices
ObservableFloatArray points = ((TriangleMesh) mesh).getPoints();
float[] p = new float[points.size()];
points.toArray(p);
StringBuilder sb = new StringBuilder();
sb.append("solid meshFX\n");
// convert faces to polygons
for (int i = 0; i < faces.size() / 6; i++) {
int i0 = f[6 * i], i1 = f[6 * i + 2], i2 = f[6 * i + 4];
Point3D pA = new Point3D(p[3 * i0], p[3 * i0 + 1], p[3 * i0 + 2]);
Point3D pB = new Point3D(p[3 * i1], p[3 * i1 + 1], p[3 * i1 + 2]);
Point3D pC = new Point3D(p[3 * i2], p[3 * i2 + 1], p[3 * i2 + 2]);
Point3D pN = pB.subtract(pA).crossProduct(pC.subtract(pA)).normalize();
sb.append(" facet normal ").append(pN.getX()).append(" ").append(pN.getY()).append(" ").append(pN.getZ()).append("\n");
sb.append(" outer loop\n");
sb.append(" vertex ").append(pA.getX()).append(" ").append(pA.getY()).append(" ").append(pA.getZ()).append("\n");
sb.append(" vertex ").append(pB.getX()).append(" ").append(pB.getY()).append(" ").append(pB.getZ()).append("\n");
sb.append(" vertex ").append(pC.getX()).append(" ").append(pC.getY()).append(" ").append(pC.getZ()).append("\n");
sb.append(" endloop\n");
sb.append(" endfacet\n");
}
sb.append("endsolid meshFX\n");
// write file
try (BufferedWriter writer = Files.newBufferedWriter(Paths.get(fileName), Charset.forName("UTF-8"), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) {
writer.write(sb.toString());
}
}
use of javafx.geometry.Point3D in project Minesweeper3D by SethDamiani.
the class Main method createCube.
private void createCube(Group cubeGroup, Group gX, Group gY, Scene scene, Stage stage) {
cubeGroup.setTranslateZ(-200);
sideB.setTranslateX(200);
sideB.setTranslateZ(200);
sideB.setRotationAxis(new Point3D(0, 1, 0));
sideB.setRotate(90);
sideC.setTranslateZ(200);
sideC.setTranslateX(-200);
sideC.setRotationAxis(new Point3D(0, 1, 0));
sideC.setRotate(90);
sideD.setTranslateZ(400);
sideE.setRotationAxis(new Point3D(1, 0, 0));
sideE.setRotate(90);
sideE.setTranslateY(200);
sideE.setTranslateZ(200);
sideF.setRotationAxis(new Point3D(1, 0, 0));
sideF.setRotate(90);
sideF.setTranslateY(-200);
sideF.setTranslateZ(200);
RotateTransition rightRotate = new RotateTransition(Duration.millis(10000), gY);
rightRotate.setAxis(Rotate.Y_AXIS);
rightRotate.setByAngle(-1000);
rightRotate.setInterpolator(Interpolator.LINEAR);
RotateTransition leftRotate = new RotateTransition(Duration.millis(10000), gY);
leftRotate.setAxis(Rotate.Y_AXIS);
leftRotate.setByAngle(1000);
leftRotate.setInterpolator(Interpolator.LINEAR);
RotateTransition upRotate = new RotateTransition(Duration.millis(10000), gX);
upRotate.setAxis(Rotate.X_AXIS);
upRotate.setByAngle(-1000);
upRotate.setInterpolator(Interpolator.LINEAR);
RotateTransition downRotate = new RotateTransition(Duration.millis(10000), gX);
downRotate.setAxis(Rotate.X_AXIS);
downRotate.setByAngle(1000);
downRotate.setInterpolator(Interpolator.LINEAR);
EventHandler<KeyEvent> KeyPressHandler = event -> {
if (event.getCode() == KeyCode.ESCAPE) {
timeTask.pause();
stage.setScene(confirmExit);
} else if (event.getCode() == KeyCode.D || event.getCode() == KeyCode.RIGHT)
rightRotate.play();
else if (event.getCode() == KeyCode.A || event.getCode() == KeyCode.LEFT)
leftRotate.play();
else if (event.getCode() == KeyCode.W || event.getCode() == KeyCode.UP)
upRotate.play();
else if (event.getCode() == KeyCode.S || event.getCode() == KeyCode.DOWN)
downRotate.play();
};
scene.addEventHandler(KeyEvent.KEY_PRESSED, KeyPressHandler);
EventHandler<KeyEvent> KeyReleaseHandler = event -> {
if (event.getCode() == KeyCode.D || event.getCode() == KeyCode.RIGHT)
rightRotate.stop();
else if (event.getCode() == KeyCode.A || event.getCode() == KeyCode.LEFT)
leftRotate.stop();
else if (event.getCode() == KeyCode.W || event.getCode() == KeyCode.UP)
upRotate.stop();
else if (event.getCode() == KeyCode.S || event.getCode() == KeyCode.DOWN)
downRotate.stop();
};
scene.addEventHandler(KeyEvent.KEY_RELEASED, KeyReleaseHandler);
}
use of javafx.geometry.Point3D in project Gargoyle by callakrsos.
the class Drag3DObject method localToScene.
public Vec3d localToScene(Vec3d pt, Vec3d result) {
Point3D res = camera.localToParentTransformProperty().get().transform(pt.x, pt.y, pt.z);
if (camera.getParent() != null) {
res = camera.getParent().localToSceneTransformProperty().get().transform(res);
}
result.set(res.getX(), res.getY(), res.getZ());
return result;
}
Aggregations