Index: orxonox/branches/importer/importer/object.cc
===================================================================
--- orxonox/branches/importer/importer/object.cc	(revision 2765)
+++ orxonox/branches/importer/importer/object.cc	(revision 2767)
@@ -2,31 +2,54 @@
 Object::Object ()
 {
-  this->readFromObjFile ("sphere.obj");
 
-  listNumber = glGenLists(1);
-  glNewList (listNumber, GL_COMPILE);
+  initialize();
 
-  glEnableClientState (GL_VERTEX_ARRAY);
-  glVertexPointer(3, GL_FLOAT, 0, vertices->getArray());
+  importFile ("sphere.obj");
+ 
+
   
   glColor3f(1.0,0,0);
-  glBegin(GL_QUADS);
+  /*  glBegin(GL_QUADS);
   printf ("face-count %i\n", faces->getCount());
   for (int i=0; i<=faces->getCount();++i)
     {
       glArrayElement((int)faces->getArray()[i] -1);
-    }
-
-  glEnd();
-  glEndList();
+   }
+   glEnd();*/
+  finalize();
 }
 
-void Object::draw ()
+bool Object::importFile (char* fileName)
+{
+  objFile = fileName;
+  this->readFromObjFile (objFile);
+  return true;
+}
+
+bool Object::initialize (void)
+{
+  faceMode = -1;
+  if ( (listNumber = glGenLists(1)) == 0 )
+    {
+      printf ("list could not be created for this Object\n");
+      return false;
+    }
+  glNewList (listNumber, GL_COMPILE);
+  glEnableClientState (GL_VERTEX_ARRAY);
+
+  return true;
+}
+
+bool Object::finalize(void)
+{
+  glEndList();
+  return true;
+}
+
+void Object::draw (void)
 {
   glCallList (listNumber);
 
 }
-
-
 
 
@@ -46,9 +69,5 @@
       if (!strncmp(Buffer, "v ", 2))
 	{
-	  char subbuffer1[10];
-	  char subbuffer2[10];
-	  char subbuffer3[10];
-	  sscanf (Buffer, "v %s %s %s", subbuffer1, subbuffer2, subbuffer3);
-	  vertices->addEntry(atof(subbuffer1), atof(subbuffer2), atof(subbuffer3));
+	  readVertex(Buffer+2);
 	}
 
@@ -56,26 +75,5 @@
       else if (!strncmp(Buffer, "f ", 2))
 	{
-	  char subbuffer1[10];
-	  char subbuffer2[10];
-	  char subbuffer3[10];
-	  char subbuffer4[10] ="";
-	  sscanf (Buffer, "f %s %s %s %s", subbuffer1, subbuffer2, subbuffer3, subbuffer4);
-	  //	  vertices->addEntry(atof(subbuffer1), atof(subbuffer2), atof(subbuffer3));
-	  if (!strcmp(subbuffer4, ""))
-	    {
-	      printf ("triag: %s, %s, %s\n", subbuffer1, subbuffer2, subbuffer3);
-	      faces->addEntry(atof(subbuffer1));
-	      faces->addEntry(atof(subbuffer2));
-	      faces->addEntry(atof(subbuffer3));
-	    }
-	  else
-	    {
-	      printf ("quad: %s, %s, %s, %s\n", subbuffer1, subbuffer2, subbuffer3, subbuffer4);
-	      faces->addEntry(atof(subbuffer1));
-	      faces->addEntry(atof(subbuffer2));
-	      faces->addEntry(atof(subbuffer3));
-	      faces->addEntry(atof(subbuffer4));
-
-	    }
+	  readFace (Buffer+2);
 	}
 
@@ -92,104 +90,67 @@
   
   OBJ_FILE->close();
+  glEnd();
   
-  /*
+}
 
-  if ( (OBJ_FILE = fopen (fileName, "r")) == NULL)
+
+bool Object::readVertex (char* vertexString)
+{
+  readVertices = true;
+  char subbuffer1[10];
+  char subbuffer2[10];
+  char subbuffer3[10];
+  sscanf (vertexString, "%s %s %s", subbuffer1, subbuffer2, subbuffer3);
+  vertices->addEntry(atof(subbuffer1), atof(subbuffer2), atof(subbuffer3));
+  return true;
+}
+
+bool Object::readFace (char* faceString)
+{
+  if (readVertices == true)
     {
-      printf ("file: %s not found.\n", fileName);
-      return false;
+      vertices->finalizeArray();
+      glVertexPointer(3, GL_FLOAT, 0, vertices->getArray());
+    }
+
+  readVertices = false;
+  char subbuffer1[10];
+  char subbuffer2[10];
+  char subbuffer3[10];
+  char subbuffer4[10] ="";
+  sscanf (faceString, "%s %s %s %s", subbuffer1, subbuffer2, subbuffer3, subbuffer4);
+  //	  vertices->addEntry(atof(subbuffer1), atof(subbuffer2), atof(subbuffer3));
+  if (!strcmp(subbuffer4, ""))
+    {
+      if (faceMode != 3)
+	{
+	  if (faceMode != -1)
+	    glEnd();
+	  glBegin(GL_TRIANGLES);
+	}
+      
+      faceMode = 3;
+      //printf ("triag: %s, %s, %s\n", subbuffer1, subbuffer2, subbuffer3);
+      glArrayElement(atoi(subbuffer1));
+      glArrayElement(atoi(subbuffer2));
+      glArrayElement(atoi(subbuffer3));
+
+      return true;
     }
   else
     {
-      char Buffer[100];
-      char optionIs = '0';
-      char optionWas = '0';
-      int entryCount = 0; //counts how many inputs an option has.
-      int lastEntryCount = 0;
-      while (fscanf (OBJ_FILE, "%c10", Buffer) != EOF)
+      if (faceMode != 4)
 	{
-	  printf("%s", Buffer);
-
-	  // case we read it is a vertex
-	  if (!strcmp (Buffer, "v"))
-	    {
-	      optionIs = 'v';
-	      entryCount = 0;
-	    }
-	  // case we read a Face
-	  else if (!strcmp (Buffer, "f"))
-	    {  
-	      optionIs = 'f';
-	      entryCount = 0;
-	    }
-	  else if (!strcmp (Buffer, "vn"))
-	    {
-	      optionIs = 'n';
-	      entryCount = 0;
-	    }
-	  else if (!strcmp (Buffer, "vt"))
-	    {
-	      optionIs = 't';
-	      entryCount = 0;
-	    }
-	  else if (!strcmp (Buffer,"s"))
-	    {
-	      optionIs = '0';
-	      entryCount = 0;
-	    }
-	  else if (!strncmp (Buffer,"u", 1))
-	    {
-	      optionIs = '0';
-	      entryCount = 0;
-	    }
-	  else if (!strcmp (Buffer,"g"))
-	    {
-	      optionIs = '0';
-	      entryCount = 0;
-	    }
-
-
-	  // all other cases
-	  else
-	    {
-	      if (optionIs == 'v')
-		{
-		  vertices->addEntry(atof(Buffer));
-		  ++entryCount;
-
-		  //		  printf ("v: %s\n", Buffer);
-		}
-	      else if (optionIs == 'f')
-		{
-		  char* pointTo;
-		  pointTo = strstr (Buffer, "/");
-		  pointTo[0] = '\0';
-		  //		  printf ("f: %s\n", Buffer);
-		  faces->addEntry(atof(Buffer));
-		  ++entryCount;
-		}
-	      
-	    }
-
-	  if (entryCount == 0 && (optionWas == 'f'))
-	    {
-	      if (lastEntryCount == 3)
-		printf ("triang\n");
-	      else if (lastEntryCount == 4)
-		printf ("quads\n");
-		     
-	    }
-
-	  lastEntryCount = entryCount;
-	  optionWas = optionIs;
-
+	  if (faceMode != -1)
+	    glEnd();
+	  glBegin(GL_QUADS);
 	}
-      vertices->finalizeArray();
-      faces->finalizeArray();
-      fclose (OBJ_FILE);
+      faceMode = 4;
+      //printf ("quad: %s, %s, %s, %s\n", subbuffer1, subbuffer2, subbuffer3, subbuffer4);
+      glArrayElement(atoi(subbuffer1));
+      glArrayElement(atoi(subbuffer2));
+      glArrayElement(atoi(subbuffer3));
+      glArrayElement(atoi(subbuffer4));
       return true;
     }
-  */
 }
-
-//caseChange (char optionIs, int entryCount)
Index: orxonox/branches/importer/importer/object.h
===================================================================
--- orxonox/branches/importer/importer/object.h	(revision 2765)
+++ orxonox/branches/importer/importer/object.h	(revision 2767)
@@ -7,8 +7,12 @@
  public:
   Object ();
+  Object (char* fileName);
   ~Object ();
   
-  void draw();
-  
+  bool importFile (char* fileName);
+  bool initialize (void);
+  bool finalize(void);
+  void draw (void);
+
   bool readFromObjFile (char* fileName);
 
@@ -20,8 +24,14 @@
   Array* colors;
   Array* faces;
+  char* objFile;
+  int faceMode;
+  bool readVertices;
 
   ifstream* OBJ_FILE;
   ifstream* MTL_FILE;
   
+  bool readVertex (char* vertexString);
+  bool readFace (char* faceString);
+  bool readVT (char* vtString);
 
 };
