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 #ifndef _pqpcollision_h_
00027 #define _pqpcollision_h_
00028
00029 #include <map>
00030
00031 #include "collisionInterface.h"
00032
00033 class Body;
00034 class VCollide;
00035
00036 struct PQP_ContactResult;
00037
00043 class PQPCollision : public CollisionInterface
00044 {
00045 private:
00046 const static int MAXCOLLISIONS = 256;
00047
00048 VCollide *mVc;
00049 std::map<const Body*, int> mIds;
00050 std::map<int, Body*> mBodies;
00051
00052 inline int getId(const Body * body);
00053 inline Body* getBody(int id);
00054 bool getIdsFromList(const std::vector<Body*> *interestList, int **iList, int *iSize);
00055
00056 void convertContactReport(PQP_ContactResult *pqpReport, ContactReport *report);
00057
00058 public:
00059 PQPCollision();
00060 ~PQPCollision();
00061
00062
00063 virtual bool addBody(Body *body, bool ExpectEmpty = false);
00064 virtual void removeBody(Body *body);
00065 virtual void cloneBody(Body *clone, const Body *original);
00066 virtual void setBodyTransform(Body *body, const transf &t);
00067
00068
00069 virtual void activateBody(const Body *body, bool active);
00070 virtual void activatePair(const Body *body1, const Body *body2, bool active);
00071 virtual bool isActive(const Body *body1, const Body *body2 = NULL);
00072
00073
00074 virtual int allCollisions(DetectionType type, CollisionReport *report,
00075 const std::vector<Body*> *interestList);
00076
00077
00078 virtual int allContacts(CollisionReport *report, double threshold,
00079 const std::vector<Body*> *interestList);
00080 virtual int contact(ContactReport *report, double threshold,
00081 const Body *body1, const Body *body2);
00082
00083
00084 virtual double pointToBodyDistance(const Body *body1, position point,
00085 position &closestPoint, vec3 &closestNormal);
00086 virtual double bodyToBodyDistance(const Body *body1, const Body *body2,
00087 position &p1, position &p2);
00088
00089
00090 virtual void bodyRegion(const Body *body, position point, vec3 normal,
00091 double radius, Neighborhood *neighborhood);
00092
00093
00094 virtual void getBoundingVolumes(const Body* body, int depth, std::vector<BoundingBox> *bvs);
00095
00096
00098 virtual void newThread();
00099 };
00100
00101 int PQPCollision::getId(const Body *body)
00102 {
00103 std::map<const Body*, int>::const_iterator it = mIds.find(body);
00104 if ( it == mIds.end() ) return -1;
00105 return it->second;
00106 }
00107
00108 Body* PQPCollision::getBody(int id)
00109 {
00110 std::map<int, Body*>::iterator it = mBodies.find(id);
00111 if ( it == mBodies.end() ) return NULL;
00112 return it->second;
00113 }
00114
00115 #endif