本文整理汇总了C++中CEntity::VPhysicsGetObject方法的典型用法代码示例。如果您正苦于以下问题:C++ CEntity::VPhysicsGetObject方法的具体用法?C++ CEntity::VPhysicsGetObject怎么用?C++ CEntity::VPhysicsGetObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CEntity
的用法示例。
在下文中一共展示了CEntity::VPhysicsGetObject方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TestForCollisionsAgainstWorld
void CEnvHeadcrabCanister::TestForCollisionsAgainstWorld( const Vector &vecEndPosition )
{
// Splash damage!
// Iterate on all entities in the vicinity.
float flDamageRadius = m_flDamageRadius;
float flDamage = m_flDamage;
CEntity *pEntity;
for ( CEntitySphereQuery sphere( vecEndPosition, flDamageRadius ); ( pEntity = sphere.GetCurrentEntity() ) != NULL; sphere.NextEntity() )
{
if ( pEntity == this )
continue;
if ( !pEntity->IsSolid() )
continue;
// Get distance to object and use it as a scale value.
Vector vecSegment;
VectorSubtract( pEntity->GetAbsOrigin(), vecEndPosition, vecSegment );
float flDistance = VectorNormalize( vecSegment );
float flFactor = 1.0f / ( flDamageRadius * (INNER_RADIUS_FRACTION - 1) );
flFactor *= flFactor;
float flScale = flDistance - flDamageRadius;
flScale *= flScale * flFactor;
if ( flScale > 1.0f )
{
flScale = 1.0f;
}
// Check for a physics object and apply force!
Vector vecForceDir = vecSegment;
IPhysicsObject *pPhysObject = pEntity->VPhysicsGetObject();
if ( pPhysObject )
{
// Send it flying!!!
float flMass = PhysGetEntityMass( pEntity );
vecForceDir *= flMass * 750 * flScale;
pPhysObject->ApplyForceCenter( vecForceDir );
}
if ( pEntity->m_takedamage && ( m_flDamage != 0.0f ) )
{
CTakeDamageInfo info( BaseEntity(), BaseEntity(), flDamage * flScale, DMG_BLAST );
CalculateExplosiveDamageForce( &info, vecSegment, pEntity->GetAbsOrigin() );
pEntity->TakeDamage( info );
}
if ( pEntity->IsPlayer() && !(static_cast<CPlayer*>(pEntity)->IsInAVehicle()) )
{
if (vecSegment.z < 0.1f)
{
vecSegment.z = 0.1f;
VectorNormalize( vecSegment );
}
float flAmount = SimpleSplineRemapVal( flScale, 0.0f, 1.0f, 250.0f, 1000.0f );
pEntity->ApplyAbsVelocityImpulse( vecSegment * flAmount );
}
}
}
示例2: TestForCollisionsAgainstEntities
//-----------------------------------------------------------------------------
// Test for impact!
//-----------------------------------------------------------------------------
void CEnvHeadcrabCanister::TestForCollisionsAgainstEntities( const Vector &vecEndPosition )
{
// Debugging!!
// NDebugOverlay::Box( GetAbsOrigin(), m_vecMin * 0.5f, m_vecMax * 0.5f, 255, 255, 0, 0, 5 );
// NDebugOverlay::Box( vecEndPosition, m_vecMin, m_vecMax, 255, 0, 0, 0, 5 );
float flRadius = CollisionProp()->BoundingRadius();
Vector vecMins( -flRadius, -flRadius, -flRadius );
Vector vecMaxs( flRadius, flRadius, flRadius );
Ray_t ray;
ray.Init( GetAbsOrigin(), vecEndPosition, vecMins, vecMaxs );
CCollideList collideList( &ray, BaseEntity(), MASK_SOLID );
enginetrace->EnumerateEntities( ray, false, &collideList );
float flDamage = m_flDamage;
// Now get each entity and react accordinly!
for( int iEntity = collideList.m_Entities.Count(); --iEntity >= 0; )
{
CEntity *pEntity = collideList.m_Entities[iEntity];
Vector vecForceDir = m_Shared.m_vecDirection;
// Check for a physics object and apply force!
IPhysicsObject *pPhysObject = pEntity->VPhysicsGetObject();
if ( pPhysObject )
{
float flMass = PhysGetEntityMass( pEntity );
vecForceDir *= flMass * 750;
pPhysObject->ApplyForceCenter( vecForceDir );
}
if ( pEntity->m_takedamage && ( m_flDamage != 0.0f ) )
{
CTakeDamageInfo info( BaseEntity(), BaseEntity(), flDamage, DMG_BLAST );
CalculateExplosiveDamageForce( &info, vecForceDir, pEntity->GetAbsOrigin() );
pEntity->TakeDamage( info );
}
}
}