動き回るいくつかの基本的な球をシミュレートするアプリケーションを構築しようとしています。
私が直面している問題は、実際に必要なときに、データがinitステートメントの外部の配列に割り当てられているように見えないことです。これは、パーティクルを含む配列を宣言した方法と関係がありますか。
さまざまなメソッドからアクセスできる構造体の配列を作成したいので、ファイルの上部の、使用したincludeステートメントの下に次のように入力します。
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;
};
配列を作成してそれにパーティクルを割り当てる初期化メソッドがあります
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