+/*
+FilterPointConvexHullIntoTree_r() - ydnar
+filters the convex hull of multiple points from a surface into the tree
+*/
+
+int FilterPointConvexHullIntoTree_r( vec3_t **points, int npoints, mapDrawSurface_t *ds, node_t *node )
+{
+ float d, dmin, dmax;
+ plane_t *plane;
+ int refs = 0;
+ int i;
+
+ if(!points)
+ return 0;
+
+ /* is this a decision node? */
+ if( node->planenum != PLANENUM_LEAF )
+ {
+ /* classify the point in relation to the plane */
+ plane = &mapplanes[ node->planenum ];
+
+ dmin = dmax = DotProduct( *(points[0]), plane->normal ) - plane->dist;
+ for(i = 1; i < npoints; ++i)
+ {
+ d = DotProduct( *(points[i]), plane->normal ) - plane->dist;
+ if(d > dmax)
+ dmax = d;
+ if(d < dmin)
+ dmin = d;
+ }
+
+ /* filter by this plane */
+ refs = 0;
+ if( dmax >= -ON_EPSILON )
+ refs += FilterPointConvexHullIntoTree_r( points, npoints, ds, node->children[ 0 ] );
+ if( dmin <= ON_EPSILON )
+ refs += FilterPointConvexHullIntoTree_r( points, npoints, ds, node->children[ 1 ] );
+
+ /* return */
+ return refs;
+ }
+
+ /* add a reference */
+ return AddReferenceToLeaf( ds, node );
+}