使用四元数的 iPhone GLGravity 示例

发布于 2024-08-26 04:46:44 字数 123 浏览 2 评论 0 原文

GLGravity iPhone 示例展示了如何使用加速度计和 OpenGL,但遇到了万向节锁定问题。我想知道是否有任何代码可以使用四元数旋转而不是欧拉角?任何帮助将不胜感激,我长期以来一直在努力解决这个问题,但没有成功......

GLGravity iPhone example showing how to use accelerometer and OpenGL suffers from Gimbal Lock problem. I'm wondering is there any code available using quaternion rotation instead of Euler angles? Any help will be greatly appreciated, I'm struggling with this from a long time without having a success ...

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

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

发布评论

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

评论(1

帥小哥 2024-09-02 04:46:44

在尝试自己实施和使用事物理论之前,它有助于很好地掌握事物的理论。下面是两篇关于使用四元数进行旋转的介绍性文章。两者主要与平滑旋转插值和避免累积旋转中的万向节锁定有关:

Gamedev.net -四元数幂

Gamasutra - 使用四元数旋转对象

现在,就实际代码而言,我建议获取并使用“行业实力”向量数学库,而不是自行构建。我的建议是抓住 Bullet 物理中间件项目的 LinearMath 部分。 Bullet 物理以及随附的线性数学库由索尼的一些顶级工程师开发,并且已经积极开发多年。它是免费提供的,不受任何许可证(Zlib许可证)的限制,并且被世界各地的专业游戏开发者使用。该库是跨平台/架构的,可以在从 iPhone 到 PS3 的任何设备上编译。

该库提供了四元数< /a> 类,允许您从欧拉角或绕任意轴旋转创建四元数,例如使用 setEulerZYX。一旦你有了四元数,就会有适用于它们的所有常见操作的内置函数;加、减、乘、归一化、slerp 等等。

为了实际将最终四元数应用于 OpenGL 渲染,Transform 类允许您从四元数构造矩阵。转换类又包含一个函数 getOpenGLMatrix 直接为您提供一个兼容的矩阵以传递给 OpenGL。

该库还包括许多其他非常有用的矩阵和向量类和函数。

google 代码 获取最新的项目符号分布,或仅获取 LinearMath 部分直接从 subversion 获取代码:svn checkout http://bullet.googlecode.com/svn/trunk/src/LinearMath

It helps to have a good grasp of the theory of things before trying to implement and use it oneself. Below are two introductory articles about using Quaternions for rotations. Both are primarily related to smooth rotation interpolations and avoiding gimbal lock in accumulated rotations:

Gamedev.net - Quaternion Powers

Gamasutra - Rotating Objects Using Quaternions

Now as far as actual code goes, I would suggest getting, and using, an "industry strength" vector math library as opposed to rolling your own. My suggestion would be grabbing the LinearMath part of the Bullet Physics Middleware project. Bullet physics, and the included linear math library, is developed by some of Sony's top engineers and has been in active development for years. It's freely available, not restricted by any license (Zlib license), and is used by professional game developers all over the world. The lib is cross platform/architecture and compiles on anything from iPhone to PS3.

The lib offers a Quaternion class that allows you to create quaternions from euler angles or from rotation about an arbitrary axis, e.g. using setEulerZYX. Once you have your quaternions, there are built in functions for all common operations applicable to them; plus, minus, mul, normalize, slerp and much more.

For actually applying your final quaternion to OpenGL rendering, the Transform class allows you to construct a matrix from a quaternion. The transform class in turn includes a function getOpenGLMatrix that directly gives you a compatible matrix to pass to OpenGL.

The lib also includes a host of other very useful matrix and vector classes and functions.

Grab the latest Bullet dist from google code, or grab just the LinearMath portion of the code directly from subversion using: svn checkout http://bullet.googlecode.com/svn/trunk/src/LinearMath

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