Confuse about hkQuaternion and hkRotation

Confuse about hkQuaternion and hkRotation

duotemplar's picture

Hi guys
I really have some confuse about the hkQuaternion and hkRotation

1.First, I have a quat like this

hkQuaternion quat;
quat.setAxisAngle(hkVector4(0, 1, 0), HK_REAL_PI / 4.0f);

Then, I want use a hkRotation to instead of this quat,

hkVector4 offset; offset.set(1,0,0);
offset.setRotatedDir( quat, offset);

hkRotation rotation;
hkVector4& col0 = rotation.getColumn(0);
hkVector4& col1 = rotation.getColumn(1);
hkVector4& col2 = rotation.getColumn(2);

hkVector4 surfaceNorm;
surfaceNorm = hkVector4(0,1,0);
col1 = surfaceNorm ;
col2.setCross( col1, offset); 
col0.setCross( col1, col2 );

But when I get the new hkQuaternion from this hkRotation

hkQuaternion temp;temp.set(rotation);

The new hkQuaternion is not the same like my initial hkQuaternion

I think I make sth wrong with this, but not know where and why.

2.How can I get the hkRotation from an exist hkQuaternion?

2 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.
havokchrisk's picture
Best Reply

Hey duotemplar,

To answer your questions:

  1. It looks like your math might be a bit off in converting a facing direction into an orothogonal rotation matrix (currently it doesn't look like any axis of your matrix aligns with your quaternion-rotated axis). You might try something like the following in place of lines 12-15 above:

    col0 = offset;
    col1 = surfaceNorm;  
    col2.setCross(col1, col0);
    col1.setCross(col0, col2);
  2. To convert an hkQuaternion inito an hkRotation, you could do something like this:
    hkQuaternion quat;
    hkRotation rot;

Also, please note that there can be multiple values of an hkQuaternion that correlate to the same hkMatrix3... so there may be times when you start with one quaternion, convert it to a rotation matrix, perform operations on it such that it ends up in its original rotation, convert it back to a quaternion, and you get a different quaternion from which you began. So the best way to verify the 'equality' of two quaternions is by using them to rotate a vector and checking the basic equality of the resulting vectors.


Developer Support Engineer

Login to leave a comment.