5
$\begingroup$

I'm trying to convert hierachical rotation matrices (from a Kinect) to manipulate a mesh in the game engine.

enter image description here

I was trying to change the Quaternion values like:

  qt.w = qr.w
  qt.x = qr.x
  qt.y = -qr.z
  qt.z = qr.y

Should this work mathematicaly?

My models joints jump randomly around (this with having only a few matrices changed from idendity to have a chance while debugging): enter image description here

enter image description here

$\endgroup$
2
  • $\begingroup$ My intuition is that's not mathematically correct. Did you tried using the to_euler() and to_quaternion() functions ? $\endgroup$
    – Polosson
    Dec 1, 2013 at 23:13
  • $\begingroup$ Are you adjusting for the fact that the bones x,y,z are local to the bone, not matching global x,y,z? $\endgroup$
    – sambler
    Dec 3, 2013 at 3:55

1 Answer 1

4
$\begingroup$

I'm not into quats at all, but here's something I noticed, which may or may not be of any use.

Swap y and z in a matrix and look at the quat:

>>> Matrix(((1,0,0,0),(0,1,0,0),(0,0,1,0),(0,0,0,1))).to_quaternion()
Quaternion((1.0, 0.0, 0.0, 0.0))

>>> Matrix(((1,0,0,0),(0,0,1,0),(0,1,0,0),(0,0,0,1))).to_quaternion()
Quaternion((0.9999999403953552, 0.0, 0.0, 0.0))

# both matrices give different orientations, but not the quats!

And here's a custom space matrix:

>>> Matrix(((1,0,0,0),(0,0,-1,0),(0,1,0,0),(0,0,0,1))).to_quaternion()
Quaternion((0.7071068286895752, 0.7071068286895752, 0.0, 0.0))

>>> Matrix(((1,0,0,0),(0,0,1,0),(0,-1,0,0),(0,0,0,1))).to_quaternion()
Quaternion((0.7071068286895752, -0.7071068286895752, 0.0, 0.0))

Note the difference 1.0 / 0.0 vs. 0.7 / 0.7 (whereas the matrices are normalized, with using zeroes and ones only) - it might not be enough to negate the sign of a quat component.

I suggest you create a custom matrix for the space conversion and cast it to quat.

$\endgroup$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .