00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00021
00022
00023 #ifndef H_SPK_AABOX
00024 #define H_SPK_AABOX
00025
00026 #include "Core/SPK_Zone.h"
00027
00028 namespace SPK
00029 {
00036 class SPK_PREFIX AABox : public Zone
00037 {
00038 SPK_IMPLEMENT_REGISTERABLE(AABox)
00039
00040 public :
00041
00043
00045
00051 AABox(const Vector3D& position = Vector3D(0.0f,0.0f,0.0f),const Vector3D& dimension = Vector3D(0.0f,0.0f,0.0f));
00052
00059 static AABox* create(const Vector3D& position = Vector3D(0.0f,0.0f,0.0f),const Vector3D& dimension = Vector3D(0.0f,0.0f,0.0f));
00060
00062
00064
00073 void setDimension(const Vector3D& dimension);
00074
00076
00078
00083 const Vector3D& getDimension() const;
00084
00086
00088
00089 virtual void generatePosition(Particle& particle,bool full) const;
00090 virtual bool contains(const Vector3D& v) const;
00091 virtual bool intersects(const Vector3D& v0,const Vector3D& v1,Vector3D* intersection,Vector3D* normal) const;
00092 virtual void moveAtBorder(Vector3D& v,bool inside) const;
00093 virtual Vector3D computeNormal(const Vector3D& point) const;
00094
00095 private :
00096
00097 Vector3D dimension;
00098
00099 bool slabIntersects(float p0,float p1,float bMin,float bMax,float& tEnter,float& tExit,int& firstAxis,int axis) const;
00100 };
00101
00102
00103 inline AABox* AABox::create(const Vector3D& position,const Vector3D& dimension)
00104 {
00105 AABox* obj = new AABox(position,dimension);
00106 registerObject(obj);
00107 return obj;
00108 }
00109
00110 inline const Vector3D& AABox::getDimension() const
00111 {
00112 return dimension;
00113 }
00114
00115 inline bool AABox::slabIntersects(float p0,float p1,float bMin,float bMax,float& tEnter,float& tExit,int& firstAxis,int axis) const
00116 {
00117 float dir = p1 - p0;
00118
00119 if (dir == 0.0f)
00120 {
00121 if ((p0 < bMin)||(p0 > bMax))
00122 return false;
00123 return true;
00124 }
00125
00126 float t0 = (bMin - p0) / dir;
00127 float t1 = (bMax - p0) / dir;
00128
00129 if (t0 > t1)
00130 {
00131 std::swap(t0,t1);
00132 axis += 3;
00133 }
00134
00135 if ((t1 < tEnter)||(t0 > tExit))
00136 return false;
00137
00138 if (t0 > tEnter)
00139 {
00140 tEnter = t0;
00141 firstAxis = (firstAxis & 0xF0) | (axis & 0x0F);
00142 }
00143
00144 if (t1 < tExit)
00145 {
00146 tExit = t1;
00147 firstAxis = (firstAxis & 0x0F) | ((axis << 4) & 0xF0);
00148 }
00149
00150 return true;
00151 }
00152 }
00153
00154 #endif