Changeset 8565 in orxonox.OLD for branches/bsp_model/src/lib/graphics
- Timestamp:
- Jun 17, 2006, 2:13:26 PM (18 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
r8564 r8565 47 47 this->tmpMesh[i] = new sVec3D[this->md3Data->meshes[i]->header->vertexNum]; 48 48 49 this->tmpNormal = new MD3Normal[2048]; //!< the temporary normals 49 this->tmpNormal = new MD3Normal*[this->md3Data->meshNum]; 50 for( int i = 0; i < this->md3Data->meshNum; i++) 51 this->tmpNormal[i] = new MD3Normal[this->md3Data->meshes[i]->header->vertexNum]; 50 52 51 53 this->tmpMatrix = new float*[this->md3Data->tagNum]; … … 112 114 113 115 114 // draw vertex normals if needed 115 if( this->bDrawNormals) { 116 // get vertex normals, interpolate if necessary 116 117 118 // draw vertex normals if needed 119 if( this->bDrawNormals) 120 { 121 // get vertex normals, interpolate if necessary 117 122 if( data->animationState.interpolationFraction != 0.0 && 118 data->animationState.currentFrame != data->animationState.nextFrame) { 119 //interpolate vertex normals 120 this->drawVertexNormals(frame, this->interpolateVertexNormals(&mesh->normals[data->animationState.currentFrame], 121 &mesh->normals[data->animationState.nextFrame], data->animationState.interpolationFraction, mesh)); 122 } 123 else { 124 //stick with current vertex normals 125 this->drawVertexNormals(frame, &mesh->normals[data->animationState.currentFrame]); 126 } 123 data->animationState.currentFrame != data->animationState.nextFrame) 124 { 125 //interpolate vertex normals 126 this->interpolateVertexNormals(&mesh->normals[data->animationState.currentFrame], 127 &mesh->normals[data->animationState.nextFrame], 128 data->animationState.interpolationFraction, mesh, i); 129 } 127 130 } 128 131 } 132 129 133 130 134 … … 184 188 * this draws the md3 model 185 189 */ 186 void MD3Model::draw() 187 { 190 void MD3Model::draw() const 191 { 192 PRINTF(0)("draw\n"); 193 188 194 //draw current bone frame 189 // this->draw(this->md3Data); 190 191 PRINTF(0)("draw\n"); 195 this->draw(this->md3Data); 192 196 } 193 197 … … 197 201 * @param data: the data to be drawn 198 202 */ 199 void MD3Model::draw(MD3Data* data) 203 void MD3Model::draw(MD3Data* data) const 200 204 { 201 205 … … 207 211 data->animationState.currentFrame != data->animationState.nextFrame) { 208 212 //interpolate bone frame 209 this->drawBoneFrame(this->interpolateBoneFrame(data->boneFrames[data->animationState.currentFrame], 210 data->boneFrames[data->animationState.nextFrame], 211 data->animationState.interpolationFraction)); 213 this->drawBoneFrame(this->tmpBoneFrame); 212 214 } 213 215 else { … … 230 232 231 233 // get mesh frame, do interpolation if necessary 232 sVec3D* frame; 233 if( data->animationState.interpolationFraction != 0.0 && 234 data->animationState.currentFrame != data->animationState.nextFrame) { 235 //interpolate mesh frame between the 2 current mesh frames 236 // frame = this->interpolateMeshFrame(mesh, data->animationState.currentFrame, data->animationState.nextFrame, 237 // data->animationState.interpolationFraction); 238 frame = this->interpolateMeshFrame( data->meshes[data->animationState.currentFrame]->meshFrames, 239 data->meshes[data->animationState.nextFrame]->meshFrames, 240 data->animationState.interpolationFraction, mesh, i); 241 } 234 sVec3D* frame = this->tmpMesh[i]; 235 236 this->drawMesh(mesh, frame); 242 237 243 238 … … 248 243 data->animationState.currentFrame != data->animationState.nextFrame) { 249 244 //interpolate vertex normals 250 this->interpolateVertexNormals(&mesh->normals[data->animationState.currentFrame], 251 &mesh->normals[data->animationState.nextFrame], 252 data->animationState.interpolationFraction, mesh); 253 } 245 this->drawVertexNormals(frame, this->tmpNormal[i]); 246 } 247 else { 248 //stick with current vertex normals 249 this->drawVertexNormals(frame, &mesh->normals[data->animationState.currentFrame]); 250 } 254 251 } 255 252 } … … 257 254 258 255 // draw all models linked to this model 256 int i = 0; 259 257 std::map<int, MD3Data*>::iterator it = data->sortedMap.begin(); 260 258 while( it != data->sortedMap.end()) … … 270 268 data->animationState.currentFrame != data->animationState.nextFrame) { 271 269 //we need to interpolate 272 MD3Tag* nextFrameTag = data->boneFrames[data->animationState.nextFrame]->tags[child->parentTagIndex]; 273 // m = this->interpolateTransformation(currFrameTag, nextFrameTag, data->animationState.interpolationFraction); 270 m = this->tmpMatrix[i]; 274 271 } 275 272 else { … … 302 299 303 300 glPopMatrix(); 301 i++; 304 302 } 305 303 } … … 309 307 * draws the mesh 310 308 */ 311 void MD3Model::drawMesh(MD3Mesh* mesh, sVec3D* frame) 309 void MD3Model::drawMesh(MD3Mesh* mesh, sVec3D* frame) const 312 310 { 313 311 glColor3f(1.0f, 1.0f, 1.0f); 314 312 glBegin( GL_TRIANGLES ); 313 314 Vector tmpVec1, tmpVec2; 315 315 316 316 // upload all triangles in the frame to OpenGL 317 317 for( int t = 0; t < mesh->header->triangleNum; t++) { 318 318 // calc normal vector 319 t his->tmpVec1.x = frame[mesh->triangles[t].vertexOffset[1]][0] - frame[mesh->triangles[t].vertexOffset[0]][0];320 t his->tmpVec2.x = frame[mesh->triangles[t].vertexOffset[2]][0] - frame[mesh->triangles[t].vertexOffset[0]][0];321 322 t his->tmpVec1.y = frame[mesh->triangles[t].vertexOffset[1]][1] - frame[mesh->triangles[t].vertexOffset[0]][1];323 t his->tmpVec2.y = frame[mesh->triangles[t].vertexOffset[2]][1] - frame[mesh->triangles[t].vertexOffset[0]][1];324 325 t his->tmpVec1.z = frame[mesh->triangles[t].vertexOffset[1]][2] - frame[mesh->triangles[t].vertexOffset[0]][2];326 t his->tmpVec2.z = frame[mesh->triangles[t].vertexOffset[2]][2] - frame[mesh->triangles[t].vertexOffset[0]][2];327 328 Vector normal = t his->tmpVec1.cross(tmpVec2);319 tmpVec1.x = frame[mesh->triangles[t].vertexOffset[1]][0] - frame[mesh->triangles[t].vertexOffset[0]][0]; 320 tmpVec2.x = frame[mesh->triangles[t].vertexOffset[2]][0] - frame[mesh->triangles[t].vertexOffset[0]][0]; 321 322 tmpVec1.y = frame[mesh->triangles[t].vertexOffset[1]][1] - frame[mesh->triangles[t].vertexOffset[0]][1]; 323 tmpVec2.y = frame[mesh->triangles[t].vertexOffset[2]][1] - frame[mesh->triangles[t].vertexOffset[0]][1]; 324 325 tmpVec1.z = frame[mesh->triangles[t].vertexOffset[1]][2] - frame[mesh->triangles[t].vertexOffset[0]][2]; 326 tmpVec2.z = frame[mesh->triangles[t].vertexOffset[2]][2] - frame[mesh->triangles[t].vertexOffset[0]][2]; 327 328 Vector normal = tmpVec1.cross(tmpVec2); 329 329 normal.normalize(); 330 330 … … 353 353 * drawo vertex normals 354 354 */ 355 void MD3Model::drawVertexNormals(sVec3D* frame, MD3Normal* normals) 355 void MD3Model::drawVertexNormals(sVec3D* frame, MD3Normal* normals) const 356 356 {} 357 357 … … 360 360 * draw bone frame 361 361 */ 362 void MD3Model::drawBoneFrame(MD3BoneFrame* frame) 362 void MD3Model::drawBoneFrame(MD3BoneFrame* frame) const 363 363 { 364 364 float x1 = frame->mins.x; … … 459 459 * interpolate vertex normal 460 460 */ 461 MD3Normal* MD3Model::interpolateVertexNormals(MD3Normal* currNormals, MD3Normal* nextNormals, float frac, MD3Mesh* mesh )462 { 463 for( int i = 0; i < mesh->header->vertexNum; i++)464 { 465 this->tmpNormal[i] .vertexNormal[0] = (int)((1.0f - frac) * currNormals[i].vertexNormal[0] + frac * nextNormals[i].vertexNormal[0]);466 this->tmpNormal[i] .vertexNormal[1] = (int)((1.0f - frac) * currNormals[i].vertexNormal[1] + frac * nextNormals[i].vertexNormal[1]);467 } 468 469 return this->tmpNormal ;461 MD3Normal* MD3Model::interpolateVertexNormals(MD3Normal* currNormals, MD3Normal* nextNormals, float frac, MD3Mesh* mesh, int i) 462 { 463 for( int j = 0; j < mesh->header->vertexNum; j++) 464 { 465 this->tmpNormal[i][j].vertexNormal[0] = (int)((1.0f - frac) * currNormals[j].vertexNormal[0] + frac * nextNormals[j].vertexNormal[0]); 466 this->tmpNormal[i][j].vertexNormal[1] = (int)((1.0f - frac) * currNormals[j].vertexNormal[1] + frac * nextNormals[j].vertexNormal[1]); 467 } 468 469 return this->tmpNormal[i]; 470 470 } 471 471 -
branches/bsp_model/src/lib/graphics/importer/md3/md3_model.h
r8564 r8565 35 35 36 36 virtual void tick(float dt); 37 virtual void draw() ;37 virtual void draw() const; 38 38 39 39 40 40 private: 41 void draw(MD3Data* data) ;41 void draw(MD3Data* data) const; 42 42 void tick(float dt, MD3Data* data); 43 43 44 void drawMesh(MD3Mesh* mesh, sVec3D* frame) ;45 void drawVertexNormals(sVec3D* frame, MD3Normal* normals) ;46 void drawBoneFrame(MD3BoneFrame* frame) ;44 void drawMesh(MD3Mesh* mesh, sVec3D* frame) const; 45 void drawVertexNormals(sVec3D* frame, MD3Normal* normals) const; 46 void drawBoneFrame(MD3BoneFrame* frame) const; 47 47 48 48 MD3BoneFrame* interpolateBoneFrame(MD3BoneFrame* currBoneFrame, MD3BoneFrame* nextBoneFrame, float frac); 49 49 sVec3D* interpolateMeshFrame(sVec3D* currMeshFrame, sVec3D* nextMeshFrame, float frac, MD3Mesh* mesh, int i); 50 MD3Normal* interpolateVertexNormals(MD3Normal* curNormals, MD3Normal* nextNormals, float frac, MD3Mesh* mesh );50 MD3Normal* interpolateVertexNormals(MD3Normal* curNormals, MD3Normal* nextNormals, float frac, MD3Mesh* mesh, int i); 51 51 float* interpolateTransformation(MD3Tag* currFrameTag, MD3Tag* nextFrameTag, float frac, int i); 52 52 … … 59 59 MD3BoneFrame* tmpBoneFrame; //!< a temporary bone frame 60 60 sVec3D** tmpMesh; //!< a temporary mesh frame 61 MD3Normal* 61 MD3Normal** tmpNormal; //!< a temporary normals frame 62 62 float** tmpMatrix; //!< a temporary matrix 63 Vector tmpVec1; 64 Vector tmpVec2; 63 65 64 }; 66 65
Note: See TracChangeset
for help on using the changeset viewer.