I have created Rubik's cube by jPCT and now I need to rotate this whole cube. I have tried to achieve this by rotation matrixes and I have rotated single cube elements but this does not seem to be good way..
So I want to rotate my camera around the cube instead of rotating the cube. It is pretty easy but problem is that jPCT changes the orientation of my camera randomly or I have done some another mistake and I am unable to fix it.
SimpleVector cameraPos = new SimpleVector(-20, 0, 0);
SimpleVector cubeCenter = new SimpleVector(2, 2, 2);
while (!org.lwjgl.opengl.Display.isCloseRequested()) {
refreshScene();
// Camera position is repeatedly rotated
cameraPos.rotateAxis(new SimpleVector(0, 0, 1), (float) Math.toRadians(1));
// Here I set camera position
world.getCamera().setPosition(cameraPos);
// Camera looks at the center of cube, but unfortunately
// not with fixed orientation
world.getCamera().lookAt(cubeCenter);
try {
Thread.sleep(50);
} catch (InterruptedException e) {
}
}
Above code performs this strange rotation of cube:
That is cool but I need rotate my cube like this:
I have tried to set camera orientation by setOrientation
method:
SimpleVector upVector = world.getCamera().getUpVector();
upVector.scalarMul(-1.0f);
world.getCamera().setOrientation(world.getCamera().getDirection(), upVector);
The last line in this code should IMHO turn camera orientation upside down, but it just does nothing. I use last version of jPCT.
How can I achieve right camera orientation? Any help is very welcome!