Hey
Ok what im trying to do is let the user specify a rotation (in a textfield) around 1 or more axis in degrees
example x = 45 degrees, y = 10 degrees, z= 0 degrees
i then create a quaternion out of this via
float x,y,z;
x = FastMath.DEG_TO_RAD * Float.parsefloat(textfieldX.getText());
y = FastMath.DEG_TO_RAD * Float.parsefloat(textfieldY.getText());
z = FastMath.DEG_TO_RAD * Float.parsefloat(textfieldZ.getText());
// rotation is a quaternion
rotation.fromAngles(x, y, z);
((Spatial) object).getLocalRotation().set(rotation);
Since i can select my object on screen i want the text fields to be updated with the current rotation of the selected object. This is where things go wrong.
I can successfully read back a rotation around 1 axis but if i have a rotation around multiple axis the values i get back is wrong.
This is how read back the quaternion to degree's
float[] angles = new float[3];
// object is the selected spacial
object.getLocalRotation().toAngles(angles);
tfX.setText("" + Math.round(FastMath.RAD_TO_DEG * angles[0]));
tfY.setText("" + Math.round(FastMath.RAD_TO_DEG * angles[1]));
tfZ.setText("" + Math.round(FastMath.RAD_TO_DEG * angles[2]));
im rounding it off because if i dont i get a value that is slightly smaller 0.00001 or so
besides specifying a rotation in whole degrees is good enough for me.
the problem is when using more than 1 axis the value i read back from the quaternion is not the value i have put in
for example
i put in
X degree to rad =5.0deg = 0.08726646rad
Y degree to rad =40.0deg = 0.6981317rad
Z degree to rad =90.0deg = 1.5707964rad
i read back in object.getLocalRotation().toAngles(angles);
angles[0] = -1.4835297
angles[1] = 1.5707961
angles[2] = 0.8726647
which offcourse will result in a completely different angle when i do FastMath.RAD_TO_DEG * angles[*]
So my question is how do i read them back correct ?
Thx
Hellmaster.