## The quaternions are xxx. And I'll go crazy

### The quaternions are xxx. And I'll go crazy

Hi.

I have been helping in the free project Goxel. And I am trying to set the camera with the ui widgets.

Well, I have chatted with the main author, and he said me that the input boxes (for rotation) must be in euler angles instead of quaternions, and yes this is good advise.

But I can't convert correctly quaternion -> euler and euler -> quaternion.

I have opened a question in stackoverflow Quaternion to euler angles and euler angles to quaternion in C, but at the moment nobody helps me.

I have looked for about this, and I saw this question in stackoverflow http://stackoverflow.com/questions/11103683/euler-angle-to-quaternion-then-quaternion-to-euler-angle. And in this question the developers used the library glm. I have been studying the code of this library and I trying copy its code, this is my last code (with the similar "gears" of glm code):

{l Code}: {l Select All Code}
`#include <stdio.h>#include <math.h>#define DR2D (180 / M_PI)#define DD2R (M_PI / 180)int main(int argc, char** argv){   float x, y, z;   float qx, qy, qz, qw;      x = 0 * DD2R;   y = 90 * DD2R;   z = 90 * DD2R;      printf("initial x=%f y=%f z=%f\n", x * DR2D, y * DR2D, z * DR2D);      float sx = sin(x / 2);   float sy = sin(y / 2);   float sz = sin(z / 2);   float cx = cos(x / 2);   float cy = cos(y / 2);   float cz = cos(z / 2);         qx = sx*cy*cz - cx*sy*sz;   qy = cx*sy*cz + sx*cy*sz;   qz = cx*cy*sz - sx*sy*cz;   qw = cx*cy*cz + sx*sy*sz;      printf("Quaternion -> (%f, %f, %f, %f)\n", qx, qy , qz , qw);      x = atan2(2 * (qy*qz + qw*qx), qw*qw - qx*qx - qy*qy + qz*qz);   float temp = -2*(qx*qz - qw*qy);   if (temp < -1)      temp = -1;   else if (temp > 1)      temp = 1;   y = asin(temp);      z = atan2(2 * (qx*qy + qw*qz), qw*qw + qx*qx - qy*qy - qz*qz);      printf("recover euler x=%.2f y=%.2f z=%.2f\n",      x * DR2D, y * DR2D, z * DR2D);            return 0;}`

But it still fail.

{l Code}: {l Select All Code}
`md@speccy-laptop ~/proyectos/goxel/test \$ rm a.out; g++ test.c; ./a.outinitial x=0.000000 y=90.000003 z=90.000003Quaternion -> (-0.500000, 0.500000, 0.500000, 0.500000)recover euler x=0.00 y=89.97 z=0.00`

I feel bad, because I don't understand completely the quaternions and I can't make a good code. Well, I know that there is a 3D rotations equivalets.

Regards.

mdtrooper

Posts: 105
Joined: 26 Jul 2012, 13:24

### Re: The quaternions are xxx. And I'll go crazy

If it helps, you can think of quaternions as a special way to write axis-angle rotations:
q = (cos(a/2), u * sin(a/2)), u is rotation axis and a is rotation angle

Your problem is with the euler angles and gimbal lock I think. Try changing float to double.
NaN

Posts: 150
Joined: 18 Jan 2010, 10:32

### Re: The quaternions are xxx. And I'll go crazy

You are awesome. Yes, I failed in the numeric precision, with double runs fine. Thanks.

mdtrooper

Posts: 105
Joined: 26 Jul 2012, 13:24

### Re: The quaternions are xxx. And I'll go crazy

Sry for offtopic, but a few questions:

Is this better than magica voxel?
Any description how the procedural scripting(?) works?
Does the project have a website?

__
edit: nvm, I found the /progs folder with a well documented example, thats a beginning!

riidom

Posts: 218
Joined: 25 Jan 2010, 02:02
Location: irgendwo an der Elbe

### Re: The quaternions are xxx. And I'll go crazy

riidom {l Wrote}:Sry for offtopic, but a few questions:

Is this better than magica voxel?
Any description how the procedural scripting(?) works?
Does the project have a website?

__
edit: nvm, I found the /progs folder with a well documented example, thats a beginning!

Well, some months ago I looked for a voxel editor (for to make a sprites with this style). I found magica voxel, but it is only for "m\$-win and rotten apple" and it smells a c#.

But I had lucky and I found this project, Goxel is easy to compile, it runs in GNU/Linux and the main developer is a nice guy (he reply all messages and bugs quickly and pleasant).

mdtrooper

Posts: 105
Joined: 26 Jul 2012, 13:24

### Who is online

Users browsing this forum: No registered users and 1 guest