fixes for physics
This commit is contained in:
@@ -117,6 +117,7 @@ extern "C" void FunnyMain( int argc, char **argv )
|
|||||||
SteamAPI_RunCallbacks();
|
SteamAPI_RunCallbacks();
|
||||||
#endif
|
#endif
|
||||||
double fCurrent = Plat_GetTime();
|
double fCurrent = Plat_GetTime();
|
||||||
|
double fStart = Plat_GetTime();
|
||||||
double fDelta = fCurrent-fPrevious;
|
double fDelta = fCurrent-fPrevious;
|
||||||
fPrevious = fCurrent;
|
fPrevious = fCurrent;
|
||||||
|
|
||||||
@@ -124,15 +125,23 @@ extern "C" void FunnyMain( int argc, char **argv )
|
|||||||
g_pHumanDeviceManager->Frame();
|
g_pHumanDeviceManager->Frame();
|
||||||
g_pServerGame->m_pBridge->Frame(fDelta);
|
g_pServerGame->m_pBridge->Frame(fDelta);
|
||||||
|
|
||||||
|
fCurrent = Plat_GetTime();
|
||||||
|
|
||||||
if (!stConstants.m_bIsDedicated)
|
if (!stConstants.m_bIsDedicated)
|
||||||
{
|
{
|
||||||
|
|
||||||
g_pWindowManager->Frame(fDelta);
|
g_pWindowManager->Frame(fDelta);
|
||||||
g_pClientGame->m_pBridge->Frame(fDelta);
|
g_pClientGame->m_pBridge->Frame(fDelta);
|
||||||
g_pRenderContext->Frame(fDelta);
|
g_pRenderContext->Frame(fDelta);
|
||||||
|
|
||||||
|
fCurrent = Plat_GetTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
Console()->Execute();
|
Console()->Execute();
|
||||||
|
|
||||||
|
|
||||||
|
fCurrent = Plat_GetTime();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
2
external/GameNetworkingSockets
vendored
2
external/GameNetworkingSockets
vendored
Submodule external/GameNetworkingSockets updated: 725e273c74...517fff0cf6
2
external/SDL
vendored
2
external/SDL
vendored
Submodule external/SDL updated: 7c11a8cb9f...1d081314a8
2
external/Vulkan-Headers
vendored
2
external/Vulkan-Headers
vendored
Submodule external/Vulkan-Headers updated: 2e0a6e699e...29184b9898
2
external/Vulkan-Utility-Libraries
vendored
2
external/Vulkan-Utility-Libraries
vendored
Submodule external/Vulkan-Utility-Libraries updated: 4f4c0b6c61...c15a1ac316
2
external/VulkanMemoryAllocator
vendored
2
external/VulkanMemoryAllocator
vendored
Submodule external/VulkanMemoryAllocator updated: f0969e908b...b3cbbb43ea
2
external/cglm
vendored
2
external/cglm
vendored
Submodule external/cglm updated: a886d6e170...83d5b2c973
2
external/slang
vendored
2
external/slang
vendored
Submodule external/slang updated: 5d775e2829...f267cb77a0
2
external/stb
vendored
2
external/stb
vendored
Submodule external/stb updated: 802cd454f2...e6cd9561ea
2
external/volk
vendored
2
external/volk
vendored
Submodule external/volk updated: d64d20b4ea...e91ceff7db
2
external/xtool
vendored
2
external/xtool
vendored
Submodule external/xtool updated: 22655f3e70...f12a84e960
@@ -1,4 +1,4 @@
|
|||||||
{
|
{
|
||||||
"Type": "Triangles",
|
"Type": "TriangleMesh",
|
||||||
"Mesh": "game/core/maps/test/test0.fpx"
|
"Mesh": "game/core/maps/test/test0.fmesh_c"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -155,6 +155,8 @@ void CFunnyGameBridge::Frame( float fDelta )
|
|||||||
|
|
||||||
float fTickRate = 1.0/60.0;
|
float fTickRate = 1.0/60.0;
|
||||||
m_fNetUpdateTimer += fDelta;
|
m_fNetUpdateTimer += fDelta;
|
||||||
|
if (m_fNetUpdateTimer >= fTickRate)
|
||||||
|
m_fNetUpdateTimer = fTickRate;
|
||||||
while (m_fNetUpdateTimer >= fTickRate)
|
while (m_fNetUpdateTimer >= fTickRate)
|
||||||
{
|
{
|
||||||
m_fNetUpdateTimer-=fTickRate;
|
m_fNetUpdateTimer-=fTickRate;
|
||||||
|
|||||||
@@ -93,6 +93,7 @@ public:
|
|||||||
virtual void UnrefPhysics( HFunnyPhysics hPhysics ) override;
|
virtual void UnrefPhysics( HFunnyPhysics hPhysics ) override;
|
||||||
|
|
||||||
CAssetArc<FunnyModel_t, MAX_MODEL_COUNT> m_models = {};
|
CAssetArc<FunnyModel_t, MAX_MODEL_COUNT> m_models = {};
|
||||||
|
CAssetArc<FunnyMesh_t, MAX_MODEL_COUNT> m_meshes = {};
|
||||||
CAssetArc<FunnyPhysics_t, MAX_PHYSICS_COUNT> m_physics = {};
|
CAssetArc<FunnyPhysics_t, MAX_PHYSICS_COUNT> m_physics = {};
|
||||||
|
|
||||||
};
|
};
|
||||||
@@ -108,6 +109,7 @@ FunnyMaterial_t *CAssetManager::GetMaterialByIndex( uint32_t uIndex )
|
|||||||
|
|
||||||
FunnyMesh_t *CAssetManager::GetMeshByIndex( uint32_t uIndex )
|
FunnyMesh_t *CAssetManager::GetMeshByIndex( uint32_t uIndex )
|
||||||
{
|
{
|
||||||
|
return m_meshes.GetObjectPtr(uIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -179,7 +181,30 @@ HFunnyMesh CAssetManager::LoadMesh( const char *szName )
|
|||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool bHasBeenCreated = false;
|
||||||
|
HFunnyMesh hAsset = m_meshes.GetOrCreateObject(szName, &bHasBeenCreated);
|
||||||
|
if (!bHasBeenCreated)
|
||||||
|
return hAsset;
|
||||||
|
FunnyMesh_t *pMesh = m_meshes.GetObjectPtr(hAsset);
|
||||||
|
|
||||||
|
IFileHandle *hMesh = filesystem->Open(szName, FILEMODE_READ);
|
||||||
|
if ( hMesh == NULL )
|
||||||
|
{
|
||||||
|
V_printf("Failed to load %s\n", szName);
|
||||||
|
m_meshes.UnrefObject(hAsset);
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
pMesh->m_nPositionCount = filesystem->Size(hMesh)/4;
|
||||||
|
pMesh->m_pfPositions = new float[pMesh->m_nPositionCount];
|
||||||
|
filesystem->Read( hMesh, pMesh->m_pfPositions, filesystem->Size(hMesh));
|
||||||
|
pMesh->m_nIndiciesCount = 0;
|
||||||
|
pMesh->m_puIndicies = 0;
|
||||||
|
|
||||||
|
|
||||||
|
return hAsset;
|
||||||
|
|
||||||
}
|
}
|
||||||
void CAssetManager::UnrefMesh( uint32_t uIndex )
|
void CAssetManager::UnrefMesh( uint32_t uIndex )
|
||||||
@@ -231,8 +256,25 @@ HFunnyPhysics CAssetManager::LoadPhysics( const char *szName )
|
|||||||
{
|
{
|
||||||
pPhysics->m_hShape = g_pPhysics->CreateBall({1.0});
|
pPhysics->m_hShape = g_pPhysics->CreateBall({1.0});
|
||||||
}
|
}
|
||||||
if (szType == "Triangles")
|
if (szType == "TriangleMesh")
|
||||||
{
|
{
|
||||||
|
V_printf("hi\n");
|
||||||
|
IJSONValue *pMeshValue = pMainObject->GetValue("Mesh");
|
||||||
|
V_printf("hi\n");
|
||||||
|
if (!pMeshValue)
|
||||||
|
{
|
||||||
|
|
||||||
|
V_printf("\"Mesh\" must be specified\n");
|
||||||
|
m_physics.UnrefObject(hPhysics);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
CUtlString szMesh = pMeshValue->GetStringValue();
|
||||||
|
V_printf("%s\n", szMesh.GetString());
|
||||||
|
HFunnyMesh hMesh = LoadMesh(szMesh);
|
||||||
|
FunnyMesh_t *pMesh = GetMeshByIndex(hMesh);
|
||||||
|
pPhysics->m_hShape = g_pPhysics->CreateTriangleMesh({pMesh->m_pfPositions, pMesh->m_nPositionCount});
|
||||||
|
V_printf("%p\n", pPhysics->m_hShape);
|
||||||
|
pPhysics->m_hMesh = hMesh;
|
||||||
}
|
}
|
||||||
|
|
||||||
return hPhysics;
|
return hPhysics;
|
||||||
|
|||||||
@@ -16,11 +16,20 @@ struct FunnyMaterial_t
|
|||||||
|
|
||||||
struct FunnyMesh_t
|
struct FunnyMesh_t
|
||||||
{
|
{
|
||||||
|
float *m_pfPositions;
|
||||||
|
uint32_t m_nPositionCount;
|
||||||
|
uint32_t *m_puIndicies;
|
||||||
|
uint32_t m_nIndiciesCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct FunnyPhysics_t
|
struct FunnyPhysics_t
|
||||||
{
|
{
|
||||||
HShape m_hShape;
|
HShape m_hShape;
|
||||||
|
|
||||||
|
union
|
||||||
|
{
|
||||||
|
HFunnyMesh m_hMesh;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
struct FunnyModel_t
|
struct FunnyModel_t
|
||||||
|
|||||||
@@ -205,6 +205,8 @@ void CFunnyGameBridge::Frame( float fDelta )
|
|||||||
float fTickRate = 1.0/60.0;
|
float fTickRate = 1.0/60.0;
|
||||||
|
|
||||||
m_fNetUpdateTimer += fDelta;
|
m_fNetUpdateTimer += fDelta;
|
||||||
|
if (m_fNetUpdateTimer >= 0.3)
|
||||||
|
m_fNetUpdateTimer = 0.3;
|
||||||
while (m_fNetUpdateTimer >= fTickRate)
|
while (m_fNetUpdateTimer >= fTickRate)
|
||||||
{
|
{
|
||||||
m_fNetUpdateTimer-=fTickRate;
|
m_fNetUpdateTimer-=fTickRate;
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ void CMOBAPlayer::Think( float fDelta )
|
|||||||
vPosition.x += m_vMovementVector.x*fDelta*5;
|
vPosition.x += m_vMovementVector.x*fDelta*5;
|
||||||
vPosition.z += m_vMovementVector.z*fDelta*5;
|
vPosition.z += m_vMovementVector.z*fDelta*5;
|
||||||
SetAbsOrigin(vPosition);
|
SetAbsOrigin(vPosition);
|
||||||
|
V_printf("player: %f %f %f\n", vPosition.x, vPosition.y, vPosition.z);
|
||||||
};
|
};
|
||||||
|
|
||||||
LINK_ENTITY_TO_CLASS(player, CMOBAPlayer)
|
LINK_ENTITY_TO_CLASS(player, CMOBAPlayer)
|
||||||
|
|||||||
@@ -11,8 +11,6 @@ void CPhysicsProp::Spawn()
|
|||||||
{
|
{
|
||||||
CBaseEntity::Spawn();
|
CBaseEntity::Spawn();
|
||||||
SetThink(Think);
|
SetThink(Think);
|
||||||
|
|
||||||
V_printf("hi\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPhysicsProp::Think( float fDelta )
|
void CPhysicsProp::Think( float fDelta )
|
||||||
@@ -60,6 +58,8 @@ void CPhysicsProp::OnModelChanged( const char *szName )
|
|||||||
m_pPhysics = g_pAssetManager->GetPhysicsByIndex(m_pModel->m_hPhysics);
|
m_pPhysics = g_pAssetManager->GetPhysicsByIndex(m_pModel->m_hPhysics);
|
||||||
m_hCollider = g_pPhysics->CreateCollider(m_pPhysics->m_hShape);
|
m_hCollider = g_pPhysics->CreateCollider(m_pPhysics->m_hShape);
|
||||||
m_pBody = g_pPhysicsWorld->CreateRigidBody(m_hCollider, k_EPhysics_Dynamic);
|
m_pBody = g_pPhysicsWorld->CreateRigidBody(m_hCollider, k_EPhysics_Dynamic);
|
||||||
|
m_pBody->SetPosition({0,0,0});
|
||||||
|
m_pBody->SetRotation({0,0,0});
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPhysicsProp::EnableMovement()
|
void CPhysicsProp::EnableMovement()
|
||||||
@@ -71,5 +71,8 @@ void CPhysicsProp::DisableMovement()
|
|||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
BEGIN_DATADESC(CPhysicsProp)
|
||||||
|
DEFINE_KEYFIELD(m_ePhysicsType, FIELD_INTEGER, "physics_type")
|
||||||
|
END_DATADESC()
|
||||||
|
|
||||||
LINK_ENTITY_TO_CLASS(prop_physics, CPhysicsProp)
|
LINK_ENTITY_TO_CLASS(prop_physics, CPhysicsProp)
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ class CPhysicsProp: public CBaseModelEntity
|
|||||||
friend CBaseEntity;
|
friend CBaseEntity;
|
||||||
friend CBaseModelEntity;
|
friend CBaseModelEntity;
|
||||||
public:
|
public:
|
||||||
DECLARE_CLASS(CPhysicsProp, CBaseModelEntity);
|
DECLARE_CLASS(CPhysicsProp, CBaseModelEntity)
|
||||||
|
DECLARE_DATADESC()
|
||||||
virtual void Spawn() override;
|
virtual void Spawn() override;
|
||||||
virtual void Precache() override;
|
virtual void Precache() override;
|
||||||
|
|
||||||
@@ -20,14 +21,18 @@ public:
|
|||||||
virtual void EnableMovement();
|
virtual void EnableMovement();
|
||||||
virtual void DisableMovement();
|
virtual void DisableMovement();
|
||||||
|
|
||||||
|
virtual void SetPhysics( EPhysicsBodyType eType );
|
||||||
|
|
||||||
void Think( float fDelta );
|
void Think( float fDelta );
|
||||||
private:
|
private:
|
||||||
EPhysicsBodyType m_ePhysicsType;
|
EPhysicsBodyType m_ePhysicsType;
|
||||||
|
EPhysicsBodyType m_eCurrentPhysicsType;
|
||||||
HFunnyModel m_hModel = 0;
|
HFunnyModel m_hModel = 0;
|
||||||
FunnyModel_t *m_pModel = NULL;
|
FunnyModel_t *m_pModel = NULL;
|
||||||
FunnyPhysics_t *m_pPhysics = NULL;
|
FunnyPhysics_t *m_pPhysics = NULL;
|
||||||
HCollider m_hCollider = 0;
|
HCollider m_hCollider = 0;
|
||||||
IPhysicsBody *m_pBody = NULL;
|
IPhysicsBody *m_pBody = NULL;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ struct CuboidShape_t
|
|||||||
float m_fExtentZ;
|
float m_fExtentZ;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TrianglesShape_t
|
struct TriangleMeshShape_t
|
||||||
{
|
{
|
||||||
float *m_pfPositions;
|
float *m_pfPositions;
|
||||||
uint32_t m_nPositionCount;
|
uint32_t m_nPositionCount;
|
||||||
@@ -45,6 +45,7 @@ public:
|
|||||||
virtual void SetRotation( Quat vRotation ) = 0;
|
virtual void SetRotation( Quat vRotation ) = 0;
|
||||||
virtual Vector GetPosition() = 0;
|
virtual Vector GetPosition() = 0;
|
||||||
virtual Quat GetRotation() = 0;
|
virtual Quat GetRotation() = 0;
|
||||||
|
virtual void SetType( EPhysicsBodyType eType ) = 0;
|
||||||
virtual void SetGravityScale( float fScale ) = 0;
|
virtual void SetGravityScale( float fScale ) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -66,7 +67,7 @@ abstract_class IPhysics
|
|||||||
public:
|
public:
|
||||||
virtual HShape CreateBall( BallShape_t ball ) = 0;
|
virtual HShape CreateBall( BallShape_t ball ) = 0;
|
||||||
virtual HShape CreateCube( CuboidShape_t ball ) = 0;
|
virtual HShape CreateCube( CuboidShape_t ball ) = 0;
|
||||||
virtual HShape CreateTriangles( TrianglesShape_t shape ) = 0;
|
virtual HShape CreateTriangleMesh( TriangleMeshShape_t shape ) = 0;
|
||||||
virtual void DestroyShape( HShape hShape ) = 0;
|
virtual void DestroyShape( HShape hShape ) = 0;
|
||||||
|
|
||||||
virtual HCollider CreateCollider( HShape hShape ) = 0;
|
virtual HCollider CreateCollider( HShape hShape ) = 0;
|
||||||
|
|||||||
@@ -17,11 +17,10 @@ DECLARE_BUILD_STAGE(rapier)
|
|||||||
CUtlString szTarget = target.GetTriplet();
|
CUtlString szTarget = target.GetTriplet();
|
||||||
if (CommandLine()->CheckParam("-norust"))
|
if (CommandLine()->CheckParam("-norust"))
|
||||||
return 0;
|
return 0;
|
||||||
rapier_lib = CUtlString("target/%s/release/librapier_rtt.a",szTarget.GetString());
|
rapier_lib = CUtlString("target/%s/debug/librapier_rtt.a",szTarget.GetString());
|
||||||
V_printf("%s\n",rapier_lib.GetString());
|
V_printf("%s\n",rapier_lib.GetString());
|
||||||
CUtlVector<CUtlString> cargo_args = {
|
CUtlVector<CUtlString> cargo_args = {
|
||||||
"build",
|
"build",
|
||||||
"--release",
|
|
||||||
"--target",
|
"--target",
|
||||||
szTarget
|
szTarget
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
//
|
//
|
||||||
//===========================================================================//
|
//===========================================================================//
|
||||||
|
|
||||||
|
#include "tier0/lib.h"
|
||||||
#include "physics.h"
|
#include "physics.h"
|
||||||
#define PHYSICS_OBJECT_DEFINED
|
#define PHYSICS_OBJECT_DEFINED
|
||||||
#define TRIG_H
|
#define TRIG_H
|
||||||
@@ -95,9 +96,9 @@ public:
|
|||||||
return CRapierPhysics_CreateCube(m_pRustHandle, ball);
|
return CRapierPhysics_CreateCube(m_pRustHandle, ball);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual HShape CreateTriangles( TrianglesShape_t shape ) override
|
virtual HShape CreateTriangleMesh( TriangleMeshShape_t shape ) override
|
||||||
{
|
{
|
||||||
return CRapierPhysics_CreateCube(m_pRustHandle, shape);
|
return CRapierPhysics_CreateTriangleMesh(m_pRustHandle, shape);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void DestroyShape( HShape hShape ) override
|
virtual void DestroyShape( HShape hShape ) override
|
||||||
|
|||||||
@@ -43,6 +43,13 @@ typedef struct CuboidShape_t {
|
|||||||
float m_fExtentZ;
|
float m_fExtentZ;
|
||||||
} CuboidShape_t;
|
} CuboidShape_t;
|
||||||
|
|
||||||
|
typedef struct TriangleMeshShape_t {
|
||||||
|
const float *m_pfPositions;
|
||||||
|
uint32_t m_nPositionCount;
|
||||||
|
const float *m_puIndicies;
|
||||||
|
uint32_t m_nIndiciesCount;
|
||||||
|
} TriangleMeshShape_t;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif // __cplusplus
|
#endif // __cplusplus
|
||||||
@@ -62,6 +69,8 @@ void CRapierPhysicsBody_SetRotation(struct RapierPhysicsBody_t *this_,
|
|||||||
float fZ,
|
float fZ,
|
||||||
float fW);
|
float fW);
|
||||||
|
|
||||||
|
void CRapierPhysicsBody_SetType(struct RapierPhysicsBody_t *this_, enum EPhysicsBodyType eType);
|
||||||
|
|
||||||
struct RapierPhysicsBody_t *CRapierPhysicsWorld_CreateRigidBody(struct RapierWorld_t *this_,
|
struct RapierPhysicsBody_t *CRapierPhysicsWorld_CreateRigidBody(struct RapierWorld_t *this_,
|
||||||
struct RapierCollider_t *pCollider,
|
struct RapierCollider_t *pCollider,
|
||||||
enum EPhysicsBodyType eType);
|
enum EPhysicsBodyType eType);
|
||||||
@@ -77,6 +86,9 @@ struct RapierCollider_t *CRapierPhysics_CreateCollider(struct RapierPhysics_t *t
|
|||||||
struct RapierShape_t *CRapierPhysics_CreateCube(struct RapierPhysics_t *this_,
|
struct RapierShape_t *CRapierPhysics_CreateCube(struct RapierPhysics_t *this_,
|
||||||
struct CuboidShape_t cuboid);
|
struct CuboidShape_t cuboid);
|
||||||
|
|
||||||
|
struct RapierShape_t *CRapierPhysics_CreateTriangleMesh(struct RapierPhysics_t *this_,
|
||||||
|
struct TriangleMeshShape_t triangle);
|
||||||
|
|
||||||
struct RapierWorld_t *CRapierPhysics_CreateWorld(struct RapierPhysics_t *this_);
|
struct RapierWorld_t *CRapierPhysics_CreateWorld(struct RapierPhysics_t *this_);
|
||||||
|
|
||||||
struct RapierPhysics_t *CRapierPhysics_New(void);
|
struct RapierPhysics_t *CRapierPhysics_New(void);
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ macro_rules! V_malloc {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
use std::{default, ptr::{self, null}, sync::Arc};
|
use std::{default, ops::Index, ptr::{self, null, null_mut}, slice::from_raw_parts, sync::Arc};
|
||||||
|
|
||||||
use parry3d::{glamx::vec3, shape::{Shape, ShapeType, SharedShape}};
|
use parry3d::{glamx::vec3, shape::{Shape, ShapeType, SharedShape}};
|
||||||
use rapier3d::{geometry::Ball, na::{UnitQuaternion, Vector4}};
|
use rapier3d::{geometry::Ball, na::{UnitQuaternion, Vector4}};
|
||||||
@@ -37,38 +37,21 @@ pub struct CuboidShape_t
|
|||||||
m_fExtentZ: f32,
|
m_fExtentZ: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[repr(C)]
|
||||||
|
#[derive(Clone, Copy)]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum RapierShapeType {
|
pub struct TriangleMeshShape_t
|
||||||
Ball(Ball),
|
{
|
||||||
Cuboid(Cuboid),
|
m_pfPositions: *const f32,
|
||||||
Capsule(Capsule),
|
m_nPositionCount: u32,
|
||||||
Segment(Segment),
|
m_puIndicies: *const f32,
|
||||||
Triangle(Triangle),
|
m_nIndiciesCount: u32,
|
||||||
Voxels(Voxels),
|
|
||||||
TriMesh(TriMesh),
|
|
||||||
Polyline(Polyline),
|
|
||||||
HalfSpace(HalfSpace),
|
|
||||||
HeightField(HeightField),
|
|
||||||
Compound(Compound),
|
|
||||||
ConvexPolyhedron(ConvexPolyhedron),
|
|
||||||
Cylinder(Cylinder),
|
|
||||||
Cone(Cone),
|
|
||||||
RoundCuboid(RoundCuboid),
|
|
||||||
RoundTriangle(RoundTriangle),
|
|
||||||
RoundCylinder(RoundCylinder),
|
|
||||||
RoundCone(RoundCone),
|
|
||||||
RoundConvexPolyhedron(RoundConvexPolyhedron),
|
|
||||||
#[allow(dead_code)]
|
|
||||||
Custom,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct RapierShape_t
|
pub struct RapierShape_t
|
||||||
{
|
{
|
||||||
m_shape: RapierShapeType,
|
|
||||||
m_sharedShape: SharedShape,
|
m_sharedShape: SharedShape,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,13 +105,6 @@ pub struct RapierPhysics_t
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct TrianglesShape_t
|
|
||||||
{
|
|
||||||
m_pfPositions: *const f32,
|
|
||||||
m_nPositionCount: const u32,
|
|
||||||
m_puIndicies,
|
|
||||||
m_nIndiciesCount,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn CRapierPhysicsBody_SetPosition( this: *mut RapierPhysicsBody_t, fX: f32, fY: f32, fZ: f32 )
|
pub unsafe extern "C" fn CRapierPhysicsBody_SetPosition( this: *mut RapierPhysicsBody_t, fX: f32, fY: f32, fZ: f32 )
|
||||||
@@ -157,7 +133,7 @@ pub struct Vector {
|
|||||||
pub unsafe extern "C" fn CRapierPhysicsBody_GetPosition( this: *mut RapierPhysicsBody_t ) -> Vector
|
pub unsafe extern "C" fn CRapierPhysicsBody_GetPosition( this: *mut RapierPhysicsBody_t ) -> Vector
|
||||||
{
|
{
|
||||||
let world: &mut RapierWorld_t = &mut *(*this).m_pWorld;
|
let world: &mut RapierWorld_t = &mut *(*this).m_pWorld;
|
||||||
let position = world.m_rigidBodies[(*this).m_hRigidBodyHandle]
|
let mut position = world.m_rigidBodies[(*this).m_hRigidBodyHandle]
|
||||||
.translation().to_array();
|
.translation().to_array();
|
||||||
return Vector { x: position[0], y: position[1], z: position[2]}
|
return Vector { x: position[0], y: position[1], z: position[2]}
|
||||||
}
|
}
|
||||||
@@ -179,6 +155,22 @@ pub unsafe extern "C" fn CRapierPhysicsBody_GetRotation( this: *mut RapierPhysic
|
|||||||
Quat{ x: rotationVector[0], y: rotationVector[1], z: rotationVector[2], w: rotationVector[3]}
|
Quat{ x: rotationVector[0], y: rotationVector[1], z: rotationVector[2], w: rotationVector[3]}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn CRapierPhysicsBody_SetType( this: *mut RapierPhysicsBody_t, eType: EPhysicsBodyType )
|
||||||
|
{
|
||||||
|
let world: &mut RapierWorld_t = &mut *(*this).m_pWorld;
|
||||||
|
let eRapierBodyType: RigidBodyType;
|
||||||
|
match eType
|
||||||
|
{
|
||||||
|
EPhysicsBodyType::k_EPhysics_Static => eRapierBodyType = RigidBodyType::Fixed,
|
||||||
|
EPhysicsBodyType::k_EPhysics_Dynamic => eRapierBodyType = RigidBodyType::Dynamic,
|
||||||
|
EPhysicsBodyType::k_EPhysics_KinematicPositionBased => eRapierBodyType = RigidBodyType::KinematicPositionBased,
|
||||||
|
EPhysicsBodyType::k_EPhysics_KinematicVelocityBased => eRapierBodyType = RigidBodyType::KinematicVelocityBased,
|
||||||
|
}
|
||||||
|
world.m_rigidBodies[(*this).m_hRigidBodyHandle]
|
||||||
|
.set_body_type(eRapierBodyType, true);
|
||||||
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn CRapierPhysicsWorld_Frame( this: *mut RapierWorld_t, fDelta: f32 )
|
pub unsafe extern "C" fn CRapierPhysicsWorld_Frame( this: *mut RapierWorld_t, fDelta: f32 )
|
||||||
{
|
{
|
||||||
@@ -245,14 +237,8 @@ pub unsafe extern "C" fn CRapierPhysics_New() -> *mut RapierPhysics_t
|
|||||||
pub unsafe extern "C" fn CRapierPhysics_CreateBall( this: *mut RapierPhysics_t, ball: BallShape_t ) -> *mut RapierShape_t
|
pub unsafe extern "C" fn CRapierPhysics_CreateBall( this: *mut RapierPhysics_t, ball: BallShape_t ) -> *mut RapierShape_t
|
||||||
{
|
{
|
||||||
let pShapeMemory: *mut RapierShape_t = V_malloc!(RapierShape_t, 1);
|
let pShapeMemory: *mut RapierShape_t = V_malloc!(RapierShape_t, 1);
|
||||||
std::ptr::write(&mut (*pShapeMemory).m_shape, RapierShapeType::Ball(Ball::new(ball.m_fRadius)));
|
std::ptr::write(&mut (*pShapeMemory).m_sharedShape, SharedShape::new(Ball::new(ball.m_fRadius)));
|
||||||
match ((*pShapeMemory).m_shape)
|
|
||||||
{
|
|
||||||
RapierShapeType::Ball(b) => {
|
|
||||||
std::ptr::write(&mut (*pShapeMemory).m_sharedShape, SharedShape::new(b));
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
pShapeMemory
|
pShapeMemory
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -260,15 +246,52 @@ pub unsafe extern "C" fn CRapierPhysics_CreateBall( this: *mut RapierPhysics_t,
|
|||||||
pub unsafe extern "C" fn CRapierPhysics_CreateCube( this: *mut RapierPhysics_t, cuboid: CuboidShape_t ) -> *mut RapierShape_t
|
pub unsafe extern "C" fn CRapierPhysics_CreateCube( this: *mut RapierPhysics_t, cuboid: CuboidShape_t ) -> *mut RapierShape_t
|
||||||
{
|
{
|
||||||
let pShapeMemory: *mut RapierShape_t = V_malloc!(RapierShape_t, 1);
|
let pShapeMemory: *mut RapierShape_t = V_malloc!(RapierShape_t, 1);
|
||||||
std::ptr::write(&mut (*pShapeMemory).m_shape, RapierShapeType::Cuboid(
|
std::ptr::write(&mut (*pShapeMemory).m_sharedShape, SharedShape::new(
|
||||||
Cuboid::new(vec3(cuboid.m_fExtentX, cuboid.m_fExtentY, cuboid.m_fExtentZ)))
|
Cuboid::new(vec3(cuboid.m_fExtentX, cuboid.m_fExtentY, cuboid.m_fExtentZ)))
|
||||||
);
|
);
|
||||||
match ((*pShapeMemory).m_shape)
|
pShapeMemory
|
||||||
{
|
|
||||||
RapierShapeType::Cuboid(b) => {
|
|
||||||
std::ptr::write(&mut (*pShapeMemory).m_sharedShape, SharedShape::new(b));
|
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn CRapierPhysics_CreateTriangleMesh( this: *mut RapierPhysics_t, triangle: TriangleMeshShape_t ) -> *mut RapierShape_t
|
||||||
|
{
|
||||||
|
let pShapeMemory: *mut RapierShape_t = V_malloc!(RapierShape_t, 1);
|
||||||
|
let positions = Vec::from_raw_parts(triangle.m_pfPositions as *mut Vec3, triangle.m_nPositionCount as usize, triangle.m_nPositionCount as usize);
|
||||||
|
let mut indices: Vec<[u32; 3]>;
|
||||||
|
|
||||||
|
if ( triangle.m_nIndiciesCount == 0 )
|
||||||
|
{
|
||||||
|
if ( triangle.m_nPositionCount % 3 != 0 )
|
||||||
|
{
|
||||||
|
return null_mut();
|
||||||
|
}
|
||||||
|
indices = vec![[0,0,0]; (triangle.m_nPositionCount/3) as usize];
|
||||||
|
for i in 0..indices.len()/3
|
||||||
|
{
|
||||||
|
let u = i as u32;
|
||||||
|
indices[i][0] = u*3;
|
||||||
|
indices[i][1] = u*3+1;
|
||||||
|
indices[i][2] = u*3+2;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ( triangle.m_nIndiciesCount % 3 != 0 )
|
||||||
|
{
|
||||||
|
return null_mut();
|
||||||
|
}
|
||||||
|
indices = Vec::from_raw_parts(triangle.m_puIndicies as *mut [u32; 3], triangle.m_nIndiciesCount as usize, triangle.m_nIndiciesCount as usize);
|
||||||
|
}
|
||||||
|
|
||||||
|
let mesh = TriMesh::new(positions, indices);
|
||||||
|
match mesh
|
||||||
|
{
|
||||||
|
Ok(m) =>
|
||||||
|
{
|
||||||
|
std::ptr::write(&mut (*pShapeMemory).m_sharedShape, SharedShape::new(m));
|
||||||
|
}
|
||||||
|
default => {}
|
||||||
}
|
}
|
||||||
pShapeMemory
|
pShapeMemory
|
||||||
}
|
}
|
||||||
@@ -276,13 +299,9 @@ pub unsafe extern "C" fn CRapierPhysics_CreateCube( this: *mut RapierPhysics_t,
|
|||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn CRapierPhysics_CreateCollider( this: *mut RapierPhysics_t, pShape: *mut RapierShape_t ) -> *mut RapierCollider_t
|
pub unsafe extern "C" fn CRapierPhysics_CreateCollider( this: *mut RapierPhysics_t, pShape: *mut RapierShape_t ) -> *mut RapierCollider_t
|
||||||
{
|
{
|
||||||
println!("this {:?}", pShape);
|
|
||||||
let shape: &SharedShape = &(*pShape).m_sharedShape;
|
let shape: &SharedShape = &(*pShape).m_sharedShape;
|
||||||
println!("this {:?}", pShape);
|
|
||||||
let pCollider = V_malloc!(RapierCollider_t, 1);
|
let pCollider = V_malloc!(RapierCollider_t, 1);
|
||||||
println!("this {:?}", pShape);
|
|
||||||
std::ptr::write(&mut (*pCollider).m_collider, ColliderBuilder::new(shape.clone()).build());
|
std::ptr::write(&mut (*pCollider).m_collider, ColliderBuilder::new(shape.clone()).build());
|
||||||
println!("this {:?}", pShape);
|
|
||||||
pCollider
|
pCollider
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user