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