Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3801 in orxonox.OLD for orxonox/trunk/src


Ignore:
Timestamp:
Apr 13, 2005, 6:54:35 PM (20 years ago)
Author:
bensch
Message:

orxonox/trunk: some more functionality to material
now it is possible to add an external Material, and it handles pointers instead of char-arrays

Location:
orxonox/trunk/src
Files:
5 edited

Legend:

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

    r3750 r3801  
    236236  face->firstElem = NULL;
    237237 
    238   face->materialString = NULL;
     238  face->material = NULL;
    239239 
    240240  face->next = NULL;
     
    288288  PRINTF(5)("Cleaning up Face\n");
    289289
    290   if (face->materialString != NULL)
    291       delete []face->materialString;
    292290  if (face->firstElem != NULL)
    293291    {
     
    549547    }
    550548  */     
    551   if (this->currentGroup->faceCount >0)
     549  if (this->currentGroup->faceCount > 0)
    552550    this->currentGroup->currentFace = this->currentGroup->currentFace->next = new Face;
    553551  this->initFace (this->currentGroup->currentFace);
    554552 
    555   this->currentGroup->currentFace->materialString = new char[strlen(matString)+1];
    556   strcpy (this->currentGroup->currentFace->materialString, matString);
    557  
     553  this->currentGroup->currentFace->material = material->search(matString);
     554
    558555  if (this->currentGroup->faceCount == 0)
    559556    this->currentGroup->faceCount ++;
    560 
     557}
     558
     559/**
     560   \brief Function that selects a material, if changed in the obj file.
     561   \param mtl the Material that will be set.
     562*/
     563bool Model::addUseMtl (Material* mtl)
     564{
     565  if (this->currentGroup->faceCount > 0)
     566    this->currentGroup->currentFace = this->currentGroup->currentFace->next = new Face;
     567  this->initFace (this->currentGroup->currentFace);
     568 
     569  this->currentGroup->currentFace->material = mtl;
     570
     571  if (this->currentGroup->faceCount == 0)
     572    this->currentGroup->faceCount ++;
    561573}
    562574
     
    591603      while (tmpFace != NULL)
    592604        {
    593           if (tmpFace->vertexCount == 0 && tmpFace->materialString != NULL)
     605          if (tmpFace->vertexCount == 0 && tmpFace->material != NULL)
    594606            {
    595607              if (this->currentGroup->faceMode != -1)
     
    597609              this->currentGroup->faceMode = 0;
    598610              Material* tmpMat;
    599               if ((tmpMat = material->search(tmpFace->materialString)) != NULL)
     611              if (tmpFace->material != NULL)
    600612                {
    601                   tmpMat->select();
    602                   PRINTF(5)("using material %s for coming Faces.\n", tmpFace->materialString);
     613                  tmpFace->material->select();
     614                  PRINTF(5)("using material %s for coming Faces.\n", tmpFace->material->getName());
    603615                }
    604               else
    605                 PRINTF(2)("material %s not found.\n", tmpFace->materialString);
    606 
    607 
    608616            }
    609617
  • orxonox/trunk/src/lib/graphics/importer/model.h

    r3657 r3801  
    5454    FaceElement* firstElem; //!< Points to the first Vertex (FaceElement) of this Face.
    5555
    56     char* materialString;   //!< The Name of the Material to which to Change.
     56    Material* material;     //!< The Material to use.
    5757
    5858    Face* next;             //!< Pointer to the next Face.
     
    106106  bool addVertexTexture(const float u, const float v);
    107107  bool addUseMtl(char* mtlString);
     108  bool addUseMtl(Material* mtl);
    108109  void finalize(void);
    109110
  • orxonox/trunk/src/story_entities/world.cc

    r3798 r3801  
    940940      this->simpleAnimation->tick(seconds);
    941941     
    942             testAnim->tick(seconds);
     942      //testAnim->tick(seconds);
    943943
    944944    }
  • orxonox/trunk/src/world_entities/skybox.cc

    r3796 r3801  
    4747  this->setClassName("SkyBox");
    4848
     49  this->model = NULL;
    4950
    50   this->model = (Model*)ResourceManager::getInstance()->load("cube", PRIM, RP_LEVEL);
    5151  this->setMode(PNODE_MOVEMENT);
    5252
    5353  this->setSize(1900.0);
     54  this->rebuild();
    5455
    55   this->material = new Material("Sky");
    56   if (fileName)
    57     this->setTexture(fileName);
    58   this->material->setIllum(3);
    59   this->material->setAmbient(1.0, 1.0, 1.0);
    60 
     56  this->material = new Material*[6];
     57  for (int i = 0; i <6; i++)
     58    {
     59      this->material[i] = new Material();
     60      this->material[i]->setIllum(3);
     61      this->material[i]->setAmbient(1.0, 1.0, 1.0);
     62    }
    6163}
    6264
     
    6769SkyBox::~SkyBox()
    6870{
    69   PRINTF(3)("Deleting the SkyBox\n");
    70   delete this->material;
     71  PRINTF(5)("Deleting the SkyBox\n");
     72 
     73  for (int i = 0; i < 6; i++)
     74    delete this->material[i];
     75  delete []this->material;
    7176}
    7277
     78
     79void SkyBox::rebuild()
     80{
     81  if (this->model)
     82    delete model;
     83  model = new Model();
     84
     85  model->addVertex (-0.5*size, -0.5*size, 0.5*size);
     86  model->addVertex (0.5*size, -0.5*size, 0.5*size);
     87  model->addVertex (-0.5*size, 0.5*size, 0.5*size);
     88  model->addVertex (0.5*size, 0.5*size, 0.5*size);
     89  model->addVertex (-0.5*size, 0.5*size, -0.5*size);
     90  model->addVertex (0.5*size, 0.5*size, -0.5*size);
     91  model->addVertex (-0.5*size, -0.5*size, -0.5*size);
     92  model->addVertex (0.5*size, -0.5*size, -0.5*size);
     93
     94  model->addVertexTexture (0.0, 0.0);
     95  model->addVertexTexture (1.0, 0.0);
     96  model->addVertexTexture (0.0, 1.0);
     97  model->addVertexTexture (1.0, 1.0);
     98  model->addVertexTexture (0.0, 2.0);
     99  model->addVertexTexture (1.0, 2.0);
     100  model->addVertexTexture (0.0, 3.0);
     101  model->addVertexTexture (1.0, 3.0);
     102  model->addVertexTexture (0.0, 4.0);
     103  model->addVertexTexture (1.0, 4.0);
     104  model->addVertexTexture (2.0, 0.0);
     105  model->addVertexTexture (2.0, 1.0);
     106  model->addVertexTexture (-1.0, 0.0);
     107  model->addVertexTexture (-1.0, 1.0);
     108
     109  model->addVertexNormal (0.0, 0.0, 1.0);
     110  model->addVertexNormal (0.0, 0.0, 1.0);
     111  model->addVertexNormal (0.0, 0.0, 1.0);
     112  model->addVertexNormal (0.0, 0.0, 1.0);
     113  model->addVertexNormal (0.0, 1.0, 0.0);
     114  model->addVertexNormal (0.0, 1.0, 0.0);
     115  model->addVertexNormal (0.0, 1.0, 0.0);
     116  model->addVertexNormal (0.0, 1.0, 0.0);
     117  model->addVertexNormal (0.0, 0.0, -1.0);
     118  model->addVertexNormal (0.0, 0.0, -1.0);
     119  model->addVertexNormal (0.0, 0.0, -1.0);
     120  model->addVertexNormal (0.0, 0.0, -1.0);
     121  model->addVertexNormal (0.0, -1.0, 0.0);
     122  model->addVertexNormal (0.0, -1.0, 0.0);
     123  model->addVertexNormal (0.0, -1.0, 0.0);
     124  model->addVertexNormal (0.0, -1.0, 0.0);
     125  model->addVertexNormal (1.0, 0.0, 0.0);
     126  model->addVertexNormal (1.0, 0.0, 0.0);
     127  model->addVertexNormal (1.0, 0.0, 0.0);
     128  model->addVertexNormal (1.0, 0.0, 0.0);
     129  model->addVertexNormal (-1.0, 0.0, 0.0);
     130  model->addVertexNormal (-1.0, 0.0, 0.0);
     131  model->addVertexNormal (-1.0, 0.0, 0.0);
     132  model->addVertexNormal (-1.0, 0.0, 0.0);
     133
     134  model->addUseMtl(material[0]);
     135  model->addFace (4, 3, 1,1,1, 2,2,2, 4,4,3, 3,3,4);
     136  model->addUseMtl(material[1]);
     137  model->addFace (4, 3, 3,3,5, 4,4,6, 6,6,7, 5,5,8);
     138  model->addUseMtl(material[2]);
     139  model->addFace (4, 3, 5,5,9, 6,6,10, 8,8,11, 7,7,12);
     140  model->addUseMtl(material[3]);
     141  model->addFace (4, 3, 7,7,13, 8,8,14, 2,10,15, 1,9,16);
     142  model->addUseMtl(material[4]);
     143  model->addFace (4, 3, 2,2,17, 8,11,18, 6,12,19, 4,4,20);
     144  model->addUseMtl(material[5]);
     145  model->addFace (4, 3, 7,13,21, 1,1,22, 3,3,23, 5,14,24);
     146}
    73147
    74148/**
     
    76150   \param fileName The filename of the Texture
    77151*/
    78 void SkyBox::setTexture(char* fileName)
     152void SkyBox::setTexture(char* top, char* bottom, char* left, char* right, char* front, char* back)
    79153{
    80   this->material->setDiffuseMap(fileName);
     154  this->material[0]->setDiffuseMap(top);
     155  this->material[1]->setDiffuseMap(bottom);
     156  this->material[2]->setDiffuseMap(left);
     157  this->material[3]->setDiffuseMap(right);
     158  this->material[4]->setDiffuseMap(front);
     159  this->material[5]->setDiffuseMap(back);
    81160}
    82161
     
    94173  glTranslatef(r.x, r.y, r.z);
    95174
    96   this->material->select();
     175  this->material[1]->select();
    97176
    98177  this->model->draw();
  • orxonox/trunk/src/world_entities/skybox.h

    r3796 r3801  
    2626
    2727  void setSize(float size);
    28   void setTexture(char* fileName);
     28  void setTexture(char* top, char* bottom, char* left, char* right, char* front, char* back);
    2929
    3030  virtual void draw();
    3131
    32  private:
    33   Material *material;    //!< A Material for the Skybox.
     32 private:
     33  void rebuild();
     34
     35  Material **material;    //!< A Material for the Skybox.
    3436  float size;       //!< Radius of the Skybox. This should match the frustum maximum range.
    3537   
Note: See TracChangeset for help on using the changeset viewer.