1 2 // 3 // modeltool.h : defintions of the model classes 4 // 5 6 #ifndef _MODEL_H_ 7 #define _MODEL_H_ 8 9 #include <string> 10 #include <vector> 11 #include <map> 12 13 extern std::string texdir; 14 extern std::string groupName; 15 extern bool useMaterials; 16 extern bool useAmbient; 17 extern bool useDiffuse; 18 extern bool useSpecular; 19 extern bool useShininess; 20 extern bool useEmission; 21 extern bool useNormals; 22 extern bool useTexcoords ; 23 extern bool flipYZ; 24 extern bool useSmoothBounce; 25 extern float shineFactor; 26 extern float globalScale; 27 extern float globalShift[3]; 28 29 extern float maxShineExponent; // OpenGL minimum shininess 30 31 extern std::vector<std::string> bspMaterialSkips; // materials to skip in a bsp map 32 33 typedef std::vector<int> tvIndexList; 34 35 typedef enum 36 { 37 eXAxis, 38 eYAxis, 39 eZAxis 40 } teModelAxis; 41 42 class CTexCoord 43 { 44 public: CTexCoord()45 CTexCoord() 46 { 47 u = v = 0; 48 } ~CTexCoord()49 ~CTexCoord() {}; 50 float u,v; 51 same(const CTexCoord & c)52 bool same ( const CTexCoord &c ) 53 { 54 return u == c.u && v ==c.v; 55 } 56 }; 57 58 typedef std::vector<CTexCoord> tvTexCoordList; 59 60 class CVertex 61 { 62 public: CVertex()63 CVertex() 64 { 65 x = y = z = 0; 66 } ~CVertex()67 ~CVertex() {}; 68 float x,y,z; 69 get(teModelAxis axis)70 float get ( teModelAxis axis ) 71 { 72 switch (axis) 73 { 74 case eXAxis: 75 return x; 76 case eYAxis: 77 return y; 78 default: 79 return z; 80 } 81 } 82 translate(float val,teModelAxis axis)83 void translate ( float val, teModelAxis axis ) 84 { 85 switch (axis) 86 { 87 case eXAxis: 88 x += val; 89 return; 90 case eYAxis: 91 y += val; 92 return; 93 case eZAxis: 94 z += val; 95 } 96 } 97 same(const CVertex & v)98 bool same ( const CVertex &v ) 99 { 100 return x == v.x && y == v.y && z == v.z; 101 } 102 }; 103 104 typedef std::vector<CVertex> tvVertList; 105 106 class CFace 107 { 108 public: CFace()109 CFace() {}; ~CFace()110 ~CFace() {}; 111 112 std::string material; 113 tvIndexList verts; 114 tvIndexList normals; 115 tvIndexList texCoords; 116 clear(void)117 void clear ( void ) 118 { 119 verts.clear(); 120 normals.clear(); 121 texCoords.clear(); 122 } 123 }; 124 typedef std::vector<CFace> tvFaceList; 125 126 127 class CMaterial 128 { 129 public: CMaterial()130 CMaterial() 131 { 132 clear(); 133 } ~CMaterial()134 ~CMaterial() {}; 135 136 std::string texture; 137 float ambient[4]; 138 float diffuse[4]; 139 float specular[4]; 140 float emission[4]; 141 float shine; 142 clear(void)143 void clear ( void ) 144 { 145 texture = ""; 146 ambient[0] = ambient[1] = ambient[2] = 0.2f; 147 ambient[3] = 1.0f; 148 diffuse[0] = diffuse[1] = diffuse[2] = 1.0f; 149 diffuse[3] = 1.0f; 150 specular[0] = specular[1] = specular[2] = 0.0f; 151 specular[3] = 1.0f; 152 emission[0] = emission[1] = emission[2] = 0.0f; 153 emission[3] = 1.0f; 154 shine = 0.0f; 155 } 156 }; 157 158 typedef std::map<std::string,CMaterial> tmMaterialMap; 159 160 class CMesh 161 { 162 public: CMesh()163 CMesh() {}; ~CMesh()164 ~CMesh() {}; 165 166 tvVertList verts; 167 tvVertList normals; 168 tvTexCoordList texCoords; 169 170 std::string name; 171 tvFaceList faces; 172 getMaxAxisValue(teModelAxis axis)173 float getMaxAxisValue ( teModelAxis axis ) 174 { 175 if (!valid()) 176 return 0.0f; 177 178 float pt = verts[0].get(axis); 179 180 for ( unsigned int i = 0; i < verts.size(); i++ ) 181 if ( verts[i].get(axis) > pt) 182 pt = verts[i].get(axis); 183 184 return pt; 185 } 186 getMinAxisValue(teModelAxis axis)187 float getMinAxisValue ( teModelAxis axis ) 188 { 189 if (!valid()) 190 return 0.0f; 191 192 float pt = verts[0].get(axis); 193 194 for ( unsigned int i = 0; i < verts.size(); i++ ) 195 if ( verts[i].get(axis) < pt) 196 pt = verts[i].get(axis); 197 198 return pt; 199 } 200 translate(float value,teModelAxis axis)201 void translate ( float value, teModelAxis axis ) 202 { 203 for ( unsigned int i = 0; i < verts.size(); i++ ) 204 verts[i].translate(value,axis); 205 } 206 valid(void)207 bool valid ( void ) 208 { 209 return faces.size() != 0; 210 } 211 clear(void)212 void clear ( void ) 213 { 214 faces.clear(); 215 verts.clear(); 216 normals.clear(); 217 texCoords.clear(); 218 name = ""; 219 } 220 void reindex ( void ); 221 }; 222 223 typedef std::vector<CMesh> tvMeshList; 224 225 226 class CCustomObject 227 { 228 public: 229 std::string name; 230 std::vector<std::string> params; 231 clear(void)232 void clear ( void ) 233 { 234 params.clear(); 235 name=""; 236 } 237 }; 238 239 typedef std::vector<CCustomObject> tvCustomObjectList; 240 241 class CModel 242 { 243 public: CModel()244 CModel() {}; ~CModel()245 ~CModel() {}; 246 247 tmMaterialMap materials; 248 tvMeshList meshes; 249 tvCustomObjectList customObjects; 250 pushAboveAxis(teModelAxis axis)251 void pushAboveAxis ( teModelAxis axis ) 252 { 253 if (!meshes.size()) 254 return; 255 256 float minValue = meshes[0].getMinAxisValue(axis); 257 258 for ( unsigned int i = 0; i < meshes.size(); i++ ) 259 if ( minValue > meshes[i].getMinAxisValue(axis)) 260 minValue = meshes[i].getMinAxisValue(axis); 261 262 for ( unsigned int i = 0; i < meshes.size(); i++ ) 263 meshes[i].translate(-minValue,axis); 264 } 265 clear(void)266 void clear ( void ) 267 { 268 meshes.clear(); 269 materials.clear(); 270 customObjects.clear(); 271 } 272 }; 273 274 275 #endif // _MODEL_H_ 276 277