Changeset 4080 in orxonox.OLD for orxonox/branches/md2_loader/src/lib
- Timestamp:
- May 6, 2005, 12:55:52 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/md2_loader/src/lib/graphics/importer/md2Model.cc
r4079 r4080 17 17 #include "md2Model.h" 18 18 19 //#include <stdio.h>20 //#include <stdlib.h>21 //#include <string>22 19 #include <fstream> 20 21 #include "list.h" 23 22 24 23 … … 84 83 bool MD2Loader::importMD2(t3DModel *pModel, char *fileName, char *textureName) 85 84 { 86 char strMessage[255] = {0};87 88 85 this->pFile = fopen(fileName, "rb"); 89 86 if( unlikely(!pFile)) … … 105 102 if( likely((int)textureName)) 106 103 { 107 tMaterialInfo textureInfo;108 strcpy(textureInfo .strFile, textureName);104 tMaterialInfo* textureInfo = new tMaterialInfo; 105 strcpy(textureInfo->strFile, textureName); 109 106 /* since there is only one texture for a .Md2 file, the ID is always 0 */ 110 textureInfo .texureId = 0;111 textureInfo .uTile = 1;107 textureInfo->texureId = 0; 108 textureInfo->uTile = 1; 112 109 /* we only have 1 material for a model */ 113 110 pModel->numOfMaterials = 1; 114 //pModel->materialList.add(texture);111 pModel->materialList->add(textureInfo); 115 112 } 116 113 … … 123 120 */ 124 121 void MD2Loader::readMD2Data() 125 {} 122 { 123 unsigned char buffer[MD2_MAX_FRAMESIZE]; 124 this->pSkins = new tMd2Skin[this->header.numSkins]; 125 this->pTexCoords = new tMd2TexCoord[this->header.numTexCoords]; 126 this->pTriangles = new tMd2Face[this->header.numTriangles]; 127 this->pFrames = new tMd2Frame[this->header.numFrames]; 128 129 /* we read the skins */ 130 fseek(this->pFile, this->header.offsetSkins, SEEK_SET); 131 fread(this->pSkins, sizeof(tMd2Skin), this->header.numSkins, this->pFile); 132 /* read all vertex data */ 133 fseek(this->pFile, this->header.offsetTexCoords, SEEK_SET); 134 fread(this->pTexCoords, sizeof(tMd2TexCoord), this->header.numTexCoords, this->pFile); 135 /* read face data for each triangle (normals) */ 136 fseek(this->pFile, this->header.offsetTriangles, SEEK_SET); 137 fread(this->pTriangles, sizeof(tMd2Face), this->header.numTriangles, this->pFile); 138 /* reading all frame data */ 139 fseek(this->pFile, this->header.offsetFrames, SEEK_SET); 140 for(int i = 0; i < this->header.numFrames; i++) 141 { 142 tMd2AliasFrame *pFrame = (tMd2AliasFrame *) buffer; 143 this->pFrames[i].pVertices = new tMd2Triangle [this->header.numVertices]; 144 145 /* read the frame animation data */ 146 fread(pFrame, 1, this->header.frameSize, this->pFile); 147 strcpy(this->pFrames[i].strName, pFrame->name); 148 tMd2Triangle *pVertices = this->pFrames[i].pVertices; 149 /* 150 scale translations, store vertices: since id used a non-opengl xyz notation, we have to swap y and z 151 and negate z axis 152 */ 153 for(int j = 0; j < this->header.numVertices; j++) 154 { 155 pVertices[j].vertex[0] = pFrame->aliasVertices[j].vertex[0] * pFrame->scale[0] + pFrame->translate[0]; 156 pVertices[j].vertex[2] = -1 * (pFrame->aliasVertices[j].vertex[1] * pFrame->scale[1] + pFrame->translate[1]); 157 pVertices[j].vertex[1] = pFrame->aliasVertices[j].vertex[2] * pFrame->scale[2] + pFrame->translate[2]; 158 } 159 } 160 } 126 161 127 162 /**
Note: See TracChangeset
for help on using the changeset viewer.