Changeset 8634 in orxonox.OLD for branches/bsp_model/src/lib
- Timestamp:
- Jun 20, 2006, 3:27:26 PM (18 years ago)
- Location:
- branches/bsp_model/src/lib/graphics/importer/md3
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/bsp_model/src/lib/graphics/importer/md3/md3_data.cc
r8602 r8634 48 48 this->loadModel(modelFileName); 49 49 // this->loadSkin(skinFileName); 50 this->init(); 50 51 } 51 52 … … 59 60 { 60 61 delete this->header; 62 } 63 64 65 /** 66 * init data 67 */ 68 void MD3Data::init() 69 { 70 // create the temporary data to work with (interpolation data) 71 this->tmpBoneFrame = new MD3BoneFrame(); 72 73 this->tmpMesh = new sVec3D*[this->header->meshNum]; 74 for( int i = 0; i < this->header->meshNum; i++) 75 this->tmpMesh[i] = new sVec3D[this->meshes[i]->header->vertexNum]; 76 77 this->tmpNormal = new MD3Normal*[this->header->meshNum]; 78 for( int i = 0; i < this->header->meshNum; i++) 79 this->tmpNormal[i] = new MD3Normal[this->meshes[i]->header->vertexNum]; 80 81 this->tmpMatrix = new float*[this->header->tagNum]; 82 for( int i = 0; i < this->header->tagNum; i++) 83 this->tmpMatrix[i] = new float[16]; 84 61 85 } 62 86 -
branches/bsp_model/src/lib/graphics/importer/md3/md3_data.h
r8602 r8634 39 39 class MD3BoneFrame; 40 40 class MD3Mesh; 41 class MD3Normal; 41 42 42 43 //! This holds the header information that is read in at the beginning of the file: id software definition … … 83 84 bool loadSkin(const std::string& fileName = ""); 84 85 86 void init(); 87 85 88 int readHeader(FILE* pFile, int fileOffset); 86 89 int readBoneFrames(FILE* pFile, int fileOffset); … … 110 113 MD3Mesh** meshes; //!< array of meshes in the model. each containing the mesh for each of the animation 111 114 112 115 MD3BoneFrame* tmpBoneFrame; //!< a temporary bone frame 116 sVec3D** tmpMesh; //!< a temporary mesh frame 117 MD3Normal** tmpNormal; //!< a temporary normals frame 118 float** tmpMatrix; //!< a temporary matrix 113 119 114 120 }; -
branches/bsp_model/src/lib/graphics/importer/md3/md3_model.cc
r8602 r8634 41 41 this->autoAssemblePlayerModel(filename, scaling); 42 42 43 44 // create the temporary data to work with (interpolation data)45 this->tmpBoneFrame = new MD3BoneFrame();46 47 this->tmpMesh = new sVec3D*[this->md3Data->header->meshNum];48 for( int i = 0; i < this->md3Data->header->meshNum; i++)49 this->tmpMesh[i] = new sVec3D[this->md3Data->meshes[i]->header->vertexNum];50 51 this->tmpNormal = new MD3Normal*[this->md3Data->header->meshNum];52 for( int i = 0; i < this->md3Data->header->meshNum; i++)53 this->tmpNormal[i] = new MD3Normal[this->md3Data->meshes[i]->header->vertexNum];54 55 this->tmpMatrix = new float*[this->md3Data->header->tagNum];56 for( int i = 0; i < this->md3Data->header->tagNum; i++)57 this->tmpMatrix[i] = new float[16];58 59 43 this->bDrawBones = false; 60 44 this->bDrawNormals = false; … … 65 49 MD3Model::~MD3Model() 66 50 { 67 delete this->tmpBoneFrame;51 // delete this->tmpBoneFrame; 68 52 // delete [] this->tmpMesh; 69 53 … … 152 136 { 153 137 //interpolate bone frame 154 this->tmpBoneFrame = this->interpolateBoneFrame(data->boneFrames[data->animationState.currentFrame],138 data->tmpBoneFrame = this->interpolateBoneFrame(data, data->boneFrames[data->animationState.currentFrame], 155 139 data->boneFrames[data->animationState.nextFrame], 156 140 data->animationState.interpolationFraction); … … 158 142 else 159 143 { 160 this->tmpBoneFrame = data->boneFrames[data->animationState.currentFrame];144 data->tmpBoneFrame = data->boneFrames[data->animationState.currentFrame]; 161 145 } 162 146 } … … 173 157 { 174 158 //interpolate mesh frame between the 2 current mesh frames 175 frame = this->interpolateMeshFrame( data ->meshes[data->animationState.currentFrame]->meshFrames,159 frame = this->interpolateMeshFrame( data, data->meshes[data->animationState.currentFrame]->meshFrames, 176 160 data->meshes[data->animationState.nextFrame]->meshFrames, 177 161 data->animationState.interpolationFraction, mesh, i); … … 182 166 frame = &mesh->meshFrames[data->animationState.currentFrame]; 183 167 } 184 this->tmpMesh[i] = frame;168 data->tmpMesh[i] = frame; 185 169 186 170 // draw vertex normals if needed … … 192 176 { 193 177 //interpolate vertex normals 194 this->interpolateVertexNormals( &mesh->normals[data->animationState.currentFrame],178 this->interpolateVertexNormals(data, &mesh->normals[data->animationState.currentFrame], 195 179 &mesh->normals[data->animationState.nextFrame], 196 180 data->animationState.interpolationFraction, mesh, i); … … 216 200 //we need to interpolate 217 201 MD3Tag* nextFrameTag = data->boneFrames[data->animationState.nextFrame]->tags[child->parentTagIndex]; 218 this->interpolateTransformation(c urrFrameTag, nextFrameTag, data->animationState.interpolationFraction, i);202 this->interpolateTransformation(child, currFrameTag, nextFrameTag, data->animationState.interpolationFraction, i); 219 203 } 220 204 else … … 222 206 //no interpolation needed, stay with last transformation 223 207 //OpenGL matrix is in column-major order 224 this->tmpMatrix[i][0] = currFrameTag->matrix[0][0]; 225 this->tmpMatrix[i][1] = currFrameTag->matrix[1][0]; 226 this->tmpMatrix[i][2] = currFrameTag->matrix[2][0]; 227 this->tmpMatrix[i][3] = 0.0f; 228 this->tmpMatrix[i][4] = currFrameTag->matrix[0][1]; 229 this->tmpMatrix[i][5] = currFrameTag->matrix[1][1]; 230 this->tmpMatrix[i][6] = currFrameTag->matrix[2][1]; 231 this->tmpMatrix[i][7] = 0.0f; 232 this->tmpMatrix[i][8] = currFrameTag->matrix[0][2]; 233 this->tmpMatrix[i][9] = currFrameTag->matrix[1][2]; 234 this->tmpMatrix[i][10]= currFrameTag->matrix[2][2]; 235 this->tmpMatrix[i][11]= 0.0f; 236 this->tmpMatrix[i][12] = currFrameTag->position.x; 237 this->tmpMatrix[i][13] = currFrameTag->position.y; 238 this->tmpMatrix[i][14] = currFrameTag->position.z; 239 this->tmpMatrix[i][15] = 1.0f; 240 } 241 242 // PRINTF(0)("matrix: \n%f, %f, %f, %f\n%f, %f, %f, %f\n%f, %f, %f, %f\n%f, %f, %f, %f\n", 243 // this->tmpMatrix[i][0], 244 // this->tmpMatrix[i][1], 245 // this->tmpMatrix[i][2], 246 // this->tmpMatrix[i][3], 247 // this->tmpMatrix[i][4], 248 // this->tmpMatrix[i][5], 249 // this->tmpMatrix[i][6], 250 // this->tmpMatrix[i][7], 251 // this->tmpMatrix[i][8], 252 // this->tmpMatrix[i][9], 253 // this->tmpMatrix[i][10], 254 // this->tmpMatrix[i][11], 255 // this->tmpMatrix[i][12], 256 // this->tmpMatrix[i][13], 257 // this->tmpMatrix[i][14], 258 // this->tmpMatrix[i][15] 259 // ); 208 data->tmpMatrix[i][0] = currFrameTag->matrix[0][0]; 209 data->tmpMatrix[i][1] = currFrameTag->matrix[1][0]; 210 data->tmpMatrix[i][2] = currFrameTag->matrix[2][0]; 211 data->tmpMatrix[i][3] = 0.0f; 212 data->tmpMatrix[i][4] = currFrameTag->matrix[0][1]; 213 data->tmpMatrix[i][5] = currFrameTag->matrix[1][1]; 214 data->tmpMatrix[i][6] = currFrameTag->matrix[2][1]; 215 data->tmpMatrix[i][7] = 0.0f; 216 data->tmpMatrix[i][8] = currFrameTag->matrix[0][2]; 217 data->tmpMatrix[i][9] = currFrameTag->matrix[1][2]; 218 data->tmpMatrix[i][10]= currFrameTag->matrix[2][2]; 219 data->tmpMatrix[i][11]= 0.0f; 220 data->tmpMatrix[i][12] = currFrameTag->position.x; 221 data->tmpMatrix[i][13] = currFrameTag->position.y; 222 data->tmpMatrix[i][14] = currFrameTag->position.z; 223 data->tmpMatrix[i][15] = 1.0f; 224 } 225 260 226 // switch to child coord system 261 227 … … 294 260 data->animationState.currentFrame != data->animationState.nextFrame) { 295 261 //interpolate bone frame 296 this->drawBoneFrame( this->tmpBoneFrame);262 this->drawBoneFrame(data->tmpBoneFrame); 297 263 } 298 264 else { … … 312 278 313 279 // get mesh frame, do interpolation if necessary 314 sVec3D* frame = this->tmpMesh[i];280 sVec3D* frame = data->tmpMesh[i]; 315 281 316 282 this->drawMesh(mesh, frame); … … 324 290 { 325 291 //interpolate vertex normals 326 this->drawVertexNormals(frame, this->tmpNormal[i]);292 this->drawVertexNormals(frame, data->tmpNormal[i]); 327 293 } 328 294 else { … … 402 368 } 403 369 glEnd(); 404 405 370 } 406 371 … … 476 441 * @param frac Interpolation fraction, in [0,1]. 477 442 */ 478 MD3BoneFrame* MD3Model::interpolateBoneFrame(MD3 BoneFrame* currBoneFrame, MD3BoneFrame* nextBoneFrame, float frac)479 { 480 this->tmpBoneFrame->mins.x = (1.0f - frac) * currBoneFrame->mins.x + frac * nextBoneFrame->mins.x;481 this->tmpBoneFrame->maxs.x = (1.0f - frac) * currBoneFrame->maxs.x + frac * nextBoneFrame->maxs.x;482 this->tmpBoneFrame->position.x = (1.0f - frac) * currBoneFrame->position.x + frac * nextBoneFrame->position.x;483 this->tmpBoneFrame->mins.y = (1.0f - frac) * currBoneFrame->mins.y + frac * nextBoneFrame->mins.y;484 this->tmpBoneFrame->maxs.y = (1.0f - frac) * currBoneFrame->maxs.y + frac * nextBoneFrame->maxs.y;485 this->tmpBoneFrame->position.y = (1.0f - frac) * currBoneFrame->position.y + frac * nextBoneFrame->position.y;486 this->tmpBoneFrame->mins.z = (1.0f - frac) * currBoneFrame->mins.z + frac * nextBoneFrame->mins.z;487 this->tmpBoneFrame->maxs.z = (1.0f - frac) * currBoneFrame->maxs.z + frac * nextBoneFrame->maxs.z;488 this->tmpBoneFrame->position.z = (1.0f - frac) * currBoneFrame->position.z + frac * nextBoneFrame->position.z;489 490 return this->tmpBoneFrame;443 MD3BoneFrame* MD3Model::interpolateBoneFrame(MD3Data* data, MD3BoneFrame* currBoneFrame, MD3BoneFrame* nextBoneFrame, float frac) 444 { 445 data->tmpBoneFrame->mins.x = (1.0f - frac) * currBoneFrame->mins.x + frac * nextBoneFrame->mins.x; 446 data->tmpBoneFrame->maxs.x = (1.0f - frac) * currBoneFrame->maxs.x + frac * nextBoneFrame->maxs.x; 447 data->tmpBoneFrame->position.x = (1.0f - frac) * currBoneFrame->position.x + frac * nextBoneFrame->position.x; 448 data->tmpBoneFrame->mins.y = (1.0f - frac) * currBoneFrame->mins.y + frac * nextBoneFrame->mins.y; 449 data->tmpBoneFrame->maxs.y = (1.0f - frac) * currBoneFrame->maxs.y + frac * nextBoneFrame->maxs.y; 450 data->tmpBoneFrame->position.y = (1.0f - frac) * currBoneFrame->position.y + frac * nextBoneFrame->position.y; 451 data->tmpBoneFrame->mins.z = (1.0f - frac) * currBoneFrame->mins.z + frac * nextBoneFrame->mins.z; 452 data->tmpBoneFrame->maxs.z = (1.0f - frac) * currBoneFrame->maxs.z + frac * nextBoneFrame->maxs.z; 453 data->tmpBoneFrame->position.z = (1.0f - frac) * currBoneFrame->position.z + frac * nextBoneFrame->position.z; 454 455 return data->tmpBoneFrame; 491 456 } 492 457 … … 496 461 * interpolate mesh frame 497 462 */ 498 sVec3D* MD3Model::interpolateMeshFrame( sVec3D* currMeshFrame, sVec3D* nextMeshFrame, float frac, MD3Mesh* mesh, int i)463 sVec3D* MD3Model::interpolateMeshFrame(MD3Data* data, sVec3D* currMeshFrame, sVec3D* nextMeshFrame, float frac, MD3Mesh* mesh, int i) 499 464 { 500 465 int vertexNum = mesh->header->vertexNum; … … 503 468 for( int t = 0; t < vertexNum * 3.0f; t++) 504 469 { 505 506 // PRINTF(0)("tmp mesh: %f, %f, %f\n", this->tmpMesh[i][t][0], this->tmpMesh[i][t][1], this->tmpMesh[i][t][2]); 507 508 this->tmpMesh[i][t][0] = (1.0f - frac) * currMeshFrame[t][0] + frac * nextMeshFrame[t][0]; 509 this->tmpMesh[i][t][1] = (1.0f - frac) * currMeshFrame[t][1] + frac * nextMeshFrame[t][1]; 510 this->tmpMesh[i][t][2] = (1.0f - frac) * currMeshFrame[t][2] + frac * nextMeshFrame[t][2]; 511 } 512 513 return this->tmpMesh[i]; 470 data->tmpMesh[i][t][0] = (1.0f - frac) * currMeshFrame[t][0] + frac * nextMeshFrame[t][0]; 471 data->tmpMesh[i][t][1] = (1.0f - frac) * currMeshFrame[t][1] + frac * nextMeshFrame[t][1]; 472 data->tmpMesh[i][t][2] = (1.0f - frac) * currMeshFrame[t][2] + frac * nextMeshFrame[t][2]; 473 } 474 475 return data->tmpMesh[i]; 514 476 } 515 477 … … 518 480 * interpolate vertex normal 519 481 */ 520 MD3Normal* MD3Model::interpolateVertexNormals(MD3 Normal* currNormals, MD3Normal* nextNormals, float frac, MD3Mesh* mesh, int i)482 MD3Normal* MD3Model::interpolateVertexNormals(MD3Data* data, MD3Normal* currNormals, MD3Normal* nextNormals, float frac, MD3Mesh* mesh, int i) 521 483 { 522 484 for( int j = 0; j < mesh->header->vertexNum; j++) 523 485 { 524 this->tmpNormal[i][j].vertexNormal[0] = (int)((1.0f - frac) * currNormals[j].vertexNormal[0] + frac * nextNormals[j].vertexNormal[0]);525 this->tmpNormal[i][j].vertexNormal[1] = (int)((1.0f - frac) * currNormals[j].vertexNormal[1] + frac * nextNormals[j].vertexNormal[1]);526 } 527 528 return this->tmpNormal[i];486 data->tmpNormal[i][j].vertexNormal[0] = (int)((1.0f - frac) * currNormals[j].vertexNormal[0] + frac * nextNormals[j].vertexNormal[0]); 487 data->tmpNormal[i][j].vertexNormal[1] = (int)((1.0f - frac) * currNormals[j].vertexNormal[1] + frac * nextNormals[j].vertexNormal[1]); 488 } 489 490 return data->tmpNormal[i]; 529 491 } 530 492 … … 533 495 * interpolate transformation 534 496 */ 535 float* MD3Model::interpolateTransformation(MD3 Tag* currFrameTag, MD3Tag* nextFrameTag, float frac, int i)497 float* MD3Model::interpolateTransformation(MD3Data* data, MD3Tag* currFrameTag, MD3Tag* nextFrameTag, float frac, int i) 536 498 { 537 499 // interpolate position … … 550 512 551 513 // quaternion code is column based, so use transposed matrix when spitting out to gl 552 this->tmpMatrix[i][0] = interpolatedMatrix[0][0];553 this->tmpMatrix[i][4] = interpolatedMatrix[1][0];554 this->tmpMatrix[i][8] = interpolatedMatrix[2][0];555 this->tmpMatrix[i][12] = interpolatedPosition.x;556 this->tmpMatrix[i][1] = interpolatedMatrix[0][1];557 this->tmpMatrix[i][5] = interpolatedMatrix[1][1];558 this->tmpMatrix[i][9] = interpolatedMatrix[2][1];559 this->tmpMatrix[i][13] = interpolatedPosition.y;560 this->tmpMatrix[i][2] = interpolatedMatrix[0][2];561 this->tmpMatrix[i][6] = interpolatedMatrix[1][2];562 this->tmpMatrix[i][10]= interpolatedMatrix[2][2];563 this->tmpMatrix[i][14] = interpolatedPosition.z;564 this->tmpMatrix[i][3] = 0.0f;565 this->tmpMatrix[i][7] = 0.0f;566 this->tmpMatrix[i][11]= 0.0f;567 this->tmpMatrix[i][15] = 1.0f;568 569 return this->tmpMatrix[i];514 data->tmpMatrix[i][0] = interpolatedMatrix[0][0]; 515 data->tmpMatrix[i][4] = interpolatedMatrix[1][0]; 516 data->tmpMatrix[i][8] = interpolatedMatrix[2][0]; 517 data->tmpMatrix[i][12] = interpolatedPosition.x; 518 data->tmpMatrix[i][1] = interpolatedMatrix[0][1]; 519 data->tmpMatrix[i][5] = interpolatedMatrix[1][1]; 520 data->tmpMatrix[i][9] = interpolatedMatrix[2][1]; 521 data->tmpMatrix[i][13] = interpolatedPosition.y; 522 data->tmpMatrix[i][2] = interpolatedMatrix[0][2]; 523 data->tmpMatrix[i][6] = interpolatedMatrix[1][2]; 524 data->tmpMatrix[i][10]= interpolatedMatrix[2][2]; 525 data->tmpMatrix[i][14] = interpolatedPosition.z; 526 data->tmpMatrix[i][3] = 0.0f; 527 data->tmpMatrix[i][7] = 0.0f; 528 data->tmpMatrix[i][11]= 0.0f; 529 data->tmpMatrix[i][15] = 1.0f; 530 531 return data->tmpMatrix[i]; 570 532 571 533 } -
branches/bsp_model/src/lib/graphics/importer/md3/md3_model.h
r8597 r8634 50 50 void drawBoneFrame(MD3BoneFrame* frame) const; 51 51 52 MD3BoneFrame* interpolateBoneFrame(MD3 BoneFrame* currBoneFrame, MD3BoneFrame* nextBoneFrame, float frac);53 sVec3D* interpolateMeshFrame( sVec3D* currMeshFrame, sVec3D* nextMeshFrame, float frac, MD3Mesh* mesh, int i);54 MD3Normal* interpolateVertexNormals(MD3 Normal* curNormals, MD3Normal* nextNormals, float frac, MD3Mesh* mesh, int i);55 float* interpolateTransformation(MD3 Tag* currFrameTag, MD3Tag* nextFrameTag, float frac, int i);52 MD3BoneFrame* interpolateBoneFrame(MD3Data* data, MD3BoneFrame* currBoneFrame, MD3BoneFrame* nextBoneFrame, float frac); 53 sVec3D* interpolateMeshFrame(MD3Data* data, sVec3D* currMeshFrame, sVec3D* nextMeshFrame, float frac, MD3Mesh* mesh, int i); 54 MD3Normal* interpolateVertexNormals(MD3Data* data, MD3Normal* curNormals, MD3Normal* nextNormals, float frac, MD3Mesh* mesh, int i); 55 float* interpolateTransformation(MD3Data* data, MD3Tag* currFrameTag, MD3Tag* nextFrameTag, float frac, int i); 56 56 57 57 private: … … 63 63 MD3AnimationCfg* config; //!< the config file parsed 64 64 65 MD3BoneFrame* tmpBoneFrame; //!< a temporary bone frame66 sVec3D** tmpMesh; //!< a temporary mesh frame67 MD3Normal** tmpNormal; //!< a temporary normals frame68 float** tmpMatrix; //!< a temporary matrix69 65 70 66 };
Note: See TracChangeset
for help on using the changeset viewer.