在 OGRE 中获取对象方向

发布于 2024-10-12 11:50:56 字数 525 浏览 5 评论 0原文

我有一个有身体和头部的角色。头部作为骨头与身体相连,我已经知道骨头的名字了。现在我想知道头部的方向?这可能吗?我尝试了这个,但它似乎不起作用:

Entity *smith = m_sceneManager->getEntity("Smith");
Bone *head = smith->getSkeleton()->getBone("Bip01 Head");
Vector3 direction = head->_getDerivedOrientation() * Vector3::UNIT_X;
std::cout << StringConverter::toString(direction) << std::endl;

我认为我应该乘以除单位 x 向量之外的其他值,所以我尝试了所有组合。在这种情况下(即史密斯实体),我使用 -Vector3::UNIT_X 得到了正确的答案,所以我认为这是正确的解决方案。我尝试与其他实体联系,但未能得到正确答案。

有什么想法吗?

I have a character with a body and head. The head is connected to the body as a bone and I already know the name of the bone. Now I want to get the direction of the head? Is that possible? I tried this but it doesn't seem to work:

Entity *smith = m_sceneManager->getEntity("Smith");
Bone *head = smith->getSkeleton()->getBone("Bip01 Head");
Vector3 direction = head->_getDerivedOrientation() * Vector3::UNIT_X;
std::cout << StringConverter::toString(direction) << std::endl;

I thought I should multiply by other than the unit x vector, so I tried all the combinations. In this case (i.e. Smith entity), I got the correct answer using -Vector3::UNIT_X, so I thought this is the correct solution. I tried with other entities, but I failed to get the correct answer.

Any idea?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

农村范ル 2024-10-19 11:50:56

将四元数乘以负 Z 应该正确返回方向作为向量:

Vector3 direction = head->_getDerivedOrientation() * Vector3::NEGATIVE_UNIT_Z;

请参阅 this在 Ogre 论坛上发帖。

Multiplying a quaternion by negative Z should correctly return the direction as a vector:

Vector3 direction = head->_getDerivedOrientation() * Vector3::NEGATIVE_UNIT_Z;

See this post on the Ogre forums.

玩心态 2024-10-19 11:50:56
// get orientation as a quaternion
const Ogre::Quaternion quaternion = head->_getDerivedOrientation();

// convert orientation to a matrix
Ogre::Matrix3 matrix3;
quaternion.ToRotationMatrix( matrix3 );

/// get euler angles from the matrix
Radian x; 
Radian y; 
Radian z;
matrix3.ToEulerAnglesXYZ( x, y, z );

// place euler angles into a vector
Ogre::Vector3 direction( x.valueRadians(), y.valueRadians(), z.valueRadians() );

我怀疑以下内容也将起作用。

// get orientation as a quaternion
const Ogre::Quaternion q = head->_getDerivedOrientation();

// use pitch, yaw, and roll as values for direction vector
const Ogre::Vector3 direction( q.getPitch(), q.getYaw(), q.getRoll() );
// get orientation as a quaternion
const Ogre::Quaternion quaternion = head->_getDerivedOrientation();

// convert orientation to a matrix
Ogre::Matrix3 matrix3;
quaternion.ToRotationMatrix( matrix3 );

/// get euler angles from the matrix
Radian x; 
Radian y; 
Radian z;
matrix3.ToEulerAnglesXYZ( x, y, z );

// place euler angles into a vector
Ogre::Vector3 direction( x.valueRadians(), y.valueRadians(), z.valueRadians() );

I suspect the following will also work.

// get orientation as a quaternion
const Ogre::Quaternion q = head->_getDerivedOrientation();

// use pitch, yaw, and roll as values for direction vector
const Ogre::Vector3 direction( q.getPitch(), q.getYaw(), q.getRoll() );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文