Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7208 in orxonox.OLD for branches/std/src/world_entities/skybox.cc


Ignore:
Timestamp:
Mar 10, 2006, 1:56:40 AM (18 years ago)
Author:
bensch
Message:

orxonox/std: less evil

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/std/src/world_entities/skybox.cc

    r7193 r7208  
    3838 * @param fileName the file to take as input for the SkyBox
    3939*/
    40 SkyBox::SkyBox(const char* fileName)
     40SkyBox::SkyBox(const std::string& fileName)
    4141{
    4242  this->preInit();
    43   if (fileName)
     43  if (!fileName.empty())
    4444    this->setTextureAndType(fileName, ".jpg");
    4545  this->postInit();
     
    8989  this->setParentMode(PNODE_MOVEMENT);
    9090
    91   this->textureName = NULL;
     91  this->textureName = "";
    9292}
    9393
     
    106106  for (int i = 0; i < 6; i++)
    107107  {
    108     if( this->material[i])
     108    if (this->material[i])
    109109      delete this->material[i];
    110     if( this->cubeTexture[i])
     110    if (this->cubeTexture[i])
    111111      ResourceManager::getInstance()->unload(this->cubeTexture[i]);
    112112  }
    113113}
     114
     115void SkyBox::setTexture(const std::string& name)
     116{
     117  this->textureName = name;
     118  this->setTextureAndType (name, "jpg");
     119};
     120
    114121
    115122/**
     
    122129               "skybox_right.jpg", "skybox_front.jpg", "skybox_back.jpg");
    123130*/
    124 void SkyBox::setTextureAndType(const char* name, const char* extension)
    125 {
    126   char* top    = new char[strlen(name)+strlen(extension)+ 10];
    127   char* bottom = new char[strlen(name)+strlen(extension)+ 10];
    128   char* left   = new char[strlen(name)+strlen(extension)+ 10];
    129   char* right  = new char[strlen(name)+strlen(extension)+ 10];
    130   char* front  = new char[strlen(name)+strlen(extension)+ 10];
    131   char* back   = new char[strlen(name)+strlen(extension)+ 10];
    132 
    133   sprintf(top, "%s_top.%s", name, extension);
    134   sprintf(bottom, "%s_bottom.%s", name, extension);
    135   sprintf(left, "%s_left.%s", name, extension);
    136   sprintf(right, "%s_right.%s", name, extension);
    137   sprintf(front, "%s_front.%s", name, extension);
    138   sprintf(back, "%s_back.%s", name, extension);
     131void SkyBox::setTextureAndType(const std::string& name, const std::string& extension)
     132{
     133  std::string top = name + "_top." + extension;
     134  std::string bottom = name + "_bottom." + extension;
     135  std::string left = name + "_left." + extension;
     136  std::string right = name + "_right." + extension;
     137  std::string front = name + "_front." + extension;
     138  std::string back = name + "_back." + extension;
    139139
    140140  this->setTextures(top, bottom, left, right, front, back);
    141 
    142   // deleted alocated memory of this function
    143   delete []top;
    144   delete []bottom;
    145   delete []left;
    146   delete []right;
    147   delete []front;
    148   delete []back;
    149141}
    150142
     
    158150 * @param back the back texture.
    159151*/
    160 void SkyBox::setTextures(const char* top, const char* bottom, const char* left,
    161                           const char* right, const char* front, const char* back)
     152void SkyBox::setTextures(const std::string& top, const std::string& bottom, const std::string& left,
     153                          const std::string& right, const std::string& front, const std::string& back)
    162154{
    163155  this->material[0]->setDiffuseMap(top);
     
    171163}
    172164
    173 void SkyBox::loadCubeMapTextures(const char* top, const char* bottom, const char* left,
    174                                   const char* right, const char* front, const char* back)
     165void SkyBox::loadCubeMapTextures(const std::string& top, const std::string& bottom, const std::string& left,
     166                                  const std::string& right, const std::string& front, const std::string& back)
    175167{
    176168  this->cubeTexture[0] = (Texture*)ResourceManager::getInstance()->load(top, RP_LEVEL, IMAGE, GL_TEXTURE_CUBE_MAP_POSITIVE_Y_EXT);
     
    304296
    305297  SYNCHELP_READ_FLOAT( size, NWT_SB_SIZE );
    306   if ( textureName )
     298  if ( !this->textureName.empty() )
    307299  {
    308     delete[] textureName;
    309     textureName = NULL;
     300    textureName = "";
    310301  }
    311   SYNCHELP_READ_STRINGM( textureName, NWT_SB_TEXTURENAME );
     302  char* texName;
     303  SYNCHELP_READ_STRINGM( texName, NWT_SB_TEXTURENAME );
    312304
    313305  this->setSize( size );
    314   this->setTextureAndType( textureName, "jpg" );
     306  this->setTextureAndType( texName, "jpg" );
    315307  this->rebuild();
    316308
     
    338330
    339331    SYNCHELP_WRITE_FLOAT(this->size, NWT_SB_SIZE);
    340     SYNCHELP_WRITE_STRING(this->textureName, NWT_SB_TEXTURENAME);
     332    SYNCHELP_WRITE_STRING(this->textureName.c_str(), NWT_SB_TEXTURENAME);
    341333
    342334    return SYNCHELP_WRITE_N;
Note: See TracChangeset for help on using the changeset viewer.