Пример #1
0
/*
=============
CL_TruePointContents

=============
*/
int CL_TruePointContents( const vec3_t p )
{
	int	i, contents;
	int	oldhull;
	hull_t	*hull;
	vec3_t	test, offset;
	physent_t	*pe;

	// sanity check
	if( !p )
		return CONTENTS_NONE;

	oldhull = clgame.pmove->usehull;

	// get base contents from world
	contents = PM_HullPointContents( &cl.worldmodel->hulls[0], 0, p );

	for( i = 0; i < clgame.pmove->nummoveent; i++ )
	{
		pe = &clgame.pmove->moveents[i];

		if( pe->solid != SOLID_NOT ) // disabled ?
			continue;

		// only brushes can have special contents
		if( !pe->model || pe->model->type != mod_brush )
			continue;

		// check water brushes accuracy
		clgame.pmove->usehull = 2;
		hull = PM_HullForBsp( pe, clgame.pmove, offset );
		clgame.pmove->usehull = oldhull;

		// offset the test point appropriately for this hull.
		VectorSubtract( p, offset, test );

		if( (pe->model->flags & MODEL_HAS_ORIGIN) && !VectorIsNull( pe->angles ))
		{
			matrix4x4	matrix;
	
			Matrix4x4_CreateFromEntity( matrix, pe->angles, offset, 1.0f );
			Matrix4x4_VectorITransform( matrix, p, test );
		};

		// test hull for intersection with this model
		if( PM_HullPointContents( hull, hull->firstclipnode, test ) == CONTENTS_EMPTY )
			continue;

		// compare contents ranking
		if( RankForContents( pe->skin ) > RankForContents( contents ))
			contents = pe->skin; // new content has more priority
	};

	return contents;
}
Пример #2
0
void LinkLeafFaces (surface_t *planelist, node_t *leafnode)
{
	face_t		*f;
	surface_t	*surf;
	int			rank, r;
	int			nummarkfaces;
	face_t		*markfaces[MAX_LEAF_FACES];

	leafnode->faces = NULL;
	leafnode->planenum = -1;

	rank = -1;
	for ( surf = planelist ; surf ; surf = surf->next)
	{
		for (f = surf->faces ; f ; f=f->next)
		{
			r = RankForContents (f->contents);
			if (r > rank)
				rank = r;
		}
	}

	leafnode->contents = ContentsForRank (rank);

	if (leafnode->contents != CONTENTS_SOLID)
	{
		nummarkfaces = 0;
		for (surf = leafnode->surfaces ; surf ; surf=surf->next)
		{
			for (f=surf->faces ; f ; f=f->next)
			{
				if (nummarkfaces == MAX_LEAF_FACES)
					Error ("nummarkfaces == MAX_LEAF_FACES");

				markfaces[nummarkfaces++] = f->original;
			}
		}

		c_leaffaces += nummarkfaces;
		markfaces[nummarkfaces] = NULL;	// end marker
		nummarkfaces++;

		leafnode->markfaces = malloc(nummarkfaces * sizeof(*leafnode->markfaces));
		memcpy (leafnode->markfaces, markfaces, nummarkfaces * sizeof(*leafnode->markfaces));
	}

	FreeLeafSurfs (leafnode);
	leafnode->surfaces = NULL;
}