Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3195 in orxonox.OLD for orxonox/trunk


Ignore:
Timestamp:
Dec 17, 2004, 12:03:30 AM (20 years ago)
Author:
bensch
Message:

orxonox/trunk/importer: this→pointers implemented in classes object, material, array, pathlist

Location:
orxonox/trunk/importer
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/importer/array.cc

    r3188 r3195  
    2121Array::Array ()
    2222{
    23   initializeArray ();
     23  this->initializeArray ();
    2424}
    2525
     
    3232  if (verbose >= 2)
    3333    printf("deleting array\n");
    34   Entry* walker = firstEntry;
     34  Entry* walker = this->firstEntry;
    3535  Entry* previous;
    3636  while (walker)
     
    4141    }
    4242  if (finalized)
    43     delete []array;
     43    delete []this->array;
    4444}
    4545
     
    5252  if (verbose >= 2)
    5353    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 entry
     54  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
    5959  return;
    6060}
     
    6969    printf ("Finalizing array. Length: %i\n", entryCount); 
    7070  //  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++)
    7575    {
    76       array[i] = walker->value;
     76      this->array[i] = walker->value;
    7777      walker = walker->next;
    7878    }
    79   finalized = true;
     79  this->finalized = true;
    8080
    8181  return;
     
    8888void Array::addEntry (GLfloat entry)
    8989{
    90   if (!finalized)
     90  if (!this->finalized)
    9191    {
    9292      if (verbose >= 3)
    9393        printf ("adding new Entry to Array: %f\n", entry);
    9494     
    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;
    100100    }
    101101  else
     
    109109void Array::addEntry (GLfloat entry0, GLfloat entry1, GLfloat entry2)
    110110{
    111   addEntry (entry0);
    112   addEntry (entry1);
    113   addEntry (entry2);
     111  this->addEntry (entry0);
     112  this->addEntry (entry1);
     113  this->addEntry (entry2);
    114114}
    115115 
     
    120120GLfloat* Array::getArray ()
    121121{
    122   return array;
     122  return this->array;
    123123}
    124124
     
    128128int Array::getCount()
    129129{
    130   return entryCount;
     130  return this->entryCount;
    131131}
    132132
     
    136136void Array::debug ()
    137137{
    138   printf ("entryCount=%i, address=%p\n", entryCount, array);
     138  printf ("entryCount=%i, address=%p\n", this->entryCount, this->array);
    139139}
  • orxonox/trunk/importer/material.cc

    r3186 r3195  
    3636PathList::PathList()
    3737{
    38   pathName = NULL;
    39   next = NULL;
     38  this->pathName = NULL;
     39  this->next = NULL;
    4040}
    4141
     
    4848PathList::PathList(char* pName)
    4949{
    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;
    5353}
    5454
     
    6060PathList::~PathList()
    6161{
    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;
    6666}
    6767
     
    114114Material::Material()
    115115{
    116   init();
    117  
    118   setName ("");
     116  this->init();
     117 
     118  this->setName ("");
    119119}
    120120
     
    125125Material::Material (char* mtlName)
    126126{
    127   init();
    128  
    129   setName (mtlName);
     127  this->init();
     128 
     129  this->setName (mtlName);
    130130}
    131131
     
    136136{
    137137  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;
    145145}
    146146
     
    171171  if (verbose >= 3)
    172172    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;
    189189
    190190 
     
    227227  // setting diffuse color
    228228  //  glColor3f (diffuse[0], diffuse[1], diffuse[2]);
    229   glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse);
     229  glMaterialfv(GL_FRONT, GL_DIFFUSE, this->diffuse);
    230230
    231231  // setting ambient color
    232   glMaterialfv(GL_FRONT, GL_AMBIENT, ambient);
     232  glMaterialfv(GL_FRONT, GL_AMBIENT, this->ambient);
    233233
    234234  // setting up Sprecular
    235   glMaterialfv(GL_FRONT, GL_SPECULAR, specular);
     235  glMaterialfv(GL_FRONT, GL_SPECULAR, this->specular);
    236236
    237237  // setting up Shininess
    238   glMaterialf(GL_FRONT, GL_SHININESS, shininess);
     238  glMaterialf(GL_FRONT, GL_SHININESS, this->shininess);
    239239 
    240240  // setting illumination Model
    241   if (illumModel == 1)
     241  if (this->illumModel == 1) //! \todo make this work, if no vertex-normals are read.
    242242    glShadeModel(GL_FLAT);
    243   else if (illumModel >= 2)
     243  else if (this->illumModel >= 2)
    244244    glShadeModel(GL_SMOOTH);
    245245
    246   if (diffuseTextureSet)
    247     glBindTexture(GL_TEXTURE_2D, diffuseTexture);
     246  if (this->diffuseTextureSet)
     247    glBindTexture(GL_TEXTURE_2D, this->diffuseTexture);
    248248  else
    249249    glBindTexture(GL_TEXTURE_2D, 0);
     
    258258void Material::setName (char* mtlName)
    259259{
    260   name = new char [strlen(mtlName)+1];
    261   strcpy(name, mtlName);
     260  this->name = new char [strlen(mtlName)+1];
     261  strcpy(this->name, mtlName);
    262262  if (verbose >= 3)
    263     printf("setting Material Name to %s.\n", name);
     263    printf("setting Material Name to %s.\n", this->name);
    264264
    265265  //  printf ("adding new Material: %s, %p\n", this->getName(), this);
     
    271271char* Material::getName (void)
    272272{
    273   return name;
     273  return this->name;
    274274}
    275275
     
    281281{
    282282  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;
    285285  //  printf ("setting illumModel to: %i\n", illumModel);
    286286}
     
    290290*/void Material::setIllum (char* illum)
    291291{
    292   setIllum (atoi(illum));
     292  this->setIllum (atoi(illum));
    293293}
    294294
     
    302302{
    303303  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;
    309309
    310310}
     
    317317  float r,g,b;
    318318  sscanf (rgb, "%f %f %f", &r, &g, &b);
    319   setDiffuse (r, g, b);
     319  this->setDiffuse (r, g, b);
    320320}
    321321
     
    329329{
    330330  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;
    336336}
    337337/**
     
    343343  float r,g,b;
    344344  sscanf (rgb, "%f %f %f", &r, &g, &b);
    345   setAmbient (r, g, b);
     345  this->setAmbient (r, g, b);
    346346}
    347347
     
    355355{
    356356  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;
    362362 }
    363363/**
     
    369369  float r,g,b;
    370370  sscanf (rgb, "%f %f %f", &r, &g, &b);
    371   setSpecular (r, g, b);
     371  this->setSpecular (r, g, b);
    372372}
    373373
     
    378378void Material::setShininess (float shini)
    379379{
    380   shininess = shini;
     380  this->shininess = shini;
    381381}
    382382/**
     
    386386void Material::setShininess (char* shini)
    387387{
    388   setShininess (atof(shini));
     388  this->setShininess (atof(shini));
    389389}
    390390
     
    396396{
    397397  if (verbose >= 3)
    398     printf ("setting Transparency of Material %s to %f.\n", name, trans);
    399   transparency = trans;
     398    printf ("setting Transparency of Material %s to %f.\n", this->name, trans);
     399  this->transparency = trans;
    400400}
    401401/**
     
    405405void Material::setTransparency (char* trans)
    406406{
    407   setTransparency (atof(trans));
     407  this->setTransparency (atof(trans));
    408408}
    409409
     
    414414void Material::addTexturePath(char* pathName)
    415415{
    416   pathList->addPath (pathName);
     416  this->pathList->addPath (pathName);
    417417}
    418418
     
    464464
    465465  //  diffuseTextureSet = loadBMP(dMap, &diffuseTexture);
    466   diffuseTextureSet = loadImage(dMap, &diffuseTexture);
     466  this->diffuseTextureSet = this->loadImage(dMap, &this->diffuseTexture);
    467467
    468468}
     
    471471   \brief Sets the Materials Ambient Map
    472472   \param aMap the Name of the Image to Use
     473   \todo implement this
    473474*/
    474475void Material::setAmbientMap(char* aMap)
     
    481482   \brief Sets the Materials Specular Map
    482483   \param sMap the Name of the Image to Use
     484   \todo implement this
    483485*/
    484486void Material::setSpecularMap(char* sMap)
     
    491493   \brief Sets the Materials Bumpiness
    492494   \param bump the Name of the Image to Use
     495   \todo implemet this
    493496*/
    494497void Material::setBump(char* bump)
     
    544547            pImage->data[i+2] = temp;
    545548          }
    546       loadTexToGL (pImage, texture);
     549      this->loadTexToGL (pImage, texture);
    547550    }
    548551  else
     
    570573          if (verbose >=2)
    571574            printf ("Requested bmp-image. Trying to Import.\n");
    572           return loadBMP(imgNameWithPath, texture);
     575          return this->loadBMP(imgNameWithPath, texture);
    573576        }
    574577     
     
    577580          if (verbose >=2)
    578581            printf ("Requested jpeg-image. Trying to Import\n");
    579           return loadJPG(imgNameWithPath, texture);
     582          return this->loadJPG(imgNameWithPath, texture);
    580583        }
    581584      else if (!strncmp(imgNameWithPath+strlen(imgNameWithPath)-4, ".tga", 4))
     
    583586          if (verbose >=2)
    584587            printf ("Requested tga-image. Trying to Import\n");
    585           return loadTGA(imgNameWithPath, texture);
     588          return this->loadTGA(imgNameWithPath, texture);
    586589        }
    587590      else if (!strncmp(imgNameWithPath+strlen(imgNameWithPath)-4, ".png", 4))
     
    589592          if (verbose >=2)
    590593            printf ("Requested png-image. Trying to Import\n");
    591           return loadPNG(imgNameWithPath, texture);
     594          return this->loadPNG(imgNameWithPath, texture);
    592595        }
    593596      else
     
    704707      pImage->data[i+2] = temp;
    705708    }
    706   loadTexToGL (pImage, texture);
    707  
    708   return true;
     709  this->loadTexToGL (pImage, texture);
     710 
    709711
    710712  if (pImage)
     
    717719      free(pImage);
    718720    }
     721  return true;
    719722
    720723}
     
    802805    exit(0);
    803806 
    804   loadTexToGL (pImage, texture);
     807  this->loadTexToGL (pImage, texture);
    805808  if (pImage)
    806809    {
     
    947950    }
    948951 
    949   loadTexToGL (pImage, texture);
     952  this->loadTexToGL (pImage, texture);
    950953
    951954  return true;
     
    11301133  while(currentpixel < pixelcount);     // Loop while there are still pixels left
    11311134
    1132   loadTexToGL (pImage, texture);
     1135  this->loadTexToGL (pImage, texture);
    11331136
    11341137  return true;
     
    12651268    }
    12661269  */
    1267   loadTexToGL (pImage, texture); 
     1270  this->loadTexToGL (pImage, texture); 
    12681271 
    12691272  free(pImage->data);
  • orxonox/trunk/importer/object.cc

    r3190 r3195  
    2525{
    2626
    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();
    3434}
    3535
     
    4040Object::Object(char* fileName)
    4141{
    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();
    4949}
    5050
     
    5656Object::Object(char* fileName, float scaling)
    5757{
    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();
    6666}
    6767
     
    7575  if (verbose >= 2)
    7676    printf ("Deleting display Lists.\n");
    77   Group* walker = firstGroup;
     77  Group* walker = this->firstGroup;
    7878  while (walker != NULL)
    7979    {
     
    8484    }
    8585
    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;
    9292
    9393  if (verbose >=2)
    9494    printf("Deleting Materials.\n");
    95   if (material)
    96     delete material;
     95  if (this->material)
     96    delete this->material;
    9797}
    9898
     
    106106  if (verbose >=2)
    107107    printf("drawing the 3D-Objects\n");
    108   Group* walker = firstGroup;
     108  Group* walker = this->firstGroup;
    109109  while (walker != NULL)
    110110    {
     
    124124void Object::draw (int groupNumber) const
    125125{
    126   if (groupNumber >= groupCount)
     126  if (groupNumber >= this->groupCount)
    127127    {
    128128      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);
    130130      return;
    131131    }
    132132  if (verbose >=2)
    133133    printf("drawing the requested 3D-Objects if found.\n");
    134   Group* walker = firstGroup;
     134  Group* walker = this->firstGroup;
    135135  int counter = 0;
    136136  while (walker != NULL)
     
    147147    }
    148148  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);
    150150  return;
    151151
     
    162162  if (verbose >=2)
    163163    printf("drawing the requested 3D-Objects if found.\n");
    164   Group* walker = firstGroup;
     164  Group* walker = this->firstGroup;
    165165  while (walker != NULL)
    166166    {
     
    175175    }
    176176  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);
    178178  return;
    179179}
     
    184184int Object::getGroupCount (void) const
    185185{
    186   return groupCount;
     186  return this->groupCount;
    187187}
    188188
     
    199199
    200200  // 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;
    204204 
    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();
    215215
    216216  return true;
     
    233233
    234234  group->firstFace = new Face;
    235   initFace (group->firstFace);
     235  this->initFace (group->firstFace);
    236236  group->currentFace = group->firstFace;
    237237}
     
    263263    printf("cleaning up the 3D-Object to save Memory.\n");
    264264
    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);
    273273  return true;
    274274}
     
    306306  if (face->firstElem != NULL)
    307307    {
    308       cleanupFaceElement(face->firstElem);
     308      this->cleanupFaceElement(face->firstElem);
    309309      delete face->firstElem;
    310310    }
     
    312312  if (face->next != NULL)
    313313    {
    314       cleanupFace (face->next);
     314      this->cleanupFace (face->next);
    315315      delete face->next;
    316316    }
     
    327327  if (faceElem->next != NULL)
    328328    {
    329       cleanupFaceElement (faceElem->next);
     329      this->cleanupFaceElement (faceElem->next);
    330330      delete faceElem->next;
    331331    }
     
    357357      name = tmpName+1;
    358358    }
    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';
    362362  if (verbose >=2)
    363363    if (strlen(objPath)> 0)
     
    368368      printf("Resolved file %s.\n", name);
    369369 
    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);
    374374  this->readFromObjFile ();
    375375  return true;
     
    383383{
    384384  char* fileName = new char [strlen(objPath)+strlen(objFileName)+1];
    385   if (objFileName != NULL && !strcmp(objFileName, ""))
     385  if (this->objFileName != NULL && !strcmp(this->objFileName, ""))
    386386    return false;
    387   strcpy(fileName, objPath);
    388   strcat(fileName, objFileName);
     387  strcpy(fileName, this->objPath);
     388  strcat(fileName, this->objFileName);
    389389
    390390  ifstream* OBJ_FILE = new ifstream(fileName);
     
    394394        printf ("unable to open .OBJ file: %s\n Loading Box Object instead.\n", fileName);
    395395      BoxObject();
     396      OBJ_FILE->close();
    396397      delete []fileName;
    397       OBJ_FILE->close();
     398      delete OBJ_FILE;
    398399      return false;
    399400    }
     
    405406      OBJ_FILE->getline(Buffer, 10000);
    406407      if (verbose >=4)
    407         printf ("Read input line: %s\n",Buffer);
     408        printf ("Read input line: %s\n", Buffer);
    408409     
    409410
     
    411412      if (!strncmp(Buffer, "v ", 2))
    412413        {
    413           readVertex(Buffer+2);
     414          this->readVertex(Buffer+2);
    414415        }
    415416
     
    417418      else if (!strncmp(Buffer, "f ", 2))
    418419        {
    419           readFace (Buffer+2);
     420          this->readFace (Buffer+2);
    420421        }
    421422     
    422423      else if (!strncmp(Buffer, "mtllib ", 7))
    423424        {
    424           readMtlLib (Buffer+7);
     425          this->readMtlLib (Buffer+7);
    425426        }
    426427
    427428      else if (!strncmp(Buffer, "usemtl ", 7))
    428429        {
    429           readUseMtl (Buffer+7);
     430          this->readUseMtl (Buffer+7);
    430431        }
    431432
    432433      // case VertexNormal
    433434      else if (!strncmp(Buffer, "vn ", 3))
    434       {
    435         readVertexNormal(Buffer+3);
    436       }
    437 
     435        {
     436          this->readVertexNormal(Buffer+3);
     437        }
     438     
    438439      // case VertexTextureCoordinate
    439440      else if (!strncmp(Buffer, "vt ", 3))
    440       {
    441         readVertexTexture(Buffer+3);
    442       }
     441        {
     442          this->readVertexTexture(Buffer+3);
     443        }
    443444      // case group
    444445      else if (!strncmp(Buffer, "g ", 2))
    445446        {
    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
    449450        {
    450451          if (verbose >= 2)
     
    453454    }
    454455  OBJ_FILE->close();
     456  delete OBJ_FILE;
    455457  delete []fileName;
    456458  return true;
     
    469471  if (verbose >=3)
    470472    printf ("Read Group: %s.\n", groupString);
    471   if (groupCount != 0 && currentGroup->faceCount>0)
     473  if (this->groupCount != 0 && this->currentGroup->faceCount>0)
    472474    {
    473475      //      finalizeGroup(currentGroup);
    474       currentGroup = currentGroup->next = new Group;
    475       initGroup(currentGroup);
     476      this->currentGroup = this->currentGroup->next = new Group;
     477      this->initGroup(this->currentGroup);
    476478    }
    477479  // setting the group name if not default.
    478480  if (strcmp(groupString, "default"))
    479481    {
    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;
    484486
    485487}
     
    499501  if (verbose >= 3)
    500502    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);
    502504  return true;
    503505}
     
    512514bool Object::readFace (char* faceString)
    513515{
    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;
    519521  tmpElem->next = NULL;
    520522  while(strcmp (faceString, "\0"))
    521523    {
    522       if (currentGroup->currentFace->vertexCount>0)
     524      if (this->currentGroup->currentFace->vertexCount>0)
    523525          tmpElem = tmpElem->next = new FaceElement;
    524526      tmpElem->next = NULL;
     
    561563      if (strcmp (faceString, "\0"))
    562564        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;
    567569}
    568570
     
    581583  if (verbose >=3 )
    582584    printf("found vertex-Normal %f, %f, %f\n", &subbuffer1,&subbuffer2,&subbuffer3);
    583   normals->addEntry(subbuffer1, subbuffer2, subbuffer3);
     585  this->normals->addEntry(subbuffer1, subbuffer2, subbuffer3);
    584586  return true;
    585587}
     
    599601  if (verbose >=3 )
    600602    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);
    603605  return true;
    604606}
     
    615617bool Object::readMtlLib (char* mtlFile)
    616618{
    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);
    622624 
    623625
     
    630632      if (verbose >= 1)
    631633        printf ("unable to open file: %s\n", fileName);
     634      MTL_FILE->close();
    632635      delete []fileName;
    633       MTL_FILE->close();
     636      delete MTL_FILE;
    634637      return false;
    635638    }
     
    704707
    705708    }
     709  MTL_FILE->close();
    706710  delete []fileName;
     711  delete MTL_FILE;
    707712  return true;
    708713}
     
    714719bool Object::readUseMtl (char* matString)
    715720{
    716   if (!mtlFileName)
     721  if (!this->mtlFileName)
    717722    {
    718723      if (verbose >= 1)
     
    721726    }
    722727     
    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);
    726731 
    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);
    729734 
    730   if (currentGroup->faceCount == 0)
    731     currentGroup->faceCount ++;
     735  if (this->currentGroup->faceCount == 0)
     736    this->currentGroup->faceCount ++;
    732737
    733738}
     
    740745
    741746  // finalize the Arrays
    742   vertices->finalizeArray();
    743   vTexture->finalizeArray();
     747  this->vertices->finalizeArray();
     748  this->vTexture->finalizeArray();
    744749  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)
    751756    {
    752757
    753758      // creating a glList for the Group
    754       if ((currentGroup->listNumber = glGenLists(1)) == 0)
     759      if ((this->currentGroup->listNumber = glGenLists(1)) == 0)
    755760        {
    756761          printf ("list could not be created for this Object\n");
    757762          return false;
    758763        }
    759       glNewList (currentGroup->listNumber, GL_COMPILE);
     764      glNewList (this->currentGroup->listNumber, GL_COMPILE);
    760765
    761766      // Putting Faces to GL
    762       Face* tmpFace = currentGroup->firstFace;
     767      Face* tmpFace = this->currentGroup->firstFace;
    763768      while (tmpFace != NULL)
    764769        {
    765770          if (tmpFace->vertexCount == 0 && tmpFace->materialString != NULL)
    766771            {
    767               if (currentGroup->faceMode != -1)
     772              if (this->currentGroup->faceMode != -1)
    768773                glEnd();
    769               currentGroup->faceMode = 0;
     774              this->currentGroup->faceMode = 0;
    770775              if (verbose >= 2)
    771776                printf ("using material %s for coming Faces.\n", tmpFace->materialString);
     
    778783          else if (tmpFace->vertexCount == 3)
    779784            {
    780               if (currentGroup->faceMode != 3)
     785              if (this->currentGroup->faceMode != 3)
    781786                {
    782                   if (currentGroup->faceMode != -1)
     787                  if (this->currentGroup->faceMode != -1)
    783788                    glEnd();
    784789                  glBegin(GL_TRIANGLES);
    785790                }
    786791             
    787               currentGroup->faceMode = 3;
     792              this->currentGroup->faceMode = 3;
    788793              if (verbose >=3)
    789794                printf ("found triag.\n");
     
    792797          else if (tmpFace->vertexCount == 4)
    793798            {
    794               if (currentGroup->faceMode != 4)
     799              if (this->currentGroup->faceMode != 4)
    795800                {
    796                   if (currentGroup->faceMode != -1)
     801                  if (this->currentGroup->faceMode != -1)
    797802                    glEnd();
    798803                  glBegin(GL_QUADS);
    799804                }
    800               currentGroup->faceMode = 4;
     805              this->currentGroup->faceMode = 4;
    801806              if (verbose >=3 )
    802807                printf ("found quad.\n");
     
    805810          else if (tmpFace->vertexCount > 4)
    806811            {
    807               if (currentGroup->faceMode != -1)
     812              if (this->currentGroup->faceMode != -1)
    808813                glEnd();
    809814              glBegin(GL_POLYGON);
    810815              if (verbose >=3)
    811816                printf ("Polygon with %i faces found.", tmpFace->vertexCount);
    812               currentGroup->faceMode = tmpFace->vertexCount;
     817              this->currentGroup->faceMode = tmpFace->vertexCount;
    813818            }
    814819         
     
    817822            {
    818823              //      printf ("%s\n", tmpElem->value);
    819               addGLElement(tmpElem);
     824              this->addGLElement(tmpElem);
    820825              tmpElem = tmpElem->next;
    821826            }
     
    824829      glEnd();
    825830      glEndList();
    826       currentGroup = currentGroup->next;
     831
     832      this->currentGroup = this->currentGroup->next;
    827833    }
    828834}
     
    844850
    845851  if (elem->texCoordNumber != -1)
    846     glTexCoord2fv(vTexture->getArray() + elem->texCoordNumber * 2);
     852    glTexCoord2fv(this->vTexture->getArray() + elem->texCoordNumber * 2);
    847853  if (elem->normalNumber != -1)
    848     glNormal3fv(normals->getArray() + elem->normalNumber * 3);
     854    glNormal3fv(this->normals->getArray() + elem->normalNumber * 3);
    849855  if (elem->vertexNumber != -1)
    850     glVertex3fv(vertices->getArray() + elem->vertexNumber * 3);
     856    glVertex3fv(this->vertices->getArray() + elem->vertexNumber * 3);
    851857
    852858}
     
    925931        printf ("Found Normale number %d: (%f; %f, %f).\n", i, normArray[i].x, normArray[i].y, normArray[i].z);
    926932
    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);
    928934
    929935    }
     
    940946void Object::BoxObject(void)
    941947{
    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");
    990996
    991997  /* 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");
    9981004  */
    9991005
    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.