Javafx 如何按三维对象的边而不是中心旋转三维对象
我想弄清楚轴点在3D中是如何工作的。我试图使一个三维长方体在长方体的边缘而不是在中心旋转。任何帮助都将不胜感激。谢谢 您可以对长方体应用旋转变换,因为它允许设置角度、轴心点和旋转轴。看 这将在长方体的中心应用变换:Javafx 如何按三维对象的边而不是中心旋转三维对象,javafx,3d,pivot,javafx-3d,Javafx,3d,Pivot,Javafx 3d,我想弄清楚轴点在3D中是如何工作的。我试图使一个三维长方体在长方体的边缘而不是在中心旋转。任何帮助都将不胜感激。谢谢 您可以对长方体应用旋转变换,因为它允许设置角度、轴心点和旋转轴。看 这将在长方体的中心应用变换: Rotate rotate = new Rotate(0, 0, 0, 0, Rotate.Z_AXIS); Box box = new Box(100, 100, 100); box.getTransforms().add(rotate); 虽然这将应用于其中一个边缘: Rot
Rotate rotate = new Rotate(0, 0, 0, 0, Rotate.Z_AXIS);
Box box = new Box(100, 100, 100);
box.getTransforms().add(rotate);
虽然这将应用于其中一个边缘:
Rotate rotate = new Rotate(0, -50, -50, 0, Rotate.Z_AXIS);
Box box = new Box(100, 100, 100);
box.getTransforms().add(rotate);
这是一个具有两种情况动画的快速测试:
private long time;
private final IntegerProperty counter = new SimpleIntegerProperty();
@Override
public void start(Stage primaryStage) {
Rotate rotate1 = new Rotate(0, 0, 0, 0, Rotate.Z_AXIS);
rotate1.angleProperty().bind(counter);
Box box1 = new Box(100, 100, 100);
box1.setMaterial(new PhongMaterial(Color.LIMEGREEN));
box1.getTransforms().add(rotate1);
Cylinder axis1 = new Cylinder(2, 200);
axis1.setRotationAxis(Rotate.X_AXIS);
axis1.setRotate(90);
axis1.setMaterial(new PhongMaterial(Color.RED));
Group group1 = new Group(box1, axis1);
group1.setTranslateX(-100);
Rotate rotate2 = new Rotate(0, -50, -50, 0, Rotate.Z_AXIS);
rotate2.angleProperty().bind(counter);
Box box2 = new Box(100, 100, 100);
box2.setMaterial(new PhongMaterial(Color.LAVENDER));
box2.getTransforms().add(rotate2);
Cylinder axis2 = new Cylinder(2, 200);
axis2.setRotationAxis(Rotate.X_AXIS);
axis2.setRotate(90);
axis2.setTranslateX(-50);
axis2.setTranslateY(-50);
axis2.setMaterial(new PhongMaterial(Color.RED));
Group group2 = new Group(box2, axis2);
group2.setTranslateX(200);
Group root = new Group(group1, group2);
SubScene subScene = new SubScene(root, 600, 400, true, SceneAntialiasing.BALANCED);
PerspectiveCamera camera = new PerspectiveCamera();
camera.setTranslateX(-200);
camera.setTranslateY(-200);
camera.setTranslateZ(-100);
camera.setRotationAxis(new Point3D(0, 0.5, 0.5));
camera.setRotate(10);
subScene.setCamera(camera);
Scene scene = new Scene(new StackPane(subScene), 600, 400, true, SceneAntialiasing.BALANCED);
primaryStage.setScene(scene);
primaryStage.show();
AnimationTimer timer = new AnimationTimer() {
@Override
public void handle(long now) {
if (now - time > 30_000_000) {
counter.set((counter.get() + 1) % 360);
time = now;
}
}
};
timer.start();
}
伙计,谢谢你。那些红线确实让事情变得更清楚了。谢谢你!!很高兴它帮助了你。考虑把答案标记为被接受,这样对其他人也会有帮助。