Changeset 10314 in orxonox.OLD for trunk/src/lib/graphics
- Timestamp:
- Jan 24, 2007, 12:45:39 AM (18 years ago)
- Location:
- trunk/src/lib/graphics/importer
- Files:
-
- 12 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;
Note: See TracChangeset
for help on using the changeset viewer.