physics
This commit is contained in:
@@ -47,6 +47,7 @@ void engine_build(struct build_data b)
|
||||
.include_dirs = include_dirs,
|
||||
});
|
||||
add_item(&o.files, tier1_lib);
|
||||
add_item(&o.files, rapierLib);
|
||||
|
||||
char* libs[] = {
|
||||
"c",
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "brush.h"
|
||||
#include "physics.h"
|
||||
#include "rendering.h"
|
||||
#include "tier0/platform.h"
|
||||
#include "tier1/utlbuffer.h"
|
||||
#include "tier1/utlvector.h"
|
||||
|
||||
void CBrushEntity::Precache()
|
||||
@@ -10,7 +12,32 @@ void CBrushEntity::Precache()
|
||||
|
||||
void CBrushEntity::Spawn()
|
||||
{
|
||||
CUtlBuffer<uint32_t> indicies(m_mesh.GetSize()*3);
|
||||
for (uint32_t i = 0;i<indicies.GetSize();i++)
|
||||
{
|
||||
indicies[i]=i;
|
||||
}
|
||||
CUtlBuffer<Point<float>> triangles(m_mesh.GetSize()*3);
|
||||
uint32_t i = 0;
|
||||
for (auto tri: m_mesh)
|
||||
{
|
||||
V_memcpy(&triangles[i],tri.location,36);
|
||||
i+=1;
|
||||
}
|
||||
V_printf("indicides %i\n",indicies.GetSize());
|
||||
V_printf("vertices %i\n",triangles.GetSize());
|
||||
|
||||
px_collider_params params = {};
|
||||
params.friction = 0;
|
||||
m_collider = px_trimesh((Point<float>*)triangles.GetMemory(), triangles.GetSize(), (uint32_t(*)[3])indicies.GetMemory(), indicies.GetSize()/3 ,params);
|
||||
px_matrix mat = {};
|
||||
mat.m[0] = 1;
|
||||
mat.m[4] = 1;
|
||||
mat.m[9] = 1;
|
||||
mat.m[15] = 1;
|
||||
px_rigidbody_params param = {};
|
||||
param.gravity_scale = 1;
|
||||
m_body = px_staticbody(px, m_collider, mat);
|
||||
};
|
||||
|
||||
void CBrushEntity::Destroy()
|
||||
@@ -19,7 +46,6 @@ void CBrushEntity::Destroy()
|
||||
}
|
||||
void CBrushEntity::Think( float fDelta )
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ void ConVar::InstallChangeCallback( ConCommandFn )
|
||||
|
||||
float ConVar::GetFloat( void )
|
||||
{
|
||||
|
||||
return m_fValue;
|
||||
}
|
||||
int ConVar::GetInt( void )
|
||||
{
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "engine.h"
|
||||
#include "baseentity.h"
|
||||
#include "server.h"
|
||||
#include "physics.h"
|
||||
|
||||
#ifdef __linux
|
||||
#include "signal.h"
|
||||
@@ -48,6 +49,8 @@ void IEngine_Signal(int sig)
|
||||
_exit(0);
|
||||
};
|
||||
|
||||
funnyphysics *px;
|
||||
|
||||
void IEngine::Init()
|
||||
{
|
||||
/* trap signals */
|
||||
@@ -66,6 +69,7 @@ void IEngine::Init()
|
||||
|
||||
IFileSystem::InitFilesystem();
|
||||
IVideo::Init();
|
||||
px = px_init();
|
||||
IServer::LoadGame("funnygame");
|
||||
};
|
||||
|
||||
|
||||
@@ -70,7 +70,6 @@ void ILevel::LoadLevel( const char *szLevelName )
|
||||
continue;
|
||||
}
|
||||
pBrush->m_mesh = CUtlVector<Triangle_t>(0);
|
||||
V_printf("%i\n",pBrush->m_mesh.GetSize());
|
||||
for ( uint32_t j = 0; j<pEntityHeader->nTriangles; j++ )
|
||||
{
|
||||
Triangle_t triangle = {};
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "tier1/utlstring.h"
|
||||
#include "baseentity.h"
|
||||
#include "console.h"
|
||||
#include "physics.h"
|
||||
|
||||
void *g_serverdll;
|
||||
|
||||
@@ -20,15 +21,16 @@ float g_fAccumulator = 0;
|
||||
void IServer::Think( float fDelta )
|
||||
{
|
||||
g_fAccumulator += fDelta;
|
||||
float fTickrate = 1.0/g_tickrate.GetInt();
|
||||
float fTickrate = 1.0/g_tickrate.GetFloat();
|
||||
/* tickrate */
|
||||
while(g_fAccumulator>=fTickrate)
|
||||
{
|
||||
g_fAccumulator-=fTickrate;
|
||||
for (auto &entity: g_entities)
|
||||
{
|
||||
entity->Think(fTickrate);
|
||||
g_fAccumulator-=fTickrate;
|
||||
}
|
||||
px_frame(px, fTickrate);
|
||||
}
|
||||
for (auto &entity: g_entities)
|
||||
{
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
#include "baseentity.h"
|
||||
#include "cglm/mat4.h"
|
||||
#include "physics.h"
|
||||
#include "cglm/cglm.h"
|
||||
|
||||
class CLight: public CBaseEntity
|
||||
{
|
||||
@@ -6,7 +9,10 @@ public:
|
||||
virtual void Precache ( void ) override;
|
||||
virtual void Spawn( void ) override;
|
||||
virtual void Destroy( void ) override;
|
||||
virtual void Think( float fDelta ) override;
|
||||
virtual void Think( float fDelta ) override;
|
||||
private:
|
||||
Collider* col;
|
||||
RigidBodyHandle *m_body;
|
||||
};
|
||||
|
||||
void CLight::Precache()
|
||||
@@ -16,7 +22,19 @@ void CLight::Precache()
|
||||
|
||||
void CLight::Spawn()
|
||||
{
|
||||
|
||||
px_collider_params params = {};
|
||||
params.friction = 0;
|
||||
col = px_box(1, 1, 1, params);
|
||||
px_matrix mat = {};
|
||||
mat.m[0] = 1;
|
||||
mat.m[4] = 1;
|
||||
mat.m[9] = 1;
|
||||
mat.m[15] = 1;
|
||||
mat.m[3]=-10;
|
||||
mat.m[11]=10;
|
||||
px_rigidbody_params param = {};
|
||||
param.gravity_scale = 1;
|
||||
m_body=px_rigidbody(px, col, mat, param);
|
||||
};
|
||||
|
||||
void CLight::Destroy()
|
||||
@@ -25,7 +43,8 @@ void CLight::Destroy()
|
||||
}
|
||||
void CLight::Think( float fDelta )
|
||||
{
|
||||
|
||||
px_vec3 pos = px_getposition(px, m_body);
|
||||
V_printf("%p %f %f %f\n",col, pos.m[0], pos.m[1], pos.m[2]);
|
||||
};
|
||||
|
||||
DECLARE_ENTITY(light, CLight)
|
||||
|
||||
@@ -12,21 +12,21 @@ public:
|
||||
|
||||
void CWorldSpawn::Precache()
|
||||
{
|
||||
|
||||
CBrushEntity::Precache();
|
||||
}
|
||||
|
||||
void CWorldSpawn::Spawn()
|
||||
{
|
||||
|
||||
CBrushEntity::Spawn();
|
||||
};
|
||||
|
||||
void CWorldSpawn::Destroy()
|
||||
{
|
||||
|
||||
CBrushEntity::Destroy();
|
||||
}
|
||||
void CWorldSpawn::Think( float fDelta )
|
||||
{
|
||||
|
||||
CBrushEntity::Think(fDelta);
|
||||
};
|
||||
|
||||
DECLARE_ENTITY(worldspawn, CWorldSpawn)
|
||||
|
||||
@@ -168,6 +168,7 @@ void IBrushRenderer::Frame( float fDelta )
|
||||
glm_perspective(glm_rad(90),(float)g_nWindowWidth/g_nWindowHeight, 0.01, 100, g_brushProject->projection);
|
||||
glm_rotate(g_brushProject->projection, glm_rad(90), (vec4){1,0,0,0});
|
||||
glm_scale(g_brushProject->projection, (vec4){1,-1,1,1});
|
||||
glm_rotate(g_brushProject->projection, glm_rad(-90), (vec4){0,0,1,0});
|
||||
if (g_bConfigNotify)
|
||||
{
|
||||
meshdepth.Destroy();
|
||||
@@ -199,7 +200,7 @@ void IBrushRenderer::Frame( float fDelta )
|
||||
{
|
||||
CTexture *texture = (CTexture*)t;
|
||||
VkDescriptorImageInfo image = {};
|
||||
image.imageLayout = VK_IMAGE_LAYOUT_GENERAL;
|
||||
image.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
|
||||
image.imageView = texture->image.m_imageView;
|
||||
image.sampler = g_brushSampler;
|
||||
textures.AppendTail(image);
|
||||
|
||||
@@ -231,6 +231,9 @@ void IVideo::Init()
|
||||
|
||||
/* select one in vk_gpu */
|
||||
g_vkPhysicalDevice = PhysicalDevices[vulkan_gpu.GetInt()];
|
||||
VkPhysicalDeviceProperties Properties = {};
|
||||
vkGetPhysicalDeviceProperties(g_vkPhysicalDevice, &Properties);
|
||||
V_printf("Using %s\n", Properties.deviceName);
|
||||
|
||||
/* queue family */
|
||||
uint32_t nNumQueueFamilies = 0;
|
||||
|
||||
Reference in New Issue
Block a user