better physics

This commit is contained in:
2026-03-05 00:30:27 +02:00
parent ddbdef713b
commit 2da75ebdd8
68 changed files with 743 additions and 262450 deletions

View File

@@ -16,7 +16,7 @@ macro_rules! V_malloc {
use std::{default, ptr::{self, null}, sync::Arc};
use parry3d::{glamx::vec3, shape::{Shape, ShapeType, SharedShape}};
use rapier3d::{geometry::Ball};
use rapier3d::{geometry::Ball, na::{UnitQuaternion, Vector4}};
use rapier3d::prelude::*;
use libc::{malloc, free};
@@ -93,26 +93,67 @@ pub struct RapierPhysics_t
{
}
#[no_mangle]
pub unsafe extern "C" fn CRapierPhysicsBody_SetPosition( this: *mut RapierPhysicsBody_t, fX: f32, fY: f32, fZ: f32 )
{
let world: &mut RapierWorld_t = &mut *(*this).m_pWorld;
world.m_rigidBodies[(*this).m_hRigidBodyHandle]
.set_translation(vec3(fX, fY, fZ), true);
print!("{} {} {}\n", fX, fY, fZ);
}
#[no_mangle]
pub unsafe extern "C" fn CRapierPhysicsBody_SetRotation( this: *mut RapierPhysicsBody_t, fX: f32, fY: f32, fZ: f32, fW: f32 )
{
let world: &mut RapierWorld_t = &mut *(*this).m_pWorld;
world.m_rigidBodies[(*this).m_hRigidBodyHandle]
.set_translation(vec3(fX, fY, fZ), true);
}
#[repr(C)]
pub struct Vector {
x: f32,
y: f32,
z: f32,
}
#[no_mangle]
pub unsafe extern "C" fn CRapierPhysicsBody_GetPosition( this: *mut RapierPhysicsBody_t ) -> Vector
{
let world: &mut RapierWorld_t = &mut *(*this).m_pWorld;
let position = world.m_rigidBodies[(*this).m_hRigidBodyHandle]
.translation().to_array();
return Vector { x: position[0], y: position[1], z: position[2]}
}
#[repr(C)]
pub struct Quat {
x: f32,
y: f32,
z: f32,
w: f32,
}
#[no_mangle]
pub unsafe extern "C" fn CRapierPhysicsBody_GetRotation( this: *mut RapierPhysicsBody_t ) -> Quat
{
let world: &mut RapierWorld_t = &mut *(*this).m_pWorld;
let rotationVector = world.m_rigidBodies[(*this).m_hRigidBodyHandle]
.rotation().to_array();
Quat{ x: rotationVector[0], y: rotationVector[1], z: rotationVector[2], w: rotationVector[3]}
}
#[no_mangle]
pub unsafe extern "C" fn CRapierPhysicsWorld_Frame( this: *mut RapierWorld_t, fDelta: f32 )
{
let gravity = vec3(0.0, -9.81, 0.0);
let vGravity = vec3(0.0, -9.8, 0.0);
let mut integrationParameters = IntegrationParameters::default();
integrationParameters.dt = fDelta;
let mut physicsPipeline = PhysicsPipeline::new();
let physicsHooks = ();
let eventHandler = ();
physicsPipeline.step(
gravity,
vGravity,
&integrationParameters,
&mut (*this).m_islandManager,
&mut (*this).m_broadPhase,
@@ -125,10 +166,6 @@ pub unsafe extern "C" fn CRapierPhysicsWorld_Frame( this: *mut RapierWorld_t, fD
&physicsHooks,
&eventHandler,
);
for (h, b) in (*this).m_colliders.iter()
{
print!("{:?}\n",b.position())
}
}
#[no_mangle]
@@ -207,12 +244,8 @@ pub unsafe extern "C" fn CRapierPhysics_CreateCollider( this: *mut RapierPhysics
{
let pRapierShape = (*pShape).m_pShape;
let shape: &SharedShape = &(*pShape).m_sharedShape;
let rapierCollider = ColliderBuilder::new(shape.clone()).build();
let collider = RapierCollider_t {
m_collider: rapierCollider,
};
let pCollider = V_malloc!(RapierCollider_t, 1);
*pCollider = collider;
std::ptr::write(&mut (*pCollider).m_collider, ColliderBuilder::new(shape.clone()).build());
pCollider
}