示例#1
0
unsigned int FindPlane( vec3d_t norm, fp_t dist )
{
	int		i;	

	SnapPlane( norm, &dist );

 	for ( i = 0; i < p_planenum; i++ )
	{
		if ( ArePlanesEqual( p_planes[i].norm, p_planes[i].dist, norm, dist ) )
		{
			aplane_t	*pl;
			pl = (aplane_t *) malloc( sizeof( aplane_t) );
			Vec3dCopy( pl->norm, norm );
			pl->dist = dist;
			pl->next = p_planes[i].planes;
			p_planes[i].planes = pl;
			return i;				   
		}
#if 0
		else if ( ArePlanesNearlyEqual( p_planes[i].norm, p_planes[i].dist, norm, dist ) )
			printf( " * FindPlane: planes are nearly equal. *\n" );
#endif
	 
	}

	return AddPlane( norm, dist );
}
示例#2
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 );
}
示例#3
0
文件: map.c 项目: clbr/netradiant
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 );
}
示例#4
0
文件: map.c 项目: TTimo/GtkRadiant
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);
}
示例#5
0
文件: map.c 项目: TTimo/GtkRadiant
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 );
}
示例#6
0
文件: map.c 项目: darkshade9/aq2w
/*
 * 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);
}
示例#7
0
文件: map.c 项目: EEmmanuel7/quetoo
/*
 * @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);
}
示例#8
0
文件: map.cpp 项目: nicogiraldi/ufoai
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);
}
示例#9
0
/*
  ====================
  WritePlaneClass

  ====================
*/
void WritePlaneClass( char *name )
{
	FILE		*h;
	int		i;

	hobj_t		*planecls;
	hobj_t		*tmp;
	hpair_t		*pair;
	char		idtext[256];

#if 0
	printf( "averraging planes ...\n" );
	for ( i = 0; i < p_planenum; i+=2 )
	{
		int		num;
		vec3d_t		norm;
		fp_t		dist;
		aplane_t	*pl;
		Vec3dCopy( norm, p_planes[i].norm );
		dist = p_planes[i].dist;

		for ( num = 1, pl = p_planes[i].planes; pl ; pl=pl->next, num++ )
		{
			Vec3dAdd( norm, pl->norm, norm );
			dist+=pl->dist;
		}
		Vec3dUnify2( p_planes[i].norm, norm );
		p_planes[i].dist = dist / ((fp_t)(num));

		SnapPlane( p_planes[i].norm, &p_planes[i].dist );
		Vec3dFlip( p_planes[i+1].norm, p_planes[i].norm );
		p_planes[i+1].dist = -p_planes[i].dist;
	}
#endif	

	planecls = NewClass( "planes", "planes0" );

	for ( i = 0; i < p_planenum; i++ )
	{
		sprintf( idtext, "#%u", p_planes[i].clsname );
		tmp = NewClass( "plane", idtext );
		
		sprintf( idtext, "%f %f %f", p_planes[i].norm[0], p_planes[i].norm[1], p_planes[i].norm[2] );
		pair = NewHPair2( "vec3d", "norm", idtext );
		InsertHPair( tmp, pair );

		sprintf( idtext, "%f", p_planes[i].dist );
		pair = NewHPair2( "float", "dist", idtext );
		InsertHPair( tmp, pair );

		sprintf( idtext, "%d", p_planes[i].type );
		pair = NewHPair2( "int", "type", idtext );
		InsertHPair( tmp, pair );

		sprintf( idtext, "#%u", p_planes[i].clsref_flipplane );
		pair = NewHPair2( "ref", "flipplane", idtext );
		InsertHPair( tmp, pair );

		InsertClass( planecls, tmp );
	}

	h = fopen( name, "w" );
	WriteClass( planecls, h );
	fclose( h );
}