00001
00002
00003
00004 #ifndef BoundingBox_Header
00005 #define BoundingBox_Header
00006
00007 #include "face.h"
00008 #include "point3d.h"
00009 #include "reallocablearray.h"
00010
00011
00012 typedef struct CollisionBoxPairStruct CollisionBoxPair;
00013
00014
00015
00016 class BoundingBox {
00017 friend class BoundingBoxNode;
00018 friend class BoundingBoxLeaf;
00019 public:
00020 BoundingBox(BoundingBox* _parent);
00021 virtual ~BoundingBox();
00022
00023
00024 static BoundingBox* createTree(Object* object);
00025 static BoundingBox* createTree(List<BoundingBoxLeaf*> &bbList);
00026
00027
00028 virtual bool isLeaf() = 0;
00029 virtual void update() = 0;
00030 virtual void detectCollisions(BoundingBox* boundingBox, int myLevel, int otherLevel,
00031 ReallocableArray<CollisionBoxPair>* collisionPairs) = 0;
00032 virtual double collisionDepth(BoundingBox* boundingBox) = 0;
00033 virtual bool hasMarker() = 0;
00034 virtual void setMarker(bool marker_) = 0;
00035
00036 virtual void draw();
00037 virtual bool overlap(BoundingBox* boundingBox);
00038 virtual Point3D center();
00039
00040 inline BoundingBox* getParent() { return parent; }
00041 inline void setParent(BoundingBox* parent_) { parent = parent_; }
00042 inline Point3D getMin() { return min; }
00043 inline Point3D getMax() { return max; }
00044 inline void setMin(Point3D min_) { min = min_; }
00045 inline void setMax(Point3D max_) { max = max_; }
00046 inline Point3D getNormal() { return normal; }
00047 inline void setNormal(Point3D normal_) { normal = normal_; }
00048 inline Object* getObject() { return object; }
00049 inline void setObject(Object* object_) { object = object_; }
00050
00051 inline double getWidth() { return max.x - min.x; }
00052 inline double getHeight() { return max.y - min.y; }
00053 inline double getDepth() { return max.z - min.z; }
00054 inline double getVolume() { return getWidth() * getHeight() * getDepth(); }
00055 protected:
00056 BoundingBox* parent;
00057 Point3D min;
00058 Point3D max;
00059 Point3D normal;
00060 Object* object;
00061 };
00062
00063
00064 class BoundingBoxNode : public BoundingBox {
00065 public:
00066 BoundingBoxNode(BoundingBox *left_ = NULL,
00067 BoundingBox *right_ = NULL,
00068 BoundingBox *parent_ = NULL);
00069 ~BoundingBoxNode();
00070
00071 bool isLeaf() { return false; }
00072 void draw();
00073 void update();
00074 void internalUpdate();
00075 void detectCollisions(BoundingBox* boundingBox, int myLevel, int otherLevel,
00076 ReallocableArray<CollisionBoxPair>* collisionPairs);
00077 double collisionDepth(BoundingBox* boundingBox);
00078 bool hasMarker() { return marker; }
00079 void setMarker(bool marker_) { marker = marker_; };
00080
00081 inline BoundingBox* getLeft() { return left; }
00082 inline BoundingBox* getRight() { return right; }
00083 inline void setLeft(BoundingBox* left_) { left = left_; }
00084 inline void setRight(BoundingBox* right_) { right = right_; }
00085 private:
00086 BoundingBox *left;
00087 BoundingBox *right;
00088 bool marker;
00089 };
00090
00091
00092
00093 class BoundingBoxLeaf : public BoundingBox {
00094 public:
00095 BoundingBoxLeaf(Face *face_, BoundingBox *parent_ = NULL);
00096 ~BoundingBoxLeaf();
00097
00098 bool isLeaf() { return true; }
00099 void update();
00100 void detectCollisions(BoundingBox* boundingBox, int myLevel, int otherLevel,
00101 ReallocableArray<CollisionBoxPair>* collisionPairs);
00102 double collisionDepth(BoundingBox* boundingBox);
00103 bool hasMarker() { return face->getMarker(); }
00104 void setMarker(bool marker_) { face->setMarker(marker_); };
00105
00106 inline Face* getFace() { return face; }
00107 inline void setFace(Face *face_) { face = face_; }
00108 private:
00109 Face *face;
00110 };
00111
00112 #endif // BoundingBox_Header
00113