本文整理汇总了C++中IPhysicsObject类的典型用法代码示例。如果您正苦于以下问题:C++ IPhysicsObject类的具体用法?C++ IPhysicsObject怎么用?C++ IPhysicsObject使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IPhysicsObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Pickup_PhysGunLaunchVelocity
Vector Pickup_PhysGunLaunchVelocity( CBaseEntity *pObject, const Vector &vecForward, PhysGunForce_t reason )
{
// The object must be valid
if ( pObject == NULL )
{
Assert( 0 );
return vec3_origin;
}
// Shouldn't ever get here with a non-vphysics object.
IPhysicsObject *pPhysicsObject = pObject->VPhysicsGetObject();
if ( pPhysicsObject == NULL )
{
Assert( 0 );
return vec3_origin;
}
// Call the pickup entity's callback
IPlayerPickupVPhysics *pPickup = dynamic_cast<IPlayerPickupVPhysics *>(pObject);
if ( pPickup != NULL && pPickup->ShouldPuntUseLaunchForces( reason ) )
return pPickup->PhysGunLaunchVelocity( vecForward, pPhysicsObject->GetMass() );
// Do our default behavior
return Pickup_DefaultPhysGunLaunchVelocity( vecForward, pPhysicsObject->GetMass() );
}
示例2: ConsumeEntity
//-----------------------------------------------------------------------------
// Purpose: Adds the entity's mass to the aggregate mass consumed
//-----------------------------------------------------------------------------
void CGravityVortexController::ConsumeEntity( CBaseEntity *pEnt )
{
// Get our base physics object
IPhysicsObject *pPhysObject = pEnt->VPhysicsGetObject();
if ( pPhysObject == NULL )
return;
// Ragdolls need to report the sum of all their parts
CRagdollProp *pRagdoll = dynamic_cast< CRagdollProp* >( pEnt );
if ( pRagdoll != NULL )
{
// Find the aggregate mass of the whole ragdoll
ragdoll_t *pRagdollPhys = pRagdoll->GetRagdoll();
for ( int j = 0; j < pRagdollPhys->listCount; ++j )
{
m_flMass += pRagdollPhys->list[j].pObject->GetMass();
}
}
else
{
// Otherwise we just take the normal mass
m_flMass += pPhysObject->GetMass();
}
// Destroy the entity
UTIL_Remove( pEnt );
}
示例3: VPhysicsGetObject
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
int CPhysBox::OnTakeDamage( const CTakeDamageInfo &info )
{
// note: if motion is disabled, OnTakeDamage can't apply physics force
int ret = BaseClass::OnTakeDamage( info );
// Check our health against the threshold:
if( m_damageToEnableMotion > 0 && GetHealth() < m_damageToEnableMotion )
{
// only do this once
m_damageToEnableMotion = 0;
IPhysicsObject *pPhysicsObject = VPhysicsGetObject();
if ( pPhysicsObject != NULL )
{
pPhysicsObject->Wake();
pPhysicsObject->EnableMotion( true );
VPhysicsTakeDamage( info );
}
}
if ( info.GetInflictor() )
{
m_OnDamaged.FireOutput( info.GetAttacker(), this );
}
return ret;
}
示例4: FindPhysicsObject
void CPhysicsSpring::GetSpringObjectConnections( string_t nameStart, string_t nameEnd, IPhysicsObject **pStart, IPhysicsObject **pEnd )
{
IPhysicsObject *pStartObject = FindPhysicsObject( STRING(nameStart) );
IPhysicsObject *pEndObject = FindPhysicsObject( STRING(nameEnd) );
// Assume the world for missing objects
if ( !pStartObject )
{
pStartObject = g_PhysWorldObject;
}
else if ( !pEndObject )
{
// try to sort so that the world is always the start object
pEndObject = pStartObject;
pStartObject = g_PhysWorldObject;
}
else
{
CBaseEntity *pEntity0 = (CBaseEntity *) (pStartObject->GetGameData());
g_pNotify->AddEntity( this, pEntity0 );
CBaseEntity *pEntity1 = (CBaseEntity *) pEndObject->GetGameData();
g_pNotify->AddEntity( this, pEntity1 );
}
*pStart = pStartObject;
*pEnd = pEndObject;
}
示例5: VPhysicsGetObject
void C_HL2MPRagdoll::ImpactTrace( trace_t *pTrace, int iDamageType, const char *pCustomImpactName )
{
IPhysicsObject *pPhysicsObject = VPhysicsGetObject();
if( !pPhysicsObject )
return;
Vector dir = pTrace->endpos - pTrace->startpos;
if ( iDamageType == DMG_BLAST )
{
dir *= 4000; // adjust impact strenght
// apply force at object mass center
pPhysicsObject->ApplyForceCenter( dir );
}
else
{
Vector hitpos;
VectorMA( pTrace->startpos, pTrace->fraction, dir, hitpos );
VectorNormalize( dir );
dir *= 4000; // adjust impact strenght
// apply force where we hit it
pPhysicsObject->ApplyForceOffset( dir, hitpos );
// Blood spray!
// FX_CS_BloodSpray( hitpos, dir, 10 );
}
m_pRagdoll->ResetRagdollSleepAfterTime();
}
示例6: SetMoveType
// as CItem, but we don't install the touch function
void CASW_Pickup::Spawn( void )
{
SetMoveType( MOVETYPE_FLYGRAVITY );
SetSolid( SOLID_BBOX );
SetBlocksLOS( false );
AddEFlags( EFL_NO_ROTORWASH_PUSH );
// This will make them not collide with the player, but will collide
// against other items + weapons
SetCollisionGroup( COLLISION_GROUP_WEAPON );
CollisionProp()->UseTriggerBounds( true, ITEM_PICKUP_BOX_BLOAT );
//SetTouch(&CItem::ItemTouch);
if ( CreateItemVPhysicsObject() == false )
return;
m_takedamage = DAMAGE_EVENTS_ONLY;
#ifdef HL2MP
SetThink( &CItem::FallThink );
SetNextThink( gpGlobals->curtime + 0.1f );
#endif
if ( m_bFreezePickup )
{
IPhysicsObject *pPhysicsObject = VPhysicsGetObject();
if ( pPhysicsObject != NULL )
{
pPhysicsObject->EnableMotion( false );
}
}
}
示例7: VectorSubtract
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 );
}
}
}
示例8: TakeDamage
//-----------------------------------------------------------------------------
// Purpose:
// Input :
// Output :
//-----------------------------------------------------------------------------
int CTDP_NPC_CombineS::TakeDamage( const CTakeDamageInfo &info )
{
if( info.GetInflictor() && info.GetInflictor()->VPhysicsGetObject() )
{
// Hit by a physics object! Was I blocking?
if( m_fIsBlocking )
{
IPhysicsObject *pPhysObject;
pPhysObject = info.GetInflictor()->VPhysicsGetObject();
if( pPhysObject )
{
// Only deflect objects of relatively low mass
//DevMsg( "MASS: %f\n", pPhysObject->GetMass() );
if( pPhysObject->GetMass() <= 30.0 )
{
// No damage from light objects (tuned for melons)
return 0;
}
}
}
}
BaseClass::TakeDamage( info );
return 0;
}
示例9: GetMoveProbe
//-----------------------------------------------------------------------------
// Step iteratively toward a destination position
//-----------------------------------------------------------------------------
AIMotorMoveResult_t CAI_Motor::MoveGroundStep( const Vector &newPos, CBaseEntity *pMoveTarget, float yaw, bool bAsFarAsCan, AIMoveTrace_t *pTraceResult )
{
// By definition, this will produce different results than GroundMoveLimit()
// because there's no guarantee that it will step exactly one step
// See how far toward the new position we can step...
// But don't actually test for ground geometric validity;
// if it isn't valid, there's not much we can do about it
AIMoveTrace_t moveTrace;
GetMoveProbe()->TestGroundMove( GetLocalOrigin(), newPos, MASK_NPCSOLID, AITGM_IGNORE_FLOOR, &moveTrace );
if ( pTraceResult )
{
*pTraceResult = moveTrace;
}
bool bHitTarget = (moveTrace.pObstruction && (pMoveTarget == moveTrace.pObstruction ));
// Move forward either if there was no obstruction or if we're told to
// move as far as we can, regardless
bool bIsBlocked = IsMoveBlocked(moveTrace.fStatus);
if ( !bIsBlocked || bAsFarAsCan || bHitTarget )
{
// The true argument here causes it to touch all triggers
// in the volume swept from the previous position to the current position
UTIL_SetOrigin(GetOuter(), moveTrace.vEndPosition, true);
// skip tiny steps, but notify the shadow object of any large steps
if ( moveTrace.flStepUpDistance > 0.1f )
{
float height = clamp( moveTrace.flStepUpDistance, 0, StepHeight() );
IPhysicsObject *pPhysicsObject = GetOuter()->VPhysicsGetObject();
if ( pPhysicsObject )
{
IPhysicsShadowController *pShadow = pPhysicsObject->GetShadowController();
if ( pShadow )
{
pShadow->StepUp( height );
}
}
}
if ( yaw != -1 )
{
QAngle angles = GetLocalAngles();
angles.y = yaw;
SetLocalAngles( angles );
}
if ( bHitTarget )
return AIM_PARTIAL_HIT_TARGET;
if ( !bIsBlocked )
return AIM_SUCCESS;
if ( moveTrace.fStatus == AIMR_BLOCKED_NPC )
return AIM_PARTIAL_HIT_NPC;
return AIM_PARTIAL_HIT_WORLD;
}
return AIM_FAILED;
}
示例10: CheckWater
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool CPropJeep::CheckWater( void )
{
bool bInWater = false;
// Check all four wheels.
for ( int iWheel = 0; iWheel < JEEP_WHEEL_COUNT; ++iWheel )
{
// Get the current wheel and get its contact point.
IPhysicsObject *pWheel = m_VehiclePhysics.GetWheel( iWheel );
if ( !pWheel )
continue;
// Check to see if we hit water.
if ( pWheel->GetContactPoint( &m_WaterData.m_vecWheelContactPoints[iWheel], NULL ) )
{
m_WaterData.m_bWheelInWater[iWheel] = ( UTIL_PointContents( m_WaterData.m_vecWheelContactPoints[iWheel] ) & MASK_WATER ) ? true : false;
if ( m_WaterData.m_bWheelInWater[iWheel] )
{
bInWater = true;
}
}
}
// Check the body and the BONNET.
int iEngine = LookupAttachment( "vehicle_engine" );
Vector vecEnginePoint;
QAngle vecEngineAngles;
GetAttachment( iEngine, vecEnginePoint, vecEngineAngles );
m_WaterData.m_bBodyInWater = ( UTIL_PointContents( vecEnginePoint ) & MASK_WATER ) ? true : false;
if ( m_WaterData.m_bBodyInWater )
{
if ( m_bHasPoop )
{
RemoveAllDecals();
m_bHasPoop = false;
}
if ( !m_VehiclePhysics.IsEngineDisabled() )
{
m_VehiclePhysics.SetDisableEngine( true );
}
}
else
{
if ( m_VehiclePhysics.IsEngineDisabled() )
{
m_VehiclePhysics.SetDisableEngine( false );
}
}
if ( bInWater )
{
// Check the player's water level.
CheckWaterLevel();
}
return bInWater;
}
示例11: VPhysicsGetObject
//-----------------------------------------------------------------------------
// Purpose: Input handler for waking up the cannister if it is sleeping.
//-----------------------------------------------------------------------------
void CPhysicsCannister::InputWake( inputdata_t &data )
{
IPhysicsObject *pPhys = VPhysicsGetObject();
if ( pPhys != NULL )
{
pPhys->Wake();
}
}
示例12: VPhysicsGetObject
void CTripwireHook::SetVelocity( const Vector &velocity, const AngularImpulse &angVelocity )
{
IPhysicsObject *pPhysicsObject = VPhysicsGetObject();
if ( pPhysicsObject )
{
pPhysicsObject->AddVelocity( &velocity, &angVelocity );
}
}
示例13: VPhysicsGetObject
void CGETKnife::SetVelocity( const Vector &velocity, const AngularImpulse &angVelocity )
{
IPhysicsObject *pPhysicsObject = VPhysicsGetObject();
if ( pPhysicsObject )
{
pPhysicsObject->SetVelocityInstantaneous( &velocity, &angVelocity );
}
}
示例14: VPhysicsGetObject
void CBaseGrenadeProjectile::SetVelocity( const Vector &velocity, const AngularImpulse &angVelocity )
{
IPhysicsObject *pPhysicsObject = VPhysicsGetObject();
if ( pPhysicsObject )
{
pPhysicsObject->AddVelocity( &velocity, &angVelocity );
}
}
示例15: GetModelPtr
void CRagdollPropAttached::InitRagdollAttached( IPhysicsObject *pAttached, const Vector &forceVector, int forceBone, matrix3x4_t *pPrevBones, matrix3x4_t *pBoneToWorld, float dt, int collisionGroup, CBaseAnimating *pFollow, int boneIndexRoot, const Vector &boneLocalOrigin, int parentBoneAttach, const Vector &worldAttachOrigin )
{
int ragdollAttachedIndex = 0;
if ( parentBoneAttach > 0 )
{
studiohdr_t *pStudioHdr = GetModelPtr();
mstudiobone_t *pBone = pStudioHdr->pBone( parentBoneAttach );
ragdollAttachedIndex = pBone->physicsbone;
}
InitRagdoll( forceVector, forceBone, vec3_origin, pPrevBones, pBoneToWorld, dt, collisionGroup, false );
IPhysicsObject *pRefObject = m_ragdoll.list[ragdollAttachedIndex].pObject;
Vector attachmentPointRagdollSpace;
pRefObject->WorldToLocal( attachmentPointRagdollSpace, worldAttachOrigin );
constraint_ragdollparams_t constraint;
constraint.Defaults();
matrix3x4_t tmp, worldToAttached, worldToReference, constraintToWorld;
Vector offsetWS;
pAttached->LocalToWorld( offsetWS, boneLocalOrigin );
AngleMatrix( QAngle(0, pFollow->GetAbsAngles().y, 0 ), offsetWS, constraintToWorld );
constraint.axes[0].SetAxisFriction( -2, 2, 20 );
constraint.axes[1].SetAxisFriction( 0, 0, 0 );
constraint.axes[2].SetAxisFriction( -15, 15, 20 );
pAttached->GetPositionMatrix( tmp );
MatrixInvert( tmp, worldToAttached );
pRefObject->GetPositionMatrix( tmp );
MatrixInvert( tmp, worldToReference );
ConcatTransforms( worldToReference, constraintToWorld, constraint.constraintToReference );
ConcatTransforms( worldToAttached, constraintToWorld, constraint.constraintToAttached );
// for now, just slam this to be the passed in value
MatrixSetColumn( attachmentPointRagdollSpace, 3, constraint.constraintToReference );
DisableCollisions( pAttached );
m_pAttachConstraint = physenv->CreateRagdollConstraint( pRefObject, pAttached, m_ragdoll.pGroup, constraint );
FollowEntity( pFollow );
SetOwnerEntity( pFollow );
RagdollActivate( m_ragdoll );
Relink();
m_boneIndexAttached = boneIndexRoot;
m_ragdollAttachedObjectIndex = ragdollAttachedIndex;
m_attachmentPointBoneSpace = boneLocalOrigin;
Vector vTemp;
MatrixGetColumn( constraint.constraintToReference, 3, vTemp );
m_attachmentPointRagdollSpace = vTemp;
}