如何显示100浮动立方体使用的DirectX或OpenGL? [英] How To Display 100 Floating Cubes Using DirectX OR OpenGL?
问题描述
我想显示〜100采用浮冰块的DirectX
或的OpenGL
。
I'd like to display ~100 floating cubes using DirectX
or OpenGL
.
我在寻找既一些示例源$ C $ C,或技术的详细介绍。我知道这种事情很容易让你实现3D大师在那里,但我有足够的麻烦,甚至一个多维数据集才能正确显示。
I'm looking for either some sample source code, or a description of the technique. I know this kind of thing is easy for you accomplished '3D' gurus out there but I have enough trouble getting even one cube to display correctly.
我梳理了网上有一个良好的系列教程,虽然他们谈论怎么办 3D
元,我找不到是如何的信息做大量的 3D
原语 - 立方
,领域
, 金字塔
等等。
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.
基本上......把你的$ C $下写一个函数多维数据集,那么就调用该函数的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 :)
这篇关于如何显示100浮动立方体使用的DirectX或OpenGL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!