使用四元数沿球体表面移动

发布于 2024-09-29 07:34:03 字数 147 浏览 1 评论 0原文

我正在编写一个 3D 游戏,其中用户控制第一人称相机,并且运动被限制在球体的内表面。我已经设法限制运动,但我无法弄清楚如何使用四元数管理相机方向。理想情况下,相机向上矢量应沿着球体的法线指向其中心,并且用户应该能够自由环顾四周 - 就好像我们始终位于球体的底部,无论他移动到哪里。

I'm programming a 3D game where the user controls a first-person camera, and movement is constrained to the inside surface of a sphere. I've managed to constrain the movement, but I'm having trouble figuring out how to manage the camera orientation using quaternions. Ideally the camera up vector should point along the normal of the sphere towards its center, and user should be able to free look around - as if we was always on the bottom of the sphere, no matter where he moves.

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

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

发布评论

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

评论(2

笑叹一世浮沉 2024-10-06 07:34:04

四元数通常用于避免自由空间运动中的万向节锁定(飞行模拟等)。就您而言,您实际上想要万向节效果,因为被迫保持直立的相机在必须几乎笔直向上或向下指向时不可避免地会表现得很奇怪。

您应该能够将相机的方向表示为仅指示相机指向的方向的纬度/经度对。

Quaternions are normally used to avoid gimbal lock in free space motion (flight sims, etc.). In your case, you actually want the gimbal effect, since a camera that is forced to stay upright will inevitably behave strangely when it has to point almost straight up or down.

You should be able to represent the camera's orientation as just a latitude/longitude pair indicating the direction the camera is pointing.

云淡月浅 2024-10-06 07:34:03

假设您有两个描述相机方向的向量。一个是您的 V'up,描述相对于相机方向的向上方向,另一个是您的 V'norm 这将是相机瞄准的方向。您还会有一个位置 p',您的相机在某个时间所处的位置。您可以定义一个规范的方向和位置,例如:

Vup = <0, 1, 0>
Vnorm = <0, 0, 1>
p = <0, -1, 0>

给定一个四元数旋转 q,然后将旋转应用于这些向量以获得:

V'up = qVupq-1
V'norm = qVnormq-1
p' = qpq-1

在您的特定情况下,您定义 q 来增量累积导致最终旋转的各种旋转您应用到相机。效果将是它看起来像你所描述的那样。也就是说,您在静态定向和定位的球体内移动相机,而不是在静态定向和定位的相机周围移动球体。

每个增量都是通过围绕向量旋转某个角度 θ 来计算的 V = V'up x V'<子>规范

Presumably you have two vectors describing the camera's orienation. One will be your V'up describing which way is up relative to the camera orientation and the other will be your V'norm which will be the direction the camera is aimed. You will also have a position p', where your camera is located at some time. You define a canonical orientation and position given by, say:

Vup = <0, 1, 0>
Vnorm = <0, 0, 1>
p = <0, -1, 0>

Given a quaternion rotation q you then apply your rotation to those vectors to get:

V'up = qVupq-1
V'norm = qVnormq-1
p' = qpq-1

In your particular situation, you define q to incrementally accumulate the various rotations that result in the final rotation you apply to the camera. The effect will be that it looks like what you're describing. That is, you move the camera inside a statically oriented and positioned sphere rather than moving the spehere around a statically oriented and positioned camera.

Each increment is computed by a rotation of some angle θ about the vector V = V'up x V'norm.

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