bool CBoneFollower::Init( CBaseEntity *pOwner, const char *pModelName, solid_t &solid, const Vector &position, const QAngle &orientation ) { SetOwnerEntity( pOwner ); UTIL_SetModel( this, pModelName ); m_fEffects |= EF_NODRAW; // invisible #if VISUALIZE_FOLLOWERS_BOUNDINGBOX m_debugOverlays |= OVERLAY_BBOX_BIT; #endif m_modelIndex = modelinfo->GetModelIndex( pModelName ); m_solidIndex = solid.index; SetAbsOrigin( position ); SetAbsAngles( orientation ); SetMoveType( MOVETYPE_PUSH ); SetSolid( SOLID_VPHYSICS ); SetCollisionGroup( pOwner->GetCollisionGroup() ); AddSolidFlags( FSOLID_CUSTOMRAYTEST | FSOLID_CUSTOMBOXTEST ); solid.params.pGameData = (void *)this; IPhysicsObject *pPhysics = VPhysicsInitShadow( false, false, &solid ); if ( !pPhysics ) return false; pPhysics->SetCallbackFlags( pPhysics->GetCallbackFlags() | CALLBACK_GLOBAL_TOUCH ); pPhysics->EnableGravity( false ); return true; }
bool CGrenade_Brickbat::CreateVPhysics() { VPhysicsInitNormal( SOLID_VPHYSICS, 0, false ); IPhysicsObject *pPhysics = VPhysicsGetObject(); if ( pPhysics ) { // we want world touches unsigned int flags = pPhysics->GetCallbackFlags(); pPhysics->SetCallbackFlags( flags | CALLBACK_GLOBAL_TOUCH_STATIC ); } return true; }
bool CTripwireHook::CreateVPhysics() { // Create the object in the physics system IPhysicsObject *pPhysicsObject = VPhysicsInitNormal( SOLID_BBOX, 0, false ); // Make sure I get touch called for static geometry if ( pPhysicsObject ) { int flags = pPhysicsObject->GetCallbackFlags(); flags |= CALLBACK_GLOBAL_TOUCH_STATIC; pPhysicsObject->SetCallbackFlags(flags); } return true; }
bool CNPC_Tentacle::CreateVPhysics( void ) { BaseClass::CreateVPhysics(); IPhysicsObject *pPhysics = VPhysicsGetObject(); if( pPhysics ) { unsigned short flags = pPhysics->GetCallbackFlags(); flags |= CALLBACK_GLOBAL_TOUCH; pPhysics->SetCallbackFlags( flags ); } m_BoneFollowerManager.InitBoneFollowers( this, ARRAYSIZE(pTentacleFollowerBoneNames), pTentacleFollowerBoneNames ); return true; }
void PhysCreateVirtualTerrain( CBaseEntity *pWorld, const objectparams_t &defaultParams ) { for ( int i = 0; i < MAX_MAP_DISPINFO; i++ ) { virtualterrainparams_t params; params.index = i; CPhysCollide *pCollide = modelinfo->GetCollideForVirtualTerrain( params ); if ( pCollide ) { solid_t solid; solid.params = defaultParams; solid.params.enableCollisions = true; solid.params.pGameData = static_cast<void *>(pWorld); solid.params.pName = "world"; int surfaceData = physprops->GetSurfaceIndex( "default" ); // create this as part of the world IPhysicsObject *pObject = physenv->CreatePolyObjectStatic( pCollide, surfaceData, vec3_origin, vec3_angle, &solid.params ); pObject->SetCallbackFlags( pObject->GetCallbackFlags() | CALLBACK_NEVER_DELETED ); } } }
void PhysCreateVirtualTerrain( CBaseEntity *pWorld, const objectparams_t &defaultParams ) { char nameBuf[1024]; for ( int i = 0; i < MAX_MAP_DISPINFO; i++ ) { CPhysCollide *pCollide = modelinfo->GetCollideForVirtualTerrain( i ); if ( pCollide ) { solid_t solid; solid.params = defaultParams; solid.params.enableCollisions = true; solid.params.pGameData = static_cast<void *>(pWorld); Q_snprintf(nameBuf, sizeof(nameBuf), "vdisp_%04d", i ); solid.params.pName = nameBuf; int surfaceData = physprops->GetSurfaceIndex( "default" ); // create this as part of the world IPhysicsObject *pObject = physenv->CreatePolyObjectStatic( pCollide, surfaceData, vec3_origin, vec3_angle, &solid.params ); pObject->SetCallbackFlags( pObject->GetCallbackFlags() | CALLBACK_NEVER_DELETED ); pObject->SetCollisionHints( COLLISION_HINT_STATICSOLID ); } } }
bool CBoneFollower::Init( CBaseEntity *pOwner, const char *pModelName, solid_t &solid, const Vector &position, const QAngle &orientation ) { SetOwnerEntity( pOwner ); UTIL_SetModel( this, pModelName ); AddEffects( EF_NODRAW ); // invisible m_modelIndex = modelinfo->GetModelIndex( pModelName ); m_solidIndex = solid.index; SetAbsOrigin( position ); SetAbsAngles( orientation ); SetMoveType( MOVETYPE_PUSH ); SetSolid( SOLID_VPHYSICS ); SetCollisionGroup( pOwner->GetCollisionGroup() ); AddSolidFlags( FSOLID_CUSTOMRAYTEST | FSOLID_CUSTOMBOXTEST ); solid.params.pGameData = (void *)this; IPhysicsObject *pPhysics = VPhysicsInitShadow( false, false, &solid ); if ( !pPhysics ) return false; // we can't use the default model bounds because each entity is only one bone of the model // so compute the OBB of the physics model and use that. Vector mins, maxs; physcollision->CollideGetAABB( &mins, &maxs, pPhysics->GetCollide(), vec3_origin, vec3_angle ); SetCollisionBounds( mins, maxs ); pPhysics->SetCallbackFlags( pPhysics->GetCallbackFlags() | CALLBACK_GLOBAL_TOUCH ); pPhysics->EnableGravity( false ); // This is not a normal shadow controller that is trying to go to a space occupied by an entity in the game physics // This entity is not running PhysicsPusher(), so Vphysics is supposed to move it // This line of code informs vphysics of that fact if ( pOwner->IsNPC() ) { pPhysics->GetShadowController()->SetPhysicallyControlled( true ); } return true; }
IPhysicsObject *PhysCreateWorld_Shared( CBaseEntity *pWorld, vcollide_t *pWorldCollide, const objectparams_t &defaultParams ) { solid_t solid; fluid_t fluid; int surfaceData = physprops->GetSurfaceIndex( "default" ); objectparams_t params = defaultParams; params.pGameData = static_cast<void *>(pWorld); params.pName = "world"; IPhysicsObject *pWorldPhysics = physenv->CreatePolyObjectStatic( pWorldCollide->solids[0], surfaceData, vec3_origin, vec3_angle, ¶ms ); // hint - saves vphysics some work pWorldPhysics->SetCallbackFlags( pWorldPhysics->GetCallbackFlags() | CALLBACK_NEVER_DELETED ); //PhysCheckAdd( world, "World" ); // walk the world keys in case there are some fluid volumes to create IVPhysicsKeyParser *pParse = physcollision->VPhysicsKeyParserCreate( pWorldCollide ); bool bCreateVirtualTerrain = false; while ( !pParse->Finished() ) { const char *pBlock = pParse->GetCurrentBlockName(); if ( !strcmpi( pBlock, "solid" ) || !strcmpi( pBlock, "staticsolid" ) ) { solid.params = defaultParams; pParse->ParseSolid( &solid, &g_SolidSetup ); solid.params.enableCollisions = true; solid.params.pGameData = static_cast<void *>(pWorld); solid.params.pName = "world"; int surfaceData = physprops->GetSurfaceIndex( "default" ); // already created world above if ( solid.index == 0 ) continue; if ( !pWorldCollide->solids[solid.index] ) { // this implies that the collision model is a mopp and the physics DLL doesn't support that. bCreateVirtualTerrain = true; continue; } // create this as part of the world IPhysicsObject *pObject = physenv->CreatePolyObjectStatic( pWorldCollide->solids[solid.index], surfaceData, vec3_origin, vec3_angle, &solid.params ); // invalid collision model or can't create, ignore if (!pObject) continue; pObject->SetCallbackFlags( pObject->GetCallbackFlags() | CALLBACK_NEVER_DELETED ); Assert( solid.contents != 0 ); pObject->SetContents( solid.contents ); if ( solid.contents & CONTENTS_SOLID ) { pObject->SetCollisionHints(COLLISION_HINT_STATICSOLID); } if ( !pWorldPhysics ) { pWorldPhysics = pObject; } } else if ( !strcmpi( pBlock, "fluid" ) ) { pParse->ParseFluid( &fluid, NULL ); // create a fluid for floating if ( fluid.index > 0 ) { solid.params = defaultParams; // copy world's params solid.params.enableCollisions = true; solid.params.pName = "fluid"; solid.params.pGameData = static_cast<void *>(pWorld); fluid.params.pGameData = static_cast<void *>(pWorld); int surfaceData = physprops->GetSurfaceIndex( fluid.surfaceprop ); // create this as part of the world IPhysicsObject *pWater = physenv->CreatePolyObjectStatic( pWorldCollide->solids[fluid.index], surfaceData, vec3_origin, vec3_angle, &solid.params ); pWater->SetCallbackFlags( pWater->GetCallbackFlags() | CALLBACK_NEVER_DELETED ); physenv->CreateFluidController( pWater, &fluid.params ); } } else if ( !strcmpi( pBlock, "materialtable" ) ) { int surfaceTable[128]; memset( surfaceTable, 0, sizeof(surfaceTable) ); pParse->ParseSurfaceTable( surfaceTable, NULL ); physprops->SetWorldMaterialIndexTable( surfaceTable, 128 ); } else if ( !strcmpi(pBlock, "virtualterrain" ) ) { bCreateVirtualTerrain = true; pParse->SkipBlock(); } else { // unknown chunk??? pParse->SkipBlock(); } } physcollision->VPhysicsKeyParserDestroy( pParse ); if ( bCreateVirtualTerrain && physcollision->SupportsVirtualMesh() ) { PhysCreateVirtualTerrain( pWorld, defaultParams ); } return pWorldPhysics; }