Cube rotate in Javafx












0















I have a question about rotation in javafx. To be specific "RotateTransition"
For now i made cube 2x2 thanks to http://stackoverflow.com/questions/34001900/how-to-render-3d-graphics-properly. Somehow i need to start rotating cube not the scene as i do it now. So here is the probem. How can i change it to move faces of the cube not the scene around the cube ?
Here is how it looks now : Cube rotation



Here is the code :



public class RubiksCube extends Application {

public static final int RED = 0;
public static final int GREEN = 1;
public static final int BLUE = 2;
public static final int YELLOW = 3;
public static final int ORANGE = 4;
public static final int WHITE = 5;
public static final int GRAY = 6;

public static final float X_RED = 0.5f / 7f;
public static final float X_GREEN = 1.5f / 7f;
public static final float X_BLUE = 2.5f / 7f;
public static final float X_YELLOW = 3.5f / 7f;
public static final float X_ORANGE = 4.5f / 7f;
public static final float X_WHITE = 5.5f / 7f;
public static final float X_GRAY = 6.5f / 7f;

private double mousePosX;
private double mousePosY;
private double mouseOldX;
private double mouseOldY;

@FXML
Scene scene;

@SuppressWarnings("unused")
@Override
public void start(Stage primaryStage) throws IOException {

Group root = new Group();
Parent dupa = FXMLLoader.load(getClass().getResource("Design.fxml"));
Scene scene = new Scene(root, 600, 600, true, SceneAntialiasing.BALANCED);
scene.setFill(Color.BLACK);
PerspectiveCamera camera = new PerspectiveCamera(true);
camera.setNearClip(0.1);
camera.setFarClip(10000.0);
camera.setTranslateZ(-10);
scene.setCamera(camera);

PhongMaterial mat = new PhongMaterial();
// image can be found here http://i.stack.imgur.com/uN4dv.png
mat.setDiffuseMap(new Image(getClass().getResourceAsStream("palette.png")));

Group meshGroup = new Group();

AtomicInteger cont = new AtomicInteger();
patternFaceF.forEach(p -> {
MeshView meshP = new MeshView();
meshP.setMesh(createCube(p));
meshP.setMaterial(mat);
Point3D pt = pointsFaceF.get(cont.getAndIncrement());
meshP.getTransforms().addAll(new Translate(pt.getX(), pt.getY(), pt.getZ()));
meshGroup.getChildren().add(meshP);
});

Rotate rotateX = new Rotate(30, 0, 0, 0, Rotate.X_AXIS);
Rotate rotateY = new Rotate(20, 0, 0, 0, Rotate.Y_AXIS);
meshGroup.getTransforms().addAll(rotateX, rotateY);

root.getChildren().addAll(meshGroup, new AmbientLight(Color.WHITE));

scene.setOnMousePressed(me -> {
mouseOldX = me.getSceneX();
mouseOldY = me.getSceneY();
});
scene.setOnMouseDragged(me -> {
mousePosX = me.getSceneX();
mousePosY = me.getSceneY();
rotateX.setAngle(rotateX.getAngle()-(mousePosY - mouseOldY));
rotateY.setAngle(rotateY.getAngle()+(mousePosX - mouseOldX));
mouseOldX = mousePosX;
mouseOldY = mousePosY;
});

primaryStage.setTitle("Simple Rubik's Cube - JavaFX");
primaryStage.setScene(scene);
primaryStage.show();
}
// F R U B L D
private static final int FLD = new int{BLUE, GRAY, GRAY, GRAY, ORANGE, WHITE};
private static final int FRD = new int{BLUE, RED, GRAY, GRAY, GRAY, WHITE};
private static final int FLU = new int{BLUE, GRAY, YELLOW, GRAY, ORANGE, GRAY};
private static final int FRU = new int{BLUE, RED, YELLOW, GRAY, GRAY, GRAY};

private static final Point3D pFLD = new Point3D(-0.55, 0.55, -0.55);
private static final Point3D pFRD = new Point3D( 0.55, 0.55, -0.55);
private static final Point3D pFLU = new Point3D(-0.55, -0.55, -0.55);
private static final Point3D pFRU = new Point3D( 0.55, -0.55, -0.55);

private static final int BLD = new int{GRAY, GRAY, GRAY, GREEN, ORANGE, WHITE};
private static final int BRD = new int{GRAY, RED, GRAY, GREEN, GRAY, WHITE};
private static final int BLU = new int{GRAY, GRAY, YELLOW, GREEN, ORANGE, GRAY};
private static final int BRU = new int{GRAY, RED, YELLOW, GREEN, GRAY, GRAY};

private static final Point3D pBLD = new Point3D(-0.55, 0.55, 0.55);
private static final Point3D pBRD = new Point3D( 0.55, 0.55, 0.55);
private static final Point3D pBLU = new Point3D(-0.55, -0.55, 0.55);
private static final Point3D pBRU = new Point3D( 0.55, -0.55, 0.55);

private static final List<int> patternFaceF = Arrays.asList(
FLD, FRD, FLU, FRU,
BLD, BRD, BLU, BRU);

private static final List<Point3D> pointsFaceF = Arrays.asList(
pFLD, pFRD, pFLU, pFRU,
pBLD, pBRD, pBLU, pBRU);

private TriangleMesh createCube(int face) {
TriangleMesh m = new TriangleMesh();

// POINTS
m.getPoints().addAll(
0.5f, 0.5f, 0.5f,
0.5f, -0.5f, 0.5f,
0.5f, 0.5f, -0.5f,
0.5f, -0.5f, -0.5f,
-0.5f, 0.5f, 0.5f,
-0.5f, -0.5f, 0.5f,
-0.5f, 0.5f, -0.5f,
-0.5f, -0.5f, -0.5f
);

// TEXTURES
m.getTexCoords().addAll(
X_RED, 0.5f,
X_GREEN, 0.5f,
X_BLUE, 0.5f,
X_YELLOW, 0.5f,
X_ORANGE, 0.5f,
X_WHITE, 0.5f,
X_GRAY, 0.5f
);

// FACES
m.getFaces().addAll(
2,face[0],3,face[0],6,face[0], // F
3,face[0],7,face[0],6,face[0],

0,face[1],1,face[1],2,face[1], // R
2,face[1],1,face[1],3,face[1],

1,face[2],5,face[2],3,face[2], // U
5,face[2],7,face[2],3,face[2],

0,face[3],4,face[3],1,face[3], // B
4,face[3],5,face[3],1,face[3],

4,face[4],6,face[4],5,face[4], // L
6,face[4],7,face[4],5,face[4],

0,face[5],2,face[5],4,face[5], // D
2,face[5],6,face[5],4,face[5]
);
return m;
}

public static void main(String args) {
launch(args);
}

}









share|improve this question

























  • Rotating individual faces in this very simplified model can be really challenging. I'd suggest you have a look at this link and this one for a more complex version.

    – José Pereda
    Nov 21 '18 at 20:56
















0















I have a question about rotation in javafx. To be specific "RotateTransition"
For now i made cube 2x2 thanks to http://stackoverflow.com/questions/34001900/how-to-render-3d-graphics-properly. Somehow i need to start rotating cube not the scene as i do it now. So here is the probem. How can i change it to move faces of the cube not the scene around the cube ?
Here is how it looks now : Cube rotation



Here is the code :



public class RubiksCube extends Application {

public static final int RED = 0;
public static final int GREEN = 1;
public static final int BLUE = 2;
public static final int YELLOW = 3;
public static final int ORANGE = 4;
public static final int WHITE = 5;
public static final int GRAY = 6;

public static final float X_RED = 0.5f / 7f;
public static final float X_GREEN = 1.5f / 7f;
public static final float X_BLUE = 2.5f / 7f;
public static final float X_YELLOW = 3.5f / 7f;
public static final float X_ORANGE = 4.5f / 7f;
public static final float X_WHITE = 5.5f / 7f;
public static final float X_GRAY = 6.5f / 7f;

private double mousePosX;
private double mousePosY;
private double mouseOldX;
private double mouseOldY;

@FXML
Scene scene;

@SuppressWarnings("unused")
@Override
public void start(Stage primaryStage) throws IOException {

Group root = new Group();
Parent dupa = FXMLLoader.load(getClass().getResource("Design.fxml"));
Scene scene = new Scene(root, 600, 600, true, SceneAntialiasing.BALANCED);
scene.setFill(Color.BLACK);
PerspectiveCamera camera = new PerspectiveCamera(true);
camera.setNearClip(0.1);
camera.setFarClip(10000.0);
camera.setTranslateZ(-10);
scene.setCamera(camera);

PhongMaterial mat = new PhongMaterial();
// image can be found here http://i.stack.imgur.com/uN4dv.png
mat.setDiffuseMap(new Image(getClass().getResourceAsStream("palette.png")));

Group meshGroup = new Group();

AtomicInteger cont = new AtomicInteger();
patternFaceF.forEach(p -> {
MeshView meshP = new MeshView();
meshP.setMesh(createCube(p));
meshP.setMaterial(mat);
Point3D pt = pointsFaceF.get(cont.getAndIncrement());
meshP.getTransforms().addAll(new Translate(pt.getX(), pt.getY(), pt.getZ()));
meshGroup.getChildren().add(meshP);
});

Rotate rotateX = new Rotate(30, 0, 0, 0, Rotate.X_AXIS);
Rotate rotateY = new Rotate(20, 0, 0, 0, Rotate.Y_AXIS);
meshGroup.getTransforms().addAll(rotateX, rotateY);

root.getChildren().addAll(meshGroup, new AmbientLight(Color.WHITE));

scene.setOnMousePressed(me -> {
mouseOldX = me.getSceneX();
mouseOldY = me.getSceneY();
});
scene.setOnMouseDragged(me -> {
mousePosX = me.getSceneX();
mousePosY = me.getSceneY();
rotateX.setAngle(rotateX.getAngle()-(mousePosY - mouseOldY));
rotateY.setAngle(rotateY.getAngle()+(mousePosX - mouseOldX));
mouseOldX = mousePosX;
mouseOldY = mousePosY;
});

primaryStage.setTitle("Simple Rubik's Cube - JavaFX");
primaryStage.setScene(scene);
primaryStage.show();
}
// F R U B L D
private static final int FLD = new int{BLUE, GRAY, GRAY, GRAY, ORANGE, WHITE};
private static final int FRD = new int{BLUE, RED, GRAY, GRAY, GRAY, WHITE};
private static final int FLU = new int{BLUE, GRAY, YELLOW, GRAY, ORANGE, GRAY};
private static final int FRU = new int{BLUE, RED, YELLOW, GRAY, GRAY, GRAY};

private static final Point3D pFLD = new Point3D(-0.55, 0.55, -0.55);
private static final Point3D pFRD = new Point3D( 0.55, 0.55, -0.55);
private static final Point3D pFLU = new Point3D(-0.55, -0.55, -0.55);
private static final Point3D pFRU = new Point3D( 0.55, -0.55, -0.55);

private static final int BLD = new int{GRAY, GRAY, GRAY, GREEN, ORANGE, WHITE};
private static final int BRD = new int{GRAY, RED, GRAY, GREEN, GRAY, WHITE};
private static final int BLU = new int{GRAY, GRAY, YELLOW, GREEN, ORANGE, GRAY};
private static final int BRU = new int{GRAY, RED, YELLOW, GREEN, GRAY, GRAY};

private static final Point3D pBLD = new Point3D(-0.55, 0.55, 0.55);
private static final Point3D pBRD = new Point3D( 0.55, 0.55, 0.55);
private static final Point3D pBLU = new Point3D(-0.55, -0.55, 0.55);
private static final Point3D pBRU = new Point3D( 0.55, -0.55, 0.55);

private static final List<int> patternFaceF = Arrays.asList(
FLD, FRD, FLU, FRU,
BLD, BRD, BLU, BRU);

private static final List<Point3D> pointsFaceF = Arrays.asList(
pFLD, pFRD, pFLU, pFRU,
pBLD, pBRD, pBLU, pBRU);

private TriangleMesh createCube(int face) {
TriangleMesh m = new TriangleMesh();

// POINTS
m.getPoints().addAll(
0.5f, 0.5f, 0.5f,
0.5f, -0.5f, 0.5f,
0.5f, 0.5f, -0.5f,
0.5f, -0.5f, -0.5f,
-0.5f, 0.5f, 0.5f,
-0.5f, -0.5f, 0.5f,
-0.5f, 0.5f, -0.5f,
-0.5f, -0.5f, -0.5f
);

// TEXTURES
m.getTexCoords().addAll(
X_RED, 0.5f,
X_GREEN, 0.5f,
X_BLUE, 0.5f,
X_YELLOW, 0.5f,
X_ORANGE, 0.5f,
X_WHITE, 0.5f,
X_GRAY, 0.5f
);

// FACES
m.getFaces().addAll(
2,face[0],3,face[0],6,face[0], // F
3,face[0],7,face[0],6,face[0],

0,face[1],1,face[1],2,face[1], // R
2,face[1],1,face[1],3,face[1],

1,face[2],5,face[2],3,face[2], // U
5,face[2],7,face[2],3,face[2],

0,face[3],4,face[3],1,face[3], // B
4,face[3],5,face[3],1,face[3],

4,face[4],6,face[4],5,face[4], // L
6,face[4],7,face[4],5,face[4],

0,face[5],2,face[5],4,face[5], // D
2,face[5],6,face[5],4,face[5]
);
return m;
}

public static void main(String args) {
launch(args);
}

}









share|improve this question

























  • Rotating individual faces in this very simplified model can be really challenging. I'd suggest you have a look at this link and this one for a more complex version.

    – José Pereda
    Nov 21 '18 at 20:56














0












0








0


0






I have a question about rotation in javafx. To be specific "RotateTransition"
For now i made cube 2x2 thanks to http://stackoverflow.com/questions/34001900/how-to-render-3d-graphics-properly. Somehow i need to start rotating cube not the scene as i do it now. So here is the probem. How can i change it to move faces of the cube not the scene around the cube ?
Here is how it looks now : Cube rotation



Here is the code :



public class RubiksCube extends Application {

public static final int RED = 0;
public static final int GREEN = 1;
public static final int BLUE = 2;
public static final int YELLOW = 3;
public static final int ORANGE = 4;
public static final int WHITE = 5;
public static final int GRAY = 6;

public static final float X_RED = 0.5f / 7f;
public static final float X_GREEN = 1.5f / 7f;
public static final float X_BLUE = 2.5f / 7f;
public static final float X_YELLOW = 3.5f / 7f;
public static final float X_ORANGE = 4.5f / 7f;
public static final float X_WHITE = 5.5f / 7f;
public static final float X_GRAY = 6.5f / 7f;

private double mousePosX;
private double mousePosY;
private double mouseOldX;
private double mouseOldY;

@FXML
Scene scene;

@SuppressWarnings("unused")
@Override
public void start(Stage primaryStage) throws IOException {

Group root = new Group();
Parent dupa = FXMLLoader.load(getClass().getResource("Design.fxml"));
Scene scene = new Scene(root, 600, 600, true, SceneAntialiasing.BALANCED);
scene.setFill(Color.BLACK);
PerspectiveCamera camera = new PerspectiveCamera(true);
camera.setNearClip(0.1);
camera.setFarClip(10000.0);
camera.setTranslateZ(-10);
scene.setCamera(camera);

PhongMaterial mat = new PhongMaterial();
// image can be found here http://i.stack.imgur.com/uN4dv.png
mat.setDiffuseMap(new Image(getClass().getResourceAsStream("palette.png")));

Group meshGroup = new Group();

AtomicInteger cont = new AtomicInteger();
patternFaceF.forEach(p -> {
MeshView meshP = new MeshView();
meshP.setMesh(createCube(p));
meshP.setMaterial(mat);
Point3D pt = pointsFaceF.get(cont.getAndIncrement());
meshP.getTransforms().addAll(new Translate(pt.getX(), pt.getY(), pt.getZ()));
meshGroup.getChildren().add(meshP);
});

Rotate rotateX = new Rotate(30, 0, 0, 0, Rotate.X_AXIS);
Rotate rotateY = new Rotate(20, 0, 0, 0, Rotate.Y_AXIS);
meshGroup.getTransforms().addAll(rotateX, rotateY);

root.getChildren().addAll(meshGroup, new AmbientLight(Color.WHITE));

scene.setOnMousePressed(me -> {
mouseOldX = me.getSceneX();
mouseOldY = me.getSceneY();
});
scene.setOnMouseDragged(me -> {
mousePosX = me.getSceneX();
mousePosY = me.getSceneY();
rotateX.setAngle(rotateX.getAngle()-(mousePosY - mouseOldY));
rotateY.setAngle(rotateY.getAngle()+(mousePosX - mouseOldX));
mouseOldX = mousePosX;
mouseOldY = mousePosY;
});

primaryStage.setTitle("Simple Rubik's Cube - JavaFX");
primaryStage.setScene(scene);
primaryStage.show();
}
// F R U B L D
private static final int FLD = new int{BLUE, GRAY, GRAY, GRAY, ORANGE, WHITE};
private static final int FRD = new int{BLUE, RED, GRAY, GRAY, GRAY, WHITE};
private static final int FLU = new int{BLUE, GRAY, YELLOW, GRAY, ORANGE, GRAY};
private static final int FRU = new int{BLUE, RED, YELLOW, GRAY, GRAY, GRAY};

private static final Point3D pFLD = new Point3D(-0.55, 0.55, -0.55);
private static final Point3D pFRD = new Point3D( 0.55, 0.55, -0.55);
private static final Point3D pFLU = new Point3D(-0.55, -0.55, -0.55);
private static final Point3D pFRU = new Point3D( 0.55, -0.55, -0.55);

private static final int BLD = new int{GRAY, GRAY, GRAY, GREEN, ORANGE, WHITE};
private static final int BRD = new int{GRAY, RED, GRAY, GREEN, GRAY, WHITE};
private static final int BLU = new int{GRAY, GRAY, YELLOW, GREEN, ORANGE, GRAY};
private static final int BRU = new int{GRAY, RED, YELLOW, GREEN, GRAY, GRAY};

private static final Point3D pBLD = new Point3D(-0.55, 0.55, 0.55);
private static final Point3D pBRD = new Point3D( 0.55, 0.55, 0.55);
private static final Point3D pBLU = new Point3D(-0.55, -0.55, 0.55);
private static final Point3D pBRU = new Point3D( 0.55, -0.55, 0.55);

private static final List<int> patternFaceF = Arrays.asList(
FLD, FRD, FLU, FRU,
BLD, BRD, BLU, BRU);

private static final List<Point3D> pointsFaceF = Arrays.asList(
pFLD, pFRD, pFLU, pFRU,
pBLD, pBRD, pBLU, pBRU);

private TriangleMesh createCube(int face) {
TriangleMesh m = new TriangleMesh();

// POINTS
m.getPoints().addAll(
0.5f, 0.5f, 0.5f,
0.5f, -0.5f, 0.5f,
0.5f, 0.5f, -0.5f,
0.5f, -0.5f, -0.5f,
-0.5f, 0.5f, 0.5f,
-0.5f, -0.5f, 0.5f,
-0.5f, 0.5f, -0.5f,
-0.5f, -0.5f, -0.5f
);

// TEXTURES
m.getTexCoords().addAll(
X_RED, 0.5f,
X_GREEN, 0.5f,
X_BLUE, 0.5f,
X_YELLOW, 0.5f,
X_ORANGE, 0.5f,
X_WHITE, 0.5f,
X_GRAY, 0.5f
);

// FACES
m.getFaces().addAll(
2,face[0],3,face[0],6,face[0], // F
3,face[0],7,face[0],6,face[0],

0,face[1],1,face[1],2,face[1], // R
2,face[1],1,face[1],3,face[1],

1,face[2],5,face[2],3,face[2], // U
5,face[2],7,face[2],3,face[2],

0,face[3],4,face[3],1,face[3], // B
4,face[3],5,face[3],1,face[3],

4,face[4],6,face[4],5,face[4], // L
6,face[4],7,face[4],5,face[4],

0,face[5],2,face[5],4,face[5], // D
2,face[5],6,face[5],4,face[5]
);
return m;
}

public static void main(String args) {
launch(args);
}

}









share|improve this question
















I have a question about rotation in javafx. To be specific "RotateTransition"
For now i made cube 2x2 thanks to http://stackoverflow.com/questions/34001900/how-to-render-3d-graphics-properly. Somehow i need to start rotating cube not the scene as i do it now. So here is the probem. How can i change it to move faces of the cube not the scene around the cube ?
Here is how it looks now : Cube rotation



Here is the code :



public class RubiksCube extends Application {

public static final int RED = 0;
public static final int GREEN = 1;
public static final int BLUE = 2;
public static final int YELLOW = 3;
public static final int ORANGE = 4;
public static final int WHITE = 5;
public static final int GRAY = 6;

public static final float X_RED = 0.5f / 7f;
public static final float X_GREEN = 1.5f / 7f;
public static final float X_BLUE = 2.5f / 7f;
public static final float X_YELLOW = 3.5f / 7f;
public static final float X_ORANGE = 4.5f / 7f;
public static final float X_WHITE = 5.5f / 7f;
public static final float X_GRAY = 6.5f / 7f;

private double mousePosX;
private double mousePosY;
private double mouseOldX;
private double mouseOldY;

@FXML
Scene scene;

@SuppressWarnings("unused")
@Override
public void start(Stage primaryStage) throws IOException {

Group root = new Group();
Parent dupa = FXMLLoader.load(getClass().getResource("Design.fxml"));
Scene scene = new Scene(root, 600, 600, true, SceneAntialiasing.BALANCED);
scene.setFill(Color.BLACK);
PerspectiveCamera camera = new PerspectiveCamera(true);
camera.setNearClip(0.1);
camera.setFarClip(10000.0);
camera.setTranslateZ(-10);
scene.setCamera(camera);

PhongMaterial mat = new PhongMaterial();
// image can be found here http://i.stack.imgur.com/uN4dv.png
mat.setDiffuseMap(new Image(getClass().getResourceAsStream("palette.png")));

Group meshGroup = new Group();

AtomicInteger cont = new AtomicInteger();
patternFaceF.forEach(p -> {
MeshView meshP = new MeshView();
meshP.setMesh(createCube(p));
meshP.setMaterial(mat);
Point3D pt = pointsFaceF.get(cont.getAndIncrement());
meshP.getTransforms().addAll(new Translate(pt.getX(), pt.getY(), pt.getZ()));
meshGroup.getChildren().add(meshP);
});

Rotate rotateX = new Rotate(30, 0, 0, 0, Rotate.X_AXIS);
Rotate rotateY = new Rotate(20, 0, 0, 0, Rotate.Y_AXIS);
meshGroup.getTransforms().addAll(rotateX, rotateY);

root.getChildren().addAll(meshGroup, new AmbientLight(Color.WHITE));

scene.setOnMousePressed(me -> {
mouseOldX = me.getSceneX();
mouseOldY = me.getSceneY();
});
scene.setOnMouseDragged(me -> {
mousePosX = me.getSceneX();
mousePosY = me.getSceneY();
rotateX.setAngle(rotateX.getAngle()-(mousePosY - mouseOldY));
rotateY.setAngle(rotateY.getAngle()+(mousePosX - mouseOldX));
mouseOldX = mousePosX;
mouseOldY = mousePosY;
});

primaryStage.setTitle("Simple Rubik's Cube - JavaFX");
primaryStage.setScene(scene);
primaryStage.show();
}
// F R U B L D
private static final int FLD = new int{BLUE, GRAY, GRAY, GRAY, ORANGE, WHITE};
private static final int FRD = new int{BLUE, RED, GRAY, GRAY, GRAY, WHITE};
private static final int FLU = new int{BLUE, GRAY, YELLOW, GRAY, ORANGE, GRAY};
private static final int FRU = new int{BLUE, RED, YELLOW, GRAY, GRAY, GRAY};

private static final Point3D pFLD = new Point3D(-0.55, 0.55, -0.55);
private static final Point3D pFRD = new Point3D( 0.55, 0.55, -0.55);
private static final Point3D pFLU = new Point3D(-0.55, -0.55, -0.55);
private static final Point3D pFRU = new Point3D( 0.55, -0.55, -0.55);

private static final int BLD = new int{GRAY, GRAY, GRAY, GREEN, ORANGE, WHITE};
private static final int BRD = new int{GRAY, RED, GRAY, GREEN, GRAY, WHITE};
private static final int BLU = new int{GRAY, GRAY, YELLOW, GREEN, ORANGE, GRAY};
private static final int BRU = new int{GRAY, RED, YELLOW, GREEN, GRAY, GRAY};

private static final Point3D pBLD = new Point3D(-0.55, 0.55, 0.55);
private static final Point3D pBRD = new Point3D( 0.55, 0.55, 0.55);
private static final Point3D pBLU = new Point3D(-0.55, -0.55, 0.55);
private static final Point3D pBRU = new Point3D( 0.55, -0.55, 0.55);

private static final List<int> patternFaceF = Arrays.asList(
FLD, FRD, FLU, FRU,
BLD, BRD, BLU, BRU);

private static final List<Point3D> pointsFaceF = Arrays.asList(
pFLD, pFRD, pFLU, pFRU,
pBLD, pBRD, pBLU, pBRU);

private TriangleMesh createCube(int face) {
TriangleMesh m = new TriangleMesh();

// POINTS
m.getPoints().addAll(
0.5f, 0.5f, 0.5f,
0.5f, -0.5f, 0.5f,
0.5f, 0.5f, -0.5f,
0.5f, -0.5f, -0.5f,
-0.5f, 0.5f, 0.5f,
-0.5f, -0.5f, 0.5f,
-0.5f, 0.5f, -0.5f,
-0.5f, -0.5f, -0.5f
);

// TEXTURES
m.getTexCoords().addAll(
X_RED, 0.5f,
X_GREEN, 0.5f,
X_BLUE, 0.5f,
X_YELLOW, 0.5f,
X_ORANGE, 0.5f,
X_WHITE, 0.5f,
X_GRAY, 0.5f
);

// FACES
m.getFaces().addAll(
2,face[0],3,face[0],6,face[0], // F
3,face[0],7,face[0],6,face[0],

0,face[1],1,face[1],2,face[1], // R
2,face[1],1,face[1],3,face[1],

1,face[2],5,face[2],3,face[2], // U
5,face[2],7,face[2],3,face[2],

0,face[3],4,face[3],1,face[3], // B
4,face[3],5,face[3],1,face[3],

4,face[4],6,face[4],5,face[4], // L
6,face[4],7,face[4],5,face[4],

0,face[5],2,face[5],4,face[5], // D
2,face[5],6,face[5],4,face[5]
);
return m;
}

public static void main(String args) {
launch(args);
}

}






java javafx rotation javafx-3d






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 21:59









Slaw

8,38631033




8,38631033










asked Nov 21 '18 at 19:53









TubenuTubenu

32




32













  • Rotating individual faces in this very simplified model can be really challenging. I'd suggest you have a look at this link and this one for a more complex version.

    – José Pereda
    Nov 21 '18 at 20:56



















  • Rotating individual faces in this very simplified model can be really challenging. I'd suggest you have a look at this link and this one for a more complex version.

    – José Pereda
    Nov 21 '18 at 20:56

















Rotating individual faces in this very simplified model can be really challenging. I'd suggest you have a look at this link and this one for a more complex version.

– José Pereda
Nov 21 '18 at 20:56





Rotating individual faces in this very simplified model can be really challenging. I'd suggest you have a look at this link and this one for a more complex version.

– José Pereda
Nov 21 '18 at 20:56












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53419591%2fcube-rotate-in-javafx%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53419591%2fcube-rotate-in-javafx%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith