Changeset 3151 in orxonox.OLD for orxonox/branches/dave/src/object.cc
- Timestamp:
- Dec 11, 2004, 5:26:18 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/dave/src/object.cc
r2860 r3151 119 119 120 120 /** 121 121 \brief finalizes an Object. 122 122 This funcion is needed, to close the glList and all the other lists. 123 123 */ … … 226 226 if (verbose >= 2) 227 227 printf("Adding new Group\n"); 228 group->name = ""; 228 229 group->faceMode = -1; 229 group-> name = "";230 group->faceCount =0; 230 231 if ((group->listNumber = glGenLists(1)) == 0 ) 231 232 { … … 246 247 group->firstVertexTexture = currentGroup->firstVertexTexture + currentGroup->vTexture->getCount()/2; 247 248 } 248 249 if (verbose >=2) 250 printf ("Creating new Arrays, with starting points v:%i, vt:%i, vn:%i .\n", group->firstVertex, group->firstVertexTexture, group->firstNormal); 249 251 group->vertices = new Array(); 250 252 group->normals = new Array(); … … 256 258 /** 257 259 \brief finalizes a Group. 260 \param group the group to finalize. 258 261 */ 259 262 bool Object::finalizeGroup(Group* group) 260 263 { 264 if (verbose >=2) 265 printf ("Finalize group %s.\n", group->name); 261 266 glEnd(); 262 267 glEndList(); 268 } 269 /** 270 \brief deletes the Arrays of the Group to save space. 271 \param group the group to delete the arrays from. 272 */ 273 bool Object::cleanupGroup(Group* group) 274 { 275 if (verbose >=2) 276 printf ("cleaning up group %s.\n", group->name); 263 277 264 278 delete group->vertices; … … 266 280 delete group->vTexture; 267 281 } 282 268 283 /** 269 284 \brief Reads in the .obj File and sets all the Values. … … 282 297 } 283 298 objFileName = fileName; 284 char Buffer[ 500];299 char Buffer[10000]; 285 300 while(!OBJ_FILE->eof()) 286 301 { 287 OBJ_FILE->getline(Buffer, 500);302 OBJ_FILE->getline(Buffer, 10000); 288 303 if (verbose >=4) 289 304 printf ("Read input line: %s\n",Buffer); … … 330 345 } 331 346 OBJ_FILE->close(); 347 return true; 332 348 333 349 } … … 363 379 { 364 380 currentGroup->vertices->finalizeArray(); 365 glVertexPointer(3, GL_FLOAT, 0, currentGroup->vertices->getArray());381 // glVertexPointer(3, GL_FLOAT, 0, currentGroup->vertices->getArray()); 366 382 currentGroup->normals->finalizeArray(); 367 glNormalPointer(GL_FLOAT, 0, currentGroup->normals->getArray());383 // glNormalPointer(GL_FLOAT, 0, currentGroup->normals->getArray()); 368 384 currentGroup->vTexture->finalizeArray(); 369 385 } 370 386 371 387 readingVertices = false; 372 char subbuffer1[20]; 373 char subbuffer2[20]; 374 char subbuffer3[20]; 375 char subbuffer4[20] =""; 376 sscanf (faceString, "%s %s %s %s", subbuffer1, subbuffer2, subbuffer3, subbuffer4); 377 if (!strcmp(subbuffer4, "")) 388 currentGroup->faceCount++; 389 390 int elemCount = 0; 391 392 FaceElement* firstElem = new FaceElement; 393 FaceElement* tmpElem = firstElem; 394 395 396 while(strcmp (faceString, "\0")) 397 { 398 if (elemCount>0) 399 tmpElem = tmpElem->next = new FaceElement; 400 tmpElem->next = NULL; 401 402 403 sscanf (faceString, "%s", tmpElem->value); 404 faceString += strlen(tmpElem->value); 405 if (strcmp (faceString, "\0")) 406 faceString++; 407 elemCount++; 408 409 410 } 411 412 413 if (elemCount == 3) 378 414 { 379 415 if (currentGroup->faceMode != 3) … … 386 422 currentGroup->faceMode = 3; 387 423 if (verbose >=3) 388 printf ("found triag: %s, %s, %s\n", subbuffer1, subbuffer2, subbuffer3); 389 addGLElement(subbuffer1); 390 addGLElement(subbuffer2); 391 addGLElement(subbuffer3); 392 return true; 393 } 394 else 424 printf ("found triag.\n"); 425 } 426 427 else if (elemCount == 4) 395 428 { 396 429 if (currentGroup->faceMode != 4) … … 402 435 currentGroup->faceMode = 4; 403 436 if (verbose >=3 ) 404 printf ("found quad: %s, %s, %s, %s\n", subbuffer1, subbuffer2, subbuffer3, subbuffer4); 405 addGLElement(subbuffer1); 406 addGLElement(subbuffer2); 407 addGLElement(subbuffer3); 408 addGLElement(subbuffer4); 409 return true; 410 } 437 printf ("found quad.\n"); 438 } 439 440 else if (elemCount > 4) 441 { 442 if (currentGroup->faceMode != -1) 443 glEnd(); 444 glBegin(GL_POLYGON); 445 if (verbose >=3) 446 printf ("Polygon with %i faces found.", elemCount); 447 currentGroup->faceMode = elemCount; 448 } 449 450 tmpElem = firstElem; 451 while (tmpElem != NULL) 452 { 453 // printf ("%s\n", tmpElem->value); 454 addGLElement(tmpElem->value); 455 tmpElem = tmpElem->next; 456 } 457 411 458 } 412 459 … … 423 470 { 424 471 if (verbose >=3) 425 printf ("importing grafical Element .... includingto openGL\n");472 printf ("importing grafical Element to openGL\n"); 426 473 char* vertex = elementString; 427 474 428 475 char* texture; 429 texture = strstr (vertex, "/"); 430 texture[0] = '\0'; 431 texture ++; 432 glTexCoord2fv(currentGroup->vTexture->getArray()+(atoi(texture)-1 - currentGroup->firstVertexTexture)*2); 433 434 char* normal; 435 if ((normal = strstr (texture, "/")) !=NULL) 436 { 437 normal[0] = '\0'; 438 normal ++; 439 //glArrayElement(atoi(vertex)-1); 440 glNormal3fv(currentGroup->normals->getArray() +(atoi(normal)-1 - currentGroup->firstNormal)*3); 441 } 476 if ((texture = strstr (vertex, "/")) != NULL) 477 { 478 texture[0] = '\0'; 479 texture ++; 480 if (verbose>=3) 481 printf ("includeing texture #%i, and mapping it to group texture #%i, textureArray has %i entries.\n", atoi(texture), (atoi(texture)-1 - currentGroup->firstVertexTexture)*3, currentGroup->vTexture->getCount()); 482 glTexCoord2fv(currentGroup->vTexture->getArray()+(atoi(texture)-1 - currentGroup->firstVertexTexture)*2); 483 484 char* normal; 485 if ((normal = strstr (texture, "/")) !=NULL) 486 { 487 normal[0] = '\0'; 488 normal ++; 489 //glArrayElement(atoi(vertex)-1); 490 glNormal3fv(currentGroup->normals->getArray() +(atoi(normal)-1 - currentGroup->firstNormal)*3); 491 } 492 } 493 if (verbose>=3) 494 printf ("includeing vertex #%i, and mapping it to group vertex #%i, vertexArray has %i entries.\n", atoi(vertex), (atoi(vertex)-1 - currentGroup->firstVertex)*3, currentGroup->vertices->getCount()); 442 495 glVertex3fv(currentGroup->vertices->getArray() +(atoi(vertex)-1 - currentGroup->firstVertex)*3); 443 496 … … 488 541 bool Object::readGroup (char* groupString) 489 542 { 490 // printf ("test\n"); 491 if (!strcmp(groupString, "default")) 492 { 493 if (groupCount != 0) 494 { 495 Group* newGroup = new Group; 496 finalizeGroup(currentGroup); 497 currentGroup->nextGroup = newGroup; 498 initGroup(newGroup); 499 currentGroup = newGroup; // must be after init see initGroup for more info 500 } 501 ++groupCount; 502 } 503 else 504 { 505 506 currentGroup->name = new char [strlen(groupString)]; 543 // setting the group name if not default. 544 if (strcmp(currentGroup->name, "default")) 545 { 546 currentGroup->name = (char*) malloc ( strlen(groupString) * sizeof (char)); 507 547 strcpy(currentGroup->name, groupString); 508 548 } 549 if (groupCount != 0 && currentGroup->faceCount>0) 550 { 551 Group* newGroup = new Group; 552 finalizeGroup(currentGroup); 553 currentGroup->nextGroup = newGroup; 554 initGroup(newGroup); 555 cleanupGroup(currentGroup); // deletes the arrays of the group; must be after initGroup. 556 currentGroup = newGroup; // must be after init see initGroup for more info 557 } 558 559 ++groupCount; 560 509 561 } 510 562
Note: See TracChangeset
for help on using the changeset viewer.