Files
funnygame/game/server/physicsprop.cpp
2026-03-18 18:41:28 +02:00

103 lines
2.0 KiB
C++

#include "physicsprop.h"
#include "game.h"
CPhysicsProp::CPhysicsProp()
{
SetAbsOrigin({0,0,0});
SetAbsQAngles(0,0,0);
}
void CPhysicsProp::Precache()
{
}
void CPhysicsProp::Spawn()
{
CBaseEntity::Spawn();
SetThink(Think);
}
void CPhysicsProp::Think( float fDelta )
{
BaseClass::Think(fDelta);
if (m_pBody)
{
if (m_ePhysicsType != m_eCurrentPhysicsType)
{
m_ePhysicsType = m_eCurrentPhysicsType;
m_pBody->SetType(m_eCurrentPhysicsType);
}
BaseClass::SetAbsOrigin(m_pBody->GetPosition());
BaseClass::SetAbsAngles(m_pBody->GetRotation());
}
}
void CPhysicsProp::SetAbsAngles( Quat vQuat )
{
BaseClass::SetAbsAngles( vQuat );
if (m_pBody)
m_pBody->SetRotation(GetAbsAngles());
}
void CPhysicsProp::SetAbsQAngles( float fPitch, float fYaw, float fRoll )
{
BaseClass::SetAbsQAngles( fPitch, fYaw, fRoll);
if (m_pBody)
m_pBody->SetRotation(GetAbsAngles());
}
void CPhysicsProp::SetAbsOrigin( Vector origin )
{
BaseClass::SetAbsOrigin( origin );
if (m_pBody)
m_pBody->SetPosition(GetAbsOrigin());
}
void CPhysicsProp::OnModelChanged( const char *szName )
{
if (m_hModel)
{
g_pAssetManager->UnrefModel(m_hModel);
}
m_hModel = g_pAssetManager->LoadModel(szName);
m_pModel = g_pAssetManager->GetModelByIndex(m_hModel);
m_pPhysics = g_pAssetManager->GetPhysicsByIndex(m_pModel->m_hPhysics);
m_hCollider = g_pPhysics->CreateCollider(m_pPhysics->m_hShape);
m_pBody = g_pPhysicsWorld->CreateRigidBody(m_hCollider, m_eCurrentPhysicsType);
m_pBody->SetPosition(GetAbsOrigin());
m_pBody->SetRotation(GetAbsAngles());
m_ePhysicsType = m_eCurrentPhysicsType;
if (!V_strcmp(szName, "game/core/maps/test/test0.fmdl"))
{
m_pBody->SetType(k_EPhysics_Static);
SetScale(1);
}
}
void CPhysicsProp::EnableMovement()
{
}
void CPhysicsProp::DisableMovement()
{
}
void CPhysicsProp::SetPhysics( EPhysicsBodyType eType )
{
m_eCurrentPhysicsType = eType;
}
BEGIN_DATADESC(CPhysicsProp)
DEFINE_KEYFIELD(m_ePhysicsType, FIELD_INTEGER, "physics_type")
END_DATADESC()
LINK_ENTITY_TO_CLASS(prop_physics, CPhysicsProp)