Index: /orxonox/trunk/src/lib/graphics/importer/md2Model.cc
===================================================================
--- /orxonox/trunk/src/lib/graphics/importer/md2Model.cc	(revision 4281)
+++ /orxonox/trunk/src/lib/graphics/importer/md2Model.cc	(revision 4282)
@@ -68,10 +68,185 @@
 
 /********************************************************************************
- *   MD2Model2                                                                  *
+ *   MD2Model                                                                   *
  ********************************************************************************/
 
 MD2Model::MD2Model()
 {
-  /*
+  /* this creates the data container via ressource manager */
+  this->data = new MD2Data();
+  this->scaleFactor = this->data->scaleFactor;
+
+  this->setAnim(BOOM);
+}
+
+
+MD2Model::~MD2Model()
+{
+
+}
+
+
+bool MD2Model::loadModel(const char* fileName)
+{
+  return this->data->loadModel(fileName);
+}
+
+
+bool MD2Model::loadSkin(const char* fileName)
+{
+  return this->data->loadSkin(fileName);
+}
+
+
+/**
+   \brief initializes an array of vert with the current frame scaled vertices
+
+   we won't use the pVertices array directly, since its much easier and we need
+   saving of data anyway
+*/
+void MD2Model::interpolate(sVec3D* verticesList)
+{
+  sVec3D* currVec;
+  sVec3D* nextVec;
+
+  currVec = &this->data->pVertices[this->data->numVertices * this->animationState.currentFrame];
+  nextVec = &this->data->pVertices[this->data->numVertices * this->animationState.nextFrame];
+
+  for(int i = 0; i < this->data->numFrames; ++i)
+    {
+      verticesList[i][0] = (currVec[i][0] + this->animationState.interpolationState * (nextVec[i][0] - currVec[i][0])) * this->scaleFactor;
+      verticesList[i][1] = (currVec[i][1] + this->animationState.interpolationState * (nextVec[i][1] - currVec[i][1])) * this->scaleFactor;
+      verticesList[i][2] = (currVec[i][2] + this->animationState.interpolationState * (nextVec[i][2] - currVec[i][2])) * this->scaleFactor;
+    }
+}
+
+
+void MD2Model::setAnim(int type)
+{
+  if( (type < 0) || (type > MAX_ANIMATIONS) )
+    type = 0;
+
+  this->animationState.startFrame = animationList[type].firstFrame;
+  this->animationState.endFrame = animationList[type].lastFrame;
+  this->animationState.nextFrame = animationList[type].firstFrame + 1;
+  this->animationState.fps = animationList[type].fps;
+  this->animationState.type = type;
+  
+  this->animationState.interpolationState = 0.0;
+  this->animationState.localTime = 0.0;
+  this->animationState.lastTime = 0.0;
+  this->animationState.currentFrame = animationList[type].firstFrame;
+}
+
+
+void MD2Model::tick(float time)
+{
+  this->animationState.localTime += time;
+}
+
+
+void MD2Model::draw()
+{
+  if( likely(this->animationState.localTime > 0.0))
+    this->animate();
+
+  glPushMatrix();
+
+  this->renderFrame();
+
+  glPopMatrix();
+} 
+
+
+void MD2Model::renderFrame()
+{
+  static sVec3D verticesList[MD2_MAX_VERTICES]; /* performance: created only once in a lifetime */
+  int* pCommands = this->data->pGLCommands;
+
+  /* some face culling stuff */
+  glPushAttrib(GL_POLYGON_BIT);
+  glFrontFace(GL_CW);
+  glEnable(GL_CULL_FACE);
+  glCullFace(GL_BACK);
+     
+  this->processLighting();
+  this->interpolate(verticesList);
+  this->data->material->select();
+
+  /* draw the triangles */
+  while( int i = *(pCommands++)) /* strange looking while loop for maximum performance */
+    {
+      if( i < 0)
+	{
+	  glBegin(GL_TRIANGLE_FAN);
+	  i = -i;
+	}
+      else
+	{
+	  glBegin(GL_TRIANGLE_STRIP);
+	}
+
+      for(; i > 0; i--, pCommands += 3) /* down counting for loop, next 3 gl commands */
+	{
+	  glNormal3fv(anorms[this->data->pLightNormals[pCommands[2]]]);
+	  glTexCoord2f( ((float *)pCommands)[0], 1.0-((float *)pCommands)[1] );
+	  glVertex3fv(verticesList[pCommands[2]]);
+	}
+      glEnd();
+    }
+  glDisable(GL_CULL_FACE);
+  glPopAttrib();
+}
+
+
+void MD2Model::animate()
+{
+  if( this->animationState.localTime - this->animationState.lastTime > (1.0f / this->animationState.fps))
+    {
+      this->animationState.currentFrame = this->animationState.nextFrame;
+      this->animationState.nextFrame++;
+      
+      if( this->animationState.nextFrame > this->animationState.endFrame)
+	this->animationState.nextFrame = this->animationState.startFrame;
+      this->animationState.lastTime = this->animationState.localTime;
+    }
+
+  if( this->animationState.currentFrame > (this->data->numFrames - 1) )
+    this->animationState.currentFrame = 0;
+  if( this->animationState.nextFrame > (this->data->numFrames - 1) )
+    this->animationState.nextFrame = 0;
+
+  this->animationState.interpolationState = this->animationState.fps * 
+    (this->animationState.localTime - this->animationState.lastTime);
+}
+
+
+/* hhmmm... id used a very different way to do lightning... */
+void MD2Model::processLighting()
+{
+  shadeDots = anormsDots[((int)(md2Angle*(SHADEDOT_QUANT / 360.0)))&(SHADEDOT_QUANT - 1)];
+}
+
+
+void MD2Model::debug()
+{
+  PRINT(0)("\n==========================| MD2Model::debug() |===\n");
+  PRINT(0)("=  Model FileName:\t%s\n", this->data->fileName);
+  PRINT(0)("=  Skin FileName:\t%s\n", this->data->skinFileName);
+  PRINT(0)("=  Size in Memory:\t%i Bytes\n", this->data->header->frameSize * this->data->header->numFrames + 64); // 64bytes is the header size
+  PRINT(0)("=  Number of Vertices:\t%i\n", this->data->header->numVertices);
+  PRINT(0)("=  Number of Frames: \t%i\n", this->data->header->numFrames);
+  PRINT(0)("=  Height, Width:\t%i, %i\n", this->data->header->skinHeight, this->data->header->skinWidth);
+  PRINT(0)("===================================================\n\n");
+}
+
+
+/********************************************************************************
+ *   MD2Data                                                                    *
+ ********************************************************************************/
+
+
+MD2Data::MD2Data()
+{
   this->pVertices = NULL;
   this->pGLCommands = NULL;
@@ -83,29 +258,18 @@
   
   this->scaleFactor = 1.0f;
-  */
-
-  /* this creates the data container via ressource manager */
-  this->data = new MD2Data();
-
-  this->setAnim(BOOM);
-}
-
-
-MD2Model::~MD2Model()
-{
-  /*
+}
+
+
+MD2Data::~MD2Data()
+{
   delete [] this->pVertices;
   delete [] this->pGLCommands;
   delete [] this->pLightNormals;
-  */
-}
-
-
-
-bool MD2Model::loadModel(const char* fileName)
-{
-  return this->data->loadModel(fileName);
-  
-
+}
+
+
+
+bool MD2Data::loadModel(const char* fileName)
+{
   FILE *pFile;                            //file stream
   char* buffer;                           //buffer for frame data
@@ -171,10 +335,9 @@
 
 
-bool MD2Model::loadSkin(const char* fileName)
-{
-  return this->data->loadSkin(fileName);
-
+bool MD2Data::loadSkin(const char* fileName)
+{
   this->skinFileName = new char[strlen(fileName)+1];
   strcpy(this->skinFileName, fileName);
+
   this->material = new Material("md2ModelTest");
   this->material->setDiffuseMap(fileName);
@@ -182,248 +345,2 @@
   this->material->setAmbient(1.0, 1.0, 1.0);
 }
-
-
-/**
-   \brief initializes an array of vert with the current frame scaled vertices
-
-   we won't use the pVertices array directly, since its much easier and we need
-   saving of data anyway
-*/
-void MD2Model::interpolate(sVec3D* verticesList)
-{
-  sVec3D* currVec;
-  sVec3D* nextVec;
-
-  currVec = &this->data->pVertices[this->data->numVertices * this->animationState.currentFrame];
-  nextVec = &this->data->pVertices[this->data->numVertices * this->animationState.nextFrame];
-
-  for(int i = 0; i < this->data->numFrames; ++i)
-    {
-      verticesList[i][0] = (currVec[i][0] + this->animationState.interpolationState * (nextVec[i][0] - currVec[i][0])) * this->data->scaleFactor;
-      verticesList[i][1] = (currVec[i][1] + this->animationState.interpolationState * (nextVec[i][1] - currVec[i][1])) * this->data->scaleFactor;
-      verticesList[i][2] = (currVec[i][2] + this->animationState.interpolationState * (nextVec[i][2] - currVec[i][2])) * this->data->scaleFactor;
-    }
-}
-
-
-void MD2Model::setAnim(int type)
-{
-  if( (type < 0) || (type > MAX_ANIMATIONS) )
-    type = 0;
-
-  this->animationState.startFrame = animationList[type].firstFrame;
-  this->animationState.endFrame = animationList[type].lastFrame;
-  this->animationState.nextFrame = animationList[type].firstFrame + 1;
-  this->animationState.fps = animationList[type].fps;
-  this->animationState.type = type;
-  
-  this->animationState.interpolationState = 0.0;
-  this->animationState.localTime = 0.0;
-  this->animationState.lastTime = 0.0;
-  this->animationState.currentFrame = animationList[type].firstFrame;
-}
-
-
-void MD2Model::tick(float time)
-{
-  this->animationState.localTime += time;
-}
-
-
-void MD2Model::draw()
-{
-  if( likely(this->animationState.localTime > 0.0))
-    this->animate();
-
-  glPushMatrix();
-
-  this->renderFrame();
-
-  glPopMatrix();
-} 
-
-
-void MD2Model::renderFrame()
-{
-  static sVec3D verticesList[MD2_MAX_VERTICES]; /* performance: created only once in a lifetime */
-  int* pCommands = this->data->pGLCommands;
-
-  /* some face culling stuff */
-  glPushAttrib(GL_POLYGON_BIT);
-  glFrontFace(GL_CW);
-  glEnable(GL_CULL_FACE);
-  glCullFace(GL_BACK);
-     
-  this->processLighting();
-  this->interpolate(verticesList);
-  this->data->material->select();
-
-  /* draw the triangles */
-  while( int i = *(pCommands++)) /* strange looking while loop for maximum performance */
-    {
-      if( i < 0)
-	{
-	  glBegin(GL_TRIANGLE_FAN);
-	  i = -i;
-	}
-      else
-	{
-	  glBegin(GL_TRIANGLE_STRIP);
-	}
-
-      for(; i > 0; i--, pCommands += 3) /* down counting for loop, next 3 gl commands */
-	{
-	  glNormal3fv(anorms[this->data->pLightNormals[pCommands[2]]]);
-	  glTexCoord2f( ((float *)pCommands)[0], 1.0-((float *)pCommands)[1] );
-	  glVertex3fv(verticesList[pCommands[2]]);
-	}
-      glEnd();
-    }
-  glDisable(GL_CULL_FACE);
-  glPopAttrib();
-}
-
-
-void MD2Model::animate()
-{
-  if( this->animationState.localTime - this->animationState.lastTime > (1.0f / this->animationState.fps))
-    {
-      this->animationState.currentFrame = this->animationState.nextFrame;
-      this->animationState.nextFrame++;
-      
-      if( this->animationState.nextFrame > this->animationState.endFrame)
-	this->animationState.nextFrame = this->animationState.startFrame;
-      this->animationState.lastTime = this->animationState.localTime;
-    }
-
-  if( this->animationState.currentFrame > (this->data->numFrames - 1) )
-    this->animationState.currentFrame = 0;
-  if( this->animationState.nextFrame > (this->data->numFrames - 1) )
-    this->animationState.nextFrame = 0;
-
-  this->animationState.interpolationState = this->animationState.fps * 
-    (this->animationState.localTime - this->animationState.lastTime);
-}
-
-
-/* hhmmm... id used a very different way to do lightning... */
-void MD2Model::processLighting()
-{
-  shadeDots = anormsDots[((int)(md2Angle*(SHADEDOT_QUANT / 360.0)))&(SHADEDOT_QUANT - 1)];
-}
-
-
-void MD2Model::debug()
-{
-  PRINT(0)("==========================| MD2Model::debug() |===\n");
-  PRINT(0)("=  Model FileName:\t%s\n", this->data->fileName);
-  PRINT(0)("=  Skin FileName:\t%s\n", this->data->skinFileName);
-  PRINT(0)("=  Size in Memory:\t%i Bytes\n", this->data->header->frameSize * this->data->header->numFrames + 64); // 64bytes is the header size
-  PRINT(0)("=  Number of Vertices:\t%i\n", this->data->header->numVertices);
-  PRINT(0)("=  Number of Frames: \t%i\n", this->data->header->numFrames);
-  PRINT(0)("=  Height, Width\t\t%i, %i\n", this->data->header->skinHeight, this->data->header->skinWidth);
-  PRINT(0)("===================================================\n\n");
-}
-
-
-
-
-
-MD2Data::MD2Data()
-{
-  this->pVertices = NULL;
-  this->pGLCommands = NULL;
-  this->pLightNormals = NULL; 
-
-  this->numFrames = 0;
-  this->numVertices = 0;
-  this->numGLCommands = 0;
-  
-  this->scaleFactor = 1.0f;
-}
-
-
-MD2Data::~MD2Data()
-{
-  delete [] this->pVertices;
-  delete [] this->pGLCommands;
-  delete [] this->pLightNormals;
-}
-
-
-
-bool MD2Data::loadModel(const char* fileName)
-{
-  FILE *pFile;                            //file stream
-  char* buffer;                           //buffer for frame data
-  sFrame* frame;                          //temp frame
-  sVec3D *pVertex;
-  int* pNormals;
-
-  pFile = fopen(fileName, "rb");
-  if( unlikely(!pFile)) 
-    {
-      PRINTF(1)("Couldn't open the MD2 File for loading. Exiting.\n");
-      return false;
-    }
-  this->header = new MD2Header;
-  fread(this->header, 1, sizeof(MD2Header), pFile);
-  /* check for the header version: make sure its a md2 file :) */
-  if( unlikely(this->header->version != MD2_VERSION) && unlikely(this->header->ident != MD2_IDENT))
-    {
-      PRINTF(1)("Couldn't load file %s: invalid file format: stop loading\n", fileName);
-      return false;
-    }
-
-  this->fileName = new char[strlen(fileName)+1];
-  strcpy(this->fileName, fileName);
-  /* got the data: map it to locals */
-  this->numFrames = this->header->numFrames;
-  this->numVertices = this->header->numVertices;
-  this->numTriangles = this->header->numTriangles;
-  this->numGLCommands = this->header->numGlCommands;
-  /* allocate memory for the data storage */
-  this->pVertices = new sVec3D[this->numVertices * this->numFrames];
-  this->pGLCommands = new int[this->numGLCommands];
-  this->pLightNormals = new int[this->numVertices * this->numFrames];
-  buffer = new char[this->numFrames * this->header->frameSize];
-
-  /* read frame data from the file to a temp buffer */
-  fseek(pFile, this->header->offsetFrames, SEEK_SET);
-  fread(buffer, this->header->frameSize, this->numFrames, pFile);
-  /* read opengl commands */
-  fseek(pFile, this->header->offsetGlCommands, SEEK_SET);
-  fread(this->pGLCommands, sizeof(int), this->numGLCommands, pFile);
-
-  for(int i = 0; i < this->numFrames; ++i)
-    {
-      frame = (sFrame*)(buffer + this->header->frameSize * i); 
-      pVertex = this->pVertices + this->numVertices  * i;
-      pNormals = this->pLightNormals + this->numVertices * i;
-
-      for(int j = 0; j < this->numVertices; ++j)
-	{
-	  /* SPEEDUP: *(pVerts + i + 0) = (*(frame->pVertices + i + 0)...  */
-	  pVertex[j][0] = (frame->pVertices[j].v[0] * frame->scale[0]) + frame->translate[0];
-	  pVertex[j][1] = (frame->pVertices[j].v[2] * frame->scale[2]) + frame->translate[2];
-	  pVertex[j][2] = -1.0 * (frame->pVertices[j].v[1] * frame->scale[1] + frame->translate[1]);
-	  
-	  pNormals[j] = frame->pVertices[j].lightNormalIndex;
-	}
-    }
-
-  delete [] buffer;
-  fclose(pFile);
-}
-
-
-bool MD2Data::loadSkin(const char* fileName)
-{
-  this->skinFileName = new char[strlen(fileName)+1];
-  strcpy(this->skinFileName, fileName);
-
-  this->material = new Material("md2ModelTest");
-  this->material->setDiffuseMap(fileName);
-  this->material->setIllum(3);
-  this->material->setAmbient(1.0, 1.0, 1.0);
-}
Index: /orxonox/trunk/src/lib/graphics/importer/md2Model.h
===================================================================
--- /orxonox/trunk/src/lib/graphics/importer/md2Model.h	(revision 4281)
+++ /orxonox/trunk/src/lib/graphics/importer/md2Model.h	(revision 4282)
@@ -164,22 +164,7 @@
  private:
   MD2Data* data;
-  
-  int numFrames;
-  int numVertices;
-  int numTriangles;
-  int numGLCommands;
-  char* fileName;
-  char* skinFileName;
-  MD2Header* header;
 
-  sVec3D* pVertices;
-  int* pGLCommands;
-  int* pLightNormals;
-  glCommandVertex* pGLCommands2;
-  
-
-  Material* material;
+  float scaleFactor;
   sAnimState animationState;
-  float scaleFactor;
 };
 
