Quick question:
I have the Euler angles (defined as rotX, rotY, rotZ in radians) and I’m trying to convert these to a quaternion. Now, my understanding of quaternions is extremely limited, but I’m wondering if the following code is working:
public void setOrientation(float x, float y, float z){
x*=0.5f;
y*=0.5f;
z*=0.5f;
float c1 = (float)Math.cos(x);
float c2 = (float)Math.cos(y);
float c3 = (float)Math.cos(z);
float s1 = (float)Math.sin(x);
float s2 = (float)Math.sin(y);
float s3 = (float)Math.sin(z);
localOrientation = new Quaternion(
s1*s2*c3 + c1*c2*s3,
s1*c2*c3 + c1*s2*s3,
c1*s2*c3 - s1*c2*s3,
c1*c2*c3 - s1*s2*s3
);
}
Input:
1.570796 0.000000 0.000000
Output:
0.0 0.70710665 0.0 0.7071069
From what I can see, the direction seems to be off, assuming bones aren’t supposed to extrude in a 90 degree angle out of the body. =S