Hi,
I've added a AABB Sphere intersection tests in my collision 'library'. The approach I'm taking is:
- calculate 'max' vector of sphere center and AABB min (lets call it maxSphereAABB)
- calculate 'min' vector of maxSphereAABB and AABB max
- this results in a vector between the closest point on the AABB to the spherecenter
- now I compare the length of this vector to the sphere radius
Voila, is the distance is lower, we have intersection.
This all works fine I believe, but my questions are:
- how can I logically explain/ draw out how I'm calculating the point closest on the AABB.
I've tried it with drawing an example but that didn't work out:
Maybe someone can draw me a better example where I can visually see the maxSphereAABB vector etc. to finally find the closestPointOnAABB.
Another question I have, is how do I go from here if I wanted to check for intersection between a OBB and a Sphere.
bool AABBSphereCollision(const AABBWORLD &pAABB, const SPHERE &pSphere)
{
XMVECTOR maxSphereAABB = XMVectorMax(XMLoadFloat3(&pSphere.WorldCenter), XMLoadFloat3(&pAABB._Min));
XMVECTOR closestPointInAABB = XMVectorMin(maxSphereAABB, XMLoadFloat3(&pAABB._Max));
XMVECTOR dist = XMVector3Length(closestPointInAABB - XMLoadFloat3(&pSphere.WorldCenter));
float distSqr = XMVectorGetX(dist) * XMVectorGetX(dist);
if(distSqr < pSphere.RadiusSqr()) return true;
return false;
}
Any input is appreciated.