Quote
Doesn't each axis need to pass this test to result in a collision, not just one?
Posted 16 July 2007 - 02:27 PM
Quote
Posted 16 July 2007 - 02:43 PM
Posted 16 July 2007 - 02:45 PM
Posted 16 July 2007 - 02:49 PM
Posted 16 July 2007 - 02:57 PM
bronxbomber92 said:
bool boxesIntersect(aabb a, aabb :)
{
return
a.min.x > b.max.x || a.max.x < b.min.x ||
a.min.y > b.max.y || a.max.y < b.min.y ||
a.min.z > b.max.z || a.max.z < b.min.z;
}
bool boxIsContainedWithinBox(aabb inner, aabb outer)
{
return
a.min.x >= b.min.x && a.max.x <= b.max.x &&
a.min.y >= b.min.y && a.max.y <= b.max.y &&
a.min.z >= b.min.z && a.max.z <= b.max.z;
}
Of course, this function only tests whether A is in B. If you want to test the other way around as well, swap A and B and call the same function.
Posted 16 July 2007 - 03:05 PM
int AABB::IntersectsAABB( const AABB& box )
{
if( box.min.x >= min.x && box.max.x <= max.x &&
box.min.y >= min.y && box.max.y <= max.y &&
box.min.z >= min.z && box.max.z <= max.z )
{
return INSIDE;
}
if( max.x < box.min.x || min.x > box.max.x )
return OUTSIDE;
if( max.y < box.min.y || min.y > box.max.y )
return OUTSIDE;
if( max.z < box.min.z || min.z > box.max.z )
return OUTSIDE;
return INTERSECTS;
}
Posted 18 July 2007 - 05:46 PM
bool AABB::IntersectsPlane( const CVector3D& normal, const float distanceFromOrigin )
{
CVector3D diagMin, diagMax;
if( normal.x >= 0 )
{
diagMin.x = min.x;
diagMax.x = max.x;
}
else
{
diagMin.x = max.x;
diagMax.x = min.x;
}
if( normal.y >= 0 )
{
diagMin.y = min.y;
diagMax.y = max.y;
}
else
{
diagMin.y = max.y;
diagMax.y = min.y;
}
if( normal.z >= 0 )
{
diagMin.z = min.z;
diagMax.z = max.z;
}
else
{
diagMin.z = max.z;
diagMax.z = min.z;
}
float test = DotProduct( normal, diagMin ) + distanceFromOrigin;
if( test > 0.0f )
return false;
test = DotProduct( normal, diagMax ) + distanceFromOrigin;
if( test >= 0.0f )
return true;
else
return false;
}
Posted 18 July 2007 - 11:20 PM
bool AABB::Intersects(const Vector & normal, float dist)
{
Vector absNormal(fabs(normal.x), fabs(normal.y), fabs(normal.z))
float c = Dot(center, normal);
float e = Dot(extents, absNormal);
return dist < (c - e) || dist > (c + e);
}
The absNormal can be calculated very vast if you make use of SSE optimizations (simply bitwise AND the SSE vector register with 0x7fffffff 7fffffff 7fffffff 7ffffffff).
Posted 19 July 2007 - 04:15 AM
Posted 19 July 2007 - 06:39 AM
Posted 19 July 2007 - 04:40 PM
Posted 20 July 2007 - 04:48 AM
Posted 20 July 2007 - 10:02 AM
Reedbeta said:
Posted 20 July 2007 - 04:56 PM
.oisyn said:
0 members, 2 guests, 0 anonymous users