controllers done i guess

This commit is contained in:
2026-06-15 16:11:55 +03:00
parent c51080a903
commit 900b12a6a6
14 changed files with 206 additions and 48 deletions

View File

@@ -26,10 +26,9 @@ void C_MOBAPlayer::Think( float fDelta )
if (pPlayerEntity == this)
{
}
m_pLeftHand = (C_MOBAPlayerHandController*)EntitySystem()->GetEntities()[m_leftHandId];
m_pRightHand = (C_MOBAPlayerHandController*)EntitySystem()->GetEntities()[m_rightHandId];
m_pLeftHand = (C_MOBAPlayerHandController*)EntitySystem()->GetEntityByIndex(m_leftHandId);
m_pRightHand = (C_MOBAPlayerHandController*)EntitySystem()->GetEntityByIndex(m_rightHandId);
BaseClass::Think(fDelta);
V_printf("device: %p %p\n", m_pLeftHand, m_pRightHand );
};
LINK_ENTITY_TO_CLASS(player, C_MOBAPlayer)
@@ -161,6 +160,14 @@ void Game_OnGameAxisDiff( EInputDeviceType eDevice, EInputAxis eAxis, float fVal
void C_MOBAPlayerHandController::Precache()
{
m_hNormal = g_pAssetManager->LoadModel("game/core/models/hand.fmdl");
m_pNormalModel = g_pAssetManager->GetModelByIndex(m_hNormal);
m_hSqueezed = g_pAssetManager->LoadModel("game/core/models/sphere.fmdl");
m_pSqueezedModel = g_pAssetManager->GetModelByIndex(m_hSqueezed);
m_pModel = m_pNormalModel;
m_pMesh = g_pAssetManager->GetMeshByIndex(m_pModel->m_hMesh)->m_pMesh;
m_pInstance = g_pWorldRenderer->CreateInstance(m_pMesh);
}
@@ -172,10 +179,45 @@ void C_MOBAPlayerHandController::Spawn()
void C_MOBAPlayerHandController::Think( float fDelta )
{
V_printf("controller: %p %f %f %f\n", this, m_vDesiredHandPosition.x, m_vDesiredHandPosition.y, m_vDesiredHandPosition.z );
SetAbsOrigin(m_vDesiredHandPosition);
BaseClass::Think(fDelta);
};
if (m_fSqueeze != m_fPreviousSqueeze)
{
if (m_fSqueeze > 0.5 && m_fPreviousSqueeze > 0.5)
goto draw;
if (m_fSqueeze <= 0.5 && m_fPreviousSqueeze <= 0.5)
goto draw;
if (m_pInstance)
g_pWorldRenderer->DestroyMeshInstance(m_pMesh, m_pInstance);
if (m_fSqueeze > 0.5)
m_pModel = m_pSqueezedModel;
else
m_pModel = m_pNormalModel;
m_pMesh = g_pAssetManager->GetMeshByIndex(m_pModel->m_hMesh)->m_pMesh;
m_pInstance = g_pWorldRenderer->CreateInstance(m_pMesh);
}
draw:
if (m_pInstance)
{
CBaseMaterial *pMat = g_pAssetManager->GetMaterialByIndex(m_pModel->m_hMaterial)->m_pLayout;
m_pInstance->SetPosition(m_vDesiredHandPosition);
m_pInstance->SetRotation(m_vDesiredHandRotation);
m_pInstance->SetScale({0.025, 0.025, 0.025});
m_pInstance->SetMaterial(pMat);
}
m_fPreviousSqueeze = m_fSqueeze;
}
C_MOBAPlayerHandController::~C_MOBAPlayerHandController()
{
if (m_pInstance)
g_pWorldRenderer->DestroyMeshInstance(m_pMesh, m_pInstance);
g_pAssetManager->UnrefModel(m_hNormal);
g_pAssetManager->UnrefModel(m_hSqueezed);
}
LINK_ENTITY_TO_CLASS(player_hand_controller, C_MOBAPlayerHandController)
@@ -208,11 +250,19 @@ void XRInputCallback( IXRController *pController, EXRInputType_t eType, const ch
if (pCon == NULL)
return;
switch (action)
{
case k_EXRInputAction_Pose:
pCon->m_vDesiredHandPosition = value.pose.pos;
V_printf("callback: %p %f %f %f\n", pCon, pCon->m_vDesiredHandPosition.x, pCon->m_vDesiredHandPosition.y, pCon->m_vDesiredHandPosition.z );
switch (eType) {
case k_EXRInput_Grip:
if (action == k_EXRInputAction_Pose)
{
pCon->m_vDesiredHandPosition = value.pose.pos;
pCon->m_vDesiredHandRotation = value.pose.rot;
}
break;
case k_EXRInput_Squeeze:
if (action == k_EXRInputAction_Value)
{
pCon->m_fSqueeze = value.f32.value;
}
break;
default:
break;

View File

@@ -3,19 +3,32 @@
#define MILMOBA_PLAYER_H
#include "basemodelentity.h"
class C_MOBAPlayerHandController: public C_BaseModelEntity
class C_MOBAPlayerHandController: public C_BaseEntity
{
public:
DECLARE_CLASS(C_MOBAPlayerHandController, C_BaseModelEntity);
DECLARE_CLASS(C_MOBAPlayerHandController, C_BaseEntity);
DECLARE_DATADESC();
DECLARE_CLIENTCLASS();
virtual void Precache ( void ) override;
virtual void Spawn( void ) override;
void Think( float fDelta );
virtual ~C_MOBAPlayerHandController() override;
Vector m_vDesiredHandPosition = {};
Quat m_vDesiredHandRotation = {};
float m_fPreviousSqueeze = 0;
float m_fSqueeze = 0;
HFunnyModel m_hNormal = NULL;
FunnyModel_t *m_pNormalModel = NULL;
HFunnyModel m_hSqueezed = NULL;
FunnyModel_t *m_pSqueezedModel = NULL;
FunnyModel_t *m_pModel = NULL;
IMesh *m_pMesh = NULL;
IMeshInstance *m_pInstance = NULL;
};
class C_MOBAPlayer: public C_BaseModelEntity
@@ -45,10 +58,10 @@ public:
Vector m_vLocalMovementVector;
Vector vCameraPos;
C_MOBAPlayerHandController *m_pLeftHand;
int m_leftHandId = 0;
C_MOBAPlayerHandController *m_pRightHand;
int m_rightHandId = 0;
C_MOBAPlayerHandController *m_pLeftHand = NULL;
int m_leftHandId = EDICT_INDEX_UNDEFINED;
C_MOBAPlayerHandController *m_pRightHand = NULL;
int m_rightHandId = EDICT_INDEX_UNDEFINED;
};