Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef KIT_KTTM_H
- #define KIT_KTTM_H
- #define KIT_TTM_NEAR 1.0f
- #define KIT_TTM_FAR 20.0f
- #include <stdint.h>
- #include <SDL2/SDL.h>
- #include <KIT/kmath.h>
- /* TTL */
- typedef struct {
- char* name; //name of the material
- KIT_vec3 Ka; //ambient color
- KIT_vec3 Kd; //diffuse color
- KIT_vec3 Ks; //specular color
- float Ns; //specular exponent
- float d; //alpha (opaqueness)
- KIT_vec3 Tf; //transmission filter color (RGB)
- //CIEXYZ transmission filter color not supported
- //transmission filter color from spectral curve file not supported
- float Ni; //optical density (index of refraction)
- uint32_t ilm; //illumination model
- SDL_Texture* mKa; //ambient texture map
- SDL_Texture* mKd; //diffuse texture map
- SDL_Texture* mKs; //specular color texture map
- SDL_Texture* mNs; //specular highlight component
- SDL_Texture* md; //alpha texture map
- SDL_Texture* mbm; //bump map
- SDL_Texture* dsp; //displacement map
- SDL_Texture* dcl; //stencil decal texture
- //texture map option parameters are not supported
- KIT_vec3 Ke; //emissive color (.mtl extension)
- } KIT_TTL_Material;
- typedef struct {
- KIT_BTS* bts;
- KIT_TTL_Material* mats;
- uint32_t mats_len;
- } KIT_TTL;
- /* TTM */
- #define KIT_TTM_PRINT_TRIANGLE(t) \
- printf("[[(%.1f,%.1f,%.1f), (%.1f,%.1f,%.1f), (%.1f,%.1f), 0x%X],\n", \
- t->a.pos.x, t->a.pos.y, t->a.pos.z, \
- t->a.norm.x,t->a.norm.y,t->a.norm.z, \
- t->a.uv.x, t->a.uv.y, t->a.clri); \
- printf(" [(%.1f,%.1f,%.1f), (%.1f,%.1f,%.1f), (%.1f,%.1f), 0x%X],\n", \
- t->b.pos.x, t->b.pos.y, t->b.pos.z, \
- t->b.norm.x,t->b.norm.y,t->b.norm.z, \
- t->b.uv.x, t->b.uv.y, t->b.clri); \
- printf(" [(%.1f,%.1f,%.1f), (%.1f,%.1f,%.1f), (%.1f,%.1f), 0x%X]]\n", \
- t->c.pos.x, t->c.pos.y, t->c.pos.z, \
- t->c.norm.x,t->c.norm.y,t->c.norm.z, \
- t->c.uv.x, t->c.uv.y, t->c.clri);
- typedef struct {
- KIT_vec3 pos,norm; //xyz, normal vector
- SDL_FPoint uv; //uv texture coordinates
- union {
- SDL_Color clr; //rgba value (Uint8 * 4)
- uint32_t clri;
- };
- } KIT_TTM_Vertex;
- typedef struct {
- KIT_TTM_Vertex a,b,c;
- KIT_vec3 mid; //triangle midpoint = (a+b+c)/3
- KIT_vec3 norm; //triangle normal vector
- } KIT_TTM_Triangle;
- typedef struct {
- char* name; //points to bts data; don't free() this
- KIT_TTL_Material* umt; //material used, also don't free() this
- KIT_TTM_Triangle* original; //ttm's original state; copy to work for transform
- KIT_TTM_Triangle* work; //work buffer for faces; copy to render for rendering
- KIT_TTM_Triangle* render; //buffer for rendering
- uint32_t numTriangles;
- uint32_t numWorkTris; //<= numTriangles due to clipping/culling
- int s; //smooth shading; boolean
- } KIT_TTM_Object;
- typedef struct {
- KIT_BTS* bts; //contains the model's raw bts data
- KIT_TTL** ttls; uint32_t ttls_len; //material libraries
- KIT_TTL_Material** mats; uint32_t mats_len; //points to materials actually used
- KIT_TTM_Object* objects; uint32_t objects_len;
- } KIT_TTM;
- typedef struct {
- SDL_Texture* texture;
- SDL_Renderer* renderer;
- float* zBuffer;
- float v_w,v_h; //viewport dimensions (not in pixels)
- int w,h;
- //uint32_t pixelFormat; (assumed ABGR32)
- } KIT_TTM_Canvas3D;
- /* TTL */
- extern KIT_TTL* KIT_TTL_LoadFile(const char* filePath, SDL_Renderer* r);
- extern void KIT_TTL_Destroy(KIT_TTL** ttl_p);
- /* TTM */
- extern KIT_TTM* KIT_TTM_LoadFile(const char* filePath, SDL_Renderer* r);
- extern void KIT_TTM_Destroy(KIT_TTM** ttm_p);
- extern int KIT_TTM_Transform(KIT_TTM* ttm, int* opt, KIT_vec3* ops, int opCount);
- extern int KIT_TTM_ZCompareVert(const void* p1, const void* p2);
- extern int KIT_TTM_ZCompareTri(const void* p1, const void* p2);
- extern KIT_TTM_Canvas3D* KIT_TTM_CreateCanvas3D(SDL_Renderer* renderer,
- int w,int h, float v_w,float v_h);
- extern void KIT_TTM_DestroyCanvas3D(KIT_TTM_Canvas3D** c_p);
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement