//----------------------------------------------------------------------------- // Purpose: // Input : *pEntity - // &mins - // &maxs - // &origin - // isStatic - // Output : static IPhysicsObject //----------------------------------------------------------------------------- IPhysicsObject *PhysModelCreateOBB( CBaseEntity *pEntity, const Vector &mins, const Vector &maxs, const Vector &origin, const QAngle &angle, bool isStatic ) { int modelIndex = pEntity->GetModelIndex(); const char *pSurfaceProps = "flesh"; solid_t solid; PhysGetDefaultAABBSolid( solid ); Vector dims = maxs - mins; solid.params.volume = dims.x * dims.y * dims.z; if ( modelIndex ) { const model_t *model = modelinfo->GetModel( modelIndex ); if ( model ) { CStudioHdr studioHdr( modelinfo->GetStudiomodel( model ), mdlcache ); if (studioHdr.IsValid()) { pSurfaceProps = Studio_GetDefaultSurfaceProps( &studioHdr ); } } } Q_strncpy( solid.surfaceprop, pSurfaceProps, sizeof( solid.surfaceprop ) ); CPhysCollide *pCollide = PhysCreateBbox( mins, maxs ); if ( !pCollide ) return NULL; return PhysModelCreateCustom( pEntity, pCollide, origin, angle, STRING(pEntity->GetModelName()), isStatic, &solid ); }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CPlayerClass::InitVCollision( void ) { CPhysCollide *pStandModel = PhysCreateBbox( PLAYERCLASS_HULL_STAND_MIN, PLAYERCLASS_HULL_STAND_MAX ); CPhysCollide *pCrouchModel = PhysCreateBbox( PLAYERCLASS_HULL_DUCK_MIN, PLAYERCLASS_HULL_DUCK_MAX ); solid_t solid; solid.params = g_PhysDefaultObjectParams; solid.params.mass = 85.0f; solid.params.inertia = 1e24f; solid.params.enableCollisions = false; //disable drag solid.params.dragCoefficient = 0; // create standing hull m_pPlayer->m_pShadowStand = PhysModelCreateCustom( m_pPlayer, pStandModel, m_pPlayer->GetLocalOrigin(), m_pPlayer->GetLocalAngles(), "tfplayer_generic", false, &solid ); m_pPlayer->m_pShadowStand->SetCallbackFlags( CALLBACK_SHADOW_COLLISION ); // create crouchig hull m_pPlayer->m_pShadowCrouch = PhysModelCreateCustom( m_pPlayer, pCrouchModel, m_pPlayer->GetLocalOrigin(), m_pPlayer->GetLocalAngles(), "tfplayer_generic", false, &solid ); m_pPlayer->m_pShadowCrouch->SetCallbackFlags( CALLBACK_SHADOW_COLLISION ); // default to stand m_pPlayer->VPhysicsSetObject( m_pPlayer->m_pShadowStand ); //disable drag m_pPlayer->m_pShadowStand->EnableDrag( false ); m_pPlayer->m_pShadowCrouch->EnableDrag( false ); // tell physics lists I'm a shadow controller object PhysAddShadow( m_pPlayer ); m_pPlayer->m_pPhysicsController = physenv->CreatePlayerController( m_pPlayer->m_pShadowStand ); // init state if ( m_pPlayer->GetFlags() & FL_DUCKING ) { m_pPlayer->SetVCollisionState( VPHYS_CROUCH ); } else { m_pPlayer->SetVCollisionState( VPHYS_WALK ); } }
// This creates a vphysics object with a shadow controller that follows the AI IPhysicsObject *C_RagdollShadow::VPhysicsInitShadow( bool allowPhysicsMovement, bool allowPhysicsRotation ) { studiohdr_t *hdr = GetModelPtr(); if ( !hdr ) { return NULL; } // If this entity already has a physics object, then it should have been deleted prior to making this call. Assert(!m_pPhysicsObject); // make sure m_vecOrigin / m_vecAngles are correct const Vector &origin = GetAbsOrigin(); QAngle angles = GetAbsAngles(); IPhysicsObject *pPhysicsObject = NULL; if ( GetSolid() == SOLID_BBOX ) { const char *pSurfaceProps = "flesh"; if ( GetModelIndex() && modelinfo->GetModelType( GetModel() ) == mod_studio ) { pSurfaceProps = Studio_GetDefaultSurfaceProps( hdr ); } angles = vec3_angle; CPhysCollide *pCollide = PhysCreateBbox( WorldAlignMins(), WorldAlignMaxs() ); if ( !pCollide ) return NULL; pPhysicsObject = PhysModelCreateCustom( this, pCollide, origin, angles, pSurfaceProps ); } else { pPhysicsObject = PhysModelCreateRagdoll( this, GetModelIndex(), origin, angles ); } VPhysicsSetObject( pPhysicsObject ); pPhysicsObject->SetShadow( Vector(1e4,1e4,1e4), AngularImpulse(1e4,1e4,1e4), allowPhysicsMovement, allowPhysicsRotation ); pPhysicsObject->UpdateShadow( GetAbsOrigin(), GetAbsAngles(), false, 0 ); // PhysAddShadow( this ); return pPhysicsObject; }