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 printpositions(struct Positions*, unsigned int);
void printnormals(struct Normals*, unsigned int);
// ** = 'pass by reference' of a pointer to struct // ** = 'pass by reference' of a pointer to struct
bool getmeshheader(struct MeshHeader**, unsigned int i, const char * const); 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, bool getmeshheader(struct MeshHeader **hs,
unsigned int i, unsigned int i,
const char * const filedata) { const char * const filedata) {
@ -75,13 +85,11 @@ bool getmeshbatch(struct Batch **b,
} }
unsigned int offset = h -> offsetBatches; unsigned int offset = h -> offsetBatches;
*b = (struct Batch*)(filedata + offset); *b = (struct Batch*)(filedata + offset);
(*b) -> p = (struct Positions*)(filedata + ((*b) -> offsetPositions)); (*b) -> p = (struct Positions*)(filedata + ((*b) -> offsetPositions));
printf("p = %x\n", (*b) -> offsetPositions); (*b) -> n = (struct Normals*)(filedata + ((*b) -> offsetNormals));
printpositions((*b) -> p, 3); (*b) -> u = (struct UVs*)(filedata + ((*b) -> offsetUVs));
(*b) -> n = NULL; (*b) -> bi = (struct BoneIndexes*)(filedata + ((*b) -> offsetBoneIndexes));
(*b) -> u = NULL; (*b) -> bw = (struct BoneWeights*)(filedata + ((*b) -> offsetBoneWeights));
(*b) -> bi = NULL;
(*b) -> bw = NULL;
done = true; done = true;
return done; return done;
} }

View File

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