[diff for Quaternion] Few spelling mistakes and inconsistencies

Was doing a tutorial on Quaternions, and couldn’t figure out the order of rotations as the javadoc was a bit off. And I found a few spelling mistakes also, didn’t inspect the whole file, so there may be more.



[patch]

— Base (BASE)

+++ Locally Modified (Based On LOCAL)

@@ -233,7 +233,7 @@



/**

  • <code>fromAngles</code> builds a Quaternion from the Euler rotation
  • * angles (x,y,z) aka (pitch, yaw, rall)). Note that we are applying in order: roll, yaw, pitch but<br />
    
  • * angles (x,y,z) aka (pitch, yaw, roll)). Note that we are applying in order: (y, z, x) aka (yaw, roll, pitch) but<br />
    
  • * object.  The value is retrieved as if this quaternion was first normalized.<br />
    
  • * object. The value is retrieved as if this quaternion was first normalized.<br />
    

*

  • @param i
  •        the column to retrieve. Must be between 0 and 2.<br />
    

@@ -585,7 +585,7 @@

/**

  • <code>toAngleAxis</code> sets a given angle and axis to that
  • represented by the current quaternion. The values are stored as
  • * following: The axis is provided as a parameter and built by the method,<br />
    
  • * follows: The axis is provided as a parameter and built by the method,<br />
    
  • the angle is returned as a float.

    *
  • @param axisStore

    @@ -1096,6 +1096,7 @@



    /**
  • <code>normalize</code> normalizes the current <code>Quaternion</code>
  • * The result is stored interally.<br />
    

*/

public Quaternion normalizeLocal() {

float n = FastMath.invSqrt(norm());

@@ -1128,7 +1129,7 @@

/**

  • <code>inverse</code> calculates the inverse of this quaternion and
  • returns this quaternion after it is calculated. If this quaternion does
  • * not have an inverse (if it's norma is 0 or less), nothing happens<br />
    
  • * not have an inverse (if it's normal is 0 or less), nothing happens<br />
    

*

  • @return the inverse of this quaternion

    */

    @@ -1158,7 +1159,7 @@

    /**

    *
  • <code>toString</code> creates the string representation of this
  • * &lt;code&gt;Quaternion&lt;/code&gt;. The values of the quaternion are displace (x,<br />
    
  • * &lt;code&gt;Quaternion&lt;/code&gt;. The values of the quaternion are displaced by (x,<br />
    
  • y, z, w), in the following manner: <br>
  • (x, y, z, w)

    *

    [/patch]

Committed, although I wasn’t able to get the diff to apply correctly :confused:

There was a bit of a discussion about the documentation of the Euler angles a while ago,Don’t know if it is anything that should be taken into account. http://hub.jmonkeyengine.org/groups/general-2/forum/topic/definition-of-pitch-yaw-roll-in-jmonkeyengine/

@sbook said:
Committed, although I wasn't able to get the diff to apply correctly :/


Was probably my fault, i did get an error when trying to update the Quaternion after I made my own changes to it.

@jmaasing said:
There was a bit of a discussion about the documentation of the Euler angles a while ago,Don't know if it is anything that should be taken into account. http://hub.jmonkeyengine.org/groups/general-2/forum/topic/definition-of-pitch-yaw-roll-in-jmonkeyengine/


yeh that guy got confused like me, because jME Quaternions do it in the order y, z, x but they were still miss labelled as z, y, x (roll, yaw, pitch) for fromAngles(). But i agree that there is still some ambiguity, for example Spatial.rotate() doesn't mention the order at all, I thought it was applied x, y and then z as I'm sure many other people starting would, so I was getting very frustrated trying to figure out what was happening. I was wondering why

[java]spatial.rotate(x, 0, 0);
spatial.rotate(0, y, 0);
spatial.rotate(0, 0, z);[/java]

didn't equal
[java]spatial.rotate(x, y, z)[/java]

you have to do:

[java]spatial.rotate(0, y, 0);
spatial.rotate(0, 0, z);
spatial.rotate(x, 0, 0);[/java]

because under the hood, that the order spatial.rotate(x, y, z) and Quaternion().fromAngles(x, y, z) are essential doing it.

I don't know if that's how Quaternions are meant to be applied, or if jME chose to adopt it like that, but more needs to be done to explain it better. Which i will be doing in my tutorial :)

Also can you apply this patch to Spatial. Been wanting this function for about 8 months now :)

[patch]
--- Base (BASE)
+++ Locally Modified (Based On LOCAL)
@@ -806,6 +806,23 @@
}

/**
+ * <code>setLocalRotation</code> sets the local rotation of this node
+ * using euler angles. Note: the order of rotations will be: y, then z, then x
+ *
+ * @param xAngle
+ * the Euler pitch of rotation (in radians)
+ * @param yAngle
+ * the Euler yaw of rotation (in radians)
+ * @param zAngle
+ * the Euler roll of rotation (in radians)
+ */
+ public void setLocalRotation(float xAngle, float yAngle, float zAngle) {
+ Quaternion quaternion = new Quaternion().fromAngles(xAngle, yAngle, zAngle);
+ localTransform.setRotation(quaternion);
+ setTransformRefresh();
+ }
+
+ /**
* <code>getLocalScale</code> retrieves the local scale of this node.
*
* @return the local scale of this node.
[/patch]

Concatenating rotations doesn’t really work commutative.

@wezrule said:Also can you apply this patch to Spatial. Been wanting this function for about 8 months now :)


Make a new thread for that one.. new functionality = new discussion
@normen said:
Concatenating rotations doesn't really work commutative.

i know :)
@sbook said:
Make a new thread for that one.. new functionality = new discussion

done
1 Like
@wezrule said:
I was wondering why

[java]spatial.rotate(x, 0, 0);
spatial.rotate(0, y, 0);
spatial.rotate(0, 0, z);[/java]

didn't equal
[java]spatial.rotate(x, y, z)[/java]

you have to do:

[java]spatial.rotate(0, y, 0);
spatial.rotate(0, 0, z);
spatial.rotate(x, 0, 0);[/java]


Did you test this? Because it looks wrong to me on a quick glance. I'd expect roll to be last and not second.

yeh been testing it a lot today, heres a testcase:



[java]

package mygame;



import com.jme3.app.SimpleApplication;

import com.jme3.light.DirectionalLight;

import com.jme3.math.ColorRGBA;

import com.jme3.math.FastMath;

import com.jme3.math.Vector3f;

import com.jme3.scene.Spatial;



public class Rotations extends SimpleApplication {



private Spatial player;



public static void main(String[] args) {

new Rotations().start();

}



@Override

public void simpleInitApp() {



DirectionalLight sun = new DirectionalLight();

sun.setDirection(new Vector3f(1, 0, -2).normalizeLocal());

sun.setColor(ColorRGBA.White);

rootNode.addLight(sun);



player = assetManager.loadModel("Models/Sinbad/Sinbad.mesh.xml");

player.setLocalScale(0.5f);

rootNode.attachChild(player);



//player.rotate(0, FastMath.HALF_PI, 0); //y

//player.rotate(0, 0, FastMath.HALF_PI); //z

//player.rotate(FastMath.HALF_PI, 0, 0); //x



player.rotate(FastMath.HALF_PI, FastMath.HALF_PI, FastMath.HALF_PI);

}

}

[/java]