Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 16, 2005, 1:33:19 PM (20 years ago)
Author:
bensch
Message:

orxonox/branches/openAL: merged trunk back to openAL
merged with command:

svn merge ../trunk/ openAL/ -r 3920:HEAD

no conflicts at all

Location:
orxonox/branches/openAL
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/openAL

    • Property svn:externals
      •  

        old new  
        1 data http://svn.orxonox.ethz.ch/data
         1
  • orxonox/branches/openAL/src/world_entities/skybox.cc

    r3913 r4194  
    2828
    2929#include "skybox.h"
     30
    3031#include "stdincl.h"
     32#include "factory.h"
    3133
    3234#include "material.h"
     
    3638//#include "world_entity.h"
    3739
     40CREATE_FACTORY(SkyBox);
    3841
    3942using namespace std;
     
    4548SkyBox::SkyBox(char* fileName)
    4649{
     50  this->preInit();
     51  this->postInit();
     52}
     53
     54SkyBox::SkyBox(TiXmlElement* root) : WorldEntity(root)
     55{
     56  this->preInit();
     57
     58  const char* string;
     59
     60  // Model Loading     
     61  string = grabParameter( root, "materialset");
     62  if( string != NULL)
     63    this->setTexture(string, "jpg");
     64  else
     65    {
     66      PRINTF(0)("SkyBox is missing a proper 'MaterialSet'\n");
     67    }
     68  if( this->skyModel == NULL)
     69    {
     70      PRINTF(0)("SkyBox model '%s' could not be loaded\n", string);
     71    }
     72  this->postInit();
     73}
     74
     75void SkyBox::preInit(void)
     76{
    4777  this->setClassName("SkyBox");
     78  this->skyModel = NULL;
    4879  this->material = new Material*[6];
    49   for (int i = 0; i <6; i++)
     80  for (int i = 0; i < 6; i++)
    5081    {
    5182      this->material[i] = new Material();
     
    5687    }
    5788  this->setMode(PNODE_MOVEMENT);
    58 
     89}
     90
     91void SkyBox::postInit(void)
     92{
    5993  this->setSize(1900.0);
     94  this->rebuild();
    6095}
    6196
     
    66101SkyBox::~SkyBox()
    67102{
    68   PRINTF(5)("Deleting the SkyBox\n");
    69  
     103  PRINTF(5)("Deleting SkyBox\n");
    70104  for (int i = 0; i < 6; i++)
    71105    delete this->material[i];
     
    84118void SkyBox::setTexture(const char* name, const char* extension)
    85119{
    86   char* top    = new char[strlen(name)+strlen(extension)+ 6];
    87   char* bottom = new char[strlen(name)+strlen(extension)+ 9];
    88   char* left   = new char[strlen(name)+strlen(extension)+ 7];
    89   char* right  = new char[strlen(name)+strlen(extension)+ 8];
    90   char* front  = new char[strlen(name)+strlen(extension)+ 8];
    91   char* back   = new char[strlen(name)+strlen(extension)+ 7];
     120  char* top    = new char[strlen(name)+strlen(extension)+ 10];
     121  char* bottom = new char[strlen(name)+strlen(extension)+ 10];
     122  char* left   = new char[strlen(name)+strlen(extension)+ 10];
     123  char* right  = new char[strlen(name)+strlen(extension)+ 10];
     124  char* front  = new char[strlen(name)+strlen(extension)+ 10];
     125  char* back   = new char[strlen(name)+strlen(extension)+ 10];
    92126
    93127  sprintf(top, "%s_top.%s", name, extension);
     
    100134  this->setTextures(top, bottom, left, right, front, back);
    101135
     136  // deleted alocated memory of this function
    102137  delete []top;
    103138  delete []bottom;
     
    125160  this->material[4]->setDiffuseMap(front);
    126161  this->material[5]->setDiffuseMap(back);
    127 
    128   this->rebuild();
    129162}
    130163
     
    135168{
    136169  this->size = size;
    137 
    138   this->rebuild();
    139170}
    140171
     
    149180  glTranslatef(r.x, r.y, r.z);
    150181
    151   this->model->draw();
     182  this->skyModel->draw();
    152183
    153184  glPopMatrix();
     
    162193void SkyBox::rebuild()
    163194{
    164   if (this->model)
    165     delete model;
    166   model = new Model();
    167 
    168   model->addVertex (-0.5*size, -0.5*size, 0.5*size); 
    169   model->addVertex (0.5*size, -0.5*size, 0.5*size);
    170   model->addVertex (-0.5*size, 0.5*size, 0.5*size);
    171   model->addVertex (0.5*size, 0.5*size, 0.5*size);
    172   model->addVertex (-0.5*size, 0.5*size, -0.5*size);
    173   model->addVertex (0.5*size, 0.5*size, -0.5*size);
    174   model->addVertex (-0.5*size, -0.5*size, -0.5*size);
    175   model->addVertex (0.5*size, -0.5*size, -0.5*size);
    176 
    177   model->addVertexTexture (0.0, 0.0);
    178   model->addVertexTexture (1.0, 0.0);
    179   model->addVertexTexture (1.0, 1.0);
    180   model->addVertexTexture (0.0, 1.0);
    181 
    182   model->addVertexNormal (0.0, 0.0, 1.0);
    183   model->addVertexNormal (0.0, 1.0, 0.0);
    184   model->addVertexNormal (0.0, 0.0, -1.0);
    185   model->addVertexNormal (0.0, -1.0, 0.0);
    186   model->addVertexNormal (1.0, 0.0, 0.0);
    187   model->addVertexNormal (-1.0, 0.0, 0.0);
    188 
    189   model->setMaterial(material[0]);
    190   model->addFace (4, VERTEX_TEXCOORD_NORMAL, 3,2,4, 4,3,4, 6,4,4, 5,1,4); // top
    191   model->setMaterial(material[1]);
    192   model->addFace (4, VERTEX_TEXCOORD_NORMAL, 7,4,2, 8,1,2, 2,2,2, 1,3,2); // bottom
    193   model->setMaterial(material[2]);
    194   model->addFace (4, VERTEX_TEXCOORD_NORMAL, 1,1,3, 2,2,3, 4,3,3, 3,4,3); // left
    195   model->setMaterial(material[3]);
    196   model->addFace (4, VERTEX_TEXCOORD_NORMAL, 5,3,1, 6,4,1, 8,1,1, 7,2,1); // right
    197   model->setMaterial(material[4]);
    198   model->addFace (4, VERTEX_TEXCOORD_NORMAL, 2,1,6, 8,2,6, 6,3,6, 4,4,6); // front
    199   model->setMaterial(material[5]);
    200   model->addFace (4, VERTEX_TEXCOORD_NORMAL, 7,1,5, 1,2,5, 3,3,5, 5,4,5); // back
     195  if (this->skyModel)
     196    delete skyModel;
     197  skyModel = new Model();
     198
     199  this->skyModel->addVertex (-0.5*size, -0.5*size, 0.5*size); 
     200  this->skyModel->addVertex (0.5*size, -0.5*size, 0.5*size);
     201  this->skyModel->addVertex (-0.5*size, 0.5*size, 0.5*size);
     202  this->skyModel->addVertex (0.5*size, 0.5*size, 0.5*size);
     203  this->skyModel->addVertex (-0.5*size, 0.5*size, -0.5*size);
     204  this->skyModel->addVertex (0.5*size, 0.5*size, -0.5*size);
     205  this->skyModel->addVertex (-0.5*size, -0.5*size, -0.5*size);
     206  this->skyModel->addVertex (0.5*size, -0.5*size, -0.5*size);
     207
     208  this->skyModel->addVertexTexture (0.0, 0.0);
     209  this->skyModel->addVertexTexture (1.0, 0.0);
     210  this->skyModel->addVertexTexture (1.0, 1.0);
     211  this->skyModel->addVertexTexture (0.0, 1.0);
     212
     213  this->skyModel->addVertexNormal (0.0, 0.0, 1.0);
     214  this->skyModel->addVertexNormal (0.0, 1.0, 0.0);
     215  this->skyModel->addVertexNormal (0.0, 0.0, -1.0);
     216  this->skyModel->addVertexNormal (0.0, -1.0, 0.0);
     217  this->skyModel->addVertexNormal (1.0, 0.0, 0.0);
     218  this->skyModel->addVertexNormal (-1.0, 0.0, 0.0);
     219
     220  this->skyModel->setMaterial(material[0]);
     221  this->skyModel->addFace (4, VERTEX_TEXCOORD_NORMAL, 2,1,3, 3,2,3, 5,3,3, 4,0,3); // top
     222  this->skyModel->setMaterial(material[1]);
     223  this->skyModel->addFace (4, VERTEX_TEXCOORD_NORMAL, 6,3,1, 7,0,1, 1,1,1, 0,2,1); // bottom
     224  this->skyModel->setMaterial(material[2]);
     225  this->skyModel->addFace (4, VERTEX_TEXCOORD_NORMAL, 0,0,2, 1,1,2, 3,2,2, 2,3,2); // left
     226  this->skyModel->setMaterial(material[3]);
     227  this->skyModel->addFace (4, VERTEX_TEXCOORD_NORMAL, 4,2,0, 5,3,0, 7,0,0, 6,1,0); // right
     228  this->skyModel->setMaterial(material[4]);
     229  this->skyModel->addFace (4, VERTEX_TEXCOORD_NORMAL, 1,0,5, 7,1,5, 5,2,5, 3,3,6); // front
     230  this->skyModel->setMaterial(material[5]);
     231  this->skyModel->addFace (4, VERTEX_TEXCOORD_NORMAL, 6,0,4, 0,1,4, 2,2,4, 4,3,4); // back
    201232 
    202   model->finalize();
    203 }
     233  this->skyModel->finalize();
     234}
Note: See TracChangeset for help on using the changeset viewer.