如何改变cocos3d中的旋转顺序

发布于 2024-12-25 02:54:50 字数 238 浏览 5 评论 0原文

我是cocos3d的新手,现在遇到一个问题。

在cocos3d中,我想旋转一个节点。我得到了x轴、y轴、z轴的角度,然后我使用属性:rotation来旋转,像这样:

theNodeToBeRotated.rotation = cc3v(x,y,z);

但是我发现它没有按照我的预期旋转,因为文档说旋转顺序是yxz。

我想将顺序更改为 xyz。谁能告诉我怎么做吗?

I'm a fresh in cocos3d, now I have a problem.

In cocos3d, I want to rotate a node. I got the angles in x axis, y axis, z axis, then I used the property:rotation to rotate, like this:

theNodeToBeRotated.rotation = cc3v(x,y,z);

But I found out it didn't rotate as I expected, because the document said the rotate order is y-x-z.

I want to change the order to x-y-z. Can anyone let me know how?

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

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

发布评论

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

评论(1

路弥 2025-01-01 02:54:50

您可能需要进一步澄清以下内容:“它没有按我预期的方式旋转”

OpenGL ES(因此,cocos3D)使用 y 轴向上,因此旋转顺序仍然是 xyz。如果您要导入模型,则需要考虑 3D 编辑器的坐标系并进行相应调整。

如果您不习惯使用三维表示,从 2D 到 3D 的跨越可能是一个重大障碍。在 Cocos3D 中:

  • x 轴右侧为正,左侧为负
  • y 轴向上为正,向下为负
  • z 轴朝你移动为正,远离你为负

设想这三条轴,或者更好的是,一根绳子。

如果您绕 x 轴旋转,请从左到右水平握住绳子:物体会朝您旋转或远离您旋转。

如果你绕 y 轴旋转,从脚到头垂直握住绳子:物体会像旋转门一样旋转。

如果您绕 z 轴旋转,请将一端靠近胸部,另一端尽可能远离:物体会像钟面一样旋转。

-- 更新

我强烈不建议更改旋转顺序,因为使用 YXZ 是 OpenGL 标准。如果您想修改它,请查看 CC3GLMatrixMath 并查找 kmMat4RotationYXZ - 还有 kmMat4RotationZYX。如果您想要 XYZ,则需要构建自己的旋转矩阵并在 CC3GLMatrix 和 CC3GLMatrixMath 中进行相应更新。

作为参考,您还有 OpenGL 红皮书 - 它应该给你一些建议。

You might need to clarify further regarding the following: "it didn't rotate as I expected"

OpenGL ES (and ergo, cocos3D) uses the y-axis as up so the rotation order is still x-y-z. If you are importing a model, you then need to take into account the 3D editor's co-ordinate system and adapt accordingly.

If you are not used to working with three-dimensional representations, the leap from 2D to 3D can be a significant hurdle. Within Cocos3D:

  • the x-axis is positive on the right and negative on the left
  • the y-axis is positive upwards and negative downwards
  • the z-axis is positive moving towards you and negative moving away from you

Envisage those three lines of axis, or even better, a piece of string.

If you are rotating around the x-axis, hold the string horizontally from left to right: the object would rotating towards you or away from you.

If you are rotating around the y-axis, hold the string vertically from feet to head: the object would rotate as if like a revolving door.

If you are rotating around the z-axis, hold one end close to your chest and the other end as far away as possible: the object would rotate similar to a clock face.

-- Update

I heavily wouldn't recommend changing the rotation order as it is the OpenGL standard to use Y-X-Z. If you wish to modify it, take a look at CC3GLMatrixMath and look for kmMat4RotationYXZ - there is also kmMat4RotationZYX. If you want to have X-Y-Z, you would need to construct your own rotation matrix and update accordingly in CC3GLMatrix and CC3GLMatrixMath.

As a reference, you also have the OpenGL Red book - it should have some suggestions for you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文