Difference between revisions of "UTIL EntitiesAlongRay"

From Valve Developer Community
Jump to: navigation, search
(Created page with 'This is a Utility function that when supplied a Ray_t will return an integer indicating the number of entities encountered along the ray, then will enumerate and place them i…')
 
(Cleanup, Categories, etc)
Line 1: Line 1:
This is a Utility function that when supplied a [[Ray_t]] will return an integer indicating the number of entities encountered along the ray, then will enumerate and place them into an array.  
+
{{wrongtitle|UTIL_EntitiesAlongRay}}
 +
This is a UTIL function that when supplied a [[Ray_t]] will return an integer indicating the number of entities encountered along the ray, then will enumerate and place them into an array.  
  
 
You can either specify an array, and the size of the array, and a mask for which encountered entities will be included in the array, or you can simply supply a [[Ray_t]] and an pointer to an instance of the CFlaggedEntitiesEnum class.
 
You can either specify an array, and the size of the array, and a mask for which encountered entities will be included in the array, or you can simply supply a [[Ray_t]] and an pointer to an instance of the CFlaggedEntitiesEnum class.
  
== Function Headers ==
+
== Usage ==
 
<source lang=cpp>
 
<source lang=cpp>
 
int UTIL_EntitiesAlongRay( const Ray_t &ray, CFlaggedEntitiesEnum *pEnum )
 
int UTIL_EntitiesAlongRay( const Ray_t &ray, CFlaggedEntitiesEnum *pEnum )
 +
</source>
  
 +
<source lang=cpp>
 
int UTIL_EntitiesAlongRay( CBaseEntity **pList, int listMax, const Ray_t &ray, int flagMask )
 
int UTIL_EntitiesAlongRay( CBaseEntity **pList, int listMax, const Ray_t &ray, int flagMask )
 
</source>
 
</source>
  
 
+
== Examples ==
== Usage ==
 
  
 
<source lang=cpp>
 
<source lang=cpp>
int nCount = UTIL_EntitiesAlongRay( list, 1024, ray, FL_NPC | FL_CLIENT );
+
int nCount = UTIL_EntitiesAlongRay( list, 1024, ray, FL_NPC | FL_CLIENT );
for ( int i = 0; i < nCount; i++ )
+
for ( int i = 0; i < nCount; i++ )
{
+
{
if ( !IsAttractiveTarget( list[i] ) )
+
if ( !IsAttractiveTarget( list[i] ) )
continue;
+
continue;
  
VectorSubtract( list[i]->WorldSpaceCenter(), vecStartPoint, vecDelta );
+
VectorSubtract( list[i]->WorldSpaceCenter(), vecStartPoint, vecDelta );
distance = VectorNormalize( vecDelta );
+
distance = VectorNormalize( vecDelta );
flDot = DotProduct( vecDelta, vecVelDir );
+
flDot = DotProduct( vecDelta, vecVelDir );
 
 
if ( flDot > flMaxDot )
+
if ( flDot > flMaxDot )
{
+
{
if ( distance < flBestDist )
+
if ( distance < flBestDist )
{
+
{
pBestTarget = list[i];
+
pBestTarget = list[i];
flBestDist = distance;
+
flBestDist = distance;
}
 
}
 
 
}
 
}
 
}
 
}
 +
}
 
</source>
 
</source>
 +
 +
[[Category:Programming]]
 +
[[Category:UTIL]]

Revision as of 18:49, 10 April 2011

Template:Wrongtitle This is a UTIL function that when supplied a Ray_t will return an integer indicating the number of entities encountered along the ray, then will enumerate and place them into an array.

You can either specify an array, and the size of the array, and a mask for which encountered entities will be included in the array, or you can simply supply a Ray_t and an pointer to an instance of the CFlaggedEntitiesEnum class.

Usage

int UTIL_EntitiesAlongRay( const Ray_t &ray, CFlaggedEntitiesEnum *pEnum )
int UTIL_EntitiesAlongRay( CBaseEntity **pList, int listMax, const Ray_t &ray, int flagMask )

Examples

int nCount = UTIL_EntitiesAlongRay( list, 1024, ray, FL_NPC | FL_CLIENT );
for ( int i = 0; i < nCount; i++ )
{
	if ( !IsAttractiveTarget( list[i] ) )
		continue;

	VectorSubtract( list[i]->WorldSpaceCenter(), vecStartPoint, vecDelta );
	distance = VectorNormalize( vecDelta );
	flDot = DotProduct( vecDelta, vecVelDir );
			
	if ( flDot > flMaxDot )
	{
		if ( distance < flBestDist )
		{
			pBestTarget = list[i];
			flBestDist = distance;
		}
	}
}