Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00037 #include "fcl/broadphase/broadphase_bruteforce.h"
00038 #include <limits>
00039
00040 namespace fcl
00041 {
00042
00043 void NaiveCollisionManager::registerObjects(const std::vector<CollisionObject*>& other_objs)
00044 {
00045 std::copy(other_objs.begin(), other_objs.end(), std::back_inserter(objs));
00046 }
00047
00048 void NaiveCollisionManager::unregisterObject(CollisionObject* obj)
00049 {
00050 objs.remove(obj);
00051 }
00052
00053 void NaiveCollisionManager::registerObject(CollisionObject* obj)
00054 {
00055 objs.push_back(obj);
00056 }
00057
00058 void NaiveCollisionManager::setup()
00059 {
00060
00061 }
00062
00063 void NaiveCollisionManager::update()
00064 {
00065
00066 }
00067
00068 void NaiveCollisionManager::clear()
00069 {
00070 objs.clear();
00071 }
00072
00073 void NaiveCollisionManager::getObjects(std::vector<CollisionObject*>& objs_) const
00074 {
00075 objs_.resize(objs.size());
00076 std::copy(objs.begin(), objs.end(), objs_.begin());
00077 }
00078
00079 void NaiveCollisionManager::collide(CollisionObject* obj, void* cdata, CollisionCallBack callback) const
00080 {
00081 if(size() == 0) return;
00082
00083 for(std::list<CollisionObject*>::const_iterator it = objs.begin(), end = objs.end(); it != end; ++it)
00084 {
00085 if(callback(obj, *it, cdata))
00086 return;
00087 }
00088 }
00089
00090 void NaiveCollisionManager::distance(CollisionObject* obj, void* cdata, DistanceCallBack callback) const
00091 {
00092 if(size() == 0) return;
00093
00094 FCL_REAL min_dist = std::numeric_limits<FCL_REAL>::max();
00095 for(std::list<CollisionObject*>::const_iterator it = objs.begin(), end = objs.end();
00096 it != end; ++it)
00097 {
00098 if(obj->getAABB().distance((*it)->getAABB()) < min_dist)
00099 {
00100 if(callback(obj, *it, cdata, min_dist))
00101 return;
00102 }
00103 }
00104 }
00105
00106 void NaiveCollisionManager::collide(void* cdata, CollisionCallBack callback) const
00107 {
00108 if(size() == 0) return;
00109
00110 for(std::list<CollisionObject*>::const_iterator it1 = objs.begin(), end = objs.end();
00111 it1 != end; ++it1)
00112 {
00113 std::list<CollisionObject*>::const_iterator it2 = it1; it2++;
00114 for(; it2 != end; ++it2)
00115 {
00116 if((*it1)->getAABB().overlap((*it2)->getAABB()))
00117 if(callback(*it1, *it2, cdata))
00118 return;
00119 }
00120 }
00121 }
00122
00123 void NaiveCollisionManager::distance(void* cdata, DistanceCallBack callback) const
00124 {
00125 if(size() == 0) return;
00126
00127 FCL_REAL min_dist = std::numeric_limits<FCL_REAL>::max();
00128 for(std::list<CollisionObject*>::const_iterator it1 = objs.begin(), end = objs.end(); it1 != end; ++it1)
00129 {
00130 std::list<CollisionObject*>::const_iterator it2 = it1; it2++;
00131 for(; it2 != end; ++it2)
00132 {
00133 if((*it1)->getAABB().distance((*it2)->getAABB()) < min_dist)
00134 {
00135 if(callback(*it1, *it2, cdata, min_dist))
00136 return;
00137 }
00138 }
00139 }
00140 }
00141
00142 void NaiveCollisionManager::collide(BroadPhaseCollisionManager* other_manager_, void* cdata, CollisionCallBack callback) const
00143 {
00144 NaiveCollisionManager* other_manager = static_cast<NaiveCollisionManager*>(other_manager_);
00145
00146 if((size() == 0) || (other_manager->size() == 0)) return;
00147
00148 if(this == other_manager)
00149 {
00150 collide(cdata, callback);
00151 return;
00152 }
00153
00154 for(std::list<CollisionObject*>::const_iterator it1 = objs.begin(), end1 = objs.end(); it1 != end1; ++it1)
00155 {
00156 for(std::list<CollisionObject*>::const_iterator it2 = other_manager->objs.begin(), end2 = other_manager->objs.end(); it2 != end2; ++it2)
00157 {
00158 if((*it1)->getAABB().overlap((*it2)->getAABB()))
00159 if(callback((*it1), (*it2), cdata))
00160 return;
00161 }
00162 }
00163 }
00164
00165 void NaiveCollisionManager::distance(BroadPhaseCollisionManager* other_manager_, void* cdata, DistanceCallBack callback) const
00166 {
00167 NaiveCollisionManager* other_manager = static_cast<NaiveCollisionManager*>(other_manager_);
00168
00169 if((size() == 0) || (other_manager->size() == 0)) return;
00170
00171 if(this == other_manager)
00172 {
00173 distance(cdata, callback);
00174 return;
00175 }
00176
00177 FCL_REAL min_dist = std::numeric_limits<FCL_REAL>::max();
00178 for(std::list<CollisionObject*>::const_iterator it1 = objs.begin(), end1 = objs.end(); it1 != end1; ++it1)
00179 {
00180 for(std::list<CollisionObject*>::const_iterator it2 = other_manager->objs.begin(), end2 = other_manager->objs.end(); it2 != end2; ++it2)
00181 {
00182 if((*it1)->getAABB().distance((*it2)->getAABB()) < min_dist)
00183 {
00184 if(callback(*it1, *it2, cdata, min_dist))
00185 return;
00186 }
00187 }
00188 }
00189 }
00190
00191 bool NaiveCollisionManager::empty() const
00192 {
00193 return objs.empty();
00194 }
00195
00196
00197 }