[osg-users] Quaternion multiplication order

Robert Osfield robert.osfield at gmail.com
Wed Oct 17 01:29:33 PDT 2007


Hi Will,

The quaternion multiplication order has to be consistent with the rest
of the OSG i.e.

   v' = v * M;

Now what is standard for other libraries, or even other communities is
an issue, but since libraries and communities all use their own
standards there is now way for the OSG to be consistent with all of
them - it has to stick with one and keep to it.

In the case of quats and matrix orderering one should have the same
between result from doing

   Quat q1 = ..
   Quat q2 = ..

   Matrix m1 = osg::Matrix::rotate(q1) *  osg::Matrix::rotate(q2);
   Matrix m2 = osg::Matrix::rotate(q1*q2);

   // if everything works m1 should equal m2;

Robert.


On 10/16/07, Will Dicharry <wdicharry at gmail.com> wrote:
> Hello,
>
> I noticed that the cross terms in osg's quaternion class binary
> multiplication differ from the usual mathematical definition of quaternion
> multiplication.  The subtractions are opposite what they should be.
>
> osg's implementation is
>
>
> /// Binary multiply
>
> inline const Quat operator*(const Quat& rhs) const
>
> {
>
> return Quat( rhs._v[3]*_v[0] + rhs._v[0]*_v[3] + rhs._v[1]*_v[2] -
> rhs._v[2]*_v[1],
>
> rhs._v[3]*_v[1] - rhs._v[0]*_v[2] + rhs._v[1]*_v[3] + rhs._v[2]*_v[0],
>
> rhs._v[3]*_v[2] + rhs._v[0]*_v[1] - rhs._v[1]*_v[0] + rhs._v[2]*_v[3],
>
> rhs._v[3]*_v[3] - rhs._v[0]*_v[0] - rhs._v[1]*_v[1] - rhs._v[2]*_v[2] );
>
> }
>
> I believe that it should be:
>
> /// Binary multiply
>
> inline const Quat operator*(const Quat& rhs) const
>
> {
>
> return Quat(
>
> rhs._v[3]*_v[0] + rhs._v[0]*_v[3] - rhs._v[1]*_v[2] + rhs._v[2]*_v[1],
>
> rhs._v[3]*_v[1] + rhs._v[0]*_v[2] + rhs._v[1]*_v[3] - rhs._v[2]*_v[0],
>
> rhs._v[3]*_v[2] - rhs._v[0]*_v[1] + rhs._v[1]*_v[0] + rhs._v[2]*_v[3],
>
> rhs._v[3]*_v[3] - rhs._v[0]*_v[0] - rhs._v[1]*_v[1] - rhs._v[2]*_v[2] );
>
> }
>
> The effect of this transposition is to force a pre-multiplication ordering
> for the operation.  I am wondering whether this is intentional or a mistake
> and if it is intentional, why was it chosen to work this way.  I searched
> the osg mailing list archives, and I found a similar question posted in
> 2004, but I haven't been able to find a follow up to that message.
>
> This causes problems in my application because I may receive orientation
> data from a source that uses a different quaternion library using the
> post-multiplication ordering, which is the standard way in the mathematical
> community.
>
> Thanks,
> Will
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>



More information about the osg-users mailing list