// ** Only AABB in local space
// ** and object transform, as mentioned above :)
bool cFrustum::BoxInside( const cBoundingBox& box, const cMatrix4& T ) const
{
// ** Add object translation to AABB 'min' and 'max'
cBoundingBox aabb = box + T.GetTranslation();
const cVector3& min = aabb.min;
const cVector3& max = aabb.max;
cVector3 c = aabb.GetCenter();
// ** Half-extents
float w = aabb.GetWidth() * 0.5f;
float h = aabb.GetHeight() * 0.5f;
float d = aabb.GetDepth() * 0.5f;
// ** I don't have scale in matrix, so I just calculate a transpose
cMatrix4 tT = cMatrix4::Transpose( T );
for(int i = 0; i < 6; i++ )
{
cVector3 N = frustum.normal;
// ** Multiplies N by 3x3 transposed rotation matrix
tT.TransformVector( N );
// ** Intersection test as if it is an AABB
if( N * min + frustum.distance > 0 ) continue;
if( N * max + frustum.distance > 0 ) continue;
if(N.x * (c.x + w) + N.y * (c.y - h) + N.z * (c.z - d) + frustum.distance > 0)
continue;
if(N.x * (c.x - w) + N.y * (c.y + h) + N.z * (c.z - d) + frustum.distance > 0)
continue;
if(N.x * (c.x + w) + N.y * (c.y + h) + N.z * (c.z - d) + frustum.distance > 0)
continue;
if(N.x * (c.x - w) + N.y * (c.y - h) + N.z * (c.z + d) + frustum.distance > 0)
continue;
if(N.x * (c.x + w) + N.y * (c.y - h) + N.z * (c.z + d) + frustum.distance > 0)
continue;
if(N.x * (c.x - w) + N.y * (c.y + h) + N.z * (c.z + d) + frustum.distance > 0)
continue;
return false;
}
}
Thanks :)
Transforming frustum to OBB space
Hi there! :)
I need to check if the static mesh is in frustum. I already have a 'Frustum-AABB' test and it works, but I also need a 'Frustum-OBB' test... but everything I have is AABB in local space and object transform :)
I tried to transform normals of frustum planes and add object translation to AABB 'min' and 'max', but this works only if I have translation OR rotation matrix applied to object. If I concatenate this transforms( R*T ) my function doesn't work :(
Here is the code I wrote to check if OBB is in frustum:
Quote:Original post by 0xFF
I need to check if the static mesh is in frustum. I already have a 'Frustum-AABB' test and it works, but I also need a 'Frustum-OBB' test.
Intersection of Orthogonal View Frustum and Oriented
Bounding Box using Separation Axis Testing
I also have an implementation of this at my geometrictools.com website.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement