本文整理汇总了C++中CGlobalEntityList::FindEntityByClassname方法的典型用法代码示例。如果您正苦于以下问题:C++ CGlobalEntityList::FindEntityByClassname方法的具体用法?C++ CGlobalEntityList::FindEntityByClassname怎么用?C++ CGlobalEntityList::FindEntityByClassname使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CGlobalEntityList
的用法示例。
在下文中一共展示了CGlobalEntityList::FindEntityByClassname方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
//-----------------------------------------------------------------------------
// Purpose: Finds the first entity within radius distance by class name.
// Input : pStartEntity - The entity to start from when doing the search.
// szName - Entity class name, ie "info_target".
// vecSrc - Center of search radius.
// flRadius - Search radius for classname search, 0 to search everywhere.
// Output : Returns a pointer to the found entity, NULL if none.
//-----------------------------------------------------------------------------
CBaseEntity *CGlobalEntityList::FindEntityByClassnameWithin( CBaseEntity *pStartEntity, const char *szName, const Vector &vecSrc, float flRadius )
{
//
// Check for matching class names within the search radius.
//
CBaseEntity *pEntity = pStartEntity;
float flMaxDist2 = flRadius * flRadius;
if (flMaxDist2 == 0)
{
return gEntList.FindEntityByClassname( pEntity, szName );
}
while ((pEntity = gEntList.FindEntityByClassname( pEntity, szName )) != NULL)
{
if ( !pEntity->edict() )
continue;
float flDist2 = (pEntity->GetAbsOrigin() - vecSrc).LengthSqr();
if (flMaxDist2 > flDist2)
{
return pEntity;
}
}
return NULL;
}
示例2:
//-----------------------------------------------------------------------------
// Purpose: Finds the first entity within radius distance by class name.
// Input : pStartEntity - The entity to start from when doing the search.
// szName - Entity class name, ie "info_target".
// vecSrc - Center of search radius.
// flRadius - Search radius for classname search, 0 to search everywhere.
// Output : Returns a pointer to the found entity, NULL if none.
//-----------------------------------------------------------------------------
CBaseEntity *CGlobalEntityList::FindEntityByClassnameWithin( CBaseEntity *pStartEntity, const char *szName, const Vector &vecSrc, float flRadius, int brushPrecision )
{
//
// Check for matching class names within the search radius.
//
CBaseEntity *pEntity = pStartEntity;
float flMaxDist2 = flRadius * flRadius;
if (flMaxDist2 == 0)
{
return gEntList.FindEntityByClassname( pEntity, szName );
}
while ((pEntity = gEntList.FindEntityByClassname( pEntity, szName )) != NULL)
{
if ( !pEntity->edict() )
continue;
Vector origin;
if ( pEntity->IsBSPModel() && pEntity->CollisionProp())
{
if ( brushPrecision == BRUSHPRECISION_NEAREST )
pEntity->CollisionProp()->CalcNearestPoint(vecSrc,&origin);
else
origin = pEntity->CollisionProp()->GetCollisionOrigin();
}
else
origin = pEntity->GetAbsOrigin();
float flDist2 = (origin - vecSrc).LengthSqr();
if (flMaxDist2 > flDist2)
{
return pEntity;
}
}
return NULL;
}