[opensource-dev] converting degrees into quaternions

CJ Davies cjohndavies at gmail.com
Tue Jul 31 09:01:26 PDT 2012


Looks like my problem was an amateur mistake - causing integer division 
on a float value, which when dealing with values that range between -1 & 
1 is fairly debilitating!

I'm now getting the right values, but in the wrong places, using the

LLQuaternion(F32 x, F32 y, F32 z, F32 w);

constructor. I presume this must just be because whilst SL uses E/W as 
+ve/-ve x axis & N/S as +ve/-ve y axis I must be assuming something else 
for my magnetometer/accelerometer.

SL looking North - {0.0, 0.0, 0.7, 0.7}
magnetometer pointing North - {0.0, 0.0, 0.0, 1.0}

SL looking East - {0.0, 0.0, 0.0, 1.0}
magnetometer pointing North - {0.7, 0.0, 0.0, 0.7}

SL looking South - {0.0, 0.0, -0.7, 0.7}
magnetometer pointing South - {-1.0, 0.0, 0.0, 0.0}

SL looking West - {0.0, 0.0, 1.0, 0.0}
magnetometer pointing West - {-0.7, 0.0, 0.0, 0.7}

Whilst I'm at it, llquaternion.h has some confusing comments in it... 
(look at the order of parameters in declaration & comment closely!)

const LLQuaternion&	setEulerAngles(F32 roll, F32 pitch, F32 yaw);	// 
Sets Quaternion to euler2quat(pitch, yaw, roll)

Regards,
CJ Davies

On 31/07/12 16:14, Nexii Malthus wrote:
> Hey Folks,
>
> The C++ codebase doesn't have much to do with LSL, so llEuler2Rot won't
> exactly help.
>
> What you are looking for CJ are the helper functions for quaternions,
> maybe this one will help:
>
>   const  LLQuaternion&  setEulerAngles(F32  roll,  F32  pitch,  F32  yaw);
>
> (form llquaternion
> <https://bitbucket.org/lindenlab/viewer-release/src/24c6da14256c/indra/llmath/llquaternion.h#cl-83>)
>
> - Nexii
>
> On Tue, Jul 31, 2012 at 1:38 PM, Sophira Crystal <sl-dev at theblob.org
> <mailto:sl-dev at theblob.org>> wrote:
>
>     Hi,
>
>     To follow up on this...
>
>     The easiest way to do what you want is to make a vector made up of
>     <roll, bearing, pitch> in degrees, multiply the vector by DEG_TO_RAD,
>     and then put it through llEuler2Rot. You should then have a good
>     rotation that you can pass to a function that needs it.
>
>     Hope this helps!
>
>       - Sophie.
>
>     On Tue, Jul 31, 2012 at 1:29 PM, Sophira Crystal <sl-dev at theblob.org
>     <mailto:sl-dev at theblob.org>> wrote:
>      > Hi,
>      >
>      > You don't convert degrees to quaternions directly. You convert
>     vectors
>      > to rotations (which are quarternions), and you do that with the
>      > llEuler2Rot function.
>      >
>      > As for the rest of your query, you might find
>      > http://wiki.secondlife.com/wiki/Rotation helpful - I don't know much
>      > about rotations, but I bet the answer you want is probably in there
>      > somewhere.
>      >
>      > I hope my reply's been helpful, even though I personally don't
>     know much...
>      >
>      >  - Sophie.
>      >
>      > On Tue, Jul 31, 2012 at 11:54 AM, CJ Davies
>     <cjohndavies at gmail.com <mailto:cjohndavies at gmail.com>> wrote:
>      >> I've been struggling with this for 2 days now & am no closer to
>     working
>      >> it out (despite investigating all sorts of examples online,
>     including
>      >> the SL wiki).
>      >>
>      >> I have a accelerometer/magnetometer that tells me orientation via
>      >> compass bearing, pitch & roll. All of these are in degrees which can
>      >> easily be converted to radians via foo*DEG_TO_RAD. I want to
>     plug these
>      >> values into llcoordframe methods to control where the camera
>     points. All
>      >> of the llcoordframe stuff works in quaternions & I can't for the
>     life of
>      >> me convert properly.
>      >>
>      >> I've just tried following this approach -->
>      >>
>     http://www.euclideanspace.com/maths/geometry/rotations/conversions/eulerToQuaternion/index.htm
>      >>
>      >> But this results in output like this --> http://paste2.org/p/2089138
>      >>
>      >> Note how the calculated w/x/y/z values change drastically with tiny
>      >> changes in the bearing/pitch/roll, eg between lines 43 & 50 (the
>      >> accelerometer/magnetometer was motionless on the desk at the time!).
>      >>
>      >> Any help greatly appreciated.
>      >>
>      >> Regards,
>      >> CJ Davies
>      >> _______________________________________________
>      >> Policies and (un)subscribe information available here:
>      >> http://wiki.secondlife.com/wiki/OpenSource-Dev
>      >> Please read the policies before posting to keep unmoderated
>     posting privileges
>     _______________________________________________
>     Policies and (un)subscribe information available here:
>     http://wiki.secondlife.com/wiki/OpenSource-Dev
>     Please read the policies before posting to keep unmoderated posting
>     privileges
>
>



More information about the opensource-dev mailing list