私はいくつかの基本的な球体をシミュレートするアプリケーションを構築しようとしています。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;
};
私は配列を作成する初期化メソッドを持っていますそして、drawメソッドの内部で、それ
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