improve rendering and physics

This commit is contained in:
2026-03-18 18:41:28 +02:00
parent 0a506f7185
commit b56d85f95d
33 changed files with 141 additions and 82 deletions

View File

@@ -1,6 +1,11 @@
#include "physicsprop.h"
#include "game.h"
CPhysicsProp::CPhysicsProp()
{
SetAbsOrigin({0,0,0});
SetAbsQAngles(0,0,0);
}
void CPhysicsProp::Precache()
{
@@ -16,12 +21,17 @@ void CPhysicsProp::Spawn()
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());
}
V_printf("%f %f %f\n", GetAbsOrigin().x, GetAbsOrigin().y, GetAbsOrigin().z);
}
void CPhysicsProp::SetAbsAngles( Quat vQuat )
@@ -29,7 +39,7 @@ void CPhysicsProp::SetAbsAngles( Quat vQuat )
BaseClass::SetAbsAngles( vQuat );
if (m_pBody)
m_pBody->SetRotation(m_pBody->GetRotation());
m_pBody->SetRotation(GetAbsAngles());
}
void CPhysicsProp::SetAbsQAngles( float fPitch, float fYaw, float fRoll )
@@ -37,14 +47,14 @@ void CPhysicsProp::SetAbsQAngles( float fPitch, float fYaw, float fRoll )
BaseClass::SetAbsQAngles( fPitch, fYaw, fRoll);
if (m_pBody)
m_pBody->SetRotation(m_pBody->GetRotation());
m_pBody->SetRotation(GetAbsAngles());
}
void CPhysicsProp::SetAbsOrigin( Vector origin )
{
BaseClass::SetAbsOrigin( origin );
if (m_pBody)
m_pBody->SetPosition(m_pBody->GetPosition());
m_pBody->SetPosition(GetAbsOrigin());
}
void CPhysicsProp::OnModelChanged( const char *szName )
@@ -57,9 +67,16 @@ void CPhysicsProp::OnModelChanged( const char *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});
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()
@@ -71,6 +88,13 @@ void CPhysicsProp::DisableMovement()
{
}
void CPhysicsProp::SetPhysics( EPhysicsBodyType eType )
{
m_eCurrentPhysicsType = eType;
}
BEGIN_DATADESC(CPhysicsProp)
DEFINE_KEYFIELD(m_ePhysicsType, FIELD_INTEGER, "physics_type")
END_DATADESC()