如何使用 Glut 让相机飞过 OpenGL 中的对象?

发布于 2024-10-17 08:46:33 字数 595 浏览 1 评论 0原文

首先,我的所有代码都可以在这里找到,它位于 3 个文件中。

flythrough.cppsupport.cpp, support.h

好的...所以如果你运行这似乎有效,但有几件事确实困扰着我!

相机从一个奇怪的位置开始,我尝试改变各种变量,但似乎没有效果。

现在最大的问题是移动相机。此时...相机将左右移动,但不会向前或向后移动。当我尝试向前移动时,就像像素正在做正确的事情一样,当我向前移动时,该对象最终会消失,就像我已经移过它一样,但当我靠近时,对象本身并不会“显得更大”。向后移动也是如此。

如果您能想出任何办法,请告诉我。

我想补充一点,大部分代码来自我的教科书。经过我自己的修改。

谢谢!

First off, all of my code can be found here, it's in 3 files.

flythrough.cpp, support.cpp, support.h

Okay... so if you run that, it seems to work, but a few things are really bugging me!

The camera is starting off in a strange location, I try to change all kinds of variables, but it doesn't seem to have an effect.

The biggest issue right now is moving the camera. At this point in time... the camera WILL move left and right, but NOT forward or backward. When I try to move forward, it's like the pixels are doing the correct thing, the object will eventually vanish as I move forward, like I've moved past it, but the object itself is not "appearing larger" as I get closer. Same for moving backward.

Please let me know if you can come up with anything.

I'd like to add that a majority of this code comes from my textbook. With modifications from myself.

Thanks!

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

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

发布评论

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

评论(2

烟花易冷人易散 2024-10-24 08:46:33

它是正交相机,因此您无法沿 Z 轴移动。您需要更改相机类型才能完成您想要做的事情。

参考:第 33 行,flythrough.cpp

glOrtho(-2.0 * 64 / 48.0, 2.0 * 64 / 48.0, -2.0, 2.0, 100, 100.0);

通常,只需取消注释此行,然后编写以下内容:

gluPerspective(60.0, 640.0 / 480.0, 0.1, 1000.0);

这会将透视矩阵乘以当前加载的单位矩阵 (LoadIdentity())。

参考: http://www.opengl.org/sdk/docs/man /xhtml/gluPerspective.xml

Its an orthographic camera, therefore you cannot move along the Z axis. You need to change your camera type to do what your trying to do.

Ref: Line 33, flythrough.cpp

glOrtho(-2.0 * 64 / 48.0, 2.0 * 64 / 48.0, -2.0, 2.0, 100, 100.0);

Typically, just uncomment this line, then write the following:

gluPerspective(60.0, 640.0 / 480.0, 0.1, 1000.0);

This will multiply a perspective matrix by the currently loaded identity matrix (LoadIdentity()).

Ref: http://www.opengl.org/sdk/docs/man/xhtml/gluPerspective.xml

迷雾森÷林ヴ 2024-10-24 08:46:33

在不尝试计算出轴的情况下,您是否尝试过沿 Z 轴而不是 Y 轴前后移动相机。也许您的深度轴设置为 Z 而不是 Y。

Without trying to work out your axis, have you tried moving the camera back and forwards along the Z axis instead of Y. Perhaps your depth axis is setup to be Z not Y.

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