diff options
Diffstat (limited to 'obj.h')
-rw-r--r-- | obj.h | 47 |
1 files changed, 32 insertions, 15 deletions
@@ -1,8 +1,7 @@ -#ifndef OBJ_H -#define OBJ_H +#ifndef _OBJLOADER_H_ +#define _OBJLOADER_H_ -/* external variables */ -char obj_last_fname[31]; +extern char obj_last_fname[101]; typedef struct { @@ -17,9 +16,9 @@ typedef struct typedef struct { - int Vertex[4]; - int Normal[4]; - int TexCoord[4]; + unsigned int Vertex[4]; + unsigned int Normal[4]; + unsigned int TexCoord[4]; } ObjFace; typedef struct @@ -28,8 +27,8 @@ typedef struct float Ni; float d; float Tr; - ObjVertex Tf; int illum; + ObjVertex Tf; ObjVertex Ka; ObjVertex Kd; ObjVertex Ks; @@ -44,13 +43,13 @@ typedef struct char *objectName; char *groupName; char *usemtl; - - ObjMtl *mtl; - int nVertex, nNormal, nTexCoord, nFace; - ObjVertex *VertexArray; - ObjNormal *NormalArray; + + ObjMtl *mtl; + ObjVertex *VertexArray; + ObjNormal *NormalArray; ObjTexCoord *TexCoordArray; - ObjFace *FaceArray; + ObjFace *FaceArray; + unsigned nVertex, nNormal, nTexCoord, nFace; } ObjModel; /* function prototypes */ @@ -58,14 +57,32 @@ ObjModel *ObjLoadModel(char *, size_t); /* read a file into argument 2, and return amount of bytes read */ size_t ObjLoadFile(char *, char **); - void ObjList(ObjModel *); /* once we load an .obj file, we can extract path up to last '/' to load a * mtl or texture that resides in the same folder */ char *ObjGetPath(char *); +void ObjPutFaceGLCmd(const ObjModel *, const unsigned); void ObjFree(ObjModel *); +static inline ObjNormal *ObjGetNormal(const ObjModel *model, const unsigned i, + const unsigned j) +{ + return &(model->NormalArray[model->FaceArray[i].Normal[j] - 1]); +} + +static inline ObjTexCoord *ObjGetTexCoord(const ObjModel *model, const unsigned i, + const unsigned j) +{ + return &(model->TexCoordArray[model->FaceArray[i].TexCoord[j] - 1]); +} + +static inline ObjVertex *ObjGetVertex(const ObjModel *model, const unsigned i, + const unsigned j) +{ + return &(model->VertexArray[model->FaceArray[i].Vertex[j] - 1]); +} + #endif |