Changeset 4111 in orxonox.OLD for orxonox/branches
- Timestamp:
- May 7, 2005, 5:22:44 PM (20 years ago)
- Location:
- orxonox/branches/heightMap/src/lib/graphics/importer
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/heightMap/src/lib/graphics/importer/Makefile.in
r4090 r4111 115 115 EXEEXT = @EXEEXT@ 116 116 GPROF = @GPROF@ 117 GTHREAD_CFLAGS = @GTHREAD_CFLAGS@118 GTHREAD_LIBS = @GTHREAD_LIBS@119 117 GTK2_CFLAGS = @GTK2_CFLAGS@ 120 118 GTK2_LIBS = @GTK2_LIBS@ 121 119 HAVE_CURL_FALSE = @HAVE_CURL_FALSE@ 122 120 HAVE_CURL_TRUE = @HAVE_CURL_TRUE@ 123 HAVE_GTHREAD_FALSE = @HAVE_GTHREAD_FALSE@124 HAVE_GTHREAD_TRUE = @HAVE_GTHREAD_TRUE@125 121 HAVE_GTK2_FALSE = @HAVE_GTK2_FALSE@ 126 122 HAVE_GTK2_TRUE = @HAVE_GTK2_TRUE@ … … 143 139 PACKAGE_VERSION = @PACKAGE_VERSION@ 144 140 PATH_SEPARATOR = @PATH_SEPARATOR@ 141 RANLIB = @RANLIB@ 145 142 SET_MAKE = @SET_MAKE@ 146 143 SHELL = @SHELL@ … … 151 148 ac_ct_CC = @ac_ct_CC@ 152 149 ac_ct_CXX = @ac_ct_CXX@ 150 ac_ct_RANLIB = @ac_ct_RANLIB@ 153 151 ac_ct_STRIP = @ac_ct_STRIP@ 154 152 am__fastdepCC_FALSE = @am__fastdepCC_FALSE@ -
orxonox/branches/heightMap/src/lib/graphics/importer/array.cc
r3590 r4111 112 112 113 113 /** 114 \brief Gives back the array !! MUST be executed AFTER finalize.115 \returns The created array.116 */117 GLfloat* Array::getArray ()118 {119 return this->array;120 }121 122 /**123 \returns The Count of entries in the Array124 */125 int Array::getCount()126 {127 return this->entryCount;128 }129 130 /**131 114 \brief Simple debug info about the Array 132 115 */ 133 void Array::debug ( )116 void Array::debug (void) const 134 117 { 135 118 PRINT(0)("entryCount=%i, address=%p\n", this->entryCount, this->array); -
orxonox/branches/heightMap/src/lib/graphics/importer/array.h
r3590 r4111 23 23 void addEntry(GLfloat entry0, GLfloat entry1, GLfloat entry2); 24 24 25 GLfloat* getArray (); 26 int getCount(); 27 void debug(void); 25 /** \returns The array */ 26 inline const GLfloat* getArray () const {return this->array;} 27 /** \returns The Count of entries in the Array*/ 28 inline int getCount(void)const {return this->entryCount;} 29 void debug(void) const ; 28 30 private: 29 31 //! One entry of the Array -
orxonox/branches/heightMap/src/lib/graphics/importer/material.cc
r3914 r4111 88 88 89 89 // setting the transparency 90 if (this->transparency == 1.0) 91 { 92 glDisable(GL_BLEND); 93 } 94 else 90 if (this->transparency < 1.0) 95 91 { 96 92 glEnable(GL_BLEND); … … 98 94 glBlendFunc(GL_SRC_ALPHA, GL_ONE); 99 95 } 96 else 97 { 98 glDisable(GL_BLEND); 99 glColor4f(1.0f, 1.0f, 1.0f, 1.0f); 100 } 101 100 102 101 103 // setting illumination Model … … 109 111 glEnable(GL_TEXTURE_2D); 110 112 glBindTexture(GL_TEXTURE_2D, this->diffuseTexture->getTexture()); 113 114 /* This allows alpha blending of 2D textures with the scene */ 115 if (this->diffuseTexture->hasAlpha()) 116 { 117 glEnable(GL_BLEND); 118 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 119 } 111 120 } 112 121 else -
orxonox/branches/heightMap/src/lib/graphics/importer/model.cc
r3917 r4111 27 27 using namespace std; 28 28 29 ////////////////// 30 // DE-CONSTRUCT // 31 ////////////////// 32 /** 33 \brief Creates a 3D-Model. and assigns it a Name. 29 30 //////////////////// 31 /// SUB-Elements /// 32 //////////////////// 33 /** 34 \brief creates a new ModelFaceElement 35 */ 36 ModelFaceElement::ModelFaceElement() 37 { 38 this->vertexNumber = -1; 39 this->normalNumber = -1; 40 this->texCoordNumber = -1; 41 42 this->next = NULL; 43 } 44 45 /** 46 \brief destroys a ModelFaceElement 47 */ 48 ModelFaceElement::~ModelFaceElement() 49 { 50 if (this->next) 51 delete this->next; 52 } 53 54 /** 55 \brief creates a new ModelFace 56 */ 57 ModelFace::ModelFace() 58 { 59 this->vertexCount = 0; 60 61 this->firstElem = NULL; 62 63 this->material = NULL; 64 65 this->next = NULL; 66 67 } 68 69 /** 70 \brief deletes a ModelFace 71 */ 72 ModelFace::~ModelFace() 73 { 74 PRINTF(5)("Cleaning up Face\n"); 75 76 if (this->firstElem != NULL) 77 delete this->firstElem; 78 79 if (this->next != NULL) 80 delete this->next; 81 } 82 83 /** 84 \brief Creates a new ModelGroup 85 */ 86 ModelGroup::ModelGroup() 87 { 88 PRINTF(4)("Adding new Group\n"); 89 this->name = ""; 90 this->faceMode = -1; 91 this->faceCount = 0; 92 this->next = NULL; 93 94 this->firstFace = new ModelFace; 95 this->currentFace = this->firstFace; 96 } 97 98 /** 99 \brief deletes a ModelGroup 100 */ 101 ModelGroup::~ModelGroup() 102 { 103 PRINTF(5)("Cleaning up group\n"); 104 if (this->firstFace != NULL) 105 delete this->firstFace; 106 107 if (this->next !=NULL) 108 delete this->next; 109 } 110 111 /** 112 \brief cleans up a ModelGroup 113 114 actually does the same as the delete Operator, but does not delete the predecessing group 115 */ 116 void ModelGroup::cleanup(void) 117 { 118 PRINTF(5)("Cleaning up group\n"); 119 if (this->firstFace) 120 delete this->firstFace; 121 this->firstFace = NULL; 122 if (this->next) 123 this->next->cleanup(); 124 } 125 126 127 ///////////// 128 /// MODEL /// 129 ///////////// 130 /** 131 \brief Creates a 3D-Model. 132 133 assigns it a Name and a Type 34 134 */ 35 135 Model::Model(const char* modelName, MODEL_TYPE type) … … 42 142 this->finalized = false; 43 143 // setting the start group; 44 this->firstGroup = new Group; 45 this->currentGroup = this->firstGroup; 144 this->currentGroup = this->firstGroup = new ModelGroup; 46 145 this->groupCount = 0; 47 48 this->initGroup (this->currentGroup); 146 this->vertexCount = 0; 147 this->normalCount = 0; 148 this->texCoordCount = 0; 149 49 150 this->scaleFactor = 1; 50 151 … … 76 177 77 178 PRINTF(5)("Deleting display Lists.\n"); 78 Group* walker = this->firstGroup; 79 while (walker != NULL) 80 { 81 glDeleteLists (walker->listNumber, 1); 82 Group* delWalker = walker; 83 walker = walker->next; 84 delete delWalker; 85 } 179 delete this->firstGroup; 86 180 87 181 // deleting Arrays … … 92 186 tIterator<Material>* tmpIt = this->materialList->getIterator(); 93 187 Material* material = tmpIt->nextElement(); 188 189 //! \todo do we really have to delete this material?? 94 190 while(material) 95 191 { … … 128 224 { 129 225 PRINTF(4)("drawing the 3D-Models\n"); 130 Group* walker= this->firstGroup;131 while ( walker!= NULL)132 { 133 PRINTF(5)("Drawing model %s\n", walker->name);134 glCallList ( walker->listNumber);135 walker = walker->next;226 ModelGroup* tmpGroup = this->firstGroup; 227 while (tmpGroup != NULL) 228 { 229 PRINTF(5)("Drawing model %s\n", tmpGroup->name); 230 glCallList (tmpGroup->listNumber); 231 tmpGroup = tmpGroup->next; 136 232 } 137 233 } … … 151 247 } 152 248 PRINTF(4)("drawing the requested 3D-Models if found.\n"); 153 Group* walker= this->firstGroup;249 ModelGroup* tmpGroup = this->firstGroup; 154 250 int counter = 0; 155 while ( walker!= NULL)251 while (tmpGroup != NULL) 156 252 { 157 253 if (counter == groupNumber) 158 254 { 159 PRINTF(4)("Drawing model number %i named %s\n", counter, walker->name);160 glCallList ( walker->listNumber);255 PRINTF(4)("Drawing model number %i named %s\n", counter, tmpGroup->name); 256 glCallList (tmpGroup->listNumber); 161 257 return; 162 258 } 163 259 ++counter; 164 walker = walker->next;260 tmpGroup = tmpGroup->next; 165 261 } 166 262 PRINTF(2)("Model number %i in %s not Found.\n", groupNumber, this->name); … … 178 274 { 179 275 PRINTF(4)("drawing the requested 3D-Models if found.\n"); 180 Group* walker= this->firstGroup;181 while ( walker!= NULL)182 { 183 if (!strcmp( walker->name, groupName))276 ModelGroup* tmpGroup = this->firstGroup; 277 while (tmpGroup != NULL) 278 { 279 if (!strcmp(tmpGroup->name, groupName)) 184 280 { 185 PRINTF(4)("Drawing model %s\n", walker->name);186 glCallList ( walker->listNumber);281 PRINTF(4)("Drawing model %s\n", tmpGroup->name); 282 glCallList (tmpGroup->listNumber); 187 283 return; 188 284 } 189 walker = walker->next;285 tmpGroup = tmpGroup->next; 190 286 } 191 287 PRINTF(2)("Model Named %s in %s not Found.\n", groupName, this->name); 192 288 return; 193 }194 195 /**196 \returns Count of the Models in this File197 */198 int Model::getGroupCount (void) const199 {200 return this->groupCount;201 289 } 202 290 … … 210 298 void Model::setName(const char* name) 211 299 { 212 if (this->name) 213 delete this->name;300 if (this->name) 301 delete []this->name; 214 302 if (name) 215 303 { … … 219 307 else 220 308 this->name = NULL; 221 }222 223 /**224 \brief initializes a new Group model225 \param group the group that should be initialized.226 \todo Maybe Group should be a Class, because it does a lot of stuff227 228 */229 bool Model::initGroup(Group* group)230 {231 PRINTF(4)("Adding new Group\n");232 group->name = "";233 group->faceMode = -1;234 group->faceCount = 0;235 group->next = NULL;236 237 group->firstFace = new Face;238 this->initFace (group->firstFace);239 group->currentFace = group->firstFace;240 }241 242 /**243 \brief initializes a new Face. (sets default Values)244 \param face The face to initialize245 */246 bool Model::initFace (Face* face)247 {248 face->vertexCount = 0;249 250 face->firstElem = NULL;251 252 face->material = NULL;253 254 face->next = NULL;255 256 return true;257 309 } 258 310 … … 268 320 if (this->normals) 269 321 delete this->normals; 322 270 323 this->vertices = NULL; 271 324 this->vTexture = NULL; … … 280 333 { 281 334 PRINTF(4)("cleaning up the 3D-Model to save Memory.\n"); 282 this-> cleanupGroup(this->firstGroup);335 this->firstGroup->cleanup(); 283 336 return true; 284 337 } 285 338 286 /** 287 \brief Cleans up all groups starting from group. 288 \param group the first Group to clean 289 */ 290 bool Model::cleanupGroup (Group* group) 291 { 292 PRINTF(5)("Cleaning up group\n"); 293 if (group->firstFace != NULL) 294 { 295 cleanupFace (group->firstFace); 296 delete group->firstFace; 297 } 298 299 if (group->next !=NULL) 300 cleanupGroup (group->next); 301 return true; 302 } 303 304 /** 305 \brief Cleans up all Faces starting from face until NULL is reached. 306 \param face the first face to clean. 307 */ 308 bool Model::cleanupFace (Face* face) 309 { 310 PRINTF(5)("Cleaning up Face\n"); 311 312 if (face->firstElem != NULL) 313 { 314 this->cleanupFaceElement(face->firstElem); 315 delete face->firstElem; 316 } 317 318 if (face->next != NULL) 319 { 320 this->cleanupFace (face->next); 321 delete face->next; 322 } 323 } 324 325 /** 326 \brief Cleans up all FaceElements starting from faceElem. 327 \param faceElem the first FaceElement to clean. 328 */ 329 bool Model::cleanupFaceElement(FaceElement* faceElem) 330 { 331 if (faceElem->next != NULL) 332 { 333 this->cleanupFaceElement (faceElem->next); 334 delete faceElem->next; 335 } 336 } 339 337 340 338 341 ////////// … … 354 357 /** 355 358 \brief adds a new Material to the Material List 356 \param material the name of the Material to add359 \param materialName the name of the Material to add 357 360 \returns the added material 358 361 */ 359 362 Material* Model::addMaterial(const char* materialName) 360 363 { 361 362 364 Material* newMat = new Material(); 363 365 newMat->setName(materialName); … … 395 397 396 398 This function initializes a new Group. 397 With it you should be able to import .obj-files with more than one Models inside.398 */ 399 bool Model::addGroup 399 With it you should be able to create Models with more than one SubModel inside 400 */ 401 bool Model::addGroup(const char* groupString) 400 402 { 401 403 PRINTF(5)("Read Group: %s.\n", groupString); 402 if (this->groupCount != 0 && this->currentGroup->faceCount >0)404 if (this->groupCount != 0 && this->currentGroup->faceCount > 0) 403 405 { 404 406 // finalizeGroup(currentGroup); 405 this->currentGroup = this->currentGroup->next = new Group; 406 this->initGroup(this->currentGroup); 407 this->currentGroup = this->currentGroup->next = new ModelGroup; 407 408 } 408 409 // setting the group name if not default. … … 429 430 PRINTF(5)("reading in a vertex: %f %f %f\n", &subbuffer1, &subbuffer2, &subbuffer3); 430 431 this->vertices->addEntry(subbuffer1*scaleFactor, subbuffer2*scaleFactor, subbuffer3*scaleFactor); 432 this->vertexCount++; 431 433 return true; 432 434 } … … 443 445 PRINTF(5)("reading in a vertex: %f %f %f\n", x, y, z); 444 446 this->vertices->addEntry(x*scaleFactor, y*scaleFactor, z*scaleFactor); 447 this->vertexCount++; 445 448 return true; 446 449 } … … 460 463 PRINTF(5)("found vertex-Normal %f, %f, %f\n", &subbuffer1,&subbuffer2,&subbuffer3); 461 464 this->normals->addEntry(subbuffer1, subbuffer2, subbuffer3); 465 this->normalCount++; 462 466 return true; 463 467 } … … 475 479 PRINTF(5)("found vertex-Normal %f, %f, %f\n", x, y, z); 476 480 this->normals->addEntry(x, y, z); 481 this->normalCount++; 482 return true; 477 483 } 478 484 … … 492 498 this->vTexture->addEntry(subbuffer1); 493 499 this->vTexture->addEntry(subbuffer2); 500 this->texCoordCount++; 494 501 return true; 495 502 } … … 507 514 this->vTexture->addEntry(u); 508 515 this->vTexture->addEntry(v); 516 this->texCoordCount++; 517 return true; 509 518 } 510 519 … … 518 527 { 519 528 if (this->currentGroup->faceCount >0) 520 this->currentGroup->currentFace = this->currentGroup->currentFace->next = new Face; 521 this->initFace (this->currentGroup->currentFace); 522 523 FaceElement* tmpElem = this->currentGroup->currentFace->firstElem = new FaceElement; 529 this->currentGroup->currentFace = this->currentGroup->currentFace->next = new ModelFace; 530 531 ModelFaceElement* tmpElem = this->currentGroup->currentFace->firstElem = new ModelFaceElement; 524 532 tmpElem->next = NULL; 525 533 while(strcmp (faceString, "\0")) 526 534 { 527 535 if (this->currentGroup->currentFace->vertexCount>0) 528 tmpElem = tmpElem->next = new FaceElement;536 tmpElem = tmpElem->next = new ModelFaceElement; 529 537 tmpElem->next = NULL; 530 538 … … 552 560 if (vertex) 553 561 tmpElem->vertexNumber = atoi(vertex)-1; 554 else555 tmpElem->vertexNumber = -1;556 562 if (texture) 557 563 tmpElem->texCoordNumber = atoi(texture)-1; 558 else559 tmpElem->texCoordNumber = -1;560 564 if (normal) 561 565 tmpElem->normalNumber = atoi(normal)-1; 562 else563 tmpElem->normalNumber = -1;564 566 565 567 faceString += tmpLen; … … 579 581 bool Model::addFace(int faceElemCount, VERTEX_FORMAT type, ...) 580 582 { 581 if (this->currentGroup->faceCount > 0) 582 this->currentGroup->currentFace = this->currentGroup->currentFace->next = new Face; 583 this->initFace (this->currentGroup->currentFace); 584 585 FaceElement* tmpElem = this->currentGroup->currentFace->firstElem = new FaceElement; 586 tmpElem->next = NULL; 583 if (this->currentGroup->faceCount > 0) 584 this->currentGroup->currentFace = this->currentGroup->currentFace->next = new ModelFace; 585 586 ModelFaceElement* tmpElem = this->currentGroup->currentFace->firstElem = new ModelFaceElement; 587 587 588 588 va_list itemlist; … … 591 591 for (int i = 0; i < faceElemCount; i++) 592 592 { 593 if (this->currentGroup->currentFace->vertexCount>0) 594 tmpElem = tmpElem->next = new FaceElement; 595 tmpElem->next = NULL; 593 if (this->currentGroup->currentFace->vertexCount > 0) 594 tmpElem = tmpElem->next = new ModelFaceElement; 596 595 597 596 tmpElem->vertexNumber = va_arg (itemlist, int) -1; … … 614 613 { 615 614 if (this->currentGroup->faceCount > 0) 616 this->currentGroup->currentFace = this->currentGroup->currentFace->next = new Face; 617 this->initFace (this->currentGroup->currentFace); 615 this->currentGroup->currentFace = this->currentGroup->currentFace->next = new ModelFace; 618 616 619 617 this->currentGroup->currentFace->material = this->findMaterialByName(matString); … … 630 628 { 631 629 if (this->currentGroup->faceCount > 0) 632 this->currentGroup->currentFace = this->currentGroup->currentFace->next = new Face; 633 this->initFace (this->currentGroup->currentFace); 630 this->currentGroup->currentFace = this->currentGroup->currentFace->next = new ModelFace; 634 631 635 632 this->currentGroup->currentFace->material = mtl; … … 662 659 Vector curV; 663 660 664 Group* tmpGroup = firstGroup;661 ModelGroup* tmpGroup = firstGroup; 665 662 while (tmpGroup) 666 663 { 667 Face* tmpFace = tmpGroup->firstFace;664 ModelFace* tmpFace = tmpGroup->firstFace; 668 665 while (tmpFace) 669 666 { 670 667 if (tmpFace->firstElem) 671 668 { 672 FaceElement* firstElem = tmpFace->firstElem;673 FaceElement* prevElem;674 FaceElement* curElem = firstElem;675 FaceElement* nextElem;676 FaceElement* lastElem;669 ModelFaceElement* firstElem = tmpFace->firstElem; 670 ModelFaceElement* prevElem; 671 ModelFaceElement* curElem = firstElem; 672 ModelFaceElement* nextElem; 673 ModelFaceElement* lastElem; 677 674 // find last Element of the Chain. !! IMPORTANT:the last Element of the Chain must point to NULL, or it will resolv into an infinity-loop. 678 675 while (curElem) … … 704 701 } 705 702 706 for (int i=0; i <vertices->getCount()/3;i++)703 for (int i=0; i < vertices->getCount()/3;i++) 707 704 { 708 705 normArray[i].normalize(); 709 706 PRINTF(5)("Found Normale number %d: (%f; %f, %f).\n", i, normArray[i].x, normArray[i].y, normArray[i].z); 710 707 711 this-> normals->addEntry(normArray[i].x, normArray[i].y, normArray[i].z);708 this->addVertexNormal(normArray[i].x, normArray[i].y, normArray[i].z); 712 709 713 710 } … … 744 741 745 742 // Putting Faces to GL 746 Face* tmpFace = this->currentGroup->firstFace;743 ModelFace* tmpFace = this->currentGroup->firstFace; 747 744 while (tmpFace != NULL) 748 745 { … … 794 791 } 795 792 796 FaceElement* tmpElem = tmpFace->firstElem;793 ModelFaceElement* tmpElem = tmpFace->firstElem; 797 794 while (tmpElem != NULL) 798 795 { … … 826 823 glNormalPointer(3, 0, this->normals->getArray()); 827 824 glTexCoordPointer(2, GL_FLOAT, 0, this->vTexture->getArray()); 828 829 825 } 830 826 … … 841 837 merging this information, the face will be drawn. 842 838 */ 843 bool Model::addGLElement ( FaceElement* elem)839 bool Model::addGLElement (ModelFaceElement* elem) 844 840 { 845 841 PRINTF(5)("importing grafical Element to openGL.\n"); 846 842 847 843 if (elem->texCoordNumber != -1) 848 glTexCoord2fv(this->vTexture->getArray() + elem->texCoordNumber * 2); 844 { 845 if (likely(elem->texCoordNumber < this->texCoordCount)) 846 glTexCoord2fv(this->vTexture->getArray() + elem->texCoordNumber * 2); 847 else 848 PRINTF(2)("TextureCoordinate %d is not in the List (max: %d)\nThe Model might be incomplete\n", 849 elem->texCoordNumber, this->texCoordCount); 850 } 849 851 if (elem->normalNumber != -1) 850 glNormal3fv(this->normals->getArray() + elem->normalNumber * 3); 852 { 853 if (likely(elem->normalNumber < this->normalCount)) 854 glNormal3fv(this->normals->getArray() + elem->normalNumber * 3); 855 else 856 PRINTF(2)("Normal %d is not in the List (max: %d)\nThe Model might be incomplete", 857 elem->normalNumber, this->normalCount); 858 } 851 859 if (elem->vertexNumber != -1) 852 glVertex3fv(this->vertices->getArray() + elem->vertexNumber * 3); 860 { 861 if (likely(elem->vertexNumber < this->vertexCount)) 862 glVertex3fv(this->vertices->getArray() + elem->vertexNumber * 3); 863 else 864 PRINTF(2)("Vertex %d is not in the List (max: %d)\nThe Model might be incomplete", 865 elem->vertexNumber, this->vertexCount); 866 } 853 867 854 868 } -
orxonox/branches/heightMap/src/lib/graphics/importer/model.h
r3917 r4111 34 34 VERTEX_TEXCOORD_NORMAL = NORMAL | TEXCOORD}; 35 35 36 //////////////////// 37 /// SUB-ELEMENTS /// 38 //////////////////// 39 //! This is the placeholder of one Vertex beloning to a Face. 40 class ModelFaceElement 41 { 42 public: 43 ModelFaceElement(); 44 ~ModelFaceElement(); 45 46 int vertexNumber; //!< The number of the Vertex out of the Array* vertices, this vertex points to. 47 int normalNumber; //!< The number of the Normal out of the Array* normals, this vertex points to. 48 int texCoordNumber; //!< The number of the textureCoordinate out of the Array* vTexture, this vertex points to. 49 ModelFaceElement* next; //!< Point to the next FaceElement in this List. 50 }; 51 52 //! This is the placeholder of a Face belonging to a Group of Faces. 53 class ModelFace 54 { 55 public: 56 ModelFace(); 57 ~ModelFace(); 58 59 int vertexCount; //!< The Count of vertices this Face has. 60 ModelFaceElement* firstElem; //!< Points to the first Vertex (FaceElement) of this Face. 61 62 Material* material; //!< The Material to use. 63 64 ModelFace* next; //!< Pointer to the next Face. 65 }; 66 67 //! Group to handle multiple Models per obj-file. 68 class ModelGroup 69 { 70 public: 71 ModelGroup(); 72 ~ModelGroup(); 73 74 void cleanup(); 75 76 char* name; //!< the Name of the Group. this is an identifier, that can be accessed via the draw (char* name) function. 77 78 GLubyte* indices; //!< The indices of the Groups. Needed for vertex-arrays 79 GLuint listNumber; //!< The number of the GL-List this Group gets. 80 ModelFace* firstFace; //!< The first Face in this group. 81 ModelFace* currentFace; //!< The current Face in this Group (the one we are currently working with.) 82 int faceMode; //!< The Mode the Face is in: initially -1, 0 for FaceList opened, 1 for Material, 3 for triangle, 4 for Quad, 5+ for Poly \todo ENUM... 83 int faceCount; //!< The Number of Faces this Group holds. 84 85 ModelGroup* next; //!< Pointer to the next Group. 86 }; 87 88 ///////////// 89 /// MODEL /// 90 ///////////// 91 36 92 //! Class that handles 3D-Models. it can also read them in and display them. 37 93 class Model 38 94 { 39 95 private: 40 /////////////41 // structs //42 /////////////43 //! This is the placeholder of one Vertex beloning to a Face.44 struct FaceElement45 {46 int vertexNumber; //!< The number of the Vertex out of the Array* vertices, this vertex points to.47 int normalNumber; //!< The number of the Normal out of the Array* normals, this vertex points to.48 int texCoordNumber; //!< The number of the textureCoordinate out of the Array* vTexture, this vertex points to.49 FaceElement* next; //!< Point to the next FaceElement in this List.50 };51 96 52 //! This is the placeholder of a Face belonging to a Group of Faces. 53 struct Face 54 { 55 int vertexCount; //!< The Count of vertices this Face has. 56 FaceElement* firstElem; //!< Points to the first Vertex (FaceElement) of this Face. 97 char* name; //!< This is the name of the Model. 98 MODEL_TYPE type; //!< A type for the Model 99 bool finalized; //!< Sets the Object to be finalized. 57 100 58 Material* material; //!< The Material to use. 101 int vertexCount; //!< A modelwide Counter for vertices. 102 int normalCount; //!< A modelwide Counter for the normals. 103 int texCoordCount; //!< A modelwide Counter for the texCoord. 104 Array* vertices; //!< The Array that handles the Vertices. 105 Array* normals; //!< The Array that handles the Normals. 106 Array* vTexture; //!< The Array that handles the VertexTextureCoordinates. 59 107 60 Face* next; //!< Pointer to the next Face. 61 }; 108 ModelGroup* firstGroup; //!< The first of all groups. 109 ModelGroup* currentGroup; //!< The currentGroup. this is the one we will work with. 110 int groupCount; //!< The Count of Groups. 62 111 63 //! Group to handle multiple Models per obj-file. 64 struct Group 65 { 66 char* name; //!< the Name of the Group. this is an identifier, that can be accessed via the draw (char* name) function. 67 68 GLubyte* indices; //!< The indices of the Groups. Needed for vertex-arrays 69 GLuint listNumber; //!< The number of the GL-List this Group gets. 70 Face* firstFace; //!< The first Face in this group. 71 Face* currentFace; //!< The current Face in this Group (the one we are currently working with.) 72 int faceMode; //!< The Mode the Face is in: initially -1, 0 for FaceList opened, 1 for Material, 3 for triangle, 4 for Quad, 5+ for Poly \todo ENUM... 73 int faceCount; //!< The Number of Faces this Group holds. 74 75 Group* next; //!< Pointer to the next Group. 76 }; 77 78 char* name; //!< This is the name of the Model. 79 MODEL_TYPE type; 80 bool finalized; //!< Sets the Object to be finalized. 81 82 Array* vertices; //!< The Array that handles the Vertices. 83 int verticesCount; //!< A global Counter for vertices. 84 Array* normals; //!< The Array that handles the Normals. 85 Array* vTexture; //!< The Array that handles the VertexTextureCoordinates. 86 87 Group* firstGroup; //!< The first of all groups. 88 Group* currentGroup; //!< The currentGroup. this is the one we will work with. 89 int groupCount; //!< The Count of Groups. 90 91 tList<Material>* materialList; 112 tList<Material>* materialList;//!< A list for all the Materials in this Model 92 113 93 94 bool initGroup(Group* group);95 bool initFace (Face* face);96 97 114 bool buildVertexNormals(void); 98 115 99 116 bool importToDisplayList(void); 100 bool addGLElement( FaceElement* elem);117 bool addGLElement(ModelFaceElement* elem); 101 118 102 119 bool importToVertexArray(void); … … 104 121 bool deleteArrays(void); 105 122 bool cleanup(void); 106 bool cleanupGroup(Group* group);107 bool cleanupFace(Face* face);108 bool cleanupFaceElement(FaceElement* faceElem);109 123 110 124 … … 121 135 122 136 void setName(const char* name); 137 /** \returns the Name of the Model */ 123 138 inline const char* getName() {return this->name;} 124 139 … … 126 141 void draw(int groupNumber) const; 127 142 void draw(char* groupName) const; 128 int getGroupCount() const; 143 144 /** \returns Count of the Models (Groups) in this File */ 145 inline int getGroupCount(void) const {return this->groupCount;} 129 146 130 147 Material* addMaterial(Material* material); … … 143 160 bool setMaterial(Material* mtl); 144 161 void finalize(void); 162 163 /** \returns The number of Vertices of the Model */ 164 inline int getVertexCount(void) const {return this->vertexCount;} 165 /** \returns The number of Normals of the Model */ 166 inline int getNormalCount(void) const {return this->normalCount;} 167 /** \returns The number of Texture Coordinates of the Model*/ 168 inline int getTexCoordCount(void) const {return this->texCoordCount;} 145 169 }; 146 170 -
orxonox/branches/heightMap/src/lib/graphics/importer/objModel.cc
r3916 r4111 196 196 this->mtlFileName = new char [strlen(mtlFile)+1]; 197 197 strcpy(this->mtlFileName, mtlFile); 198 char* fileName = new char [strlen(objPath) + strlen(this->mtlFileName)+1]; 199 strcpy(fileName, this->objPath); 200 strcat(fileName, this->mtlFileName); 198 char* fileName = new char [strlen(this->objPath) + strlen(this->mtlFileName)+1]; 199 sprintf(fileName, "%s%s", this->objPath, this->mtlFileName); 201 200 202 201 -
orxonox/branches/heightMap/src/lib/graphics/importer/texture.cc
r3905 r4111 25 25 Texture::Texture(const char* imageName) 26 26 { 27 bAlpha = false; 27 28 this->texture = 0; 28 29 if (imageName) … … 112 113 if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) { 113 114 SDL_SetAlpha(surface, saved_flags | SDL_OPENGL, saved_alpha); 115 this->bAlpha = true; 114 116 } 115 117 … … 119 121 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 120 122 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 121 /* glTexImage2D(GL_TEXTURE_2D, 123 // build the Texture 124 glTexImage2D(GL_TEXTURE_2D, 122 125 0, 123 126 GL_RGBA, … … 127 130 GL_UNSIGNED_BYTE, 128 131 image->pixels); 129 */132 // build the MipMaps 130 133 gluBuild2DMipmaps(GL_TEXTURE_2D, 131 3,134 GL_RGBA, 132 135 w, 133 136 h, … … 135 138 GL_UNSIGNED_BYTE, 136 139 image->pixels); 137 140 138 141 SDL_FreeSurface(image); /* No longer needed */ 139 142 -
orxonox/branches/heightMap/src/lib/graphics/importer/texture.h
r3905 r4111 23 23 char* searchTextureInPaths(const char* texName) const; 24 24 void swap(unsigned char &a, unsigned char &b); 25 26 bool bAlpha; //!< if the texture has an alpha channel. 25 27 public: 26 28 Texture(const char* imageName = NULL); … … 30 32 inline GLuint getTexture(void) {return this->texture;} 31 33 GLuint loadTexToGL (SDL_Surface* surface); 34 inline bool hasAlpha(void) {return bAlpha;} 32 35 33 36 bool loadImage(const char* imageName);
Note: See TracChangeset
for help on using the changeset viewer.