Changeset 10183 in orxonox.OLD for branches/mount_points
- Timestamp:
- Jan 6, 2007, 4:30:36 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/mount_points/src/lib/graphics/importer/static_model.cc
r10182 r10183 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); … … 112 112 std::vector<Vector> vertices; 113 113 114 if( groupName.find("MP.", 0) != std::string::npos) 114 // check if the name has a "MP" prefix or else it won't work 115 if( groupName.find("MP.", 0) == std::string::npos) 116 continue; 117 118 119 PRINTF(0)("Found a MountPoint: %s\n", groupName.c_str()); 120 121 // now check if it is a mount point identifier 122 if( (*groupIt)._faces.size() != 6) 115 123 { 116 PRINTF(0)("Found a MountPoint: %s\n", groupName.c_str()); 117 118 // now check if it is a mount point identifier 119 if( (*groupIt)._faces.size() != 6) { 120 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", 121 groupName.c_str(), (*groupIt)._faces.size()); 124 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", 125 groupName.c_str(), (*groupIt)._faces.size()); 126 } 127 128 // now extract the direction from the length: 129 std::vector<StaticModelData::Face>::const_iterator faceIt = (*groupIt)._faces.begin(); 130 for( ; faceIt < (*groupIt)._faces.end(); faceIt++) 131 { 132 // now go through all modelfaceelements 133 std::vector<StaticModelData::FaceElement>::const_iterator faceElementIt = (*faceIt)._elements.begin(); 134 for( ; faceElementIt < (*faceIt)._elements.end(); faceElementIt++) 135 { 136 int vert = (*faceElementIt).vertexNumber; 137 vertices.push_back(Vector(this->data->getVertices()[vert*3], 138 this->data->getVertices()[vert*3 + 1], 139 this->data->getVertices()[vert*3 + 2])); 122 140 } 123 124 // now extract the direction from the length: 125 std::vector<StaticModelData::Face>::const_iterator faceIt = (*groupIt)._faces.begin(); 126 for( ; faceIt < (*groupIt)._faces.end(); faceIt++) 141 } 142 143 // vertex with the max surrounding faces is the up-point (pyramid like object) 144 std::vector<Vector>::const_iterator it = vertices.begin(); 145 Vector tmpPoint; 146 int tmpCount; 147 Vector up; 148 int maxCount = 0; 149 for( ; it < vertices.end(); it++) 150 { 151 tmpCount = 0; 152 tmpPoint = (*it); 153 // 154 std::vector<Vector>::const_iterator it2 = vertices.begin(); 155 for( ; it2 < vertices.end(); it2++) 156 if( tmpPoint == *it2) 157 tmpCount++; 158 159 // if this is the vertex with the most surrounding vertices 160 if( tmpCount > maxCount) 127 161 { 128 // now go through all modelfaceelements 129 std::vector<StaticModelData::FaceElement>::const_iterator faceElementIt = (*faceIt)._elements.begin(); 130 for( ; faceElementIt < (*faceIt)._elements.end(); faceElementIt++) 131 { 132 int vert = (*faceElementIt).vertexNumber; 133 vertices.push_back(Vector(this->data->getVertices()[vert*3], 134 this->data->getVertices()[vert*3 + 1], 135 this->data->getVertices()[vert*3 + 2])); 136 } 162 up = tmpPoint; 163 maxCount = tmpCount; 137 164 } 138 139 // vertex with the max surrounding faces is the up-point (pyramid like object)140 std::vector<Vector>::const_iterator it = vertices.begin();141 Vector tmpPoint;142 int tmpCount;143 Vector upPoint;144 int maxCount = 0;145 for( ; it < vertices.end(); it++)146 {147 tmpCount = 0;148 tmpPoint = (*it);149 //150 std::vector<Vector>::const_iterator it2 = vertices.begin();151 for( ; it2 < vertices.end(); it2++)152 if( tmpPoint == *it2)153 tmpCount++;154 155 // if this is the vertex with the most surrounding vertices156 if( tmpCount > maxCount)157 {158 upPoint = tmpPoint;159 maxCount = tmpCount;160 }161 }162 163 164 // now get the longest side of the first face, this will be the forward vector165 Vector forward;166 Vector side1 = vertices[0] - vertices[1];167 Vector side2 = vertices[1] - vertices[2];168 Vector side3 = vertices[2] - vertices[3];169 170 if( fabs(side1.len()) > fabs(side2.len()) && fabs(side1.len()) > fabs(side3.len()))171 forward = side1;172 else if( fabs(side2.len()) > fabs(side1.len()) && fabs(side2.len()) > fabs(side3.len()))173 forward = side2;174 else if( fabs(side3.len()) > fabs(side1.len()) && fabs(side3.len()) > fabs(side2.len()))175 forward = side3;176 177 // now get the center of the object178 Vector center;179 it = vertices.begin();180 for( ; it < vertices.end(); it++)181 center += (*it);182 // scale183 center /= vertices.size();184 185 PRINTF(0)("Up Point\n");186 upPoint.debug();187 188 PRINTF(0)("Center\n");189 center.debug();190 191 PRINTF(0)("Forward\n");192 forward.debug();193 194 165 } 195 166 167 168 // now get the longest side of the first face, this will be the forward vector 169 Vector forward; 170 Vector side1 = vertices[0] - vertices[1]; 171 Vector side2 = vertices[1] - vertices[2]; 172 Vector side3 = vertices[2] - vertices[3]; 173 174 if( fabs(side1.len()) > fabs(side2.len()) && fabs(side1.len()) > fabs(side3.len())) 175 forward = side1; 176 else if( fabs(side2.len()) > fabs(side1.len()) && fabs(side2.len()) > fabs(side3.len())) 177 forward = side2; 178 else if( fabs(side3.len()) > fabs(side1.len()) && fabs(side3.len()) > fabs(side2.len())) 179 forward = side3; 180 181 // now get the center of the object 182 Vector center; 183 it = vertices.begin(); 184 for( ; it < vertices.end(); it++) 185 center += (*it); 186 // scale 187 center /= vertices.size(); 188 189 PRINTF(0)("Up Point\n"); 190 up.debug(); 191 192 PRINTF(0)("Center\n"); 193 center.debug(); 194 195 PRINTF(0)("Forward\n"); 196 forward.debug(); 197 198 // now add the mount point 199 this->addMountPoint( up, forward, center); 196 200 } 197 198 199 201 } 200 202
Note: See TracChangeset
for help on using the changeset viewer.