Original Post
Hello. Im trying to do frustum culling, but i cant get it to work properly. Iv concluded that it must be the intersection test between the 3d plane and the quadtree node's bounding cube (a 2d rect). I am using a intersection algorithm i got from the book "3d Terrain Engine programming with dx9". And im getting some really strange results. For instance, when i create a plane at the point 0,0,0 with the normal 0,0,1. Only the first row of nodes in the quadtree after the position 0,0 reports as beeing behind the plane, and all other nodes behind them dont. This is wrong since all nodes below 0,0 of the tree should be behind a plane at those coordinages. Anyway this is what the algorithm looks like, if anyone can catch what is wrong with it i would be very happy. Thanks in advance.
//-----------------------------------------------------------------------------
// Name: classify_plane
// Desc:
//-----------------------------------------------------------------------------
inline int classify_plane(const cube_t& cube, const plane_t& plane)
{
vector3d_t min_point, max_point;
// build two points based on the direction
// of the plane vector. min_point
// and max_point are the two points
// on the rectangle furthest away from
// each other along the plane normal
if (plane.m_normal.x > 0.0f)
{
min_point.x = (float)cube.m_point0.x;
max_point.x = (float)cube.m_point1.x;
}
else
{
min_point.x = (float)cube.m_point1.x;
max_point.x = (float)cube.m_point0.x;
}
if (plane.m_normal.y > 0.0f)
{
min_point.y = (float)cube.m_point0.y;
max_point.y = (float)cube.m_point1.y;
}
else
{
min_point.y = (float)cube.m_point1.y;
max_point.y = (float)cube.m_point0.y;
}
if (plane.m_normal.z > 0.0f)
{
min_point.z = (float)cube.m_point0.z;
max_point.z = (float)cube.m_point1.z;
}
else
{
min_point.z = (float)cube.m_point1.z;
max_point.z = (float)cube.m_point0.z;
}
// compute the signed distance from
// the plane to both points
float dmin = plane.signed_distance(min_point);
float dmax = plane.signed_distance(max_point);
// the rectangle intersects the plane if
// one value is positive and the other is negative
if (dmin * dmax < 0.0f)
{
return PLANE_INTERSECT;
}
else if (dmin)
{
return PLANE_FRONT;
}
return PLANE_BACK;
}