Question about Quaternion fromAngles/toAngles

There seems to be a lot of fuzz about changing some things in jME 2.1 ( if it ever comes out), so I'd like to ask for a small feature.

( Is that actually allowed if you have less than 40k of posts on this forum or will I roast in monkey hell? )

the methods in Question are Quaternion.fromAngles( float[] angles ) and Quaternion.toAngles( float[] angles )

they both require and return a float array of length 3, but there already is a very handy class for handling 3 floats, with MANY handy methods for manipulating these floats, …, could it be ?? … VECTOR3f !

Is there a reason why these methods require/ return float[] ?

This little problem really started to anoy me when i started to work with torque in jmePhysiscs 2, because addTorque and getTorque use Vectors and i always have to convert.

( I manipulate my character's rotation along a curve with physics because setLocalRotation really, really didn't work with physiscs )



first of all: fromAngles(…) returns void.

second: toAngles does not return a Vector3f because the semantics are that it calculates three rotation angles (yaw, roll, pitch like in aeronautics). the operations of Vector3f like normalize, mult, and so on do NOT make any sense with this data.

In my opinion the current implementations are legit.

so long,


maybe, but thats just splitting hairs  :wink:

anyone else opinions?

I know that fromAngles returns void but it requires a float[],

    public void fromAngles(float[] angles) {
        if (angles.length != 3)
            throw new IllegalArgumentException(
                    "Angles array must have three elements");

        fromAngles(angles[0], angles[1], angles[2]);

i also know that fromAngles/toAngles calculates the euler angles from a Quaternion, and that this has nothing to do with Vectors per se.
But these three angles could be represented by a Vector3f because it has many handy methods for manipulting said three floats, with the array you have to do everything yourself, it's just a question of convinience.
Plus in jmePhysics 2 the Torque and angular velocity ( the change of these three angles over time ) is already represented as a Vector3f. ( At least you can only get them or set them with vectors, ode seems to work to work with three floats )

PlusPlus if the methods used vectors they wouldn't have to check if the array had the right size, that's one possible IllegalArgumentException less.

p.s.: why does Quaternion.fromAngles( float[] ) return void,but

   public Quaternion fromAngles(float yaw, float roll, float pitch) {
        float angle;
        float sinRoll, sinPitch, sinYaw, cosRoll, cosPitch, cosYaw;
        angle = pitch * 0.5f;
        sinPitch = FastMath.sin(angle);
        cosPitch = FastMath.cos(angle);
        angle = roll * 0.5f;
        sinRoll = FastMath.sin(angle);
        cosRoll = FastMath.cos(angle);
        angle = yaw * 0.5f;
        sinYaw = FastMath.sin(angle);
        cosYaw = FastMath.cos(angle);

        // variables used to reduce multiplication calls.
        float cosRollXcosPitch = cosRoll * cosPitch;
        float sinRollXsinPitch = sinRoll * sinPitch;
        float cosRollXsinPitch = cosRoll * sinPitch;
        float sinRollXcosPitch = sinRoll * cosPitch;
        w = (cosRollXcosPitch * cosYaw - sinRollXsinPitch * sinYaw);
        x = (cosRollXcosPitch * sinYaw + sinRollXsinPitch * cosYaw);
        y = (sinRollXcosPitch * cosYaw + cosRollXsinPitch * sinYaw);
        z = (cosRollXsinPitch * cosYaw - sinRollXcosPitch * sinYaw);
        return this;

returns a quaternion, fromAngles( float[] ), as seen in the first code snippet, just delegates to fromAngles( float, float, float ) for convinience but returns void.

splitting hairs is my speciality.

I can turn this guy  :mrgreen:

into this guy  :?

in no time