// --- QGAMES::Position SabreWulfScene::limitPosition (int mn, const QGAMES::Position& pos, const QGAMES::Vector& or) { // If the orientation has no a valid value... // It is not possible to continue... QGAMES::Position result = pos; if (or == QGAMES::Vector::_cero) return (result); // Select all zones valid... Locations vLocs; QGAMES::Rectangle l = QGAMES::Rectangle::_noRectangle; SabreWulfScene::Locations locs = calculateLocations (mn); for (int i = 0; i < (int) locs.size (); i++) if (locs [i]._zone.hasIn (pos)) vLocs [i] = locs [i]; if (vLocs.empty ()) return (result); // Incredible, but it could happen. Sabreman movements take into account // the position of the corner most oriented to the movement // When this method is calling, the position could be any! bool found = false; while (!found) { for (Locations::const_iterator j = vLocs.begin (); j != vLocs.end () && !found; j++) if (!(*j).second._zone.hasIn (result)) // The minimum zone... found = true; if (!found) result += or; } return (result); }
// Location Management /*virtual*/ void AssetLocatorMemoryImpl::addLevelOfDetailLocation( AssetTag* pAssetTag, unsigned int lod, std::string location ) { Locations locations = mAssetLocations[ pAssetTag ]; // Defensive Progamming: Cap LOD at size of old_vector. if (lod > locations.size()) lod = locations.size(); locations.insert( locations.begin() + lod, location ); mAssetLocations[ pAssetTag ] = locations; }
Locations::iterator findClosest(Position& beg, Locations& others) { double closest = std::numeric_limits<double>::max(); Locations::iterator pos = others.end(); for(Locations::iterator it = others.begin(); it != others.end(); ++it) { double current = distance(beg, it->second); if(current < closest) { closest = current; pos = it; } } return pos; }