Simple?? Quaternion rotation problem

A friend and I were messing around with jME and were rotating 2 cubes. We had different ideas on how we could do it, but got one way to work. The other didn’t and we aren’t sure why.

We have an array of the geometry we want to rotate. Below is a code snippet -


          Quaternion rotQuat = new Quaternion();
          Quaternion localQuat = null;
          float angle = 0; 

          if (timer.getTimePerFrame() < 1) {
                angle = timer.getTimePerFrame() * 50;
          }
               rotQuat.fromAngleAxis(angle*FastMath.DEG_TO_RAD, new Vector3f(1, 0, 0));

         for (int i = 0; i < spinList.size(); i++){

               TriMesh geom = (TriMesh)spinList.get(i);
               localQuat = geom.getLocalRotation();
               localQuat.addLocal(rotQuat);

        }


Shouldn’t this take the quat from the current object and add a small amount of rotation to it?

If we instead change 2 things: make the angle additive each time, ie angle += … and then do a geom.setLocalRotation(rotQuat), it works. Of course, this means all the rotating objects are rotated at exactly the same angles, rather than whatever angles they started at.

Regards,
Dr. A>

FYI, this was answered on the official jME forums

I double checked there and don’t see that anyone has responded. My thread at the jme forum there is -

http://www.jmonkeyengine.com/jmeforum/viewtopic.php?t=1437

Thanks,
Dr. A>

Oops, sorry, there was another similar thread around the same time:

http://www.jmonkeyengine.com/jmeforum/viewtopic.php?t=1424

I think you would multiply, like: localQuat = rotQuat.multiply(localQuat);

Looks like another poster suggests the same thing on your other thread. :slight_smile: