My goal is a game played with dice. I am using javafx.
First question: Is there an easy way to customize the 3d box in javafx. It doesn't matter to me, if I have to add an image to every side of the die or if I use just one image which wraps around the box. (After lots of research I didn't find anything about it.)
In the code below I created a stackpane, which is a 3d cube. It is build from 6 Rectangles, each of the is filled with one side of a die (1 to 6). If I rotate the stackpane by 180 degrees, the Rectangle which should be in the foreground is in the background and the one which was before in front is visible again.
Second question: How to fix this?
Or is there a better way to realize that? First I was thinking about using TriangleMesh, but it seemd to be as complicated as my version.
@FXML
private StackPane stack;
@Override
public void initialize(URL url, ResourceBundle rb) {
...
//other code
for (int i = 1; i < 7; i++){
Rectangle rt = getRectangle(i);
rt.setSmooth(true);
stack.getChildren().add(rt);
switch(i) {
case 1:
rt.setTranslateZ(100);
break;
case 2:
rt.getTransforms().add(new Rotate(270, 50,50,0,Rotate.X_AXIS));
rt.setTranslateZ(100*0.5);
rt.setHeight(100);
rt.setTranslateY(100*0.5);
break;
case 3:
rt.setTranslateZ(100*0.5);
rt.getTransforms().add(new Rotate(90, 50, 50, 0, Rotate.Y_AXIS));
rt.setWidth(100);
rt.setTranslateX(-(100*0.5-1));
break;
case 4:
rt.setTranslateZ(100*0.5);
rt.getTransforms().add(new Rotate(90,50,50,0,Rotate.Y_AXIS));
rt.setWidth(100);
rt.setTranslateX(100*0.5);
break;
case 5:
rt.setTranslateZ(100*0.5);
rt.setTranslateY(-(100*0.5));
rt.getTransforms().add(new Rotate(270,50,50,0, Rotate.X_AXIS));
rt.setHeight(100);
break;
case 6:
rt.setTranslateZ(0);
break;
}
private Rectangle getRectangle(int number){
Rectangle rt = new Rectangle(100, 100);
rt.setFill(new ImagePattern(loadImage(number)));
return rt;
}