您的位置:首页 > 其它

Confuse about hkQuaternion and hkRotation

2015-08-17 06:46 459 查看
Hi guys

I really have some confuse about the hkQuaternion and hkRotation

1.First, I have a quat like this
[code]1
hkQuaternion
quat;
2
quat.setAxisAngle(hkVector4(0,
1, 0), HK_REAL_PI / 4.0f);
[/code]

Then, I want use a hkRotation to instead of this quat,
[code]01
hkVector4
offset; offset.
set
(1,0,0);
02
offset.setRotatedDir(
quat, offset);
03
04
hkRotation
rotation;
05
hkVector4&
col0 = rotation.getColumn(0);
06
hkVector4&
col1 = rotation.getColumn(1);
07
hkVector4&
col2 = rotation.getColumn(2);
08
09
hkVector4
surfaceNorm;
10
surfaceNorm
= hkVector4(0,1,0);
11
 
12
col1
= surfaceNorm ;
13
col2.setCross(
col1, offset);
14
col2.normalize3();
15
col0.setCross(
col1, col2 );
[/code]

But when I get the new hkQuaternion from this hkRotation
[code]1
hkQuaternion
temp;temp.
set
(rotation);
[/code]

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?

RSSTop

2 posts / 0 new
Last post

Best Reply

For more complete information about compiler optimizations, see our Optimization Notice.



Log
In to post comments

havokchrisk

Mon, 09/13/2010 - 11:31

BEST REPLY

Hey duotemplar,

To answer your questions:

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:

[code]1
col0
= offset;
2
col1
= surfaceNorm;
3
col2.setCross(col1,
col0);
4
col2.normalize3();
5
col1.setCross(col0,
col2);
[/code]

To convert an hkQuaternion inito an hkRotation, you could do something like this:

[code]1
hkQuaternion
quat;
2
hkRotation
rot;
3
rot.
set
(quat);
[/code]

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: