1
プロジェクトRybiのキューブゲームで作業するには、特定の軸を中心にキューブを回転させる必要があります。 X軸が90度回転しているので、再びX軸回りに回すと、X軸がZの回転をとるので、回転はZ軸の方向になります。JavaFX:軸を回転させずにオブジェクトを回転する
以下、私があなたを紹介するのと同じ状況。
は、物事私はあなたが単に(inverseDeltaTransform
を使用して)軸に逆変換を適用することができ
public class RybiCube extends Application {
final Group root = new Group();
final PerspectiveCamera camera = new PerspectiveCamera(true);
final XformCamera cameraXform = new XformCamera();
public static final double CAMERA_INITIAL_DISTANCE = -1000;
public static final double CAMERA_NEAR_CLIP = 0.1;
public static final double CAMERA_FAR_CLIP = 10000.0;
public void init(Stage primaryStage) {
Box box = new Box();
box.setHeight(70);
box.setWidth(200);
box.setDepth(70);
//box.setRotationAxis(Rotate.Y_AXIS);
//box.setRotate(80);
box.getTransforms().add(new Rotate(90,Rotate.Y_AXIS));
box.getTransforms().add(new Rotate(45,Rotate.X_AXIS));
PhongMaterial material = new PhongMaterial();
material.setDiffuseColor(Color.ORANGE);
material.setSpecularColor(Color.BLACK);
box.setMaterial(material);
root.getChildren().add(box);
buildCamera();
Scene scene = new Scene(root, 600, 600, true);
primaryStage.setScene(scene);
scene.setCamera(camera);
///
primaryStage.setResizable(false);
scene.setFill(Color.rgb(0, 0,0,0.5));
primaryStage.setScene(scene);
}
private void buildCamera() {
root.getChildren().add(cameraXform);
cameraXform.getChildren().add(camera);
camera.setNearClip(CAMERA_NEAR_CLIP);
camera.setFarClip(CAMERA_FAR_CLIP);
camera.setTranslateZ(CAMERA_INITIAL_DISTANCE);
}
public void start(Stage primaryStage)
{
init(primaryStage);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
class XformCamera extends Group {
final Translate tr = new Translate(0.0, 0.0, 0.0);
final Rotate rx = new Rotate(00, Rotate.X_AXIS);
final Rotate ry = new Rotate(10, Rotate.Y_AXIS);
final Rotate rz = new Rotate(0, Rotate.Z_AXIS);
public XformCamera() {
super();
this.getTransforms().addAll(tr, rx, ry, rz);
}
}
おかげで、あなたは私の人生を救った、それは解決される。 –