/* ================== CM_FindPlane2 ================== */ static int CM_FindPlane2(float plane[4], int *flipped) { #ifndef USE_HASHING int i; // see if the points are close enough to an existing plane for(i = 0; i < numPlanes; i++) { if(CM_PlaneEqual(&planes[i], plane, flipped)) return i; } *flipped = false; return CM_CreateNewFloatPlane(plane); #else int i, hash, h; cPlane_t *p; hash = CM_GenerateHashValue(plane); // search the border bins as well for(i = -1; i <= 1; i++) { h = (hash + i) & (PLANE_HASHES - 1); for(p = planeHashTable[h]; p; p = p->hashChain) { if(CM_PlaneEqual(p, plane, flipped)) { return p - planes; } } } *flipped = false; return CM_CreateNewFloatPlane(plane); #endif }
/* ================== CM_FindPlane2 ================== */ int CM_FindPlane2( float plane[ 4 ], bool *flipped ) { int i; cPlane_t *p; int hash, h; //SnapPlane(normal, &dist); hash = CM_GenerateHashValue( plane ); // search the border bins as well for ( i = -1; i <= 1; i++ ) { h = ( hash + i ) & ( PLANE_HASHES - 1 ); for ( p = planeHashTable[ h ]; p; p = p->hashChain ) { if ( CM_PlaneEqual( p, plane, flipped ) ) { return p - planes; } } } *flipped = false; return CM_CreateNewFloatPlane( plane ); }
/* ================ CM_AddPlaneToHash ================ */ static void CM_AddPlaneToHash(cPlane_t * p) { long hash; hash = CM_GenerateHashValue(p->plane); p->hashChain = planeHashTable[hash]; planeHashTable[hash] = p; }
/* ================== CM_FindPlane ================== */ int CM_FindPlane( const float *p1, const float *p2, const float *p3 ) { float plane[ 4 ]; int i; float d; cPlane_t *p; int hash, h; if ( !CM_PlaneFromPoints( plane, p1, p2, p3 ) ) { return -1; } hash = CM_GenerateHashValue( plane ); // search the border bins as well for ( i = -1; i <= 1; i++ ) { h = ( hash + i ) & ( PLANE_HASHES - 1 ); for ( p = planeHashTable[ h ]; p; p = p->hashChain ) { //check points on the plane if ( DotProduct( plane, p->plane ) < 0 ) { continue; // allow backwards planes? } d = DotProduct( p1, p->plane ) - p->plane[ 3 ]; if ( d < -PLANE_TRI_EPSILON || d > PLANE_TRI_EPSILON ) { continue; } d = DotProduct( p2, p->plane ) - p->plane[ 3 ]; if ( d < -PLANE_TRI_EPSILON || d > PLANE_TRI_EPSILON ) { continue; } d = DotProduct( p3, p->plane ) - p->plane[ 3 ]; if ( d < -PLANE_TRI_EPSILON || d > PLANE_TRI_EPSILON ) { continue; } return p - planes; } } return CM_CreateNewFloatPlane( plane ); }