glulookat() 用法-opengl 和 C++

发布于 2024-12-23 06:58:19 字数 329 浏览 1 评论 0原文

0你能帮我解决这个场景吗:我有一个 3D 世界,我想以第一人称方式定位相机(真正的目的是在穿越小行星时从宇宙飞船内部的第一人称视图腰带)。在这种情况下 glulookat 的参数是什么?我想:

gluLookAt(30, 30, 30, 0, 0, 0, 0, 1, 0);//the up vector would be normal y axis

这样的说法正确吗?

另外,如果我想让相机随着船一起移动,该怎么做?当移动船时,我还应该从 glulookat 移动“眼睛”坐标?像眼睛坐标(glulookat 的前 3 个参数)之类的东西应该与船坐标相同吗?

0Could you please help me out with this scenario: I have a 3D world, and I want to position the camera in a first-person manner( the real purpose would be a first-person view from inside a spaceship, while travelling through an asteroid belt). What would be the parameters for glulookat in this case? I thought of:

gluLookAt(30, 30, 30, 0, 0, 0, 0, 1, 0);//the up vector would be normal y axis

Would this be correct?

Also if I want the camera to move along with the ship, how would that be done? When moving the ship I should also move the "eye" coordinates from glulookat? Something like the eye coordinates(the first 3 parametres of glulookat) should be the same with the ship coordinates?

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

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

发布评论

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

评论(1

川水往事 2024-12-30 06:58:19

您建议的 gluLookAt 调用会将相机定位在 (30,30,30) 并将其指向原点。

gluLookAt(Ship_Position_X,Ship_Position_Y,Ship_Position_Z,
          Ship_Forward_X,Ship_Forward_Y,Ship_Forward_Z,
          0,1,0);

这更像是你所需要的。您必须在每一帧中调用它,以便相机能够跟随船舶的运动。如果你想让船做桶滚,你必须有额外的变量来跟踪向上向量。

我喜欢有某种结构来保存坐标,以便我可以重载 gl 函数来获取它们并编写更短的函数调用,例如

// roll your own glVec, or use a co-ordinate class provided by a library you happen to be using.
inline void gluLookAt(glVec position, glVec forward, glVec up)
{
    gluLookAt(position.x,position.y,position.z,forward.x,forward.y,forward.z,up.x,up.y,up.z);
}

The gluLookAt call you propose would position the camera at (30,30,30) and point it at the origin.

gluLookAt(Ship_Position_X,Ship_Position_Y,Ship_Position_Z,
          Ship_Forward_X,Ship_Forward_Y,Ship_Forward_Z,
          0,1,0);

This is more like what you need. You'll have to call it every frame so that the camera will follow the ship's movement. If you want the ship to do a barrel roll, you'll have to have additional variables to track the up vector.

I like to have some kind of struct to hold co-ordinates so that I can overload gl functions to take them and write shorter function calls, e.g.

// roll your own glVec, or use a co-ordinate class provided by a library you happen to be using.
inline void gluLookAt(glVec position, glVec forward, glVec up)
{
    gluLookAt(position.x,position.y,position.z,forward.x,forward.y,forward.z,up.x,up.y,up.z);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文