Changeset 1309 for GTP/trunk/Lib/Geom
- Timestamp:
- 09/01/06 10:52:30 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoLodManager.cpp
r1071 r1309 12 12 #include "GeoLodManager.h" 13 13 #include "GeoLodObject.h" 14 14 #include <algorithm> 15 /* 15 16 namespace Geometry 16 17 { 18 19 17 20 class lodobj_idpos_node_t 18 21 { … … 21 24 LodObject *lodobj; 22 25 float dist2cam; // used to index the lodobj in the other map 23 bool must_recalculate_distance;24 26 bool operator < (const lodobj_idpos_node_t &o) const { return (lodobj->GetUniqueID()<o.lodobj->GetUniqueID()); } 25 27 }; 26 } 28 }*/ 27 29 28 30 using namespace Geometry; … … 32 34 near_range(near),far_range(far) 33 35 { 36 // make the lodobj_dists vector into a heap 37 make_heap(lodobj_dists.begin(),lodobj_dists.end()); 34 38 } 35 39 36 40 void Geometry::LodManager::AddLodObj(LodObject * o, const Geometry::Vector3 &p) 37 41 { 38 float dist = CalculateDistToCamera(p); 39 lodobj_dists[dist] = lodobj_dist_node_t(o); 42 float dist = CalculateDistToCamera(p); 43 lodobj_dists.push_back(lodobj_dist_node_t(dist,o)); 44 push_heap(lodobj_dists.begin(),lodobj_dists.end()); 45 // lodobj_dists[dist] = lodobj_dist_node_t(o); 40 46 UpdateLODObjectPos(o,p); 41 47 } … … 44 50 void Geometry::LodManager::UpdateLOD(void) 45 51 { 46 // recalculate distances if have to 47 if (camera_changed) 52 if (!lodobj_dists.empty()) 48 53 { 49 // if the camera has changed, recalculate all lodobject distances to it 50 lodobj_dists.clear(); 51 for (std::map<Geometry::lodobj_idpos_node_t,Geometry::Vector3>::iterator it = lodobj_pos.begin(); it != lodobj_pos.end(); it++) 52 { 53 const lodobj_idpos_node_t & posnode = it->first; 54 const Vector3 & pos = it->second; 55 float newdist = CalculateDistToCamera(pos); 56 lodobj_dists[newdist] = lodobj_dist_node_t(posnode.lodobj); 57 } 58 camera_changed=false; 59 } 60 else 61 { 62 // if any of the objects changed its position, the distance must be recalculated 63 for (std::map<Geometry::lodobj_idpos_node_t,Geometry::Vector3>::iterator it = lodobj_pos.begin(); it != lodobj_pos.end(); it++) 64 { 65 const lodobj_idpos_node_t & posnode = it->first; 66 if (posnode.must_recalculate_distance) 54 // update distances to the camera 55 bool must_resort = false; 56 for (std::vector<lodobj_dist_node_t>::iterator it=lodobj_dists.begin(); it!=lodobj_dists.end(); it++) 57 { 58 lodobj_dist_node_t & node = *it; 59 if (camera_changed || node.must_recalculate_distance) 67 60 { 68 const Vector3 & pos = it->second; 69 float newdist = CalculateDistToCamera(pos); 70 lodobj_dists[newdist] = lodobj_dist_node_t(posnode.lodobj); 71 /* lodobj_dists.erase(it);*/ 61 RecalculateDist(node); 62 must_resort=true; 72 63 } 73 64 } 65 if (must_resort) 66 sort_heap(lodobj_dists.begin(),lodobj_dists.end()); 67 68 // select a tree to change its LOD 69 // float random_dist = SelectRandomDistance(); 70 // std::map<float,Geometry::lodobj_dist_node_t>::iterator nearest = lodobj_dists.upper_bound(random_dist); 71 72 // the begining of the list is the greater element (greater dist) 73 lodobj_dist_node_t & node = lodobj_dists.front(); 74 74 } 75 camera_changed=false; 76 } 75 77 76 // select a tree to change its LOD 77 float random_dist = SelectRandomDistance(); 78 std::map<float,Geometry::lodobj_dist_node_t>::iterator nearest = lodobj_dists.upper_bound(random_dist); 78 void Geometry::LodManager::RecalculateDist(lodobj_dist_node_t & node) 79 { 80 std::map<uint32,Vector3>::iterator posit = lodobj_pos.find(node.lodobj->GetUniqueID()); 81 assert(posit!=lodobj_pos.end()); 82 const Vector3 & pos = posit->second; 83 84 node.dist2cam = CalculateDistToCamera(pos); 79 85 } 86 80 87 81 88 void Geometry::LodManager::UpdateCamera(const Geometry::Vector3 &p) … … 87 94 void Geometry::LodManager::UpdateLODObjectPos(LodObject *o, const Geometry::Vector3 &p) 88 95 { 89 lodobj_pos[ lodobj_idpos_node_t(o)] = p;96 lodobj_pos[o->GetUniqueID()] = p; 90 97 } 91 98
Note: See TracChangeset
for help on using the changeset viewer.