Bug in GeomTransform

Hmm… sounds like the Matrix4f is being populated with NaNS. The Matrix4f bug may be in the set(Quat4f q) method (instead or in addition to the bug in the get(Quat4f q) method). You could try implementing set(Quat4f q). The upper 3x3 is:

1 - 2qy2 - 2qz2 2qxqy - 2qzqw 2qxqz + 2qyqw
2qxqy + 2qzqw 1 - 2qx2 - 2qz2 2qyqz - 2qxqw
2qxqz - 2qyqw 2qyqz + 2qxqw 1 - 2qx2 - 2qy2

qy2, etc… == qy squared or qy*qy.

Ohh - I forgot to tell you:
The matrix created out of the rotation and translation from my function is the same as the one created by multiplying the two matrices.

I don’t know if RunDemo or OdejavaToXith is working correctly, because OdejavaToXith is doing something special with Geomtransforms I don’t understand. It adds another TransformGroup there. But shouldn’t GeomTransform automatically return the correct Position transformed by the body and the Geom?

And something else that I want to get sure of:
(0, 0.707, 0.707, 0) is a valid Quat4f, isn’t it? It get’s normalized to (0, 0.70710677, 0.70710677, 0) I’m asking, because (0, 0.707107, 0.707107, 0) gets also normalized to the same value, but it doesn’t create the NaNs. It creates a Quat4f of (0,0,0, …E-4)

… means I don’t know the exact numerals there.

Edit: I checked OdejavaToXith3D, but I think now, it works correctly.

Hi
I executed this code twice with only the modification of changing the b in line 10 to boxG and the boxG in line 12 to b:


1     Odejava.getInstance();
2     world = new World();
3     GeomBox boxG = new GeomBox(280, 60,240);
4     GeomTransform t = new MyGeomTransform();
5     t.setEncapsulatedGeom(boxG);
6     Body b = new Body("boxBody",world);
7     b.addGeom(t);
8     b.adjustMass(1);
9      
10    b.setQuaternion(new Quat4f(0,0,0,1));
11    boxG.setPosition(20, 600, 30);
12    boxG.setQuaternion(new Quat4f(0,0.7071068f,0.7071068f,0));
13    geoms.add(t);
14    System.out.println("boxG: "+boxG.getQuaternion());
15    System.out.println("t :"+t.getQuaternion());
16    System.out.println("b :"+b.getQuaternion());
17    System.out.println("Transform: "+t.getTransform());
18    System.out.println("Rotation: "+t.getRotation());
19    System.out.println("axisA: "+t.getAxisAngle());
20    System.out.println();
21    System.out.println("boxG: "+boxG.getPosition());
22    System.out.println("t :"+t.getPosition());
23    System.out.println("b :"+b.getPosition());

[tr][td]
without modification:
boxG: (0.0, 0.70710677, 0.70710677, 0.0)
t :(0.0, 0.70710677, 0.70710677, 0.0)
b :(0.0, 0.0, 0.0, 1.0)
Transform: -0.9999999, 0.0, 0.0, 20.0
0.0, 5.9604645E-8, 0.99999994, 600.0
0.0, 0.99999994, 5.9604645E-8, 30.0
0.0, 0.0, 0.0, 1.0

Rotation: -0.9999999, 0.0, 0.0
0.0, 5.9604645E-8, 0.99999994
0.0, 0.99999994, 5.9604645E-8

axisA: (0.0, 0.70710677, 0.70710677, 3.1415927)

boxG: (20.0, 600.0, 30.0)
t :(20.0, 600.0, 30.0)
b :(0.0, 0.0, 0.0)

-> Box is rotated.
[/td][td]
with modification:
boxG: (0.0, 0.0, 0.0, 1.0)
t :(0.0, 0.70710677, 0.70710677, 0.0)
b :(0.0, 0.70710677, 0.70710677, 0.0)
Transform: -0.9999999, 0.0, 0.0, 403.05087
0.0, 5.9604645E-8, 0.99999994, -14.142136
0.0, 0.99999994, 5.9604645E-8, 14.142136
0.0, 0.0, 0.0, 1.0

Rotation: -0.9999999, 0.0, 0.0
0.0, 5.9604645E-8, 0.99999994
0.0, 0.99999994, 5.9604645E-8

axisA: (0.0, 0.70710677, 0.70710677, 3.1415927)

boxG: (20.0, 600.0, 30.0)
t :(403.05087, -14.142136, 14.142136)
b :(0.0, 0.0, 0.0)

-> Box is not rotated.
[/td][/tr]
The position of the Box is in both cases the same.

I think this is totally strange espacially because the rotation-output does not show any signs, that there might be differences, but RunDemo shows different rotations.
The positions are different, but RunDemo shows the same position.

My only conclusion is, that I’ve misunderstood something, or rundemo is not working correctly.

PS: The updateCachedTransform is used. I’ve checked that.

Ok I’ve solved now why it wasn’t shown correctly :slight_smile: I called world.step() and that somehow resetted the rotation of the body. Now I can start checking for errors in my transformation code :).

Hi
I wrote now some code to do the multiplication of the translations. I use a matrix to transform the translation, but I simply multiply the Quats to get the result Quat.


        this.getBody().getQuaternion(tmpQuat);
        this.getEncapsulatedGeom().getPosition(position);
        cachedBodyTransform.setIdentity();
        cachedBodyTransform.set(tmpQuat);
        cachedBodyTransform.transform(position);
        this.getBody().getPosition(tmpPos);
        position.add(tmpPos);
        
        this.getEncapsulatedGeom().getQuaternion(rotation);
        this.getBody().getQuaternion(tmpQuat);
        rotation.mul(tmpQuat);

I think this is a good workaround for the bug ;D, but I haven’t been able to test it completely :(. I’d like to know if it also works for you.

Arne

PS: I have created a subclass of GeomTransform, to do this, because I wasn’t able to compile the odejava src - something with the xode stuff sucked - It wasn’t able to find some Classes there. It would be good if someone did the changes also to the GeomTransform directly.

Edit: I also think this way not so much garbage gets created.

Holy crap - it’s no bug at all - at least it shows correctly, when Joints are used and the simulation proceeds - the code I wrote doesn’t work there. So I’m going back to using the old GeomTransform - And with having one big mystery more …