Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/world_entities/skybox.cc @ 3803

Last change on this file since 3803 was 3803, checked in by bensch, 20 years ago

orxonox/trunk: SkyBox even better,

world-entity implements a draw function of its own

some other minor stuff

File size: 6.3 KB
Line 
1
2/*
3   orxonox - the future of 3D-vertical-scrollers
4
5   Copyright (C) 2004 orx
6
7   This program is free software; you can redistribute it and/or modify
8   it under the terms of the GNU General Public License as published by
9   the Free Software Foundation; either version 2, or (at your option)
10   any later version.
11
12   ### File Specific:
13   main-programmer: David Gruetter
14   co-programmer: Benjamin Grauer
15   
16   Created by Dave: this file is actually quite similar to player.cc and so is
17   skybox.h similar to player.h
18   With that said, things should be clear:)
19   
20   Edited:
21   Bensch: more constructors, changeability, comments...
22   Patrick: giving it the common orxonox style, not much to do... good work Dave!
23
24*/
25
26#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY
27
28
29#include "skybox.h"
30#include "stdincl.h"
31
32#include "material.h"
33#include "vector.h"
34#include "resource_manager.h"
35#include "model.h"
36//#include "world_entity.h"
37
38
39using namespace std;
40
41/**
42   \brief Constructs a SkyBox and takes fileName as a map.
43   \param fileName the file to take as input for the SkyBox
44*/
45SkyBox::SkyBox(char* fileName)
46{
47  this->setClassName("SkyBox");
48  this->material = new Material*[6];
49  for (int i = 0; i <6; i++) 
50    {
51      this->material[i] = new Material();
52      this->material[i]->setIllum(3);
53      this->material[i]->setAmbient(1.0, 1.0, 1.0);
54    }
55  this->setMode(PNODE_MOVEMENT);
56
57
58
59  this->setSize(1900.0);
60  this->rebuild();
61}
62
63
64/**
65   \brief default destructor
66*/
67SkyBox::~SkyBox()
68{
69  PRINTF(5)("Deleting the SkyBox\n");
70 
71  for (int i = 0; i < 6; i++)
72    delete this->material[i];
73  delete []this->material;
74}
75
76/**
77   \brief sets A set of textures when just giving a Name and an extension:
78
79   usage: give this function an argument like
80   setTexture("skybox", "jpg");
81   and it will convert this to
82   setTextures("skybox_top.jpg", "skybox_bottom.jpg", "skybox_left.jpg",
83               "skybox_right.jpg", "skybox_front.jpg", "skybox_back.jpg");
84*/
85void SkyBox::setTexture(const char* name, const char* extension)
86{
87  char* top    = new char[strlen(name)+strlen(extension)+ 6];
88  char* bottom = new char[strlen(name)+strlen(extension)+ 9];
89  char* left   = new char[strlen(name)+strlen(extension)+ 7];
90  char* right  = new char[strlen(name)+strlen(extension)+ 8];
91  char* front  = new char[strlen(name)+strlen(extension)+ 8];
92  char* back   = new char[strlen(name)+strlen(extension)+ 7];
93
94  sprintf(top, "%s_top.%s", name, extension);
95  sprintf(bottom, "%s_bottom.%s", name, extension);
96  sprintf(left, "%s_left.%s", name, extension);
97  sprintf(right, "%s_right.%s", name, extension);
98  sprintf(front, "%s_front.%s", name, extension);
99  sprintf(back, "%s_back.%s", name, extension);
100 
101  this->setTextures(top, bottom, left, right, front, back);
102
103  delete []top;
104  delete []bottom;
105  delete []left;
106  delete []right;
107  delete []front;
108  delete []back;
109}
110
111/**
112   \brief Defines which textures should be loaded onto the SkyBox.
113   \param top the top texture.
114   \param bottom the bottom texture.
115   \param left the left texture.
116   \param right the right texture.
117   \param front the front texture.
118   \param back the back texture.
119*/
120void SkyBox::setTextures(const char* top, const char* bottom, const char* left, const char* right, const char* front, const char* back)
121{
122  this->material[0]->setDiffuseMap(top);
123  this->material[1]->setDiffuseMap(bottom);
124  this->material[2]->setDiffuseMap(left);
125  this->material[3]->setDiffuseMap(right);
126  this->material[4]->setDiffuseMap(front);
127  this->material[5]->setDiffuseMap(back);
128}
129
130/**
131   \brief sets the Radius of the Sphere.
132   \param radius The Radius of The Sphere
133*/
134void SkyBox::setSize(float size)
135{
136  this->size = size;
137}
138
139/**
140   \brief rebuilds the SkyBox
141   
142   this must be done, when changing the Size of the Skybox (runtime-efficency)
143*/
144void SkyBox::rebuild()
145{
146  if (this->model)
147    delete model;
148  model = new Model();
149
150  model->addVertex (-0.5*size, -0.5*size, 0.5*size);
151  model->addVertex (0.5*size, -0.5*size, 0.5*size);
152  model->addVertex (-0.5*size, 0.5*size, 0.5*size);
153  model->addVertex (0.5*size, 0.5*size, 0.5*size);
154  model->addVertex (-0.5*size, 0.5*size, -0.5*size);
155  model->addVertex (0.5*size, 0.5*size, -0.5*size);
156  model->addVertex (-0.5*size, -0.5*size, -0.5*size);
157  model->addVertex (0.5*size, -0.5*size, -0.5*size);
158
159  model->addVertexTexture (0.0, 0.0);
160  model->addVertexTexture (1.0, 0.0);
161  model->addVertexTexture (0.0, 1.0);
162  model->addVertexTexture (1.0, 1.0);
163  model->addVertexTexture (0.0, 2.0);
164  model->addVertexTexture (1.0, 2.0);
165  model->addVertexTexture (0.0, 3.0);
166  model->addVertexTexture (1.0, 3.0);
167  model->addVertexTexture (0.0, 4.0);
168  model->addVertexTexture (1.0, 4.0);
169  model->addVertexTexture (2.0, 0.0);
170  model->addVertexTexture (2.0, 1.0);
171  model->addVertexTexture (-1.0, 0.0);
172  model->addVertexTexture (-1.0, 1.0);
173
174  model->addVertexNormal (0.0, 0.0, 1.0);
175  model->addVertexNormal (0.0, 0.0, 1.0);
176  model->addVertexNormal (0.0, 0.0, 1.0);
177  model->addVertexNormal (0.0, 0.0, 1.0);
178  model->addVertexNormal (0.0, 1.0, 0.0);
179  model->addVertexNormal (0.0, 1.0, 0.0);
180  model->addVertexNormal (0.0, 1.0, 0.0);
181  model->addVertexNormal (0.0, 1.0, 0.0);
182  model->addVertexNormal (0.0, 0.0, -1.0);
183  model->addVertexNormal (0.0, 0.0, -1.0);
184  model->addVertexNormal (0.0, 0.0, -1.0);
185  model->addVertexNormal (0.0, 0.0, -1.0);
186  model->addVertexNormal (0.0, -1.0, 0.0);
187  model->addVertexNormal (0.0, -1.0, 0.0);
188  model->addVertexNormal (0.0, -1.0, 0.0);
189  model->addVertexNormal (0.0, -1.0, 0.0);
190  model->addVertexNormal (1.0, 0.0, 0.0);
191  model->addVertexNormal (1.0, 0.0, 0.0);
192  model->addVertexNormal (1.0, 0.0, 0.0);
193  model->addVertexNormal (1.0, 0.0, 0.0);
194  model->addVertexNormal (-1.0, 0.0, 0.0);
195  model->addVertexNormal (-1.0, 0.0, 0.0);
196  model->addVertexNormal (-1.0, 0.0, 0.0);
197  model->addVertexNormal (-1.0, 0.0, 0.0);
198
199  model->addUseMtl(material[0]);
200  model->addFace (4, 3, 1,1,1, 2,2,2, 4,4,3, 3,3,4);
201  model->addUseMtl(material[1]);
202  model->addFace (4, 3, 3,3,5, 4,4,6, 6,6,7, 5,5,8);
203  model->addUseMtl(material[2]);
204  model->addFace (4, 3, 5,5,9, 6,6,10, 8,8,11, 7,7,12);
205  model->addUseMtl(material[3]);
206  model->addFace (4, 3, 7,7,13, 8,8,14, 2,10,15, 1,9,16);
207  model->addUseMtl(material[4]);
208  model->addFace (4, 3, 2,2,17, 8,11,18, 6,12,19, 4,4,20);
209  model->addUseMtl(material[5]);
210  model->addFace (4, 3, 7,13,21, 1,1,22, 3,3,23, 5,14,24);
211 
212  model->finalize();
213}
Note: See TracBrowser for help on using the repository browser.