我正试图构建一个应用程序来模拟一些移动的基本球体。使用OpenGL和GLFW处理C数组
我面临的问题是,它看起来不像是在我真正需要的时候将数据分配给init语句之外的数组。这与我声明包含粒子的数组的方式有关。
我想创建可以从各种方法来访问结构数组所以在我已经使用了包括以下声明我的文件的开头:
struct particle particles[];
// Particle types
enum TYPES { PHOTON, NEUTRINO };
// Represents a 3D point
struct vertex3f
{
float x;
float y;
float z;
};
// Represents a particle
struct particle
{
enum TYPES type;
float radius;
struct vertex3f location;
};
我有创建数组的INITIALISE方法和分配颗粒它
void init(void)
{
// Create a GLU quadrics object
quadric = gluNewQuadric();
struct particle particles[max_particles];
float xm = (width/2) * -1;
float xp = width/2;
float ym = (height/2) * -1;
float yp = height/2;
int i;
for (i = 0; i < max_particles; i++)
{
struct particle p;
struct vertex3f location;
location.x = randFloat(xm, xp);
location.y = randFloat(ym, yp);
location.z = 0.0f;
p.location = location;
p.radius = 0.3f;
particles[i] = p;
}
}
然后平局方法内绘制集场景的方法
// Draws the second stage
void drawSecondStage(void)
{
int i;
for (i = 0; i < max_particles; i++)
{
struct particle p = particles[i];
glPushMatrix();
glTranslatef(p.location.x , p.location.y, p.location.z);
glColor3f(1.0f, 0.0f, 0.0f);
gluSphere(quadric, 0.3f, 30, 30);
glPopMatrix();
printf("%f\n", particles[i].location.x);
}
}
这里是我的代码http://pastebin.com/m131405dc
非常感谢您的回答 - 并深入您的工作。 谢谢! – Malachi 2009-04-29 11:53:29