Index: branches/bsp_model/src/lib/graphics/importer/md3/md3_model.cc
===================================================================
--- branches/bsp_model/src/lib/graphics/importer/md3/md3_model.cc	(revision 8564)
+++ branches/bsp_model/src/lib/graphics/importer/md3/md3_model.cc	(revision 8565)
@@ -47,5 +47,7 @@
       this->tmpMesh[i] = new sVec3D[this->md3Data->meshes[i]->header->vertexNum];
 
-    this->tmpNormal = new MD3Normal[2048];                    //!< the temporary normals
+    this->tmpNormal = new MD3Normal*[this->md3Data->meshNum];
+    for( int i = 0; i < this->md3Data->meshNum; i++)
+      this->tmpNormal[i] = new MD3Normal[this->md3Data->meshes[i]->header->vertexNum];
 
     this->tmpMatrix = new float*[this->md3Data->tagNum];
@@ -112,19 +114,21 @@
 
 
-      // draw vertex normals if needed
-          if( this->bDrawNormals) {
-        // get vertex normals, interpolate if necessary
+
+
+          // draw vertex normals if needed
+          if( this->bDrawNormals)
+          {
+            // get vertex normals, interpolate if necessary
             if( data->animationState.interpolationFraction != 0.0 &&
-                data->animationState.currentFrame != data->animationState.nextFrame) {
-          //interpolate vertex normals
-              this->drawVertexNormals(frame, this->interpolateVertexNormals(&mesh->normals[data->animationState.currentFrame],
-                                      &mesh->normals[data->animationState.nextFrame], data->animationState.interpolationFraction, mesh));
-                }
-                else {
-          //stick with current vertex normals
-                  this->drawVertexNormals(frame, &mesh->normals[data->animationState.currentFrame]);
-                }
+                data->animationState.currentFrame != data->animationState.nextFrame)
+            {
+              //interpolate vertex normals
+              this->interpolateVertexNormals(&mesh->normals[data->animationState.currentFrame],
+                                              &mesh->normals[data->animationState.nextFrame],
+                                              data->animationState.interpolationFraction, mesh, i);
+             }
           }
     }
+
 
 
@@ -184,10 +188,10 @@
    * this draws the md3 model
    */
-  void MD3Model::draw()
-  {
+  void MD3Model::draw() const
+  {
+    PRINTF(0)("draw\n");
+
     //draw current bone frame
-//     this->draw(this->md3Data);
-
-    PRINTF(0)("draw\n");
+    this->draw(this->md3Data);
   }
 
@@ -197,5 +201,5 @@
    * @param data: the data to be drawn
    */
-  void MD3Model::draw(MD3Data* data)
+  void MD3Model::draw(MD3Data* data) const
   {
 
@@ -207,7 +211,5 @@
           data->animationState.currentFrame != data->animationState.nextFrame) {
         //interpolate bone frame
-        this->drawBoneFrame(this->interpolateBoneFrame(data->boneFrames[data->animationState.currentFrame],
-                            data->boneFrames[data->animationState.nextFrame],
-                            data->animationState.interpolationFraction));
+        this->drawBoneFrame(this->tmpBoneFrame);
       }
       else {
@@ -230,14 +232,7 @@
 
       // get mesh frame, do interpolation if necessary
-      sVec3D* frame;
-      if( data->animationState.interpolationFraction != 0.0 &&
-          data->animationState.currentFrame != data->animationState.nextFrame) {
-        //interpolate mesh frame between the 2 current mesh frames
-//         frame = this->interpolateMeshFrame(mesh, data->animationState.currentFrame, data->animationState.nextFrame,
-//                                            data->animationState.interpolationFraction);
-        frame = this->interpolateMeshFrame( data->meshes[data->animationState.currentFrame]->meshFrames,
-                                            data->meshes[data->animationState.nextFrame]->meshFrames,
-                                            data->animationState.interpolationFraction, mesh, i);
-      }
+      sVec3D* frame = this->tmpMesh[i];
+
+      this->drawMesh(mesh, frame);
 
 
@@ -248,8 +243,10 @@
             data->animationState.currentFrame != data->animationState.nextFrame) {
           //interpolate vertex normals
-          this->interpolateVertexNormals(&mesh->normals[data->animationState.currentFrame],
-                                         &mesh->normals[data->animationState.nextFrame],
-                                         data->animationState.interpolationFraction, mesh);
-        }
+          this->drawVertexNormals(frame, this->tmpNormal[i]);
+            }
+            else {
+          //stick with current vertex normals
+              this->drawVertexNormals(frame, &mesh->normals[data->animationState.currentFrame]);
+            }
       }
     }
@@ -257,4 +254,5 @@
 
     // draw all models linked to this model
+    int i = 0;
     std::map<int, MD3Data*>::iterator it = data->sortedMap.begin();
     while( it != data->sortedMap.end())
@@ -270,6 +268,5 @@
           data->animationState.currentFrame != data->animationState.nextFrame) {
         //we need to interpolate
-        MD3Tag* nextFrameTag = data->boneFrames[data->animationState.nextFrame]->tags[child->parentTagIndex];
-//         m = this->interpolateTransformation(currFrameTag, nextFrameTag, data->animationState.interpolationFraction);
+        m = this->tmpMatrix[i];
       }
       else {
@@ -302,4 +299,5 @@
 
       glPopMatrix();
+      i++;
     }
   }
@@ -309,22 +307,24 @@
    * draws the mesh
    */
-  void MD3Model::drawMesh(MD3Mesh* mesh, sVec3D* frame)
+  void MD3Model::drawMesh(MD3Mesh* mesh, sVec3D* frame) const
   {
     glColor3f(1.0f, 1.0f, 1.0f);
     glBegin( GL_TRIANGLES );
+
+    Vector tmpVec1, tmpVec2;
 
     // upload all triangles in the frame to OpenGL
     for( int t = 0; t < mesh->header->triangleNum; t++) {
       // calc normal vector
-      this->tmpVec1.x = frame[mesh->triangles[t].vertexOffset[1]][0] - frame[mesh->triangles[t].vertexOffset[0]][0];
-      this->tmpVec2.x = frame[mesh->triangles[t].vertexOffset[2]][0] - frame[mesh->triangles[t].vertexOffset[0]][0];
-
-      this->tmpVec1.y = frame[mesh->triangles[t].vertexOffset[1]][1] - frame[mesh->triangles[t].vertexOffset[0]][1];
-      this->tmpVec2.y = frame[mesh->triangles[t].vertexOffset[2]][1] - frame[mesh->triangles[t].vertexOffset[0]][1];
-
-      this->tmpVec1.z = frame[mesh->triangles[t].vertexOffset[1]][2] - frame[mesh->triangles[t].vertexOffset[0]][2];
-      this->tmpVec2.z = frame[mesh->triangles[t].vertexOffset[2]][2] - frame[mesh->triangles[t].vertexOffset[0]][2];
-
-      Vector normal = this->tmpVec1.cross(tmpVec2);
+      tmpVec1.x = frame[mesh->triangles[t].vertexOffset[1]][0] - frame[mesh->triangles[t].vertexOffset[0]][0];
+      tmpVec2.x = frame[mesh->triangles[t].vertexOffset[2]][0] - frame[mesh->triangles[t].vertexOffset[0]][0];
+
+      tmpVec1.y = frame[mesh->triangles[t].vertexOffset[1]][1] - frame[mesh->triangles[t].vertexOffset[0]][1];
+      tmpVec2.y = frame[mesh->triangles[t].vertexOffset[2]][1] - frame[mesh->triangles[t].vertexOffset[0]][1];
+
+      tmpVec1.z = frame[mesh->triangles[t].vertexOffset[1]][2] - frame[mesh->triangles[t].vertexOffset[0]][2];
+      tmpVec2.z = frame[mesh->triangles[t].vertexOffset[2]][2] - frame[mesh->triangles[t].vertexOffset[0]][2];
+
+      Vector normal = tmpVec1.cross(tmpVec2);
       normal.normalize();
 
@@ -353,5 +353,5 @@
    *  drawo vertex normals
    */
-  void MD3Model::drawVertexNormals(sVec3D* frame, MD3Normal* normals)
+  void MD3Model::drawVertexNormals(sVec3D* frame, MD3Normal* normals) const
   {}
 
@@ -360,5 +360,5 @@
    * draw bone frame
    */
-  void MD3Model::drawBoneFrame(MD3BoneFrame* frame)
+  void MD3Model::drawBoneFrame(MD3BoneFrame* frame) const
   {
     float x1 = frame->mins.x;
@@ -459,13 +459,13 @@
    * interpolate vertex normal
    */
-  MD3Normal* MD3Model::interpolateVertexNormals(MD3Normal* currNormals, MD3Normal* nextNormals, float frac, MD3Mesh* mesh)
-  {
-    for( int i = 0; i < mesh->header->vertexNum; i++)
-    {
-      this->tmpNormal[i].vertexNormal[0] = (int)((1.0f - frac) * currNormals[i].vertexNormal[0] + frac * nextNormals[i].vertexNormal[0]);
-      this->tmpNormal[i].vertexNormal[1] = (int)((1.0f - frac) * currNormals[i].vertexNormal[1] + frac * nextNormals[i].vertexNormal[1]);
-    }
-
-    return this->tmpNormal;
+  MD3Normal* MD3Model::interpolateVertexNormals(MD3Normal* currNormals, MD3Normal* nextNormals, float frac, MD3Mesh* mesh, int i)
+  {
+    for( int j = 0; j < mesh->header->vertexNum; j++)
+    {
+      this->tmpNormal[i][j].vertexNormal[0] = (int)((1.0f - frac) * currNormals[j].vertexNormal[0] + frac * nextNormals[j].vertexNormal[0]);
+      this->tmpNormal[i][j].vertexNormal[1] = (int)((1.0f - frac) * currNormals[j].vertexNormal[1] + frac * nextNormals[j].vertexNormal[1]);
+    }
+
+    return this->tmpNormal[i];
   }
 
