Esempio n. 1
0
/*
=================
FindFloatPlane

changed to allow a number of test points to be supplied that
must be within an epsilon distance of the plane
=================
*/
int FindFloatPlane( vec3_t normal, vec_t dist, int numPoints, vec3_t *points )
{
	int		i, j, hash, h;
	plane_t		*p;
	vec_t		d;
	
	
	SnapPlane( normal, &dist );
	hash = (PLANE_HASHES - 1) & (int)fabs( dist );
	
	for( i = -1; i <= 1; i++ )
	{
		h = (hash + i) & (PLANE_HASHES - 1);
		for( p = planehash[ h ]; p != NULL; p = p->hash_chain )
		{
			if( !PlaneEqual( p, normal, dist ))
				continue;
			
			// test supplied points against this plane
			for( j = 0; j < numPoints; j++ )
			{
				d = DotProduct( points[j], normal ) - dist;
				if( fabs( d ) > distanceEpsilon )
					break;
			}
			
			if( j >= numPoints )
				return p - mapplanes;
		}
	}
	
	// none found, so create a new one
	return CreateNewFloatPlane( normal, dist );
}
Esempio n. 2
0
int FindFloatPlane( vec3_t innormal, vec_t dist, int numPoints, vec3_t *points ) // NOTE: this has a side effect on the normal. Good or bad?

#ifdef USE_HASHING

{
	int		i, j, hash, h;
	int pidx;
	plane_t	*p;
	vec_t	d;
	vec3_t normal;

	VectorCopy(innormal, normal);
#if Q3MAP2_EXPERIMENTAL_SNAP_PLANE_FIX
	SnapPlaneImproved(normal, &dist, numPoints, (const vec3_t *) points);
#else
	SnapPlane( normal, &dist );
#endif
	/* hash the plane */
	hash = (PLANE_HASHES - 1) & (int) fabs( dist );
	
	/* search the border bins as well */
	for( i = -1; i <= 1; i++ )
	{
		h = (hash + i) & (PLANE_HASHES - 1);
		for( pidx = planehash[ h ] - 1; pidx != -1; pidx = mapplanes[pidx].hash_chain - 1 )
		{
			p = &mapplanes[pidx];

			/* do standard plane compare */
			if( !PlaneEqual( p, normal, dist ) )
				continue;
			
			/* ydnar: uncomment the following line for old-style plane finding */
			//%	return p - mapplanes;
			
			/* ydnar: test supplied points against this plane */
			for( j = 0; j < numPoints; j++ )
			{
				// NOTE: When dist approaches 2^16, the resolution of 32 bit floating
				// point number is greatly decreased.  The distanceEpsilon cannot be
				// very small when world coordinates extend to 2^16.  Making the
				// dot product here in 64 bit land will not really help the situation
				// because the error will already be carried in dist.
				d = DotProduct( points[ j ], p->normal ) - p->dist;
				d = fabs(d);
				if (d != 0.0 && d >= distanceEpsilon)
					break; // Point is too far from plane.
			}
			
			/* found a matching plane */
			if( j >= numPoints )
				return p - mapplanes;
		}
	}
	
	/* none found, so create a new one */
	return CreateNewFloatPlane( normal, dist );
}
Esempio n. 3
0
int		FindFloatPlane (vec3_t normal, vec_t dist)
{
	int		i;
	plane_t	*p;

	SnapPlane (normal, &dist);
	for (i=0, p=mapplanes ; i<nummapplanes ; i++, p++)
	{
		if (PlaneEqual (p, normal, dist))
			return i;
	}

	return CreateNewFloatPlane (normal, dist);
}
Esempio n. 4
0
int FindFloatPlane( vec3_t normal, vec_t dist, int numPoints, vec3_t *points )

#ifdef USE_HASHING

{
	int i, j, hash, h;
	plane_t *p;
	vec_t d;


	/* hash the plane */
	SnapPlane( normal, &dist );
	hash = ( PLANE_HASHES - 1 ) & (int) fabs( dist );

	/* search the border bins as well */
	for ( i = -1; i <= 1; i++ )
	{
		h = ( hash + i ) & ( PLANE_HASHES - 1 );
		for ( p = planehash[ h ]; p != NULL; p = p->hash_chain )
		{
			/* do standard plane compare */
			if ( !PlaneEqual( p, normal, dist ) ) {
				continue;
			}

			/* ydnar: uncomment the following line for old-style plane finding */
			//%	return p - mapplanes;

			/* ydnar: test supplied points against this plane */
			for ( j = 0; j < numPoints; j++ )
			{
				d = DotProduct( points[ j ], normal ) - dist;
				if ( fabs( d ) > distanceEpsilon ) {
					break;
				}
			}

			/* found a matching plane */
			if ( j >= numPoints ) {
				return p - mapplanes;
			}
		}
	}

	/* none found, so create a new one */
	return CreateNewFloatPlane( normal, dist );
}
Esempio n. 5
0
/*
 * FindFloatPlane
 */
int FindFloatPlane(vec3_t normal, vec_t dist) {
	int i;
	const map_plane_t *p;
	int hash;

	SnapPlane(normal, &dist);
	hash = (int) fabs(dist) / 8;
	hash &= (PLANE_HASHES - 1);

	// search the border bins as well
	for (i = -1; i <= 1; i++) {
		const int h = (hash + i) & (PLANE_HASHES - 1);
		for (p = plane_hash[h]; p; p = p->hash_chain) {
			if (PlaneEqual(p, normal, dist))
				return p - map_planes;
		}
	}

	return CreateNewFloatPlane(normal, dist);
}
Esempio n. 6
0
/*
 * @brief
 */
int32_t FindPlane(vec3_t normal, dvec_t dist) {
	int32_t i;

	SnapPlane(normal, &dist);
	const uint16_t hash = ((uint32_t) fabsl(dist)) & (PLANE_HASHES - 1);

	// search the border bins as well
	for (i = -1; i <= 1; i++) {
		const uint16_t h = (hash + i) & (PLANE_HASHES - 1);
		const map_plane_t *p = plane_hash[h];

		while (p) {
			if (PlaneEqual(p, normal, dist)) {
				return p - map_planes;
			}
			p = p->hash_chain;
		}
	}

	return CreateNewFloatPlane(normal, dist);
}
Esempio n. 7
0
uint16_t FindOrCreateFloatPlane (vec3_t normal, vec_t dist)
{
	int i;
	plane_t* p;
	int hash;

	SnapPlane(normal, &dist);
	hash = GetPlaneHashValueForDistance(dist);

	/* search the border bins as well */
	for (i = -1; i <= 1; i++) {
		const int h = (hash + i) & (PLANE_HASHES - 1);
		for (p = planehash[h]; p; p = p->hash_chain) {
			if (PlaneEqual(p, normal, dist)) {
				const intptr_t index = p - mapplanes;
				return (int16_t)index;
			}
		}
	}

	return CreateNewFloatPlane(normal, dist);
}