79 lines
1.6 KiB
C++
79 lines
1.6 KiB
C++
#include "physicsprop.h"
|
|
#include "game.h"
|
|
|
|
|
|
void CPhysicsProp::Precache()
|
|
{
|
|
|
|
}
|
|
|
|
void CPhysicsProp::Spawn()
|
|
{
|
|
CBaseEntity::Spawn();
|
|
SetThink(Think);
|
|
}
|
|
|
|
void CPhysicsProp::Think( float fDelta )
|
|
{
|
|
BaseClass::Think(fDelta);
|
|
if (m_pBody)
|
|
{
|
|
BaseClass::SetAbsOrigin(m_pBody->GetPosition());
|
|
BaseClass::SetAbsAngles(m_pBody->GetRotation());
|
|
}
|
|
V_printf("%f %f %f\n", GetAbsOrigin().x, GetAbsOrigin().y, GetAbsOrigin().z);
|
|
}
|
|
|
|
void CPhysicsProp::SetAbsAngles( Quat vQuat )
|
|
{
|
|
|
|
BaseClass::SetAbsAngles( vQuat );
|
|
if (m_pBody)
|
|
m_pBody->SetRotation(m_pBody->GetRotation());
|
|
}
|
|
|
|
void CPhysicsProp::SetAbsQAngles( float fPitch, float fYaw, float fRoll )
|
|
{
|
|
|
|
BaseClass::SetAbsQAngles( fPitch, fYaw, fRoll);
|
|
if (m_pBody)
|
|
m_pBody->SetRotation(m_pBody->GetRotation());
|
|
}
|
|
|
|
void CPhysicsProp::SetAbsOrigin( Vector origin )
|
|
{
|
|
BaseClass::SetAbsOrigin( origin );
|
|
if (m_pBody)
|
|
m_pBody->SetPosition(m_pBody->GetPosition());
|
|
}
|
|
|
|
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, k_EPhysics_Dynamic);
|
|
m_pBody->SetPosition({0,0,0});
|
|
m_pBody->SetRotation({0,0,0});
|
|
}
|
|
|
|
void CPhysicsProp::EnableMovement()
|
|
{
|
|
|
|
}
|
|
|
|
void CPhysicsProp::DisableMovement()
|
|
{
|
|
|
|
}
|
|
BEGIN_DATADESC(CPhysicsProp)
|
|
DEFINE_KEYFIELD(m_ePhysicsType, FIELD_INTEGER, "physics_type")
|
|
END_DATADESC()
|
|
|
|
LINK_ENTITY_TO_CLASS(prop_physics, CPhysicsProp)
|