Alright, so this is how I am doing it:
float xrot = 0; float yrot = 0; float zrot = 0; Quaternion q = new Quaternion().fromRotationMatrix(player.model.getRotation()); if(q.getW() > 1){ q.normalizeLocal(); } float angle = (float) (2 * Math.acos(q.getW())); double s = Math.sqrt(1-q.getW()*q.getW()); if (s < 0.001) { // test to avoid divide by zero, s is always positive due to sqrt // if s close to zero then direction of axis not important xrot = q.getXf(); // if it is important that axis is normalised then replace with x=1; y=z=0; yrot = q.getYf(); zrot = q.getZf(); // z = q.getZ(); } else { xrot = (float) (q.getXf() / s); // normalise axis yrot = (float) (q.getYf() / s); zrot = (float) (q.getZf() / s); }
But it doesn't seem to work when I try to put it into use:
player.model.addTranslation(zrot * player.speed, 0, xrot * player.speed);
AddTranslation takes 3 numbers to move my model by than many spaces (x, y, z), but hen I give it the numbers above it doesn't move the model in the direction it has been rotated (on the XZ plane)