使用 DirectX 或 OpenGL 显示 100 个浮动立方体 [英] Displaying 100 Floating Cubes Using DirectX OR OpenGL

查看:29
本文介绍了使用 DirectX 或 OpenGL 显示 100 个浮动立方体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 DirectXOpenGL 显示 100 个浮动立方体.

I'd like to display 100 floating cubes using DirectX or OpenGL.

我正在寻找一些示例源代码,或对该技术的描述.我无法正确显示更多的立方体.

I'm looking for either some sample source code, or a description of the technique. I have trouble getting more one cube to display correctly.

我已经在网上搜索了一系列很好的教程,虽然他们谈论如何制作 3D 基元,但我找不到关于如何制作大量 3D 基元 - cubesspherespyramids 等等.

I've combed the net for a good series of tutorials and although they talk about how to do 3D primitives, what I can't find is information on how to do large numbers of 3D primitives - cubes, spheres, pyramids, and so forth.

推荐答案

你说要显示一个立方体已经够麻烦了...所以我不确定你是否有一个要显示的.

You say you have enough trouble getting one cube to display... so I am not sure if you have got one to display or not.

基本上……将编写多维数据集的代码放在一个函数中,然后调用该函数 100 次.

Basically... put your code for writing a cube in one function, then just call that function 100 times.

void DrawCube()
{
    //code to draw the cube
}

void DisplayCubes()
{
    for(int i = 0; i < 10; ++i)
    {   
         for(int j = 0; j < 10; ++j)
         {
             glPushMatrix();
             //alter these values depending on the size of your cubes.
             //This call makes sure that your cubes aren't drawn overtop of each other
             glTranslatef(i*5.0, j*5.0, 0);
             DrawCube();
             glPopMatrix();
         }
    }              
}

这是您如何进行此操作的基本大纲.如果你想要更有效的东西,一旦你掌握了基础知识,就看看显示列表:)

That is the basic outline for how you could go about doing this. If you want something more efficient take a look into Display Lists sometime once you have the basics figured out :)

这篇关于使用 DirectX 或 OpenGL 显示 100 个浮动立方体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆