- Timestamp:
- Jan 24, 2007, 12:45:39 AM (18 years ago)
- Location:
- trunk/src
- Files:
-
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/graphics/importer/bsp/bsp_file.cc
r10033 r10314 430 430 char fileName [500]; 431 431 char ext [500]; 432 struct stat results;433 432 434 433 … … 660 659 int errorCode = 0; //!< the error code for the texture loading functions 661 660 unsigned int lightMap; //!< the OpenGL texture handle 662 int mipmapLevel = 0; //!< the maximum mipmap level for this texture663 int mipmapWidth = 0; //!< the width of the mipmap664 int mipmapHight = 0; //!< the height of the mipmap3661 //int mipmapLevel = 0; //!< the maximum mipmap level for this texture 662 //int mipmapWidth = 0; //!< the width of the mipmap 663 //int mipmapHight = 0; //!< the height of the mipmap3 665 664 float sc, scale, temp; 666 665 for(int i = 0; i < 128*128*3 ; i++) … … 1101 1100 { 1102 1101 int sto = array[0]; 1103 array[0] = scale * array[1] ;1104 array[1] = scale * array[2];1105 array[2] = scale * sto ;1102 array[0] = (int) scale * array[1] ; 1103 array[1] = (int) scale * array[2]; 1104 array[2] = (int) scale * sto ; 1106 1105 } 1107 1106 -
trunk/src/lib/graphics/importer/bsp/bsp_manager.cc
r10076 r10314 298 298 }//else 299 299 300 301 // now sort the transparent faces in the right order 302 int size = this->trasparent.size(); 303 304 // bubble sort 305 bool hasSwapped = true; 306 Vector v1, v2; 307 308 while( hasSwapped) 309 { 310 hasSwapped = false; 311 312 for( int i = 0; i < size - 1; i++) 313 { 314 // sorting test 315 face& fac1 = (this->bspFile->faces)[this->trasparent[i]]; 316 face& fac2 = (this->bspFile->faces)[this->trasparent[i+1]]; 317 318 // get center of face 1 319 const BspVertex* curVertex = (BspVertex *) this->bspFile->vertice; 320 321 // assign the values of the vertices 322 v1(curVertex[fac1.vertex].position[0], curVertex[fac1.vertex].position[1], curVertex[fac1.vertex].position[2]); 323 v2(curVertex[fac2.vertex].position[0], curVertex[fac2.vertex].position[1], curVertex[fac2.vertex].position[2]); 324 // relativly to observer 325 v1 = this->cam - v1; 326 v2 = this->cam - v2; 327 328 // swap if necessary 329 if( v1 > v2) 330 { 331 // swap elements 332 int tmp = this->trasparent[i+1]; 333 this->trasparent[i+1] = this->trasparent[i]; 334 this->trasparent[i] = tmp; 335 336 hasSwapped = true; 337 } 338 } 339 } 340 341 342 343 // draw all solid faces 300 344 while(!this->opal.empty()) { 301 this->draw_face(this->opal.front()); 302 this->opal.pop_front(); 303 } 345 this->draw_face(this->opal.back()); // front() 346 this->opal.pop_back(); // pop_back() 347 } 348 349 // draw all transparent faces 304 350 while(!this->trasparent.empty()) { 305 351 this->draw_face(this->trasparent.back()); -
trunk/src/lib/graphics/importer/bsp/bsp_manager.h
r10033 r10314 128 128 bool * alreadyVisible; 129 129 // Deques to store the visible faces 130 ::std:: deque<int> trasparent; //!< the ones with transparancy go here131 ::std:: deque<int> opal; //!< the others here.130 ::std::vector<int> trasparent; //!< the ones with transparancy go here 131 ::std::vector<int> opal; //!< the others here. 132 132 133 133 Vector out; //!< Stores collision coordinates -
trunk/src/lib/graphics/importer/model.cc
r9869 r10314 17 17 18 18 #include "model.h" 19 19 #include "debug.h" 20 20 #include "glincl.h" 21 21 … … 88 88 glEnd(); 89 89 } 90 91 92 /** 93 * adds a mounting point to the model 94 * @param up up vector 95 * @param forward forward vector 96 * @param center center vector 97 */ 98 void Model::addMountPoint(const Vector& up, const Vector& forward, const Vector& center, const std::string& name) 99 { 100 mountPointSkeleton mps; 101 mps.up = up; 102 mps.forward = forward; 103 mps.center = center; 104 mps.name = name; 105 106 this->mountPoints.push_back(mps); 107 } -
trunk/src/lib/graphics/importer/model.h
r10147 r10314 52 52 53 53 54 //! skeleton informations for all mount points 55 typedef struct 56 { 57 std::string name; //!< the name of the mount point 58 Vector up; //!< the up vector 59 Vector forward; //!< the forward vector 60 Vector center; //!< the center vector 61 } mountPointSkeleton; 62 63 64 54 65 //! This class defines the basic components of a model 55 66 class Model : virtual public BaseObject { 56 67 ObjectListDeclaration(Model); 68 69 typedef std::list<mountPointSkeleton> mpList; 57 70 58 71 public: … … 85 98 /** function to extract the mount points from the model data */ 86 99 virtual void extractMountPoints() {} 100 /** @returns a list of mounting points */ 101 inline const mpList& getMountPoints() const { return this->mountPoints; } 102 void addMountPoint(const Vector& up, const Vector& forward, const Vector& center, const std::string& name); 87 103 88 104 … … 92 108 93 109 protected: 94 modelInfo pModelInfo; //!< Reference to the modelInfo 110 modelInfo pModelInfo; //!< Reference to the modelInfo 111 mpList mountPoints; //!< a list of all mounting point skeletons 95 112 }; 96 113 -
trunk/src/lib/graphics/importer/obj/objModel.cc
r10147 r10314 44 44 45 45 this->finalize(); 46 47 this->extractMountPoints();48 46 } 49 47 -
trunk/src/lib/graphics/importer/oif/object_information_file.cc
r10147 r10314 24 24 25 25 26 27 /** 28 * constructor 29 */ 30 OIFData::OIFData() 31 { 32 this->_root = NULL; 33 } 34 35 26 36 /** 27 37 * constructor … … 30 40 OIFData::OIFData(const std::string& fileName) 31 41 { 42 this->_root = NULL; 32 43 this->load(fileName); 44 } 45 46 47 OIFData::~OIFData() 48 { 49 if( this->_root) 50 delete this->_root; 33 51 } 34 52 … … 40 58 void OIFData::load(const std::string& fileName) 41 59 { 42 // 43 if( fileName.empty()) 60 if( fileName.empty()) 44 61 { 45 PRINTF( 3)("No filename specified for object information loading");62 PRINTF(1)("No filename specified for object information loading"); 46 63 return; 47 64 } 48 65 49 TiXmlDocument XMLDoc(fileName);66 TiXmlDocument* XMLDoc = new TiXmlDocument(fileName); 50 67 // load the campaign document 51 if( !XMLDoc .LoadFile(fileName))68 if( !XMLDoc->LoadFile(fileName)) 52 69 { 53 70 // report an error 54 PRINTF( 3)("Could not load XML File %s: %s @ %d:%d\n", fileName.c_str(), XMLDoc.ErrorDesc(), XMLDoc.ErrorRow(), XMLDoc.ErrorCol());71 PRINTF(1)("Could not load XML File %s: %s @ %d:%d\n", fileName.c_str(), XMLDoc->ErrorDesc(), XMLDoc->ErrorRow(), XMLDoc->ErrorCol()); 55 72 return; 56 73 } 57 74 58 75 // check basic validity 59 TiXmlElement* root = XMLDoc.RootElement();60 assert( root != NULL);76 this->_root = XMLDoc->RootElement(); 77 assert( this->_root != NULL); 61 78 62 if( strcmp( root->Value(), "ObjectInformationFile"))79 if( strcmp( this->_root->Value(), "ObjectInformationFile")) 63 80 { 64 81 // report an error 65 PRINTF( 2)("Specified XML File is not an orxonox object information file (<ObjectInformationFile> element missing)\n");82 PRINTF(1)("Specified XML File is not an orxonox object information file (<ObjectInformationFile> element missing)\n"); 66 83 return; 67 84 } 68 85 69 // construct campaign 70 // return new Campaign( root); 86 // this->initMountPoint( this->_root); 71 87 } 72 88 73 89 74 75 90 /** 76 * standard constructor 91 * constructor 92 * @param fileName name of the file 77 93 */ 78 94 ObjectInformationFile::ObjectInformationFile() 95 : data(new OIFData) 79 96 { 80 97 this->init(); … … 107 124 108 125 /** 126 * the definition of the assignment operator 127 * @param oif 128 * @return 129 */ 130 ObjectInformationFile& ObjectInformationFile::operator=(const ObjectInformationFile& oif) 131 { 132 this->init(); 133 this->data = oif.data; 134 135 return *this; 136 } 137 138 /** 109 139 * initizlizing function 110 140 */ … … 112 142 { 113 143 144 } 145 146 147 void ObjectInformationFile::load(const std::string& fileName) 148 { 149 this->data = OIFData::Pointer(new OIFData(fileName)); 114 150 } 115 151 … … 124 160 125 161 162 /** 163 * this initializes the mount point 164 * @param mountPoint to be initialized 165 */ 166 // void ObjectInformationFile::initMountPoint(MountPoint* mountPoint) 167 // { 168 // TiXmlElement* root = this->data->root(); 169 // 170 // } 126 171 127 ObjectInformationFile& ObjectInformationFile::operator=(const ObjectInformationFile& oif)128 {129 this->data = oif.data;130 return *this;131 }132 133 134 -
trunk/src/lib/graphics/importer/oif/object_information_file.h
r10147 r10314 20 20 21 21 public: 22 OIFData(); 22 23 OIFData(const std::string& fileName); 23 virtual ~OIFData() {}24 virtual ~OIFData(); 24 25 25 26 void load(const std::string& fileName); 27 void initMountPoint(const TiXmlElement* root); 28 29 inline const TiXmlElement* root() { return this->_root; } 26 30 27 31 28 32 private: 29 33 TiXmlElement* _root; //!< root of the xml file 30 34 }; 31 35 … … 40 44 virtual ~ObjectInformationFile(); 41 45 46 void load(const std::string& fileName); 47 42 48 ObjectInformationFile& operator=(const ObjectInformationFile& oif); 49 50 /** @returns a reference to the xml oif file */ 51 inline const TiXmlElement* getMountPointDescription() { return this->data->root(); } 52 53 inline void acquireData(const OIFData::Pointer& data) { this->data = data; } 54 const OIFData::Pointer& dataPointer() const { return this->data; }; 55 56 43 57 44 58 private: -
trunk/src/lib/graphics/importer/oif/resource_oif.cc
r10147 r10314 26 26 Resources::StorePointer* ptr = this->acquireResource(fileName); 27 27 28 28 29 if (ptr) 29 30 { 30 PRINTF( 0)("FOUND OIF: %s\n", fileName.c_str());31 //this->acquireData(static_cast<ResourceOIF::OIFResourcePointer*>(ptr)->ptr());31 PRINTF(5)("FOUND OIF: %s\n", fileName.c_str()); 32 this->acquireData(static_cast<ResourceOIF::OIFResourcePointer*>(ptr)->ptr()); 32 33 } 33 34 else 34 35 { 35 PRINTF( 4)("NOT FOUND OIF: %s\n", fileName.c_str());36 // std::string modelFileName = this->Resource::locateFile(modelName);37 // //std::string skinFileName = this->Resource::locateFile(skinName);38 // this->MD2Model::load(modelFileName, skinName, scale);39 // this->Resource::addResource(new ResourceOIF::OIFResourcePointer(loadString(modelName, skinName, scale), keepLevel, this->MD2Model::dataPointer()));36 PRINTF(5)("NOT FOUND OIF: %s\n", fileName.c_str()); 37 std::string fullName = this->Resource::locateFile(fileName); 38 PRINTF(5)("trying loading of: %s\n", fullName.c_str()); 39 this->load(fullName); 40 this->Resource::addResource(new ResourceOIF::OIFResourcePointer(fileName, keepLevel, this->ObjectInformationFile::dataPointer())); 40 41 } 41 42 -
trunk/src/lib/graphics/importer/oif/resource_oif.h
r10147 r10314 15 15 { 16 16 public: 17 ResourceOIF(const std::string& fileName, const Resources::KeepLevel& keepLevel = Resources::KeepLevel()); 17 ResourceOIF(const std::string& fileName, 18 const Resources::KeepLevel& keepLevel = Resources::KeepLevel()); 18 19 static ResourceOIF createFromString(const std::string& loadString, const Resources::KeepLevel& keepLevel = Resources::KeepLevel()); 19 20 -
trunk/src/lib/graphics/importer/static_model.cc
r10147 r10314 45 45 46 46 StaticModel::StaticModel(const StaticModel& staticModel) 47 : data(staticModel.data)47 : data(staticModel.data) 48 48 { 49 49 this->registerObject(this, StaticModel::_objectList); … … 111 111 std::vector<Vector> vertices; 112 112 113 if( groupName.find("MP.", 0) != std::string::npos) 113 // check if the name has a "MP" prefix or else it won't work 114 if( groupName.find("MP.", 0) == std::string::npos) 115 continue; 116 117 118 PRINTF(5)("Found a MountPoint: %s\n", groupName.c_str()); 119 120 StaticModelData::Face triangle[3]; 121 122 // now check if it is a mount point identifier 123 if( (*groupIt)._faces.size() != 11) 114 124 { 115 PRINTF(0)("Found a MountPoint: %s\n", groupName.c_str()); 116 117 // now check if it is a mount point identifier 118 if( this->data->getGroups().size() != 5) { 119 PRINTF(1)("the face count of %s is wrong, perhaps you missnamed this object or used the wrong mount point object\n", groupName.c_str()); 125 PRINTF(1)("the face count of %s is wrong, perhaps you missnamed this object or used the wrong mount point object (got %i faces)\n", 126 groupName.c_str(), (*groupIt)._faces.size()); 127 } 128 129 // now iterate through all faces 130 std::vector<StaticModelData::Face>::const_iterator faceIt = (*groupIt)._faces.begin(); 131 for( int i = 0; faceIt < (*groupIt)._faces.end(); faceIt++) 132 { 133 if( (*faceIt)._elements.size() == 3) 134 { 135 triangle[i++] = (*faceIt); 120 136 } 121 122 // now extract the direction from the length: 123 std::vector<StaticModelData::Face>::const_iterator faceIt = (*groupIt)._faces.begin(); 124 for( ; faceIt < (*groupIt)._faces.end(); faceIt++) 137 } 138 139 140 Vector center; 141 Vector xAxis; 142 Vector yAxis; 143 Vector zAxis; 144 // now process all points 145 for( int i = 0; i < 3; i++) 146 { 147 // convert the float vertices to vectors 148 Vector a( this->data->getVertices()[triangle[i]._elements[0].vertexNumber * 3], 149 this->data->getVertices()[triangle[i]._elements[0].vertexNumber * 3 + 1], 150 this->data->getVertices()[triangle[i]._elements[0].vertexNumber * 3 + 2]); 151 Vector b( this->data->getVertices()[triangle[i]._elements[1].vertexNumber * 3], 152 this->data->getVertices()[triangle[i]._elements[1].vertexNumber * 3 + 1], 153 this->data->getVertices()[triangle[i]._elements[1].vertexNumber * 3 + 2]); 154 Vector c( this->data->getVertices()[triangle[i]._elements[2].vertexNumber * 3], 155 this->data->getVertices()[triangle[i]._elements[2].vertexNumber * 3 + 1], 156 this->data->getVertices()[triangle[i]._elements[2].vertexNumber * 3 + 2]); 157 158 Vector ab = a - b; 159 Vector ac = a - c; 160 Vector bc = b - c; 161 162 Vector axis1; 163 Vector axis2; 164 // now find the center point (the one with the 90degree angle) 165 if( fabs(ab.dot( ac)) < 0.0001) 125 166 { 126 // now go through all modelfaceelements 127 std::vector<StaticModelData::FaceElement>::const_iterator faceElementIt = (*faceIt)._elements.begin(); 128 for( ; faceElementIt < (*faceIt)._elements.end(); faceElementIt++) 129 { 130 int vert = (*faceElementIt).vertexNumber; 131 vertices.push_back(Vector(this->data->getVertices()[vert*3], 132 this->data->getVertices()[vert*3 + 1], 133 this->data->getVertices()[vert*3 + 2])); 134 } 167 center = a; 168 axis1 = b - a; 169 axis2 = c - a; 135 170 } 136 137 // vertex with the max count is the up-point 138 std::vector<Vector>::const_iterator it = vertices.begin(); 139 Vector tmpPoint; 140 int tmpCount; 141 Vector upPoint; 142 int maxCount = 0; 143 for( ; it < vertices.end(); it++) 171 else if( fabs(ab.dot(bc)) < 0.0001) 144 172 { 145 tmpCount = 0; 146 tmpPoint = (*it); 147 // 148 std::vector<Vector>::const_iterator it2 = vertices.begin(); 149 for( ; it2 < vertices.end(); it2++) 150 if( tmpPoint == *it2) 151 tmpCount++; 152 153 // if this is the vertex with the most surrounding vertices 154 if( tmpCount > maxCount) 155 { 156 upPoint = tmpPoint; 157 maxCount = tmpCount; 158 } 173 center = b; 174 axis1 = a - b; 175 axis2 = c - b; 159 176 } 160 161 // now get the center of the object 162 Vector center; 163 it = vertices.begin(); 164 for( ; it < vertices.end(); it++) 165 center += (*it); 166 // scale 167 center /= vertices.size(); 168 169 177 else if( fabs(bc.dot(ac)) < 0.0001) 178 { 179 center = c; 180 axis1 = b - c; 181 axis2 = a - c; 182 } 183 184 185 // get the longest axis (without defining a max() funciton :D 186 if( xAxis.len() < axis1.len() ) 187 xAxis = axis1; 188 if( xAxis.len() < axis2.len()) 189 xAxis = axis2; 190 191 192 // find the 2nd longest axis to be y-axis 193 if( xAxis.len() > axis1.len() && yAxis.len() < axis1.len()) 194 yAxis = axis1; 195 if( xAxis.len() > axis2.len() && yAxis.len() < axis2.len()) 196 yAxis = axis2; 197 198 199 // needed... no explanation here.. 200 if( zAxis.len() == 0.) 201 zAxis = yAxis; 202 203 // find the shortest axis to be z-axis 204 if( yAxis.len() > axis1.len() ) 205 zAxis = axis1; 206 if( yAxis.len() > axis2.len() ) 207 zAxis = axis2; 170 208 } 171 209 210 // now add the mount point 211 this->addMountPoint( zAxis, yAxis, center, groupName); 172 212 } 173 174 175 213 } 176 214 -
trunk/src/lib/graphics/importer/static_model.h
r10147 r10314 58 58 59 59 void finalize(); 60 v oid extractMountPoints();60 virtual void extractMountPoints(); 61 61 62 62 void acquireData(const StaticModelData::Pointer& data); … … 71 71 private: 72 72 void updateBase(); 73 74 73 75 private: 74 76 StaticModelData::Pointer data; -
trunk/src/lib/math/vector.h
r9110 r10314 47 47 /** @param v: the Vecor to compare with this one @returns true, if the Vecors are different, false otherwise */ 48 48 inline bool operator!= (const Vector& v) const { return (this->x!=v.x||this->y!=v.y||this->z!=v.z)?true:false; }; 49 inline bool operator> (const Vector& v) const { return (this->len() > v.len()); } 50 inline bool operator< (const Vector& v) const { return (this->len() < v.len()); } 51 49 52 /** @param index The index of the "array" @returns the x/y/z coordinate */ 50 53 inline float operator[] (float index) const {if( index == 0) return this->x; if( index == 1) return this->y; if( index == 2) return this->z; } … … 82 85 inline const Vector& operator= (const sVec3D& v) { this->x = v[0]; this->y = v[1]; this->z = v[2]; return *this; } 83 86 inline const Vector& operator= (const float* v) { this->x = v[0]; this->y = v[1]; this->z = v[2]; return *this; } 87 88 /** this operator can be used to assign values to the vector */ 89 inline void operator() (float x, float y, float z) { this->x = x; this->y = y; this->z = z;} 90 91 92 93 84 94 /** @param v: the other vector \return the dot product of the vectors */ 85 95 float dot (const Vector& v) const { return x*v.x+y*v.y+z*v.z; }; -
trunk/src/story_entities/game_world.cc
r10013 r10314 11 11 ### File Specific: 12 12 main-programmer: Patrick Boenzli 13 main-programmer: Benjamin Grauer 13 14 co-programmer: Christian Meyer 14 co-programmer: Benjamin Grauer 15 15 16 */ 16 17 … … 73 74 SHELL_COMMAND(togglePNodeVisibility, GameWorld, togglePNodeVisibility); 74 75 SHELL_COMMAND(showBVLevel, GameWorld, toggleBVVisibility); 76 SHELL_COMMAND(showMountPoints, GameWorld, toggleMPVisibility); 75 77 76 78 … … 88 90 this->showBV = false; 89 91 this->showBVLevel = 3; 92 this->showMPV = false; 90 93 91 94 this->dataXML = NULL; … … 541 544 ObjectManager::EntityList::const_iterator entity; 542 545 for (entity = drawList.begin(); entity != drawList.end(); entity++) 546 { 543 547 if ((*entity)->isVisible()) 544 548 (*entity)->draw(); 549 550 if( unlikely( this->showMPV)) 551 (*entity)->debugDrawMountPoints(); 552 } 545 553 } 546 554 … … 666 674 } 667 675 676 668 677 if( unlikely(this->showPNodes)) 669 678 PNode::getNullParent()->debugDraw(0); -
trunk/src/story_entities/game_world.h
r9869 r10314 62 62 void togglePNodeVisibility(); 63 63 void toggleBVVisibility(int level); 64 inline void toggleMPVisibility() { this->showMPV = !this->showMPV; } 64 65 65 66 inline void setSky(WorldEntity* sky) { this->dataTank->sky = sky; } … … 99 100 bool showBV; //!< if the Bounding Volumes should be visible. 100 101 int showBVLevel; //!< the depth level of the displayed bounding volumes 102 bool showMPV; //!< true if the mounting points should be drawn for debug purposes 101 103 102 104 /* world timing */ -
trunk/src/story_entities/movie_loader.cc
r10114 r10314 63 63 64 64 65 ErrorMessage MovieLoader::init() { }65 ErrorMessage MovieLoader::init() { return ErrorMessage();} 66 66 67 67 68 ErrorMessage MovieLoader::loadData() { }68 ErrorMessage MovieLoader::loadData() { return ErrorMessage();} 69 69 70 70 … … 72 72 { 73 73 this->unsubscribeEvents(ES_GAME); 74 75 return ErrorMessage(); 74 76 } 75 77 … … 82 84 this->bRunning = true; 83 85 this->run(); 86 87 return true; 84 88 } 85 89 … … 89 93 90 94 this->bRunning = false; 95 96 return true; 91 97 } 92 98 93 bool MovieLoader::pause() { }94 bool MovieLoader::resume() { }99 bool MovieLoader::pause() { return false; } 100 bool MovieLoader::resume() { return false; } 95 101 96 102 void MovieLoader::run() -
trunk/src/world_entities/mount_point.cc
r10147 r10314 10 10 11 11 ### File Specific 12 main-programmer: Patrick Boenzli patrick@orxonox.net12 main-programmer: Patrick Boenzli, patrick@orxonox.net 13 13 co-programmer: 14 14 */ … … 19 19 #include "util/loading/factory.h" 20 20 #include "util/loading/load_param.h" 21 #include "util/loading/load_param_xml.h" 22 21 23 22 24 … … 27 29 28 30 ObjectListDefinition(MountPoint); 29 CREATE_FACTORY(MountPoint);30 31 31 32 … … 33 34 * construct 34 35 */ 35 MountPoint::MountPoint () 36 { 36 MountPoint::MountPoint (const Vector& up, const Vector& forward, const Vector& center, const std::string& name) 37 { 38 PRINTF(5)("Created mount point %s\n", name.c_str()); 39 40 this->_name = name; 41 this->setAbsCoor( center); 42 this->setAbsDir( Quaternion(forward, up)); 43 37 44 this->init(); 38 45 } 39 46 40 41 /**42 * constructor43 * @param root the xml root element44 */45 MountPoint::MountPoint(const TiXmlElement* root)46 {47 this->init();48 49 if( root != NULL)50 this->loadParams(root);51 }52 47 53 48 … … 75 70 * @param root the XML-element to load the MD2Creature's properties from 76 71 */ 77 void MountPoint::loadParams(const TiXmlElement* root) 78 { 79 WorldEntity::loadParams(root); 72 void MountPoint::initMountPoint(const TiXmlElement* root) 73 { 74 if( root == NULL) 75 { 76 PRINTF(1)("MountPoint - initialization failed, since I got no valid xml element\n"); 77 return; 78 } 79 // now get the first element 80 const TiXmlElement* element = root->FirstChildElement("MountPoints"); 81 if( element == NULL) 82 { 83 PRINTF(1)("I am in section: %s, Object Information file is missing a proper 'MountPoints' section\n", root->Value()); 84 // element = root->FirstChildElement( ); 85 // PRINTF(0)("first child: %s\n", element->Value()); 86 } 87 else 88 { 89 element = element->FirstChildElement(); 90 // parse the information for this mount point 91 92 PRINTF(4)("Loading WorldEntities\n"); 93 while( element != NULL) 94 { 95 std::string name = element->Value(); 96 97 PRINTF(5)("checking %s against local %s\n", name.c_str(), this->_name.c_str()); 98 // check if we got the right mount point 99 if( this->_name.find(name, 0) != std::string::npos) 100 { 101 PRINTF(5)("found mount point %s\n", this->_name.c_str()); 102 // load it 103 this->loadParam(element); 104 } 105 106 element = element->NextSiblingElement(); 107 } 108 } 109 } 110 111 112 113 /** 114 * load the parameters from the xml section 115 * @param root the root element of this xml branche 116 */ 117 void MountPoint::loadParam(const TiXmlElement* root) 118 { 119 // first check for the description 120 LoadParam(root, "Description", this, MountPoint, setDescription) 121 .describe("Sets this mount point a description"); 122 123 // now check for the orx class to create 124 LoadParam(root, "OrxClass", this, MountPoint, setOrxClass) 125 .describe("Sets the class this mount points should host"); 126 127 LoadParamXML(root, "Details", this, MountPoint, loadDetails); 128 } 129 130 131 /** 132 * load the parameters from the world entity 133 * @param root the root element of this xml branche 134 */ 135 void MountPoint::loadDetails(const TiXmlElement* root) 136 { 137 if( this->_mount != NULL) 138 { 139 PRINTF(0)("Got detail informations\n"); 140 this->_mount->loadParams( root); 141 } 142 } 143 144 145 /** 146 * setst the description (optional) via xml tag 147 * @param description string containing the description 148 */ 149 void MountPoint::setDescription(const std::string& description) 150 { 151 this->_description = description; 152 } 153 154 155 156 /** 157 * sets the class of this mount point 158 * @param orxClass class 159 */ 160 void MountPoint::setOrxClass(const std::string& orxClass) 161 { 162 // create the object for this mount point 163 BaseObject* obj = Factory::fabricate(orxClass); 164 // check if the object is created correctly 165 if( obj != NULL) 166 { 167 if( obj->isA( WorldEntity::staticClassID())) 168 { 169 // cast down the object to WE 170 this->_mount = dynamic_cast<WorldEntity*>(obj); 171 172 // now set the position, direction and reparent it to this node 173 this->_mount->setAbsCoor( this->getAbsCoor()); 174 this->_mount->setAbsDir( this->getAbsDir()); 175 this->_mount->setParent( this); 176 177 this->_mount->toList( (OM_LIST)(this->getOMListNumber()+1)); 178 } 179 } 180 else 181 PRINTF(1)("Couldn't create %s for this mount point (%s)\n", orxClass.c_str(), this->_name.c_str()); 80 182 } 81 183 … … 89 191 { 90 192 91 92 193 } 93 194 … … 98 199 void MountPoint::draw() const 99 200 { 100 101 201 } 102 202 … … 108 208 void MountPoint::debugDraw() const 109 209 { 110 210 // invoke the underlying pnode debug draw 211 this->debugDraw(); 111 212 } 112 213 -
trunk/src/world_entities/mount_point.h
r10147 r10314 12 12 13 13 public: 14 MountPoint (); 15 MountPoint(const TiXmlElement* root); 14 MountPoint (const Vector& up, const Vector& forward, const Vector& center, const std::string& name); 16 15 virtual ~MountPoint (); 17 16 18 17 void init(); 19 virtual void loadParams(const TiXmlElement* root); 18 void initMountPoint(const TiXmlElement* root); 19 void loadParam(const TiXmlElement* root); 20 void loadDetails(const TiXmlElement* root); 20 21 22 void setDescription(const std::string& description); 23 void setOrxClass(const std::string& orxClass); 21 24 22 25 virtual void tick (float time); … … 32 35 private: 33 36 WorldEntity* _mount; //!< the entity mounted at this mount point 37 std::string _name; //!< the name of the mount point 38 39 std::string _description; //!< string containing an optional description 34 40 35 41 }; -
trunk/src/world_entities/world_entity.cc
r10147 r10314 12 12 13 13 ### File Specific: 14 main-programmer: Patrick Boenzli, Benjamin Grauer 15 co-programmer: Christian Meier 14 main-programmer: Patrick Boenzli 15 main-programmer: Benjamin Grauer 16 co-programmer: Christian Meier 16 17 */ 17 18 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY … … 73 74 this->scaling = 1.0f; 74 75 this->oiFile = NULL; 76 // add 10 members to this array 77 this->mountPoints.reserve(10); 75 78 76 79 /* OSOLETE */ … … 141 144 .describe("the fileName of the model, that should be loaded onto this world-entity. (must be relative to the data-dir)") 142 145 .defaultValues("", 1.0f, 0); 146 147 LoadParam(root, "mountpoints", this, WorldEntity, loadMountPoints) 148 .describe("the fileName of the object information file (optional)"); 143 149 144 150 LoadParam(root, "maxHealth", this, WorldEntity, setHealthMax) … … 204 210 StaticModel* model = new StaticModel(); 205 211 *model = ResourceOBJ(fileName, this->scaling); 212 213 // check if ther is a valid model and load other stuff 206 214 if (model->getVertexCount() > 0) 207 215 { 208 216 this->setModel(model, modelNumber); 209 if( modelNumber == 0 /* FIXME && !this->isA(CL_WEAPON) */) 217 218 if( modelNumber == 0) 219 { 210 220 this->buildObbTree(obbTreeDepth); 221 } 211 222 } 212 223 else 213 224 delete model; 214 215 // now get the object information file for this model, if any216 std::string oifName = fileName.substr(0, fileName.length() - 4) + ".oif";217 this->loadObjectInformationFile( oifName);218 225 } 219 226 /// LOADING AN MD2-model … … 269 276 * @param fileName the name of the file 270 277 */ 271 void WorldEntity::loadObjectInformationFile(const std::string& fileName) 272 { 273 PRINTF(4)("loading the oif File: %s\n", fileName.c_str()); 274 278 void WorldEntity::loadMountPoints(const std::string& fileName) 279 { 280 PRINTF(5)("loading the oif File: %s\n", fileName.c_str()); 281 282 // now load the object information file 275 283 this->oiFile = new ObjectInformationFile(fileName); 284 285 // get the model to load 286 Model* model = this->getModel(); 287 288 // extract the mount points 289 model->extractMountPoints(); 290 291 // first get all mount points from the model 292 const std::list<mountPointSkeleton> mpList = model->getMountPoints(); 293 // for each skeleton create a mounting point world entity 294 std::list<mountPointSkeleton>::const_iterator it = mpList.begin(); 295 296 for( ; it != mpList.end(); it++) 297 { 298 // create the mount points world entity 299 MountPoint* mp = new MountPoint( (*it).up, (*it).forward, (*it).center, (*it).name); 300 // parent it to this WE 301 mp->setParent( this); 302 // now add to the right group 303 mp->toList( (OM_LIST)(this->getOMListNumber()+1)); 304 // now get the number and add the mount point to the slot 305 std::string nrStr = (*it).name.substr(3, 2); 306 // add the mount point 307 this->addMountPoint(atoi(nrStr.c_str()), mp); 308 309 // now fill the mount point 310 mp->initMountPoint( this->oiFile->getMountPointDescription()); 311 } 312 276 313 } 277 314 … … 337 374 void WorldEntity::addMountPoint(int slot, MountPoint* mountPoint) 338 375 { 339 if( this->mountPoints[slot] != NULL) 340 { 341 PRINTF(0)("adding a mount point to a slot, that already exists! ignoring - maybe some object do not get connected well (object: %s)\n", this->getClassCName()); 376 if( this->mountPoints.capacity() < (unsigned int)slot) 377 { 378 // reserve 5 more slots than needed so this function is called as rare as possible 379 this->mountPoints.reserve(slot + 5); 380 } 381 else if( this->mountPoints[slot] != NULL) 382 { 383 PRINTF(4)("adding a mount point to a slot, that already is occupied! ignoring - maybe some object did not get connected well (object: %s)\n", this->getClassCName()); 342 384 } 343 385 … … 794 836 795 837 838 839 /** 840 * draw the mounting points 841 */ 842 void WorldEntity::debugDrawMountPoints() const 843 { 844 845 std::vector<MountPoint*>::const_iterator it = this->mountPoints.begin(); 846 for( ; it < this->mountPoints.end(); it++) 847 { 848 if( (*it) != NULL) 849 { 850 (*it)->debugDraw(); 851 } 852 } 853 } 854 855 796 856 /** 797 857 * Debug the WorldEntity -
trunk/src/world_entities/world_entity.h
r10147 r10314 53 53 Model* getModel(unsigned int modelNumber = 0) const { return (this->models.size() > modelNumber)? this->models[modelNumber] : NULL; }; 54 54 55 void load ObjectInformationFile(const std::string& fileName);55 void loadMountPoints(const std::string& fileName); 56 56 inline void loadMD2Texture(const std::string& fileName) { this->md2TextureFileName = fileName; } 57 57 … … 73 73 virtual void tick (float time); 74 74 virtual void draw () const; 75 void debugDrawMountPoints() const; 75 76 76 77 /* --- Collision Detection Block --- */
Note: See TracChangeset
for help on using the changeset viewer.