- Timestamp:
- May 19, 2005, 10:50:00 PM (20 years ago)
- Location:
- orxonox/branches/md2_loader/src/lib/graphics/importer
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/md2_loader/src/lib/graphics/importer/md2Model.cc
r4226 r4227 532 532 { 533 533 FILE *pFile; //file stream 534 tMd2Header header;534 //tMd2Header header; 535 535 char* buffer; //buffer for frame data 536 536 sFrame* frame; //temp frame … … 544 544 return false; 545 545 } 546 fread( &header, 1, sizeof(tMd2Header), pFile);546 fread(header, 1, sizeof(tMd2Header), pFile); 547 547 /* check for the header version: make sure its a md2 file :) */ 548 548 if( unlikely(header.version != MD2_VERSION) && unlikely(header.ident != MD2_IDENT)) … … 553 553 554 554 /* got the data: map it to locals */ 555 this->numFrames = header.numFrames;556 this->numVertices = header.numVertices;557 this->numTriangles = header.numTriangles;558 this->numGLCommands = header.numGlCommands;555 this->numFrames = this->header->numFrames; 556 this->numVertices = this->header->numVertices; 557 this->numTriangles = this->header->numTriangles; 558 this->numGLCommands = this->header->numGlCommands; 559 559 /* allocate memory for the data storage */ 560 560 this->pVertices = new sVec3D[this->numVertices * this->numFrames]; 561 561 this->pGLCommands = new int[this->numGLCommands]; 562 562 this->pLightNormals = new int[this->numVertices * this->numFrames]; 563 buffer = new char[this->numFrames * header.frameSize];563 buffer = new char[this->numFrames * this->header->frameSize]; 564 564 565 565 /* read frame data from the file to a temp buffer */ 566 fseek(pFile, header.offsetFrames, SEEK_SET);567 fread(buffer, header.frameSize, this->numFrames, pFile);566 fseek(pFile, this->header->offsetFrames, SEEK_SET); 567 fread(buffer, this->header->frameSize, this->numFrames, pFile); 568 568 /* read opengl commands */ 569 fseek(pFile, header.offsetGlCommands, SEEK_SET);569 fseek(pFile, this->header->offsetGlCommands, SEEK_SET); 570 570 fread(this->pGLCommands, sizeof(int), this->numGLCommands, pFile); 571 571 … … 574 574 /* 575 575 faster but evt. buggy 576 frame = (sFrame*)(buffer + header.frameSize * i);576 frame = (sFrame*)(buffer + this->header->frameSize * i); 577 577 pVertex = this->pVertices + this->numVertices * i; 578 578 pNormals = this->pLightNormals + this->numVertices * i; 579 579 */ 580 frame = (sFrame *)&buffer[ header.frameSize * i];580 frame = (sFrame *)&buffer[this->header->frameSize * i]; 581 581 pVertex = &this->pVertices[this->numVertices * i]; 582 582 pNormals = &this->pLightNormals[this->numVertices * i]; … … 645 645 646 646 //printf(" pVertices %f, %f, %f\n", pVertices[i][0], pVertices[i][1], pVertices[i][2]); 647 //printf(" list: %f, %f, %f \n", verticesList[i][0], verticesList[i][1], verticesList[i][2]);647 printf(" list: %f, %f, %f \n", verticesList[i][0], verticesList[i][1], verticesList[i][2]); 648 648 } 649 649 } … … 792 792 } 793 793 794 795 void MD2Model2::debug() 796 { 797 PRINT(0)("==========================| MD2Model2::debug() |==="); 798 PRINT(0)("= Model Name: %s", this->); 799 PRINT(0)(" Position: %f/%f/%f\n", this->lightPosition[0], this->lightPosition[1], this->lightPosition[2]); 800 PRINT(0)(" DiffuseColor: %f/%f/%f\n", this->diffuseColor[0], this->diffuseColor[1], this->diffuseColor[2]); 801 PRINT(0)(" SpecularColor: %f/%f/%f\n", this->specularColor[0], this->specularColor[1], this->specularColor[2]); 802 PRINT(0)(" Attenuation: constant=%f linear=%f quadratic=%f\n", this->constantAttenuation, this->linearAttenuation, this->quadraticAttenuation); 803 } 804 805 806 int ident; //!< This is used to identify the file 807 int version; //!< The version number of the file (Must be 8) 808 809 int skinWidth; //!< The skin width in pixels 810 int skinHeight; //!< The skin height in pixels 811 int frameSize; //!< The size in bytes the frames are 812 813 int numSkins; //!< The number of skins associated with the model 814 int numVertices; //!< The number of vertices (constant for each frame) 815 int numTexCoords; //!< The number of texture coordinates 816 int numTriangles; //!< The number of faces (polygons) 817 int numGlCommands; //!< The number of gl commands 818 int numFrames; //!< The number of animation frames 819 820 int offsetSkins; //!< The offset in the file for the skin data 821 int offsetTexCoords; //!< The offset in the file for the texture data 822 int offsetTriangles; //!< The offset in the file for the face data 823 int offsetFrames; //!< The offset in the file for the frames data 824 int offsetGlCommands; //!< The offset in the file for the gl commands data 825 int offsetEnd; //!< The end of the file offset -
orxonox/branches/md2_loader/src/lib/graphics/importer/md2Model.h
r4224 r4227 174 174 175 175 176 177 //! This is a MD2 Model class178 class MD2Model2 : public AbstractModel {179 180 public:181 MD2Model2();182 virtual ~MD2Model2();183 184 bool loadModel(const char* filename);185 bool loadSkin(const char* filename);186 187 void drawFrame(int frame);188 void draw();189 void draw2();190 191 void setAnim(int type);192 void scaleModel(float scaleFactor) { this->scaleFactor = scaleFactor;}193 194 void tick(float dtS);195 196 197 private:198 void animate();199 void processLighting();200 void interpolate(sVec3D* verticesList);201 void renderFrame();202 203 public:204 /* these variables are static, because they are all the same for every model */205 static sVec3D anorms[NUM_VERTEX_NORMALS];206 static float anormsDots[SHADEDOT_QUANT][256];207 static sAnim animationList[21];208 209 private:210 int numFrames;211 int numVertices;212 int numTriangles;213 int numGLCommands;214 215 sVec3D* pVertices;216 int* pGLCommands;217 int* pLightNormals;218 219 unsigned int textureID;220 Material* material;221 sAnimState animationState;222 float scaleFactor;223 //tMd2Header* header;224 };225 226 227 176 //! A class that handles all of the loading code 228 177 class MD2Loader : public BaseObject { … … 250 199 251 200 201 //! This is a MD2 Model class 202 class MD2Model2 : public AbstractModel { 203 204 public: 205 MD2Model2(); 206 virtual ~MD2Model2(); 207 208 bool loadModel(const char* filename); 209 bool loadSkin(const char* filename); 210 211 void drawFrame(int frame); 212 void draw(); 213 void draw2(); 214 215 void setAnim(int type); 216 void scaleModel(float scaleFactor) { this->scaleFactor = scaleFactor;} 217 218 void tick(float dtS); 219 void debug(); 220 221 222 private: 223 void animate(); 224 void processLighting(); 225 void interpolate(sVec3D* verticesList); 226 void renderFrame(); 227 228 public: 229 /* these variables are static, because they are all the same for every model */ 230 static sVec3D anorms[NUM_VERTEX_NORMALS]; 231 static float anormsDots[SHADEDOT_QUANT][256]; 232 static sAnim animationList[21]; 233 234 private: 235 int numFrames; 236 int numVertices; 237 int numTriangles; 238 int numGLCommands; 239 240 sVec3D* pVertices; 241 int* pGLCommands; 242 int* pLightNormals; 243 244 unsigned int textureID; 245 Material* material; 246 sAnimState animationState; 247 float scaleFactor; 248 tMd2Header* header; 249 }; 250 251 252 253 254 252 255 #endif /* _MD2MODEL_H */
Note: See TracChangeset
for help on using the changeset viewer.