- Timestamp:
- Jan 9, 2006, 11:53:53 PM (19 years ago)
- Location:
- trunk/src
- Files:
-
- 2 added
- 1 deleted
- 4 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/Makefile.am
r6432 r6455 16 16 lib/gui/gtk_gui/libORXgui.a \ 17 17 lib/graphics/importer/libORXimporter.a \ 18 lib/graphics/importer/libtc.a \ 18 19 lib/graphics/libORXgraphics.a \ 19 20 lib/sound/libORXsound.a \ … … 36 37 lib/gui/gtk_gui/libORXgui.a \ 37 38 lib/graphics/importer/libORXimporter.a \ 39 lib/graphics/importer/libtc.a \ 38 40 lib/graphics/libORXgraphics.a \ 39 41 lib/sound/libORXsound.a \ -
trunk/src/defs/class_id.h
r6437 r6455 164 164 CL_SKYSPHERE = 0x00000206, 165 165 CL_TERRAIN = 0x00000207, 166 CL_WATER = 0x00000208, 167 166 168 CL_TEST_ENTITY = 0x00000209, 167 169 CL_SPACE_SHIP = 0x0000020a, … … 227 229 CL_MD2Model = 0x00000809, 228 230 CL_HEIGHT_MAP = 0x0000080a, 231 CL_GRID = 0x0000080b, 232 229 233 CL_LIGHT = 0x00000811, 230 234 CL_PARTICLE_EMITTER = 0x00000812, -
trunk/src/lib/graphics/importer/Makefile.am
r6446 r6455 16 16 height_map.cc 17 17 18 libtc_a_SOURCES = tc.c 18 libtc_a_SOURCES = tc.cc 19 19 20 20 -
trunk/src/world_entities/Makefile.am
r6434 r6455 50 50 world_entities/creatures/md2_creature.cc \ 51 51 \ 52 world_entities/spawning_point.cc 52 world_entities/spawning_point.cc \ 53 \ 54 world_entities/environments/water.cc 53 55 54 56 WorldEntities_HEADERS_ = \ … … 96 98 world_entities/creatures/md2_creature.h \ 97 99 \ 98 world_entities/spawning_point.h 100 world_entities/spawning_point.h \ 101 \ 102 world_entities/environments/water.h -
trunk/src/world_entities/environments/water.cc
r6451 r6455 16 16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY 17 17 18 #include "skybox.h" 18 #include "water.h" 19 #include "factory.h" 20 #include "load_param.h" 19 21 20 #include "load_param.h" 21 #include "factory.h" 22 #include "static_model.h" 23 #include "material.h" 24 #include "network_game_manager.h" 25 #include "converter.h" 22 #include "grid.h" 26 23 27 24 using namespace std; 28 25 29 CREATE_FACTORY( SkyBox, CL_SKYBOX);26 CREATE_FACTORY(Water, CL_WATER); 30 27 31 /** 32 * Constructs a SkyBox and takes fileName as a map. 33 * @param fileName the file to take as input for the SkyBox 34 */ 35 SkyBox::SkyBox(const char* fileName) 28 29 Water::Water(const TiXmlElement* root) 36 30 { 37 this->preInit(); 38 if (fileName) 39 this->setTextureAndType(fileName, ".jpg"); 40 this->postInit(); 31 this->resX = this->resY = 10; 32 this->sizeX = this->sizeY = 1.0; 33 this->grid = NULL; 34 35 if (root != NULL) 36 this->loadParams(root); 41 37 } 42 38 43 /** 44 * initializes a skybox from a XmlElement 45 */ 46 SkyBox::SkyBox(const TiXmlElement* root) 39 Water::~Water() 47 40 { 48 this->preInit();49 41 50 this->loadParams(root);51 52 this->postInit();53 42 } 54 43 55 void SkyBox::loadParams(const TiXmlElement* root)44 void Water::loadParams(const TiXmlElement* root) 56 45 { 57 static_cast<WorldEntity*>(this)->loadParams(root);46 WorldEntity::loadParams(root); 58 47 59 LoadParam(root, "Materialset", this, SkyBox, setTexture) 60 .describe("Sets the material on the SkyBox. The string must be the path relative to the data-dir, and without a trailing .jpg"); 48 LoadParam(root, "size", this, Water, setSize) 49 .describe("the size of the WaterSurface") 50 .defaultValues(2, 1.0f, 1.0f); 61 51 62 LoadParam(root, "Size", this, SkyBox, setSize) 63 .describe("Sets the Size of the SkyBox (normally this should be 90% of the maximal viewing Distance)."); 52 LoadParam(root, "resolution", this, Water, setResolution) 53 .describe("sets the resolution of the water surface") 54 .defaultValues(2, 10, 10); 64 55 } 65 56 66 void SkyBox::preInit()57 void Water::rebuildGrid() 67 58 { 68 this->setClassID(CL_SKYBOX, "SkyBox");69 this->toList(OM_ENVIRON_NOTICK);70 this-> size = 100.0;59 if (this->grid != NULL) 60 delete this->grid; 61 this->grid = new Grid(this->sizeX, this->sizeY, this->resX, this->resY); 71 62 72 for (int i = 0; i < 6; i++)73 {74 this->material[i] = new Material();75 this->material[i]->setIllum(3);76 this->material[i]->setDiffuse(0.0,0.0,0.0);77 this->material[i]->setSpecular(0.0,0.0,0.0);78 this->material[i]->setAmbient(2.0, 2.0, 2.0);79 }80 this->setParentMode(PNODE_MOVEMENT);81 82 this->textureName = NULL;83 63 } 84 64 85 void SkyBox::postInit()65 void Water::setResolution(unsigned int resX, unsigned int resY) 86 66 { 87 this->rebuild(); 67 this->resX = resX; 68 this->resY = resY; 88 69 } 89 70 90 91 /** 92 * default destructor 93 */ 94 SkyBox::~SkyBox() 71 void Water::setSize(float sizeX, float sizeY) 95 72 { 96 PRINTF(5)("Deleting SkyBox\n"); 97 this->setModel(NULL); //< so that WorldEntity does not try to delete it again. 98 for (int i = 0; i < 6; i++) 99 delete this->material[i]; 73 this->sizeX = sizeX; 74 this->sizeY = sizeY; 100 75 } 101 76 102 /**103 * sets A set of textures when just giving a Name and an extension:104 105 usage: give this function an argument like106 setTexture("skybox", "jpg");107 and it will convert this to108 setTextures("skybox_top.jpg", "skybox_bottom.jpg", "skybox_left.jpg",109 "skybox_right.jpg", "skybox_front.jpg", "skybox_back.jpg");110 */111 void SkyBox::setTextureAndType(const char* name, const char* extension)112 {113 char* top = new char[strlen(name)+strlen(extension)+ 10];114 char* bottom = new char[strlen(name)+strlen(extension)+ 10];115 char* left = new char[strlen(name)+strlen(extension)+ 10];116 char* right = new char[strlen(name)+strlen(extension)+ 10];117 char* front = new char[strlen(name)+strlen(extension)+ 10];118 char* back = new char[strlen(name)+strlen(extension)+ 10];119 120 sprintf(top, "%s_top.%s", name, extension);121 sprintf(bottom, "%s_bottom.%s", name, extension);122 sprintf(left, "%s_left.%s", name, extension);123 sprintf(right, "%s_right.%s", name, extension);124 sprintf(front, "%s_front.%s", name, extension);125 sprintf(back, "%s_back.%s", name, extension);126 127 this->setTextures(top, bottom, left, right, front, back);128 129 // deleted alocated memory of this function130 delete []top;131 delete []bottom;132 delete []left;133 delete []right;134 delete []front;135 delete []back;136 }137 138 /**139 * Defines which textures should be loaded onto the SkyBox.140 * @param top the top texture.141 * @param bottom the bottom texture.142 * @param left the left texture.143 * @param right the right texture.144 * @param front the front texture.145 * @param back the back texture.146 */147 void SkyBox::setTextures(const char* top, const char* bottom, const char* left, const char* right, const char* front, const char* back)148 {149 this->material[0]->setDiffuseMap(top);150 this->material[1]->setDiffuseMap(bottom);151 this->material[2]->setDiffuseMap(left);152 this->material[3]->setDiffuseMap(right);153 this->material[4]->setDiffuseMap(front);154 this->material[5]->setDiffuseMap(back);155 }156 157 /**158 * @param size The new size of the SkyBox159 160 * do not forget to rebuild the SkyBox after this.161 */162 void SkyBox::setSize(float size)163 {164 this->size = size;165 }166 167 /**168 * rebuilds the SkyBox169 170 this must be done, when changing the Size of the Skybox (runtime-efficency)171 */172 void SkyBox::rebuild()173 {174 StaticModel* model = new StaticModel();175 176 model->addVertex (-0.5*size, -0.5*size, 0.5*size);177 model->addVertex (0.5*size, -0.5*size, 0.5*size);178 model->addVertex (-0.5*size, 0.5*size, 0.5*size);179 model->addVertex (0.5*size, 0.5*size, 0.5*size);180 model->addVertex (-0.5*size, 0.5*size, -0.5*size);181 model->addVertex (0.5*size, 0.5*size, -0.5*size);182 model->addVertex (-0.5*size, -0.5*size, -0.5*size);183 model->addVertex (0.5*size, -0.5*size, -0.5*size);184 185 model->addVertexTexture (0.0, 1.0);186 model->addVertexTexture (1.0, 1.0);187 model->addVertexTexture (1.0, 0.0);188 model->addVertexTexture (0.0, 0.0);189 190 model->addVertexNormal (0.0, 0.0, 1.0);191 model->addVertexNormal (0.0, 1.0, 0.0);192 model->addVertexNormal (0.0, 0.0, -1.0);193 model->addVertexNormal (0.0, -1.0, 0.0);194 model->addVertexNormal (1.0, 0.0, 0.0);195 model->addVertexNormal (-1.0, 0.0, 0.0);196 197 model->setMaterial(material[0]);198 model->addFace (4, VERTEX_TEXCOORD_NORMAL, 2,0,3, 3,1,3, 5,2,3, 4,3,3); // top199 model->setMaterial(material[1]);200 model->addFace (4, VERTEX_TEXCOORD_NORMAL, 6,0,1, 7,1,1, 1,2,1, 0,3,1); // bottom201 model->setMaterial(material[2]);202 model->addFace (4, VERTEX_TEXCOORD_NORMAL, 4,2,2, 5,3,2, 7,0,2, 6,1,2); // left203 model->setMaterial(material[3]);204 model->addFace (4, VERTEX_TEXCOORD_NORMAL, 0,0,0, 1,1,0, 3,2,0, 2,3,0); // right205 model->setMaterial(material[4]);206 model->addFace (4, VERTEX_TEXCOORD_NORMAL, 1,0,5, 7,1,5, 5,2,5, 3,3,5); // front207 model->setMaterial(material[5]);208 model->addFace (4, VERTEX_TEXCOORD_NORMAL, 6,0,4, 0,1,4, 2,2,4, 4,3,4); // back209 210 model->finalize();211 212 this->setModel(model);213 }214 215 int SkyBox::writeBytes( const byte * data, int length, int sender )216 {217 setRequestedSync( false );218 setIsOutOfSync( false );219 220 SYNCHELP_READ_BEGIN();221 222 SYNCHELP_READ_FKT( WorldEntity::writeState );223 224 SYNCHELP_READ_FLOAT( size );225 if ( textureName )226 {227 delete[] textureName;228 textureName = NULL;229 }230 SYNCHELP_READ_STRINGM( textureName );231 232 PRINT(0)("GOT DATA: size=%f texture='%s'\n", size, textureName);233 234 this->setSize( size );235 this->setTextureAndType( textureName, "jpg" );236 this->rebuild();237 238 return SYNCHELP_READ_N;239 }240 241 242 243 int SkyBox::readBytes( byte * data, int maxLength, int * reciever )244 {245 if ( isOutOfSync() && !requestedSync() && this->getHostID()!=this->getOwner() )246 {247 (NetworkGameManager::getInstance())->sync( this->getUniqueID(), this->getOwner() );248 setRequestedSync( true );249 }250 251 int rec = this->getRequestSync();252 if ( rec > 0 )253 {254 PRINT(0)("SEND DATA: size=%f texture='%s'\n", size, textureName);255 *reciever = rec;256 257 SYNCHELP_WRITE_BEGIN();258 259 SYNCHELP_WRITE_FKT( WorldEntity::readState );260 261 SYNCHELP_WRITE_FLOAT(this->size);262 SYNCHELP_WRITE_STRING(this->textureName);263 264 return SYNCHELP_WRITE_N;265 }266 267 *reciever = 0;268 return 0;269 }270 271 void SkyBox::writeDebug( ) const272 {273 }274 275 void SkyBox::readDebug( ) const276 {277 } -
trunk/src/world_entities/environments/water.h
r6451 r6455 1 1 /*! 2 * @file skybox.h2 * @file water.h 3 3 * Definition of the SkyBox, that handles the Display of an atmosphere for orxonox. 4 4 * … … 7 7 */ 8 8 9 #ifndef _ SKYBOX_H10 #define _ SKYBOX_H9 #ifndef _WATER_H 10 #define _WATER_H 11 11 12 12 /* INCLUDES */ … … 15 15 /* FORWARD DECLARATION */ 16 16 class Material; 17 class Grid; 17 18 18 //! A Class to handle a SkyBox19 class SkyBox: public WorldEntity19 //! A Class to handle a WaterEffects 20 class Water : public WorldEntity 20 21 { 21 22 public: 22 SkyBox(const char* fileName= NULL);23 SkyBox(const TiXmlElement* root);23 Water(const TiXmlElement* root = NULL); 24 ~Water(); 24 25 25 virtual ~SkyBox();26 void loadParams(const TiXmlElement* root); 26 27 27 void init(); 28 void preInit(); 28 void setResolution(unsigned int resX, unsigned int resY); 29 void setSize(float sizeX, float sizeY); 30 void rebuildGrid(); 29 31 30 void loadParams(const TiXmlElement* root); 32 private: 33 Grid* grid; //!< The water-surface-model to render with 31 34 32 void postInit(); 33 34 35 void setSize(float size); 36 /** assumes jpg as input-format */ 37 void setTexture(const char* name) { if (textureName) delete[] textureName; textureName = new char[strlen(name)+1]; strcpy(textureName, name); this->setTextureAndType (name, "jpg"); }; 38 39 void setTextureAndType(const char* name, const char* extension); 40 void setTextures(const char* top, const char* bottom, const char* left, 41 const char* right, const char* front, const char* back); 42 43 virtual int writeBytes(const byte* data, int length, int sender); 44 virtual int readBytes(byte* data, int maxLength, int * reciever); 45 virtual void writeDebug() const; 46 virtual void readDebug() const; 47 48 private: 49 void rebuild(); 50 51 Material* material[6]; //!< Materials for the SkyBox. sorted by number (0-5) top, bottom, left, right, front, back 52 float size; //!< Size of the SkyBox. This should match the frustum maximum range. 53 char* textureName; //!< Name of the Texture 54 35 unsigned int resX, resY; 36 float sizeX, sizeY; 55 37 }; 56 38 57 #endif /* _ SKYBOX_H */39 #endif /* _WATER_H */ 58 40 59 41
Note: See TracChangeset
for help on using the changeset viewer.