<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://jogamp.org/bugzilla/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.2"
          urlbase="https://jogamp.org/bugzilla/"
          
          maintainer="sgothel@jausoft.com"
>

    <bug>
          <bug_id>636</bug_id>
          
          <creation_ts>2012-11-06 23:29:07 +0100</creation_ts>
          <short_desc>Quaternion multiplication unexpected behavior</short_desc>
          <delta_ts>2012-11-11 09:14:03 +0100</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>3</classification_id>
          <classification>JogAmp</classification>
          <product>Jogl</product>
          <component>graph</component>
          <version>2</version>
          <rep_platform>All</rep_platform>
          <op_sys>all</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>---</priority>
          <bug_severity>critical</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Tek">fwdk98003</reporter>
          <assigned_to name="Sven Gothel">sgothel</assigned_to>
          <cc>rami.santina</cc>
    
    <cc>sgothel</cc>
          
          <cf_type>---</cf_type>
          <cf_scm_refs>jogl 944562a9600598dfa8a23f96f568fde999e1eca3
jogl 5fafc1ac360333645b807dcd8dff0c0a655ea439</cf_scm_refs>
          <cf_workaround>---</cf_workaround>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1951</commentid>
    <comment_count>0</comment_count>
    <who name="Tek">fwdk98003</who>
    <bug_when>2012-11-06 23:29:07 +0100</bug_when>
    <thetext>I am using JOGL 2.0 rc 10.

I tried using Quaternion class that was implemented in jogamp.graph.math.MathFloat.Quaternion and I noticed an error in mult(Quaternion).

I am not a Quaternion expert but according to all math site online quaternion multiplication is done as follows:

Let Q1 and Q2 be two quaternions, which are defined, respectively, as (w1, x1, y1, z1) and (w2, x2, y2, z2).
(Q1 * Q2).w = (w1w2 - x1x2 - y1y2 - z1z2)
(Q1 * Q2).x = (w1x2 + x1w2 + y1z2 - z1y2)
(Q1 * Q2).y = (w1y2 - x1z2 + y1w2 + z1x2)
(Q1 * Q2).z = (w1z2 + x1y2 - y1x2 + z1w2

http://en.wikipedia.org/wiki/Quaternion
http://www.cprogramming.com/tutorial/3d/quaternions.html
http://mathworld.wolfram.com/Quaternion.html

In Quaternion class, mult(Quaternion) is currently defined as:

    public void mult(Quaternion q)
    {
        float w1 = w*q.w - (x*q.x + y*q.y + z*q.z);

        float x1 = w*q.z + q.w*z + y*q.z - z*q.y;
        float y1 = w*q.x + q.w*x + z*q.x - x*q.z;
        float z1 = w*q.y + q.w*y + x*q.y - y*q.x;

        w = w1;
        x = x1;
        y = y1;
        z = z1; 
    }
I believe this multiplication is incorrect and it rotated my jogl model unpredictively.  Also, according to quaternion definition, quaternion multiplication are not commutative!!! (ie: q.w*z is different from z*q.w)

I override the mult(Quaternion) with the definition of quaternion multiplication and it behaves as expected:

    public void mult(Quaternion q)
    {
        float w1 = w*q.w - x*q.x - y*q.y - z*q.z;

        float x1 = w*q.x + x*q.w + y*q.z - z*q.y;
        float y1 = w*q.y - x*q.z + y*q.w + x*q.x;
        float z1 = w*q.z + x*q.y - y*q.x + y*q.w;

        w = w1;
        x = x1;
        y = y1;
        z = z1; 
    }

Thank you in advance</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1953</commentid>
    <comment_count>1</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2012-11-07 01:57:38 +0100</bug_when>
    <thetext>Thank you for your detailed bug report, inclusive references and fix.

Assigned to the original author, Rami Santina.

Let&apos;s wait until Rami has a chance to reply.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1954</commentid>
    <comment_count>2</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2012-11-07 01:59:04 +0100</bug_when>
    <thetext>@Rami: We may want to merge math util stuff (FloatUtil, ..) somehow more central ?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1956</commentid>
    <comment_count>3</comment_count>
    <who name="Rami Santina">rami.santina</who>
    <bug_when>2012-11-07 12:04:30 +0100</bug_when>
    <thetext>Yup thats correct, the fix is verified. Its good that we havent used this method in graph yet :) Great Catch. Thanks.

PS: its true quaternions are not commutative, but thats regarding q1*12 vs q2*q1, thus has nothing to do with quat. premitives. since w1*w2 will always give same result :)

@Sven, can you merge in this fix?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1957</commentid>
    <comment_count>4</comment_count>
    <who name="Rami Santina">rami.santina</who>
    <bug_when>2012-11-07 15:59:41 +0100</bug_when>
    <thetext>Yup thats correct, the fix is verified. Its good that we havent used this method in graph yet :) Great Catch. Thanks.

PS: its true quaternions are not commutative, but thats regarding q1*12 vs q2*q1, thus has nothing to do with quat. premitives. since w1*w2 will always give same result :)

@Sven, can you merge in this fix?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1958</commentid>
    <comment_count>5</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2012-11-07 16:32:02 +0100</bug_when>
    <thetext>(In reply to comment #4)
&gt; @Sven, can you merge in this fix?
Yes.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1959</commentid>
    <comment_count>6</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2012-11-07 16:33:15 +0100</bug_when>
    <thetext>BTW ... can we have a unit test for this ? :)

I will also validate the package location of out float/math stuff.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1960</commentid>
    <comment_count>7</comment_count>
    <who name="Tek">fwdk98003</who>
    <bug_when>2012-11-07 18:32:34 +0100</bug_when>
    <thetext>(In reply to comment #4)
&gt; PS: its true quaternions are not commutative, but thats regarding q1*12 vs
&gt; q2*q1, thus has nothing to do with quat. premitives. since w1*w2 will always
&gt; give same result :)

Thank you for clearing that up.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1970</commentid>
    <comment_count>8</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2012-11-11 09:14:03 +0100</bug_when>
    <thetext>Fixed w/ 944562a9600598dfa8a23f96f568fde999e1eca3 - setting Tek as author of commit.

Also went fwd to reorg. math util locations, see commit 5fafc1ac360333645b807dcd8dff0c0a655ea439,
etc ..</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>