且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用 DirectX 或 OpenGL 显示 100 个浮动立方体

更新时间:2023-11-08 12:01:52

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

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 :)