Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00014 #ifndef HRPCOLLISION_COLDET_MODEL_PAIR_H_INCLUDED
00015 #define HRPCOLLISION_COLDET_MODEL_PAIR_H_INCLUDED
00016
00017 #define LOCAL_EPSILON 0.0001f
00018
00019 #include "config.h"
00020 #include "CollisionData.h"
00021 #include "ColdetModel.h"
00022 #include "CollisionPairInserterBase.h"
00023 #include <vector>
00024 #include <hrpUtil/Referenced.h>
00025 #include <hrpUtil/config.h>
00026
00027 namespace hrp {
00028
00029 class HRP_COLLISION_EXPORT ColdetModelPair : public Referenced
00030 {
00031 public:
00032 ColdetModelPair();
00033 ColdetModelPair(ColdetModelPtr model0, ColdetModelPtr model1,
00034 double tolerance=0);
00035 ColdetModelPair(const ColdetModelPair& org);
00036 virtual ~ColdetModelPair();
00037
00038 void set(ColdetModelPtr model0, ColdetModelPtr model1);
00039
00040 ColdetModel* model(int index) { return models[index].get(); }
00041 IceMaths::Matrix4x4* transform(int index) { return models[index]->transform; }
00042
00043 std::vector<collision_data>& detectCollisions() {
00044 return detectCollisionsSub(true);
00045 }
00046
00047 std::vector<collision_data>& collisions() {
00048 return collisionPairInserter->cdContact;
00049 }
00050
00051 void clearCollisions(){
00052 collisionPairInserter->cdContact.clear();
00053 }
00054
00055 bool checkCollision() {
00056 return !detectCollisionsSub(false).empty();
00057 }
00058
00059 double computeDistance(double *point0, double *point1);
00060
00065 double computeDistance(int& out_triangle0, double* out_point0, int& out_triangle1, double* out_point1);
00066
00067 bool detectIntersection();
00068
00069 double tolerance() const { return tolerance_; }
00070
00071 void setCollisionPairInserter(CollisionPairInserterBase *inserter);
00072
00073 int calculateCentroidIntersection(float &cx, float &cy, float &A, float radius, std::vector<float> vx, std::vector<float> vy);
00074
00075 int makeCCW(std::vector<float> &vx, std::vector<float> &vy);
00076
00077 float calculatePolygonArea(const std::vector<float> &vx, const std::vector<float> &vy);
00078 void calculateSectorCentroid(float &cx, float &cy, float radius, float th1, float th2);
00079
00080 inline bool isInsideCircle(float r, float x, float y) {
00081 return sqrt(pow(x, 2) + pow(y, 2)) <= r;
00082 }
00083 bool isInsideTriangle(float x, float y, const std::vector<float> &vx, const std::vector<float> &vy);
00084
00085 int calculateIntersection(std::vector<float> &x, std::vector<float> &y, float radius, float x1, float y1, float x2, float y2);
00086 ColdetModelPair& operator=(const ColdetModelPair& cmp);
00087
00088 void enableNormalVectorCorrection(bool flag) {
00089 collisionPairInserter->normalVectorCorrection = flag;
00090 }
00091 private:
00092 std::vector<collision_data>& detectCollisionsSub(bool detectAllContacts);
00093 bool detectMeshMeshCollisions(bool detectAllContacts);
00094 bool detectSphereSphereCollisions(bool detectAllContacts);
00095 bool detectSphereMeshCollisions(bool detectAllContacts);
00096 bool detectPlaneCylinderCollisions(bool detectAllContacts);
00097 bool detectPlaneMeshCollisions(bool detectAllContacts);
00098
00099 ColdetModelPtr models[2];
00100 double tolerance_;
00101
00102 CollisionPairInserterBase *collisionPairInserter;
00103
00104 int boxTestsCount;
00105 int triTestsCount;
00106
00107 enum pointType {vertex, inter};
00108 enum figType {tri, sector};
00109
00110 struct pointStruct {
00111 float x, y, angle;
00112 pointType type;
00113 int code;
00114 };
00115
00116 struct figStruct {
00117 figType type;
00118 int p1, p2;
00119 float area;
00120 float cx, cy;
00121 };
00122 };
00123
00124 typedef boost::intrusive_ptr<ColdetModelPair> ColdetModelPairPtr;
00125 }
00126
00127
00128 #endif