Quaternion Rotations

Hi

I’m mot quite sure, if have missed something, or if it is supposed to be like that, or if it is a bug. I wrote a small programm to get the grip on these Odejava rotations. Why I wrote it see also http://www.java-gaming.org/cgi-bin/JGNetForums/YaBB.cgi?board=physics;action=display;num=1111085614
Here is the code:


        Odejava.getInstance();
        world = new World();
        GeomBox boxG = new GeomBox(280, 60,240);
        boxG.setQuaternion(new Quat4f(0,0.707f,0.707f,0));
        GeomTransform t = new GeomTransform();
        t.setEncapsulatedGeom(boxG);
        Body b = new Body("boxBody",world);
        b.addGeom(t);
        b.adjustMass(1);
        System.out.println("boxG: "+boxG.getQuaternion());
        System.out.println("t :"+t.getQuaternion());
        System.out.println("b :"+b.getQuaternion());

When I execute this code it prints these Quaternions:


boxG: (0.0, 0.7071068, 0.7071068, 0.0)
t :(NaN, NaN, NaN, NaN)
b :(0.0, 0.0, 0.0, 1.0)

Why is t = (NaN, NaN, NaN, NaN) - It doesn’t look correct, but the Box is transformed anyways … correctly.

Arne

what happens if you add a t.setQuaternion in there I wounder?

What is the position for each?

Do you know what NaN means? It literally stands for Not a Number and normally means there is some problem with your simulation.

Will.

[quote]what happens if you add a t.setQuaternion in there I wounder?
[/quote]
I set t to (0,0.707,0.707,0), then it prints this:

boxG: (0.0, 0.7071068, 0.7071068, 0.0)
t :(0.0, 0.0, 0.0, 1.0)
b :(0.0, 0.70710677, 0.70710677, 0.0)

This is strange, because it is still transformed like when not using t.setQuaternion(0.0, 0.7071068, 0.7071068, 0.0) - at least it looks like it, when I show it with RunDemo.

When I set t.setQuaternion(0,0,0,1) it’s the same output as by not setting it.

[quote] What is the position for each?
[/quote]
I’m not setting any positions so they’re all (0|0|0). I checked this also by printing them.

[quote] Do you know what NaN means? It literally stands for Not a Number and normally means there is some problem with your simulation.
[/quote]
Yeah, division by 0 or something like that. The only thing is, that the code I printed was all the code the constructer of my test class consistet of. Ok - I added t also to a Vector, for being able to show it with RunDemo.

Hi

I solved why I get all the NaN-values !!! I checked the odejava source and performed the transformations odejava is doing for my problem myself. It’s actually only the code of updataCachedTransform in GeomTransform.
I wrote this code:


        Quat4f g = new Quat4f(0,0.707f,0.707f,0); // the quaternion of the encapsulated geom
        Matrix4f mg = new Matrix4f();
        mg.set(g); //all rotations are transformed into matrices
        Quat4f b = new Quat4f(0,0,0,1); // the quaternion of the body
        Matrix4f mb = new Matrix4f();
        mb.set(b);
        b.mul(g);  // for comparing the different results I multiplied the quaternions
        mb.mul(mg); // and the matrices
        System.out.println(b); //printing the result of the Quaternion multiplication - the quat result is also transformed into a matrix
        System.out.println();
        Matrix4f res = new Matrix4f();
        res.set(b);
        System.out.println(res);
        System.out.println("--------------------------------");
//printing the result of the Matrix multiplication - the matrix result is also transformed into a quad - this is the way odejava does it
        Quat4f mres = new Quat4f();
        mb.get(mres);
        System.out.println(mres);
        System.out.println();
        System.out.println(mb);

I get this output:

(0.0, 0.7071068, 0.7071068, 0.0)

-1.0000002, 0.0, 0.0, 0.0
0.0, -1.1920929E-7, 1.0000001, 0.0
0.0, 1.0000001, -1.1920929E-7, 0.0
0.0, 0.0, 0.0, 1.0


(NaN, NaN, NaN, NaN)

-1.0000002, 0.0, 0.0, 0.0
0.0, -1.1920929E-7, 1.0000001, 0.0
0.0, 1.0000001, -1.1920929E-7, 0.0
0.0, 0.0, 0.0, 1.0

I think it is obvious, that the matrix isn’t transformed correctly into a quat.