work on world

This commit is contained in:
2026-03-16 15:35:31 +02:00
parent c05bca6d27
commit 6d5141cf43
33 changed files with 416 additions and 100 deletions

View File

@@ -29,6 +29,7 @@ pub struct BallShape_t
#[repr(C)]
#[derive(Clone, Copy)]
#[derive(Debug)]
pub struct CuboidShape_t
{
m_fExtentX: f32,
@@ -36,12 +37,38 @@ pub struct CuboidShape_t
m_fExtentZ: f32,
}
#[derive(Clone)]
#[derive(Debug)]
pub enum RapierShapeType {
Ball(Ball),
Cuboid(Cuboid),
Capsule(Capsule),
Segment(Segment),
Triangle(Triangle),
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(Debug)]
pub struct RapierShape_t
{
m_eType: ShapeType,
m_pShape: *mut dyn Shape,
m_shape: RapierShapeType,
m_sharedShape: SharedShape,
}
@@ -57,6 +84,7 @@ pub enum EPhysicsBodyType
#[derive(Clone)]
#[derive(Debug)]
pub struct RapierCollider_t
{
m_collider: Collider,
@@ -94,6 +122,14 @@ pub struct RapierPhysics_t
}
struct TrianglesShape_t
{
m_pfPositions: *const f32,
m_nPositionCount: const u32,
m_puIndicies,
m_nIndiciesCount,
};
#[no_mangle]
pub unsafe extern "C" fn CRapierPhysicsBody_SetPosition( this: *mut RapierPhysicsBody_t, fX: f32, fY: f32, fZ: f32 )
{
@@ -201,51 +237,52 @@ pub unsafe extern "C" fn CRapierPhysics_New() -> *mut RapierPhysics_t
{
let physics = RapierPhysics_t {};
let pPhysics = V_malloc!(RapierPhysics_t, 1);
*pPhysics = physics;
*pPhysics = physics.clone();
pPhysics
}
#[no_mangle]
pub unsafe extern "C" fn CRapierPhysics_CreateBall( this: *mut RapierPhysics_t, ball: BallShape_t ) -> *mut RapierShape_t
{
let rapierShape = Ball::new(ball.m_fRadius);
let pRapierShapeMemory: *mut Ball = V_malloc!(Ball, 1);
*pRapierShapeMemory = rapierShape;
let shape: RapierShape_t = RapierShape_t {
m_eType: ShapeType::Ball,
m_pShape: pRapierShapeMemory,
m_sharedShape: SharedShape::new(rapierShape)
};
let pShapeMemory: *mut RapierShape_t = V_malloc!(RapierShape_t, 1);
*pShapeMemory = shape;
std::ptr::write(&mut (*pShapeMemory).m_shape, RapierShapeType::Ball(Ball::new(ball.m_fRadius)));
match ((*pShapeMemory).m_shape)
{
RapierShapeType::Ball(b) => {
std::ptr::write(&mut (*pShapeMemory).m_sharedShape, SharedShape::new(b));
}
_ => {}
}
pShapeMemory
}
#[no_mangle]
pub unsafe extern "C" fn CRapierPhysics_CreateCube( this: *mut RapierPhysics_t, cuboid: CuboidShape_t ) -> *mut RapierShape_t
{
let rapierShape = Cuboid::new(vec3(cuboid.m_fExtentX, cuboid.m_fExtentY, cuboid.m_fExtentZ));
let pRapierShapeMemory: *mut Cuboid = V_malloc!(Cuboid, 1);
*pRapierShapeMemory = rapierShape;
let shape: RapierShape_t = RapierShape_t {
m_eType: ShapeType::Cuboid,
m_pShape: pRapierShapeMemory,
m_sharedShape: SharedShape::new(rapierShape)
};
let pShapeMemory: *mut RapierShape_t = V_malloc!(RapierShape_t, 1);
*pShapeMemory = shape;
std::ptr::write(&mut (*pShapeMemory).m_shape, RapierShapeType::Cuboid(
Cuboid::new(vec3(cuboid.m_fExtentX, cuboid.m_fExtentY, cuboid.m_fExtentZ)))
);
match ((*pShapeMemory).m_shape)
{
RapierShapeType::Cuboid(b) => {
std::ptr::write(&mut (*pShapeMemory).m_sharedShape, SharedShape::new(b));
}
_ => {}
}
pShapeMemory
}
#[no_mangle]
pub unsafe extern "C" fn CRapierPhysics_CreateCollider( this: *mut RapierPhysics_t, pShape: *mut RapierShape_t ) -> *mut RapierCollider_t
{
let pRapierShape = (*pShape).m_pShape;
println!("this {:?}", pShape);
let shape: &SharedShape = &(*pShape).m_sharedShape;
println!("this {:?}", pShape);
let pCollider = V_malloc!(RapierCollider_t, 1);
println!("this {:?}", pShape);
std::ptr::write(&mut (*pCollider).m_collider, ColliderBuilder::new(shape.clone()).build());
println!("this {:?}", pShape);
pCollider
}