Shader linking i guess

This commit is contained in:
2026-04-12 14:52:33 +03:00
parent 79ceac1005
commit 457b455042
38 changed files with 12534 additions and 114 deletions

View File

@@ -52,6 +52,12 @@ public:
RapierPhysicsBody_t *m_pBody = NULL;
};
struct Option_checkCastFn
{
fnCheckCast c;
};
class CRapierPhysicsWorld: public IPhysicsWorld
{
public:
@@ -80,14 +86,14 @@ public:
}
virtual CastResult_t RayCast( Vector vBegin, Vector vEnd ) override
virtual CastResult_t RayCast( Vector vBegin, Vector vEnd, fnCheckCast check ) override
{
return CRapierPhysicsWorld_RayCast(m_pWorld, vBegin, vEnd);
return CRapierPhysicsWorld_RayCast(m_pWorld, vBegin, vEnd, (Option_checkCastFn){check} );
}
virtual CastResult_t ShapeCast( HShape hShape, Quat vOrientation, Vector vBegin, Vector vEnd ) override
virtual CastResult_t ShapeCast( HShape hShape, Quat vOrientation, Vector vBegin, Vector vEnd, fnCheckCast check ) override
{
return CRapierPhysicsWorld_ShapeCast(m_pWorld, (RapierShape_t*)hShape, vOrientation, vBegin, vEnd );
return CRapierPhysicsWorld_ShapeCast(m_pWorld, (RapierShape_t*)hShape, vOrientation, vBegin, vEnd, (Option_checkCastFn){check} );
}

View File

@@ -10,6 +10,8 @@ typedef enum EPhysicsBodyType {
k_EPhysics_KinematicVelocityBased,
} EPhysicsBodyType;
typedef struct Option_checkCastFn Option_checkCastFn;
typedef struct RapierCollider_t RapierCollider_t;
typedef struct RapierPhysicsBody_t RapierPhysicsBody_t;
@@ -39,6 +41,7 @@ typedef struct CastResult_t {
struct Vector m_vCollisionPoint;
float m_fTime;
float m_fDistance;
struct Vector m_vNormal;
} CastResult_t;
typedef struct BallShape_t {
@@ -87,13 +90,15 @@ void CRapierPhysicsWorld_Frame(struct RapierWorld_t *this_, float fDelta);
struct CastResult_t CRapierPhysicsWorld_RayCast(struct RapierWorld_t *this_,
struct Vector vBegin,
struct Vector vEnd);
struct Vector vEnd,
struct Option_checkCastFn checkCast);
struct CastResult_t CRapierPhysicsWorld_ShapeCast(struct RapierWorld_t *this_,
struct RapierShape_t *pShape,
struct Quat vOrientation,
struct Vector vBegin,
struct Vector vEnd);
struct Vector vEnd,
struct Option_checkCastFn checkCast);
struct RapierShape_t *CRapierPhysics_CreateBall(struct RapierPhysics_t *this_,
struct BallShape_t ball);
@@ -109,6 +114,8 @@ struct RapierShape_t *CRapierPhysics_CreateTriangleMesh(struct RapierPhysics_t *
struct RapierWorld_t *CRapierPhysics_CreateWorld(struct RapierPhysics_t *this_);
void CRapierPhysics_DestroyShape(struct RapierPhysics_t *this_, struct RapierShape_t *shape);
struct RapierPhysics_t *CRapierPhysics_New(void);
#ifdef __cplusplus

View File

@@ -20,6 +20,8 @@ use parry3d::{glamx::{Pose3A}, query::ShapeCastOptions};
use rapier3d::{geometry::Ball, na::{UnitQuaternion, Vector4, coordinates::XYZ}};
use rapier3d::prelude::*;
use libc::{malloc, free};
use std::ffi::c_void;
use std::sync::Mutex;
#[repr(C)]
#[derive(Default, Debug)]
@@ -95,6 +97,7 @@ pub struct CastResult_t
m_vCollisionPoint: Vector,
m_fTime: f32,
m_fDistance: f32,
m_vNormal: Vector,
}
#[derive(Clone)]
@@ -242,8 +245,12 @@ pub unsafe extern "C" fn CRapierPhysicsWorld_CreateRigidBody(
pBody
}
type checkCastFn = extern "C" fn( pCollider: *mut RapierCollider_t ) -> bool;
#[no_mangle]
pub unsafe extern "C" fn CRapierPhysicsWorld_RayCast( this: *mut RapierWorld_t, vBegin: Vector, vEnd: Vector ) -> CastResult_t
pub unsafe extern "C" fn CRapierPhysicsWorld_RayCast( this: *mut RapierWorld_t, vBegin: Vector, vEnd: Vector, checkCast: Option<checkCastFn> ) -> CastResult_t
{
let mut cast = CastResult_t::default();
let vDir = Vector{ x: vEnd.x-vBegin.x, y:vEnd.y-vBegin.y, z:vEnd.z-vBegin.z};
@@ -252,11 +259,22 @@ pub unsafe extern "C" fn CRapierPhysicsWorld_RayCast( this: *mut RapierWorld_t,
let ray = Ray::new(
Vec3 { x: vBegin.x, y: vBegin.y, z: vBegin.z },
Vec3 { x: vNormalizedDir.x, y: vNormalizedDir.y, z: vNormalizedDir.z });
let mut filter = QueryFilter::default();
let predicate = |handle: ColliderHandle, collider: &Collider| -> bool {
checkCast.unwrap()(collider.user_data as *mut RapierCollider_t)
};
if let Some(f) = checkCast
{
filter.predicate = Option::Some(&predicate);
}
let queryPipeline = (*this).m_broadPhase.as_query_pipeline(
(*this).m_narrowPhase.query_dispatcher(),
&(*this).m_rigidBodies,
&(*this).m_colliders,
QueryFilter::default(),
filter,
);
if let Some((handle, intersection)) = queryPipeline.cast_ray_and_get_normal(&ray, fMaxDistance, true)
{
@@ -268,25 +286,43 @@ pub unsafe extern "C" fn CRapierPhysicsWorld_RayCast( this: *mut RapierWorld_t,
y: vBegin.y + vNormalizedDir.y * intersection.time_of_impact,
z: vBegin.z + vNormalizedDir.z * intersection.time_of_impact,
};
cast.m_vNormal = Vector{
x: intersection.normal.x,
y: intersection.normal.y,
z: intersection.normal.y,
}
}
cast
}
#[no_mangle]
pub unsafe extern "C" fn CRapierPhysicsWorld_ShapeCast( this: *mut RapierWorld_t, pShape: *mut RapierShape_t, vOrientation: Quat, vBegin: Vector, vEnd: Vector ) -> CastResult_t
pub unsafe extern "C" fn CRapierPhysicsWorld_ShapeCast( this: *mut RapierWorld_t, pShape: *mut RapierShape_t, vOrientation: Quat, vBegin: Vector, vEnd: Vector, checkCast: Option<checkCastFn> ) -> CastResult_t
{
let mut cast = CastResult_t::default();
let vDir = Vector{ x: vEnd.x-vBegin.x, y:vEnd.y-vBegin.y, z:vEnd.z-vBegin.z};
let fMaxDistance = f32::sqrt(vDir.x*vDir.x+vDir.y*vDir.y+vDir.z*vDir.z);
let vNormalizedDir = Vector{ x: vDir.x/fMaxDistance, y:vDir.y/fMaxDistance, z:vDir.z/fMaxDistance};
let mut filter = QueryFilter::default();
let predicate = |handle: ColliderHandle, collider: &Collider| -> bool {
checkCast.unwrap()(collider.user_data as *mut RapierCollider_t)
};
if let Some(f) = checkCast
{
filter.predicate = Option::Some(&predicate);
}
let queryPipeline = (*this).m_broadPhase.as_query_pipeline(
(*this).m_narrowPhase.query_dispatcher(),
&(*this).m_rigidBodies,
&(*this).m_colliders,
QueryFilter::default(),
filter,
);
let vRustDir = Vector{ x: vNormalizedDir.x, y: vNormalizedDir.y, z: vNormalizedDir.z };
let mut castOptions = ShapeCastOptions::default();
castOptions.stop_at_penetration = true;
castOptions.max_time_of_impact = fMaxDistance;
@@ -315,6 +351,11 @@ pub unsafe extern "C" fn CRapierPhysicsWorld_ShapeCast( this: *mut RapierWorld_t
y: vBegin.y + vNormalizedDir.y * intersection.time_of_impact,
z: vBegin.z + vNormalizedDir.z * intersection.time_of_impact,
};
cast.m_vNormal = Vector{
x: intersection.normal1.x,
y: intersection.normal1.y,
z: intersection.normal1.z,
}
}
cast
@@ -394,6 +435,12 @@ pub unsafe extern "C" fn CRapierPhysics_CreateTriangleMesh( this: *mut RapierPhy
}
pShapeMemory
}
#[no_mangle]
pub unsafe extern "C" fn CRapierPhysics_DestroyShape( this: *mut RapierPhysics_t, shape: *mut RapierShape_t )
{
std::ptr::drop_in_place(&mut (*shape).m_sharedShape);
free(shape as *mut c_void);
}
#[no_mangle]
pub unsafe extern "C" fn CRapierPhysics_CreateCollider( this: *mut RapierPhysics_t, pShape: *mut RapierShape_t ) -> *mut RapierCollider_t
@@ -401,6 +448,7 @@ pub unsafe extern "C" fn CRapierPhysics_CreateCollider( this: *mut RapierPhysics
let shape: &SharedShape = &(*pShape).m_sharedShape;
let pCollider = V_malloc!(RapierCollider_t, 1);
std::ptr::write(&mut (*pCollider).m_collider, ColliderBuilder::new(shape.clone()).build());
(*pCollider).m_collider.user_data = pCollider as u128;
pCollider
}