Initialized pointers for arrays in struct Batch

This commit is contained in:
_ 2018-04-07 22:09:29 -07:00
parent fb962d2ffe
commit ad357afc36
3 changed files with 18 additions and 8 deletions

View File

@ -76,6 +76,8 @@ void printmeshbatch(struct Batch*);
void printpositions(struct Positions*, unsigned int);
void printnormals(struct Normals*, unsigned int);
// ** = 'pass by reference' of a pointer to struct
bool getmeshheader(struct MeshHeader**, unsigned int i, const char * const);

View File

@ -49,6 +49,16 @@ void printpositions(struct Positions *p, unsigned int count) {
}
}
void printnormals(struct Normals *n, unsigned int count) {
if (n == NULL) {
return;
}
unsigned int i;
for (i = 0; i < count; i++) {
printf("(%f, %f, %f)\n", (n[i]).x, (n[i]).y, (n[i]).z);
}
}
bool getmeshheader(struct MeshHeader **hs,
unsigned int i,
const char * const filedata) {
@ -76,12 +86,10 @@ bool getmeshbatch(struct Batch **b,
unsigned int offset = h -> offsetBatches;
*b = (struct Batch*)(filedata + offset);
(*b) -> p = (struct Positions*)(filedata + ((*b) -> offsetPositions));
printf("p = %x\n", (*b) -> offsetPositions);
printpositions((*b) -> p, 3);
(*b) -> n = NULL;
(*b) -> u = NULL;
(*b) -> bi = NULL;
(*b) -> bw = NULL;
(*b) -> n = (struct Normals*)(filedata + ((*b) -> offsetNormals));
(*b) -> u = (struct UVs*)(filedata + ((*b) -> offsetUVs));
(*b) -> bi = (struct BoneIndexes*)(filedata + ((*b) -> offsetBoneIndexes));
(*b) -> bw = (struct BoneWeights*)(filedata + ((*b) -> offsetBoneWeights));
done = true;
return done;
}

View File

@ -117,7 +117,7 @@ void extractmeshes(const char *filedata,
unsigned int i;
bool ok;
//h -> numMesh
for (i = 0; i < 3; i++) {
for (i = 1; i < 2; i++) {
ok = getmeshheader(&mh, i, filedata);
if (ok) {
getmeshbatch(&b, mh, filedata);