I have a function that fills a 2D array with verticies but i want the 2D array to be declared outside the function, where the size is unknown. so the function only manipulates the array.
I don't know what parameter to pass in, or how to declare the function. Can someone have a read, and tell me the right (better) way to do it?
what i've got so far:
typedef struct {
float x, y, z;
} VERTEX;
VERTEX **points;
void build_shape( float fi, float theta ) {
float fi;
float theta;
float delta = PI / scale;
points = (VERTEX**)malloc(sizeof(VERTEX)*(scale*2+1));
/* as in: VERTEX points[scale*2+1][scale*2+1] */
VERTEX v;
v.x = 0; /* initialisation */
v.y = 0;
v.z = 0;
if( surface == WIREFRAME ) {
/* horizontal lines in the wire-frame rendering */
for( fi = 0.0; fi <= 2*PI; fi += delta ) {
for( theta = 0; theta <= 2*PI; theta += delta ) {
calc_shape( fi, theta, &v );
points[fi/(PI/denom)][theta/(PI/denom)] = v;
}
}
/* vertical lines in the wire-frame rendering */
for( theta = 0.0; theta <= 2*PI; theta += delta ) {
for( fi = 0.0; fi <= 2*PI; fi += delta ) {
calc_shape( fi, theta, &v );
points[fi/(PI/denom)][theta/(PI/denom)] = v;
}
}
}
}
I don't know what parameter to pass in, or how to declare the function. Can someone have a read, and tell me the right (better) way to do it?
what i've got so far:
typedef struct {
float x, y, z;
} VERTEX;
VERTEX **points;
void build_shape( float fi, float theta ) {
float fi;
float theta;
float delta = PI / scale;
points = (VERTEX**)malloc(sizeof(VERTEX)*(scale*2+1));
/* as in: VERTEX points[scale*2+1][scale*2+1] */
VERTEX v;
v.x = 0; /* initialisation */
v.y = 0;
v.z = 0;
if( surface == WIREFRAME ) {
/* horizontal lines in the wire-frame rendering */
for( fi = 0.0; fi <= 2*PI; fi += delta ) {
for( theta = 0; theta <= 2*PI; theta += delta ) {
calc_shape( fi, theta, &v );
points[fi/(PI/denom)][theta/(PI/denom)] = v;
}
}
/* vertical lines in the wire-frame rendering */
for( theta = 0.0; theta <= 2*PI; theta += delta ) {
for( fi = 0.0; fi <= 2*PI; fi += delta ) {
calc_shape( fi, theta, &v );
points[fi/(PI/denom)][theta/(PI/denom)] = v;
}
}
}
}