本文整理汇总了C++中IPhysicsObject::AddVelocity方法的典型用法代码示例。如果您正苦于以下问题:C++ IPhysicsObject::AddVelocity方法的具体用法?C++ IPhysicsObject::AddVelocity怎么用?C++ IPhysicsObject::AddVelocity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IPhysicsObject
的用法示例。
在下文中一共展示了IPhysicsObject::AddVelocity方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SetVelocity
void CBaseGrenadeProjectile::SetVelocity( const Vector &velocity, const AngularImpulse &angVelocity )
{
IPhysicsObject *pPhysicsObject = VPhysicsGetObject();
if ( pPhysicsObject )
{
pPhysicsObject->AddVelocity( &velocity, &angVelocity );
}
}
示例2: SetVelocity
void CTripwireHook::SetVelocity( const Vector &velocity, const AngularImpulse &angVelocity )
{
IPhysicsObject *pPhysicsObject = VPhysicsGetObject();
if ( pPhysicsObject )
{
pPhysicsObject->AddVelocity( &velocity, &angVelocity );
}
}
示例3: Drop
//DHL - Skillet - Fix ammo exploits
void CWeaponFrag::Drop( const Vector &vecVelocity )
{
if ( !HasPrimaryAmmo() )
{
//BaseClass::Drop( vecVelocity );
SUB_Remove();
return;
}
if ( !GetOwner() )
return;
DecrementAmmo( GetOwner() );
Reload(); //Do draw animation and stuff
#ifndef CLIENT_DLL
CBasePlayer *owner = ToBasePlayer(GetOwner());
Vector vThrowPos = owner->Weapon_ShootPosition() - Vector(0,0,12);
//Create a grenade
CBaseCombatWeapon* pGrenade;
pGrenade = (CBaseCombatWeapon *)CBaseEntity::Create( "weapon_frag", vThrowPos, vec3_angle, NULL );
if ( !pGrenade )
return;
pGrenade->SetRemoveable( true );
//If it was dropped then there's no need to respawn it.
pGrenade->AddSpawnFlags( SF_NORESPAWN );
pGrenade->StopAnimation();
pGrenade->StopFollowingEntity( );
pGrenade->SetMoveType( MOVETYPE_FLYGRAVITY );
// clear follow stuff, setup for collision
pGrenade->SetGravity(1.0);
pGrenade->m_iState = WEAPON_NOT_CARRIED;
pGrenade->RemoveEffects( EF_NODRAW );
pGrenade->FallInit();
pGrenade->SetGroundEntity( NULL );
pGrenade->SetTouch(NULL);
pGrenade->SetOwnerEntity( NULL );
pGrenade->SetOwner( NULL );
//Toss it in the direction of the player's view
Vector vecNewVelocity;
Vector vecDir;
owner->EyeVectors( &vecDir );
vecNewVelocity = ( vecDir * 500.0f );
IPhysicsObject *pObj = pGrenade->VPhysicsGetObject();
if ( pObj != NULL )
{
AngularImpulse angImp( 200, 200, 200 );
pObj->AddVelocity( &vecNewVelocity, &angImp );
}
#endif
}
示例4: SetVelocity
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CGrenadeHopwire::SetVelocity( const Vector &velocity, const AngularImpulse &angVelocity )
{
IPhysicsObject *pPhysicsObject = VPhysicsGetObject();
if ( pPhysicsObject != NULL )
{
pPhysicsObject->AddVelocity( &velocity, &angVelocity );
}
}
示例5: InitGib
//------------------------------------------------------------------------------
// Purpose : Initialize a gibs position and velocity
// Input :
// Output :
//------------------------------------------------------------------------------
void CGib::InitGib( CBaseEntity *pVictim, float fMinVelocity, float fMaxVelocity )
{
// ------------------------------------------------------------------------
// If have a pVictim spawn the gib somewhere in the pVictim's bounding volume
// ------------------------------------------------------------------------
if ( pVictim )
{
// Find a random position within the bounding box (add 1 to Z to get it out of the ground)
Vector vecOrigin;
pVictim->CollisionProp()->RandomPointInBounds( vec3_origin, Vector( 1, 1, 1 ), &vecOrigin );
vecOrigin.z += 1.0f;
SetAbsOrigin( vecOrigin );
// make the gib fly away from the attack vector
Vector vecNewVelocity = g_vecAttackDir * -1;
// mix in some noise
vecNewVelocity.x += random->RandomFloat ( -0.25, 0.25 );
vecNewVelocity.y += random->RandomFloat ( -0.25, 0.25 );
vecNewVelocity.z += random->RandomFloat ( -0.25, 0.25 );
vecNewVelocity *= random->RandomFloat ( fMaxVelocity, fMinVelocity );
QAngle vecNewAngularVelocity = GetLocalAngularVelocity();
vecNewAngularVelocity.x = random->RandomFloat ( 100, 200 );
vecNewAngularVelocity.y = random->RandomFloat ( 100, 300 );
SetLocalAngularVelocity( vecNewAngularVelocity );
// copy owner's blood color
SetBloodColor( pVictim->BloodColor() );
AdjustVelocityBasedOnHealth( pVictim->m_iHealth, vecNewVelocity );
// Attempt to be physical if we can
if ( VPhysicsInitNormal( SOLID_BBOX, 0, false ) )
{
IPhysicsObject *pObj = VPhysicsGetObject();
if ( pObj != NULL )
{
AngularImpulse angImpulse = RandomAngularImpulse( -500, 500 );
pObj->AddVelocity( &vecNewVelocity, &angImpulse );
}
}
else
{
SetSolid( SOLID_BBOX );
SetCollisionBounds( vec3_origin, vec3_origin );
SetAbsVelocity( vecNewVelocity );
}
SetCollisionGroup( COLLISION_GROUP_DEBRIS );
}
LimitVelocity();
}
示例6: Clone
void C_PhysPropClientside::Clone( Vector &velocity )
{
C_PhysPropClientside *pEntity = C_PhysPropClientside::CreateNew();
if ( !pEntity )
return;
pEntity->m_spawnflags = m_spawnflags;
// We never want to be motion disabled
pEntity->m_spawnflags &= ~SF_PHYSPROP_MOTIONDISABLED;
pEntity->SetDmgModBullet( GetDmgModBullet() );
pEntity->SetDmgModClub( GetDmgModClub() );
pEntity->SetDmgModExplosive( GetDmgModExplosive() );
pEntity->SetModelName( GetModelName() );
pEntity->SetLocalOrigin( GetLocalOrigin() );
pEntity->SetLocalAngles( GetLocalAngles() );
pEntity->SetOwnerEntity( this );
pEntity->SetPhysicsMode( PHYSICS_MULTIPLAYER_CLIENTSIDE );
if ( !pEntity->Initialize() )
{
pEntity->Release();
return;
}
pEntity->m_nSkin = m_nSkin;
pEntity->m_iHealth = m_iHealth;
if ( pEntity->m_iHealth == 0 )
{
// if no health, don't collide with player anymore, don't take damage
pEntity->m_takedamage = DAMAGE_NO;
pEntity->SetCollisionGroup( COLLISION_GROUP_NONE );
}
IPhysicsObject *pPhysicsObject = pEntity->VPhysicsGetObject();
if( pPhysicsObject )
{
// randomize velocity by 5%
float rndf = RandomFloat( -0.025, 0.025 );
Vector rndVel = velocity + rndf*velocity;
pPhysicsObject->AddVelocity( &rndVel, NULL );
}
else
{
// failed to create a physics object
pEntity->Release();
}
}
示例7: CreateCorpse
//-----------------------------------------------------------------------------
// Create a corpse
//-----------------------------------------------------------------------------
void CPropAPC::CreateCorpse( )
{
m_lifeState = LIFE_DEAD;
for ( int i = 0; i < APC_MAX_GIBS; ++i )
{
CPhysicsProp *pGib = assert_cast<CPhysicsProp*>(CreateEntityByName( "prop_physics" ));
pGib->SetAbsOrigin( GetAbsOrigin() );
pGib->SetAbsAngles( GetAbsAngles() );
pGib->SetAbsVelocity( GetAbsVelocity() );
pGib->SetModel( s_pGibModelName[i] );
pGib->Spawn();
pGib->SetMoveType( MOVETYPE_VPHYSICS );
float flMass = pGib->GetMass();
if ( flMass < 200 )
{
Vector vecVelocity;
pGib->GetMassCenter( &vecVelocity );
vecVelocity -= WorldSpaceCenter();
vecVelocity.z = fabs(vecVelocity.z);
VectorNormalize( vecVelocity );
// Apply a force that would make a 100kg mass travel 150 - 300 m/s
float flRandomVel = random->RandomFloat( 150, 300 );
vecVelocity *= (100 * flRandomVel) / flMass;
vecVelocity.z += 100.0f;
AngularImpulse angImpulse = RandomAngularImpulse( -500, 500 );
IPhysicsObject *pObj = pGib->VPhysicsGetObject();
if ( pObj != NULL )
{
pObj->AddVelocity( &vecVelocity, &angImpulse );
}
pGib->SetCollisionGroup( COLLISION_GROUP_DEBRIS );
}
if( hl2_episodic.GetBool() )
{
// EP1 perf hit
pGib->Ignite( 6, false );
}
else
{
pGib->Ignite( 60, false );
}
}
AddSolidFlags( FSOLID_NOT_SOLID );
AddEffects( EF_NODRAW );
UTIL_Remove( this );
}
示例8: CreateCorpse
void QUA_helicopter::CreateCorpse( )
{
m_lifeState = LIFE_DEAD;
for ( int i = 0; i < HELICOPTER_MAX_GIBS; ++i )
{
CPhysicsProp *pGib = assert_cast<CPhysicsProp*>(CreateEntityByName( "prop_physics_multiplayer" ));
pGib->SetAbsOrigin( GetAbsOrigin() );
pGib->SetAbsAngles( GetAbsAngles() );
pGib->SetAbsVelocity( GetAbsVelocity() );
pGib->SetModel( s_pGibModelName[i] );
pGib->Spawn();
pGib->SetMoveType( MOVETYPE_VPHYSICS );
float flMass = pGib->GetMass();
/*if ( flMass < 200 )
{*/
Vector vecVelocity;
pGib->GetMassCenter( &vecVelocity );
vecVelocity -= WorldSpaceCenter();
vecVelocity.z = fabs(vecVelocity.z);
VectorNormalize( vecVelocity );
// Apply a force that would make a 100kg mass travel 150 - 300 m/s
float flRandomVel = random->RandomFloat( 150, 300 );
vecVelocity *= (100 * flRandomVel) / flMass;
vecVelocity.z += 100.0f;
AngularImpulse angImpulse = RandomAngularImpulse( -500, 500 );
IPhysicsObject *pObj = pGib->VPhysicsGetObject();
if ( pObj != NULL )
{
pObj->AddVelocity( &vecVelocity, &angImpulse );
}
pGib->SetCollisionGroup( COLLISION_GROUP_DEBRIS );
/*}*/
pGib->Ignite( 60, false );
pGib->Dissolve( NULL, gpGlobals->curtime, false, ENTITY_DISSOLVE_NORMAL );
}
AddSolidFlags( FSOLID_NOT_SOLID );
AddEffects( EF_NODRAW );
UTIL_RemoveImmediate( this );
}
示例9: DoMagnetSuck
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CPhysMagnet::DoMagnetSuck( CBaseEntity *pOther )
{
if ( !HasSpawnFlags( SF_MAGNET_SUCK ) )
return;
if ( !m_bActive )
return;
// Don't repeatedly suck
if ( m_flNextSuckTime > gpGlobals->curtime )
return;
// Look for physics objects underneath the magnet and suck them onto it
Vector vecCheckPos, vecSuckPoint;
VectorTransform( Vector(0,0,-96), EntityToWorldTransform(), vecCheckPos );
VectorTransform( Vector(0,0,-64), EntityToWorldTransform(), vecSuckPoint );
CBaseEntity *pEntities[20];
int iNumEntities = UTIL_EntitiesInSphere( pEntities, 20, vecCheckPos, 80.0, 0 );
for ( int i = 0; i < iNumEntities; i++ )
{
CBaseEntity *pEntity = pEntities[i];
if ( !pEntity || pEntity == pOther )
continue;
IPhysicsObject *pPhys = pEntity->VPhysicsGetObject();
if ( pPhys && pEntity->GetMoveType() == MOVETYPE_VPHYSICS && pPhys->GetMass() < 5000 )
{
// Do we have line of sight to it?
trace_t tr;
UTIL_TraceLine( GetAbsOrigin(), pEntity->GetAbsOrigin(), MASK_SHOT, this, 0, &tr );
if ( tr.fraction == 1.0 || tr.m_pEnt == pEntity )
{
// Pull it towards the magnet
Vector vecVelocity = (vecSuckPoint - pEntity->GetAbsOrigin());
VectorNormalize(vecVelocity);
vecVelocity *= 5 * pPhys->GetMass();
pPhys->AddVelocity( &vecVelocity, NULL );
}
}
}
m_flNextSuckTime = gpGlobals->curtime + 2.0;
}
示例10: OnDataChanged
void C_StriderRagdoll::OnDataChanged( DataUpdateType_t type )
{
BaseClass::OnDataChanged( type );
if ( type == DATA_UPDATE_CREATED )
{
CreateStriderRagdoll();
IPhysicsObject *pPhysicsObject = VPhysicsGetObject();
if( pPhysicsObject )
{
AngularImpulse aVelocity(0,0,0);
Vector vecExaggeratedVelocity = 3 * m_vecRagdollVelocity;
pPhysicsObject->AddVelocity( &vecExaggeratedVelocity, &aVelocity );
}
}
}
示例11: ThrowBrickbat
//-----------------------------------------------------------------------------
// Purpose:
//
//
//-----------------------------------------------------------------------------
void CWeaponBrickbat::ThrowBrickbat( Vector vecSrc, Vector vecVelocity, float damage)
{
CGrenade_Brickbat *pBrickbat = (CGrenade_Brickbat*)Create( BrickBatAmmoArray[m_iCurrentAmmoType].m_sClassName, vecSrc, vec3_angle, GetOwner() );
if (!pBrickbat)
{
Msg("Brickbat type (%s) not defined!\n",BrickBatAmmoArray[m_iCurrentAmmoType].m_sClassName);
return;
}
AngularImpulse vecAngVel;
// Tumble through the air
vecAngVel.x = random->RandomFloat ( -100, -500 );
vecAngVel.z = random->RandomFloat ( -100, -500 );
vecAngVel.y = random->RandomFloat ( -100, -500 );
// If physically simulated
IPhysicsObject *pPhysicsObject = pBrickbat->VPhysicsGetObject();
if ( pPhysicsObject )
{
pPhysicsObject->AddVelocity( &vecVelocity, &vecAngVel );
}
// Otherwise
else
{
pBrickbat->SetAbsVelocity( vecVelocity );
QAngle angVel;
AngularImpulseToQAngle( vecAngVel, angVel );
pBrickbat->SetLocalAngularVelocity( angVel );
}
pBrickbat->SetThrower( GetOwner() );
pBrickbat->SetOwnerEntity( ((CBaseEntity*)GetOwner()) );
pBrickbat->SetDamage(damage);
m_nAmmoCount[m_iCurrentAmmoType]--;
m_bNeedThrow = false;
}
示例12: OnPhysGunPickup
void CItem_ItemCrate::OnPhysGunPickup( CBasePlayer *pPhysGunUser, PhysGunPickup_t reason )
{
BaseClass::OnPhysGunPickup( pPhysGunUser, reason );
m_OnCacheInteraction.FireOutput( pPhysGunUser, this );
if ( reason == PUNTED_BY_CANNON && m_CrateAppearance != CRATE_APPEARANCE_RADAR_BEACON )
{
Vector vForward;
AngleVectors( pPhysGunUser->EyeAngles(), &vForward, NULL, NULL );
Vector vForce = Pickup_PhysGunLaunchVelocity( this, vForward, PHYSGUN_FORCE_PUNTED );
AngularImpulse angular = AngularImpulse( 0, 0, 0 );
IPhysicsObject *pPhysics = VPhysicsGetObject();
if ( pPhysics )
{
pPhysics->AddVelocity( &vForce, &angular );
}
TakeDamage( CTakeDamageInfo( pPhysGunUser, pPhysGunUser, GetHealth(), DMG_GENERIC ) );
}
}
示例13: InitGrenade
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFWeaponBaseGrenadeProj::InitGrenade( const Vector &velocity, const AngularImpulse &angVelocity,
CBaseCombatCharacter *pOwner, const CTFWeaponInfo &weaponInfo )
{
// We can't use OwnerEntity for grenades, because then the owner can't shoot them with his hitscan weapons (due to collide rules)
// Thrower is used to store the person who threw the grenade, for damage purposes.
SetOwnerEntity( NULL );
SetThrower( pOwner );
SetupInitialTransmittedGrenadeVelocity( velocity );
SetGravity( 0.4f/*BaseClass::GetGrenadeGravity()*/ );
SetFriction( 0.2f/*BaseClass::GetGrenadeFriction()*/ );
SetElasticity( 0.45f/*BaseClass::GetGrenadeElasticity()*/ );
SetDamage( weaponInfo.GetWeaponData( TF_WEAPON_PRIMARY_MODE ).m_nDamage );
SetDamageRadius( weaponInfo.m_flDamageRadius );
ChangeTeam( pOwner->GetTeamNumber() );
IPhysicsObject *pPhysicsObject = VPhysicsGetObject();
if ( pPhysicsObject )
{
pPhysicsObject->AddVelocity( &velocity, &angVelocity );
}
}
示例14: StartTouch
void CNPC_Portal_FloorTurret::StartTouch( CBaseEntity *pOther )
{
BaseClass::StartTouch( pOther );
IPhysicsObject *pOtherPhys = pOther->VPhysicsGetObject();
if ( !pOtherPhys )
return;
if ( !m_pMotionController )
return;
if ( m_pMotionController->Enabled() )
{
m_pMotionController->Suspend( 2.0f );
IPhysicsObject *pTurretPhys = VPhysicsGetObject();
if ( !pOther->IsPlayer() && pOther->GetMoveType() == MOVETYPE_VPHYSICS && !(pTurretPhys && ((pTurretPhys->GetGameFlags() & FVPHYSICS_PLAYER_HELD) != 0)) )
{
// Get a lateral impulse
Vector vVelocityImpulse = GetAbsOrigin() - pOther->GetAbsOrigin();
vVelocityImpulse.z = 0.0f;
if ( vVelocityImpulse.IsZero() )
{
vVelocityImpulse.x = 1.0f;
vVelocityImpulse.y = 1.0f;
}
VectorNormalize( vVelocityImpulse );
// If impulse is too much along the forward or back axis, skew it
Vector vTurretForward, vTurretRight;
GetVectors( &vTurretForward, &vTurretRight, NULL );
float fForwardDotImpulse = vTurretForward.Dot( vVelocityImpulse );
if ( fForwardDotImpulse > 0.7f || fForwardDotImpulse < -0.7f )
{
vVelocityImpulse += vTurretRight;
VectorNormalize( vVelocityImpulse );
}
Vector vAngleImpulse( ( vTurretRight.Dot( vVelocityImpulse ) < 0.0f ) ? ( -1.6f ) : ( 1.6f ), RandomFloat( -0.5f, 0.5f ), RandomFloat( -0.5f, 0.5f ) );
vVelocityImpulse *= TURRET_FLOOR_PHYSICAL_FORCE_MULTIPLIER;
vAngleImpulse *= TURRET_FLOOR_PHYSICAL_FORCE_MULTIPLIER;
pTurretPhys->AddVelocity( &vVelocityImpulse, &vAngleImpulse );
// Check if another turret is hitting us
CNPC_Portal_FloorTurret *pPortalFloor = dynamic_cast<CNPC_Portal_FloorTurret*>( pOther );
if ( pPortalFloor && pPortalFloor->m_lifeState == LIFE_ALIVE )
{
Vector vTurretVelocity, vOtherVelocity;
pTurretPhys->GetVelocity( &vTurretVelocity, NULL );
pOtherPhys->GetVelocity( &vOtherVelocity, NULL );
// If it's moving faster
if ( vOtherVelocity.LengthSqr() > vTurretVelocity.LengthSqr() )
{
// Make the turret falling onto this one talk
pPortalFloor->EmitSound( GetTurretTalkName( PORTAL_TURRET_COLLIDE ) );
pPortalFloor->m_fNextTalk = gpGlobals->curtime + 1.2f;
pPortalFloor->m_bDelayTippedTalk = true;
// Delay out potential tipped talking so we can here the other turret talk
m_fNextTalk = gpGlobals->curtime + 0.6f;
m_bDelayTippedTalk = true;
}
}
if ( pPortalFloor && m_bEnabled && m_bLaserOn && !m_bOutOfAmmo )
{
// Award friendly fire achievement if we're a live turret being knocked over by another turret.
IGameEvent *event = gameeventmanager->CreateEvent( "turret_hit_turret" );
if ( event )
{
gameeventmanager->FireEvent( event );
}
}
}
}
}
示例15: Event_Killed
//-----------------------------------------------------------------------------
// Purpose:
// Input : &info -
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
void CTDP_NPC_CombineS::Event_Killed( const CTakeDamageInfo &info )
{
// Don't bother if we've been told not to, or the player has a megaphyscannon
/* if ( combine_spawn_health.GetBool() == false || PlayerHasMegaPhysCannon() )
{
BaseClass::Event_Killed( info );
return;
}*/
CBasePlayer *pPlayer = ToBasePlayer( info.GetAttacker() );
if ( pPlayer != NULL )
{
// Elites drop alt-fire ammo, so long as they weren't killed by dissolving.
if( IsElite() )
{
CBaseEntity *pItem = DropItem( "item_ammo_ar2_altfire", WorldSpaceCenter()+RandomVector(-4,4), RandomAngle(0,360) );
if ( pItem )
{
IPhysicsObject *pObj = pItem->VPhysicsGetObject();
if ( pObj )
{
Vector vel = RandomVector( -64.0f, 64.0f );
AngularImpulse angImp = RandomAngularImpulse( -300.0f, 300.0f );
vel[2] = 0.0f;
pObj->AddVelocity( &vel, &angImp );
}
if( info.GetDamageType() & DMG_DISSOLVE )
{
CBaseAnimating *pAnimating = dynamic_cast<CBaseAnimating*>(pItem);
if( pAnimating )
{
pAnimating->Dissolve( NULL, gpGlobals->curtime, false, ENTITY_DISSOLVE_NORMAL );
}
}
}
}
//CTDPGameRules *pTDPGameRules = static_cast<CTDPGameRules *>(g_pGameRules);
// Attempt to drop health
/*if ( pTDPGameRules->NPC_ShouldDropHealth( pPlayer ) )
{
DropItem( "item_healthvial", WorldSpaceCenter()+RandomVector(-4,4), RandomAngle(0,360) );
pTDPGameRules->NPC_DroppedHealth();
}*/
// Attempt to drop a grenade
/*if ( pTDPGameRules->NPC_ShouldDropGrenade( pPlayer ) )
{
DropItem( "weapon_frag", WorldSpaceCenter()+RandomVector(-4,4), RandomAngle(0,360) );
pTDPGameRules->NPC_DroppedGrenade();
}*/
}
BaseClass::Event_Killed( info );
}