Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 3, 2005, 1:35:22 AM (20 years ago)
Author:
bensch
Message:

orxonox/trunk: Model-Class is now more dynamic (all subelements are now classes too, i hope, that atilla was right about classes being as fast as structs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/lib/graphics/importer/model.cc

    r4020 r4022  
    2727using namespace std;
    2828
    29 //////////////////
    30 // DE-CONSTRUCT //
    31 //////////////////
    32 /**
    33    \brief Creates a 3D-Model. and assigns it a Name.
     29
     30////////////////////
     31/// SUB-Elements ///
     32////////////////////
     33ModelFaceElement::ModelFaceElement()
     34{
     35}
     36
     37ModelFaceElement::~ModelFaceElement()
     38{
     39  if (this->next != NULL)
     40    delete this->next;
     41}
     42
     43ModelFace::ModelFace()
     44{
     45  this->vertexCount = 0;
     46
     47  this->firstElem = NULL;
     48 
     49  this->material = NULL;
     50 
     51  this->next = NULL;
     52
     53}
     54
     55ModelFace::~ModelFace()
     56{
     57  PRINTF(5)("Cleaning up Face\n");
     58
     59  if (this->firstElem != NULL)
     60    {
     61      delete this->firstElem;
     62    }
     63     
     64  if (this->next != NULL)
     65    {
     66      delete this->next;
     67    }
     68
     69}
     70
     71ModelGroup::ModelGroup()
     72{
     73  PRINTF(4)("Adding new Group\n");
     74  this->name = "";
     75  this->faceMode = -1;
     76  this->faceCount = 0; 
     77  this->next = NULL;
     78 
     79  this->firstFace = new ModelFace;
     80  this->currentFace = this->firstFace;
     81}
     82
     83ModelGroup::~ModelGroup()
     84{
     85  PRINTF(5)("Cleaning up group\n");
     86  if (this->firstFace != NULL)
     87    {
     88      delete this->firstFace;
     89    }
     90
     91  if (this->next !=NULL)
     92    delete this->next;
     93}
     94
     95void ModelGroup::cleanup(void)
     96{
     97  if (this->firstFace)
     98    delete this->firstFace;
     99  this->firstFace = NULL;
     100  if (this->next)
     101    this->next->cleanup();
     102}
     103
     104
     105/////////////
     106/// MODEL ///
     107/////////////
     108/**
     109   \brief Creates a 3D-Model.
     110
     111   assigns it a Name and a Type
    34112*/
    35113Model::Model(const char* modelName, MODEL_TYPE type)
     
    42120  this->finalized = false;
    43121  // setting the start group;
    44   this->firstGroup = new Group;
    45   this->currentGroup = this->firstGroup;
     122  this->currentGroup = this->firstGroup = new ModelGroup;
    46123  this->groupCount = 0;
    47124 
    48   this->initGroup (this->currentGroup);
    49125  this->scaleFactor = 1;
    50126
     
    76152
    77153  PRINTF(5)("Deleting display Lists.\n");
    78   Group* walker = this->firstGroup;
     154  ModelGroup* walker = this->firstGroup;
    79155  while (walker != NULL)
    80156    {
    81157      glDeleteLists (walker->listNumber, 1);
    82       Group* delWalker = walker;
     158      ModelGroup* delWalker = walker;
    83159      walker = walker->next;
    84160      delete delWalker;
     
    128204{
    129205  PRINTF(4)("drawing the 3D-Models\n");
    130   Group* walker = this->firstGroup;
     206  ModelGroup* walker = this->firstGroup;
    131207  while (walker != NULL)
    132208    {
     
    151227    }
    152228  PRINTF(4)("drawing the requested 3D-Models if found.\n");
    153   Group* walker = this->firstGroup;
     229  ModelGroup* walker = this->firstGroup;
    154230  int counter = 0;
    155231  while (walker != NULL)
     
    178254{
    179255  PRINTF(4)("drawing the requested 3D-Models if found.\n");
    180   Group* walker = this->firstGroup;
     256  ModelGroup* walker = this->firstGroup;
    181257  while (walker != NULL)
    182258    {
     
    210286void Model::setName(const char* name)
    211287{
    212   if (this->name) 
     288  if (this->name)
    213289    delete []this->name;
    214290  if (name)
     
    219295  else
    220296    this->name = NULL;
    221 }
    222 
    223 /**
    224    \brief initializes a new Group model
    225    \param group the group that should be initialized.
    226    \todo Maybe Group should be a Class, because it does a lot of stuff
    227    
    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 initialize
    245 */
    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;
    257297}
    258298
     
    280320{
    281321  PRINTF(4)("cleaning up the 3D-Model to save Memory.\n");
    282   this->cleanupGroup(this->firstGroup);
     322  this->firstGroup->cleanup();
    283323  return true;
    284324}
    285325
    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 }
     326
    337327
    338328//////////
     
    395385
    396386   This function initializes a new Group.
    397    With it you should be able to import .obj-files with more than one Models inside.
     387   With it you should be able to create Models with more than one SubModel inside
    398388*/
    399389bool Model::addGroup (const char* groupString)
    400390{
    401391  PRINTF(5)("Read Group: %s.\n", groupString);
    402   if (this->groupCount != 0 && this->currentGroup->faceCount>0)
     392  if (this->groupCount != 0 && this->currentGroup->faceCount > 0)
    403393    {
    404394      //      finalizeGroup(currentGroup);
    405       this->currentGroup = this->currentGroup->next = new Group;
    406       this->initGroup(this->currentGroup);
     395      this->currentGroup = this->currentGroup->next = new ModelGroup;
    407396    }
    408397  // setting the group name if not default.
     
    518507{
    519508  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;
     509    this->currentGroup->currentFace = this->currentGroup->currentFace->next = new ModelFace;
     510
     511  ModelFaceElement* tmpElem = this->currentGroup->currentFace->firstElem = new ModelFaceElement;
    524512  tmpElem->next = NULL;
    525513  while(strcmp (faceString, "\0"))
    526514    {
    527515      if (this->currentGroup->currentFace->vertexCount>0)
    528           tmpElem = tmpElem->next = new FaceElement;
     516          tmpElem = tmpElem->next = new ModelFaceElement;
    529517      tmpElem->next = NULL;
    530518
     
    579567bool Model::addFace(int faceElemCount, VERTEX_FORMAT type, ...)
    580568{
    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;
     569  if (this->currentGroup->faceCount > 0)
     570    this->currentGroup->currentFace = this->currentGroup->currentFace->next = new ModelFace;
     571 
     572  ModelFaceElement* tmpElem = this->currentGroup->currentFace->firstElem = new ModelFaceElement;
    586573  tmpElem->next = NULL;
    587574 
     
    592579    {
    593580      if (this->currentGroup->currentFace->vertexCount>0)
    594           tmpElem = tmpElem->next = new FaceElement;
     581        tmpElem = tmpElem->next = new ModelFaceElement;
    595582      tmpElem->next = NULL;
    596583
     
    614601{
    615602  if (this->currentGroup->faceCount > 0)
    616     this->currentGroup->currentFace = this->currentGroup->currentFace->next = new Face;
    617   this->initFace (this->currentGroup->currentFace);
     603    this->currentGroup->currentFace = this->currentGroup->currentFace->next = new ModelFace;
    618604 
    619605  this->currentGroup->currentFace->material = this->findMaterialByName(matString);
     
    630616{
    631617  if (this->currentGroup->faceCount > 0)
    632     this->currentGroup->currentFace = this->currentGroup->currentFace->next = new Face;
    633   this->initFace (this->currentGroup->currentFace);
     618    this->currentGroup->currentFace = this->currentGroup->currentFace->next = new ModelFace;
    634619 
    635620  this->currentGroup->currentFace->material = mtl;
     
    662647  Vector curV;
    663648
    664   Group* tmpGroup = firstGroup;
     649  ModelGroup* tmpGroup = firstGroup;
    665650  while (tmpGroup)
    666651    {
    667       Face* tmpFace = tmpGroup->firstFace;
     652      ModelFace* tmpFace = tmpGroup->firstFace;
    668653      while (tmpFace)
    669654        {
    670655          if (tmpFace->firstElem)
    671656            {
    672               FaceElement* firstElem = tmpFace->firstElem;
    673               FaceElement* prevElem;
    674               FaceElement* curElem = firstElem;
    675               FaceElement* nextElem;
    676               FaceElement* lastElem;
     657              ModelFaceElement* firstElem = tmpFace->firstElem;
     658              ModelFaceElement* prevElem;
     659              ModelFaceElement* curElem = firstElem;
     660              ModelFaceElement* nextElem;
     661              ModelFaceElement* lastElem;
    677662              // 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.
    678663              while (curElem)
     
    744729
    745730      // Putting Faces to GL
    746       Face* tmpFace = this->currentGroup->firstFace;
     731      ModelFace* tmpFace = this->currentGroup->firstFace;
    747732      while (tmpFace != NULL)
    748733        {
     
    794779            }
    795780         
    796           FaceElement* tmpElem = tmpFace->firstElem;
     781          ModelFaceElement* tmpElem = tmpFace->firstElem;
    797782          while (tmpElem != NULL)
    798783            {
     
    841826   merging this information, the face will be drawn.
    842827*/
    843 bool Model::addGLElement (FaceElement* elem)
     828bool Model::addGLElement (ModelFaceElement* elem)
    844829{
    845830  PRINTF(5)("importing grafical Element to openGL.\n");
Note: See TracChangeset for help on using the changeset viewer.