118 lines
2.7 KiB
C++
118 lines
2.7 KiB
C++
#include "baseplayer.h"
|
|
#include "cglm/affine-pre.h"
|
|
#include "cglm/mat4.h"
|
|
#include "engine.h"
|
|
#include "rendering.h"
|
|
#include "input.h"
|
|
#include "fgui/widget.h"
|
|
#include "fgui/rect.h"
|
|
#include "fgui/label.h"
|
|
#include "mesh.h"
|
|
|
|
class C_MOBAPlayer: public C_BaseEntity
|
|
{
|
|
public:
|
|
virtual void Precache ( void ) override;
|
|
virtual void Spawn( void ) override;
|
|
virtual void Destroy( void ) override;
|
|
virtual void Think( float fDelta ) override;
|
|
|
|
IMesh *m_pMesh;
|
|
IMeshInstance *m_pMeshInstance;
|
|
};
|
|
|
|
void C_MOBAPlayer::Precache()
|
|
{
|
|
}
|
|
|
|
void C_MOBAPlayer::Spawn()
|
|
{
|
|
float cubeVertices[] = {
|
|
// Front face
|
|
-0.1f, -0.1f, 0.1f, 0, 0,
|
|
0.1f, -0.1f, 0.1f, 1, 0,
|
|
0.1f, 0.1f, 0.1f, 1, 1,
|
|
-0.1f, -0.1f, 0.1f, 0, 0,
|
|
0.1f, 0.1f, 0.1f, 1, 1,
|
|
-0.1f, 0.1f, 0.1f, 0, 1,
|
|
|
|
// Back face
|
|
0.1f, -0.1f, -0.1f, 0, 0,
|
|
-0.1f, -0.1f, -0.1f, 1, 0,
|
|
-0.1f, 0.1f, -0.1f, 1, 1,
|
|
0.1f, -0.1f, -0.1f, 0, 0,
|
|
-0.1f, 0.1f, -0.1f, 1, 1,
|
|
0.1f, 0.1f, -0.1f, 0, 1,
|
|
|
|
// Left face
|
|
-0.1f, -0.1f, -0.1f, 0, 0,
|
|
-0.1f, -0.1f, 0.1f, 1, 0,
|
|
-0.1f, 0.1f, 0.1f, 1, 1,
|
|
-0.1f, -0.1f, -0.1f, 0, 0,
|
|
-0.1f, 0.1f, 0.1f, 1, 1,
|
|
-0.1f, 0.1f, -0.1f, 0, 1,
|
|
|
|
// Right face
|
|
0.1f, -0.1f, 0.1f, 0, 0,
|
|
0.1f, -0.1f, -0.1f, 1, 0,
|
|
0.1f, 0.1f, -0.1f, 1, 1,
|
|
0.1f, -0.1f, 0.1f, 0, 0,
|
|
0.1f, 0.1f, -0.1f, 1, 1,
|
|
0.1f, 0.1f, 0.1f, 0, 1,
|
|
|
|
// Top face
|
|
-0.1f, 0.1f, 0.1f, 0, 0,
|
|
0.1f, 0.1f, 0.1f, 1, 0,
|
|
0.1f, 0.1f, -0.1f, 1, 1,
|
|
-0.1f, 0.1f, 0.1f, 0, 0,
|
|
0.1f, 0.1f, -0.1f, 1, 1,
|
|
-0.1f, 0.1f, -0.1f, 0, 1,
|
|
|
|
// Bottom face
|
|
-0.1f, -0.1f, -0.1f, 0, 0,
|
|
0.1f, -0.1f, -0.1f, 1, 0,
|
|
0.1f, -0.1f, 0.1f, 1, 1,
|
|
-0.1f, -0.1f, -0.1f, 0, 0,
|
|
0.1f, -0.1f, 0.1f, 1, 1,
|
|
-0.1f, -0.1f, 0.1f, 0, 1
|
|
};
|
|
|
|
IVertexBuffer *pVertexBuffer = Renderer()->CreateVertexBuffer(sizeof(cubeVertices));
|
|
void *pMapping = pVertexBuffer->Map();
|
|
V_memcpy(pMapping, cubeVertices, sizeof(cubeVertices));
|
|
pVertexBuffer->Unmap();
|
|
|
|
m_pMesh = IMeshRendering::CreateMesh();
|
|
m_pMesh->SetVertexBuffer(0, pVertexBuffer);
|
|
m_pMeshInstance = m_pMesh->CreateInstance();
|
|
|
|
};
|
|
|
|
void C_MOBAPlayer::Destroy()
|
|
{
|
|
|
|
}
|
|
void C_MOBAPlayer::Think( float fDelta )
|
|
{
|
|
float x = g_fAxisValues[AXIS_MOUSE_X];
|
|
float y = g_fAxisValues[AXIS_MOUSE_Y];
|
|
float fPitch = glm_rad(x);
|
|
float fYaw = glm_rad(y);
|
|
if (g_localClient->pBasePlayer == pEntity)
|
|
{
|
|
glm_mat4_identity(g_cameraView);
|
|
glm_rotate_z(g_cameraView, fYaw, g_cameraView);
|
|
glm_rotate_y(g_cameraView, fPitch, g_cameraView);
|
|
g_cameraView[3][0] = pEntity->m_position[0];
|
|
g_cameraView[3][1] = pEntity->m_position[1];
|
|
g_cameraView[3][2] = pEntity->m_position[2]+0.7;
|
|
}
|
|
mat4 m;
|
|
glm_mat4_identity(m);
|
|
m_pMeshInstance->SetMatrix(m);
|
|
m_pMeshInstance->SetPosition(pEntity->m_position);
|
|
m_pMeshInstance->Draw();
|
|
};
|
|
|
|
LINK_CLIENT_ENTITY(C_MOBAPlayer, CMOBAPlayer)
|