Changeset 2850 in orxonox.OLD for orxonox/trunk/importer
- Timestamp:
- Nov 14, 2004, 6:16:42 AM (20 years ago)
- Location:
- orxonox/trunk/importer
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/importer/framework.cc
r2848 r2850 5 5 WindowHandler wHandler; // Create an instance of the whandler basecode class 6 6 Object* obj; 7 Object* obj2;8 Object* obj3;9 7 float rotator = 0.0; 10 8 GLfloat whiteLight[] = {1.0, 1.0, 0.0,1.0}; … … 54 52 else 55 53 obj = new Object(); 56 54 57 55 GLfloat lmodelAmbient[] = {.1, .1, .1, 1.0}; 58 56 glLightfv(GL_LIGHT0, GL_DIFFUSE, whiteLight); -
orxonox/trunk/importer/material.cc
r2847 r2850 82 82 setAmbient(0,0,0); 83 83 setSpecular(0,0,0); 84 setShininess(2 );84 setShininess(2.0); 85 85 setTransparency(0.0); 86 86 -
orxonox/trunk/importer/object.cc
r2848 r2850 65 65 { 66 66 if (verbose >= 2) 67 printf ("Don't know what to delete, or how to destroy a glList\n"); 68 67 printf ("Deleting display List.\n"); 68 Group* walker = firstGroup; 69 while (walker != NULL) 70 { 71 glDeleteLists (walker->listNumber, 1); 72 Group* lastWalker = walker; 73 walker = walker->nextGroup; 74 delete lastWalker; 75 } 69 76 } 70 77 … … 77 84 if (verbose >=3) 78 85 printf("new 3D-Object is being created\n"); 79 faceMode = -1; 80 if ( (listNumber = glGenLists(1)) == 0 )81 {82 printf ("list could not be created for this Object\n");83 return false;84 }85 86 87 // setting the start group; 88 firstGroup = new Group; 89 currentGroup = firstGroup; 90 groupCount = 0; 91 92 initGroup (currentGroup); 86 93 mtlFileName = ""; 87 94 scaleFactor = 1; 88 vertices = new Array();89 normals = new Array();90 vTexture = new Array();91 92 95 material = new Material(); 93 96 94 glNewList (listNumber, GL_COMPILE);95 97 glEnableClientState (GL_VERTEX_ARRAY); 96 glEnableClientState (GL_NORMAL_ARRAY);98 // glEnableClientState (GL_NORMAL_ARRAY); 97 99 // glEnableClientState (GL_TEXTURE_COORD_ARRAY); 100 98 101 99 102 return true; … … 119 122 bool Object::finalize(void) 120 123 { 124 // if (verbose >=3) 125 printf("finalizing the 3D-Object\n"); 126 finalizeGroup (currentGroup); 127 if (material != NULL) 128 delete material; 129 return true; 130 } 131 132 /** 133 \brief Draws the Object 134 It does this by just calling the List that must have been created earlier. 135 */ 136 void Object::draw (void) 137 { 121 138 if (verbose >=3) 122 printf("finalizing the 3D-Object\n"); 139 printf("drawing the 3D-Object\n"); 140 Group* walker = firstGroup; 141 while (walker != NULL) 142 { 143 glCallList (walker->listNumber); 144 walker = walker->nextGroup; 145 } 146 } 147 148 /** 149 \brief initializes a new Group object 150 */ 151 bool Object::initGroup(Group* group) 152 { 153 if (verbose >= 2) 154 printf("Adding new Group\n"); 155 group->faceMode = -1; 156 if ((group->listNumber = glGenLists(1)) == 0 ) 157 { 158 printf ("list could not be created for this Object\n"); 159 return false; 160 } 161 162 if (groupCount == 0) 163 { 164 group->firstVertex = 0; 165 group->firstNormal = 0; 166 group->firstNormal = 0; 167 } 168 else 169 { 170 group->firstVertex = currentGroup->firstVertex + currentGroup->vertices->getCount()/3; 171 group->firstNormal = currentGroup->firstNormal + currentGroup->normals->getCount()/3; 172 group->firstVertexTexture = currentGroup->firstVertexTexture + currentGroup->vTexture->getCount()/2; 173 } 174 175 group->vertices = new Array(); 176 group->normals = new Array(); 177 group->vTexture = new Array(); 178 179 glNewList (group->listNumber, GL_COMPILE); 180 } 181 182 /** 183 \brief finalizes a Group. 184 */ 185 bool Object::finalizeGroup(Group* group) 186 { 123 187 glEnd(); 124 188 glEndList(); 125 delete vertices; 126 delete normals; 127 delete vTexture; 128 if (material != NULL) 129 delete material; 130 return true; 131 } 132 133 /** 134 \brief Draws the Object 135 It does this by just calling the List that must have been created earlier. 136 */ 137 void Object::draw (void) 138 { 139 if (verbose >=3) 140 printf("drawing the 3D-Object\n"); 141 glCallList (listNumber); 142 } 143 189 190 delete group->vertices; 191 delete group->normals; 192 delete group->vTexture; 193 } 144 194 /** 145 195 \brief Reads in the .obj File and sets all the Values. … … 202 252 else if (!strncmp(Buffer, "g", 1)) 203 253 { 204 printf("ERROR GROUPS NOT IMPLEMENTED YET\n");254 readGroup (Buffer+2); 205 255 } 206 256 } … … 216 266 bool Object::readVertex (char* vertexString) 217 267 { 218 read Vertices = true;268 readingVertices = true; 219 269 char subbuffer1[20]; 220 270 char subbuffer2[20]; … … 223 273 if (verbose >= 3) 224 274 printf ("reading in a vertex: %s %s %s\n", subbuffer1, subbuffer2, subbuffer3); 225 vertices->addEntry(atof(subbuffer1)*scaleFactor, atof(subbuffer2)*scaleFactor, atof(subbuffer3)*scaleFactor);275 currentGroup->vertices->addEntry(atof(subbuffer1)*scaleFactor, atof(subbuffer2)*scaleFactor, atof(subbuffer3)*scaleFactor); 226 276 return true; 227 277 } … … 235 285 bool Object::readFace (char* faceString) 236 286 { 237 if (readVertices == true) 238 { 239 vertices->finalizeArray(); 240 glVertexPointer(3, GL_FLOAT, 0, vertices->getArray()); 241 normals->finalizeArray(); 242 glNormalPointer(GL_FLOAT, 0, normals->getArray()); 243 vTexture->finalizeArray(); 244 } 245 246 readVertices = false; 287 // finalize the Arrays; 288 if (readingVertices == true) 289 { 290 currentGroup->vertices->finalizeArray(); 291 glVertexPointer(3, GL_FLOAT, 0, currentGroup->vertices->getArray()); 292 currentGroup->normals->finalizeArray(); 293 glNormalPointer(GL_FLOAT, 0, currentGroup->normals->getArray()); 294 currentGroup->vTexture->finalizeArray(); 295 } 296 297 readingVertices = false; 247 298 char subbuffer1[20]; 248 299 char subbuffer2[20]; … … 252 303 if (!strcmp(subbuffer4, "")) 253 304 { 254 if ( faceMode != 3)255 { 256 if ( faceMode != -1)305 if (currentGroup->faceMode != 3) 306 { 307 if (currentGroup->faceMode != -1) 257 308 glEnd(); 258 309 glBegin(GL_TRIANGLES); 259 310 } 260 311 261 faceMode = 3;312 currentGroup->faceMode = 3; 262 313 if (verbose >=3) 263 314 printf ("found triag: %s, %s, %s\n", subbuffer1, subbuffer2, subbuffer3); … … 269 320 else 270 321 { 271 if ( faceMode != 4)272 { 273 if ( faceMode != -1)322 if (currentGroup->faceMode != 4) 323 { 324 if (currentGroup->faceMode != -1) 274 325 glEnd(); 275 326 glBegin(GL_QUADS); 276 327 } 277 faceMode = 4;328 currentGroup->faceMode = 4; 278 329 if (verbose >=3 ) 279 330 printf ("found quad: %s, %s, %s, %s\n", subbuffer1, subbuffer2, subbuffer3, subbuffer4); … … 305 356 texture[0] = '\0'; 306 357 texture ++; 307 glTexCoord2fv( vTexture->getArray()+(atoi(texture)-1)*2);358 glTexCoord2fv(currentGroup->vTexture->getArray()+(atoi(texture)-1 - currentGroup->firstVertexTexture)*2); 308 359 309 360 char* normal; … … 313 364 normal ++; 314 365 //glArrayElement(atoi(vertex)-1); 315 glNormal3fv( normals->getArray() +(atoi(normal)-1)*3);316 } 317 glVertex3fv( vertices->getArray() +(atoi(vertex)-1)*3);366 glNormal3fv(currentGroup->normals->getArray() +(atoi(normal)-1 - currentGroup->firstNormal)*3); 367 } 368 glVertex3fv(currentGroup->vertices->getArray() +(atoi(vertex)-1 - currentGroup->firstVertex)*3); 318 369 319 370 } … … 326 377 bool Object::readVertexNormal (char* normalString) 327 378 { 328 read Vertices = true;379 readingVertices = true; 329 380 char subbuffer1[20]; 330 381 char subbuffer2[20]; … … 333 384 if (verbose >=3 ) 334 385 printf("found vertex-Normal %s, %s, %s\n", subbuffer1,subbuffer2,subbuffer3); 335 normals->addEntry(atof(subbuffer1), atof(subbuffer2), atof(subbuffer3));386 currentGroup->normals->addEntry(atof(subbuffer1), atof(subbuffer2), atof(subbuffer3)); 336 387 return true; 337 388 } … … 344 395 bool Object::readVertexTexture (char* vTextureString) 345 396 { 346 read Vertices = true;397 readingVertices = true; 347 398 char subbuffer1[20]; 348 399 char subbuffer2[20]; … … 350 401 if (verbose >=3 ) 351 402 printf("found vertex-Texture %s, %s\n", subbuffer1,subbuffer2); 352 vTexture->addEntry(atof(subbuffer1)); 353 vTexture->addEntry(atof(subbuffer2)); 354 return true; 403 currentGroup->vTexture->addEntry(atof(subbuffer1)); 404 currentGroup->vTexture->addEntry(atof(subbuffer2)); 405 return true; 406 } 407 408 /** 409 \brief parses a group String 410 This function initializes a new Group. 411 With it you should be able to import .obj-files with more than one Objects inside. 412 \param groupString the new Group to create 413 */ 414 bool Object::readGroup (char* groupString) 415 { 416 // printf ("test\n"); 417 if (!strcmp(groupString, "default")) 418 { 419 if (groupCount != 0) 420 { 421 Group* newGroup = new Group; 422 finalizeGroup(currentGroup); 423 currentGroup->nextGroup = newGroup; 424 initGroup(newGroup); 425 currentGroup = newGroup; // must be after init see initGroup for more info 426 } 427 ++groupCount; 428 } 429 else 430 { 431 currentGroup->name = groupString; 432 } 355 433 } 356 434 … … 441 519 } 442 520 443 if ( faceMode != -1)521 if (currentGroup->faceMode != -1) 444 522 glEnd(); 445 faceMode = 0;523 currentGroup->faceMode = 0; 446 524 if (verbose >= 2) 447 525 printf ("using material %s for coming Faces.\n", matString); -
orxonox/trunk/importer/object.h
r2842 r2850 33 33 void draw (void); 34 34 35 bool readFromObjFile (char* fileName);36 35 37 36 38 37 private: 39 GLuint listNumber; 40 Array* vertices; 41 int verticesCount; 42 Array* colors; 43 Array* normals; 44 Array* vTexture; 38 //! Group to handle multiple Objects per obj-file 39 struct Group 40 { 41 char* name; 42 43 GLuint listNumber; 44 Array* vertices; 45 int verticesCount; 46 Array* colors; 47 Array* normals; 48 Array* vTexture; 49 int faceMode; 50 51 int firstVertex; 52 int firstNormal; 53 int firstVertexTexture; 54 55 Group* nextGroup; 56 }; 57 58 Group* firstGroup; //!< the first of all groups. 59 Group* currentGroup; //!< the currentGroup. this is the one we will work with. 60 int groupCount; 61 62 bool readingVertices; 63 45 64 char* objFileName; 46 65 char* mtlFileName; 47 int faceMode; 48 bool readVertices; 66 49 67 Material* material; 50 68 float scaleFactor; … … 52 70 ifstream* OBJ_FILE; 53 71 ifstream* MTL_FILE; 72 73 bool initGroup(Group* group); 74 bool finalizeGroup (Group* group); 75 76 77 ///// readin /// 78 bool readFromObjFile (char* fileName); 54 79 55 80 bool readVertex (char* vertexString); … … 58 83 bool readVertexNormal (char* normalString); 59 84 bool readVertexTexture (char* vTextureString); 85 bool readGroup (char* groupString); 60 86 bool readMtlLib (char* matFile); 61 87 bool readUseMtl (char* mtlString);
Note: See TracChangeset
for help on using the changeset viewer.