本文整理汇总了C++中IPhysicsObject::SetVelocity方法的典型用法代码示例。如果您正苦于以下问题:C++ IPhysicsObject::SetVelocity方法的具体用法?C++ IPhysicsObject::SetVelocity怎么用?C++ IPhysicsObject::SetVelocity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IPhysicsObject
的用法示例。
在下文中一共展示了IPhysicsObject::SetVelocity方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ThrowGrenade
void CWeaponGrenade::ThrowGrenade( CBasePlayer *pPlayer )
{
#ifndef CLIENT_DLL
Vector vecEye = pPlayer->EyePosition();
Vector vForward, vRight;
pPlayer->EyeVectors( &vForward, &vRight, NULL );
Vector vecSrc = vecEye + vForward * 18.0f + vRight * 8.0f;
CheckThrowPosition( pPlayer, vecEye, vecSrc );
vForward[2] += 0.1f;
Vector vecThrow;
pPlayer->GetVelocity( &vecThrow, NULL );
vecThrow += vForward * 1200;
CBaseGrenade *pGrenade = GrenadeBoing_Create( vecSrc, vec3_angle, vecThrow, AngularImpulse(600,random->RandomInt(-1200,1200),0), pPlayer, GRENADE_TIMER, false );
if ( pGrenade )
{
if ( pPlayer && pPlayer->m_lifeState != LIFE_ALIVE )
{
pPlayer->GetVelocity( &vecThrow, NULL );
IPhysicsObject *pPhysicsObject = pGrenade->VPhysicsGetObject();
if ( pPhysicsObject )
pPhysicsObject->SetVelocity( &vecThrow, NULL );
}
pGrenade->SetDamage( GetHL2MPWpnData().m_iPlayerDamage );
pGrenade->SetDamageRadius( GRENADE_DAMAGE_RADIUS );
}
#endif
}
示例2: GetAbsVelocity
//------------------------------------------------------------------------------
// Pow!
//------------------------------------------------------------------------------
void CPropAPC2::ExplodeAndThrowChunk( const Vector &vecExplosionPos )
{
ExplosionCreate( vecExplosionPos, vec3_angle, this, 1000, 500.0f,
SF_ENVEXPLOSION_NODAMAGE | SF_ENVEXPLOSION_NOSPARKS | SF_ENVEXPLOSION_NODLIGHTS |
SF_ENVEXPLOSION_NOSMOKE | SF_ENVEXPLOSION_NOFIREBALLSMOKE, 0 );
UTIL_ScreenShake( vecExplosionPos, 25.0, 150.0, 1.0, 750.0f, SHAKE_START );
// Drop a flaming, smoking chunk.
CGib *pChunk = CREATE_ENTITY( CGib, "gib" );
pChunk->Spawn( "models/gibs/hgibs.mdl" );
pChunk->SetBloodColor( DONT_BLEED );
QAngle vecSpawnAngles;
vecSpawnAngles.Random( -90, 90 );
pChunk->SetAbsOrigin( vecExplosionPos );
pChunk->SetAbsAngles( vecSpawnAngles );
int nGib = random->RandomInt( 0, APC_MAX_CHUNKS - 1 );
pChunk->Spawn( s_pChunkModelName[nGib] );
pChunk->SetOwnerEntity( this );
pChunk->m_lifeTime = random->RandomFloat( 6.0f, 8.0f );
pChunk->SetCollisionGroup( COLLISION_GROUP_DEBRIS );
IPhysicsObject *pPhysicsObject = pChunk->VPhysicsInitNormal( SOLID_VPHYSICS, pChunk->GetSolidFlags(), false );
// Set the velocity
if ( pPhysicsObject )
{
pPhysicsObject->EnableMotion( true );
Vector vecVelocity;
QAngle angles;
angles.x = random->RandomFloat( -40, 0 );
angles.y = random->RandomFloat( 0, 360 );
angles.z = 0.0f;
AngleVectors( angles, &vecVelocity );
vecVelocity *= random->RandomFloat( 300, 900 );
vecVelocity += GetAbsVelocity();
AngularImpulse angImpulse;
angImpulse = RandomAngularImpulse( -180, 180 );
pChunk->SetAbsVelocity( vecVelocity );
pPhysicsObject->SetVelocity(&vecVelocity, &angImpulse );
}
CEntityFlame *pFlame = CEntityFlame::Create( pChunk, false );
if ( pFlame != NULL )
{
pFlame->SetLifetime( pChunk->m_lifeTime );
}
pChunk->Dissolve( NULL, gpGlobals->curtime, false, ENTITY_DISSOLVE_NORMAL );
}
示例3: ThrowGrenade
//-----------------------------------------------------------------------------
// Purpose:
// Input : *pPlayer -
//-----------------------------------------------------------------------------
void CWeaponFrag::ThrowGrenade( CBasePlayer *pPlayer )
{
#ifndef CLIENT_DLL
Vector vecEye = pPlayer->EyePosition();
Vector vForward, vRight;
pPlayer->EyeVectors( &vForward, &vRight, NULL );
Vector vecSrc = vecEye + vForward * 18.0f + vRight * 8.0f;
CheckThrowPosition( pPlayer, vecEye, vecSrc );
// vForward[0] += 0.1f;
vForward[2] += 0.1f;
Vector vecThrow;
pPlayer->GetVelocity( &vecThrow, NULL );
vecThrow += vForward * 1200;
CBaseGrenade *pGrenade = Fraggrenade_Create( vecSrc, vec3_angle, vecThrow, AngularImpulse(600,random->RandomInt(-1200,1200),0), pPlayer, GRENADE_TIMER, false );
if ( pGrenade )
{
if ( pPlayer && pPlayer->m_lifeState != LIFE_ALIVE )
{
pPlayer->GetVelocity( &vecThrow, NULL );
IPhysicsObject *pPhysicsObject = pGrenade->VPhysicsGetObject();
if ( pPhysicsObject )
{
pPhysicsObject->SetVelocity( &vecThrow, NULL );
}
}
pGrenade->SetDamage( GetHL2MPWpnData().m_iPlayerDamage );
pGrenade->SetDamageRadius( GRENADE_DAMAGE_RADIUS );
}
#endif
m_bRedraw = true;
WeaponSound( SINGLE );
// player "shoot" animation
pPlayer->SetAnimation( PLAYER_ATTACK1 );
}
示例4: TransferPhysicsObject
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool CTriggerPortalCleanser::TransferPhysicsObject( CBaseEntity *pFrom, CBaseEntity *pTo, bool wakeUp )
{
IPhysicsObject *pVPhysics = pFrom->VPhysicsGetObject();
if ( !pVPhysics || pVPhysics->IsStatic() )
return false;
Vector vecVelocity, vecAngular;
pVPhysics->GetVelocity( &vecVelocity, &vecAngular );
// clear out the pointer so it won't get deleted
pFrom->VPhysicsSwapObject( NULL );
// remove any AI behavior bound to it
pVPhysics->RemoveShadowController();
// transfer to the new owner
pTo->VPhysicsSetObject( pVPhysics );
pVPhysics->SetGameData( (void *)pTo );
pTo->VPhysicsUpdate( pVPhysics );
// may have been temporarily disabled by the old object
pVPhysics->EnableMotion( true );
pVPhysics->EnableGravity( false );
// Slow down and push up the object.
vecVelocity /= 2;
vecAngular /= 2;
vecVelocity.z += 10;
pVPhysics->SetVelocity( &vecVelocity, &vecAngular );
// Update for the new entity solid type
pVPhysics->RecheckCollisionFilter();
if ( wakeUp )
{
pVPhysics->Wake();
}
return true;
}
示例5: ThrowGrenade
//-----------------------------------------------------------------------------
// Purpose:
// Input : *pPlayer -
//-----------------------------------------------------------------------------
void CWeaponFrag::ThrowGrenade( CBasePlayer *pPlayer, bool Invis /*= false*/ )
{
#ifndef CLIENT_DLL
Vector vecEye = pPlayer->EyePosition();
Vector vForward, vRight;
pPlayer->EyeVectors( &vForward, &vRight, NULL );
Vector vecSrc = vecEye + vForward * 18.0f + vRight * 8.0f;
CheckThrowPosition( pPlayer, vecEye, vecSrc );
// vForward[0] += 0.1f;
vForward[2] += 0.1f;
Vector vecThrow;
pPlayer->GetVelocity( &vecThrow, NULL );
//DHL - We're just gonna set the grenade off at vecSrc if it goes off "in their hand", so don't worry about velocity
if ( !Invis )
vecThrow += vForward * 1200;
//DHL: Added conditional to last arg, to allow priming...
//If we haven't hit the time we should explode yet, use the remaining time as the clock for the grenade
//Otherwise (we're due to explode) throw (will be forced in the PostFrame function) and go off near immediately
CBaseGrenade *pGrenade = Fraggrenade_Create( vecSrc, vec3_angle, vecThrow, AngularImpulse(600,random->RandomInt(-1200,1200),0), pPlayer, ( (flExplodeTime > gpGlobals->curtime) ? (flExplodeTime - gpGlobals->curtime) : 0.01f ), false );
if ( pGrenade )
{
if ( pPlayer && pPlayer->m_lifeState != LIFE_ALIVE )
{
pPlayer->GetVelocity( &vecThrow, NULL );
IPhysicsObject *pPhysicsObject = pGrenade->VPhysicsGetObject();
if ( pPhysicsObject )
{
pPhysicsObject->SetVelocity( &vecThrow, NULL );
}
}
pGrenade->SetDamage( GetHL2MPWpnData().m_iPlayerDamage );
pGrenade->SetDamageRadius( GRENADE_DAMAGE_RADIUS );
if ( Invis ) //DHL - Don't always want to be able to see the grenade
{
pGrenade->AddEffects( EF_NODRAW );
pGrenade->SetMoveType( MOVETYPE_NONE );
CUtlVector<CBaseEntity *> childrenList;
GetAllChildren( pGrenade, childrenList );
if ( childrenList.Count() ) // If there's any children in the list...
{
for ( int i = childrenList.Count()-1; i >= 0; --i )
{
UTIL_Remove( childrenList[i] ); //Remove them all
}
}
pGrenade->SetAbsVelocity( vec3_origin );
pGrenade->SetAbsOrigin( vecSrc ); //Put the grenade right back in their hand incase it's moved
pGrenade->Detonate();
}
}
#endif
m_bRedraw = true;
WeaponSound( SINGLE );
// player "shoot" animation
pPlayer->SetAnimation( PLAYER_ATTACK1 );
}
示例6: Event_Killed
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CPropAPC::Event_Killed( const CTakeDamageInfo &info )
{
m_OnDeath.FireOutput( info.GetAttacker(), this );
Vector vecAbsMins, vecAbsMaxs;
CollisionProp()->WorldSpaceAABB( &vecAbsMins, &vecAbsMaxs );
Vector vecNormalizedMins, vecNormalizedMaxs;
CollisionProp()->WorldToNormalizedSpace( vecAbsMins, &vecNormalizedMins );
CollisionProp()->WorldToNormalizedSpace( vecAbsMaxs, &vecNormalizedMaxs );
Vector vecAbsPoint;
CPASFilter filter( GetAbsOrigin() );
for (int i = 0; i < 5; i++)
{
CollisionProp()->RandomPointInBounds( vecNormalizedMins, vecNormalizedMaxs, &vecAbsPoint );
te->Explosion( filter, random->RandomFloat( 0.0, 1.0 ), &vecAbsPoint,
g_sModelIndexFireball, random->RandomInt( 4, 10 ),
random->RandomInt( 8, 15 ),
( i < 2 ) ? TE_EXPLFLAG_NODLIGHTS : TE_EXPLFLAG_NOPARTICLES | TE_EXPLFLAG_NOFIREBALLSMOKE | TE_EXPLFLAG_NODLIGHTS,
100, 0 );
}
// TODO: make the gibs spawn in sync with the delayed explosions
int nGibs = random->RandomInt( 1, 4 );
for ( int i = 0; i < nGibs; i++)
{
// Throw a flaming, smoking chunk.
CGib *pChunk = CREATE_ENTITY( CGib, "gib" );
pChunk->Spawn( "models/gibs/hgibs.mdl" );
pChunk->SetBloodColor( DONT_BLEED );
QAngle vecSpawnAngles;
vecSpawnAngles.Random( -90, 90 );
pChunk->SetAbsOrigin( vecAbsPoint );
pChunk->SetAbsAngles( vecSpawnAngles );
int nGib = random->RandomInt( 0, APC_MAX_CHUNKS - 1 );
pChunk->Spawn( s_pChunkModelName[nGib] );
pChunk->SetOwnerEntity( this );
pChunk->m_lifeTime = random->RandomFloat( 6.0f, 8.0f );
pChunk->SetCollisionGroup( COLLISION_GROUP_DEBRIS );
IPhysicsObject *pPhysicsObject = pChunk->VPhysicsInitNormal( SOLID_VPHYSICS, pChunk->GetSolidFlags(), false );
// Set the velocity
if ( pPhysicsObject )
{
pPhysicsObject->EnableMotion( true );
Vector vecVelocity;
QAngle angles;
angles.x = random->RandomFloat( -20, 20 );
angles.y = random->RandomFloat( 0, 360 );
angles.z = 0.0f;
AngleVectors( angles, &vecVelocity );
vecVelocity *= random->RandomFloat( 300, 900 );
vecVelocity += GetAbsVelocity();
AngularImpulse angImpulse;
angImpulse = RandomAngularImpulse( -180, 180 );
pChunk->SetAbsVelocity( vecVelocity );
pPhysicsObject->SetVelocity(&vecVelocity, &angImpulse );
}
CEntityFlame *pFlame = CEntityFlame::Create( pChunk, false );
if ( pFlame != NULL )
{
pFlame->SetLifetime( pChunk->m_lifeTime );
}
}
UTIL_ScreenShake( vecAbsPoint, 25.0, 150.0, 1.0, 750.0f, SHAKE_START );
if( hl2_episodic.GetBool() )
{
// EP1 perf hit
Ignite( 6, false );
}
else
{
Ignite( 60, false );
}
m_lifeState = LIFE_DYING;
// Spawn a lesser amount if the player is close
m_iRocketSalvoLeft = DEATH_VOLLEY_ROCKET_COUNT;
m_flRocketTime = gpGlobals->curtime;
}
示例7: ThrowObject
void CNPC_Dog::ThrowObject( const char *pAttachmentName )
{
if ( m_hPhysicsEnt )
{
m_bHasObject = false;
IPhysicsObject *pPhysObj = m_hPhysicsEnt->VPhysicsGetObject();
if ( pPhysObj )
{
Vector vGunPos;
QAngle angGunAngles;
AngularImpulse angVelocity = RandomAngularImpulse( -250 , -250 ) / pPhysObj->GetMass();
InvalidateBoneCache();
int iAttachment = LookupAttachment( pAttachmentName );
if ( iAttachment == 0 )
iAttachment = m_iPhysGunAttachment;
GetAttachment( iAttachment, vGunPos, angGunAngles );
pPhysObj->Wake();
if ( pPhysObj->GetShadowController() )
{
m_hPhysicsEnt->SetParent( NULL );
m_hPhysicsEnt->SetMoveType( (MoveType_t)m_iContainerMoveType );
m_hPhysicsEnt->SetOwnerEntity( this );
pPhysObj->RemoveShadowController();
pPhysObj->SetPosition( m_hPhysicsEnt->GetLocalOrigin(), m_hPhysicsEnt->GetLocalAngles(), true );
pPhysObj->RecheckCollisionFilter();
pPhysObj->RecheckContactPoints();
}
if ( m_hThrowTarget == NULL )
#ifdef SecobMod__Enable_Fixed_Multiplayer_AI
m_hThrowTarget = UTIL_GetNearestVisiblePlayer(this);
#else
m_hThrowTarget = AI_GetSinglePlayer();
#endif //SecobMod__Enable_Fixed_Multiplayer_AI
Vector vThrowDirection;
if ( m_hThrowTarget )
{
Vector vThrowOrigin = m_hThrowTarget->GetAbsOrigin();
if ( m_hThrowTarget->IsPlayer() )
vThrowOrigin = vThrowOrigin + Vector( random->RandomFloat( -128, 128 ), random->RandomFloat( -128, 128 ), 0 );
Vector vecToss = VecCheckToss( this, vGunPos, vThrowOrigin, m_flThrowArcModifier, 1.0f, true );
if( vecToss == vec3_origin )
{
// Fix up an impossible throw so dog will at least toss the box in the target's general direction instead of dropping it.
// Also toss it up in the air so it will fall down and break. (Just throw the box up at a 45 degree angle)
Vector forward, up;
GetVectors( &forward, NULL, &up );
vecToss = forward + up;
VectorNormalize( vecToss );
vecToss *= pPhysObj->GetMass() * 30.0f;
}
vThrowDirection = vecToss + ( m_hThrowTarget->GetSmoothedVelocity() / 2 );
Vector vLinearDrag;
Vector unitVel = vThrowDirection;
VectorNormalize( unitVel );
float flTest = 1000 / vThrowDirection.Length();
float flDrag = pPhysObj->CalculateLinearDrag( vThrowDirection );
vThrowDirection = vThrowDirection + ( unitVel * ( flDrag * flDrag ) ) / flTest;
pPhysObj->SetVelocity( &vThrowDirection, &angVelocity );
m_flTimeToCatch = gpGlobals->curtime + dog_max_wait_time.GetFloat();
//Don't start pulling until the object is away from me.
//We base the time on the throw velocity.
m_flTimeToPull = gpGlobals->curtime + ( 1000 / vThrowDirection.Length() );
}
//Fire Output!
m_OnThrow.FireOutput( this, this );
ClearBeams();
if ( m_bBeamEffects == true )
{
EmitSound( "Weapon_PhysCannon.Launch" );
//.........这里部分代码省略.........
示例8: PullObject
void CNPC_Dog::PullObject( bool bMantain )
{
if ( m_hPhysicsEnt == NULL )
{
TaskFail( "Ack! No Phys Object!");
return;
}
IPhysicsObject *pPhysObj = m_hPhysicsEnt->VPhysicsGetObject();
if ( pPhysObj == NULL )
{
TaskFail( "Pulling object with no Phys Object?!" );
return;
}
if( pPhysObj->GetGameFlags() & FVPHYSICS_PLAYER_HELD )
{
m_bHasObject = false;
ClearBeams();
TaskFail("Player Grabbed Ball");
return;
}
CreateBeams();
Vector vGunPos;
GetAttachment( m_iPhysGunAttachment, vGunPos );
float flDistance = ( vGunPos - m_hPhysicsEnt->WorldSpaceCenter() ).Length();
if ( bMantain == false )
{
if ( flDistance <= DOG_CATCH_DISTANCE )
{
m_hPhysicsEnt->SetOwnerEntity( this );
GetNavigator()->StopMoving();
//Fire Output!
m_OnPickup.FireOutput( this, this );
m_bHasObject = true;
ClearBeams();
TaskComplete();
return;
}
}
Vector vDir = ( vGunPos - m_hPhysicsEnt->WorldSpaceCenter() );
Vector vCurrentVel;
float flCurrentVel;
AngularImpulse vCurrentAI;
pPhysObj->GetVelocity( &vCurrentVel, &vCurrentAI );
flCurrentVel = vCurrentVel.Length();
VectorNormalize( vCurrentVel );
VectorNormalize( vDir );
float flVelMod = DOG_PULL_VELOCITY_MOD;
if ( bMantain == true )
flVelMod *= 2;
vCurrentVel = vCurrentVel * flCurrentVel * flVelMod;
vCurrentAI = vCurrentAI * DOG_PULL_ANGULARIMP_MOD;
pPhysObj->SetVelocity( &vCurrentVel, &vCurrentAI );
vDir = vDir * flDistance * (DOG_PULL_TO_GUN_VEL_MOD * 2);
Vector vAngle( 0, 0, 0 );
pPhysObj->AddVelocity( &vDir, &vAngle );
}
示例9: RunTask
//.........这里部分代码省略.........
if ( pPlayer )
{
flDistanceToPlayer = (pPlayer->GetAbsOrigin() - m_hPhysicsEnt->WorldSpaceCenter()).Length();
}
IPhysicsObject *pPhysObj = m_hPhysicsEnt->VPhysicsGetObject();
if ( !pPhysObj )
{
Warning( "npc_dog: TASK_DOG_WAIT_FOR_OBJECT with m_hPhysicsEnt->VPhysicsGetObject == NULL\n" );
}
if ( pPhysObj && !( pPhysObj->GetGameFlags() & FVPHYSICS_PLAYER_HELD ) && flDistanceToPlayer > ( flDistance * 2 ) )
{
if ( m_flTimeToPull <= gpGlobals->curtime )
{
Vector vCurrentVel;
float flCurrentVel;
AngularImpulse vCurrentAI;
pPhysObj->GetVelocity( &vCurrentVel, &vCurrentAI );
flCurrentVel = vCurrentVel.Length();
VectorNormalize( vCurrentVel );
if ( pPhysObj && flDistance <= DOG_PULL_DISTANCE )
{
Vector vDir = ( vGunPos - m_hPhysicsEnt->WorldSpaceCenter() );
VectorNormalize( vDir );
vCurrentVel = vCurrentVel * ( flCurrentVel * DOG_PULL_VELOCITY_MOD );
vCurrentAI = vCurrentAI * DOG_PULL_ANGULARIMP_MOD;
pPhysObj->SetVelocity( &vCurrentVel, &vCurrentAI );
vDir = vDir * flDistance * DOG_PULL_TO_GUN_VEL_MOD;
Vector vAngle( 0, 0, 0 );
pPhysObj->AddVelocity( &vDir, &vAngle );
CreateBeams();
}
float flDot = DotProduct( vCurrentVel, vForward );
if ( flDistance >= DOG_PULL_DISTANCE && flDistance <= ( DOG_PULL_DISTANCE * 2 ) && flDot > -0.3 )
{
if ( pPhysObj->IsAsleep() == false && !( pPhysObj->GetGameFlags() & FVPHYSICS_PLAYER_HELD ) )
{
Vector vecGoalPos;
Vector vecDir;
vecDir = GetLocalOrigin() - m_hPhysicsEnt->WorldSpaceCenter();
VectorNormalize(vecDir);
vecDir.z = 0;
vecGoalPos = m_hPhysicsEnt->WorldSpaceCenter() + (vecDir * DOG_PHYSOBJ_MOVE_TO_DIST );
GetNavigator()->ClearGoal();
//If I'm near my goal, then just walk to it.
Activity aActivity = ACT_RUN;
if ( ( vecGoalPos - GetLocalOrigin() ).Length() <= 128 )
aActivity = ACT_WALK;
示例10: CreateVPhysicsFromOBBs
bool CStatueProp::CreateVPhysicsFromOBBs( CBaseAnimating *pInitBaseAnimating )
{
// Make enough pointers to convexes for each hitbox
CPhysConvex **ppConvex = new (CPhysConvex*[ m_pInitOBBs->Count() ]);
float flTotalVolume = 0.0f;
float flTotalSurfaceArea = 0.0f;
for ( int i = 0; i < m_pInitOBBs->Count(); i++ )
{
const outer_collision_obb_t *pOBB = &((*m_pInitOBBs)[ i ]);
// Accumulate volume and area
Vector flDimentions = pOBB->vecMaxs - pOBB->vecMins;
flTotalVolume += flDimentions.x * flDimentions.y * flDimentions.z;
flTotalSurfaceArea += 2.0f * ( flDimentions.x * flDimentions.y + flDimentions.x * flDimentions.z + flDimentions.y * flDimentions.z );
// Get angled min and max extents
Vector vecMins, vecMaxs;
VectorRotate( pOBB->vecMins, pOBB->angAngles, vecMins );
VectorRotate( pOBB->vecMaxs, pOBB->angAngles, vecMaxs );
// Get the corners in world space
Vector vecMinCorner = pOBB->vecPos + vecMins;
Vector vecMaxCorner = pOBB->vecPos + vecMaxs;
// Get the normals of the hitbox in world space
Vector vecForward, vecRight, vecUp;
AngleVectors( pOBB->angAngles, &vecForward, &vecRight, &vecUp );
vecRight = -vecRight;
// Convert corners and normals to local space
Vector vecCornerLocal[ 2 ];
Vector vecNormalLocal[ 3 ];
matrix3x4_t matToWorld = EntityToWorldTransform();
VectorITransform( vecMaxCorner, matToWorld, vecCornerLocal[ 0 ] );
VectorITransform( vecMinCorner, matToWorld, vecCornerLocal[ 1 ] );
VectorIRotate( vecForward, matToWorld, vecNormalLocal[ 0 ] );
VectorIRotate( vecRight, matToWorld, vecNormalLocal[ 1 ] );
VectorIRotate( vecUp, matToWorld, vecNormalLocal[ 2 ] );
// Create 6 planes from the local oriented hit box data
float pPlanes[ 4 * 6 ];
for ( int iPlane = 0; iPlane < 6; ++iPlane )
{
int iPlaneMod2 = iPlane % 2;
int iPlaneDiv2 = iPlane / 2;
bool bOdd = ( iPlaneMod2 == 1 );
// Plane Normal
pPlanes[ iPlane * 4 + 0 ] = vecNormalLocal[ iPlaneDiv2 ].x * ( bOdd ? -1.0f : 1.0f );
pPlanes[ iPlane * 4 + 1 ] = vecNormalLocal[ iPlaneDiv2 ].y * ( bOdd ? -1.0f : 1.0f );
pPlanes[ iPlane * 4 + 2 ] = vecNormalLocal[ iPlaneDiv2 ].z * ( bOdd ? -1.0f : 1.0f );
// Plane D
pPlanes[ iPlane * 4 + 3 ] = ( vecCornerLocal[ iPlaneMod2 ].x * vecNormalLocal[ iPlaneDiv2 ].x +
vecCornerLocal[ iPlaneMod2 ].y * vecNormalLocal[ iPlaneDiv2 ].y +
vecCornerLocal[ iPlaneMod2 ].z * vecNormalLocal[ iPlaneDiv2 ].z ) * ( bOdd ? -1.0f : 1.0f );
}
// Create convex from the intersection of these planes
ppConvex[ i ] = physcollision->ConvexFromPlanes( pPlanes, 6, 0.0f );
}
// Make a single collide out of the group of convex boxes
CPhysCollide *pPhysCollide = physcollision->ConvertConvexToCollide( ppConvex, m_pInitOBBs->Count() );
delete[] ppConvex;
// Create the physics object
objectparams_t params = g_PhysDefaultObjectParams;
params.pGameData = static_cast<void *>( this );
int nMaterialIndex = physprops->GetSurfaceIndex( "ice" ); // use ice material
IPhysicsObject* p = physenv->CreatePolyObject( pPhysCollide, nMaterialIndex, GetAbsOrigin(), GetAbsAngles(), ¶ms );
Assert( p != NULL );
// Set velocity
Vector vecInitialVelocity = pInitBaseAnimating->GetAbsVelocity();
p->SetVelocity( &vecInitialVelocity, NULL );
// Compute mass
float flMass;
float flDensity, flThickness;
physprops->GetPhysicsProperties( nMaterialIndex, &flDensity, &flThickness, NULL, NULL );
// Make it more hollow
flThickness = MIN ( 1.0f, flThickness + 0.5f );
if ( flThickness > 0.0f )
{
flMass = flTotalSurfaceArea * flThickness * CUBIC_METERS_PER_CUBIC_INCH * flDensity;
}
else
{
// density is in kg/m^3, volume is in in^3
flMass = flTotalVolume * CUBIC_METERS_PER_CUBIC_INCH * flDensity;
//.........这里部分代码省略.........
示例11: CreateVPhysicsFromHitBoxes
//.........这里部分代码省略.........
VectorITransform( vecMinCorner, matToWorld, vecCornerLocal[ 1 ] );
VectorIRotate( vecForward, matToWorld, vecNormalLocal[ 0 ] );
VectorIRotate( vecRight, matToWorld, vecNormalLocal[ 1 ] );
VectorIRotate( vecUp, matToWorld, vecNormalLocal[ 2 ] );
// Create 6 planes from the local oriented hit box data
float pPlanes[ 4 * 6 ];
for ( int iPlane = 0; iPlane < 6; ++iPlane )
{
int iPlaneMod2 = iPlane % 2;
int iPlaneDiv2 = iPlane / 2;
bool bOdd = ( iPlaneMod2 == 1 );
// Plane Normal
pPlanes[ iPlane * 4 + 0 ] = vecNormalLocal[ iPlaneDiv2 ].x * ( bOdd ? -1.0f : 1.0f );
pPlanes[ iPlane * 4 + 1 ] = vecNormalLocal[ iPlaneDiv2 ].y * ( bOdd ? -1.0f : 1.0f );
pPlanes[ iPlane * 4 + 2 ] = vecNormalLocal[ iPlaneDiv2 ].z * ( bOdd ? -1.0f : 1.0f );
// Plane D
pPlanes[ iPlane * 4 + 3 ] = ( vecCornerLocal[ iPlaneMod2 ].x * vecNormalLocal[ iPlaneDiv2 ].x +
vecCornerLocal[ iPlaneMod2 ].y * vecNormalLocal[ iPlaneDiv2 ].y +
vecCornerLocal[ iPlaneMod2 ].z * vecNormalLocal[ iPlaneDiv2 ].z ) * ( bOdd ? -1.0f : 1.0f );
}
// Create convex from the intersection of these planes
ppConvex[ i ] = physcollision->ConvexFromPlanes( pPlanes, 6, 0.0f );
}
// Make a single collide out of the group of convex boxes
CPhysCollide *pPhysCollide = physcollision->ConvertConvexToCollide( ppConvex, set->numhitboxes );
delete[] ppConvex;
// Create the physics object
objectparams_t params = g_PhysDefaultObjectParams;
params.pGameData = static_cast<void *>( this );
int nMaterialIndex = physprops->GetSurfaceIndex( "ice" ); // use ice material
IPhysicsObject* p = physenv->CreatePolyObject( pPhysCollide, nMaterialIndex, GetAbsOrigin(), GetAbsAngles(), ¶ms );
Assert( p != NULL );
// Set velocity
Vector vecInitialVelocity = pInitBaseAnimating->GetAbsVelocity();
p->SetVelocity( &vecInitialVelocity, NULL );
// Compute mass
float flMass;
float flDensity, flThickness;
physprops->GetPhysicsProperties( nMaterialIndex, &flDensity, &flThickness, NULL, NULL );
// Make it more hollow
flThickness = MIN ( 1.0f, flThickness + 0.5f );
if ( flThickness > 0.0f )
{
flMass = flTotalSurfaceArea * flThickness * CUBIC_METERS_PER_CUBIC_INCH * flDensity;
}
else
{
// density is in kg/m^3, volume is in in^3
flMass = flTotalVolume * CUBIC_METERS_PER_CUBIC_INCH * flDensity;
}
// Mass is somewhere between the original and if it was all ice
p->SetMass( flMass );
// Yes, gravity
p->EnableGravity( true );
// Use this as our vphysics
VPhysicsSetObject( p );
SetSolid( SOLID_VPHYSICS );
AddSolidFlags( FSOLID_CUSTOMRAYTEST | FSOLID_CUSTOMBOXTEST );
SetMoveType( MOVETYPE_VPHYSICS );
if ( pInitBaseAnimating != this )
{
// Transfer children from the init base animating
TransferChildren( pInitBaseAnimating, this );
CBaseEntity *pChild = FirstMoveChild();
while ( pChild )
{
CEntityFreezing *pFreezing = dynamic_cast<CEntityFreezing*>( pChild );
if ( pFreezing )
{
pFreezing->FinishFreezing();
}
pChild = pChild->NextMovePeer();
}
}
return true;
}
示例12: StartTouch
//-----------------------------------------------------------------------------
// Purpose: Called when an entity starts touching us.
// Input : pOther - The entity that is touching us.
//-----------------------------------------------------------------------------
void CTriggerPortalCleanser::StartTouch( CBaseEntity *pOther )
{
if ( PassesTriggerFilters(pOther) )
{
EHANDLE hOther;
hOther = pOther;
bool bAdded = false;
if ( m_hTouchingEntities.Find( hOther ) == m_hTouchingEntities.InvalidIndex() )
{
m_hTouchingEntities.AddToTail( hOther );
bAdded = true;
}
m_OnStartTouch.FireOutput(pOther, this);
if ( bAdded && ( m_hTouchingEntities.Count() == 1 ) )
{
// First entity to touch us that passes our filters
m_OnStartTouchAll.FireOutput( pOther, this );
}
if ( portal_cleanser_debug.GetBool() )
{
Msg("%s START-TOUCH: for %s\n", GetDebugName(), pOther->GetDebugName() );
}
if ( !pOther->IsPlayer() )
{
CBaseAnimating *pAnim = pOther->GetBaseAnimating();
if ( !pAnim )
return;
// Can't dissolve twice.
if ( pAnim->IsDissolving() )
return;
// Force player to drop this object.
Pickup_ForcePlayerToDropThisObject( pOther );
if ( !FClassnameIs( pOther, "prop_physics" ) )
{
if ( FClassnameIs( pOther, "simple_physics_prop" ) || FClassnameIs( pOther, "simple_physics_brush" ) )
{
// simple_physics_prop ?
return;
}
if ( portal_cleanser_debug.GetBool() )
{
Msg("%s IS CREATING: simple_physics_prop\n", GetDebugName());
}
// Other object needs to be replaced by simple_physics_prop.
pOther = CreateSimplePhysicsObject( pOther );
// Dissolve the entity.
CBaseAnimating *pAnim = pOther->GetBaseAnimating();
pAnim->Dissolve( NULL, gpGlobals->curtime, false, ENTITY_DISSOLVE_NORMAL );
if ( portal_cleanser_debug.GetBool() )
{
Msg("%s DISSOLVE SIMPLE PHYSICS: %s\n", GetDebugName(), pOther->GetDebugName() );
}
// Outputs
m_hActivator = pOther;
m_OnDissolve.FireOutput(m_hActivator, this);
return;
}
IPhysicsObject *pPhysics = pOther->VPhysicsGetObject();
if ( pPhysics )
{
// Dissolve the entity.
pAnim->Dissolve( NULL, gpGlobals->curtime, false, ENTITY_DISSOLVE_NORMAL );
if ( portal_cleanser_debug.GetBool() )
{
Msg("%s DISSOLVE PHYSICS: %s\n", GetDebugName(), pOther->GetDebugName() );
}
// Turn off the gravity for this object.
pPhysics->EnableGravity( false );
// Slow down and push up the object.
Vector vecVelocity, vecAngular;
pPhysics->GetVelocity( &vecVelocity, &vecAngular );
vecVelocity /= 2;
vecAngular /= 2;
vecVelocity.z += 10;
pPhysics->SetVelocity( &vecVelocity, &vecAngular );
// Outputs
m_hActivator = pOther;
m_OnDissolve.FireOutput(m_hActivator, this);
//.........这里部分代码省略.........