Changeset 9869 in orxonox.OLD for trunk/src/lib/graphics
- Timestamp:
- Oct 3, 2006, 12:19:30 AM (18 years ago)
- Location:
- trunk/src/lib/graphics
- Files:
-
- 1 deleted
- 59 edited
- 16 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/graphics/Makefile.am
r9006 r9869 6 6 libORXgraphics_a_SOURCES = \ 7 7 graphics_engine.cc \ 8 graphics_effect.cc \ 8 9 light.cc \ 9 10 shader.cc \ 11 shader_data.cc \ 12 resource_shader.cc \ 10 13 \ 11 14 render2D/render_2d.cc \ … … 19 22 text_engine/font.cc \ 20 23 text_engine/font_data.cc \ 21 \ 22 effects/graphics_effect.cc \ 23 effects/atmospheric_engine.cc \ 24 effects/weather_effect.cc \ 25 effects/sun_effect.cc \ 26 effects/fog_effect.cc \ 27 effects/volfog_effect.cc \ 28 effects/rain_effect.cc \ 29 effects/snow_effect.cc \ 30 effects/cloud_effect.cc \ 31 effects/lightning_effect.cc \ 32 effects/lense_flare.cc 24 text_engine/resource_font.cc 33 25 34 26 noinst_HEADERS =\ 35 27 graphics_engine.h \ 28 graphics_effect.h \ 36 29 light.h \ 37 30 shader.h \ 31 shader_data.h \ 32 resource_shader.h \ 38 33 \ 39 34 render2D/render_2d.h \ … … 47 42 text_engine/font.h \ 48 43 text_engine/font_data.h \ 49 text_engine/default_font.xpm \ 50 \ 51 effects/graphics_effect.h \ 52 effects/atmospheric_engine.h \ 53 effects/weather_effect.h \ 54 effects/sun_effect.h \ 55 effects/fog_effect.h \ 56 effects/volfog_effect.h \ 57 effects/rain_effect.h \ 58 effects/snow_effect.h \ 59 effects/cloud_effect.h \ 60 effects/lightning_effect.h \ 61 effects/lense_flare.h 44 text_engine/resource_font.h \ 45 text_engine/default_font.xpm 62 46 63 47 -
trunk/src/lib/graphics/graphics_engine.cc
r9406 r9869 17 17 18 18 #include "graphics_engine.h" 19 #include "util/loading/resource_manager.h"20 19 #include "state.h" 21 20 … … 28 27 #include "debug.h" 29 28 30 #include " util/preferences.h"29 #include "parser/preferences/preferences.h" 31 30 #include "substring.h" 32 31 #include "text.h" … … 35 34 #include "texture.h" 36 35 37 #include "effects/graphics_effect.h" 38 #include "effects/fog_effect.h" 39 #include "effects/lense_flare.h" 36 #include "graphics_effect.h" 40 37 41 38 #include "shell_command.h" 42 39 #include "loading/load_param_xml.h" 43 40 44 41 #include "parser/tinyxml/tinyxml.h" 45 42 #include "util/loading/load_param.h" 46 43 #include "util/loading/factory.h" 47 #include "class_list.h"48 44 49 45 #ifdef __WIN32__ … … 54 50 SHELL_COMMAND(fps, GraphicsEngine, toggleFPSdisplay); 55 51 52 ObjectListDefinition(GraphicsEngine); 53 56 54 /** 57 55 * @brief standard constructor … … 59 57 GraphicsEngine::GraphicsEngine () 60 58 { 61 this-> setClassID(CL_GRAPHICS_ENGINE, "GraphicsEngine");59 this->registerObject(this, GraphicsEngine::_objectList); 62 60 this->setName("GraphicsEngine"); 63 61 … … 117 115 { 118 116 LoadParamXML(root, "GraphicsEffect", this, GraphicsEngine, loadGraphicsEffects) 119 .describe("loads a graphics effect");117 .describe("loads a graphics effect"); 120 118 } 121 119 … … 590 588 591 589 // tick the graphics effects 592 if (this->graphicsEffects != NULL || (this->graphicsEffects = ClassList::getList(CL_GRAPHICS_EFFECT)) != NULL) 593 { 594 std::list<BaseObject*>::const_iterator it; 595 for (it = this->graphicsEffects->begin(); it != this->graphicsEffects->end(); it++) 596 dynamic_cast<GraphicsEffect*>(*it)->tick(dt); 597 } 590 for (ObjectList<GraphicsEffect>::const_iterator it = GraphicsEffect::objectList().begin(); 591 it != GraphicsEffect::objectList().end(); 592 ++it) 593 (*it)->tick(dt); 598 594 } 599 595 … … 688 684 { 689 685 case EV_VIDEO_RESIZE: 690 691 692 } 693 } 686 this->resolutionChanged(event.resize); 687 break; 688 } 689 } -
trunk/src/lib/graphics/graphics_engine.h
r9406 r9869 30 30 class GraphicsEngine : public EventListener 31 31 { 32 ObjectListDeclaration(GraphicsEngine); 32 33 public: 33 34 virtual ~GraphicsEngine(); -
trunk/src/lib/graphics/importer/Makefile.am
r8724 r9869 4 4 noinst_LIBRARIES = libORXimporter.a libtc.a 5 5 6 libORXimporter_a_SOURCES = model.cc \ 7 interactive_model.cc \ 8 md_model_structure.cc \ 9 vertex_array_model.cc \ 10 grid.cc \ 11 static_model.cc \ 12 objModel.cc \ 13 primitive_model.cc \ 14 height_map.cc \ 15 bsp_manager.cc \ 16 bsp_file.cc \ 17 bsp_tree_node.cc \ 18 bsp_tree_leaf.cc \ 19 \ 20 material.cc \ 21 texture.cc \ 22 texture_data.cc \ 23 texture_sequence.cc \ 24 media_container.cc \ 25 movie_player.cc \ 26 \ 27 bsp_manager.cc \ 28 bsp_file.cc \ 29 bsp_tree_node.cc \ 30 bsp_tree_leaf.cc \ 31 \ 32 md2/md2Model.cc \ 33 \ 34 md3/md3_model.cc \ 35 md3/md3_animation.cc \ 36 md3/md3_animation_cfg.cc \ 37 md3/md3_bone_frame.cc \ 38 md3/md3_mesh.cc \ 39 md3/md3_data.cc \ 40 md3/md3_tag.cc 6 libORXimporter_a_SOURCES = \ 7 model.cc \ 8 interactive_model.cc \ 9 md_model_structure.cc \ 10 vertex_array_model.cc \ 11 grid.cc \ 12 static_model.cc \ 13 static_model_data.cc \ 14 objModel.cc \ 15 resource_obj.cc \ 16 primitive_model.cc \ 17 height_map.cc \ 18 bsp_manager.cc \ 19 bsp_file.cc \ 20 bsp_tree_node.cc \ 21 bsp_tree_leaf.cc \ 22 \ 23 material.cc \ 24 texture.cc \ 25 texture_data.cc \ 26 resource_texture.cc \ 27 texture_sequence.cc \ 28 media_container.cc \ 29 movie_player.cc \ 30 \ 31 bsp_manager.cc \ 32 bsp_file.cc \ 33 bsp_tree_node.cc \ 34 bsp_tree_leaf.cc \ 35 \ 36 md2/md2Model.cc \ 37 md2/resource_md2.cc 38 # \ 39 md3/md3_model.cc \ 40 md3/md3_animation.cc \ 41 md3/md3_animation_cfg.cc \ 42 md3/md3_bone_frame.cc \ 43 md3/md3_mesh.cc \ 44 md3/md3_data.cc \ 45 md3/md3_tag.cc 41 46 42 47 … … 54 59 grid.h \ 55 60 static_model.h \ 61 static_model_data.h \ 56 62 objModel.h \ 63 resource_obj.h \ 57 64 primitive_model.h \ 58 65 anorms.h \ … … 63 70 texture.h \ 64 71 texture_data.h \ 72 resource_texture.h \ 65 73 texture_sequence.h \ 66 74 \ … … 74 82 \ 75 83 md2/md2Model.h \ 84 md2/resource_md2.h \ 76 85 \ 77 86 md3/md3_model.h \ -
trunk/src/lib/graphics/importer/bsp_file.cc
r9406 r9869 466 466 PRINTF(4)("BSP FILE: Name %s . \n", fileName); 467 467 468 absFileName = Resource Manager::getFullName(fileName);468 absFileName = Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(fileName); 469 469 470 470 if(File(absFileName).exists()) { … … 481 481 strncat (fileName, ext, strlen(fileName)); 482 482 483 absFileName = Resource Manager::getFullName(fileName);483 absFileName = Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(fileName); 484 484 485 485 if(File(absFileName).exists()) { … … 496 496 strncat (fileName, ext, strlen(fileName)); 497 497 498 absFileName = Resource Manager::getFullName(fileName);498 absFileName = Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(fileName); 499 499 500 500 if(File(absFileName).exists()) { … … 511 511 strncat (fileName, ext, strlen(fileName)); 512 512 513 absFileName = Resource Manager::getFullName(fileName);513 absFileName = Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(fileName); 514 514 515 515 if(File(absFileName).exists()) { … … 524 524 strcpy(ext, ".TGA"); 525 525 strncat (fileName, ext, strlen(fileName)); 526 absFileName = Resource Manager::getFullName(fileName);526 absFileName = Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(fileName); 527 527 528 528 if(File(absFileName).exists()/*stat( absFileName.c_str() , &results) == 0*/) { … … 537 537 strcpy(ext, ".jpg"); 538 538 strncat (fileName, ext, strlen(fileName)); 539 absFileName = Resource Manager::getFullName(fileName);539 absFileName = Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(fileName); 540 540 if(File(absFileName).exists()) { 541 541 PRINTF(4)("BSP FILE: gefunden . \n"); … … 551 551 strcpy(ext, ".JPG"); 552 552 strncat (fileName, ext, strlen(fileName)); 553 absFileName = Resource Manager::getFullName(fileName);553 absFileName = Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(fileName); 554 554 if(File(absFileName).exists()) { 555 555 PRINTF(4)("BSP FILE: gefunden . \n"); … … 566 566 strcpy(ext, ".bmp"); 567 567 strncat (fileName, ext, strlen(fileName)); 568 absFileName = Resource Manager::getFullName(fileName);568 absFileName = Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(fileName); 569 569 570 570 if(File(absFileName).exists()) { … … 580 580 strcpy(ext, ".BMP"); 581 581 strncat (fileName, ext, strlen(fileName)); 582 absFileName = Resource Manager::getFullName(fileName);582 absFileName = Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(fileName); 583 583 584 584 if(File(absFileName).exists()) { … … 611 611 this->testSurf = NULL; 612 612 613 this->testSurf = IMG_Load(Resource Manager::getFullName(mat).c_str());613 this->testSurf = IMG_Load(Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(mat).c_str()); 614 614 if(this->testSurf != NULL) { 615 615 if(this->testSurf->format->Amask != 0 ) tmpAMat.alpha = true; -
trunk/src/lib/graphics/importer/bsp_manager.cc
r9235 r9869 33 33 #include "world_entities/player.h" 34 34 #include "world_entities/playable.h" 35 #include "util/loading/resource_manager.h" 35 36 36 // STL Containers 37 37 #include <vector> … … 41 41 #include "world_entity.h" 42 42 43 #include "util/loading/resource_manager.h" 43 44 #include "util/loading/load_param.h" 44 45 #include "util/loading/factory.h" … … 91 92 this->bspFile = new BspFile(); 92 93 this->bspFile->scale = scale; 93 if(this->bspFile->read(Resource Manager::getFullName(fileName).c_str()) == -1)94 if(this->bspFile->read(Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(fileName).c_str()) == -1) 94 95 return -1; 95 96 … … 1376 1377 if( this->outputFraction == 1.0f) // No collision Detected 1377 1378 { 1378 if( this->outputAllSolid ) 1379 if( this->outputAllSolid ) 1379 1380 { 1380 1381 this->collPlane = new plane; -
trunk/src/lib/graphics/importer/height_map.cc
r8316 r9869 22 22 #include "p_node.h" 23 23 #include "state.h" 24 #include "util/loading/resource_manager.h"25 24 #include "debug.h" 26 25 … … 327 326 328 327 328 ObjectListDefinition(HeightMap); 329 329 330 330 … … 413 413 void HeightMap::init(const std::string& heightMapName) 414 414 { 415 this-> setClassID(CL_HEIGHT_MAP, "HeightMap");415 this->registerObject(this, HeightMap::_objectList); 416 416 417 417 this->shiftX = 0; -
trunk/src/lib/graphics/importer/height_map.h
r7526 r9869 29 29 30 30 class SDL_Surface; 31 class Vector;32 31 class Material; 33 class PNode;34 32 class Texture; 35 33 class HeightMap; … … 70 68 71 69 70 72 71 //!< the height map representation itself 73 72 class HeightMap : public VertexArrayModel 74 73 { 74 ObjectListDeclaration(HeightMap); 75 75 friend class Tile; 76 76 -
trunk/src/lib/graphics/importer/interactive_model.cc
r9406 r9869 22 22 23 23 24 ObjectListDefinition(InteractiveModel); 25 24 26 /** 25 27 * standard constructor … … 28 30 InteractiveModel::InteractiveModel() 29 31 { 30 this-> setClassID(CL_INTERACTIVE_MODEL, "InteractiveModel");32 this->registerObject(this, InteractiveModel::_objectList); 31 33 } 32 34 -
trunk/src/lib/graphics/importer/interactive_model.h
r9003 r9869 30 30 class InteractiveModel : public Model 31 31 { 32 ObjectListDeclaration(InteractiveModel); 32 33 public: 33 34 InteractiveModel(); … … 38 39 virtual void setAnimation(int animNum, int playbackMode = 0) = 0; 39 40 virtual void setAnimation(int firstFrame, int lastFrame, int fps, int bStoppable, int animPlayback) {} 40 virtual int getAnimation() = 0;41 virtual int getAnimation() const = 0; 41 42 42 43 virtual bool isAnimationFinished() { return false; } -
trunk/src/lib/graphics/importer/material.cc
r9406 r9869 25 25 #include "loading/load_param.h" 26 26 27 #include "util/loading/resource_manager.h" 27 #include "resource_texture.h" 28 29 ObjectListDefinition(Material); 28 30 29 31 /** … … 33 35 Material::Material (const std::string& mtlName) 34 36 { 35 this-> setClassID(CL_MATERIAL, "Material");37 this->registerObject(this, Material::_objectList); 36 38 37 39 this->setIllum(3); … … 90 92 PRINTF(5)("delete Material %s.\n", this->getCName()); 91 93 92 if (this->ambientTexture != NULL)93 ResourceManager::getInstance()->unload(this->ambientTexture);94 if (this->specularTexture != NULL)95 ResourceManager::getInstance()->unload(this->specularTexture);96 97 94 if (this == Material::selectedMaterial) 98 95 Material::selectedMaterial = NULL; … … 101 98 102 99 const Material* Material::selectedMaterial = NULL; 103 104 105 /// TODO FIX THIS106 // Material& Material::operator=(const Material& m)107 // {108 // this->setIllum(m.illumModel);109 // this->setDiffuse(m.diffuse[0],m.diffuse[1],m.diffuse[2]);110 // this->setAmbient(m.ambient[0],m.ambient[1],m.ambient[2]);111 // this->setSpecular(m.specular[0],m.specular[1],m.specular[2]);112 // this->setShininess(m.shininess);113 // this->setTransparency(m.transparency);114 //115 // if (this->diffuseTexture != NULL)116 // ResourceManager::getInstance()->unload(this->diffuseTexture);117 // if (m.diffuseTexture != NULL)118 // this->diffuseTexture = (Texture*)ResourceManager::getInstance()->copy(m.diffuseTexture);119 // this->ambientTexture = NULL; /// FIXME120 // this->specularTexture = NULL; /// FIXME121 //122 // this->setName(m.getName());123 // }124 125 126 100 127 101 /** … … 288 262 289 263 290 291 /**292 * @brief Adds a Texture Path to the List of already existing Paths293 * @param pathName The Path to add.294 */295 void Material::addTexturePath(const std::string& pathName)296 {297 ResourceManager::getInstance()->addImageDir(pathName);298 }299 300 // MAPPING //301 302 303 264 /** 304 265 * @brief Sets the Diffuse map of this Texture. … … 322 283 * @param textureNumber The Texture-Number from 0 to GL_MAX_TEXTURE_UNITS 323 284 */ 324 void Material::setDiffuseMap(const TextureData Pointer& textureDataPointer, unsigned int textureNumber)285 void Material::setDiffuseMap(const TextureData::Pointer& textureDataPointer, unsigned int textureNumber) 325 286 { 326 287 assert(textureNumber < Material::getMaxTextureUnits()); … … 349 310 if (!dMap.empty()) 350 311 { 351 Texture* tex = dynamic_cast<Texture*>(ResourceManager::getInstance()->load(dMap, IMAGE, RP_GAME, (int)target)); 352 if (tex != NULL) 353 this->textures[textureNumber] = *tex; 312 this->textures[textureNumber] = ResourceTexture(dMap); 313 //dynamic_cast<Texture*>(ResourceManager::getInstance()->load(dMap, IMAGE, RP_GAME, (int)target)); 314 /* if (tex != NULL) 315 this->textures[textureNumber] = tex; 354 316 else 355 this->textures[textureNumber] = Texture(); 317 this->textures[textureNumber] = Texture();*/ 356 318 } 357 319 else -
trunk/src/lib/graphics/importer/material.h
r8761 r9869 24 24 class Material : public BaseObject 25 25 { 26 ObjectListDeclaration(Material); 26 27 public: 27 28 Material (const std::string& mtlName = ""); 28 29 virtual ~Material (); 29 30 31 Material& operator=(const Material& material); 32 30 33 void loadParams(const TiXmlElement* root); 31 32 Material& operator=(const Material& material);33 34 34 35 bool select () const; … … 53 54 // MAPPING // 54 55 void setDiffuseMap(const Texture& texture, unsigned int textureNumber = 0); 55 void setDiffuseMap(const TextureData Pointer& texturePointer, unsigned int textureNumber = 0);56 void setDiffuseMap(const TextureData::Pointer& texturePointer, unsigned int textureNumber = 0); 56 57 void setDiffuseMap(const std::string& dMap, GLenum target = GL_TEXTURE_2D, unsigned int textureNumber = 0); 57 58 void setSDLDiffuseMap(SDL_Surface *surface, GLenum target = GL_TEXTURE_2D, unsigned int textureNumber = 0); … … 65 66 66 67 const Texture& diffuseTexture(unsigned int i = 0) const { return this->textures[i]; }; 67 68 static void addTexturePath(const std::string& pathName);69 68 70 69 static const std::string& blendFuncToString(GLenum blendFunc); -
trunk/src/lib/graphics/importer/md2/md2Model.cc
r9406 r9869 19 19 20 20 #include "debug.h" 21 #include " util/loading/resource_manager.h"22 23 24 21 #include "resource_md2.h" 22 23 24 ObjectListDefinition(MD2Model); 25 25 26 26 //! the model anorms 27 27 sVec3D MD2Model::anorms[NUM_VERTEX_NORMALS] = { 28 29 };28 #include "anorms.h" 29 }; 30 30 31 31 //! anormal dots, no idea of how this shall work, but it does 32 32 float MD2Model::anormsDots[SHADEDOT_QUANT][256] = { 33 34 };33 #include "anormtab.h" 34 }; 35 35 36 36 … … 42 42 sAnim MD2Model::animationList[22] = 43 43 { 44 // begin, end, fps, interruptable44 // begin, end, fps, interruptable 45 45 { 0, 39, 9, 1 }, //!< STAND 46 46 { 40, 45, 10, 1 }, //!< RUN … … 73 73 ********************************************************************************/ 74 74 75 MD2Model::MD2Model() 76 : data(new MD2Data()) 77 { 78 this->init(); 79 } 80 81 #include "resource_md2.h" 75 82 /** 76 83 \brief simple constructor initializing all variables 77 84 */ 78 85 MD2Model::MD2Model(const std::string& modelFileName, const std::string& skinFileName, float scale) 79 { 80 this->setClassID(CL_MD2_MODEL, "MD2Model"); 81 /* this creates the data container via ressource manager */ 82 if (!modelFileName.empty()) 83 this->data = (MD2Data*)ResourceManager::getInstance()->load(modelFileName, MD2, RP_GAME, skinFileName, scale); 84 if( unlikely(this->data == NULL)) 85 PRINTF(0)("The model was not found, MD2Model Loader finished abnormaly. Update the data-repos\n"); 86 86 : data(new MD2Data()) 87 { 88 this->init(); 87 89 this->scaleFactor = scale; 88 this->animationSpeed = 1.0f; 89 90 shadeDots = MD2Model::anormsDots[0]; 91 /* set the animation stat mannualy */ 92 this->animationState.type = STAND; 93 this->animationState.numPlays = 1; 94 this->setAnimation(STAND); 95 96 this->debug(); 97 98 //write the modelinfo information 90 91 this->data = ResourceMD2(modelFileName, skinFileName, scale).data; 92 rebuildInfo(); 93 94 //this->debug(); 95 } 96 97 MD2Model::MD2Model(const MD2Model& model) 98 : data(model.data) 99 { 100 this->init(); 101 this->rebuildInfo(); 102 } 103 104 MD2Model& MD2Model::operator=(const MD2Model& md2model) 105 { 106 this->data = md2model.data; 107 this->rebuildInfo(); 108 return *this; 109 } 110 111 void MD2Model::rebuildInfo() 112 { 113 //write the modelinfo information 99 114 this->pModelInfo.numVertices = this->data->numVertices; 100 115 this->pModelInfo.numTriangles = this->data->numTriangles; … … 107 122 108 123 // triangle conversion 124 if (this->pModelInfo.pTriangles != NULL) 125 delete[] this->pModelInfo.pTriangles; 109 126 this->pModelInfo.pTriangles = new sTriangleExt[this->data->numTriangles]; 110 127 for( int i = 0; i < this->data->numTriangles; i++) … … 118 135 this->pModelInfo.pTriangles[i].indexToTexCoor[2] = this->data->pTriangles[i].indexToTexCoor[2]; 119 136 } 137 } 138 139 bool MD2Model::load(const std::string& modelFileName, const std::string& skinFileName, float scale) 140 { 141 this->data = MD2Data::Pointer(new MD2Data(modelFileName, skinFileName, scale)); 142 this->rebuildInfo(); 120 143 } 121 144 … … 132 155 this->pModelInfo.pTexCoor = NULL; 133 156 this->pModelInfo.pTriangles = NULL; 134 135 ResourceManager::getInstance()->unload(this->data); 136 } 137 157 } 158 159 160 void MD2Model::init() 161 { 162 this->registerObject(this, MD2Model::_objectList); 163 /* this creates the data container via ressource manager */ 164 if( unlikely(this->data.isNull())) 165 PRINTF(0)("The model was not found, MD2Model Loader finished abnormaly. Update the data-repos\n"); 166 167 this->scaleFactor = 1.0f; 168 this->animationSpeed = 1.0f; 169 170 shadeDots = MD2Model::anormsDots[0]; 171 /* set the animation stat mannualy */ 172 this->animationState.type = STAND; 173 this->animationState.numPlays = 1; 174 this->setAnimation(STAND); 175 } 138 176 139 177 /** … … 153 191 154 192 for( int i = 0; i < this->data->numVertices; ++i) 155 156 157 158 159 193 { 194 this->verticesList[i][0] = currVec[i][0] + this->animationState.interpolationState * (nextVec[i][0] - currVec[i][0]); 195 this->verticesList[i][1] = currVec[i][1] + this->animationState.interpolationState * (nextVec[i][1] - currVec[i][1]); 196 this->verticesList[i][2] = currVec[i][2] + this->animationState.interpolationState * (nextVec[i][2] - currVec[i][2]); 197 } 160 198 } 161 199 … … 259 297 /* draw the triangles */ 260 298 while( int i = *(pCommands++)) /* strange looking while loop for maximum performance */ 299 { 300 if( i < 0) 261 301 { 262 if( i < 0) 263 { 264 glBegin(GL_TRIANGLE_FAN); 265 i = -i; 266 } 267 else 268 { 269 glBegin(GL_TRIANGLE_STRIP); 270 } 271 272 for(; i > 0; i--, pCommands += 3) /* down counting for loop, next 3 gl commands */ 273 { 274 glTexCoord2f( ((float *)pCommands)[0], ((float *)pCommands)[1] ); 275 glNormal3fv(anorms[this->data->pLightNormals[pCommands[2]]]); 276 glVertex3fv(this->verticesList[pCommands[2]]); 277 } 278 glEnd(); 279 302 glBegin(GL_TRIANGLE_FAN); 303 i = -i; 280 304 } 305 else 306 { 307 glBegin(GL_TRIANGLE_STRIP); 308 } 309 310 for(; i > 0; i--, pCommands += 3) /* down counting for loop, next 3 gl commands */ 311 { 312 glTexCoord2f( ((float *)pCommands)[0], ((float *)pCommands)[1] ); 313 glNormal3fv(anorms[this->data->pLightNormals[pCommands[2]]]); 314 glVertex3fv(this->verticesList[pCommands[2]]); 315 } 316 glEnd(); 317 318 } 281 319 glDisable(GL_CULL_FACE); 282 320 glPopAttrib(); … … 289 327 int* pCommands = this->data->pGLCommands; 290 328 /* some face culling stuff */ 291 // glPushAttrib(GL_POLYGON_BIT);292 // glFrontFace(GL_CW);293 // glEnable(GL_CULL_FACE);294 // glCullFace(GL_BACK);295 //296 // this->processLighting();297 // this->interpolate(/*this->verticesList*/);329 // glPushAttrib(GL_POLYGON_BIT); 330 // glFrontFace(GL_CW); 331 // glEnable(GL_CULL_FACE); 332 // glCullFace(GL_BACK); 333 // 334 // this->processLighting(); 335 // this->interpolate(/*this->verticesList*/); 298 336 this->data->material.select(); 299 337 … … 337 375 338 376 if( this->animationState.localTime - this->animationState.lastTime > (1.0f / this->animationState.fps)) 377 { 378 this->animationState.currentFrame = this->animationState.nextFrame; 379 this->animationState.nextFrame++; 380 381 if( this->animationState.nextFrame > this->animationState.endFrame ) 339 382 { 340 this->animationState.currentFrame = this->animationState.nextFrame; 341 this->animationState.nextFrame++; 342 343 if( this->animationState.nextFrame > this->animationState.endFrame ) 383 if( this->animationState.animPlaybackMode == MD2_ANIM_LOOP) 344 384 { 345 if( this->animationState.animPlaybackMode == MD2_ANIM_LOOP) 346 { 347 this->animationState.nextFrame = this->animationState.startFrame; 348 this->animationState.numPlays++; 349 } 350 else 351 { 352 this->animationState.nextFrame = this->animationState.endFrame; 353 } 385 this->animationState.nextFrame = this->animationState.startFrame; 386 this->animationState.numPlays++; 354 387 } 355 this->animationState.lastTime = this->animationState.localTime; 388 else 389 { 390 this->animationState.nextFrame = this->animationState.endFrame; 391 } 356 392 } 357 358 // if( this->animationState.currentFrame > (this->data->numFrames - 1) ) 359 // this->animationState.currentFrame = 0; 360 361 // if( (this->animationState.nextFrame > (this->data->numFrames - 1)) && this->animationState.animPlaybackMode == MD2_ANIM_LOOP) 362 // this->animationState.nextFrame = 0; 393 this->animationState.lastTime = this->animationState.localTime; 394 } 395 396 // if( this->animationState.currentFrame > (this->data->numFrames - 1) ) 397 // this->animationState.currentFrame = 0; 398 399 // if( (this->animationState.nextFrame > (this->data->numFrames - 1)) && this->animationState.animPlaybackMode == MD2_ANIM_LOOP) 400 // this->animationState.nextFrame = 0; 363 401 364 402 this->animationState.interpolationState = this->animationState.fps * 365 (this->animationState.localTime - this->animationState.lastTime);403 (this->animationState.localTime - this->animationState.lastTime); 366 404 } 367 405 … … 390 428 PRINT(0)("= Number of Frames: \t%i\n", this->data->header->numFrames); 391 429 PRINT(0)("= Height, Width:\t%i, %i\n", this->data->header->skinHeight, this->data->header->skinWidth); 392 PRINT(0)("= Pointer to the data object: %p\n", this->data);430 //PRINT(0)("= Pointer to the data object: %p\n", this->data); 393 431 PRINT(0)("===================================================\n\n"); 394 432 } … … 399 437 ********************************************************************************/ 400 438 439 MD2Data::MD2Data() 440 { 441 this->init(); 442 } 443 401 444 /** 402 445 \brief simple constructor … … 404 447 MD2Data::MD2Data(const std::string& modelFileName, const std::string& skinFileName, float scale) 405 448 { 406 scale *= 0.1f; 407 449 this->init(); 450 this->scaleFactor = scale * .1; 451 452 this->loadModel(modelFileName); 453 this->loadSkin(skinFileName); 454 } 455 456 void MD2Data::init() 457 { 458 this->scaleFactor = 1.0; 408 459 this->pVertices = NULL; 409 460 this->pGLCommands = NULL; 410 461 this->pLightNormals = NULL; 411 462 this->pTexCoor = NULL; 463 this->header = NULL; 412 464 413 465 this->numFrames = 0; … … 415 467 this->numGLCommands = 0; 416 468 this->numTexCoor = 0; 417 418 // this->scaleFactor = 1.0f; 419 this->scaleFactor = scale; 420 421 this->fileName = ""; 422 this->skinFileName = ""; 423 this->loadModel(modelFileName); 424 this->loadSkin(skinFileName); 425 } 426 469 } 427 470 428 471 /** … … 462 505 pFile = fopen(fileName.c_str(), "rb"); 463 506 if( unlikely(!pFile)) 464 465 466 467 507 { 508 PRINTF(1)("Couldn't open the MD2 File for loading. Exiting.\n"); 509 return false; 510 } 468 511 this->header = new MD2Header; 469 512 fread(this->header, 1, sizeof(MD2Header), pFile); 470 513 /* check for the header version: make sure its a md2 file :) */ 471 514 if( unlikely(this->header->version != MD2_VERSION) && unlikely(this->header->ident != MD2_IDENT)) 472 473 474 475 515 { 516 PRINTF(1)("Couldn't load file %s: invalid file format: stop loading\n", fileName.c_str()); 517 return false; 518 } 476 519 477 520 this->fileName =fileName; … … 506 549 507 550 for(int i = 0; i < this->numFrames; ++i) 551 { 552 frame = (sFrame*)(buffer + this->header->frameSize * i); 553 pVertex = this->pVertices + this->numVertices * i; 554 pNormals = this->pLightNormals + this->numVertices * i; 555 556 for(int j = 0; j < this->numVertices; ++j) 508 557 { 509 frame = (sFrame*)(buffer + this->header->frameSize * i); 510 pVertex = this->pVertices + this->numVertices * i; 511 pNormals = this->pLightNormals + this->numVertices * i; 512 513 for(int j = 0; j < this->numVertices; ++j) 514 { 515 /* SPEEDUP: *(pVerts + i + 0) = (*(frame->pVertices + i + 0)... */ 516 pVertex[j][0] = ((frame->pVertices[j].v[0] * frame->scale[0] ) + frame->translate[0] )* this->scaleFactor; 517 pVertex[j][1] = ((frame->pVertices[j].v[2] * frame->scale[2]) + frame->translate[2]) * this->scaleFactor; 518 pVertex[j][2] = (-1.0 * (frame->pVertices[j].v[1] * frame->scale[1] + frame->translate[1])) * this->scaleFactor; 519 520 //printf("vertex %i/%i: (%f, %f, %f)\n", j, this->numVertices, pVertex[j][0], pVertex[j][1], pVertex[j][2]); 521 522 pNormals[j] = frame->pVertices[j].lightNormalIndex; 523 } 558 /* SPEEDUP: *(pVerts + i + 0) = (*(frame->pVertices + i + 0)... */ 559 pVertex[j][0] = ((frame->pVertices[j].v[0] * frame->scale[0] ) + frame->translate[0] )* this->scaleFactor; 560 pVertex[j][1] = ((frame->pVertices[j].v[2] * frame->scale[2]) + frame->translate[2]) * this->scaleFactor; 561 pVertex[j][2] = (-1.0 * (frame->pVertices[j].v[1] * frame->scale[1] + frame->translate[1])) * this->scaleFactor; 562 563 //printf("vertex %i/%i: (%f, %f, %f)\n", j, this->numVertices, pVertex[j][0], pVertex[j][1], pVertex[j][2]); 564 565 pNormals[j] = frame->pVertices[j].lightNormalIndex; 524 566 } 525 PRINTF(4)("Finished loading the md2 file\n"); 567 } 568 PRINTF(4)("Finished loading the md2 file\n"); 526 569 527 570 delete [] buffer; … … 538 581 { 539 582 if( fileName.empty()) 540 541 542 543 583 { 584 this->skinFileName = ""; 585 return false; 586 } 544 587 545 588 this->skinFileName = fileName; -
trunk/src/lib/graphics/importer/md2/md2Model.h
r9235 r9869 20 20 21 21 #include "base_object.h" 22 #include "count_pointer.h" 22 23 23 24 #include "interactive_model.h" … … 45 46 struct MD2Header 46 47 { 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 48 int ident; //!< This is used to identify the file 49 int version; //!< The version number of the file (Must be 8) 50 51 int skinWidth; //!< The skin width in pixels 52 int skinHeight; //!< The skin height in pixels 53 int frameSize; //!< The size in bytes the frames are 54 55 int numSkins; //!< The number of skins associated with the model 56 int numVertices; //!< The number of vertices (constant for each frame) 57 int numTexCoords; //!< The number of texture coordinates 58 int numTriangles; //!< The number of faces (polygons) 59 int numGlCommands; //!< The number of gl commands 60 int numFrames; //!< The number of animation frames 61 62 int offsetSkins; //!< The offset in the file for the skin data 63 int offsetTexCoords; //!< The offset in the file for the texture data 64 int offsetTriangles; //!< The offset in the file for the face data 65 int offsetFrames; //!< The offset in the file for the frames data 66 int offsetGlCommands; //!< The offset in the file for the gl commands data 67 int offsetEnd; //!< The end of the file offset 67 68 }; 68 69 … … 70 71 //! animation names enumeration 71 72 typedef enum MD2animType 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 73 { 74 STAND, //0 75 RUN, //1 76 ATTACK, //2 77 PAIN_A, //3 78 PAIN_B, //4 79 PAIN_C, //5 80 JUMP, //6 81 FLIP, //7 82 SALUTE, //8 83 FALLBACK, //9 84 WAVE, //10 85 POINT, //11 86 CROUCH_STAND, 87 CROUCH_WALK, 88 CROUCH_ATTACK, 89 CROUCH_PAIN, 90 CROUCH_DEATH, 91 DEATH_FALLBACK, 92 DEATH_FALLFORWARD, 93 DEATH_FALLBACKSLOW, 94 BOOM, 95 WALK, 96 97 MAX_ANIMATIONS 98 }; 98 99 99 100 … … 116 117 class MD2Data : public BaseObject 117 118 { 118 public: 119 MD2Data(const std::string& modelFileName, const std::string& skinFileName, float scale = 1.0f); 119 public: 120 typedef CountPointer<MD2Data> Pointer; 121 public: 122 MD2Data(); 123 MD2Data(const std::string& modelFileName, const std::string& skinFileName, float scale = 1.0f); 120 124 virtual ~MD2Data(); 121 125 122 private: 123 bool loadModel(const std::string& fileName); 124 bool loadSkin(const std::string& fileName = ""); 125 126 public: 126 private: 127 void init(); 128 bool loadModel(const std::string& fileName); 129 bool loadSkin(const std::string& fileName = ""); 130 131 public: 127 132 int numFrames; //!< number of frames 128 133 int numVertices; //!< number of vertices … … 148 153 149 154 //! This is a MD2 Model class 150 class MD2Model : public InteractiveModel { 151 152 public: 155 class MD2Model : public InteractiveModel 156 { 157 ObjectListDeclaration(MD2Model); 158 public: 159 MD2Model(); 153 160 MD2Model(const std::string& modelFileName, const std::string& skinFileName = "", float scale = 1.0f); 161 MD2Model(const MD2Model& model); 154 162 virtual ~MD2Model(); 163 164 MD2Model& operator=(const MD2Model& md2model); 165 166 bool load(const std::string& modelFileName, const std::string& skinFileName = "", float scale = 1.0f); 155 167 156 168 virtual void draw() const; … … 160 172 virtual void setAnimation(int firstFrame, int lastFrame, int fps, int bStoppable, int animPlayback); 161 173 /** returns the current animation @returns animation type */ 162 inline int MD2Model::getAnimation(){ return this->animationState.type; }174 inline int getAnimation() const { return this->animationState.type; } 163 175 virtual void setAnimationSpeed(float speed) { this->animationSpeed = speed; } 164 virtual bool isAnimationFinished(){ return (this->animationState.currentFrame == this->animationState.endFrame )?true:false; }176 virtual bool isAnimationFinished() const { return (this->animationState.currentFrame == this->animationState.endFrame )?true:false; } 165 177 /** scales the current model @param scaleFactor: the factor [0..1] to use for scaling */ 166 178 void scaleModel(float scaleFactor) { this->scaleFactor = scaleFactor;} 167 179 180 181 void acquireData(const MD2Data::Pointer& data) { this->data = data; rebuildInfo(); }; 182 const MD2Data::Pointer& dataPointer() const { return this->data; }; 168 183 virtual void tick(float dtS); 169 184 void debug(); … … 171 186 172 187 private: 188 void init(); 189 void rebuildInfo(); 190 173 191 void animate(float time); 174 192 void processLighting(); … … 177 195 178 196 179 197 public: 180 198 /* these variables are static, because they are all the same for every model */ 181 static sVec3D anorms[NUM_VERTEX_NORMALS]; //!< the anormals182 static float anormsDots[SHADEDOT_QUANT][256]; //!< the anormals dot products183 static sAnim animationList[22]; //!< the anomation list184 185 float* shadeDots;186 187 MD2Data* data;//!< the md2 data pointer188 189 190 float scaleFactor; //!< the scale factor (individual)191 float animationSpeed; //!< the speed of the animation (factor for the time)192 sAnimState animationState; //!< animation state of the model193 sVec3D verticesList[MD2_MAX_VERTICES]; //!< place to temp sav the vert199 static sVec3D anorms[NUM_VERTEX_NORMALS]; //!< the anormals 200 static float anormsDots[SHADEDOT_QUANT][256]; //!< the anormals dot products 201 static sAnim animationList[22]; //!< the anomation list 202 //! again one of these strange id software parts 203 float* shadeDots; 204 205 CountPointer<MD2Data> data; //!< the md2 data pointer 206 207 private: 208 float scaleFactor; //!< the scale factor (individual) 209 float animationSpeed; //!< the speed of the animation (factor for the time) 210 sAnimState animationState; //!< animation state of the model 211 sVec3D verticesList[MD2_MAX_VERTICES]; //!< place to temp sav the vert 194 212 }; 195 213 -
trunk/src/lib/graphics/importer/md3/md3_model.h
r8724 r9869 45 45 46 46 virtual void setAnimation(int animNum, int playbackMode = 0) {} 47 virtual int getAnimation() { return 0;}47 virtual int getAnimation() const { return 0;} 48 48 49 49 virtual void tick(float dt); -
trunk/src/lib/graphics/importer/media_container.cc
r8316 r9869 26 26 27 27 #include "util/loading/resource_manager.h" 28 29 28 /* header for debug output */ 30 29 #include "debug.h" 31 30 31 ObjectListDefinition(MediaContainer); 32 32 33 33 /** … … 37 37 { 38 38 // set the class id for the base object 39 this-> setClassID(CL_MEDIA_CONTAINER, "MediaContainer");39 this->registerObject(this, MediaContainer::_objectList); 40 40 41 41 fps = 0; … … 91 91 return false; 92 92 // check whether file exists 93 if(!Resource Manager::isInDataDir(filename))93 if(!Resources::ResourceManager::getInstance()->checkFileInMainPath(filename)) 94 94 { 95 95 PRINTF(1)("Could not find %s\n", filename.c_str()); … … 101 101 102 102 // Open video file 103 if (av_open_input_file(&format_context, Resource Manager::getFullName(filename).c_str(), NULL, 0, NULL) !=0 )104 { 105 PRINTF(1)("Could not open %s\n", Resource Manager::getFullName(filename).c_str());103 if (av_open_input_file(&format_context, Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(filename).c_str(), NULL, 0, NULL) !=0 ) 104 { 105 PRINTF(1)("Could not open %s\n", Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(filename).c_str()); 106 106 return false; 107 107 } … … 110 110 if (av_find_stream_info(format_context) < 0) 111 111 { 112 PRINTF(1)("Could not find stream information in %s\n", Resource Manager::getFullName(filename).c_str());112 PRINTF(1)("Could not find stream information in %s\n", Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(filename).c_str()); 113 113 return false; 114 114 } … … 119 119 if(video_stream == -1) 120 120 { 121 PRINTF(1)("Could not find a video stream in %s\n", Resource Manager::getFullName(filename).c_str());121 PRINTF(1)("Could not find a video stream in %s\n", Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(filename).c_str()); 122 122 return false; 123 123 } -
trunk/src/lib/graphics/importer/media_container.h
r7221 r9869 24 24 class MediaContainer : public TextureSequence 25 25 { 26 26 ObjectListDeclaration(MediaContainer); 27 27 private: 28 28 -
trunk/src/lib/graphics/importer/model.cc
r9406 r9869 20 20 #include "glincl.h" 21 21 22 22 ObjectListDefinition(Model); 23 23 24 24 /** … … 28 28 Model::Model() 29 29 { 30 this-> setClassID(CL_MODEL, "Model");30 this->registerObject(this, Model::_objectList); 31 31 this->pModelInfo.numVertices = 0; 32 32 this->pModelInfo.numTriangles = 0; -
trunk/src/lib/graphics/importer/model.h
r8035 r9869 54 54 //! This class defines the basic components of a model 55 55 class Model : virtual public BaseObject { 56 ObjectListDeclaration(Model); 56 57 57 58 public: -
trunk/src/lib/graphics/importer/movie_player.cc
r7221 r9869 24 24 // include your own header 25 25 #include "movie_player.h" 26 27 26 #include "util/loading/resource_manager.h" 28 27 … … 30 29 #include "debug.h" 31 30 31 ObjectListDefinition(MoviePlayer); 32 32 33 33 MoviePlayer::MoviePlayer(const std::string& filename) 34 34 { 35 35 // set the class id for the base object 36 this->setClassID(CL_MOVIE_PLAYER, "MoviePlayer"); 37 36 this->registerObject(this, MoviePlayer::_objectList); 38 37 status = STOP; 39 38 timer = 0; … … 90 89 return false; 91 90 // check whether file exists 92 if(!Resource Manager::isInDataDir(filename))91 if(!Resources::ResourceManager::getInstance()->checkFileInMainPath(filename)) 93 92 { 94 93 PRINTF(1)("Could not find %s\n", filename.c_str()); … … 100 99 101 100 // Open video file 102 if (av_open_input_file(&format_context, Resource Manager::getFullName(filename).c_str(), NULL, 0, NULL) !=0 )103 { 104 PRINTF(1)("Could not open %s\n", Resource Manager::getFullName(filename).c_str());101 if (av_open_input_file(&format_context, Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(filename).c_str(), NULL, 0, NULL) !=0 ) 102 { 103 PRINTF(1)("Could not open %s\n", Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(filename).c_str()); 105 104 return false; 106 105 } … … 109 108 if (av_find_stream_info(format_context) < 0) 110 109 { 111 PRINTF(1)("Could not find stream information in %s\n", Resource Manager::getFullName(filename).c_str());110 PRINTF(1)("Could not find stream information in %s\n", Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(filename).c_str()); 112 111 return false; 113 112 } … … 118 117 if(video_stream == -1) 119 118 { 120 PRINTF(1)("Could not find a video stream in %s\n", Resource Manager::getFullName(filename).c_str());119 PRINTF(1)("Could not find a video stream in %s\n", Resources::ResourceManager::getInstance()->prependAbsoluteMainPath(filename).c_str()); 121 120 return false; 122 121 } -
trunk/src/lib/graphics/importer/movie_player.h
r7221 r9869 31 31 class MoviePlayer : public BaseObject 32 32 { 33 ObjectListDeclaration(MoviePlayer); 33 34 34 35 private: -
trunk/src/lib/graphics/importer/objModel.cc
r8369 r9869 18 18 #include "objModel.h" 19 19 20 #include <stdio.h>21 20 #include <string.h> 22 #include <stdlib.h>21 #include "loading/resource_manager.h" 23 22 24 23 #define PARSELINELENGTH 8192 … … 27 26 #include "compiler.h" 28 27 28 ObjectListDefinition(OBJModel); 29 29 /** 30 30 * @brief Crates a 3D-Model, loads in a File and scales it. … … 35 35 : StaticModel(fileName) 36 36 { 37 this-> setClassID(CL_OBJ_MODEL, "OBJModel");37 this->registerObject(this, OBJModel::_objectList); 38 38 39 39 this->objPath = "./"; 40 40 41 this->s caleFactor = scaling;41 this->setScaleFactor(scaling); 42 42 43 43 this->importFile (fileName); … … 77 77 else 78 78 this->objPath = "./"; 79 Material::addTexturePath(this->objPath);79 Resources::ResourceManager::getInstance()->addResourcePath("Texture", this->objPath); 80 80 81 81 this->readFromObjFile (fileName); -
trunk/src/lib/graphics/importer/objModel.h
r8369 r9869 12 12 class OBJModel : public StaticModel 13 13 { 14 public: 15 OBJModel(const std::string& fileName, float scaling = 1.0); 14 ObjectListDeclaration(OBJModel); 15 public: 16 OBJModel(const std::string& fileName, float scaling = 1.0); 16 17 virtual ~OBJModel(); 17 18 18 19 private: 19 20 ///// readin ///// 20 21 22 21 bool importFile (const std::string& fileName); 22 bool readFromObjFile (const std::string& fileName); 23 bool readMtlLib (const std::string& matFile); 23 24 24 25 26 27 28 29 30 25 private: 26 void setIllum (Material* material, const char* illum); 27 void setDiffuse (Material* material, const char* rgb); 28 void setAmbient (Material* material, const char* rgb); 29 void setSpecular (Material* material, const char* rgb); 30 void setShininess (Material* material, const char* shini); 31 void setTransparency (Material* material, const char* trans); 31 32 32 33 33 private: 34 std::string objPath; //!< The Path where the obj and mtl-file are located. 34 35 }; 35 36 -
trunk/src/lib/graphics/importer/static_model.cc
r9406 r9869 26 26 27 27 28 ////////////////////29 /// SUB-Elements ///30 ////////////////////31 /**32 * @brief creates a new ModelFaceElement33 */34 ModelFaceElement::ModelFaceElement()35 {36 this->vertexNumber = -1;37 this->normalNumber = -1;38 this->texCoordNumber = -1;39 40 this->next = NULL;41 }42 43 /**44 * @brief destroys a ModelFaceElement45 */46 ModelFaceElement::~ModelFaceElement()47 {48 if (this->next)49 delete this->next;50 }51 52 /**53 * @brief creates a new ModelFace54 */55 ModelFace::ModelFace()56 {57 this->vertexCount = 0;58 59 this->firstElem = NULL;60 61 this->material = NULL;62 63 this->next = NULL;64 }65 66 /**67 * deletes a ModelFace68 */69 ModelFace::~ModelFace()70 {71 PRINTF(5)("Cleaning up Face\n");72 73 if (this->firstElem != NULL)74 delete this->firstElem;75 76 if (this->next != NULL)77 delete this->next;78 }79 80 /**81 * @brief Creates a new ModelGroup82 */83 ModelGroup::ModelGroup()84 {85 PRINTF(4)("Adding new Group\n");86 this->name = "";87 this->faceMode = -1;88 this->faceCount = 0;89 this->next = NULL;90 this->listNumber = 0;91 this->indices = NULL;92 93 this->firstFace = new ModelFace;94 this->currentFace = this->firstFace;95 }96 97 /**98 * @brief deletes a ModelGroup99 */100 ModelGroup::~ModelGroup()101 {102 PRINTF(5)("Cleaning up group\n");103 if (this->firstFace != NULL)104 delete this->firstFace;105 106 // deleting the glList107 if (this->listNumber != 0)108 glDeleteLists(this->listNumber, 1);109 110 if (this->next !=NULL)111 delete this->next;112 113 }114 115 /**116 * @brief cleans up a ModelGroup117 *118 * actually does the same as the delete Operator, but does not delete the predecessing group119 */120 void ModelGroup::cleanup()121 {122 PRINTF(5)("Cleaning up group\n");123 if (this->firstFace)124 delete this->firstFace;125 this->firstFace = NULL;126 if (this->next)127 this->next->cleanup();128 }129 130 131 28 ///////////// 132 29 /// MODEL /// 133 30 ///////////// 31 ObjectListDefinition(StaticModel); 32 134 33 /** 135 34 * @brief Creates a 3D-Model. … … 138 37 */ 139 38 StaticModel::StaticModel(const std::string& modelName) 39 : data(new StaticModelData(modelName)) 140 40 { 141 this-> setClassID(CL_STATIC_MODEL, "StaticModel");41 this->registerObject(this, StaticModel::_objectList); 142 42 PRINTF(4)("new 3D-Model is being created\n"); 143 43 this->setName(modelName); 44 } 144 45 145 this->finalized = false; 46 StaticModel::StaticModel(const StaticModel& staticModel) 47 : data(staticModel.data) 48 { 49 this->registerObject(this, StaticModel::_objectList); 50 this->setName(staticModel.getName()); 51 this->updateBase(); 52 } 146 53 147 // setting the start group;148 this->currentGroup = this->firstGroup = new ModelGroup;149 this->groupCount = 0;150 this->faceCount = 0;151 152 this->scaleFactor = 1.0f;153 }154 54 155 55 /** … … 161 61 { 162 62 PRINTF(4)("Deleting Model "); 163 if (!this->getName().empty())164 {165 PRINT(4)("%s\n", this->getCName());166 }167 else168 {169 PRINT(4)("\n");170 }171 this->cleanup();172 173 PRINTF(5)("Deleting display Lists.\n");174 delete this->firstGroup;175 176 // deleting the MaterialList177 PRINTF(5)("Deleting Materials.\n");178 179 //! @todo do we really have to delete this material??180 std::list<ModelMaterial*>::iterator modMat;181 for(modMat = this->materialList.begin(); modMat != this->materialList.end(); modMat++)182 {183 if (!(*modMat)->external)184 delete (*modMat)->material;185 delete (*modMat);186 }187 63 188 64 // mark this stuff as beeing deleted … … 190 66 this->pModelInfo.pNormals = NULL; 191 67 this->pModelInfo.pTexCoor = NULL; 68 this->pModelInfo.pTriangles = NULL; 192 69 } 70 71 StaticModel& StaticModel::operator=(const StaticModel& model) 72 { 73 this->data = model.data; 74 this->updateBase(); 75 return *this; 76 }; 77 193 78 194 79 /** … … 197 82 void StaticModel::finalize() 198 83 { 199 // this creates the display List. 200 this->importToDisplayList(); 201 this->buildTriangleList(); 202 203 // write out the modelInfo data used for the collision detection! 204 this->pModelInfo.pVertices = &this->vertices[0]; 205 this->pModelInfo.pNormals = &this->normals[0]; 206 this->pModelInfo.pTexCoor = &this->vTexture[0]; 207 208 this->finalized = true; 84 data->finalize(); 85 this->updateBase(); 209 86 } 210 87 211 /** 212 * @brief rebuild the Model from the Information we got. 213 */ 214 void StaticModel::rebuild() 88 void StaticModel::acquireData(const StaticModelData::Pointer& data) 215 89 { 216 PRINTF(3)("Rebuilding Model '%s'\n", this->getCName()); 217 this->finalize(); 218 } 219 220 ////////// 221 // DRAW // 222 ////////// 223 /** 224 * @brief Draws the Models of all Groups. 225 * 226 * It does this by just calling the Lists that must have been created earlier. 227 */ 228 void StaticModel::draw () const 229 { 230 PRINTF(4)("drawing the 3D-Models\n"); 231 ModelGroup* tmpGroup = this->firstGroup; 232 while (tmpGroup != NULL) 233 { 234 PRINTF(5)("Drawing model %s\n", tmpGroup->name.c_str()); 235 glCallList (tmpGroup->listNumber); 236 tmpGroup = tmpGroup->next; 237 } 238 } 239 240 241 /** 242 * @brief Draws the Model number groupNumber 243 * @param groupNumber The number of the group that will be displayed. 244 * 245 * It does this by just calling the List that must have been created earlier. 246 */ 247 void StaticModel::draw (int groupNumber) const 248 { 249 if (unlikely(groupNumber >= this->groupCount)) 250 { 251 PRINTF(2)("You requested model number %i, but this File only contains of %i Models.\n", groupNumber-1, this->groupCount); 252 return; 253 } 254 PRINTF(4)("drawing the requested 3D-Models if found.\n"); 255 ModelGroup* tmpGroup = this->firstGroup; 256 int counter = 0; 257 while (tmpGroup != NULL) 258 { 259 if (counter == groupNumber) 260 { 261 PRINTF(4)("Drawing model number %i named %s\n", counter, tmpGroup->name.c_str()); 262 glCallList (tmpGroup->listNumber); 263 return; 264 } 265 ++counter; 266 tmpGroup = tmpGroup->next; 267 } 268 PRINTF(2)("Model number %i in %s not Found.\n", groupNumber, this->getCName()); 269 return; 270 } 271 272 273 /** 274 * @brief Draws the Model with a specific groupName 275 * @param groupName The name of the group that will be displayed. 276 * 277 * It does this by just calling the List that must have been created earlier. 278 */ 279 void StaticModel::draw (const std::string& groupName) const 280 { 281 PRINTF(4)("drawing the requested 3D-Models if found.\n"); 282 ModelGroup* tmpGroup = this->firstGroup; 283 while (tmpGroup != NULL) 284 { 285 if (tmpGroup->name == groupName) 286 { 287 PRINTF(4)("Drawing model %s\n", tmpGroup->name.c_str()); 288 glCallList (tmpGroup->listNumber); 289 return; 290 } 291 tmpGroup = tmpGroup->next; 292 } 293 PRINTF(2)("Model Named %s in %s not Found.\n", groupName.c_str(), this->getCName()); 294 return; 295 } 296 297 ////////// 298 // INIT // 299 ////////// 300 301 /** 302 * @brief finalizes an Model. 303 * 304 * This funcion is needed, to delete all the Lists, and arrays that are no more 305 * needed because they are already imported into openGL. 306 * This will be applied at the end of the importing Process. 307 */ 308 bool StaticModel::cleanup() 309 { 310 PRINTF(4)("cleaning up the 3D-Model to save Memory.\n"); 311 this->firstGroup->cleanup(); 312 return true; 313 } 314 315 ////////// 316 // MESH // 317 ////////// 318 /** 319 * @brief adds a new Material to the Material List 320 * @param material the Material to add 321 * @returns the added material 322 * 323 * this also tells this Model, that all the Materials are handled externally 324 * with this option set the Materials will not be deleted with the Model. 325 */ 326 Material* StaticModel::addMaterial(Material* material) 327 { 328 if (material == NULL) 329 return NULL; 330 ModelMaterial* modMat = new ModelMaterial; 331 modMat->external = true; 332 modMat->material = material; 333 this->materialList.push_back(modMat); 334 return modMat->material; 335 } 336 337 /** 338 * @brief adds a new Material to the Material List 339 * @param materialName the name of the Material to add 340 * @returns the added material 341 */ 342 Material* StaticModel::addMaterial(const std::string& materialName) 343 { 344 ModelMaterial* modMat = new ModelMaterial; 345 modMat->external = false; 346 modMat->material = new Material(materialName); 347 348 // adding material to the List of materials 349 this->materialList.push_back(modMat); 350 return modMat->material; 351 } 352 353 /** 354 * @brief finds a Material by its name and returns it 355 * @param materialName the Name of the material to search for. 356 * @returns the Material if found, NULL otherwise 357 */ 358 Material* StaticModel::findMaterialByName(const std::string& materialName) 359 { 360 std::list<ModelMaterial*>::iterator modMat; 361 for (modMat = this->materialList.begin(); modMat != this->materialList.end(); modMat++) 362 if (materialName == (*modMat)->material->getName()) 363 return (*modMat)->material; 364 return NULL; 365 } 366 367 /** 368 * @brief parses a group String 369 * @param groupString the new Group to create 370 * 371 * This function initializes a new Group. 372 * With it you should be able to create Models with more than one SubModel inside 373 */ 374 bool StaticModel::addGroup(const std::string& groupString) 375 { 376 PRINTF(5)("Read Group: %s.\n", groupString.c_str()); 377 if (this->groupCount != 0 && this->currentGroup->faceCount > 0) 378 { 379 // finalizeGroup(currentGroup); 380 this->currentGroup = this->currentGroup->next = new ModelGroup; 381 } 382 // setting the group name if not default. 383 if (groupString == "default") 384 { 385 this->currentGroup->name = groupString; 386 } 387 ++this->groupCount; 388 return true; 389 } 390 391 /** 392 * @brief parses a vertex-String 393 * @param vertexString The String that will be parsed. 394 * 395 * If a vertex line is found this function will inject it into the vertex-Array 396 */ 397 bool StaticModel::addVertex (const std::string& vertexString) 398 { 399 float subbuffer1; 400 float subbuffer2; 401 float subbuffer3; 402 sscanf (vertexString.c_str(), "%f %f %f", &subbuffer1, &subbuffer2, &subbuffer3); 403 this->vertices.push_back(subbuffer1*scaleFactor); 404 this->vertices.push_back(subbuffer2*scaleFactor); 405 this->vertices.push_back(subbuffer3*scaleFactor); 406 this->pModelInfo.numVertices++; 407 return true; 408 } 409 410 /** 411 * @brief parses a vertex-String 412 * @param x the X-coordinate of the Vertex to add. 413 * @param y the Y-coordinate of the Vertex to add. 414 * @param z the Z-coordinate of the Vertex to add. 415 */ 416 bool StaticModel::addVertex(float x, float y, float z) 417 { 418 PRINTF(5)("reading in a vertex: %f %f %f\n", x, y, z); 419 this->vertices.push_back(x*scaleFactor); 420 this->vertices.push_back(y*scaleFactor); 421 this->vertices.push_back(z*scaleFactor); 422 this->pModelInfo.numVertices++; 423 return true; 424 } 425 426 /** 427 * @brief parses a vertexNormal-String 428 * @param normalString The String that will be parsed. 429 * 430 * If a vertexNormal line is found this function will inject it into the vertexNormal-Array 431 */ 432 bool StaticModel::addVertexNormal (const std::string& normalString) 433 { 434 float subbuffer1; 435 float subbuffer2; 436 float subbuffer3; 437 sscanf (normalString.c_str(), "%f %f %f", &subbuffer1, &subbuffer2, &subbuffer3); 438 this->normals.push_back(subbuffer1); 439 this->normals.push_back(subbuffer2); 440 this->normals.push_back(subbuffer3); 441 this->pModelInfo.numNormals++; 442 return true; 443 } 444 445 /** 446 * @brief adds a VertexNormal. 447 * @param x The x coordinate of the Normal. 448 * @param y The y coordinate of the Normal. 449 * @param z The z coordinate of the Normal. 450 * 451 * If a vertexNormal line is found this function will inject it into the vertexNormal-Array 452 */ 453 bool StaticModel::addVertexNormal(float x, float y, float z) 454 { 455 PRINTF(5)("found vertex-Normal %f, %f, %f\n", x, y, z); 456 this->normals.push_back(x); 457 this->normals.push_back(y); 458 this->normals.push_back(z); 459 this->pModelInfo.numNormals++; 460 return true; 461 } 462 463 /** 464 * @brief parses a vertexTextureCoordinate-String 465 * @param vTextureString The String that will be parsed. 466 * 467 * If a vertexTextureCoordinate line is found, 468 * this function will inject it into the vertexTexture-Array 469 * 470 * !! WARNING THIS IS DIFFERNT FROM addVervexTexture(float, float); because it changes the second entry to 1-v !! 471 */ 472 bool StaticModel::addVertexTexture (const std::string& vTextureString) 473 { 474 float subbuffer1; 475 float subbuffer2; 476 sscanf (vTextureString.c_str(), "%f %f", &subbuffer1, &subbuffer2); 477 this->vTexture.push_back(subbuffer1); 478 this->vTexture.push_back(1 - subbuffer2); 479 this->pModelInfo.numTexCoor++; 480 return true; 481 } 482 483 /** 484 * @brief adds a Texture Coordinate 485 * @param u The u coordinate of the TextureCoordinate. 486 * @param v The y coordinate of the TextureCoordinate. 487 * 488 * If a TextureCoordinate line is found this function will 489 * inject it into the TextureCoordinate-Array 490 */ 491 bool StaticModel::addVertexTexture(float u, float v) 492 { 493 PRINTF(5)("found vertex-Texture %f, %f\n", u, v); 494 this->vTexture.push_back(u); 495 this->vTexture.push_back(v); 496 this->pModelInfo.numTexCoor++; 497 return true; 498 } 499 500 /** 501 * @brief parses a face-string 502 * @param faceString The String that will be parsed. 503 * 504 * If a face line is found this function will add it to the glList. 505 * 506 * String is different from the argument addFace, 507 * in this, that the first Vertex/Normal/Texcoord is 1 instead of 0 508 * 509 * @TODO make it std::string conform 510 */ 511 bool StaticModel::addFace (const std::string& faceStringInput) 512 { 513 const char* faceString = faceStringInput.c_str(); 514 if (this->currentGroup->faceCount >0) 515 this->currentGroup->currentFace = this->currentGroup->currentFace->next = new ModelFace; 516 517 ModelFaceElement* tmpElem = this->currentGroup->currentFace->firstElem = new ModelFaceElement; 518 tmpElem->next = NULL; 519 while(strcmp (faceString, "\0")) 520 { 521 if (this->currentGroup->currentFace->vertexCount>0) 522 tmpElem = tmpElem->next = new ModelFaceElement; 523 tmpElem->next = NULL; 524 525 char tmpValue [50]; 526 int tmpLen; 527 char* vertex = NULL; 528 char* texture = NULL; 529 char* normal = NULL; 530 531 sscanf (faceString, "%s", tmpValue); 532 tmpLen = strlen(tmpValue); 533 vertex = tmpValue; 534 535 if ((texture = strstr (vertex, "/")) != NULL) 536 { 537 texture[0] = '\0'; 538 texture ++; 539 540 if ((normal = strstr (texture, "/")) !=NULL) 541 { 542 normal[0] = '\0'; 543 normal ++; 544 } 545 } 546 if (vertex) 547 tmpElem->vertexNumber = atoi(vertex)-1; 548 if (texture) 549 tmpElem->texCoordNumber = atoi(texture)-1; 550 if (normal) 551 tmpElem->normalNumber = atoi(normal)-1; 552 553 faceString += tmpLen; 554 if (strcmp (faceString, "\0")) 555 faceString++; 556 this->currentGroup->currentFace->vertexCount++; 557 } 558 559 this->currentGroup->faceCount += this->currentGroup->currentFace->vertexCount -2; 560 this->faceCount += this->currentGroup->currentFace->vertexCount -2; 561 return true; 90 this->data = data; 91 this->updateBase(); 562 92 } 563 93 … … 569 99 bool StaticModel::addFace(int faceElemCount, VERTEX_FORMAT type, ...) 570 100 { 571 if (this->currentGroup->faceCount > 0)572 this->currentGroup->currentFace = this->currentGroup->currentFace->next = new ModelFace;573 574 ModelFaceElement* tmpElem = this->currentGroup->currentFace->firstElem = new ModelFaceElement;575 576 101 va_list itemlist; 577 102 va_start (itemlist, type); 578 579 for (int i = 0; i < faceElemCount; i++) 580 { 581 if (this->currentGroup->currentFace->vertexCount > 0) 582 tmpElem = tmpElem->next = new ModelFaceElement; 583 584 tmpElem->vertexNumber = va_arg (itemlist, int); 585 if (type & TEXCOORD) 586 tmpElem->texCoordNumber = va_arg (itemlist, int); 587 if (type & NORMAL) 588 tmpElem->normalNumber = va_arg(itemlist, int); 589 this->currentGroup->currentFace->vertexCount++; 590 } 103 bool retVal = this->data->addFace(faceElemCount, type, itemlist); 591 104 va_end(itemlist); 592 593 this->currentGroup->faceCount += this->currentGroup->currentFace->vertexCount - 2; 594 this->faceCount += this->currentGroup->currentFace->vertexCount -2; 595 return true; 105 return retVal; 596 106 } 597 107 598 /** 599 * Function that selects a material, if changed in the obj file. 600 * @param matString the Material that will be set. 601 */ 602 bool StaticModel::setMaterial(const std::string& matString) 108 void StaticModel::updateBase() 603 109 { 604 if (this->currentGroup->faceCount > 0) 605 this->currentGroup->currentFace = this->currentGroup->currentFace->next = new ModelFace; 110 // write out the modelInfo data used for the collision detection! 111 this->pModelInfo.pVertices = &this->data->getVertices()[0]; 112 this->pModelInfo.numVertices = this->data->getVertices().size(); 113 this->pModelInfo.pNormals = &this->data->getNormals()[0]; 114 this->pModelInfo.numNormals = this->data->getNormals().size(); 115 this->pModelInfo.pTexCoor = &this->data->getTexCoords()[0]; 116 this->pModelInfo.numTexCoor = this->data->getTexCoords().size(); 606 117 607 this->currentGroup->currentFace->material = this->findMaterialByName(matString); 608 609 if (this->currentGroup->faceCount == 0) 610 this->currentGroup->faceCount++; 611 return true; 612 } 613 614 /** 615 * Function that selects a material, if changed in the obj file. 616 * @param mtl the Material that will be set. 617 */ 618 bool StaticModel::setMaterial(Material* mtl) 619 { 620 if (this->currentGroup->faceCount > 0) 621 this->currentGroup->currentFace = this->currentGroup->currentFace->next = new ModelFace; 622 623 this->currentGroup->currentFace->material = mtl; 624 625 if (this->currentGroup->faceCount == 0) 626 this->currentGroup->faceCount++; 627 return true; 628 } 629 630 /** 631 * @brief A routine that is able to create normals. 632 * 633 * The algorithm does the following: 634 * 1. It calculates creates Vectors for each normale, and sets them to zero. 635 * 2. It then Walks through a) all the Groups b) all the Faces c) all the FaceElements 636 * 3. It searches for a points two neighbours per Face, takes Vecotrs to them calculates FaceNormals and adds it to the Points Normal. 637 * 4. It goes through all the normale-Points and calculates the VertexNormale and includes it in the normals-Array. 638 */ 639 bool StaticModel::buildVertexNormals () 640 { 641 PRINTF(4)("Normals are being calculated.\n"); 642 643 Vector* normArray = new Vector [vertices.size()/3]; 644 for (unsigned int i=0; i<vertices.size()/3;i++) 645 normArray[i] = Vector(.0,.0,.0); 646 647 Vector prevV; 648 Vector nextV; 649 Vector curV; 650 651 ModelGroup* tmpGroup = firstGroup; 652 while (tmpGroup != NULL) 653 { 654 ModelFace* tmpFace = tmpGroup->firstFace; 655 while (tmpFace != NULL) 656 { 657 if (tmpFace->firstElem != NULL) 658 { 659 ModelFaceElement* firstElem = tmpFace->firstElem; 660 ModelFaceElement* prevElem; 661 ModelFaceElement* curElem = firstElem; 662 ModelFaceElement* nextElem; 663 ModelFaceElement* lastElem; 664 // find last Element of the Chain. !! IMPORTANT:the last Element of the Chain must point to NULL, or it will resolv into an infinity-loop. 665 while (curElem != NULL) 666 { 667 prevElem = curElem; 668 curElem = curElem->next; 669 } 670 lastElem = prevElem; 671 672 curElem = firstElem; 673 for (unsigned int j = 0; j < tmpFace->vertexCount; j++) 674 { 675 if (!(nextElem = curElem->next)) 676 nextElem = firstElem; 677 curElem->normalNumber = curElem->vertexNumber; 678 679 curV = Vector (this->vertices[curElem->vertexNumber*3], 680 this->vertices[curElem->vertexNumber*3+1], 681 this->vertices[curElem->vertexNumber*3+2]); 682 683 prevV = Vector (this->vertices[prevElem->vertexNumber*3], 684 this->vertices[prevElem->vertexNumber*3+1], 685 this->vertices[prevElem->vertexNumber*3+2]) - curV; 686 687 nextV = Vector (this->vertices[nextElem->vertexNumber*3], 688 this->vertices[nextElem->vertexNumber*3+1], 689 this->vertices[nextElem->vertexNumber*3+2]) - curV; 690 normArray[curElem->vertexNumber] = normArray[curElem->vertexNumber] + nextV.cross(prevV); 691 692 prevElem = curElem; 693 curElem = curElem->next; 694 } 695 } 696 tmpFace = tmpFace->next; 697 } 698 tmpGroup = tmpGroup->next; 699 } 700 701 for (unsigned int i=0; i < this->vertices.size()/3;i++) 702 { 703 normArray[i].normalize(); 704 PRINTF(5)("Found Normale number %d: (%f; %f, %f).\n", i, normArray[i].x, normArray[i].y, normArray[i].z); 705 706 this->addVertexNormal(normArray[i].x, normArray[i].y, normArray[i].z); 707 708 } 709 delete[] normArray; 710 return true; 711 } 712 713 //////////// 714 // openGL // 715 //////////// 716 /** 717 * reads and includes the Faces/Materials into the openGL state Machine 718 */ 719 bool StaticModel::importToDisplayList() 720 { 721 // finalize the Arrays 722 if (normals.size() == 0) // vertices-Array must be built for this 723 this->buildVertexNormals(); 724 725 this->currentGroup = this->firstGroup; 726 727 while (this->currentGroup != NULL) 728 { 729 730 // creating a glList for the Group 731 if ((this->currentGroup->listNumber = glGenLists(1)) == 0) 732 { 733 PRINTF(2)("glList could not be created for this Model\n"); 734 return false; 735 } 736 glNewList (this->currentGroup->listNumber, GL_COMPILE); 737 738 // Putting Faces to GL 739 ModelFace* tmpFace = this->currentGroup->firstFace; 740 while (tmpFace != NULL) 741 { 742 if (tmpFace->vertexCount == 0 && tmpFace->material != NULL) 743 { 744 if (this->currentGroup->faceMode != -1) 745 glEnd(); 746 this->currentGroup->faceMode = 0; 747 if (tmpFace->material != NULL) 748 { 749 tmpFace->material->select(); 750 PRINTF(5)("using material %s for coming Faces.\n", tmpFace->material->getCName()); 751 } 752 } 753 754 else if (tmpFace->vertexCount == 3) 755 { 756 if (this->currentGroup->faceMode != 3) 757 { 758 if (this->currentGroup->faceMode != -1) 759 glEnd(); 760 glBegin(GL_TRIANGLES); 761 } 762 763 this->currentGroup->faceMode = 3; 764 PRINTF(5)("found triag.\n"); 765 } 766 767 else if (tmpFace->vertexCount == 4) 768 { 769 if (this->currentGroup->faceMode != 4) 770 { 771 if (this->currentGroup->faceMode != -1) 772 glEnd(); 773 glBegin(GL_QUADS); 774 } 775 this->currentGroup->faceMode = 4; 776 PRINTF(5)("found quad.\n"); 777 } 778 779 else if (tmpFace->vertexCount > 4) 780 { 781 if (this->currentGroup->faceMode != -1) 782 glEnd(); 783 glBegin(GL_POLYGON); 784 PRINTF(5)("Polygon with %i faces found.", tmpFace->vertexCount); 785 this->currentGroup->faceMode = tmpFace->vertexCount; 786 } 787 788 ModelFaceElement* tmpElem = tmpFace->firstElem; 789 while (tmpElem != NULL) 790 { 791 // PRINTF(2)("%s\n", tmpElem->value); 792 this->addGLElement(tmpElem); 793 tmpElem = tmpElem->next; 794 } 795 tmpFace = tmpFace->next; 796 } 797 glEnd(); 798 glEndList(); 799 800 this->currentGroup = this->currentGroup->next; 801 } 802 return true; 118 this->pModelInfo.pTriangles = this->data->getTrianglesExt(); 119 this->pModelInfo.numTriangles = this->data->getTriangles().size(); 803 120 } 804 121 805 122 806 123 /** 807 * builds an array of triangles, that can later on be used for obb separation and octree separation 124 * Includes a default model 125 * 126 * This will inject a Cube, because this is the most basic model. 808 127 */ 809 bool StaticModel::buildTriangleList()810 {811 if( unlikely(this->pModelInfo.pTriangles != NULL))812 return true;813 /* make sure, that all the arrays are finalized */814 if( normals.size() == 0) // vertices-Array must be built for this815 this->buildVertexNormals();816 817 int index = 0; //!< the counter for the triangle array818 ModelFaceElement* tmpElem; //!< the temporary faceelement reference819 ModelFace* tmpFace; //!< the temporary face referece820 821 bool warned = false;822 823 this->pModelInfo.numTriangles = 0;824 825 /* count the number of triangles */826 /* now iterate through all groups and build up the triangle list */827 this->currentGroup = this->firstGroup;828 while( this->currentGroup != NULL)829 {830 tmpFace = this->currentGroup->firstFace;831 while( tmpFace != NULL)832 {833 /* if its a triangle just add it to the list */834 if( tmpFace->vertexCount == 3){835 ++this->pModelInfo.numTriangles;836 } /* if the polygon is a quad */837 else if( tmpFace->vertexCount == 4) {838 this->pModelInfo.numTriangles += 2;839 }840 else if( tmpFace->vertexCount > 4) {841 if (!warned) {842 PRINTF(2)("This model (%s) got over 4 vertices per face <=> conflicts in the CD engine!\n", this->getCName());843 warned = true;844 }845 }846 tmpFace = tmpFace->next;847 }848 this->currentGroup = this->currentGroup->next;849 }850 851 PRINTF(3)("got %i triangles, %i vertices\n", this->pModelInfo.numTriangles, this->pModelInfo.numVertices);852 853 854 /* write MODELINFO structure */855 856 /* allocate memory for the new triangle structures */857 if( (this->pModelInfo.pTriangles = new sTriangleExt[this->pModelInfo.numTriangles]) == NULL)858 {859 PRINTF(1)("Could not allocate memory for triangle list\n");860 return false;861 }862 863 /* now iterate through all groups and build up the triangle list */864 this->currentGroup = this->firstGroup;865 while( this->currentGroup != NULL)866 {867 tmpFace = this->currentGroup->firstFace;868 while( tmpFace != NULL)869 {870 tmpElem = tmpFace->firstElem;871 872 /* if its a triangle just add it to the list */873 if( tmpFace->vertexCount == 3)874 {875 for( int j = 0; j < 3; ++j)876 {877 this->pModelInfo.pTriangles[index].indexToVertices[j] = (unsigned int)tmpElem->vertexNumber * 3 ;878 this->pModelInfo.pTriangles[index].indexToNormals[j] = (unsigned int)tmpElem->normalNumber * 3 ;879 this->pModelInfo.pTriangles[index].indexToTexCoor[j] = (unsigned int)tmpElem->texCoordNumber * 3 ;880 tmpElem = tmpElem->next;881 882 }883 ++index;884 } /* if the polygon is a quad */885 else if( tmpFace->vertexCount == 4)886 {887 888 this->pModelInfo.pTriangles[index].indexToVertices[0] = (unsigned int)tmpElem->vertexNumber * 3;889 this->pModelInfo.pTriangles[index].indexToNormals[0] = (unsigned int)tmpElem->normalNumber * 3;890 this->pModelInfo.pTriangles[index].indexToTexCoor[0] = (unsigned int)tmpElem->texCoordNumber * 3;891 892 this->pModelInfo.pTriangles[index + 1].indexToVertices[0] = (unsigned int)tmpElem->vertexNumber * 3;893 this->pModelInfo.pTriangles[index + 1].indexToNormals[0] = (unsigned int)tmpElem->normalNumber * 3;894 this->pModelInfo.pTriangles[index + 1].indexToTexCoor[0] = (unsigned int)tmpElem->texCoordNumber * 3;895 tmpElem = tmpElem->next;896 897 this->pModelInfo.pTriangles[index].indexToVertices[1] = (unsigned int)tmpElem->vertexNumber * 3;898 this->pModelInfo.pTriangles[index].indexToNormals[1] = (unsigned int)tmpElem->normalNumber * 3;899 this->pModelInfo.pTriangles[index].indexToTexCoor[1] = (unsigned int)tmpElem->texCoordNumber * 3;900 tmpElem = tmpElem->next;901 902 this->pModelInfo.pTriangles[index].indexToVertices[2] = (unsigned int)tmpElem->vertexNumber * 3;903 this->pModelInfo.pTriangles[index].indexToNormals[2] = (unsigned int)tmpElem->normalNumber * 3;904 this->pModelInfo.pTriangles[index].indexToTexCoor[2] = (unsigned int)tmpElem->texCoordNumber * 3;905 906 this->pModelInfo.pTriangles[index + 1].indexToVertices[2] = (unsigned int)tmpElem->vertexNumber * 3;907 this->pModelInfo.pTriangles[index + 1].indexToNormals[2] = (unsigned int)tmpElem->normalNumber * 3;908 this->pModelInfo.pTriangles[index + 1].indexToTexCoor[2] = (unsigned int)tmpElem->texCoordNumber * 3;909 tmpElem = tmpElem->next;910 911 this->pModelInfo.pTriangles[index + 1].indexToVertices[1] = (unsigned int)tmpElem->vertexNumber * 3;912 this->pModelInfo.pTriangles[index + 1].indexToNormals[1] = (unsigned int)tmpElem->normalNumber * 3;913 this->pModelInfo.pTriangles[index + 1].indexToTexCoor[1] = (unsigned int)tmpElem->texCoordNumber * 3;914 915 index += 2;916 }917 tmpFace = tmpFace->next;918 }919 this->currentGroup = this->currentGroup->next;920 }921 return true;922 }923 924 925 /**926 * Adds a Face-element (one vertex of a face) with all its information.927 * @param elem The FaceElement to add to the OpenGL-environment.928 929 It does this by searching:930 1. The Vertex itself931 2. The VertexNormale932 3. The VertexTextureCoordinate933 merging this information, the face will be drawn.934 */935 bool StaticModel::addGLElement (ModelFaceElement* elem)936 {937 PRINTF(5)("importing grafical Element to openGL.\n");938 939 if (elem->texCoordNumber > -1)940 {941 if (likely((unsigned int)elem->texCoordNumber < this->pModelInfo.numTexCoor))942 glTexCoord2fv(&this->vTexture[0] + elem->texCoordNumber * 2);943 else944 PRINTF(2)("TextureCoordinate %d is not in the List (max: %d)\nThe Model might be incomplete\n",945 elem->texCoordNumber, this->pModelInfo.numTexCoor);946 }947 if (elem->normalNumber > -1)948 {949 if (likely((unsigned int)elem->normalNumber < this->pModelInfo.numNormals))950 glNormal3fv(&this->normals[0] + elem->normalNumber * 3);951 else952 PRINTF(2)("Normal %d is not in the List (max: %d)\nThe Model might be incomplete",953 elem->normalNumber, this->pModelInfo.numNormals);954 }955 if (elem->vertexNumber > -1)956 {957 if (likely((unsigned int)elem->vertexNumber < this->pModelInfo.numVertices))958 glVertex3fv(&this->vertices[0]+ elem->vertexNumber * 3);959 else960 PRINTF(2)("Vertex %d is not in the List (max: %d)\nThe Model might be incomplete",961 elem->vertexNumber, this->pModelInfo.numVertices);962 }963 964 return true;965 }966 967 /**968 * Includes a default model969 970 This will inject a Cube, because this is the most basic model.971 */972 128 void StaticModel::cubeModel() 973 129 { -
trunk/src/lib/graphics/importer/static_model.h
r7221 r9869 10 10 11 11 #include "material.h" 12 #include "glincl.h"13 12 #include <vector> 14 #include <list> 15 16 // definition of different modes for setting up Faces 17 #define VERTEX 0 //!< If Faces are created WITH Vertex-Coordinate 18 #define NORMAL 1 //!< If Faces are created WITH Normals (otherwise autocalculate) 19 #define TEXCOORD 2 //!< If Faces are created WITH TextureCoordinate 20 21 //! an enumerator for VERTEX_FORMAT 22 typedef enum VERTEX_FORMAT { 23 VERTEX_ONLY = VERTEX, 24 VERTEX_NORMAL = NORMAL, 25 VERTEX_TEXCOORD = TEXCOORD, 26 VERTEX_TEXCOORD_NORMAL = NORMAL | TEXCOORD 27 }; 28 29 //////////////////// 30 /// SUB-ELEMENTS /// 31 //////////////////// 32 //! This is the placeholder of one Vertex beloning to a Face. 33 class ModelFaceElement 34 { 35 public: 36 ModelFaceElement(); 37 ~ModelFaceElement(); 38 39 int vertexNumber; //!< The number of the Vertex out of the Array* vertices, this vertex points to. 40 int normalNumber; //!< The number of the Normal out of the Array* normals, this vertex points to. 41 int texCoordNumber; //!< The number of the textureCoordinate out of the Array* vTexture, this vertex points to. 42 43 ModelFaceElement* next; //!< Point to the next FaceElement in this List. 44 }; 45 46 //! This is the placeholder of a Face belonging to a Group of Faces. 47 class ModelFace 48 { 49 public: 50 ModelFace(); 51 ~ModelFace(); 52 53 unsigned int vertexCount; //!< The Count of vertices this Face has. 54 ModelFaceElement* firstElem; //!< Points to the first Vertex (FaceElement) of this Face. 55 Material* material; //!< The Material to use. 56 57 ModelFace* next; //!< Pointer to the next Face. 58 }; 59 60 //! Group to handle multiple Models per obj-file. 61 class ModelGroup 62 { 63 public: 64 ModelGroup(); 65 ~ModelGroup(); 66 67 void cleanup(); 68 69 std::string name; //!< the Name of the Group. this is an identifier, that can be accessed via the draw (std::string name) function. 70 GLubyte* indices; //!< The indices of the Groups. Needed for vertex-arrays 71 GLuint listNumber; //!< The number of the GL-List this Group gets. 72 ModelFace* firstFace; //!< The first Face in this group. 73 ModelFace* currentFace; //!< The current Face in this Group (the one we are currently working with.) 74 int faceMode; //!< The Mode the Face is in: initially -1, 0 for FaceList opened, 1 for Material, 3 for triangle, 4 for Quad, 5+ for Poly @todo ENUM... 75 int faceCount; //!< The Number of Faces this Group holds. 76 77 ModelGroup* next; //!< Pointer to the next Group. 78 }; 79 80 struct ModelMaterial 81 { 82 Material* material; 83 bool external; 84 }; 13 #include "static_model_data.h" 85 14 86 15 ///////////// … … 94 23 class StaticModel : public Model 95 24 { 96 public: 25 ObjectListDeclaration(StaticModel); 26 public: 97 27 StaticModel(const std::string& modelName = ""); 28 StaticModel(const StaticModel& staticModel); 98 29 virtual ~StaticModel(); 99 30 100 virtual void draw() const; 101 void draw(int groupNumber) const; 102 void draw(const std::string& groupName) const; 31 StaticModel& operator=(const StaticModel& model); 103 32 104 void rebuild(); 33 virtual void draw() const { data->draw(); }; 34 void draw(int groupNumber) const { data->draw(groupNumber); }; 35 void draw(const std::string& groupName) const { data->draw(groupName); }; 105 36 106 Material* addMaterial(Material* material); 107 Material* addMaterial(const std::string& materialName); 37 void rebuild() { data->rebuild(); }; 108 38 109 bool addGroup(const std::string& groupString); 39 Material* addMaterial(Material* material) { return data->addMaterial(material); }; 40 Material* addMaterial(const std::string& materialName) { return data->addMaterial(materialName); }; 110 41 111 bool addVertex(const std::string& vertexString); 112 bool addVertex(float x, float y, float z); 42 bool addGroup(const std::string& groupString) { return data->addGroup(groupString); }; 113 43 114 bool addFace(const std::string& faceString); 44 bool addVertex(const std::string& vertexString) { return data->addVertex(vertexString); }; 45 bool addVertex(float x, float y, float z) { return data->addVertex(x, y, z); }; 46 47 bool addFace(const std::string& faceString) { return data->addFace(faceString); }; 115 48 bool addFace(int faceElemCount, VERTEX_FORMAT type, ...); 116 49 117 bool addVertexNormal(const std::string& normalString) ;118 bool addVertexNormal(float x, float y, float z) ;50 bool addVertexNormal(const std::string& normalString) { return this->data->addVertexNormal(normalString); }; 51 bool addVertexNormal(float x, float y, float z) { return this->data->addVertexNormal(x,y,z); }; 119 52 120 bool addVertexTexture(const std::string& vTextureString) ;121 bool addVertexTexture(float u, float v) ;53 bool addVertexTexture(const std::string& vTextureString) { return this->data->addVertexTexture(vTextureString); }; 54 bool addVertexTexture(float u, float v) { return this->data->addVertexTexture(u, v); }; 122 55 123 bool setMaterial(const std::string& mtlString) ;124 bool setMaterial(Material* mtl) ;56 bool setMaterial(const std::string& mtlString) { return data->setMaterial(mtlString); }; 57 bool setMaterial(Material* mtl) { return data->setMaterial(mtl);}; 125 58 126 59 void finalize(); 127 60 61 void acquireData(const StaticModelData::Pointer& data); 62 const StaticModelData::Pointer& dataPointer() const { return this->data; }; 128 63 129 protected: 64 inline void setScaleFactor(float scaleFactor) { this->data->setScaleFactor(scaleFactor); }; 65 float getScaleFactor() const { return data->getScaleFactor(); } 66 67 protected: 130 68 void cubeModel(); 131 69 132 Material* findMaterialByName(const std::string& materialName); 133 134 protected: 135 float scaleFactor; //!< The Factor with which the Model should be scaled. @todo maybe one wants to scale the Model after Initialisation 136 137 private: 138 bool buildVertexNormals(); 139 140 bool importToDisplayList(); 141 bool buildTriangleList(); 142 143 bool addGLElement(ModelFaceElement* elem); 144 145 bool cleanup(); 146 147 private: 148 bool finalized; //!< Sets the Object to be finalized. 149 150 unsigned int faceCount; //!< A modelwide Counter for the faces 151 152 std::vector<GLfloat> vertices; //!< The Array that handles the Vertices. 153 std::vector<GLfloat> normals; //!< The Array that handles the Normals. 154 std::vector<GLfloat> vTexture; //!< The Array that handles the VertexTextureCoordinates. 155 156 ModelGroup* firstGroup; //!< The first of all groups. 157 ModelGroup* currentGroup; //!< The currentGroup. this is the one we will work with. 158 int groupCount; //!< The Count of Groups. 159 160 std::list<ModelMaterial*> materialList; //!< A list for all the Materials in this Model 70 private: 71 void updateBase(); 72 private: 73 StaticModelData::Pointer data; 161 74 }; 162 75 -
trunk/src/lib/graphics/importer/texture.cc
r9406 r9869 64 64 #endif 65 65 66 66 ObjectListDefinition(Texture); 67 67 68 68 /** … … 86 86 : data(texture.data) 87 87 { 88 this-> setClassID(CL_TEXTURE, "Texture");88 this->registerObject(this, Texture::_objectList); 89 89 this->priority = 0.5; 90 90 } … … 149 149 void Texture::init() 150 150 { 151 this-> setClassID(CL_TEXTURE, "Texture");152 153 this->data = TextureData Pointer(new TextureData());151 this->registerObject(this, Texture::_objectList); 152 153 this->data = TextureData::Pointer(new TextureData()); 154 154 155 155 this->priority = 0.5; … … 176 176 } 177 177 178 Texture& Texture::operator=(const TextureData Pointer& textureDataPointer)178 Texture& Texture::operator=(const TextureData::Pointer& textureDataPointer) 179 179 { 180 180 this->data = textureDataPointer; -
trunk/src/lib/graphics/importer/texture.h
r8761 r9869 1 1 /*! 2 2 * @file texture.h 3 * @brief Contains the texture class, that handles the reading of Images into Tex utre-files.3 * @brief Contains the texture class, that handles the reading of Images into Texture-files. 4 4 */ 5 5 … … 20 20 class Texture : public BaseObject 21 21 { 22 ObjectListDeclaration(Texture); 22 23 public: 23 24 Texture(); … … 28 29 29 30 Texture& operator=(const Texture& texture); 30 Texture& operator=(const TextureDataPointer& textureDataPointer); 31 Texture& operator=(const TextureData::Pointer& textureDataPointer); 32 void acquireData(const TextureData::Pointer& textureDataPointer) { this->data = textureDataPointer; }; 33 const TextureData::Pointer& dataPointer() const { return data; } 31 34 32 35 virtual ~Texture(); … … 62 65 63 66 private: 64 TextureData Pointerdata; //!< The TextureData67 TextureData::Pointer data; //!< The TextureData 65 68 GLclampf priority; //!< the priority of the current texture (used for garphics cards with limited mem) 66 69 -
trunk/src/lib/graphics/importer/texture_data.h
r8761 r9869 18 18 class TextureData 19 19 { 20 public: 21 typedef CountPointer<TextureData> Pointer; 20 22 public: 21 23 TextureData(); … … 43 45 }; 44 46 45 typedef CountPointer<TextureData> TextureDataPointer;46 47 47 #endif /* _TEXTURE_DATA_H */ -
trunk/src/lib/graphics/importer/texture_sequence.cc
r9406 r9869 28 28 #endif 29 29 30 ObjectListDefinition(TextureSequence); 31 30 32 /** 31 33 * @brief Constructor for a Texture … … 33 35 TextureSequence::TextureSequence(unsigned int count, ...) 34 36 { 35 this-> setClassID(CL_TEXTURE_SEQUENCE, "TextureSequence");37 this->registerObject(this, TextureSequence::_objectList); 36 38 37 39 va_list textureNameList; … … 54 56 TextureSequence::TextureSequence(const std::vector<std::string>& textureNames, const std::string& prependFolder) 55 57 { 56 this-> setClassID(CL_TEXTURE_SEQUENCE, "TextureSequence");58 this->registerObject(this, TextureSequence::_objectList); 57 59 this->loadImageSeries(textureNames, prependFolder); 58 60 } -
trunk/src/lib/graphics/importer/texture_sequence.h
r8324 r9869 15 15 class TextureSequence : public Texture 16 16 { 17 ObjectListDeclaration(TextureSequence); 17 18 public: 18 19 TextureSequence(unsigned int count = 0, ...); -
trunk/src/lib/graphics/importer/vertex_array_model.cc
r9406 r9869 24 24 25 25 26 ObjectListDefinition(VertexArrayModel); 26 27 27 28 ///////////// … … 35 36 VertexArrayModel::VertexArrayModel() 36 37 { 37 this-> setClassID(CL_MODEL, "VertexArrayModel");38 this->registerObject(this, VertexArrayModel::_objectList); 38 39 39 40 this->newStripe(); … … 49 50 VertexArrayModel::VertexArrayModel(const Model& model) 50 51 { 51 this-> setClassID(CL_MODEL, "VertexArrayModel");52 this->registerObject(this, VertexArrayModel::_objectList); 52 53 53 54 // importing the data to the new Model. -
trunk/src/lib/graphics/importer/vertex_array_model.h
r6769 r9869 27 27 class VertexArrayModel : public Model 28 28 { 29 public: 29 ObjectListDeclaration(VertexArrayModel); 30 public: 30 31 VertexArrayModel(); 31 32 VertexArrayModel(const Model& model); -
trunk/src/lib/graphics/light.cc
r8742 r9869 22 22 #include "glincl.h" 23 23 #include "vector.h" 24 #include "parser/tinyxml/tinyxml.h" 25 #include "util/loading/load_param.h" 24 #include "util/loading/load_param_xml.h" 26 25 #include "util/loading/factory.h" 27 26 #include "debug.h" 28 27 29 CREATE_FACTORY(Light, CL_LIGHT); 28 #include "class_id_DEPRECATED.h" 29 30 ObjectListDefinitionID(Light, CL_LIGHT); 31 CREATE_FACTORY(Light); 30 32 31 33 //! Definition of the Lights and their Names … … 51 53 PRINTF(4)("initializing Light number %d.\n", this->lightNumber); 52 54 55 this->registerObject(this, Light::_objectList); 56 53 57 this->lightNumber = LightManager::getInstance()->registerLight(this); 54 58 55 this->setClassID(CL_LIGHT, "Light");56 59 char tmpName[10]; 57 60 sprintf(tmpName, "Light[%d]", this->lightNumber); … … 211 214 ** LIGHT-MANAGER ** 212 215 ******************/ 216 ObjectListDefinition(LightManager); 213 217 /** 214 218 * standard constructor for a Light … … 216 220 LightManager::LightManager () 217 221 { 218 this-> setClassID(CL_LIGHT_MANAGER, "LightManager");222 this->registerObject(this, LightManager::_objectList); 219 223 220 224 glEnable (GL_LIGHTING); -
trunk/src/lib/graphics/light.h
r8255 r9869 25 25 class Light : public PNode 26 26 { 27 public: 28 Light(const TiXmlElement* root = NULL); 29 virtual ~Light(); 30 31 virtual void loadParams(const TiXmlElement* root); 32 33 void setDiffuseColor(GLfloat r, GLfloat g, GLfloat b); 34 void setSpecularColor(GLfloat r, GLfloat g, GLfloat b); 35 void setAttenuation(float constantAttenuation, float linearAttenuation, float quadraticAttenuation); 36 void setSpotDirection(const Vector& direction); 37 void setSpotDirection(float x, float y, float z) { setSpotDirection(Vector(x,y,z)); }; 38 void setSpotCutoff(GLfloat cutoff); 39 40 /** @returns the lightNumber*/ 41 int getLightNumber() const {return this->lightNumber;} 42 43 virtual void draw() const; 44 45 void debug() const; 46 47 // attributes 48 private: 49 int lightNumber; //!< The number of this Light. 50 GLfloat diffuseColor[4]; //!< The Diffuse Color this Light emmits. 51 GLfloat specularColor[4]; //!< The specular Color of this Light. 52 float constantAttenuation; //!< The Factor of the the Constant Attenuation. 53 float linearAttenuation; //!< The Factor of the the Linear Attenuation. 54 float quadraticAttenuation; //!< The Factor of the the Quadratic Attenuation. 55 GLfloat spotDirection[4]; //!< The direction of the Spot Light. 56 GLfloat spotCutoff; //!< The cutoff Angle of the Light Source 27 ObjectListDeclaration(Light); 28 public: 29 Light(const TiXmlElement* root = NULL); 30 virtual ~Light(); 31 32 virtual void loadParams(const TiXmlElement* root); 33 34 void setDiffuseColor(GLfloat r, GLfloat g, GLfloat b); 35 void setSpecularColor(GLfloat r, GLfloat g, GLfloat b); 36 void setAttenuation(float constantAttenuation, float linearAttenuation, float quadraticAttenuation); 37 void setSpotDirection(const Vector& direction); 38 void setSpotDirection(float x, float y, float z) { setSpotDirection(Vector(x,y,z)); }; 39 void setSpotCutoff(GLfloat cutoff); 40 41 /** @returns the lightNumber*/ 42 int getLightNumber() const {return this->lightNumber;} 43 44 virtual void draw() const; 45 46 void debug() const; 47 48 // attributes 49 private: 50 int lightNumber; //!< The number of this Light. 51 GLfloat diffuseColor[4]; //!< The Diffuse Color this Light emmits. 52 GLfloat specularColor[4]; //!< The specular Color of this Light. 53 float constantAttenuation; //!< The Factor of the the Constant Attenuation. 54 float linearAttenuation; //!< The Factor of the the Linear Attenuation. 55 float quadraticAttenuation; //!< The Factor of the the Quadratic Attenuation. 56 GLfloat spotDirection[4]; //!< The direction of the Spot Light. 57 GLfloat spotCutoff; //!< The cutoff Angle of the Light Source 57 58 }; 58 59 60 59 60 61 61 62 //! A class that handles Lights 62 63 /** … … 87 88 */ 88 89 class LightManager : public BaseObject 89 90 friend class Light;90 { 91 ObjectListDeclaration(LightManager); 91 92 92 public: 93 virtual ~LightManager(); 94 /** @returns a Pointer to the only object of this Class */ 95 inline static LightManager* getInstance() { if (!singletonRef) singletonRef = new LightManager(); return singletonRef; }; 93 friend class Light; 94 public: 95 virtual ~LightManager(); 96 /** @returns a Pointer to the only object of this Class */ 97 inline static LightManager* getInstance() { if (!singletonRef) singletonRef = new LightManager(); return singletonRef; }; 96 98 97 98 99 virtual void loadParams(const TiXmlElement* root); 100 void loadLights(const TiXmlElement* root); 99 101 100 101 102 102 void setAmbientColor(GLfloat r, GLfloat g, GLfloat b); 103 // HACK: Assuming r = g = b values 104 inline GLfloat getAmbientColor() { return this->ambientColor[0]; } 103 105 104 105 106 Light* getLight(int lightNumber) const; 107 inline Light* getLight() const { return this->currentLight; }; 106 108 107 109 void draw() const; 108 110 109 111 void debug() const; 110 112 111 112 113 private: 114 LightManager(); 113 115 114 115 116 int registerLight(Light* light); 117 void unregisterLight(Light* light); 116 118 117 118 119 119 private: 120 static LightManager* singletonRef; //!< This is the LightHandlers Reference. 121 GLfloat ambientColor[4]; //!< The ambient Color of the scene. 120 122 121 122 123 Light** lights; //!< An array of Lenght NUMBEROFLIGHTS, that holds pointers to all LightValues. 124 Light* currentLight; //!< The current Light, we are working with. 123 125 124 126 }; -
trunk/src/lib/graphics/render2D/element_2d.cc
r9406 r9869 29 29 #include "graphics_engine.h" 30 30 #include "util/loading/load_param.h" 31 #include "class_list.h"32 31 33 32 #include "color.h" 34 33 #include "debug.h" 35 34 #include "shell_command.h" 35 36 36 SHELL_COMMAND(debug, Element2D, debug2D); 37 38 ObjectListDefinition(Element2D); 37 39 38 40 … … 46 48 Element2D::Element2D (Element2D* parent, E2D_LAYER layer, short nodeFlags) 47 49 { 48 this-> setClassID(CL_ELEMENT_2D, "Element2D");50 this->registerObject(this, Element2D::_objectList); 49 51 50 52 this->setVisibility(true); … … 268 270 void Element2D::setBindNode(const std::string& bindNode) 269 271 { 270 const PNode* tmpBindNode = dynamic_cast<const PNode*>(ClassList::getObject(bindNode, CL_PARENT_NODE));272 const PNode* tmpBindNode = PNode::objectList().getObject(bindNode); 271 273 if (tmpBindNode != NULL) 272 274 this->bindNode = tmpBindNode; … … 640 642 void Element2D::addChild2D (const std::string& childName) 641 643 { 642 Element2D* childNode = dynamic_cast<Element2D*>(ClassList::getObject(childName, CL_ELEMENT_2D));644 Element2D* childNode = Element2D::objectList().getObject(childName); 643 645 if (childNode != NULL) 644 646 this->addChild2D(childNode); … … 718 720 void Element2D::setParent2D (const std::string& parentName) 719 721 { 720 Element2D* parentNode = dynamic_cast<Element2D*>(ClassList::getObject(parentName, CL_ELEMENT_2D));722 Element2D* parentNode = Element2D::objectList().getObject(parentName); 721 723 if (parentNode != NULL) 722 724 parentNode->addChild2D(this); … … 771 773 void Element2D::setParentSoft2D(const std::string& parentName, float bias) 772 774 { 773 Element2D* parentNode = dynamic_cast<Element2D*>(ClassList::getObject(parentName, CL_ELEMENT_2D));775 Element2D* parentNode = Element2D::objectList().getObject(parentName); 774 776 if (parentNode != NULL) 775 777 this->setParentSoft2D(parentNode, bias); -
trunk/src/lib/graphics/render2D/element_2d.h
r8360 r9869 47 47 48 48 E2D_PARENT_MOVEMENT = 0x0004, //!< Moves all children along with the parent. 49 // special linkage modes49 // special linkage modes 50 50 E2D_PARENT_ALL = 0x0003, //!< Moves all children around the center of their parent, and also rotates their centers 51 51 E2D_PARENT_ROTATE_AND_MOVE = 0x0005, //!< Rotates all children around their axis, and moves them as the Parent Moves, but does not rotate around the center of their parent. … … 58 58 E2D_REPARENT_DELETE_CHILDREN = 0x0040, //!< Deletes the Children of the node when This Node is Removed. (Use with care). 59 59 /// FIXME 60 60 E2D_REPARENT_KEEP_POSITION = 0x0080, //!< Tries to keep the Position if the Node is reparented. 61 61 62 62 … … 87 87 * -> the tree is sorted on insertion of a new Child: @see Element2D::addChild2D() 88 88 */ 89 class Element2D : virtual public BaseObject { 90 91 public: 92 Element2D(Element2D* parent = Element2D::getNullElement(), E2D_LAYER layer = E2D_DEFAULT_LAYER, short nodeFlags = E2D_PARENT_MODE_DEFAULT); 93 virtual ~Element2D(); 94 95 virtual void loadParams(const TiXmlElement* root); 96 97 // ACTIVATION // 98 inline void activate2D() { this->bActive = this->bRelCoorChanged = this->bRelDirChanged = true; }; 99 inline void deactivate2D() { this->bActive = false; }; 100 inline bool get2DActiveState() { return this->bActive; }; 101 102 // ALIGNMENT // 103 /** @param alignment the new Alignment of the 2D-Element */ 104 inline void setAlignment(E2D_ALIGNMENT alignment) { this->alignment = alignment; }; 105 void setAlignment(const std::string& alignment); 106 inline E2D_ALIGNMENT getAlignment() const { return this->alignment; }; 107 108 // LAYERING // 109 void setLayer(E2D_LAYER layer); 110 void setLayer(const std::string& layer); 111 /** @returns the Layer this Element is drawn to */ 112 inline E2D_LAYER getLayer() const { return this->layer; }; 113 114 // VISIBILITY // 115 /** @param visible true if the Element should be visible false otherwise (will not be rendered) */ 116 inline void setVisibility(bool visible) { this->bVisible = visible; }; 117 /** @returns the visibility state */ 118 inline bool isVisible() const { return (this->bVisible && this->bCurrentlyVisible); }; 119 120 121 // POSITIONAL (E2D-specials) // 122 /** @param bindNode the Node this 2D-element should follow. if NULL the Element will not follow anything */ 123 void setBindNode(const PNode* bindNode); 124 void setBindNode(const std::string& bindNode); 125 inline const PNode* getBindNode() const { return this->bindNode; }; 126 127 inline void setSize2D(float x, float y) { this->size = Vector2D(x, y); }; 128 inline void setSize2D(const Vector2D& size) { this->size = size; }; 129 inline const Vector2D& getSize2D() const { return this->size; }; 130 void setSizeSoft2D(float x, float y, float bias = 1.0); 131 inline void setSizeX2D(float x) { this->size.x = x; }; 132 inline void setSizeY2D(float y) { this->size.y = y; }; 133 inline float getSizeX2D() const { return this->size.x; }; 134 inline float getSizeY2D() const { return this->size.y; }; 135 136 public: 137 virtual void tick(float dt) {}; 138 virtual void draw() const {}; 139 void tick2D(float dt); 140 void draw2D(E2D_LAYER from, E2D_LAYER to) const; 141 void drawChildren(E2D_LAYER from, E2D_LAYER to) const; 142 143 // LIKE PNODE 144 public: 145 void setRelCoor2D (const Vector2D& relCoord); 146 void setRelCoorX2D(float x); 147 void setRelCoorY2D(float y); 148 void setRelCoor2D (float x, float y); 149 void setRelCoor2Dpx (int x, int y); 150 void setRelCoorSoft2D (const Vector2D& relCoordSoft, float bias = 1.0); 151 void setRelCoorSoft2D (float x, float y, float bias = 1.0); 152 void setRelCoorSoft2Dpx (int x, int y, float bias = 1.0); 153 /** @returns the relative position */ 154 inline const Vector2D& getRelCoor2D () const { return this->prevRelCoordinate; }; 155 /** @returns the Relative Coordinate Destination */ 156 inline const Vector2D& getRelCoorSoft2D() const { return (this->toCoordinate)?*this->toCoordinate:this->relCoordinate; }; 157 const Vector2D& getRelCoor2Dpx() const; 158 void setAbsCoor2D (const Vector2D& absCoord); 159 void setAbsCoor2D (float x, float y); 160 void setAbsCoorX2D(float x); 161 void setAbsCoorY2D(float y); 162 void setAbsCoor2Dpx (int x, int y); 163 void setAbsCoorSoft2D (const Vector2D& absCoordSoft, float bias = 1.0); 164 void setAbsCoorSoft2D (float x, float y, float bias = 1.0); 165 /** @returns the absolute position */ 166 inline const Vector2D& getAbsCoor2D () const { return this->absCoordinate; }; 167 const Vector2D& getAbsCoor2Dpx () const; 168 169 void shiftCoor2D (const Vector2D& shift); 170 void shiftCoor2Dpx (int x, int y); 171 172 void setRelDir2D (float relDir); 173 void setRelDirSoft2D(float relDirSoft, float bias = 1.0); 174 /** @returns the relative Direction */ 175 inline float getRelDir2D () const { return this->prevRelDirection; }; 176 /** @returns the Relative Directional Destination */ 177 inline float getRelDirSoft2D() const { return (this->toDirection)?*this->toDirection:this->relDirection; }; 178 void setAbsDir2D (float absDir); 179 void setAbsDirSoft2D (float absDirSoft, float bias = 1.0); 180 /** @returns the absolute Direction */ 181 inline float getAbsDir2D () const { return this->absDirection; }; 182 void shiftDir2D (float shiftDir); 183 184 /** @returns the Speed of the Node */ 185 inline float getSpeed() const { return 0; }; 186 /** @returns the Velocity of the Node */ 187 inline const Vector2D& getVelocity() const { return this->velocity; }; 188 189 190 void addChild2D (Element2D* child); 191 void addChild2D (const std::string& childName); 192 void removeChild2D (Element2D* child); 193 void remove2D(); 194 195 /** @param parent the new parent of this Element2D */ 196 void setParent2D (Element2D* parent) { parent->addChild2D(this); }; 197 void setParent2D (const std::string& parentName); 198 /** @returns the parent of this Element2D */ 199 inline Element2D* getParent2D () const { return this->parent; }; 200 /** @returns the List of Children of this Element2D */ 201 inline const std::list<Element2D*>& getChildren2D() const { return this->children; }; 202 203 void setParentSoft2D(Element2D* parentNode, float bias = 1.0); 204 void setParentSoft2D(const std::string& parentName, float bias = 1.0); 205 206 void setParentMode2D (E2D_PARENT_MODE parentMode); 207 void setParentMode2D (const std::string& parentingMode); 208 /** @returns the Parenting mode of this node */ 209 int getParentMode2D() const { return this->parentMode; }; 210 211 // NULL_PARENT // 212 /** @returns the NullParent, the (main) ROOT of the PNode Tree. If it does not yet exist, it will be created. */ 213 static Element2D* getNullElement() { return (Element2D::nullElement != NULL)? Element2D::nullElement : Element2D::createNullElement(); }; 214 215 216 void update2D (float dt); 217 218 void debug2D (unsigned int depth = 1, unsigned int level = 0) const; 219 void debugDraw2D(unsigned int depth = 1, float size = 1.0, Vector color = Vector(1,0,0), unsigned int level = 0) const; 220 221 // helper functions // 222 static const char* parentingModeToString2D(int parentingMode); 223 static E2D_PARENT_MODE stringToParentingMode2D(const std::string& parentingMode); 224 225 static const char* layer2DToChar(E2D_LAYER layer); 226 static E2D_LAYER charToLayer2D(const std::string& layer); 227 228 static bool layerSortPredicate(const Element2D* elem1, const Element2D* elem2); 229 230 private: 231 void eraseChild2D(Element2D* child); 232 /** tells the child that the parent's Coordinate has changed */ 233 inline void parentCoorChanged2D () { this->bRelCoorChanged = true; } 234 /** tells the child that the parent's Direction has changed */ 235 inline void parentDirChanged2D () { this->bRelDirChanged = true; } 236 /** @returns the last calculated coordinate */ 237 inline Vector2D getLastAbsCoor2D() { return this->lastAbsCoordinate; } 238 239 void reparent2D(); 240 static Element2D* createNullElement(); 241 bool checkIntegrity(const Element2D* checkParent) const; 242 243 244 private: 245 const PNode* bindNode; //!< a node over which to display this 2D-element 246 Vector2D size; //!< The size of the rendered item 247 Vector2D* toSize; //!< The Size to iterate to. 248 249 E2D_ALIGNMENT alignment; //!< How the Element is aligned around its Position 250 251 bool bVisible; //!< If the given Element2D is visible. 252 bool bCurrentlyVisible; //!< Evaluated in the TICK process, to see if the Element is Currently visible. 253 bool bActive; //!< If the given Element2D is active. 254 E2D_LAYER layer; //!< What layer this Element2D is on. 255 256 bool bRelCoorChanged; //!< If Relative Coordinate has changed since last time we checked 257 bool bRelDirChanged; //!< If Relative Direction has changed since last time we checked 258 259 Vector2D relCoordinate; //!< coordinates relative to the parent 260 Vector2D absCoordinate; //!< absolute coordinates in the world ( from (0,0,0) ) 261 float relDirection; //!< direction relative to the parent 262 float absDirection; //!< absolute diretion in the world ( from (0,0,1) ) 263 264 Vector2D prevRelCoordinate; //!< The last Relative Coordinate from the last update-Cycle. 265 Vector2D lastAbsCoordinate; //!< this is used for speedcalculation, it stores the last coordinate 266 float prevRelDirection; //!< The last Relative Direciton from the last update-Cycle. 267 268 Vector2D velocity; //!< Saves the velocity. 269 270 Vector2D* toCoordinate; //!< a position to which to iterate. (This is used in conjunction with setParentSoft.and set*CoorSoft) 271 float* toDirection; //!< a direction to which to iterate. (This is used in conjunction with setParentSoft and set*DirSoft) 272 float bias; //!< how fast to iterate to the given position (default is 1) 273 274 Element2D* parent; //!< a pointer to the parent node 275 std::list<Element2D*> children; //!< list of the children of this Element2D 276 277 unsigned int parentMode; //!< the mode of the binding 278 279 static Element2D* nullElement; //!< The top-most Element 89 class Element2D : virtual public BaseObject 90 { 91 ObjectListDeclaration(Element2D); 92 93 public: 94 Element2D(Element2D* parent = Element2D::getNullElement(), E2D_LAYER layer = E2D_DEFAULT_LAYER, short nodeFlags = E2D_PARENT_MODE_DEFAULT); 95 virtual ~Element2D(); 96 97 virtual void loadParams(const TiXmlElement* root); 98 99 // ACTIVATION // 100 inline void activate2D() { this->bActive = this->bRelCoorChanged = this->bRelDirChanged = true; }; 101 inline void deactivate2D() { this->bActive = false; }; 102 inline bool get2DActiveState() { return this->bActive; }; 103 104 // ALIGNMENT // 105 /** @param alignment the new Alignment of the 2D-Element */ 106 inline void setAlignment(E2D_ALIGNMENT alignment) { this->alignment = alignment; }; 107 void setAlignment(const std::string& alignment); 108 inline E2D_ALIGNMENT getAlignment() const { return this->alignment; }; 109 110 // LAYERING // 111 void setLayer(E2D_LAYER layer); 112 void setLayer(const std::string& layer); 113 /** @returns the Layer this Element is drawn to */ 114 inline E2D_LAYER getLayer() const { return this->layer; }; 115 116 // VISIBILITY // 117 /** @param visible true if the Element should be visible false otherwise (will not be rendered) */ 118 inline void setVisibility(bool visible) { this->bVisible = visible; }; 119 /** @returns the visibility state */ 120 inline bool isVisible() const { return (this->bVisible && this->bCurrentlyVisible); }; 121 122 123 // POSITIONAL (E2D-specials) // 124 /** @param bindNode the Node this 2D-element should follow. if NULL the Element will not follow anything */ 125 void setBindNode(const PNode* bindNode); 126 void setBindNode(const std::string& bindNode); 127 inline const PNode* getBindNode() const { return this->bindNode; }; 128 129 inline void setSize2D(float x, float y) { this->size = Vector2D(x, y); }; 130 inline void setSize2D(const Vector2D& size) { this->size = size; }; 131 inline const Vector2D& getSize2D() const { return this->size; }; 132 void setSizeSoft2D(float x, float y, float bias = 1.0); 133 inline void setSizeX2D(float x) { this->size.x = x; }; 134 inline void setSizeY2D(float y) { this->size.y = y; }; 135 inline float getSizeX2D() const { return this->size.x; }; 136 inline float getSizeY2D() const { return this->size.y; }; 137 138 public: 139 virtual void tick(float dt) {}; 140 virtual void draw() const {}; 141 void tick2D(float dt); 142 void draw2D(E2D_LAYER from, E2D_LAYER to) const; 143 void drawChildren(E2D_LAYER from, E2D_LAYER to) const; 144 145 // LIKE PNODE 146 public: 147 void setRelCoor2D (const Vector2D& relCoord); 148 void setRelCoorX2D(float x); 149 void setRelCoorY2D(float y); 150 void setRelCoor2D (float x, float y); 151 void setRelCoor2Dpx (int x, int y); 152 void setRelCoorSoft2D (const Vector2D& relCoordSoft, float bias = 1.0); 153 void setRelCoorSoft2D (float x, float y, float bias = 1.0); 154 void setRelCoorSoft2Dpx (int x, int y, float bias = 1.0); 155 /** @returns the relative position */ 156 inline const Vector2D& getRelCoor2D () const { return this->prevRelCoordinate; }; 157 /** @returns the Relative Coordinate Destination */ 158 inline const Vector2D& getRelCoorSoft2D() const { return (this->toCoordinate)?*this->toCoordinate:this->relCoordinate; }; 159 const Vector2D& getRelCoor2Dpx() const; 160 void setAbsCoor2D (const Vector2D& absCoord); 161 void setAbsCoor2D (float x, float y); 162 void setAbsCoorX2D(float x); 163 void setAbsCoorY2D(float y); 164 void setAbsCoor2Dpx (int x, int y); 165 void setAbsCoorSoft2D (const Vector2D& absCoordSoft, float bias = 1.0); 166 void setAbsCoorSoft2D (float x, float y, float bias = 1.0); 167 /** @returns the absolute position */ 168 inline const Vector2D& getAbsCoor2D () const { return this->absCoordinate; }; 169 const Vector2D& getAbsCoor2Dpx () const; 170 171 void shiftCoor2D (const Vector2D& shift); 172 void shiftCoor2Dpx (int x, int y); 173 174 void setRelDir2D (float relDir); 175 void setRelDirSoft2D(float relDirSoft, float bias = 1.0); 176 /** @returns the relative Direction */ 177 inline float getRelDir2D () const { return this->prevRelDirection; }; 178 /** @returns the Relative Directional Destination */ 179 inline float getRelDirSoft2D() const { return (this->toDirection)?*this->toDirection:this->relDirection; }; 180 void setAbsDir2D (float absDir); 181 void setAbsDirSoft2D (float absDirSoft, float bias = 1.0); 182 /** @returns the absolute Direction */ 183 inline float getAbsDir2D () const { return this->absDirection; }; 184 void shiftDir2D (float shiftDir); 185 186 /** @returns the Speed of the Node */ 187 inline float getSpeed() const { return 0; }; 188 /** @returns the Velocity of the Node */ 189 inline const Vector2D& getVelocity() const { return this->velocity; }; 190 191 192 void addChild2D (Element2D* child); 193 void addChild2D (const std::string& childName); 194 void removeChild2D (Element2D* child); 195 void remove2D(); 196 197 /** @param parent the new parent of this Element2D */ 198 void setParent2D (Element2D* parent) { parent->addChild2D(this); }; 199 void setParent2D (const std::string& parentName); 200 /** @returns the parent of this Element2D */ 201 inline Element2D* getParent2D () const { return this->parent; }; 202 /** @returns the List of Children of this Element2D */ 203 inline const std::list<Element2D*>& getChildren2D() const { return this->children; }; 204 205 void setParentSoft2D(Element2D* parentNode, float bias = 1.0); 206 void setParentSoft2D(const std::string& parentName, float bias = 1.0); 207 208 void setParentMode2D (E2D_PARENT_MODE parentMode); 209 void setParentMode2D (const std::string& parentingMode); 210 /** @returns the Parenting mode of this node */ 211 int getParentMode2D() const { return this->parentMode; }; 212 213 // NULL_PARENT // 214 /** @returns the NullParent, the (main) ROOT of the PNode Tree. If it does not yet exist, it will be created. */ 215 static Element2D* getNullElement() { return (Element2D::nullElement != NULL)? Element2D::nullElement : Element2D::createNullElement(); }; 216 217 218 void update2D (float dt); 219 220 void debug2D (unsigned int depth = 1, unsigned int level = 0) const; 221 void debugDraw2D(unsigned int depth = 1, float size = 1.0, Vector color = Vector(1,0,0), unsigned int level = 0) const; 222 223 // helper functions // 224 static const char* parentingModeToString2D(int parentingMode); 225 static E2D_PARENT_MODE stringToParentingMode2D(const std::string& parentingMode); 226 227 static const char* layer2DToChar(E2D_LAYER layer); 228 static E2D_LAYER charToLayer2D(const std::string& layer); 229 230 static bool layerSortPredicate(const Element2D* elem1, const Element2D* elem2); 231 232 private: 233 void eraseChild2D(Element2D* child); 234 /** tells the child that the parent's Coordinate has changed */ 235 inline void parentCoorChanged2D () { this->bRelCoorChanged = true; } 236 /** tells the child that the parent's Direction has changed */ 237 inline void parentDirChanged2D () { this->bRelDirChanged = true; } 238 /** @returns the last calculated coordinate */ 239 inline Vector2D getLastAbsCoor2D() { return this->lastAbsCoordinate; } 240 241 void reparent2D(); 242 static Element2D* createNullElement(); 243 bool checkIntegrity(const Element2D* checkParent) const; 244 245 246 private: 247 const PNode* bindNode; //!< a node over which to display this 2D-element 248 Vector2D size; //!< The size of the rendered item 249 Vector2D* toSize; //!< The Size to iterate to. 250 251 E2D_ALIGNMENT alignment; //!< How the Element is aligned around its Position 252 253 bool bVisible; //!< If the given Element2D is visible. 254 bool bCurrentlyVisible; //!< Evaluated in the TICK process, to see if the Element is Currently visible. 255 bool bActive; //!< If the given Element2D is active. 256 E2D_LAYER layer; //!< What layer this Element2D is on. 257 258 bool bRelCoorChanged; //!< If Relative Coordinate has changed since last time we checked 259 bool bRelDirChanged; //!< If Relative Direction has changed since last time we checked 260 261 Vector2D relCoordinate; //!< coordinates relative to the parent 262 Vector2D absCoordinate; //!< absolute coordinates in the world ( from (0,0,0) ) 263 float relDirection; //!< direction relative to the parent 264 float absDirection; //!< absolute diretion in the world ( from (0,0,1) ) 265 266 Vector2D prevRelCoordinate; //!< The last Relative Coordinate from the last update-Cycle. 267 Vector2D lastAbsCoordinate; //!< this is used for speedcalculation, it stores the last coordinate 268 float prevRelDirection; //!< The last Relative Direciton from the last update-Cycle. 269 270 Vector2D velocity; //!< Saves the velocity. 271 272 Vector2D* toCoordinate; //!< a position to which to iterate. (This is used in conjunction with setParentSoft.and set*CoorSoft) 273 float* toDirection; //!< a direction to which to iterate. (This is used in conjunction with setParentSoft and set*DirSoft) 274 float bias; //!< how fast to iterate to the given position (default is 1) 275 276 Element2D* parent; //!< a pointer to the parent node 277 std::list<Element2D*> children; //!< list of the children of this Element2D 278 279 unsigned int parentMode; //!< the mode of the binding 280 281 static Element2D* nullElement; //!< The top-most Element 280 282 }; 281 283 -
trunk/src/lib/graphics/render2D/image_plane.cc
r9406 r9869 21 21 22 22 #include "graphics_engine.h" 23 #include "glincl.h"24 23 #include "p_node.h" 25 24 26 25 26 #include "class_id_DEPRECATED.h" 27 27 28 29 30 CREATE_FACTORY(ImagePlane, CL_IMAGE_ENTITY); 28 ObjectListDefinitionID(ImagePlane, CL_IMAGE_PLANE); 29 CREATE_FACTORY(ImagePlane); 31 30 32 31 … … 56 55 void ImagePlane::init() 57 56 { 58 this-> setClassID(CL_IMAGE_PLANE, "ImagePlane");57 this->registerObject(this, ImagePlane::_objectList); 59 58 this->setName("ImagePlane"); 60 59 -
trunk/src/lib/graphics/render2D/image_plane.h
r7843 r9869 17 17 class ImagePlane : public Element2D 18 18 { 19 19 ObjectListDeclaration(ImagePlane); 20 20 public: 21 21 ImagePlane(const TiXmlElement* root = NULL); -
trunk/src/lib/graphics/render2D/render_2d.cc
r9406 r9869 19 19 20 20 #include "graphics_engine.h" 21 #include "class_list.h"22 21 #include "element_2d.h" 23 22 23 ObjectListDefinition(Render2D); 24 24 25 25 … … 29 29 Render2D::Render2D () 30 30 { 31 this->setClassID(CL_RENDER_2D, "Render2D");32 31 this->registerObject(this, Render2D::_objectList); 32 this->setName("Render2D"); 33 33 34 34 this->showNodes = false; 35 35 } 36 36 -
trunk/src/lib/graphics/render2D/render_2d.h
r7840 r9869 12 12 13 13 //! A default singleton class. 14 class Render2D : public BaseObject { 14 class Render2D : public BaseObject 15 { 16 ObjectListDeclaration(Render2D); 17 15 18 friend class Element2D; 16 19 17 18 19 20 20 public: 21 virtual ~Render2D(); 22 /** @returns a Pointer to the only object of this Class */ 23 inline static Render2D* getInstance() { if (!singletonRef) singletonRef = new Render2D(); return singletonRef; }; 21 24 22 25 void toggleNodesVisibility() { this->showNodes = !this->showNodes; }; 23 26 24 25 26 27 void update(float dt); 28 void tick(float dt); 29 void draw(E2D_LAYER from, E2D_LAYER to) const; 27 30 28 29 30 31 private: 32 Render2D(); 33 static Render2D* singletonRef; //!< Reference to this class. 31 34 32 33 35 bool showNodes; //!< If the debug-Nodes should be visible 36 }; 34 37 35 38 #endif /* _RENDER_2D_H */ -
trunk/src/lib/graphics/shader.cc
r9406 r9869 18 18 #include "shader.h" 19 19 20 #include "stdlibincl.h"21 20 #include "compiler.h" 22 21 //#include <stdio.h> … … 25 24 #include "debug.h" 26 25 27 #include "util/loading/resource_manager.h"28 26 29 27 … … 33 31 34 32 33 ObjectListDefinition(Shader); 35 34 35 void Shader::Uniform::setV(unsigned int count, float* vv) const 36 { 37 switch (count) 38 { 39 case 1: 40 glUniform1fv(this->uniform, 1, vv); 41 break; 42 case 2: 43 glUniform2fv(this->uniform, 2, vv); 44 break; 45 case 3: 46 glUniform3fv(this->uniform, 3, vv); 47 break; 48 case 4: 49 glUniform4fv(this->uniform, 4, vv); 50 break; 51 } 52 } 53 void Shader::Uniform::setV(unsigned int count, int* vv) const 54 { 55 switch (count) 56 { 57 case 1: 58 glUniform1iv(this->uniform, 1, vv); 59 break; 60 case 2: 61 glUniform2iv(this->uniform, 2, vv); 62 break; 63 case 3: 64 glUniform3iv(this->uniform, 3, vv); 65 break; 66 case 4: 67 glUniform4iv(this->uniform, 4, vv); 68 break; 69 } 70 } 71 72 73 74 Shader::Shader() 75 : data(new ShaderData) 76 { 77 78 } 36 79 37 80 /** … … 39 82 */ 40 83 Shader::Shader (const std::string& vertexShaderFile, const std::string& fragmentShaderFile) 84 : data(new ShaderData) 41 85 { 42 this->setClassID(CL_SHADER, "Shader"); 86 if (!Shader::checkShaderAbility()) 87 PRINTF(2)("Your system does not support shaders\n"); 88 this->load(vertexShaderFile, fragmentShaderFile); 43 89 44 this->shaderProgram = 0;45 this->vertexShader = 0;46 this->fragmentShader = 0;47 48 if (GLEW_ARB_shader_objects && GLEW_ARB_shading_language_100)49 {50 this->shaderProgram = glCreateProgramObjectARB();51 52 if (!vertexShaderFile.empty())53 this->loadShaderProgramm(Shader::Vertex, vertexShaderFile);54 if (!fragmentShaderFile.empty())55 this->loadShaderProgramm(Shader::Fragment, fragmentShaderFile);56 57 this->linkShaderProgram();58 59 }60 else61 {62 PRINTF(2)("Shaders are not supported on your hardware\n");63 }64 90 } 65 91 92 const Shader* Shader::storedShader = NULL; 66 93 67 /** 68 * standard deconstructor 69 */ 70 Shader::~Shader () 94 void Shader::activateShader() const 71 95 { 72 if (this->shaderProgram == glGetHandleARB(GL_PROGRAM_OBJECT_ARB)) 73 Shader::deactivateShader(); 74 75 // delete what has to be deleted here 76 this->deleteProgram(Shader::Vertex); 77 this->deleteProgram(Shader::Fragment); 78 79 if (this->fragmentShader != 0) 96 if (likely (this->getProgram() != 0)) 80 97 { 81 glDetachObjectARB(this->shaderProgram, this->fragmentShader); 82 glDeleteObjectARB(this->fragmentShader); 83 } 84 if (this->vertexShader != 0) 85 { 86 glDetachObjectARB(this->shaderProgram, this->vertexShader); 87 glDeleteObjectARB(this->vertexShader); 88 } 89 if (this->shaderProgram != 0) 90 { 91 GLint status = 0; 92 //glLinkProgramARB(this->shaderProgram); 93 glDeleteObjectARB(this->shaderProgram); 94 // link error checking 95 glGetObjectParameterivARB(this->shaderProgram, GL_OBJECT_DELETE_STATUS_ARB, &status); 96 if (status == GL_INVALID_VALUE || status == GL_INVALID_OPERATION) 97 this->printError(this->shaderProgram); 98 } 99 } 100 101 Shader* Shader::getShader(const std::string& vertexShaderFile, const std::string& fragmentShaderFile) 102 { 103 return (Shader*)ResourceManager::getInstance()->load(vertexShaderFile, SHADER, RP_LEVEL, fragmentShaderFile); 104 } 105 106 bool Shader::unload(Shader* shader) 107 { 108 return ResourceManager::getInstance()->unload(shader); 109 } 110 111 Shader* Shader::storedShader = NULL; 112 113 114 bool Shader::loadShaderProgramm(Shader::Type type, const std::string& fileName) 115 { 116 GLhandleARB shader = 0; 117 118 if (type != Shader::Vertex && type != Shader::Fragment) 119 return false; 120 this->deleteProgram(type); 121 122 123 std::string program; 124 if (!readShader(fileName, program)) 125 return false; 126 127 if (type == Shader::Vertex && GLEW_ARB_vertex_shader) 128 { 129 this->vertexShaderFile = fileName; 130 131 shader = this->vertexShader = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB); 132 } 133 134 if (type == Shader::Fragment && GLEW_ARB_fragment_shader) 135 { 136 this->fragmentShaderFile = fileName; 137 138 shader = this->fragmentShader = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB); 139 } 140 141 if (shader != 0) 142 { 143 GLint status = 0; 144 const char* prog = program.c_str(); 145 146 glShaderSourceARB(shader, 1, &prog, NULL); 147 glCompileShaderARB(shader); 148 // checking on error. 149 glGetObjectParameterivARB(shader, GL_OBJECT_COMPILE_STATUS_ARB, &status); 150 if (status == GL_INVALID_VALUE || status == GL_INVALID_OPERATION) 151 this->printError(shader); 152 else 153 glAttachObjectARB(this->shaderProgram, shader); 154 } 155 return true; 156 } 157 158 159 void Shader::linkShaderProgram() 160 { 161 GLint status = 0; 162 163 glLinkProgramARB(this->shaderProgram); 164 // link error checking 165 glGetObjectParameterivARB(this->shaderProgram, GL_OBJECT_LINK_STATUS_ARB, &status); 166 if (status == GL_INVALID_VALUE || status == GL_INVALID_OPERATION) 167 this->printError(this->shaderProgram); 168 } 169 170 171 bool Shader::readShader(const std::string& fileName, std::string& output) 172 { 173 char lineBuffer[PARSELINELENGTH]; 174 175 std::ifstream shader; 176 shader.open(fileName.c_str()); 177 if (!shader.is_open()) 178 return false; 179 180 181 while (!shader.eof()) 182 { 183 shader.getline(lineBuffer, PARSELINELENGTH); 184 output += lineBuffer; 185 output += "\n"; 186 } 187 188 189 shader.close(); 190 return true; 191 } 192 193 194 195 void Shader::activateShader() 196 { 197 if (likely (this->shaderProgram != 0)) 198 { 199 glUseProgramObjectARB(this->shaderProgram); 98 glUseProgramObjectARB(this->getProgram()); 200 99 Shader::storedShader = this; 201 100 } 202 101 } 203 204 void Shader::bindShader(const char* name, const float* value, size_t size)205 {206 if (likely (this->shaderProgram != 0)) {207 glUseProgramObjectARB(this->shaderProgram);208 209 unsigned int location = glGetUniformLocationARB(this->shaderProgram, name);210 /* This is EXPENSIVE and should be avoided. */211 212 if (size == 1) glUniform1fvARB(location, 1, value);213 else if (size == 2) glUniform2fvARB(location, 1, value);214 else if (size == 3) glUniform3fvARB(location, 1, value);215 else if (size == 4) glUniform4fvARB(location, 1, value);216 else if (size == 9) glUniformMatrix3fvARB(location, 1, false, value);217 else if (size == 16) glUniformMatrix4fvARB(location, 1, false, value);218 219 }220 }221 222 102 void Shader::deactivateShader() 223 103 { 224 if (storedShader != NULL) 225 glUseProgramObjectARB(0); 226 Shader::storedShader = NULL; 227 } 228 229 230 void Shader::deleteProgram(Shader::Type type) 231 { 232 GLint status = 0; 233 if (type == Shader::Vertex && this->vertexShader != 0) 234 { 235 this->vertexShaderFile = ""; 236 glDetachObjectARB(this->shaderProgram, this->vertexShader); 237 glDeleteObjectARB(this->vertexShader); 238 glGetObjectParameterivARB(this->vertexShader, GL_OBJECT_DELETE_STATUS_ARB, &status); 239 if (status == GL_INVALID_VALUE || status == GL_INVALID_OPERATION) 240 Shader::printError(this->vertexShader); 241 this->vertexShader = 0; 242 } 243 else if (type == Shader::Fragment && this->fragmentShader != 0) 244 { 245 this->fragmentShaderFile = ""; 246 glDetachObjectARB(this->shaderProgram, this->fragmentShader); 247 glDeleteObjectARB(this->fragmentShader); 248 glGetObjectParameterivARB(this->fragmentShader, GL_OBJECT_DELETE_STATUS_ARB, &status); 249 if (status == GL_INVALID_VALUE || status == GL_INVALID_OPERATION) 250 Shader::printError(this->fragmentShader); 251 this->fragmentShader = 0; 252 } 253 else 254 return; 255 } 256 257 258 void Shader::printError(GLhandleARB program) 259 { 260 if (program == 0) 261 return; 262 263 int infologLength = 0; 264 int charsWritten = 0; 265 char *infoLog; 266 267 glGetObjectParameterivARB(program, GL_OBJECT_INFO_LOG_LENGTH_ARB, 268 &infologLength); 269 270 if (infologLength > 0) 271 { 272 infoLog = new char[infologLength+1]; 273 glGetInfoLogARB(program, infologLength, &charsWritten, infoLog); 274 printf("%s\n", infoLog); 275 delete[] infoLog; 276 } 104 if (storedShader != NULL) 105 glUseProgramObjectARB(0); 106 Shader::storedShader = NULL; 277 107 } 278 108 … … 288 118 } 289 119 290 void Shader::debug() const291 {292 PRINT(3)("Shader info: (SHADER: %d)\n", this->shaderProgram);293 if (this->vertexShader != 0)294 {295 /* PRINT(3)("VertexShaderProgramm: number=%d, file='%s'\n", this->vertexShader, this->vertexShaderFile);296 if (this->vertexShaderSource != NULL)297 for (unsigned int i = 0; i < this->vertexShaderSource->getCount(); i++)298 PRINT(3)("%d: %s\n", i, this->vertexShaderSource->getEntry(i));299 }300 if (this->fragmentShader != 0)301 {302 PRINT(3)("FragmentShaderProgramm: number=%d, file='%s'\n", this->fragmentShader, this->fragmentShaderFile);303 if (this->fragmentShaderSource != NULL)304 for (unsigned int i = 0; i < this->fragmentShaderSource->getCount(); i++)305 PRINT(3)("%d: %s\n", i, this->fragmentShaderSource->getEntry(i));*/306 }307 }308 120 -
trunk/src/lib/graphics/shader.h
r8255 r9869 8 8 9 9 #include "base_object.h" 10 #include "glincl.h" 11 #include <vector> 12 10 #include "shader_data.h" 13 11 14 12 // FORWARD DECLARATION … … 16 14 17 15 18 //! A class for ...16 //! The Shader is a Class-wrapper around the OpenGL Shader Language (GLSL). 19 17 class Shader : public BaseObject 20 18 { 19 ObjectListDeclaration(Shader); 21 20 public: 22 21 class Uniform 23 22 { 24 23 public: 25 Uniform(const Shader* shader, const std::string& location) { this->uniform = glGetUniformLocationARB(shader->getProgram(), location.c_str()) ; }26 24 Uniform(const Shader& shader, const std::string& location) { this->uniform = glGetUniformLocation(shader.getProgram(), location.c_str()) ; }; 27 25 Uniform(GLhandleARB shaderProgram, const std::string& location) { this->uniform = glGetUniformLocation(shaderProgram, location.c_str()) ; }; … … 37 35 void set(int v0, int v1, int v2, int v3) const { glUniform4i(this->uniform, v0, v1, v2, v3); } 38 36 39 void setV(unsigned int count, float* vv) const 40 { 41 switch (count) 42 { 43 case 1: 44 glUniform1fv(this->uniform, 1, vv); 45 break; 46 case 2: 47 glUniform2fv(this->uniform, 2, vv); 48 break; 49 case 3: 50 glUniform3fv(this->uniform, 3, vv); 51 break; 52 case 4: 53 glUniform4fv(this->uniform, 4, vv); 54 break; 55 } 56 } 57 void setV(unsigned int count, int* vv) const 58 { 59 switch (count) 60 { 61 case 1: 62 glUniform1iv(this->uniform, 1, vv); 63 break; 64 case 2: 65 glUniform2iv(this->uniform, 2, vv); 66 break; 67 case 3: 68 glUniform3iv(this->uniform, 3, vv); 69 break; 70 case 4: 71 glUniform4iv(this->uniform, 4, vv); 72 break; 73 } 74 } 75 private: 37 void setV(unsigned int count, float* vv) const; 38 void setV(unsigned int count, int* vv) const; 39 40 private: 76 41 GLint uniform; 77 42 }; 78 43 79 typedef enum80 {81 None = 0,82 Fragment = 1,83 Vertex = 2,84 85 Program = 4,86 }87 Type;88 44 89 45 public: 90 Shader(const std::string& vertexShaderFile = "", const std::string& fragmentShaderFile = ""); 91 virtual ~Shader(); 92 static Shader* getShader(const std::string& vertexShaderFile, const std::string& fragmentShaderFile); 93 static bool unload(Shader* shader); 46 Shader(); 47 Shader(const std::string& vertexShaderFile, const std::string& fragmentShaderFile = ""); 48 49 Shader& operator=(const Shader& shader) { this->data = shader.data; return *this; }; 50 const ShaderData::Pointer& dataPointer() const { return data; }; 51 void acquireData(const ShaderData::Pointer& pointer) { this->data = pointer; }; 52 53 bool load(const std::string& vertexShaderFile, const std::string& fragmentShaderFile = "") 54 { return this->data->load(vertexShaderFile, fragmentShaderFile); } 55 56 57 Shader::Uniform getUniform(const std::string& location) { return Shader::Uniform(*this, location); } 58 59 GLhandleARB getProgram() const { return this->data->getProgram(); } 60 GLhandleARB getVertexS() const { return this->data->getVertexS(); } 61 GLhandleARB getFragmentS() const { return this->data->getFragmentS(); } 62 63 void activateShader() const; 64 static void deactivateShader(); 65 66 void debug() const { this->data->debug(); }; 94 67 95 68 96 69 static bool checkShaderAbility(); 97 void activateShader();98 void bindShader(const char* name, const float* value, size_t size);99 static void deactivateShader();100 70 101 Shader::Uniform getUniform(const std::string& location) { return Shader::Uniform(this, location); } 71 inline static bool isShaderActive() { return (Shader::storedShader != NULL) ? true : false; }; 72 inline static const Shader* getActiveShader() { return Shader::storedShader; }; 102 73 103 bool loadShaderProgramm(Shader::Type type, const std::string& fileName); 104 void deleteProgram(Shader::Type type); 105 106 void linkShaderProgram(); 107 108 109 bool readShader(const std::string& fileName, std::string& output); 110 111 112 inline static bool shaderActive() { return (Shader::storedShader != NULL)? true : false; }; 113 inline static Shader* getActiveShader() { return Shader::storedShader; }; 114 inline static void suspendShader() { Shader* currShader = storedShader; if (storedShader!= NULL) { Shader::deactivateShader(); Shader::storedShader = currShader;} }; 74 inline static void suspendShader() { const Shader* currShader = storedShader; if (storedShader!= NULL) { Shader::deactivateShader(); Shader::storedShader = currShader;} }; 115 75 inline static void restoreShader() { if (storedShader != NULL) storedShader->activateShader(); storedShader = NULL; }; 116 76 77 private: 78 ShaderData::Pointer data; 117 79 118 119 120 GLhandleARB getProgram() const { return this->shaderProgram; } 121 GLhandleARB getVertexS() const { return this->vertexShader; } 122 GLhandleARB getFragmentS() const { return this->fragmentShader; } 123 124 void debug() const; 125 126 static void printError(GLhandleARB program); 127 128 129 private: 130 std::string fragmentShaderFile; 131 std::string vertexShaderFile; 132 133 GLhandleARB shaderProgram; 134 135 GLhandleARB vertexShader; 136 GLhandleARB fragmentShader; 137 138 139 static Shader* storedShader; 80 static const Shader* storedShader; 140 81 }; 141 82 -
trunk/src/lib/graphics/spatial_separation/quadtree.cc
r9406 r9869 27 27 #define QUADTREE_MATERIAL_COUNT 4 28 28 29 ObjectListDefinition(Quadtree); 29 30 /** 30 31 * standard constructor … … 32 33 Quadtree::Quadtree (const modelInfo* pModelInfo, const int treeDepth) 33 34 { 34 this-> setClassID(CL_QUADTREE, "Quadtree");35 this->registerObject(this, Quadtree::_objectList); 35 36 this->pModelInfo = pModelInfo; 36 37 this->treeDepth = treeDepth; -
trunk/src/lib/graphics/spatial_separation/quadtree.h
r6022 r9869 21 21 //! A class for quadtree separation of the world 22 22 class Quadtree : public BaseObject { 23 23 ObjectListDeclaration(Quadtree); 24 24 25 25 public: -
trunk/src/lib/graphics/spatial_separation/quadtree_node.cc
r9406 r9869 27 27 28 28 29 29 ObjectListDefinition(QuadtreeNode); 30 30 31 31 /** … … 102 102 void QuadtreeNode::init() 103 103 { 104 this-> setClassID(CL_QUADTREE_NODE, "QuadtreeNode");104 this->registerObject(this, QuadtreeNode::_objectList); 105 105 106 106 /* init the rest of the variables for both init types */ -
trunk/src/lib/graphics/spatial_separation/quadtree_node.h
r6617 r9869 26 26 //! A class for a Quadtree Node representation 27 27 class QuadtreeNode : public BaseObject { 28 ObjectListDeclaration(QuadtreeNode); 28 29 29 30 public: -
trunk/src/lib/graphics/spatial_separation/spatial_separation.cc
r9406 r9869 24 24 25 25 26 26 ObjectListDefinition(SpatialSeparation); 27 27 28 28 /** 29 * standard constructor29 * @brief standard constructor 30 30 * @param model the model that is to be separated 31 31 * @param overlapSize each box will overlap for a given size 32 33 34 32 * 33 * The boxes are overlaping because this makes collision detection a lot simpler 34 * 35 35 */ 36 36 SpatialSeparation::SpatialSeparation (Model* model, float overlapSize) … … 39 39 PRINT(3)("+-| (Event) Spatial Separation process kicked on\n"); 40 40 41 this-> setClassID(CL_SPATIAL_SEPARATION, "SpatialSeparation");41 this->registerObject(this, SpatialSeparation::_objectList); 42 42 /* debug vice */ 43 43 this->createQuadtree(model); … … 46 46 47 47 /** 48 * standard constructor48 * @brief standard constructor 49 49 * @param model the model that is to be separated 50 50 * @param overlapSize each box will overlap for a given size … … 54 54 SpatialSeparation::SpatialSeparation (Model* model, Model* playerModel) 55 55 { 56 this-> setClassID(CL_SPATIAL_SEPARATION, "SpatialSeparation");56 this->registerObject(this, SpatialSeparation::_objectList); 57 57 58 58 } … … 60 60 61 61 /** 62 * standard deconstructor62 * @brief standard deconstructor 63 63 */ 64 64 SpatialSeparation::~SpatialSeparation () … … 70 70 71 71 /** 72 * creates a quadtree72 * @brief creates a quadtree 73 73 * @param model the model to do a quadtree on 74 74 * @param minLength the minimal length of a quadtree node … … 83 83 84 84 /** 85 * 85 * @brief creates a quadtree 86 86 * @param model the model to do a quadtree on 87 87 * @param minLength the minimal length of a quadtree node … … 95 95 96 96 /** 97 * creates a quadtree97 * @brief creates a quadtree 98 98 * @param model the model to do a quadtree on 99 99 * @param minLength the minimal length of a quadtree node … … 109 109 110 110 /** 111 * draws all the quadtrees111 * @brief draws all the quadtrees 112 112 */ 113 113 void SpatialSeparation::drawQuadtree() … … 118 118 this->quadtree->drawTree(); 119 119 } 120 121 122 123 124 125 126 127 128 129 130 131 -
trunk/src/lib/graphics/spatial_separation/spatial_separation.h
r6022 r9869 19 19 //! A class for spatial separation of vertices based arrays 20 20 class SpatialSeparation : public BaseObject { 21 ObjectListDeclaration(SpatialSeparation); 21 22 22 23 public: -
trunk/src/lib/graphics/text_engine/font.cc
r8989 r9869 29 29 #include "compiler.h" 30 30 31 ObjectListDefinition(Font); 31 32 32 33 Font::Font() … … 34 35 { 35 36 this->init(); 36 37 37 } 38 38 … … 118 118 Material::operator=(font); 119 119 this->data = font.data; 120 this->setTexture(this->data->textureData()); 120 121 121 122 return *this; … … 130 131 this->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 131 132 132 this-> setClassID(CL_FONT, "Font");133 if (Font::defaultFontData. get() == NULL)133 this->registerObject(this, Font::_objectList); 134 if (Font::defaultFontData.isNull()) 134 135 { 135 136 Font::initDefaultFont(); … … 138 139 } 139 140 140 FontData Pointer Font::defaultFontData(NULL);141 FontData::Pointer Font::defaultFontData(NULL); 141 142 142 143 /** … … 146 147 { 147 148 // temporarily create a Font. 148 Font::defaultFontData = FontData Pointer(new FontData);149 Font::defaultFontData = FontData::Pointer(new FontData); 149 150 // apply the Data. 150 151 Font::defaultFontData = Font(font_xpm).data; … … 159 160 bool Font::loadFontFromTTF(const std::string& fontFile, unsigned int renderSize) 160 161 { 161 this->data = FontData Pointer (new FontData());162 this->data = FontData::Pointer (new FontData()); 162 163 bool retVal = this->data->loadFontFromTTF(fontFile, renderSize); 163 164 if (!retVal) … … 174 175 bool Font::loadFontFromSDL_Surface(SDL_Surface* surface) 175 176 { 176 this->data = FontData Pointer (new FontData());177 this->data = FontData::Pointer (new FontData()); 177 178 bool retVal = this->data->loadFontFromSDL_Surface(surface); 178 179 if (!retVal) … … 196 197 197 198 198 void Font::setTexture(const TextureData Pointer& texDataPointer)199 void Font::setTexture(const TextureData::Pointer& texDataPointer) 199 200 { 200 201 this->setDiffuseMap(texDataPointer); -
trunk/src/lib/graphics/text_engine/font.h
r8766 r9869 19 19 class Font : public Material 20 20 { 21 21 ObjectListDeclaration(Font); 22 public: 23 typedef FontData::Glyph Glyph; 22 24 public: 23 25 Font(); … … 39 41 40 42 /** @returns a Pointer to the Array of Glyphs */ 41 inline Glyph**getGlyphArray() const { return this->data->getGlyphArray(); };43 inline const Glyph* const * const getGlyphArray() const { return this->data->getGlyphArray(); }; 42 44 43 45 inline int getMaxHeight() const { return data->getMaxHeight(); }; … … 50 52 void debug() const; 51 53 54 void acquireData(const FontData::Pointer& data) { this->data = data; }; 55 const FontData::Pointer& dataPointer() const { return data; }; 52 56 private: 53 57 void init(); 54 58 static void initDefaultFont(); 55 59 56 void setTexture(const TextureData Pointer& texDataPointer);60 void setTexture(const TextureData::Pointer& texDataPointer); 57 61 58 62 private: 59 FontData Pointerdata; //!< A Data-Pointer to a Font.63 FontData::Pointer data; //!< A Data-Pointer to a Font. 60 64 61 static FontData PointerdefaultFontData; //!< a default font, that is used, if other fonts were unable to be loaded.65 static FontData::Pointer defaultFontData; //!< a default font, that is used, if other fonts were unable to be loaded. 62 66 }; 63 67 -
trunk/src/lib/graphics/text_engine/font_data.h
r8768 r9869 26 26 #define FONT_DEFAULT_RENDER_SIZE 50 //!< At what Resolution to render fonts. 27 27 28 class FontData 29 { 30 31 32 public: 33 28 34 //! A struct for handling glyphs 29 35 /** 30 36 * a Glyph is one letter of a certain font 31 37 */ 32 struct Glyph33 {38 struct Glyph 39 { 34 40 // Glyph-specific (size and so on) 35 Uint16 character; //!< The character36 float minX; //!< The minimum distance from the origin in X37 float maxX; //!< The maximum distance from the origin in X38 float minY; //!< The minimum distance from the origin in Y39 float maxY; //!< The maximum distance from the origin in Y40 float width; //!< The width of the Glyph41 float height; //!< The height of the Glyph42 float bearingX; //!< How much is right of the Origin43 float bearingY; //!< How much is above the Origin44 float advance; //!< How big a Glyph would be in monospace-mode41 Uint16 character; //!< The character 42 float minX; //!< The minimum distance from the origin in X 43 float maxX; //!< The maximum distance from the origin in X 44 float minY; //!< The minimum distance from the origin in Y 45 float maxY; //!< The maximum distance from the origin in Y 46 float width; //!< The width of the Glyph 47 float height; //!< The height of the Glyph 48 float bearingX; //!< How much is right of the Origin 49 float bearingY; //!< How much is above the Origin 50 float advance; //!< How big a Glyph would be in monospace-mode 45 51 46 GLfloat texCoord[4]; //!< Texture coordinates: 0:left, 1:right, 2: top, 3: bottom.47 };52 GLfloat texCoord[4]; //!< Texture coordinates: 0:left, 1:right, 2: top, 3: bottom. 53 }; 48 54 49 50 class FontData 51 { 55 typedef CountPointer<FontData> Pointer; 52 56 public: 53 57 FontData(); … … 61 65 62 66 /** @returns a Pointer to the Array of Glyphs */ 63 inline Glyph**getGlyphArray() const { return this->glyphArray; };67 inline const Glyph* const * const getGlyphArray() const { return this->glyphArray; }; 64 68 65 69 int getMaxHeight() const { return maxHeight; }; … … 68 72 69 73 /** @returns the Texture-Data of this FontData */ 70 const TextureData Pointer& textureData() const { return texData; };74 const TextureData::Pointer& textureData() const { return texData; }; 71 75 72 76 bool rebuild() { return texData->rebuild(); }; … … 91 95 int maxDescent; //!< Max Desent of the Font. 92 96 93 TextureData Pointer texData;97 TextureData::Pointer texData; 94 98 }; 95 99 96 typedef CountPointer<FontData> FontDataPointer;97 98 100 #endif /* _FONT_DATA_H */ -
trunk/src/lib/graphics/text_engine/limited_width_text.cc
r9406 r9869 19 19 #include "font.h" 20 20 21 ObjectListDefinition(LimitedWidthText); 21 22 /** 22 23 * @brief creates a new Text Element … … 27 28 : Text(fontFile, textSize) 28 29 { 29 this-> setClassID(CL_LIMITED_WIDTH_TEXT, "LimitedWidthText");30 this->registerObject(this, LimitedWidthText::_objectList); 30 31 31 32 this->_dotsPosition = End; … … 75 76 glRotatef(this->getAbsDir2D(), 0, 0, 1); 76 77 77 Glyph* tmpGlyph;78 const Font::Glyph* tmpGlyph; 78 79 float posX = 0.0f; 79 80 glBegin(GL_QUADS); -
trunk/src/lib/graphics/text_engine/limited_width_text.h
r8980 r9869 14 14 class LimitedWidthText : public Text 15 15 { 16 ObjectListDeclaration(LimitedWidthText); 16 17 public: 17 18 typedef enum { -
trunk/src/lib/graphics/text_engine/multi_line_text.cc
r9406 r9869 19 19 #include "font.h" 20 20 21 ObjectListDefinition(MultiLineText); 22 21 23 /** 22 24 * @brief creates a new Text Element … … 27 29 : Text(fontFile, textSize) 28 30 { 29 this-> setClassID(CL_MULTI_LINE_TEXT, "MultiLineText");31 this->registerObject(this, MultiLineText::_objectList); 30 32 31 33 this->lineSpacing = 1.0; … … 78 80 glRotatef(this->getAbsDir2D(), 0, 0, 1); 79 81 80 Glyph* tmpGlyph;82 const Font::Glyph* tmpGlyph; 81 83 float posX = 0.0f; 82 84 float posY = 0.0f; -
trunk/src/lib/graphics/text_engine/multi_line_text.h
r7757 r9869 14 14 class MultiLineText : public Text 15 15 { 16 ObjectListDeclaration(MultiLineText); 16 17 public: 17 18 MultiLineText(const std::string& fontFile = "", unsigned int fontSize = TEXT_DEFAULT_SIZE, float lineWidth = 100.0); -
trunk/src/lib/graphics/text_engine/text.cc
r9406 r9869 17 17 18 18 #include "text.h" 19 #include "resource_font.h" 19 20 #include "font.h" 20 21 #include "util/loading/resource_manager.h"22 21 #include "debug.h" 22 23 ObjectListDefinition(Text); 23 24 24 25 /** … … 28 29 */ 29 30 Text::Text(const std::string& fontFile, unsigned int textSize) 30 31 { 32 this-> setClassID(CL_TEXT, "Text");31 // : _font(fontFile, FONT_DEFAULT_RENDER_SIZE) 32 { 33 this->registerObject(this, Text::_objectList); 33 34 34 35 // initialize this Text 35 this->setFont(fontFile, FONT_DEFAULT_RENDER_SIZE); 36 if (!fontFile.empty()) 37 this->setFont(fontFile, FONT_DEFAULT_RENDER_SIZE); 38 else 39 this->setFont("fonts/final_frontier.ttf", FONT_DEFAULT_RENDER_SIZE); 36 40 this->_size = textSize; 37 41 this->setSizeY2D(textSize); … … 44 48 : _font() 45 49 { 46 this-> setClassID(CL_TEXT, "Text");50 this->registerObject(this, Text::_objectList); 47 51 48 52 *this = text; … … 169 173 void Text::setFont(const std::string& fontFile, unsigned int fontSize) 170 174 { 171 Font* newFont = NULL; 172 // Font* oldFont = this->_font; 173 174 // load a new Font 175 if (!fontFile.empty()) 176 { 177 newFont = (Font*)ResourceManager::getInstance()->load(fontFile, TTF, RP_GAME, (int)fontSize); 178 if (newFont == NULL) 179 { 180 // newFont = &Font::(); 181 PRINTF(2)("Font %s could not be loaded, probably file not found\n", fontFile.c_str()); 182 } 183 } 184 185 if (newFont == NULL) 186 this->_font = Font(); 187 else 188 this->_font = *newFont; 175 this->_font = ResourceFont(fontFile, fontSize); 189 176 190 177 this->setupTextWidth(); … … 233 220 glRotatef(this->getAbsDir2D(), 0, 0, 1); 234 221 235 Glyph* tmpGlyph;222 const Font::Glyph* tmpGlyph; 236 223 float posX = 0.0f; 237 224 glBegin(GL_QUADS); -
trunk/src/lib/graphics/text_engine/text.h
r8764 r9869 26 26 class Text : public Element2D 27 27 { 28 ObjectListDeclaration(Text); 28 29 public: 29 30 Text(const std::string& fontFile = "", unsigned int fontSize = TEXT_DEFAULT_SIZE); -
trunk/src/lib/graphics/text_engine/text_engine.cc
r9406 r9869 33 33 34 34 #include "graphics_engine.h" 35 #include "util/loading/resource_manager.h"36 #include "class_list.h"37 35 38 36 #include "debug.h" … … 40 38 /// TEXT-ENGINE /// 41 39 /////////////////// 40 ObjectListDefinition(TextEngine); 42 41 /** 43 42 * standard constructor … … 45 44 TextEngine::TextEngine () 46 45 { 47 this->setClassID(CL_TEXT_ENGINE, "TextEngine");48 49 46 this->registerObject(this, TextEngine::_objectList); 47 this->setName("TextEngine"); 48 this->enableFonts(); 50 49 } 51 50 … … 62 61 { 63 62 // first remove all the remaining Texts (if any). 64 const std::list<BaseObject*>* textList = ClassList::getList(CL_TEXT); 65 if (textList != NULL) 66 { 67 while(textList->size() > 0) 68 delete dynamic_cast<Text*>(textList->front()); 69 } 63 while (!Text::objectList().empty()) 64 delete Text::objectList().front(); 70 65 // delete all remaining fonts (There should not be Anything to do here) 71 const std::list<BaseObject*>* fontList = ClassList::getList(CL_FONT); 72 if (fontList != NULL) 66 67 //const std::list<BaseObject*>* fontList = ClassList::getList(CL_FONT); 68 //if (fontList != NULL) 73 69 { 74 70 ///FIXME 75 // while (fontList->size() > 0)71 // while (fontList->size() > 0) 76 72 { 77 // Font* font = dynamic_cast<Font*>(fontList->back());73 // Font* font = dynamic_cast<Font*>(fontList->back()); 78 74 //if (likely(font != Font::getDefaultFont())) 79 75 // ResourceManager::getInstance()->unload(font, RP_GAME); … … 91 87 { 92 88 if (!TTF_WasInit()) 93 94 95 89 { 90 if(TTF_Init()==-1) 91 PRINTF(1)("TTF_Init: %s\n", TTF_GetError()); 96 92 97 98 93 TextEngine::checkVersion(); 94 } 99 95 else 100 96 PRINTF(4)("Fonts already initialized\n"); … … 107 103 { 108 104 if (TTF_WasInit()) 109 110 // Font::removeDefaultFont();111 112 105 { 106 // Font::removeDefaultFont(); 107 TTF_Quit(); 108 } 113 109 else 114 110 PRINTF(4)("Fonts were not initialized.\n"); … … 122 118 void TextEngine::debug() const 123 119 { 124 const std::list<BaseObject*>* textList = ClassList::getList(CL_TEXT); 125 if (textList != NULL) 120 PRINT(0)("+-------------------------------+\n"); 121 PRINT(0)("+ TEXT ENGINE DEBUG INFORMATION +\n"); 122 PRINT(0)("+-------------------------------+\n"); 123 PRINT(0)("Reference: %p; Text Counts: %d\n", this, Text::objectList().size()); 124 125 for (ObjectList<Text>::const_iterator it = Text::objectList().begin(); 126 it != Text::objectList().end(); 127 ++it) 126 128 { 127 PRINT(0)("+-------------------------------+\n"); 128 PRINT(0)("+ TEXT ENGINE DEBUG INFORMATION +\n"); 129 PRINT(0)("+-------------------------------+\n"); 130 PRINT(0)("Reference: %p; Text Counts: %d\n", this, textList->size()); 131 132 std::list<BaseObject*>::const_iterator text; 133 for ( text = textList->begin(); text != textList->end(); text++) 134 dynamic_cast<Text*>(*text)->debug(); 129 (*it)->debug(); 135 130 PRINT(0)("+---------------------------TE--+\n"); 136 131 } … … 152 147 compile_version.minor == link_version.minor && 153 148 compile_version.patch == link_version.patch) 154 155 156 149 { 150 return true; 151 } 157 152 else 158 159 160 161 162 153 { 154 PRINTF(2)("compiled with SDL_ttf version: %d.%d.%d\n", 155 compile_version.major, 156 compile_version.minor, 157 compile_version.patch); 163 158 164 165 166 167 168 169 159 PRINTF(2)("running with SDL_ttf version: %d.%d.%d\n", 160 link_version.major, 161 link_version.minor, 162 link_version.patch); 163 return false; 164 } 170 165 } -
trunk/src/lib/graphics/text_engine/text_engine.h
r5515 r9869 24 24 class TextEngine : public BaseObject 25 25 { 26 public: 26 ObjectListDeclaration(TextEngine); 27 public: 27 28 virtual ~TextEngine(); 28 29 /** @returns a Pointer to the only object of this Class */
Note: See TracChangeset
for help on using the changeset viewer.