Mail Archives: djgpp/1999/07/19/08:00:57
Paul J G wrote in message <7mv0te$gq2$1 AT news6 DOT svr DOT pol DOT co DOT uk>...
>Hi Guys, I really need some help big time on this one, can anyone help put
>me out of my misery ?.
I'll attempt to.
>Right, I have a structure in my program:
>
>struct { float xpoint[9],float ypoint[9] } shape[10];
>
>Fine it works, everythings OK, but now I want to be able to increase the
>amount of data used by xpoint and ypoint while still using the SHAPE
>identifier.
>eg. shape[1] will be xpoint[9],ypoint[9], shape[2] will be
>xpoint[25],ypoint[25],
> shape[3] will be xpoint[3],ypoint[3] etc.....
>However I cannot just allocate a big variable as shape[1] could be just 3
>and
>shape[2] could be 8000.
>I still want to be able to use my - shape[ whatever ].xpoint[ whatever ] -
>code.
>Not knowing what the varibles xpoint, ypoint, will be at compilation time
>they must be dynamically
>allocated, as the file length for each shape could vary.
>The idea being that I can load my 3d objects into the shape varibles.
Something like this ?
struct {
int num_pts;
float *xpoint;
float *ypoint;
float *zpoint;
} shape[10];
void set_size (int shape_no, int num_points) {
if (shape_no < 0 || shape_no >= 10) return;
num_pts = num_points;
shape[shape_no].xpoint = (float *) malloc (sizeof (float) * num_points);
shape[shape_no].ypoint = (float *) malloc (sizeof (float) * num_points);
shape[shape_no].zpoint = (float *) malloc (sizeof (float) * num_points);
}
(Note: You should check malloc worked)
...
set_size (0, 50);
for (int i = 0; i < 50; i++) {
shape[0].xpoint[i] = get_x (i);
shape[0].ypoint[i] = get_y (i);
shape[0].zpoint[i] = get_z (i);
}
...
This'll be fine if you will not have more than 10 shapes, if you want more
then you can allocate that dynamically.
None of the above has been tested, so there may be errors.
Michael Stewart
- Raw text -