Changeset 2767 in orxonox.OLD for orxonox/branches/importer
- Timestamp:
- Nov 9, 2004, 5:10:23 PM (20 years ago)
- Location:
- orxonox/branches/importer/importer
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/importer/importer/object.cc
r2765 r2767 2 2 Object::Object () 3 3 { 4 this->readFromObjFile ("sphere.obj");5 4 6 listNumber = glGenLists(1); 7 glNewList (listNumber, GL_COMPILE); 5 initialize(); 8 6 9 glEnableClientState (GL_VERTEX_ARRAY); 10 glVertexPointer(3, GL_FLOAT, 0, vertices->getArray()); 7 importFile ("sphere.obj"); 8 9 11 10 12 11 glColor3f(1.0,0,0); 13 glBegin(GL_QUADS);12 /* glBegin(GL_QUADS); 14 13 printf ("face-count %i\n", faces->getCount()); 15 14 for (int i=0; i<=faces->getCount();++i) 16 15 { 17 16 glArrayElement((int)faces->getArray()[i] -1); 18 } 19 20 glEnd(); 21 glEndList(); 17 } 18 glEnd();*/ 19 finalize(); 22 20 } 23 21 24 void Object::draw () 22 bool Object::importFile (char* fileName) 23 { 24 objFile = fileName; 25 this->readFromObjFile (objFile); 26 return true; 27 } 28 29 bool Object::initialize (void) 30 { 31 faceMode = -1; 32 if ( (listNumber = glGenLists(1)) == 0 ) 33 { 34 printf ("list could not be created for this Object\n"); 35 return false; 36 } 37 glNewList (listNumber, GL_COMPILE); 38 glEnableClientState (GL_VERTEX_ARRAY); 39 40 return true; 41 } 42 43 bool Object::finalize(void) 44 { 45 glEndList(); 46 return true; 47 } 48 49 void Object::draw (void) 25 50 { 26 51 glCallList (listNumber); 27 52 28 53 } 29 30 31 54 32 55 … … 46 69 if (!strncmp(Buffer, "v ", 2)) 47 70 { 48 char subbuffer1[10]; 49 char subbuffer2[10]; 50 char subbuffer3[10]; 51 sscanf (Buffer, "v %s %s %s", subbuffer1, subbuffer2, subbuffer3); 52 vertices->addEntry(atof(subbuffer1), atof(subbuffer2), atof(subbuffer3)); 71 readVertex(Buffer+2); 53 72 } 54 73 … … 56 75 else if (!strncmp(Buffer, "f ", 2)) 57 76 { 58 char subbuffer1[10]; 59 char subbuffer2[10]; 60 char subbuffer3[10]; 61 char subbuffer4[10] =""; 62 sscanf (Buffer, "f %s %s %s %s", subbuffer1, subbuffer2, subbuffer3, subbuffer4); 63 // vertices->addEntry(atof(subbuffer1), atof(subbuffer2), atof(subbuffer3)); 64 if (!strcmp(subbuffer4, "")) 65 { 66 printf ("triag: %s, %s, %s\n", subbuffer1, subbuffer2, subbuffer3); 67 faces->addEntry(atof(subbuffer1)); 68 faces->addEntry(atof(subbuffer2)); 69 faces->addEntry(atof(subbuffer3)); 70 } 71 else 72 { 73 printf ("quad: %s, %s, %s, %s\n", subbuffer1, subbuffer2, subbuffer3, subbuffer4); 74 faces->addEntry(atof(subbuffer1)); 75 faces->addEntry(atof(subbuffer2)); 76 faces->addEntry(atof(subbuffer3)); 77 faces->addEntry(atof(subbuffer4)); 78 79 } 77 readFace (Buffer+2); 80 78 } 81 79 … … 92 90 93 91 OBJ_FILE->close(); 92 glEnd(); 94 93 95 /* 94 } 96 95 97 if ( (OBJ_FILE = fopen (fileName, "r")) == NULL) 96 97 bool Object::readVertex (char* vertexString) 98 { 99 readVertices = true; 100 char subbuffer1[10]; 101 char subbuffer2[10]; 102 char subbuffer3[10]; 103 sscanf (vertexString, "%s %s %s", subbuffer1, subbuffer2, subbuffer3); 104 vertices->addEntry(atof(subbuffer1), atof(subbuffer2), atof(subbuffer3)); 105 return true; 106 } 107 108 bool Object::readFace (char* faceString) 109 { 110 if (readVertices == true) 98 111 { 99 printf ("file: %s not found.\n", fileName); 100 return false; 112 vertices->finalizeArray(); 113 glVertexPointer(3, GL_FLOAT, 0, vertices->getArray()); 114 } 115 116 readVertices = false; 117 char subbuffer1[10]; 118 char subbuffer2[10]; 119 char subbuffer3[10]; 120 char subbuffer4[10] =""; 121 sscanf (faceString, "%s %s %s %s", subbuffer1, subbuffer2, subbuffer3, subbuffer4); 122 // vertices->addEntry(atof(subbuffer1), atof(subbuffer2), atof(subbuffer3)); 123 if (!strcmp(subbuffer4, "")) 124 { 125 if (faceMode != 3) 126 { 127 if (faceMode != -1) 128 glEnd(); 129 glBegin(GL_TRIANGLES); 130 } 131 132 faceMode = 3; 133 //printf ("triag: %s, %s, %s\n", subbuffer1, subbuffer2, subbuffer3); 134 glArrayElement(atoi(subbuffer1)); 135 glArrayElement(atoi(subbuffer2)); 136 glArrayElement(atoi(subbuffer3)); 137 138 return true; 101 139 } 102 140 else 103 141 { 104 char Buffer[100]; 105 char optionIs = '0'; 106 char optionWas = '0'; 107 int entryCount = 0; //counts how many inputs an option has. 108 int lastEntryCount = 0; 109 while (fscanf (OBJ_FILE, "%c10", Buffer) != EOF) 142 if (faceMode != 4) 110 143 { 111 printf("%s", Buffer); 112 113 // case we read it is a vertex 114 if (!strcmp (Buffer, "v")) 115 { 116 optionIs = 'v'; 117 entryCount = 0; 118 } 119 // case we read a Face 120 else if (!strcmp (Buffer, "f")) 121 { 122 optionIs = 'f'; 123 entryCount = 0; 124 } 125 else if (!strcmp (Buffer, "vn")) 126 { 127 optionIs = 'n'; 128 entryCount = 0; 129 } 130 else if (!strcmp (Buffer, "vt")) 131 { 132 optionIs = 't'; 133 entryCount = 0; 134 } 135 else if (!strcmp (Buffer,"s")) 136 { 137 optionIs = '0'; 138 entryCount = 0; 139 } 140 else if (!strncmp (Buffer,"u", 1)) 141 { 142 optionIs = '0'; 143 entryCount = 0; 144 } 145 else if (!strcmp (Buffer,"g")) 146 { 147 optionIs = '0'; 148 entryCount = 0; 149 } 150 151 152 // all other cases 153 else 154 { 155 if (optionIs == 'v') 156 { 157 vertices->addEntry(atof(Buffer)); 158 ++entryCount; 159 160 // printf ("v: %s\n", Buffer); 161 } 162 else if (optionIs == 'f') 163 { 164 char* pointTo; 165 pointTo = strstr (Buffer, "/"); 166 pointTo[0] = '\0'; 167 // printf ("f: %s\n", Buffer); 168 faces->addEntry(atof(Buffer)); 169 ++entryCount; 170 } 171 172 } 173 174 if (entryCount == 0 && (optionWas == 'f')) 175 { 176 if (lastEntryCount == 3) 177 printf ("triang\n"); 178 else if (lastEntryCount == 4) 179 printf ("quads\n"); 180 181 } 182 183 lastEntryCount = entryCount; 184 optionWas = optionIs; 185 144 if (faceMode != -1) 145 glEnd(); 146 glBegin(GL_QUADS); 186 147 } 187 vertices->finalizeArray(); 188 faces->finalizeArray(); 189 fclose (OBJ_FILE); 148 faceMode = 4; 149 //printf ("quad: %s, %s, %s, %s\n", subbuffer1, subbuffer2, subbuffer3, subbuffer4); 150 glArrayElement(atoi(subbuffer1)); 151 glArrayElement(atoi(subbuffer2)); 152 glArrayElement(atoi(subbuffer3)); 153 glArrayElement(atoi(subbuffer4)); 190 154 return true; 191 155 } 192 */193 156 } 194 195 //caseChange (char optionIs, int entryCount) -
orxonox/branches/importer/importer/object.h
r2765 r2767 7 7 public: 8 8 Object (); 9 Object (char* fileName); 9 10 ~Object (); 10 11 11 void draw(); 12 12 bool importFile (char* fileName); 13 bool initialize (void); 14 bool finalize(void); 15 void draw (void); 16 13 17 bool readFromObjFile (char* fileName); 14 18 … … 20 24 Array* colors; 21 25 Array* faces; 26 char* objFile; 27 int faceMode; 28 bool readVertices; 22 29 23 30 ifstream* OBJ_FILE; 24 31 ifstream* MTL_FILE; 25 32 33 bool readVertex (char* vertexString); 34 bool readFace (char* faceString); 35 bool readVT (char* vtString); 26 36 27 37 };
Note: See TracChangeset
for help on using the changeset viewer.