Changeset 3195 in orxonox.OLD for orxonox/trunk
- Timestamp:
- Dec 17, 2004, 12:03:30 AM (20 years ago)
- Location:
- orxonox/trunk/importer
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/importer/array.cc
r3188 r3195 21 21 Array::Array () 22 22 { 23 initializeArray ();23 this->initializeArray (); 24 24 } 25 25 … … 32 32 if (verbose >= 2) 33 33 printf("deleting array\n"); 34 Entry* walker = firstEntry;34 Entry* walker = this->firstEntry; 35 35 Entry* previous; 36 36 while (walker) … … 41 41 } 42 42 if (finalized) 43 delete [] array;43 delete []this->array; 44 44 } 45 45 … … 52 52 if (verbose >= 2) 53 53 printf ("crating new Array\n"); 54 firstEntry = new Entry;55 firstEntry->next =NULL;56 currentEntry=firstEntry;57 finalized = false;58 entryCount = 0; //0 means one entry54 this->firstEntry = new Entry; 55 this->firstEntry->next =NULL; 56 this->currentEntry=firstEntry; 57 this->finalized = false; 58 this->entryCount = 0; //0 means one entry 59 59 return; 60 60 } … … 69 69 printf ("Finalizing array. Length: %i\n", entryCount); 70 70 // if ((array = (GLfloat*)malloc( entryCount* sizeof(GLfloat))) == NULL) 71 if (( array = new GLfloat [entryCount]) == NULL)72 printf ("could not allocate %i data Blocks\n", entryCount);73 Entry* walker = firstEntry;74 for (int i=0; i< entryCount; i++)71 if ((this->array = new GLfloat [this->entryCount]) == NULL) 72 printf ("could not allocate %i data Blocks\n", this->entryCount); 73 Entry* walker = this->firstEntry; 74 for (int i=0; i<this->entryCount; i++) 75 75 { 76 array[i] = walker->value;76 this->array[i] = walker->value; 77 77 walker = walker->next; 78 78 } 79 finalized = true;79 this->finalized = true; 80 80 81 81 return; … … 88 88 void Array::addEntry (GLfloat entry) 89 89 { 90 if (! finalized)90 if (!this->finalized) 91 91 { 92 92 if (verbose >= 3) 93 93 printf ("adding new Entry to Array: %f\n", entry); 94 94 95 currentEntry->value = entry;96 currentEntry->next = new Entry;97 currentEntry = currentEntry->next;98 currentEntry->next = NULL;99 ++ entryCount;95 this->currentEntry->value = entry; 96 this->currentEntry->next = new Entry; 97 this->currentEntry = currentEntry->next; 98 this->currentEntry->next = NULL; 99 ++this->entryCount; 100 100 } 101 101 else … … 109 109 void Array::addEntry (GLfloat entry0, GLfloat entry1, GLfloat entry2) 110 110 { 111 addEntry (entry0);112 addEntry (entry1);113 addEntry (entry2);111 this->addEntry (entry0); 112 this->addEntry (entry1); 113 this->addEntry (entry2); 114 114 } 115 115 … … 120 120 GLfloat* Array::getArray () 121 121 { 122 return array;122 return this->array; 123 123 } 124 124 … … 128 128 int Array::getCount() 129 129 { 130 return entryCount;130 return this->entryCount; 131 131 } 132 132 … … 136 136 void Array::debug () 137 137 { 138 printf ("entryCount=%i, address=%p\n", entryCount,array);138 printf ("entryCount=%i, address=%p\n", this->entryCount, this->array); 139 139 } -
orxonox/trunk/importer/material.cc
r3186 r3195 36 36 PathList::PathList() 37 37 { 38 pathName = NULL;39 next = NULL;38 this->pathName = NULL; 39 this->next = NULL; 40 40 } 41 41 … … 48 48 PathList::PathList(char* pName) 49 49 { 50 pathName = new char [strlen(pName)+1];51 strcpy ( pathName, pName);52 next = NULL;50 this->pathName = new char [strlen(pName)+1]; 51 strcpy (this->pathName, pName); 52 this->next = NULL; 53 53 } 54 54 … … 60 60 PathList::~PathList() 61 61 { 62 if ( pathName)63 delete [] pathName;64 if ( next)65 delete next;62 if (this->pathName) 63 delete []this->pathName; 64 if (this->next) 65 delete this->next; 66 66 } 67 67 … … 114 114 Material::Material() 115 115 { 116 init();117 118 setName ("");116 this->init(); 117 118 this->setName (""); 119 119 } 120 120 … … 125 125 Material::Material (char* mtlName) 126 126 { 127 init();128 129 setName (mtlName);127 this->init(); 128 129 this->setName (mtlName); 130 130 } 131 131 … … 136 136 { 137 137 if (verbose >= 2) 138 printf ("delete Material %s.\n", name);139 if ( name)140 delete [] name;141 if ( diffuseTextureSet)142 glDeleteTextures (1, & diffuseTexture);143 if ( nextMat)144 delete nextMat;138 printf ("delete Material %s.\n", this->name); 139 if (this->name) 140 delete []this->name; 141 if (this->diffuseTextureSet) 142 glDeleteTextures (1, &this->diffuseTexture); 143 if (this->nextMat) 144 delete this->nextMat; 145 145 } 146 146 … … 171 171 if (verbose >= 3) 172 172 printf ("initializing new Material.\n"); 173 nextMat = NULL;174 name ="";175 setIllum(1);176 setDiffuse(0,0,0);177 setAmbient(0,0,0);178 setSpecular(.5,.5,.5);179 setShininess(2.0);180 setTransparency(0.0);181 182 if (! pathList)183 pathList = new PathList("");184 185 186 diffuseTextureSet = false;187 ambientTextureSet = false;188 specularTextureSet = false;173 this->nextMat = NULL; 174 this->name =""; 175 this->setIllum(1); 176 this->setDiffuse(0,0,0); 177 this->setAmbient(0,0,0); 178 this->setSpecular(.5,.5,.5); 179 this->setShininess(2.0); 180 this->setTransparency(0.0); 181 182 if (!this->pathList) 183 this->pathList = new PathList(""); 184 185 186 this->diffuseTextureSet = false; 187 this->ambientTextureSet = false; 188 this->specularTextureSet = false; 189 189 190 190 … … 227 227 // setting diffuse color 228 228 // glColor3f (diffuse[0], diffuse[1], diffuse[2]); 229 glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse);229 glMaterialfv(GL_FRONT, GL_DIFFUSE, this->diffuse); 230 230 231 231 // setting ambient color 232 glMaterialfv(GL_FRONT, GL_AMBIENT, ambient);232 glMaterialfv(GL_FRONT, GL_AMBIENT, this->ambient); 233 233 234 234 // setting up Sprecular 235 glMaterialfv(GL_FRONT, GL_SPECULAR, specular);235 glMaterialfv(GL_FRONT, GL_SPECULAR, this->specular); 236 236 237 237 // setting up Shininess 238 glMaterialf(GL_FRONT, GL_SHININESS, shininess);238 glMaterialf(GL_FRONT, GL_SHININESS, this->shininess); 239 239 240 240 // setting illumination Model 241 if ( illumModel == 1)241 if (this->illumModel == 1) //! \todo make this work, if no vertex-normals are read. 242 242 glShadeModel(GL_FLAT); 243 else if ( illumModel >= 2)243 else if (this->illumModel >= 2) 244 244 glShadeModel(GL_SMOOTH); 245 245 246 if ( diffuseTextureSet)247 glBindTexture(GL_TEXTURE_2D, diffuseTexture);246 if (this->diffuseTextureSet) 247 glBindTexture(GL_TEXTURE_2D, this->diffuseTexture); 248 248 else 249 249 glBindTexture(GL_TEXTURE_2D, 0); … … 258 258 void Material::setName (char* mtlName) 259 259 { 260 name = new char [strlen(mtlName)+1];261 strcpy( name, mtlName);260 this->name = new char [strlen(mtlName)+1]; 261 strcpy(this->name, mtlName); 262 262 if (verbose >= 3) 263 printf("setting Material Name to %s.\n", name);263 printf("setting Material Name to %s.\n", this->name); 264 264 265 265 // printf ("adding new Material: %s, %p\n", this->getName(), this); … … 271 271 char* Material::getName (void) 272 272 { 273 return name;273 return this->name; 274 274 } 275 275 … … 281 281 { 282 282 if (verbose >= 3) 283 printf("setting illumModel of Material %s to %i\n", name, illum);284 illumModel = illum;283 printf("setting illumModel of Material %s to %i\n", this->name, illum); 284 this->illumModel = illum; 285 285 // printf ("setting illumModel to: %i\n", illumModel); 286 286 } … … 290 290 */void Material::setIllum (char* illum) 291 291 { 292 setIllum (atoi(illum));292 this->setIllum (atoi(illum)); 293 293 } 294 294 … … 302 302 { 303 303 if (verbose >= 3) 304 printf ("setting Diffuse Color of Material %s to r=%f g=%f b=%f.\n", name, r, g, b);305 diffuse[0] = r;306 diffuse[1] = g;307 diffuse[2] = b;308 diffuse[3] = 1.0;304 printf ("setting Diffuse Color of Material %s to r=%f g=%f b=%f.\n", this->name, r, g, b); 305 this->diffuse[0] = r; 306 this->diffuse[1] = g; 307 this->diffuse[2] = b; 308 this->diffuse[3] = 1.0; 309 309 310 310 } … … 317 317 float r,g,b; 318 318 sscanf (rgb, "%f %f %f", &r, &g, &b); 319 setDiffuse (r, g, b);319 this->setDiffuse (r, g, b); 320 320 } 321 321 … … 329 329 { 330 330 if (verbose >=3) 331 printf ("setting Ambient Color of Material %s to r=%f g=%f b=%f.\n", name, r, g, b);332 ambient[0] = r;333 ambient[1] = g;334 ambient[2] = b;335 ambient[3] = 1.0;331 printf ("setting Ambient Color of Material %s to r=%f g=%f b=%f.\n", this->name, r, g, b); 332 this->ambient[0] = r; 333 this->ambient[1] = g; 334 this->ambient[2] = b; 335 this->ambient[3] = 1.0; 336 336 } 337 337 /** … … 343 343 float r,g,b; 344 344 sscanf (rgb, "%f %f %f", &r, &g, &b); 345 setAmbient (r, g, b);345 this->setAmbient (r, g, b); 346 346 } 347 347 … … 355 355 { 356 356 if (verbose >= 3) 357 printf ("setting Specular Color of Material %s to r=%f g=%f b=%f.\n", name, r, g, b);358 specular[0] = r;359 specular[1] = g;360 specular[2] = b;361 specular[3] = 1.0;357 printf ("setting Specular Color of Material %s to r=%f g=%f b=%f.\n", this->name, r, g, b); 358 this->specular[0] = r; 359 this->specular[1] = g; 360 this->specular[2] = b; 361 this->specular[3] = 1.0; 362 362 } 363 363 /** … … 369 369 float r,g,b; 370 370 sscanf (rgb, "%f %f %f", &r, &g, &b); 371 setSpecular (r, g, b);371 this->setSpecular (r, g, b); 372 372 } 373 373 … … 378 378 void Material::setShininess (float shini) 379 379 { 380 shininess = shini;380 this->shininess = shini; 381 381 } 382 382 /** … … 386 386 void Material::setShininess (char* shini) 387 387 { 388 setShininess (atof(shini));388 this->setShininess (atof(shini)); 389 389 } 390 390 … … 396 396 { 397 397 if (verbose >= 3) 398 printf ("setting Transparency of Material %s to %f.\n", name, trans);399 t ransparency = trans;398 printf ("setting Transparency of Material %s to %f.\n", this->name, trans); 399 this->transparency = trans; 400 400 } 401 401 /** … … 405 405 void Material::setTransparency (char* trans) 406 406 { 407 setTransparency (atof(trans));407 this->setTransparency (atof(trans)); 408 408 } 409 409 … … 414 414 void Material::addTexturePath(char* pathName) 415 415 { 416 pathList->addPath (pathName);416 this->pathList->addPath (pathName); 417 417 } 418 418 … … 464 464 465 465 // diffuseTextureSet = loadBMP(dMap, &diffuseTexture); 466 diffuseTextureSet = loadImage(dMap, &diffuseTexture);466 this->diffuseTextureSet = this->loadImage(dMap, &this->diffuseTexture); 467 467 468 468 } … … 471 471 \brief Sets the Materials Ambient Map 472 472 \param aMap the Name of the Image to Use 473 \todo implement this 473 474 */ 474 475 void Material::setAmbientMap(char* aMap) … … 481 482 \brief Sets the Materials Specular Map 482 483 \param sMap the Name of the Image to Use 484 \todo implement this 483 485 */ 484 486 void Material::setSpecularMap(char* sMap) … … 491 493 \brief Sets the Materials Bumpiness 492 494 \param bump the Name of the Image to Use 495 \todo implemet this 493 496 */ 494 497 void Material::setBump(char* bump) … … 544 547 pImage->data[i+2] = temp; 545 548 } 546 loadTexToGL (pImage, texture);549 this->loadTexToGL (pImage, texture); 547 550 } 548 551 else … … 570 573 if (verbose >=2) 571 574 printf ("Requested bmp-image. Trying to Import.\n"); 572 return loadBMP(imgNameWithPath, texture);575 return this->loadBMP(imgNameWithPath, texture); 573 576 } 574 577 … … 577 580 if (verbose >=2) 578 581 printf ("Requested jpeg-image. Trying to Import\n"); 579 return loadJPG(imgNameWithPath, texture);582 return this->loadJPG(imgNameWithPath, texture); 580 583 } 581 584 else if (!strncmp(imgNameWithPath+strlen(imgNameWithPath)-4, ".tga", 4)) … … 583 586 if (verbose >=2) 584 587 printf ("Requested tga-image. Trying to Import\n"); 585 return loadTGA(imgNameWithPath, texture);588 return this->loadTGA(imgNameWithPath, texture); 586 589 } 587 590 else if (!strncmp(imgNameWithPath+strlen(imgNameWithPath)-4, ".png", 4)) … … 589 592 if (verbose >=2) 590 593 printf ("Requested png-image. Trying to Import\n"); 591 return loadPNG(imgNameWithPath, texture);594 return this->loadPNG(imgNameWithPath, texture); 592 595 } 593 596 else … … 704 707 pImage->data[i+2] = temp; 705 708 } 706 loadTexToGL (pImage, texture); 707 708 return true; 709 this->loadTexToGL (pImage, texture); 710 709 711 710 712 if (pImage) … … 717 719 free(pImage); 718 720 } 721 return true; 719 722 720 723 } … … 802 805 exit(0); 803 806 804 loadTexToGL (pImage, texture);807 this->loadTexToGL (pImage, texture); 805 808 if (pImage) 806 809 { … … 947 950 } 948 951 949 loadTexToGL (pImage, texture);952 this->loadTexToGL (pImage, texture); 950 953 951 954 return true; … … 1130 1133 while(currentpixel < pixelcount); // Loop while there are still pixels left 1131 1134 1132 loadTexToGL (pImage, texture);1135 this->loadTexToGL (pImage, texture); 1133 1136 1134 1137 return true; … … 1265 1268 } 1266 1269 */ 1267 loadTexToGL (pImage, texture);1270 this->loadTexToGL (pImage, texture); 1268 1271 1269 1272 free(pImage->data); -
orxonox/trunk/importer/object.cc
r3190 r3195 25 25 { 26 26 27 initialize();28 29 BoxObject();30 31 importToGL ();32 33 cleanup();27 this->initialize(); 28 29 this->BoxObject(); 30 31 this->importToGL (); 32 33 this->cleanup(); 34 34 } 35 35 … … 40 40 Object::Object(char* fileName) 41 41 { 42 initialize();43 44 importFile (fileName);45 46 importToGL ();47 48 cleanup();42 this->initialize(); 43 44 this->importFile (fileName); 45 46 this->importToGL (); 47 48 this->cleanup(); 49 49 } 50 50 … … 56 56 Object::Object(char* fileName, float scaling) 57 57 { 58 initialize();59 scaleFactor = scaling;60 61 importFile (fileName);62 63 importToGL ();64 65 cleanup();58 this->initialize(); 59 this->scaleFactor = scaling; 60 61 this->importFile (fileName); 62 63 this->importToGL (); 64 65 this->cleanup(); 66 66 } 67 67 … … 75 75 if (verbose >= 2) 76 76 printf ("Deleting display Lists.\n"); 77 Group* walker = firstGroup;77 Group* walker = this->firstGroup; 78 78 while (walker != NULL) 79 79 { … … 84 84 } 85 85 86 if ( objPath)87 delete [] objPath;88 if ( objFileName)89 delete [] objFileName;90 if ( mtlFileName)91 delete [] mtlFileName;86 if (this->objPath) 87 delete []this->objPath; 88 if (this->objFileName) 89 delete []this->objFileName; 90 if (this->mtlFileName) 91 delete []this->mtlFileName; 92 92 93 93 if (verbose >=2) 94 94 printf("Deleting Materials.\n"); 95 if ( material)96 delete material;95 if (this->material) 96 delete this->material; 97 97 } 98 98 … … 106 106 if (verbose >=2) 107 107 printf("drawing the 3D-Objects\n"); 108 Group* walker = firstGroup;108 Group* walker = this->firstGroup; 109 109 while (walker != NULL) 110 110 { … … 124 124 void Object::draw (int groupNumber) const 125 125 { 126 if (groupNumber >= groupCount)126 if (groupNumber >= this->groupCount) 127 127 { 128 128 if (verbose>=1) 129 printf ("You requested object number %i, but this File only contains of %i Objects.\n", groupNumber-1, groupCount);129 printf ("You requested object number %i, but this File only contains of %i Objects.\n", groupNumber-1, this->groupCount); 130 130 return; 131 131 } 132 132 if (verbose >=2) 133 133 printf("drawing the requested 3D-Objects if found.\n"); 134 Group* walker = firstGroup;134 Group* walker = this->firstGroup; 135 135 int counter = 0; 136 136 while (walker != NULL) … … 147 147 } 148 148 if (verbose >= 1) 149 printf("Object number %i in %s not Found.\n", groupNumber, objFileName);149 printf("Object number %i in %s not Found.\n", groupNumber, this->objFileName); 150 150 return; 151 151 … … 162 162 if (verbose >=2) 163 163 printf("drawing the requested 3D-Objects if found.\n"); 164 Group* walker = firstGroup;164 Group* walker = this->firstGroup; 165 165 while (walker != NULL) 166 166 { … … 175 175 } 176 176 if (verbose >= 2) 177 printf("Object Named %s in %s not Found.\n", groupName, objFileName);177 printf("Object Named %s in %s not Found.\n", groupName, this->objFileName); 178 178 return; 179 179 } … … 184 184 int Object::getGroupCount (void) const 185 185 { 186 return groupCount;186 return this->groupCount; 187 187 } 188 188 … … 199 199 200 200 // setting the start group; 201 firstGroup = new Group;202 currentGroup =firstGroup;203 groupCount = 0;201 this->firstGroup = new Group; 202 this->currentGroup = this->firstGroup; 203 this->groupCount = 0; 204 204 205 initGroup (firstGroup);206 objPath = NULL;207 objFileName = NULL;208 mtlFileName = NULL;209 scaleFactor = 1;210 material = new Material();211 212 vertices = new Array();213 vTexture = new Array();214 normals = new Array();205 this->initGroup (this->currentGroup); 206 this->objPath = NULL; 207 this->objFileName = NULL; 208 this->mtlFileName = NULL; 209 this->scaleFactor = 1; 210 this->material = new Material(); 211 212 this->vertices = new Array(); 213 this->vTexture = new Array(); 214 this->normals = new Array(); 215 215 216 216 return true; … … 233 233 234 234 group->firstFace = new Face; 235 initFace (group->firstFace);235 this->initFace (group->firstFace); 236 236 group->currentFace = group->firstFace; 237 237 } … … 263 263 printf("cleaning up the 3D-Object to save Memory.\n"); 264 264 265 if ( vertices != NULL)266 delete vertices;267 if ( vTexture != NULL)268 delete vTexture;269 if ( normals != NULL)270 delete normals;271 272 cleanupGroup(firstGroup);265 if (this->vertices) 266 delete this->vertices; 267 if (this->vTexture) 268 delete this->vTexture; 269 if (this->normals) 270 delete this->normals; 271 272 this->cleanupGroup(this->firstGroup); 273 273 return true; 274 274 } … … 306 306 if (face->firstElem != NULL) 307 307 { 308 cleanupFaceElement(face->firstElem);308 this->cleanupFaceElement(face->firstElem); 309 309 delete face->firstElem; 310 310 } … … 312 312 if (face->next != NULL) 313 313 { 314 cleanupFace (face->next);314 this->cleanupFace (face->next); 315 315 delete face->next; 316 316 } … … 327 327 if (faceElem->next != NULL) 328 328 { 329 cleanupFaceElement (faceElem->next);329 this->cleanupFaceElement (faceElem->next); 330 330 delete faceElem->next; 331 331 } … … 357 357 name = tmpName+1; 358 358 } 359 objPath = new char[name-fileName];360 strncpy( objPath, fileName, name-fileName);361 objPath[name-fileName] = '\0';359 this->objPath = new char[name-fileName]; 360 strncpy(this->objPath, fileName, name-fileName); 361 this->objPath[name-fileName] = '\0'; 362 362 if (verbose >=2) 363 363 if (strlen(objPath)> 0) … … 368 368 printf("Resolved file %s.\n", name); 369 369 370 if ( material)371 material->addTexturePath(objPath);372 objFileName = new char[strlen(name)+1];373 strcpy ( objFileName, name);370 if (this->material) 371 this->material->addTexturePath(this->objPath); 372 this->objFileName = new char[strlen(name)+1]; 373 strcpy (this->objFileName, name); 374 374 this->readFromObjFile (); 375 375 return true; … … 383 383 { 384 384 char* fileName = new char [strlen(objPath)+strlen(objFileName)+1]; 385 if ( objFileName != NULL && !strcmp(objFileName, ""))385 if (this->objFileName != NULL && !strcmp(this->objFileName, "")) 386 386 return false; 387 strcpy(fileName, objPath);388 strcat(fileName, objFileName);387 strcpy(fileName, this->objPath); 388 strcat(fileName, this->objFileName); 389 389 390 390 ifstream* OBJ_FILE = new ifstream(fileName); … … 394 394 printf ("unable to open .OBJ file: %s\n Loading Box Object instead.\n", fileName); 395 395 BoxObject(); 396 OBJ_FILE->close(); 396 397 delete []fileName; 397 OBJ_FILE->close();398 delete OBJ_FILE; 398 399 return false; 399 400 } … … 405 406 OBJ_FILE->getline(Buffer, 10000); 406 407 if (verbose >=4) 407 printf ("Read input line: %s\n", Buffer);408 printf ("Read input line: %s\n", Buffer); 408 409 409 410 … … 411 412 if (!strncmp(Buffer, "v ", 2)) 412 413 { 413 readVertex(Buffer+2);414 this->readVertex(Buffer+2); 414 415 } 415 416 … … 417 418 else if (!strncmp(Buffer, "f ", 2)) 418 419 { 419 readFace (Buffer+2);420 this->readFace (Buffer+2); 420 421 } 421 422 422 423 else if (!strncmp(Buffer, "mtllib ", 7)) 423 424 { 424 readMtlLib (Buffer+7);425 this->readMtlLib (Buffer+7); 425 426 } 426 427 427 428 else if (!strncmp(Buffer, "usemtl ", 7)) 428 429 { 429 readUseMtl (Buffer+7);430 this->readUseMtl (Buffer+7); 430 431 } 431 432 432 433 // case VertexNormal 433 434 else if (!strncmp(Buffer, "vn ", 3)) 434 435 readVertexNormal(Buffer+3);436 437 435 { 436 this->readVertexNormal(Buffer+3); 437 } 438 438 439 // case VertexTextureCoordinate 439 440 else if (!strncmp(Buffer, "vt ", 3)) 440 441 readVertexTexture(Buffer+3);442 441 { 442 this->readVertexTexture(Buffer+3); 443 } 443 444 // case group 444 445 else if (!strncmp(Buffer, "g ", 2)) 445 446 { 446 readGroup (Buffer+2);447 } 448 else if (!strncmp(Buffer, "s ", 2)) 447 this->readGroup (Buffer+2); 448 } 449 else if (!strncmp(Buffer, "s ", 2)) //! \todo smoothing groups have to be implemented 449 450 { 450 451 if (verbose >= 2) … … 453 454 } 454 455 OBJ_FILE->close(); 456 delete OBJ_FILE; 455 457 delete []fileName; 456 458 return true; … … 469 471 if (verbose >=3) 470 472 printf ("Read Group: %s.\n", groupString); 471 if ( groupCount != 0 &¤tGroup->faceCount>0)473 if (this->groupCount != 0 && this->currentGroup->faceCount>0) 472 474 { 473 475 // finalizeGroup(currentGroup); 474 currentGroup =currentGroup->next = new Group;475 initGroup(currentGroup);476 this->currentGroup = this->currentGroup->next = new Group; 477 this->initGroup(this->currentGroup); 476 478 } 477 479 // setting the group name if not default. 478 480 if (strcmp(groupString, "default")) 479 481 { 480 currentGroup->name = new char [strlen(groupString)+1];481 strcpy( currentGroup->name, groupString);482 } 483 ++ groupCount;482 this->currentGroup->name = new char [strlen(groupString)+1]; 483 strcpy(this->currentGroup->name, groupString); 484 } 485 ++this->groupCount; 484 486 485 487 } … … 499 501 if (verbose >= 3) 500 502 printf ("reading in a vertex: %f %f %f\n", &subbuffer1, &subbuffer2, &subbuffer3); 501 vertices->addEntry(subbuffer1*scaleFactor, subbuffer2*scaleFactor, subbuffer3*scaleFactor);503 this->vertices->addEntry(subbuffer1*scaleFactor, subbuffer2*scaleFactor, subbuffer3*scaleFactor); 502 504 return true; 503 505 } … … 512 514 bool Object::readFace (char* faceString) 513 515 { 514 if ( currentGroup->faceCount >0)515 currentGroup->currentFace =currentGroup->currentFace->next = new Face;516 initFace (currentGroup->currentFace);517 518 FaceElement* tmpElem = currentGroup->currentFace->firstElem = new FaceElement;516 if (this->currentGroup->faceCount >0) 517 this->currentGroup->currentFace = this->currentGroup->currentFace->next = new Face; 518 this->initFace (this->currentGroup->currentFace); 519 520 FaceElement* tmpElem = this->currentGroup->currentFace->firstElem = new FaceElement; 519 521 tmpElem->next = NULL; 520 522 while(strcmp (faceString, "\0")) 521 523 { 522 if ( currentGroup->currentFace->vertexCount>0)524 if (this->currentGroup->currentFace->vertexCount>0) 523 525 tmpElem = tmpElem->next = new FaceElement; 524 526 tmpElem->next = NULL; … … 561 563 if (strcmp (faceString, "\0")) 562 564 faceString++; 563 currentGroup->currentFace->vertexCount++;564 } 565 566 currentGroup->faceCount +=currentGroup->currentFace->vertexCount -2;565 this->currentGroup->currentFace->vertexCount++; 566 } 567 568 this->currentGroup->faceCount += this->currentGroup->currentFace->vertexCount -2; 567 569 } 568 570 … … 581 583 if (verbose >=3 ) 582 584 printf("found vertex-Normal %f, %f, %f\n", &subbuffer1,&subbuffer2,&subbuffer3); 583 normals->addEntry(subbuffer1, subbuffer2, subbuffer3);585 this->normals->addEntry(subbuffer1, subbuffer2, subbuffer3); 584 586 return true; 585 587 } … … 599 601 if (verbose >=3 ) 600 602 printf("found vertex-Texture %f, %f\n", &subbuffer1, &subbuffer2); 601 vTexture->addEntry(subbuffer1);602 vTexture->addEntry(subbuffer2);603 this->vTexture->addEntry(subbuffer1); 604 this->vTexture->addEntry(subbuffer2); 603 605 return true; 604 606 } … … 615 617 bool Object::readMtlLib (char* mtlFile) 616 618 { 617 mtlFileName = new char [strlen(mtlFile)+1];618 strcpy( mtlFileName, mtlFile);619 char* fileName = new char [strlen(objPath) + strlen( mtlFileName)+1];620 strcpy(fileName, objPath);621 strcat(fileName, mtlFileName);619 this->mtlFileName = new char [strlen(mtlFile)+1]; 620 strcpy(this->mtlFileName, mtlFile); 621 char* fileName = new char [strlen(objPath) + strlen(this->mtlFileName)+1]; 622 strcpy(fileName, this->objPath); 623 strcat(fileName, this->mtlFileName); 622 624 623 625 … … 630 632 if (verbose >= 1) 631 633 printf ("unable to open file: %s\n", fileName); 634 MTL_FILE->close(); 632 635 delete []fileName; 633 MTL_FILE->close();636 delete MTL_FILE; 634 637 return false; 635 638 } … … 704 707 705 708 } 709 MTL_FILE->close(); 706 710 delete []fileName; 711 delete MTL_FILE; 707 712 return true; 708 713 } … … 714 719 bool Object::readUseMtl (char* matString) 715 720 { 716 if (! mtlFileName)721 if (!this->mtlFileName) 717 722 { 718 723 if (verbose >= 1) … … 721 726 } 722 727 723 if ( currentGroup->faceCount >0)724 currentGroup->currentFace =currentGroup->currentFace->next = new Face;725 initFace (currentGroup->currentFace);728 if (this->currentGroup->faceCount >0) 729 this->currentGroup->currentFace = this->currentGroup->currentFace->next = new Face; 730 this->initFace (this->currentGroup->currentFace); 726 731 727 currentGroup->currentFace->materialString = new char[strlen(matString)+1];728 strcpy ( currentGroup->currentFace->materialString, matString);732 this->currentGroup->currentFace->materialString = new char[strlen(matString)+1]; 733 strcpy (this->currentGroup->currentFace->materialString, matString); 729 734 730 if ( currentGroup->faceCount == 0)731 currentGroup->faceCount ++;735 if (this->currentGroup->faceCount == 0) 736 this->currentGroup->faceCount ++; 732 737 733 738 } … … 740 745 741 746 // finalize the Arrays 742 vertices->finalizeArray();743 vTexture->finalizeArray();747 this->vertices->finalizeArray(); 748 this->vTexture->finalizeArray(); 744 749 if (normals->getCount() == 0) // vertices-Array must be uilt for this 745 buildVertexNormals();746 normals->finalizeArray();747 748 currentGroup =firstGroup;749 750 while ( currentGroup != NULL)750 this->buildVertexNormals(); 751 this->normals->finalizeArray(); 752 753 this->currentGroup = this->firstGroup; 754 755 while (this->currentGroup != NULL) 751 756 { 752 757 753 758 // creating a glList for the Group 754 if (( currentGroup->listNumber = glGenLists(1)) == 0)759 if ((this->currentGroup->listNumber = glGenLists(1)) == 0) 755 760 { 756 761 printf ("list could not be created for this Object\n"); 757 762 return false; 758 763 } 759 glNewList ( currentGroup->listNumber, GL_COMPILE);764 glNewList (this->currentGroup->listNumber, GL_COMPILE); 760 765 761 766 // Putting Faces to GL 762 Face* tmpFace = currentGroup->firstFace;767 Face* tmpFace = this->currentGroup->firstFace; 763 768 while (tmpFace != NULL) 764 769 { 765 770 if (tmpFace->vertexCount == 0 && tmpFace->materialString != NULL) 766 771 { 767 if ( currentGroup->faceMode != -1)772 if (this->currentGroup->faceMode != -1) 768 773 glEnd(); 769 currentGroup->faceMode = 0;774 this->currentGroup->faceMode = 0; 770 775 if (verbose >= 2) 771 776 printf ("using material %s for coming Faces.\n", tmpFace->materialString); … … 778 783 else if (tmpFace->vertexCount == 3) 779 784 { 780 if ( currentGroup->faceMode != 3)785 if (this->currentGroup->faceMode != 3) 781 786 { 782 if ( currentGroup->faceMode != -1)787 if (this->currentGroup->faceMode != -1) 783 788 glEnd(); 784 789 glBegin(GL_TRIANGLES); 785 790 } 786 791 787 currentGroup->faceMode = 3;792 this->currentGroup->faceMode = 3; 788 793 if (verbose >=3) 789 794 printf ("found triag.\n"); … … 792 797 else if (tmpFace->vertexCount == 4) 793 798 { 794 if ( currentGroup->faceMode != 4)799 if (this->currentGroup->faceMode != 4) 795 800 { 796 if ( currentGroup->faceMode != -1)801 if (this->currentGroup->faceMode != -1) 797 802 glEnd(); 798 803 glBegin(GL_QUADS); 799 804 } 800 currentGroup->faceMode = 4;805 this->currentGroup->faceMode = 4; 801 806 if (verbose >=3 ) 802 807 printf ("found quad.\n"); … … 805 810 else if (tmpFace->vertexCount > 4) 806 811 { 807 if ( currentGroup->faceMode != -1)812 if (this->currentGroup->faceMode != -1) 808 813 glEnd(); 809 814 glBegin(GL_POLYGON); 810 815 if (verbose >=3) 811 816 printf ("Polygon with %i faces found.", tmpFace->vertexCount); 812 currentGroup->faceMode = tmpFace->vertexCount;817 this->currentGroup->faceMode = tmpFace->vertexCount; 813 818 } 814 819 … … 817 822 { 818 823 // printf ("%s\n", tmpElem->value); 819 addGLElement(tmpElem);824 this->addGLElement(tmpElem); 820 825 tmpElem = tmpElem->next; 821 826 } … … 824 829 glEnd(); 825 830 glEndList(); 826 currentGroup = currentGroup->next; 831 832 this->currentGroup = this->currentGroup->next; 827 833 } 828 834 } … … 844 850 845 851 if (elem->texCoordNumber != -1) 846 glTexCoord2fv( vTexture->getArray() + elem->texCoordNumber * 2);852 glTexCoord2fv(this->vTexture->getArray() + elem->texCoordNumber * 2); 847 853 if (elem->normalNumber != -1) 848 glNormal3fv( normals->getArray() + elem->normalNumber * 3);854 glNormal3fv(this->normals->getArray() + elem->normalNumber * 3); 849 855 if (elem->vertexNumber != -1) 850 glVertex3fv( vertices->getArray() + elem->vertexNumber * 3);856 glVertex3fv(this->vertices->getArray() + elem->vertexNumber * 3); 851 857 852 858 } … … 925 931 printf ("Found Normale number %d: (%f; %f, %f).\n", i, normArray[i].x, normArray[i].y, normArray[i].z); 926 932 927 normals->addEntry(normArray[i].x, normArray[i].y, normArray[i].z);933 this->normals->addEntry(normArray[i].x, normArray[i].y, normArray[i].z); 928 934 929 935 } … … 940 946 void Object::BoxObject(void) 941 947 { 942 readVertex ("-0.5 -0.5 0.5");943 readVertex ("0.5 -0.5 0.5");944 readVertex ("-0.5 0.5 0.5");945 readVertex ("0.5 0.5 0.5");946 readVertex ("-0.5 0.5 -0.5");947 readVertex ("0.5 0.5 -0.5");948 readVertex ("-0.5 -0.5 -0.5");949 readVertex ("0.5 -0.5 -0.5");950 951 readVertexTexture ("0.0 0.0");952 readVertexTexture ("1.0 0.0");953 readVertexTexture ("0.0 1.0");954 readVertexTexture ("1.0 1.0");955 readVertexTexture ("0.0 2.0");956 readVertexTexture ("1.0 2.0");957 readVertexTexture ("0.0 3.0");958 readVertexTexture ("1.0 3.0");959 readVertexTexture ("0.0 4.0");960 readVertexTexture ("1.0 4.0");961 readVertexTexture ("2.0 0.0");962 readVertexTexture ("2.0 1.0");963 readVertexTexture ("-1.0 0.0");964 readVertexTexture ("-1.0 1.0");965 966 readVertexNormal ("0.0 0.0 1.0");967 readVertexNormal ("0.0 0.0 1.0");968 readVertexNormal ("0.0 0.0 1.0");969 readVertexNormal ("0.0 0.0 1.0");970 readVertexNormal ("0.0 1.0 0.0");971 readVertexNormal ("0.0 1.0 0.0");972 readVertexNormal ("0.0 1.0 0.0");973 readVertexNormal ("0.0 1.0 0.0");974 readVertexNormal ("0.0 0.0 -1.0");975 readVertexNormal ("0.0 0.0 -1.0");976 readVertexNormal ("0.0 0.0 -1.0");977 readVertexNormal ("0.0 0.0 -1.0");978 readVertexNormal ("0.0 -1.0 0.0");979 readVertexNormal ("0.0 -1.0 0.0");980 readVertexNormal ("0.0 -1.0 0.0");981 readVertexNormal ("0.0 -1.0 0.0");982 readVertexNormal ("1.0 0.0 0.0");983 readVertexNormal ("1.0 0.0 0.0");984 readVertexNormal ("1.0 0.0 0.0");985 readVertexNormal ("1.0 0.0 0.0");986 readVertexNormal ("-1.0 0.0 0.0");987 readVertexNormal ("-1.0 0.0 0.0");988 readVertexNormal ("-1.0 0.0 0.0");989 readVertexNormal ("-1.0 0.0 0.0");948 this->readVertex ("-0.5 -0.5 0.5"); 949 this->readVertex ("0.5 -0.5 0.5"); 950 this->readVertex ("-0.5 0.5 0.5"); 951 this->readVertex ("0.5 0.5 0.5"); 952 this->readVertex ("-0.5 0.5 -0.5"); 953 this->readVertex ("0.5 0.5 -0.5"); 954 this->readVertex ("-0.5 -0.5 -0.5"); 955 this->readVertex ("0.5 -0.5 -0.5"); 956 957 this->readVertexTexture ("0.0 0.0"); 958 this->readVertexTexture ("1.0 0.0"); 959 this->readVertexTexture ("0.0 1.0"); 960 this->readVertexTexture ("1.0 1.0"); 961 this->readVertexTexture ("0.0 2.0"); 962 this->readVertexTexture ("1.0 2.0"); 963 this->readVertexTexture ("0.0 3.0"); 964 this->readVertexTexture ("1.0 3.0"); 965 this->readVertexTexture ("0.0 4.0"); 966 this->readVertexTexture ("1.0 4.0"); 967 this->readVertexTexture ("2.0 0.0"); 968 this->readVertexTexture ("2.0 1.0"); 969 this->readVertexTexture ("-1.0 0.0"); 970 this->readVertexTexture ("-1.0 1.0"); 971 972 this->readVertexNormal ("0.0 0.0 1.0"); 973 this->readVertexNormal ("0.0 0.0 1.0"); 974 this->readVertexNormal ("0.0 0.0 1.0"); 975 this->readVertexNormal ("0.0 0.0 1.0"); 976 this->readVertexNormal ("0.0 1.0 0.0"); 977 this->readVertexNormal ("0.0 1.0 0.0"); 978 this->readVertexNormal ("0.0 1.0 0.0"); 979 this->readVertexNormal ("0.0 1.0 0.0"); 980 this->readVertexNormal ("0.0 0.0 -1.0"); 981 this->readVertexNormal ("0.0 0.0 -1.0"); 982 this->readVertexNormal ("0.0 0.0 -1.0"); 983 this->readVertexNormal ("0.0 0.0 -1.0"); 984 this->readVertexNormal ("0.0 -1.0 0.0"); 985 this->readVertexNormal ("0.0 -1.0 0.0"); 986 this->readVertexNormal ("0.0 -1.0 0.0"); 987 this->readVertexNormal ("0.0 -1.0 0.0"); 988 this->readVertexNormal ("1.0 0.0 0.0"); 989 this->readVertexNormal ("1.0 0.0 0.0"); 990 this->readVertexNormal ("1.0 0.0 0.0"); 991 this->readVertexNormal ("1.0 0.0 0.0"); 992 this->readVertexNormal ("-1.0 0.0 0.0"); 993 this->readVertexNormal ("-1.0 0.0 0.0"); 994 this->readVertexNormal ("-1.0 0.0 0.0"); 995 this->readVertexNormal ("-1.0 0.0 0.0"); 990 996 991 997 /* normaleLess-testingMode 992 readFace ("1 2 4 3");993 readFace ("3 4 6 5");994 readFace ("5 6 8 7");995 readFace ("7 8 2 1");996 readFace ("2 8 6 4");997 readFace ("7 1 3 5");998 this->readFace ("1 2 4 3"); 999 this->readFace ("3 4 6 5"); 1000 this->readFace ("5 6 8 7"); 1001 this->readFace ("7 8 2 1"); 1002 this->readFace ("2 8 6 4"); 1003 this->readFace ("7 1 3 5"); 998 1004 */ 999 1005 1000 readFace ("1/1/1 2/2/2 4/4/3 3/3/4");1001 readFace ("3/3/5 4/4/6 6/6/7 5/5/8");1002 readFace ("5/5/9 6/6/10 8/8/11 7/7/12");1003 readFace ("7/7/13 8/8/14 2/10/15 1/9/16");1004 readFace ("2/2/17 8/11/18 6/12/19 4/4/20");1005 readFace ("7/13/21 1/1/22 3/3/23 5/14/24");1006 1007 } 1006 this->readFace ("1/1/1 2/2/2 4/4/3 3/3/4"); 1007 this->readFace ("3/3/5 4/4/6 6/6/7 5/5/8"); 1008 this->readFace ("5/5/9 6/6/10 8/8/11 7/7/12"); 1009 this->readFace ("7/7/13 8/8/14 2/10/15 1/9/16"); 1010 this->readFace ("2/2/17 8/11/18 6/12/19 4/4/20"); 1011 this->readFace ("7/13/21 1/1/22 3/3/23 5/14/24"); 1012 1013 }
Note: See TracChangeset
for help on using the changeset viewer.