Confuse about hkQuaternion and hkRotation

来源:互联网 发布:网络依赖症的发展过程 编辑:程序博客网 时间:2024/04/28 19:53

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

1.First, I have a quat like this

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

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

01hkVector4 offset; offset.set(1,0,0);
02offset.setRotatedDir( quat, offset);
03 
04hkRotation rotation;
05hkVector4& col0 = rotation.getColumn(0);
06hkVector4& col1 = rotation.getColumn(1);
07hkVector4& col2 = rotation.getColumn(2);
08 
09hkVector4 surfaceNorm;
10surfaceNorm = hkVector4(0,1,0);
11             
12col1 = surfaceNorm ;
13col2.setCross( col1, offset);
14col2.normalize3();
15col0.setCross( col1, col2 );

But when I get the new hkQuaternion from this hkRotation

1hkQuaternion 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.
 
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:

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

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.

Chris

Developer Support Engineer
Havok
www.havok.com

0 0
原创粉丝点击