Skip to content

Commit

Permalink
Bind SimShapeFilter
Browse files Browse the repository at this point in the history
  • Loading branch information
LPGhatguy committed Dec 21, 2024
1 parent a4d5fea commit 206f24a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion crates/joltc-sys/JoltC
Submodule JoltC updated 3 files
+19 −2 JoltC/Functions.h
+36 −0 JoltC/JoltC.cpp
+1 −1 JoltPhysics
41 changes: 41 additions & 0 deletions crates/rolt/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,47 @@ impl<T: ShapeFilter> ShapeFilterBridge<T> {
}
}

/// See also: Jolt's [`SimShapeFilter`](https://jrouwe.github.io/JoltPhysicsDocs/5.1.0/class_sim_shape_filter.html) class.
pub trait SimShapeFilter {
fn should_collide(
&self,
body1: Body<'_>,
shape1: *const JPC_Shape,
subshape1: JPC_SubShapeID,
body2: Body<'_>,
shape2: *const JPC_Shape,
subshape2: JPC_SubShapeID,
) -> bool;
}

define_impl_struct!(const SimShapeFilter {
ShouldCollide,
});

struct SimShapeFilterBridge<T> {
_phantom: PhantomData<T>,
}

impl<T: SimShapeFilter> SimShapeFilterBridge<T> {
unsafe extern "C" fn ShouldCollide(
this: *const c_void,
body1: *const JPC_Body,
shape1: *const JPC_Shape,
subshape1: JPC_SubShapeID,
body2: *const JPC_Body,
shape2: *const JPC_Shape,
subshape2: JPC_SubShapeID,
) -> bool {
let this = this.cast::<T>().as_ref().unwrap();

// FIXME: `Body` should support a `const` version!
let body1 = Body::new(body1.cast_mut());
let body2 = Body::new(body2.cast_mut());

this.should_collide(body1, shape1, subshape1, body2, shape2, subshape2)
}
}

pub trait CastShapeCollector {
fn reset(&mut self);
fn add_hit(&mut self, base: &mut CastShapeBase, result: &JPC_ShapeCastResult);
Expand Down

0 comments on commit 206f24a

Please sign in to comment.