Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3195 in orxonox.OLD for orxonox/trunk/importer/material.cc


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

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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);
Note: See TracChangeset for help on using the changeset viewer.