3D Rad - Free 3D game maker - Forum

This forum is now archived!

This forum is locked, and is a read-only version. A new community-ran forum can be found at classdev.net

News:

The 3DRad community can be found at classdev.net.

Pages: [1]

Author Topic: having issues with iQuaternionToEulerAngles  (Read 118 times)

« on: May 31, 2014, 05:16:58 AM »
I am trying to measure the orientation of a camchase object in my project with the script below:

Code: [Select]
   iQuaternionToEulerAngles(CAMCHASEQUATERNION,camx,camy,camz);
However, I am having some difficulties. The camy value (which I am trying to measure) seems to only range from -90-90 degrees. 45 could mean that the camera is rotated 45 degrees clockwise, or 135 degrees. I am not sure what is causing this. How can I fix it?

Googling the problem lead me to this: http://www.3drad.com/forum/index.php?topic=5434.0;wap2 but it wasn't much help.

Thanks for any suggestions you guys might have,

George.
« Reply #1 on: May 31, 2014, 08:05:05 AM »
I'm happy to hear an intelligent question!  :D

Some time ago (two years, darn...) I ran into the same problem and started a topic about it. In short, the functions is not really broken, it's just that the problem handles rotations completely different than we would. Instead of three values, a quaternion consists of four. I'm not sure how/why, never really figured that out.

To get the 'proper' rotation values, you could rotate a vector and then calculate the separate angles. To do so, you can either use the atan2, which you'll have to add using Jestermons great RadMath dll, or use a Dot Product rule to calculate the angles between two vectors. For the last one you'll have to create 'reference vectors', aligned with the three axes.

The trick is to create three projects of the rotated vector, one in each axis, and then get the desired rotation.

I'd recommend using the atan2 variant. If you have a moment, I'll create an example.

EDIT: Forget what I said about atan2. This method works only if an object is only rotated in one axis. I found an old project using the second method. Attached below.

Hope it helps. If you have any questions, feel free to ask.
« Last Edit: May 31, 2014, 08:29:34 AM by RobertooMolvadoo »
Rocket Rumble, a 3D Rad puzzle game:
http://www.3drad.com/forum/index.php?topic=9896.0
« Reply #2 on: May 31, 2014, 08:54:02 PM »
Woohoo!  ;D Thanks Robertoo. The attached project works really well.

Cheers,

George.
« Last Edit: June 01, 2014, 01:21:47 AM by georgio123 »
Pages: [1]