I am trying to build an application to simulate some basic spheres moving around for this assignment I have got.
I am relatively new to C but I have been using .NET and java for some time.
The problem that i am facing is that it doesn't look like the data is being assigned to the array outside of the init statement when i actually need it. Is this somethingt to do with the way i've declared the array containing the particles.
I want to create an array of structs which can be accessed from various methods so at the top of my file below the include statements I have used:
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;
};
I have an initialise method which creates the array and assigns particles to it
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;
}
}
and then a inside a draw method a method to draw the set scene
// 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);
}
}
here's a copy of my code http://pastebin.com/m131405dc
Thanks in advanced!