B
berthelot samuel
Hi everyone,
This really is a tricky one ! (at least for me
. Actually I haven't
found any solution to this problem anywhere...
So I'll try to be as clear as possible in my explanations. First, I
have the following structure:
typedef struct _object3D {
float coord[8][4];
float r, g, b;
} object3D;
float coord[8][4] is an array of 2 dimensions that hold the
coordinates of the vertices of a 3D object read from a
file.Those are homogenous coordinates, that's why the dimension of the
columns is 4 instead of 3. Now as you can see
my 3D object can be composed of 8 vertices. But the problem is that
this number of vertices is static ! What if I
want to have a 3D object
made of 10 vertices. Even worse, the program will crash also in the
case my 3D object is
made of less than 8 vertices as you can see in the following:
/*Initialize elements of an Object3D*/
void initObject3D(object3D myObject3D){
for (i = 0; i < 8; i++)
/*if not 8 vertices -> CRASH
*/
for (j = 0; j < 4; j++)
myObject3D.coord[j] = 0.0;
myObject3D.r = 1.0;
myObject3D.g = 1.0;
myObject3D.b = 1.0;
}
So I thought about doing the following in order to solve my problem:
#define NBPOINTS 8
typedef struct _object3D {
float coord[NBPOINTS][4];
float r, g, b;
} object3D;
but then NBPOINTS can't be change...
OK for those who are still with me here is another thing I thought
about :
typedef float (*rowPtr3D)[4];
typedef struct _object3D {
int nbPoints; /*read from the file so we know the size of the first
dimension*/
rowPtr3D coord;
float r, g, b;} object3D;
But then it crashes in the following :
/*Initialize elements of an Object3D*/
void initObject3D(object3D myObject3D)
{
for (i = 0; i < 8; i++)
for (j = 0; j < 4; j++)
myObject3D.coord[j] = 0.0; <---- CRASH oups...
myObject3D.r = 1.0;
myObject3D.g = 1.0;
myObject3D.b = 1.0;}
OK so if anybody as an idea that may help me, let me know. I'm kinda
desperate !!!!
Cheers,
Sam.
This really is a tricky one ! (at least for me
found any solution to this problem anywhere...
So I'll try to be as clear as possible in my explanations. First, I
have the following structure:
typedef struct _object3D {
float coord[8][4];
float r, g, b;
} object3D;
float coord[8][4] is an array of 2 dimensions that hold the
coordinates of the vertices of a 3D object read from a
file.Those are homogenous coordinates, that's why the dimension of the
columns is 4 instead of 3. Now as you can see
my 3D object can be composed of 8 vertices. But the problem is that
this number of vertices is static ! What if I
want to have a 3D object
made of 10 vertices. Even worse, the program will crash also in the
case my 3D object is
made of less than 8 vertices as you can see in the following:
/*Initialize elements of an Object3D*/
void initObject3D(object3D myObject3D){
for (i = 0; i < 8; i++)
/*if not 8 vertices -> CRASH
for (j = 0; j < 4; j++)
myObject3D.coord[j] = 0.0;
myObject3D.r = 1.0;
myObject3D.g = 1.0;
myObject3D.b = 1.0;
}
So I thought about doing the following in order to solve my problem:
#define NBPOINTS 8
typedef struct _object3D {
float coord[NBPOINTS][4];
float r, g, b;
} object3D;
but then NBPOINTS can't be change...
OK for those who are still with me here is another thing I thought
about :
typedef float (*rowPtr3D)[4];
typedef struct _object3D {
int nbPoints; /*read from the file so we know the size of the first
dimension*/
rowPtr3D coord;
float r, g, b;} object3D;
But then it crashes in the following :
/*Initialize elements of an Object3D*/
void initObject3D(object3D myObject3D)
{
for (i = 0; i < 8; i++)
for (j = 0; j < 4; j++)
myObject3D.coord[j] = 0.0; <---- CRASH oups...
myObject3D.r = 1.0;
myObject3D.g = 1.0;
myObject3D.b = 1.0;}
OK so if anybody as an idea that may help me, let me know. I'm kinda
desperate !!!!
Cheers,
Sam.