如何使用 Glut 让相机飞过 OpenGL 中的对象?
首先,我的所有代码都可以在这里找到,它位于 3 个文件中。
flythrough.cpp,support.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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它是正交相机,因此您无法沿 Z 轴移动。您需要更改相机类型才能完成您想要做的事情。
参考:第 33 行,flythrough.cpp
通常,只需取消注释此行,然后编写以下内容:
这会将透视矩阵乘以当前加载的单位矩阵 (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
Typically, just uncomment this line, then write the following:
This will multiply a perspective matrix by the currently loaded identity matrix (LoadIdentity()).
Ref: http://www.opengl.org/sdk/docs/man/xhtml/gluPerspective.xml
在不尝试计算出轴的情况下,您是否尝试过沿 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.