具有 3 个向量的 OpenGL 相机

发布于 2024-12-06 17:15:25 字数 722 浏览 1 评论 0原文

好的,所以我按照本教程来帮助我在 OpenGL 中制作相机: http://nehe.gamedev.net/data/articles/article.asp?article=08

所以我跟着它,经过一番挣扎,终于有了一个解决方案,我现在有 3 个向量代表 3我的相机的轴。

但问题是?我不知道如何使用该信息来实际获得正确的旋转/平移!我尝试使用 gluLookAt,使用相机的位置作为第一个参数,然后使用相机的 Z 轴作为目标,使用 Y 轴作为向上参数。结果是,无论我向上/向下/向左/向右移动,相机永远不会停止注视单个点,并且旋转行为更加奇怪......

我是否采取了完全错误的方法?我考虑过使用四元数以某种方式计算我需要的转换,但无法弄清楚如何获取我需要的参数/如何开始......本质上我只想要一个简单的类似 FPS 的相机开始,我可以四处移动,向上/向下和向两侧看(以前我基本上都可以工作,除了向上看然后转身时,旋转搞砸了......)

一般或特定的帮助将不胜感激!因为我已经为此工作了好几个小时,但情况并没有改善...

总而言之...我需要帮助制作一个可以偏航/俯仰/滚动的相机...而不会被卡住盯着一个点。

编辑: 好吧,显然按照正确的顺序旋转真的很有帮助!愚蠢的我。无论如何,我仍然有兴趣知道如何使用相机的三个轴来形成用于转换的四元数。

Okay, so I was following this tutorial to help me with making a camera in OpenGL: http://nehe.gamedev.net/data/articles/article.asp?article=08

So I followed it, and after some struggling, finally had a solution where I now had 3 vectors that represented the 3 axes of my camera.

The problem though? I can't figure out how to use that information to actually get the right rotations/translations! I tried using gluLookAt, using the camera's position for the first parameters, then the Z axis of the camera for the target, and the Y axis for the up parameters. The result is that the camera never stops looking at a single point, regardless if I move up/down/left/right, and rotations behave even more weirdly...

Am I taking the complete wrong approach? I've considered using quaternions to somehow calculate the transformations I need, but can't figure out how to get the parameters I need for it/ how to get started... essentially I just want a simple FPS-like camera to begin with, where I can move around, and look up/down and to the sides (previously I had it mostly working, except when looking up and then turning around, the rotation screwed up...)

General or specific help would be much appreciated! Because I've been working on this for hours and hours, and the situation just isn't improving...

To sum it up... I need help making a camera that can yaw/pitch/roll... without being stuck to staring at a single point.

EDIT:
Okay, so, apparently rotating in the correct order can really help out! Silly me. Regardless, I'd still be interested to know how if I could use the three axes of my camera to form a quaternion for my transformations.

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

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

发布评论

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

评论(1

梦醒灬来后我 2024-12-13 17:15:25

我尝试使用 gluLookAt,使用相机的位置作为第一个参数,然后使用相机的 Z 轴作为目标,使用 Y 轴作为向上参数。

第二组参数不是注视方向,而是注视位置。您需要获取相机位置并通过 Z 轴进行偏移,以获得您想要查看的方向的查看位置。

无论如何,我仍然有兴趣知道如何使用相机的三个轴来形成用于转换的四元数。

是的。将它们转换为矩阵,然后将矩阵转换为四元数。有许多在线资源解释了将旋转矩阵转换为四元数的过程。

I tried using gluLookAt, using the camera's position for the first parameters, then the Z axis of the camera for the target, and the Y axis for the up parameters.

The second set of parameters isn't the look-at direction, but the look-at position. You need to take the camera position and offset it by the Z-axis to get a look-at position in the direction you want to look in.

Regardless, I'd still be interested to know how if I could use the three axes of my camera to form a quaternion for my transformations.

Yes. You turn them into a matrix, then convert the matrix into a quaternion. There are many online resources that explain the process of converting a rotation matrix into a quaternion.

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