Ejemplo n.º 1
0
/*
==================
CM_FindPlane
==================
*/
static int CM_FindPlane( float *p1, float *p2, float *p3 )
{
	float plane[ 4 ];
	int   i;
	float d;

	if ( !CM_PlaneFromPoints( plane, p1, p2, p3 ) )
	{
		return -1;
	}

	// see if the points are close enough to an existing plane
	for ( i = 0; i < numPlanes; i++ )
	{
		if ( DotProduct( plane, planes[ i ].plane ) < 0 )
		{
			continue; // allow backwards planes?
		}

		d = DotProduct( p1, planes[ i ].plane ) - planes[ i ].plane[ 3 ];

		if ( d < -PLANE_TRI_EPSILON || d > PLANE_TRI_EPSILON )
		{
			continue;
		}

		d = DotProduct( p2, planes[ i ].plane ) - planes[ i ].plane[ 3 ];

		if ( d < -PLANE_TRI_EPSILON || d > PLANE_TRI_EPSILON )
		{
			continue;
		}

		d = DotProduct( p3, planes[ i ].plane ) - planes[ i ].plane[ 3 ];

		if ( d < -PLANE_TRI_EPSILON || d > PLANE_TRI_EPSILON )
		{
			continue;
		}

		// found it
		return i;
	}

	// add a new plane
	if ( numPlanes == MAX_PATCH_PLANES )
	{
		Com_Error( ERR_DROP, "MAX_PATCH_PLANES" );
	}

	Vector4Copy( plane, planes[ numPlanes ].plane );
	planes[ numPlanes ].signbits = CM_SignbitsForNormal( plane );

	numPlanes++;

	return numPlanes - 1;
}
Ejemplo n.º 2
0
/*
==================
CM_FindPlane
==================
*/
static int CM_FindPlane( const float *p1, const float *p2, const float *p3 )
{
	float	plane[4];
	int	dummy;

	if( !CM_PlaneFromPoints( plane, p1, p2, p3 ))
		return -1;

	return CM_FindPlane2( plane, &dummy );
}
Ejemplo n.º 3
0
/*
==================
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 );
}
Ejemplo n.º 4
0
/*
==================
CM_FindPlane
==================
*/
static int CM_FindPlane(const float *p1, const float *p2, const float *p3) {
	float           plane[4];
	int             i;

	if(!CM_PlaneFromPoints(plane, p1, p2, p3))
	{
		return -1;
	}

	// use variable i as dummy
	return CM_FindPlane2(plane, &i);
}
Ejemplo n.º 5
0
/*
==================
CM_FindPlane
==================
*/
static int CM_FindPlane( bfixed *p1, bfixed *p2, bfixed *p3 ) {
	planeDef_t plane;
	int		i;
	bfixed	d;

	if ( !CM_PlaneFromPoints( plane, p1, p2, p3 ) ) {
		return -1;
	}

	// see if the points are close enough to an existing plane
	for ( i = 0 ; i < numPlanes ; i++ ) {
		if ( FIXED_VEC3DOT( plane.normal, planes[i].pd.normal ) < AFIXED_0 ) {
			continue;	// allow backwards planes?
		}

		d = FIXED_VEC3DOT( p1, planes[i].pd.normal ) - planes[i].pd.dist;
		if ( d < -PLANE_TRI_EPSILON || d > PLANE_TRI_EPSILON ) {
			continue;
		}

		d = FIXED_VEC3DOT( p2, planes[i].pd.normal ) - planes[i].pd.dist;
		if ( d < -PLANE_TRI_EPSILON || d > PLANE_TRI_EPSILON ) {
			continue;
		}

		d = FIXED_VEC3DOT( p3, planes[i].pd.normal ) - planes[i].pd.dist;
		if ( d < -PLANE_TRI_EPSILON || d > PLANE_TRI_EPSILON ) {
			continue;
		}

		// found it
		return i;
	}

	// add a new plane
	if ( numPlanes == MAX_PATCH_PLANES ) {
		Com_Error( ERR_DROP, "MAX_PATCH_PLANES" );
	}

	planes[numPlanes].pd=plane;
	planes[numPlanes].signbits = CM_SignbitsForNormal( plane.normal );

	numPlanes++;

	return numPlanes-1;
}