Changeset 4194 in orxonox.OLD for orxonox/branches/openAL/src/world_entities/skybox.cc
- Timestamp:
- May 16, 2005, 1:33:19 PM (20 years ago)
- 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
-
- Property svn:externals
-
orxonox/branches/openAL/src/world_entities/skybox.cc
r3913 r4194 28 28 29 29 #include "skybox.h" 30 30 31 #include "stdincl.h" 32 #include "factory.h" 31 33 32 34 #include "material.h" … … 36 38 //#include "world_entity.h" 37 39 40 CREATE_FACTORY(SkyBox); 38 41 39 42 using namespace std; … … 45 48 SkyBox::SkyBox(char* fileName) 46 49 { 50 this->preInit(); 51 this->postInit(); 52 } 53 54 SkyBox::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 75 void SkyBox::preInit(void) 76 { 47 77 this->setClassName("SkyBox"); 78 this->skyModel = NULL; 48 79 this->material = new Material*[6]; 49 for (int i = 0; i < 6; i++)80 for (int i = 0; i < 6; i++) 50 81 { 51 82 this->material[i] = new Material(); … … 56 87 } 57 88 this->setMode(PNODE_MOVEMENT); 58 89 } 90 91 void SkyBox::postInit(void) 92 { 59 93 this->setSize(1900.0); 94 this->rebuild(); 60 95 } 61 96 … … 66 101 SkyBox::~SkyBox() 67 102 { 68 PRINTF(5)("Deleting the SkyBox\n"); 69 103 PRINTF(5)("Deleting SkyBox\n"); 70 104 for (int i = 0; i < 6; i++) 71 105 delete this->material[i]; … … 84 118 void SkyBox::setTexture(const char* name, const char* extension) 85 119 { 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]; 92 126 93 127 sprintf(top, "%s_top.%s", name, extension); … … 100 134 this->setTextures(top, bottom, left, right, front, back); 101 135 136 // deleted alocated memory of this function 102 137 delete []top; 103 138 delete []bottom; … … 125 160 this->material[4]->setDiffuseMap(front); 126 161 this->material[5]->setDiffuseMap(back); 127 128 this->rebuild();129 162 } 130 163 … … 135 168 { 136 169 this->size = size; 137 138 this->rebuild();139 170 } 140 171 … … 149 180 glTranslatef(r.x, r.y, r.z); 150 181 151 this-> model->draw();182 this->skyModel->draw(); 152 183 153 184 glPopMatrix(); … … 162 193 void SkyBox::rebuild() 163 194 { 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); // top191 model->setMaterial(material[1]);192 model->addFace (4, VERTEX_TEXCOORD_NORMAL, 7,4,2, 8,1,2, 2,2,2, 1,3,2); // bottom193 model->setMaterial(material[2]);194 model->addFace (4, VERTEX_TEXCOORD_NORMAL, 1,1,3, 2,2,3, 4,3,3, 3,4,3); // left195 model->setMaterial(material[3]);196 model->addFace (4, VERTEX_TEXCOORD_NORMAL, 5,3,1, 6,4,1, 8,1,1, 7,2,1); // right197 model->setMaterial(material[4]);198 model->addFace (4, VERTEX_TEXCOORD_NORMAL, 2,1,6, 8,2,6, 6,3,6, 4,4,6); // front199 model->setMaterial(material[5]);200 model->addFace (4, VERTEX_TEXCOORD_NORMAL, 7,1,5, 1,2,5, 3,3,5, 5,4,5); // back195 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 201 232 202 model->finalize();203 } 233 this->skyModel->finalize(); 234 }
Note: See TracChangeset
for help on using the changeset viewer.