I assume there is a better way to do what I want to do.
I haven’t problem with rotation cube around axis unfortunately global axis.
When I want to make the rotation around local axis I just remember central point of my cube then move cube to position x=0, y=0, z=0 and I start rotation.
After rotation I move cube back to saved position.
Is there any way to do it without moving cobe?
This is my code responsible for rotation.
private static float angle = 4;
private Quat4f roll = new Quat4f();
private Quat4f quantBase = new Quat4f();
private AxisAngle4f angle4f = new AxisAngle4f();
private void update(boolean rotX, boolean rotY, boolean rotZ){
if(rotX){
angle4f.set(new Vector3f(1, 0, 0), angle * (float) (Math.PI / 180));
} if(rotY) {
angle4f.set(new Vector3f(0, 1, 0), angle * (float) (Math.PI / 180));
} if(rotZ) {
angle4f.set(new Vector3f(0, 0, 1), angle * (float) (Math.PI / 180));
}
roll.set(angle4f);
for(int i = 0;i<array.length;i+=3) {
quantBase.x = array[i];
quantBase.y = array[i+1];
quantBase.z = array[i+2];
quantBase.w = 0f;
quantBase.mul(roll, quantBase);
if(rotX) {
array[i+1] = quantBase.y;
array[i+2] = quantBase.z;
}
if(rotY) {
array[i] = quantBase.x;
array[i+2] = quantBase.z;
}
if(rotZ) {
array[i] = quantBase.x;
array[i+1] = quantBase.y;
}
}
vertexData.put(array);
vertexData.flip();
}
For clarity, this is how I understand the local and global axis.