Changeset 8563 in orxonox.OLD for branches/bsp_model
- Timestamp:
- Jun 17, 2006, 1:48:57 PM (19 years ago)
- Location:
- branches/bsp_model/src/lib/graphics/importer/md3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/bsp_model/src/lib/graphics/importer/md3/md3_model.cc
r8562 r8563 42 42 43 43 this->tmpBoneFrame = new MD3BoneFrame(); 44 this->tmpMesh = new sVec3D[2048]; //!< the temporary mesh, hopefully newer bigger than 2048 vertices 45 this->tmpNormal = new MD3Normal[2048]; //!< the temporary normals 44 45 this->tmpMesh = new sVec3D*[this->md3Data->meshNum]; 46 for( int i = 0; i < this->md3Data->meshNum; i++) 47 this->tmpMesh[i] = new sVec3D[this->md3Data->meshes[i]->header->vertexNum]; 48 49 this->tmpNormal = new MD3Normal[2048]; //!< the temporary normals 46 50 } 47 51 … … 56 60 57 61 62 63 void MD3Model::tick(float time) 64 { 65 66 } 67 68 void MD3Model::tick(float time, MD3Data* data) 69 { 70 // draw the bones if needed 71 if( this->bDrawBones) 72 { 73 // get bone frame, interpolate if necessary 74 if( data->animationState.interpolationFraction != 0.0 && 75 data->animationState.currentFrame != data->animationState.nextFrame) { 76 //interpolate bone frame 77 this->interpolateBoneFrame(data->boneFrames[data->animationState.currentFrame], 78 data->boneFrames[data->animationState.nextFrame], 79 data->animationState.interpolationFraction); 80 } 81 } 82 83 84 //draw all meshes of current frame of this model 85 for( int i = 0; i < data->meshNum; i++) 86 { 87 MD3Mesh* mesh = data->meshes[i]; 88 89 90 // get mesh frame, do interpolation if necessary 91 sVec3D* frame; 92 if( data->animationState.interpolationFraction != 0.0 && 93 data->animationState.currentFrame != data->animationState.nextFrame) { 94 //interpolate mesh frame between the 2 current mesh frames 95 frame = this->interpolateMeshFrame( data->meshes[data->animationState.currentFrame]->meshFrames, 96 data->meshes[data->animationState.nextFrame]->meshFrames, 97 data->animationState.interpolationFraction, mesh, i); 98 } 99 else { 100 //no interpolation needed, just draw current frame 101 frame = &mesh->meshFrames[data->animationState.currentFrame]; 102 } 103 104 this->drawMesh(mesh, frame); 105 106 107 // draw vertex normals if needed 108 if( this->bDrawNormals) { 109 // get vertex normals, interpolate if necessary 110 if( data->animationState.interpolationFraction != 0.0 && 111 data->animationState.currentFrame != data->animationState.nextFrame) { 112 //interpolate vertex normals 113 this->drawVertexNormals(frame, this->interpolateVertexNormals(&mesh->normals[data->animationState.currentFrame], 114 &mesh->normals[data->animationState.nextFrame], data->animationState.interpolationFraction, mesh)); 115 } 116 else { 117 //stick with current vertex normals 118 this->drawVertexNormals(frame, &mesh->normals[data->animationState.currentFrame]); 119 } 120 } 121 } 122 123 124 // draw all models linked to this model 125 std::map<int, MD3Data*>::iterator it = data->sortedMap.begin(); 126 while( it != data->sortedMap.end()) 127 { 128 MD3Data* child = it->second; 129 130 //build transformation array m from matrix, interpolate if necessary 131 float* m = new float[16]; 132 133 MD3Tag* currFrameTag = data->boneFrames[data->animationState.currentFrame]->tags[child->parentTagIndex]; 134 135 if( data->animationState.interpolationFraction != 0.0 && 136 data->animationState.currentFrame != data->animationState.nextFrame) { 137 //we need to interpolate 138 MD3Tag* nextFrameTag = data->boneFrames[data->animationState.nextFrame]->tags[child->parentTagIndex]; 139 m = this->interpolateTransformation(currFrameTag, nextFrameTag, data->animationState.interpolationFraction); 140 } 141 else { 142 //no interpolation needed, stay with last transformation 143 //OpenGL matrix is in column-major order 144 m[0] = currFrameTag->matrix[0][0]; 145 m[1] = currFrameTag->matrix[1][0]; 146 m[2] = currFrameTag->matrix[2][0]; 147 m[3] = 0.0f; 148 m[4] = currFrameTag->matrix[0][1]; 149 m[5] = currFrameTag->matrix[1][1]; 150 m[6] = currFrameTag->matrix[2][1]; 151 m[7] = 0.0f; 152 m[8] = currFrameTag->matrix[0][2]; 153 m[9] = currFrameTag->matrix[1][2]; 154 m[10]= currFrameTag->matrix[2][2]; 155 m[11]= 0.0f; 156 m[12] = currFrameTag->position.x; 157 m[13] = currFrameTag->position.y; 158 m[14] = currFrameTag->position.z; 159 m[15] = 1.0f; 160 } 161 162 //switch to child coord system 163 glPushMatrix(); 164 glMultMatrixf(m); 165 166 // and draw child 167 this->draw(child); 168 169 glPopMatrix(); 170 } 171 } 172 173 58 174 /** 59 175 * this draws the md3 model … … 62 178 { 63 179 //draw current bone frame 64 this->draw(this->md3Data);180 // this->draw(this->md3Data); 65 181 66 182 PRINTF(0)("draw\n"); … … 113 229 frame = this->interpolateMeshFrame( data->meshes[data->animationState.currentFrame]->meshFrames, 114 230 data->meshes[data->animationState.nextFrame]->meshFrames, 115 data->animationState.interpolationFraction, mesh );231 data->animationState.interpolationFraction, mesh, i); 116 232 } 117 else {118 //no interpolation needed, just draw current frame119 frame = &mesh->meshFrames[data->animationState.currentFrame];120 }121 122 this->drawMesh(mesh, frame);123 124 233 125 234 // draw vertex normals if needed … … 129 238 data->animationState.currentFrame != data->animationState.nextFrame) { 130 239 //interpolate vertex normals 131 this->drawVertexNormals(frame, this->interpolateVertexNormals(&mesh->normals[data->animationState.currentFrame], 132 &mesh->normals[data->animationState.nextFrame], data->animationState.interpolationFraction, mesh)); 133 } 134 else { 135 //stick with current vertex normals 136 this->drawVertexNormals(frame, &mesh->normals[data->animationState.currentFrame]); 240 this->interpolateVertexNormals(&mesh->normals[data->animationState.currentFrame], 241 &mesh->normals[data->animationState.nextFrame], 242 data->animationState.interpolationFraction, mesh); 137 243 } 138 244 } … … 320 426 321 427 428 322 429 /** 323 430 * interpolate mesh frame 324 431 */ 325 sVec3D* MD3Model::interpolateMeshFrame(sVec3D* currMeshFrame, sVec3D* nextMeshFrame, float frac, MD3Mesh* mesh )432 sVec3D* MD3Model::interpolateMeshFrame(sVec3D* currMeshFrame, sVec3D* nextMeshFrame, float frac, MD3Mesh* mesh, int i) 326 433 { 327 434 int vertexNum = mesh->header->vertexNum; … … 330 437 for( int t = 0; t < vertexNum * 3.0f; t++) 331 438 { 332 this->tmpMesh[ t][0] = (1.0f - frac) * currMeshFrame[t][0] + frac * nextMeshFrame[t][0];333 this->tmpMesh[ t][1] = (1.0f - frac) * currMeshFrame[t][1] + frac * nextMeshFrame[t][1];334 this->tmpMesh[ t][2] = (1.0f - frac) * currMeshFrame[t][2] + frac * nextMeshFrame[t][2];335 } 336 337 return this->tmpMesh ;439 this->tmpMesh[i][t][0] = (1.0f - frac) * currMeshFrame[t][0] + frac * nextMeshFrame[t][0]; 440 this->tmpMesh[i][t][1] = (1.0f - frac) * currMeshFrame[t][1] + frac * nextMeshFrame[t][1]; 441 this->tmpMesh[i][t][2] = (1.0f - frac) * currMeshFrame[t][2] + frac * nextMeshFrame[t][2]; 442 } 443 444 return this->tmpMesh[i]; 338 445 } 339 446 -
branches/bsp_model/src/lib/graphics/importer/md3/md3_model.h
r8562 r8563 34 34 virtual void setAnimation(int animNum, int playbackMode = 0) {} 35 35 36 virtual void tick(float dt) {} 37 38 virtual void draw(); 36 virtual void tick(float dt); 37 virtual void draw() ; 39 38 40 39 41 40 private: 42 41 void draw(MD3Data* data); 42 void tick(float dt, MD3Data* data); 43 43 44 void drawMesh(MD3Mesh* mesh, sVec3D* frame) ;45 void drawVertexNormals(sVec3D* frame, MD3Normal* normals) ;46 44 void drawMesh(MD3Mesh* mesh, sVec3D* frame) ; 45 void drawVertexNormals(sVec3D* frame, MD3Normal* normals) ; 46 void drawBoneFrame(MD3BoneFrame* frame) ; 47 47 48 48 MD3BoneFrame* interpolateBoneFrame(MD3BoneFrame* currBoneFrame, MD3BoneFrame* nextBoneFrame, float frac); 49 void drawBoneFrame(MD3BoneFrame* frame); 50 51 sVec3D* interpolateMeshFrame(sVec3D* currMeshFrame, sVec3D* nextMeshFrame, float frac, MD3Mesh* mesh); 49 sVec3D* interpolateMeshFrame(sVec3D* currMeshFrame, sVec3D* nextMeshFrame, float frac, MD3Mesh* mesh, int i); 52 50 MD3Normal* interpolateVertexNormals(MD3Normal* curNormals, MD3Normal* nextNormals, float frac, MD3Mesh* mesh); 53 51 float* interpolateTransformation(MD3Tag* currFrameTag, MD3Tag* nextFrameTag, float frac); … … 60 58 61 59 MD3BoneFrame* tmpBoneFrame; //!< a temporary bone frame 62 sVec3D* 60 sVec3D** tmpMesh; //!< a temporary mesh frame 63 61 MD3Normal* tmpNormal; //!< a temporary normals frame 64 62 float tmpMatrix[16]; //!< a temporary matrix
Note: See TracChangeset
for help on using the changeset viewer.