Hi all,
Having a little trouble with assigning values to an array within a C struct. Unfortunately i cannot assign a size to the array as i am reading values to an array to be stored, and the size is relative to the other values in the struct passed to createGeo(); the function.
The issue here is the float *coords - which i want to be filled with values in the createGeo() function.
typedef struct geom{
float dimen[3];//width, height, length
int totalQuads;
float *coords;
GLubyte indices[];
}geo;
geo Base;
void createGeo(geo inst);
int main(int argc, char *argv[])
{
Base.dimen[0] = 11;
Base.dimen[1] = 0.15;
Base.dimen[2] = 44;
createGeo(Base);
system("PAUSE");
return 0;
}
void createGeo(geo inst)
{
int i,j;
int jump = 0;
//find total of vertices required - div by 1
//int x_div = inst.dimen[0]/inst.dimen[0];
//int z_div = inst.dimen[2]/inst.dimen[2];
inst.totalQuads = (inst.dimen[0] * inst.dimen[2]) * 4;
//indices array
for(i = 0; i < inst.totalQuads; i++)
{
inst.indices[i] = i;
}
//assign memory
inst.coords = malloc(inst.totalQuads * 3 * sizeof(float));
//perhaps i should turn this into local array
//now make geom -
//length form - to 0
for(i = -inst.dimen[2]; i < 0; i++)
{
for(j = 0; j < inst.dimen[0]; j++)
{
inst.coords[0+jump][j][0] = j;
inst.coords[1+jump][j][1] = 0;
inst.coords[2+jump][j][2] = i;
inst.coords[3+jump][j][0] = j;
inst.coords[4+jump][j][1] = 0;
inst.coords[5+jump][j][2] = i;
inst.coords[6+jump][j][0] = j;
inst.coords[7+jump][j][1] = 0;
inst.coords[8+jump][j][2] = i;
inst.coords[9+jump][j][0] = j;
inst.coords[10+jump][j][1] = 0;
inst.coords[11+jump][j][2] = i;
jump++;
}
}
}
The solution is probably something really straightforward but i can't seem to get anywhere. Perhaps i should add the values to a internal float array and then do
inst.coords = my_array;
Grateful for your help!
Thanks!