Quaternions to angle in degree (solved)

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.


didn't read in detail your post so my answer might be pointless ;):



I think Quaternion.getRotationColumn(0) gives you the rotation around x. 1 for y and 2 for z.



I'm really not sure but you can try.

Maybe you are right but i have no idea how to convert that vector back to an angle

I think  the resulting Vector3f is the direction of your Spatial so you can get the angle between this vector with another one thanks to this method: Vector3f.angleBetween(…).



Edit: normalize your vectors before calling angleBetween.

And what should be the other vector ? i tried its own location and world center(0,0,0) but both result in a wrong angle



Hellmaster.

Dunno depends on what angle you desire  :?

There was a problem with our Quaternion.fromAngles method. Fix checked into jME1.0 and jME2.0.



Have a go with your stuff again after updating.

Nice find!

yep it works :D  many thanks



Hellmaster

Ah found this topic to my Quaternion problem: now I am not sure if I have the same problem: what exactly was wrong and what was fixed?

I tried Hellmasters code from the first post in this topic in my application as well and got exactly the same DEG and RAD results he posted. So if the way to get the angles from an object is correct, and I receive the same results I guess I am working too with “unfixed” source?




I had the same problem. I was not sure at first because I downloaded the JME1.0 jars somewhen in June 2008 and worked with them until now; I changed then to CVS and it works now for me too. Thanks for this topic  :slight_smile:



Just a thought: I guess there’s still a number of people who use the JME1.0 jars which seem to be from Oktober 2007 and still contain the bug? https://jme.dev.java.net/servlets/ProjectDocumentList?folderID=418&expandFolder=418&folderID=418