1 /* 2 From the 'Wizard2' engine by Spaddlewit Inc. ( http://www.spaddlewit.com ) 3 An experimental work-in-progress. 4 5 Donated to Sonic Team Junior and adapted to work with 6 Sonic Robo Blast 2. The license of this code matches whatever 7 the licensing is for Sonic Robo Blast 2. 8 */ 9 10 #ifndef _HW_MODEL_H_ 11 #define _HW_MODEL_H_ 12 13 #include "../doomtype.h" 14 15 typedef struct 16 { 17 float x, y, z; 18 } vector_t; 19 20 extern vector_t vectorXaxis; 21 extern vector_t vectorYaxis; 22 extern vector_t vectorZaxis; 23 24 void VectorRotate(vector_t *rotVec, const vector_t *axisVec, float angle); 25 26 typedef struct 27 { 28 float ambient[4], diffuse[4], specular[4], emissive[4]; 29 float shininess; 30 boolean spheremap; 31 // Texture::texture_t *texture; 32 // Texture::texture_t *lightmap; 33 } material_t; 34 35 typedef struct 36 { 37 material_t *material; // Pointer to the allocated 'materials' list in model_t 38 float *vertices; 39 float *normals; 40 float *tangents; 41 char *colors; 42 unsigned int vboID; 43 vector_t *polyNormals; 44 } mdlframe_t; 45 46 typedef struct 47 { 48 material_t *material; 49 short *vertices; 50 char *normals; 51 char *tangents; 52 unsigned int vboID; 53 } tinyframe_t; 54 55 // Equivalent to MD3's many 'surfaces' 56 typedef struct mesh_s 57 { 58 int numVertices; 59 int numTriangles; 60 61 float *uvs; 62 // if uv adjustment is needed, uvs is changed to point to adjusted ones and 63 // this one retains the originals 64 // note: this member has been added with the assumption that models are never freed. 65 // (UnloadModel is called by nobody at the time of writing.) 66 float *originaluvs; 67 float *lightuvs; 68 69 int numFrames; 70 mdlframe_t *frames; 71 tinyframe_t *tinyframes; 72 unsigned short *indices; 73 } mesh_t; 74 75 typedef struct tag_s 76 { 77 char name[64]; 78 // matrix_t transform; 79 } tag_t; 80 81 #define MODEL_INTERPOLATION_FLAG "+i" 82 83 typedef struct 84 { 85 INT32 frames[256]; 86 UINT8 numframes; 87 boolean interpolate; 88 } modelspr2frames_t; 89 90 typedef struct model_s 91 { 92 int maxNumFrames; 93 94 int numMaterials; 95 material_t *materials; 96 int numMeshes; 97 mesh_t *meshes; 98 int numTags; 99 tag_t *tags; 100 101 char *mdlFilename; 102 boolean unloaded; 103 104 char *framenames; 105 boolean interpolate[256]; 106 modelspr2frames_t *spr2frames; 107 108 // the max_s and max_t values that the uvs are currently adjusted to 109 // (if a sprite is used as a texture) 110 float max_s; 111 float max_t; 112 // These are the values that the uvs in the VBO have been adjusted to. 113 // If they are not same as max_s and max_t, then the VBO won't be used. 114 float vbo_max_s; 115 float vbo_max_t; 116 } model_t; 117 118 extern int numModels; 119 extern model_t *modelHead; 120 121 void HWR_ReloadModels(void); 122 123 tag_t *GetTagByName(model_t *model, char *name, int frame); 124 model_t *LoadModel(const char *filename, int ztag); 125 void UnloadModel(model_t *model); 126 void Optimize(model_t *model); 127 void LoadModelInterpolationSettings(model_t *model); 128 void LoadModelSprite2(model_t *model); 129 void GenerateVertexNormals(model_t *model); 130 void GeneratePolygonNormals(model_t *model, int ztag); 131 void CreateVBOTiny(mesh_t *mesh, tinyframe_t *frame); 132 void CreateVBO(mesh_t *mesh, mdlframe_t *frame); 133 void DeleteVBOs(model_t *model); 134 135 #endif 136