I am having problem with my frustum culling test (video describes):
Video
Here is the source:
//Frustum Calculation from ModelViewProjection Matrixvoid Frustum::Calculate(const Matrix &modelviewprojection) { const real * m = modelviewprojection.row; plane.normal.x = m[3] - m[0]; plane.normal.y = m[7] - m[4]; plane.normal.z = m[11] - m[8]; plane.d = m[15] - m[12]; plane.Normalize(); plane.normal.x = m[3] + m[0]; plane.normal.y = m[7] + m[4]; plane.normal.z = m[11] + m[8]; plane.d = m[15] + m[12]; plane.Normalize(); plane[TOP].normal.x = m[3] - m[1]; plane[TOP].normal.y = m[7] - m[5]; plane[TOP].normal.z = m[11] - m[9]; plane[TOP].d = m[15] - m[13]; plane[TOP].Normalize(); plane[BOTTOM].normal.x = m[3] + m[1]; plane[BOTTOM].normal.y = m[7] + m[5]; plane[BOTTOM].normal.z = m[11] + m[9]; plane[BOTTOM].d = m[15] + m[13]; plane[BOTTOM].Normalize(); plane[FAR].normal.x = m[3] - m[2]; plane[FAR].normal.y = m[7] - m[6]; plane[FAR].normal.z = m[11] - m[10]; plane[FAR].d = m[15] - m[14]; plane[FAR].Normalize(); plane[NEAR].normal.x = m[3] + m[2]; plane[NEAR].normal.y = m[7] + m[6]; plane[NEAR].normal.z = m[11] + m[10]; plane[NEAR].d = m[15] + m[14]; plane[NEAR].Normalize();}
//Test AABBVector3 getPositiveVertex(Vector3 min, Vector3 max, Vector3 point) { Vector3 p(min); if(point.x >= 0) p.x = max.x; if(point.y >= 0) p.y = max.y; if(point.z >= 0) p.z = max.z; return p;}Vector3 getNegativeVertex(Vector3 min, Vector3 max, Vector3 point) { Vector3 p(max); if(point.x >= 0) p.x = min.x; if(point.y >= 0) p.y = min.y; if(point.z >= 0) p.z = min.z; return p;}bool FrustumInBox(dour::Frustum * frustum, Vector3 min, Vector3 max) { for(uint i = 0; i < 6; ++i) { Plane &p = frustum->getPlane(i); if(Vector3::Dot(p.normal, getPositiveVertex(min, max, p.normal) + p.d) < 0) return false; //if(Vector3::Dot(p.normal, getVertexNegative(p.normal, min, max) + p.d)) -> don't need inside or intersection right now. if has contact draw } return true;}
//Octree Testvoid OctreeInFrustum(dour::OctreeNode * root, dour::Frustum * frustum) { if(FrustumInBox(frustum, root->min_, root->max_)) { if(root->submeshes.size() > 0) visibleNodes.push_back(root); if(root->nodes[0]) for(int i = 0; i < 8; ++i) OctreeInFrustum(root->nodes, frustum); }}
//Draw for(VisNodeList::iterator i = visibleNodes.begin(); i != visibleNodes.end(); ++i) DrawEntity((*i));
Thanks,
Kasya