work on openxr controllers
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#include "netprotocol.h"
|
||||
#include "userinput.h"
|
||||
#include "math.h"
|
||||
#include "cglm/euler.h"
|
||||
#ifdef STEAM
|
||||
#include "steam/isteamgameserver.h"
|
||||
#include "steam/steam_gameserver.h"
|
||||
@@ -36,6 +37,9 @@ IEngineBridge *EngineBridge()
|
||||
return &s_bridge;
|
||||
}
|
||||
|
||||
void XRInputCallback( IXRController *pController, EXRInputType_t eType, const char *szType, EXRInputActionType_t action, EXRInputValue_t value );
|
||||
|
||||
|
||||
EXPOSE_INTERFACE_FN(EngineBridge, IEngineBridge, ENGINE_BRIDGE_INTERFACE_VERSION)
|
||||
|
||||
void CFunnyGameBridge::Init()
|
||||
@@ -101,6 +105,11 @@ void CFunnyGameBridge::Init()
|
||||
g_pRenderContext->DestroyCommandList(pDoSomething);
|
||||
}
|
||||
}
|
||||
for ( uint32_t i = 0; i < pHeadSet->GetControllerCount(); i++ )
|
||||
{
|
||||
pHeadSet->GetController(i)->SetInputCallback(XRInputCallback);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void CFunnyGameBridge::Tick( float fDelta )
|
||||
@@ -145,6 +154,17 @@ void CFunnyGameBridge::Frame( float fDelta )
|
||||
|
||||
TryToConnectToServer();
|
||||
|
||||
|
||||
g_pXRManager->Frame();
|
||||
|
||||
IXRHeadset *pHeadSet = g_pXRManager->GetHeadset(0);
|
||||
if (pHeadSet) {
|
||||
XRRenderSurface_t s = pHeadSet->GetSurface(0);
|
||||
g_pWorldRenderer->SetCameraPosition(s.m_vPosition);
|
||||
V_printf("%f\n", s.m_vPosition.y);
|
||||
g_pWorldRenderer->SetCameraRotation(s.m_vRotation);
|
||||
}
|
||||
|
||||
INetworkBase *pCurrentServer = g_pServerBridge;
|
||||
pCurrentServer = g_pServerBridge;
|
||||
if (m_bIsConnectedToServer)
|
||||
@@ -197,8 +217,6 @@ void CFunnyGameBridge::Frame( float fDelta )
|
||||
EntitySystem()->NetSendThink(pCurrentServer);
|
||||
}
|
||||
g_pWorldRenderer->Frame(fDelta);
|
||||
|
||||
g_pXRManager->Frame();
|
||||
}
|
||||
|
||||
void CFunnyGameBridge::Shutdown()
|
||||
|
||||
@@ -25,16 +25,11 @@ void C_MOBAPlayer::Think( float fDelta )
|
||||
|
||||
if (pPlayerEntity == this)
|
||||
{
|
||||
Vector vCameraPos;
|
||||
vCameraPos = GetAbsOrigin();
|
||||
vCameraPos.z = 20;
|
||||
vCameraPos.y+=3;
|
||||
g_pWorldRenderer->SetCameraPosition(vCameraPos);
|
||||
Quat vCameraRot;
|
||||
glm_euler_yxz_quat((vec3){m_fPitch, m_fYaw, 0}, *(versor*)&vCameraRot);
|
||||
g_pWorldRenderer->SetCameraRotation(vCameraRot);
|
||||
}
|
||||
m_pLeftHand = (C_MOBAPlayerHandController*)EntitySystem()->GetEntities()[m_leftHandId];
|
||||
m_pRightHand = (C_MOBAPlayerHandController*)EntitySystem()->GetEntities()[m_rightHandId];
|
||||
BaseClass::Think(fDelta);
|
||||
V_printf("device: %p %p\n", m_pLeftHand, m_pRightHand );
|
||||
};
|
||||
|
||||
LINK_ENTITY_TO_CLASS(player, C_MOBAPlayer)
|
||||
@@ -43,6 +38,8 @@ BEGIN_DATADESC(C_MOBAPlayer)
|
||||
END_DATADESC()
|
||||
|
||||
IMPLEMENT_RECV_DT(C_MOBAPlayer)
|
||||
NetPropInt(m_leftHandId),
|
||||
NetPropInt(m_rightHandId),
|
||||
END_RECV_DT()
|
||||
|
||||
IMPLEMENT_SEND_DT(C_MOBAPlayer)
|
||||
@@ -162,3 +159,63 @@ void Game_OnGameAxisDiff( EInputDeviceType eDevice, EInputAxis eAxis, float fVal
|
||||
}
|
||||
|
||||
|
||||
void C_MOBAPlayerHandController::Precache()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void C_MOBAPlayerHandController::Spawn()
|
||||
{
|
||||
BaseClass::Spawn();
|
||||
SetThink(Think);
|
||||
};
|
||||
|
||||
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);
|
||||
};
|
||||
|
||||
LINK_ENTITY_TO_CLASS(player_hand_controller, C_MOBAPlayerHandController)
|
||||
|
||||
BEGIN_DATADESC(C_MOBAPlayerHandController)
|
||||
END_DATADESC()
|
||||
|
||||
IMPLEMENT_RECV_DT(C_MOBAPlayerHandController)
|
||||
END_RECV_DT()
|
||||
|
||||
IMPLEMENT_SEND_DT(C_MOBAPlayerHandController)
|
||||
END_SEND_DT()
|
||||
|
||||
void XRInputCallback( IXRController *pController, EXRInputType_t eType, const char *szType, EXRInputActionType_t action, EXRInputValue_t value )
|
||||
{
|
||||
|
||||
C_BaseEntity *pPlayer = UTIL_GetLocalPlayer();
|
||||
if (!pPlayer)
|
||||
return;
|
||||
if (!dynamic_cast<C_MOBAPlayer*>(pPlayer))
|
||||
return;
|
||||
C_MOBAPlayer *p = (C_MOBAPlayer*)pPlayer;
|
||||
C_MOBAPlayerHandController *pCon = NULL;
|
||||
|
||||
if (pController->GetControllerSide() == k_EXRController_Left)
|
||||
pCon = p->m_pLeftHand;
|
||||
|
||||
if (pController->GetControllerSide() == k_EXRController_Right)
|
||||
pCon = p->m_pRightHand;
|
||||
|
||||
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 );
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,20 @@
|
||||
#define MILMOBA_PLAYER_H
|
||||
#include "basemodelentity.h"
|
||||
|
||||
class C_MOBAPlayerHandController: public C_BaseModelEntity
|
||||
{
|
||||
public:
|
||||
DECLARE_CLASS(C_MOBAPlayerHandController, C_BaseModelEntity);
|
||||
DECLARE_DATADESC();
|
||||
DECLARE_CLIENTCLASS();
|
||||
|
||||
virtual void Precache ( void ) override;
|
||||
virtual void Spawn( void ) override;
|
||||
void Think( float fDelta );
|
||||
|
||||
Vector m_vDesiredHandPosition = {};
|
||||
Quat m_vDesiredHandRotation = {};
|
||||
};
|
||||
|
||||
class C_MOBAPlayer: public C_BaseModelEntity
|
||||
{
|
||||
@@ -30,6 +44,12 @@ public:
|
||||
Vector m_vMovementVector;
|
||||
Vector m_vLocalMovementVector;
|
||||
Vector vCameraPos;
|
||||
|
||||
C_MOBAPlayerHandController *m_pLeftHand;
|
||||
int m_leftHandId = 0;
|
||||
C_MOBAPlayerHandController *m_pRightHand;
|
||||
int m_rightHandId = 0;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user