00001 00007 #ifndef _MILKSHAPE_H_ 00008 #define _MILKSHAPE_H_ 00009 00010 #include <stdio.h> 00011 #include <stdlib.h> 00012 #include <assert.h> 00013 #include "../Graphics/OpenGL/OpenGLRenderer.h" 00014 #include "../Common/OS/Windows.h" 00015 #include "../Math/Matrix.h" 00016 #include "../Math/Vector.h" 00017 #include "Log.h" 00018 00019 //-------------------- 00020 // Defines 00021 //-------------------- 00022 #define MS_MAX_NAME 32 00023 #define MS_MAX_PATH 256 00024 00025 #define MS_PLAYER_MAX_GUNS 4 00026 00027 #ifndef byte 00028 typedef unsigned char byte; 00029 #endif 00030 00031 //-------------------- 00032 // Structs 00033 //-------------------- 00034 struct MS_Vec { 00035 float x, y, z; 00036 float w; 00037 float u, v; 00038 int bone; 00039 }; 00040 00041 struct MS_Tri { 00042 int v[3]; 00043 int n[3]; 00044 }; 00045 00046 struct MS_Normal { 00047 float x, y, z; 00048 }; 00049 00050 struct MS_KeyFrameRot { 00051 float time; 00052 float position[3]; 00053 }; 00054 00055 struct MS_KeyFramePos { 00056 float time; 00057 float position[3]; 00058 }; 00059 00060 //-------------------- 00061 // Functions 00062 //-------------------- 00063 void MS_Vec_Transform(MS_Vec *pV, const Mat4 *pM); 00064 void MS_Vec_Transform3(MS_Vec *pV, const Mat4 *pM); 00065 00066 //-------------------- 00067 // MS_Material 00068 //-------------------- 00069 class MS_Material { 00070 public: 00071 MS_Material(); 00072 virtual ~MS_Material(); 00073 void clear(); 00074 00075 void activate(); 00076 void reloadTexture(); 00077 bool loadFromAsciiSegment(const char *path, FILE *file); 00078 00079 public: 00080 char name[MS_MAX_NAME]; 00081 float ambient[4]; 00082 float diffuse[4]; 00083 float specular[4]; 00084 float emissive[4]; 00085 float shininess; 00086 float transparency; 00087 char diffuse_name[MS_MAX_NAME]; 00088 char alpha_name[MS_MAX_NAME]; 00089 TextureID texture; 00090 }; 00091 00092 //-------------------- 00093 // MS_Bone 00094 //-------------------- 00095 class MS_Bone { 00096 public: 00097 MS_Bone(); 00098 virtual ~MS_Bone(); 00099 void clear(); 00100 00101 void initialize(); 00102 void advanceTo(float fCurrentTime); 00103 void render(); 00104 bool loadFromAsciiSegment(FILE *file); 00105 00106 public: 00107 char name[MS_MAX_NAME]; 00108 char parentName[MS_MAX_NAME]; 00109 MS_Bone *parent; 00110 byte flags; 00111 float rotation[3]; 00112 float position[3]; 00113 int numPosKeys; 00114 int numRotKeys; 00115 MS_KeyFrameRot *keyFramesRot; 00116 MS_KeyFramePos *keyFramesTrans; 00117 Mat4 matRelative; 00118 Mat4 matFinal; 00119 }; 00120 00121 //-------------------- 00122 // MS_Mesh 00123 //-------------------- 00124 class MS_Mesh { 00125 public: 00126 MS_Mesh(); 00127 virtual ~MS_Mesh(); 00128 void clear(); 00129 00130 bool loadFromAsciiSegment(FILE *file); 00131 00132 int getNumVertices() { return this->numVertices; } 00133 MS_Vec *getVertices() { return this->vertices; } 00134 int getNumTriangles() { return this->numTriangles; } 00135 MS_Tri *getTriangles() { return this->triangles; } 00136 int getNumNormals() { return this->numNormals; } 00137 MS_Normal *getNormals() { return this->normals; } 00138 00139 public: 00140 int numVertices; 00141 MS_Vec *vertices; 00142 00143 int numTriangles; 00144 MS_Tri *triangles; 00145 00146 int numNormals; 00147 MS_Normal *normals; 00148 }; 00149 00150 //-------------------- 00151 // MilkShape 00152 //-------------------- 00153 class MilkShape { 00154 public: 00155 MilkShape(); 00156 virtual ~MilkShape(); 00157 void clear(); 00158 00159 bool linkBones(); 00160 void initializeBones(); 00161 void attachSkin(); 00162 void renderBones(); 00163 bool loadFromAsciiFile(const char *path, const char *filename); 00164 void advanceAnimation(float deltaTime); 00165 void render(); 00166 00167 int getNumMeshes() { return this->numMeshes; } 00168 MS_Mesh *getMeshes() { return this->pMeshes; } 00169 00170 public: 00171 int numGuns; 00172 Vec3 guns[MS_PLAYER_MAX_GUNS]; 00173 00174 protected: 00175 float fMaxTime; 00176 float fCurrentTime; 00177 00178 int numMeshes; 00179 MS_Mesh *pMeshes; 00180 00181 int *materialIndices; 00182 00183 int numMaterials; 00184 MS_Material *pMaterials; 00185 00186 int numBones; 00187 MS_Bone *pBones; 00188 }; 00189 00190 #endif