# Frustum Culling help

i’ve got this function :

bool CFrustum::CubeInFrustum( float x, float y, float z, float size )
{
for(int i = 0; i < 6; i++ )
{
if(m_Frustum[i][A] * (x - size) + m_Frustum[i][b] * (y - size) + m_Frustum[i][C] * (z - size) + m_Frustum[i][D] > 0)
continue;
if(m_Frustum[i][A] * (x + size) + m_Frustum[i][b] * (y - size) + m_Frustum[i][C] * (z - size) + m_Frustum[i][D] > 0)
continue;
if(m_Frustum[i][A] * (x - size) + m_Frustum[i][b] * (y + size) + m_Frustum[i][C] * (z - size) + m_Frustum[i][D] > 0)
continue;
if(m_Frustum[i][A] * (x + size) + m_Frustum[i][b] * (y + size) + m_Frustum[i][C] * (z - size) + m_Frustum[i][D] > 0)
continue;
if(m_Frustum[i][A] * (x - size) + m_Frustum[i][b] * (y - size) + m_Frustum[i][C] * (z + size) + m_Frustum[i][D] > 0)
continue;
if(m_Frustum[i][A] * (x + size) + m_Frustum[i][b] * (y - size) + m_Frustum[i][C] * (z + size) + m_Frustum[i][D] > 0)
continue;
if(m_Frustum[i][A] * (x - size) + m_Frustum[i][b] * (y + size) + m_Frustum[i][C] * (z + size) + m_Frustum[i][D] > 0)
continue;
if(m_Frustum[i][A] * (x + size) + m_Frustum[i][b] * (y + size) + m_Frustum[i][C] * (z + size) + m_Frustum[i][D] > 0)
continue;

``````	// If we get here, it isn't in the frustum
return false;
}

return true;
``````

}

now i want to change this so i can test for a rectange that has x,y,z size not just one radius that a cube has
does anyone know how to change the function to do this?
thanks

[This message has been edited by jono_123 (edited 01-15-2003).]

[This message has been edited by jono_123 (edited 01-18-2003).]

Seems that you don’t really understand how it works. I suppose you should replace size being next to x, y, z to size_x, size_y, size_z respectively.
BTW frustum test is not very cheap and the one you post here especially (6*8=32 dots).
A very well known optimization to that looks more or less like that:

bool TestBBox(const BBox_c &BBox) const {
for (int i = 0; i < 6; i++) {
if (Planes[i].GetDistance(
Vec3_c((Planes[i].Normal > 0) ? BBox.Min : BBox.Max,
(Planes[i].Normal > 0) ? BBox.Min : BBox.Max,
(Planes[i].Normal > 0) ? BBox.Min : BBox.Max)) <= 0) {
return 0;
}
}
return 1;
}

So you have 6*1=6 dots:]

Hope it helps.

Hello

is this what you need jono_123 ?

bool CFrustum::BoxInFrustum( const Vector3D *vmin, const Vector3D *vmax )
{
static int i=0;
for(i = 0; i < 6; i++)
{
if(m_Frustum[i] * vmin->x + m_Frustum[i] * vmin->y + m_Frustum[i] * vmin->z + m_Frustum[i] > 0)
continue;
if(m_Frustum[i] * vmax->x + m_Frustum[i] * vmin->y + m_Frustum[i] * vmin->z + m_Frustum[i] > 0)
continue;
if(m_Frustum[i] * vmin->x + m_Frustum[i] * vmax->y + m_Frustum[i] * vmin->z + m_Frustum[i] > 0) continue;
if(m_Frustum[i] * vmax->x + m_Frustum[i] * vmax->y + m_Frustum[i] * vmin->z + m_Frustum[i] > 0)
continue;
if(m_Frustum[i] * vmin->x + m_Frustum[i] * vmin->y + m_Frustum[i] * vmax->z + m_Frustum[i] > 0) continue;
if(m_Frustum[i] * vmax->x + m_Frustum[i] * vmin->y + m_Frustum[i] * vmax->z + m_Frustum[i] > 0)
continue;
if(m_Frustum[i] * vmin->x + m_Frustum[i] * vmax->y + m_Frustum[i] * vmax->z + m_Frustum[i] > 0)
continue;
if(m_Frustum[i] * vmax->x + m_Frustum[i] * vmax->y + m_Frustum[i] * vmax->z + m_Frustum[i] > 0)
continue;
// If we get here, it isn’t in the frustum
return FALSE;
}
return TRUE;
}

MickeyMouse

please give me a tip (iam ill & my head hurts) ->Planes[i].GetDistance<- / ->Planes[i].Normal<-

I’m ill as well and have about 7 exams next week Plane has normal vector and distance from origin.
Plane->GetDistance(point) returns (point dot plane_normal - plane_distance) - distance from plane to point

i dont understand how frustum culling works, but i know it’s important to make it fast…

therefore, an idea :
it’s a simlple calculation to test if a cube contacts another cube… now, what about taking the smallest cube that contains the frustum and calculating the frustum test with this box if the correct function is very mhz-expensive ?