在 opengl-c++ 中创建 3D 游戏表面/游戏板

发布于 2024-12-23 06:09:38 字数 494 浏览 3 评论 0原文

我正在尝试使用 OpenGl 创建一个 3D 盒子,它将在 C++ 中扮演 3D 游戏的游戏板/表面/房间的角色。作为起点,我找到了一些针对 2D 表面执行此操作的代码。我的问题是如何修改以下代码来达到我的目的:

for (float  i = -width; i + 0.1 <= width; i += 0.1) {
    for (float j = -height; j + 0.1 <= height; j+= 0.1) {
        glBegin(GL_QUADS);

        glNormal3f(0, 1, 0);
        glVertex3f(i, 0, j);
        glVertex3f(i, 0, j + 0.1);
        glVertex3f(i + 0.1, 0, j + 0.1);
        glVertex3f(i + 0.1, 0, j);

        glEnd();
    }
}

非常感谢。

I am trying to create a 3D box, that would play the role of a playing board/surface/room for a 3D game in C++, using OpenGl. As a starting point I found some code that does that for a 2D surface. My question would be how to modify the following code to serve my purpose:

for (float  i = -width; i + 0.1 <= width; i += 0.1) {
    for (float j = -height; j + 0.1 <= height; j+= 0.1) {
        glBegin(GL_QUADS);

        glNormal3f(0, 1, 0);
        glVertex3f(i, 0, j);
        glVertex3f(i, 0, j + 0.1);
        glVertex3f(i + 0.1, 0, j + 0.1);
        glVertex3f(i + 0.1, 0, j);

        glEnd();
    }
}

Thanks a lot.

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

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

发布评论

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

评论(1

¢好甜 2024-12-30 06:09:38

您可以使用上述代码 6 次,但每次应用不同的旋转/平移矩阵,或者您可以以正确的方式执行此操作,并为盒子中缺少的 5 面墙生成正确的几何图形。有很多用于绘制立方体的示例,即:

http:// /www.opengl.org/resources/code/samples/glut_examples/examples/examples.html

You can either use above code 6 times but each time apply different rotation/translation matrix, or you can do it the right way and generate correct geometry for missing 5 walls of your box. There are lots of samples for drawing cubes, ie.:

http://www.opengl.org/resources/code/samples/glut_examples/examples/examples.html

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