Axis Aligned Bounding Boxes (AABBs for short) are very easy to make. They are basically non-rotated boxes.
They can be made by having a max point and a min point or by having a center point and width/height/depth. For this example, I will use an AABB created with two points (min and max).
To check if a point is inside an AABB we just need to check if all its values (x,y and z) are greater than the AABB’s min values and less than the AABB’s max values.
Here is some sample C++ code using the DirectX Vector class.
struct TAABB
{
D3DXVECTOR3 m_vecMax;
D3DXVECTOR3 m_vecMin;
};
bool PointInAABB(const TAABB& tBox, const D3DXVECTOR3& vecPoint)
{
//Check if the point is less than max and greater than min
if(vecPoint.x > tBox.m_vecMin.x && vecPoint.x < tBox.m_vecMax.x &&
vecPoint.y > tBox.m_vecMin.y && vecPoint.y < tBox.m_vecMax.y &&
vecPoint.z > tBox.m_vecMin.z && vecPoint.z < tBox.m_vecMax.z)
{
return true;
}
//If not, then return false
return false;
}
{
D3DXVECTOR3 m_vecMax;
D3DXVECTOR3 m_vecMin;
};
bool PointInAABB(const TAABB& tBox, const D3DXVECTOR3& vecPoint)
{
//Check if the point is less than max and greater than min
if(vecPoint.x > tBox.m_vecMin.x && vecPoint.x < tBox.m_vecMax.x &&
vecPoint.y > tBox.m_vecMin.y && vecPoint.y < tBox.m_vecMax.y &&
vecPoint.z > tBox.m_vecMin.z && vecPoint.z < tBox.m_vecMax.z)
{
return true;
}
//If not, then return false
return false;
}
15 / Jun 2010