#ifndef AXIS_ALIGNED_BOUNDING_BOX_H
#define AXIS_ALIGNED_BOUNDING_BOX_H
namespace fw
{
struct Ray
{
D3DXVECTOR3 x0;
D3DXVECTOR3 n;
/* On spécifie l'inverse de n pour rendre le calcul plus rapide
c'est-à-dire opéré sans division */
D3DXVECTOR3 n_inv;
};
class AABB
{
public:
AABB();
AABB(const D3DXVECTOR3& min, const D3DXVECTOR3& max);
virtual ~AABB();
// Stocke tous les 8 côtés de la box dans le tableau
void GetEdges(std::vector<D3DXVECTOR3>& edges);
D3DXVECTOR3 GetCenter();
void Reset(float x, float y, float z);
void Reset(const D3DXVECTOR3& initValue);
void AddInternalPoint(float x, float y, float z);
void AddInternalPoint(const D3DXVECTOR3& p);
// Extent : distance maximale entre deux points de la box
D3DXVECTOR3 GetExtent() const;
// Renvoie le volume en unité de cube
float GetVolume();
const D3DXVECTOR3& GetMin() const ;
const D3DXVECTOR3& GetMax() const;
void Translate(const D3DXVECTOR3& translate);
void Scale(const D3DXVECTOR3& scale);
/*
Aide à la lecture :
AABB : Une Aligned Axis Bounding Box
Ray : Un rayon lancé depuis n'importe où
t : la position d'un segment à certain point
x0 : un point d'un segment (ici en l'occurence l'origine)
n : la direction du vecteur du segment
tmin, tmax : les valeurs de t pour les deux points d'intersections
http://www.scratchapixel.com/lessons/3d-basic-rendering/minimal-ray-tracer-rendering-simple-shapes/ray-box-intersection
*/
bool Intersects(const Ray& r);
void Repair();
void Transform(const D3DXMATRIX& mat);
bool Contains(const AABB& other);
private:
// Le côté proche
D3DXVECTOR3 m_minEdge;
// Le côté lointain
D3DXVECTOR3 m_maxEdge;
};
}
#endif