Horde3D
http://horde3d.org/forums/

Swap of rotations during joint tranformation
http://horde3d.org/forums/viewtopic.php?f=3&t=1855
Page 1 of 1

Author:  giacomo [ 15.01.2013, 16:14 ]
Post subject:  Swap of rotations during joint tranformation

Hi,
I was modifying the glfw example (for the Go bindings) and modifying some of the joints of the knight.
It happens that when a rotation get close to 90 deg rx and rz got swapped.
Here is the code I'm using to change the transformation:
Code:
if glfw.Key('O') == glfw.KeyPress {
        if num := horde3d.FindNodes(knight, "Bip01_Neck", horde3d.NodeTypes_Joint); num != 0 {
            head := horde3d.GetNodeFindResult(0)
            var tx, ty, tz, rx, ry, rz, sx, sy, sz float32
            horde3d.GetNodeTransform(head, &tx, &ty, &tz, &rx, &ry, &rz, &sx, &sy, &sz)
            horde3d.SetNodeTransform(head, tx, ty, tz, rx, ry, rz, sx, sy, sz)

        }
    }
    if glfw.Key('P') == glfw.KeyPress {
        if num := horde3d.FindNodes(knight, "Bip01_Neck", horde3d.NodeTypes_Joint); num != 0 {
            head := horde3d.GetNodeFindResult(0)
            var tx, ty, tz, rx, ry, rz, sx, sy, sz float32
            horde3d.GetNodeTransform(head, &tx, &ty, &tz, &rx, &ry, &rz, &sx, &sy, &sz)
            log.Printf("before: tx %f,ty %f,tz %f,rx %f,ry %f,rz %f,sx %f,sy %f,sz %f\n", tx, ty, tz, rx, ry, rz, sx, sy, sz)
            horde3d.SetNodeTransform(head, tx, ty, tz, rx, ry, rz, sx, sy, sz)
            log.Printf("after: tx %f,ty %f,tz %f,rx %f,ry %f,rz %f,sx %f,sy %f,sz %f\n", tx, ty, tz, rx, ry, rz, sx, sy, sz)

        }
   

and the logs:
Code:
2013/01/15 15:57:54 before: tx 9.184080,ty 0.000000,tz 0.003139,rx -86.450439,ry 22.060602,rz 0.000028,sx 1.000000,sy 0.999999,sz 0.999999
2013/01/15 15:57:54 after: tx 9.184080,ty 0.000000,tz 0.003139,rx -87.360443,ry 22.060602,rz 0.000028,sx 1.000000,sy 0.999999,sz 0.999999
2013/01/15 15:57:54 before: tx 9.184080,ty 0.000000,tz 0.003139,rx -87.360474,ry 22.060587,rz 0.000037,sx 1.000000,sy 0.999999,sz 0.999999
2013/01/15 15:57:54 after: tx 9.184080,ty 0.000000,tz 0.003139,rx -88.270477,ry 22.060587,rz 0.000037,sx 1.000000,sy 0.999999,sz 0.999999
2013/01/15 15:57:54 before: tx 9.184080,ty 0.000000,tz 0.003139,rx -88.270477,ry 0.000000,rz 22.051538,sx 1.000000,sy 0.999999,sz 0.999999
2013/01/15 15:57:54 after: tx 9.184080,ty 0.000000,tz 0.003139,rx -88.270477,ry 0.000000,rz 22.051538,sx 1.000000,sy 0.999999,sz 0.999999
2013/01/15 15:57:54 before: tx 9.184080,ty 0.000000,tz 0.003139,rx -88.270477,ry 0.000000,rz 22.051538,sx 1.000000,sy 0.999999,sz 0.999999
2013/01/15 15:57:54 after: tx 9.184080,ty 0.000000,tz 0.003139,rx -88.270477,ry 0.000000,rz 22.051538,sx 1.000000,sy 0.999999,sz 0.999999


The rotations swap does't happen again if the "rotation limit" is reached again.
Is this a bug or a known behavior?
As a workaround I'm keeping the rotation in (-87.0, 87.0).

Author:  Volker [ 15.01.2013, 22:54 ]
Post subject:  Re: Swap of rotations during joint tranformation

I guess that's probably a problem called gimble lock, that occures when calling h3dGetNodeTransform. Horde3D stores transformations internally as a matrix and not as the single transformation parameters. If you request them using h3dGetNodeTransform it tries to decompose the internal matrix. That's something that should be avoided, as it suffers from mathematical issues and is not very fast. You could either store the single transformation parameters by yourself, change them and pass them again to h3dSetNodeTransform, or you use whole matrices instead and pass them via h3dSetNodeTransMat (use h3dGetNodeTransMats to query the node's internal matrices).

Author:  giacomo [ 16.01.2013, 09:56 ]
Post subject:  Re: Swap of rotations during joint tranformation

I see.

Thanks for the help.

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/