@@ -123,6 +123,69 @@ macro_rules! define_impl_struct {
123123 } ;
124124}
125125
126+ /// See also: Jolt's [`ContactListener`](https://jrouwe.github.io/JoltPhysicsDocs/5.1.0/class_contact_listener.html) class.
127+ pub trait ContactListener {
128+ fn on_contact_added (
129+ & self ,
130+ body1 : & JPC_Body ,
131+ body2 : & JPC_Body ,
132+ manifold : & JPC_ContactManifold ,
133+ settings : & mut JPC_ContactSettings ,
134+ ) ;
135+
136+ fn on_contact_persisted (
137+ & self ,
138+ body1 : & JPC_Body ,
139+ body2 : & JPC_Body ,
140+ manifold : & JPC_ContactManifold ,
141+ settings : & mut JPC_ContactSettings ,
142+ ) ;
143+
144+ fn on_contact_removed ( & self , sub_shape_pair : & JPC_SubShapeIDPair ) ;
145+ }
146+
147+ define_impl_struct ! ( mut ContactListener {
148+ OnContactAdded ,
149+ OnContactPersisted ,
150+ OnContactRemoved ,
151+ } ) ;
152+
153+ struct ContactListenerBridge < T > {
154+ _phantom : PhantomData < T > ,
155+ }
156+
157+ impl < T : ContactListener > ContactListenerBridge < T > {
158+ unsafe extern "C" fn OnContactAdded (
159+ this : * mut c_void ,
160+ body1 : * const JPC_Body ,
161+ body2 : * const JPC_Body ,
162+ manifold : * const JPC_ContactManifold ,
163+ settings : * mut JPC_ContactSettings ,
164+ ) {
165+ let this = this. cast :: < T > ( ) . as_ref ( ) . unwrap ( ) ;
166+ this. on_contact_added ( & * body1, & * body2, & * manifold, & mut * settings)
167+ }
168+
169+ unsafe extern "C" fn OnContactPersisted (
170+ this : * mut c_void ,
171+ body1 : * const JPC_Body ,
172+ body2 : * const JPC_Body ,
173+ manifold : * const JPC_ContactManifold ,
174+ settings : * mut JPC_ContactSettings ,
175+ ) {
176+ let this = this. cast :: < T > ( ) . as_ref ( ) . unwrap ( ) ;
177+ this. on_contact_persisted ( & * body1, & * body2, & * manifold, & mut * settings)
178+ }
179+
180+ unsafe extern "C" fn OnContactRemoved (
181+ this : * mut c_void ,
182+ sub_shape_pair : * const JPC_SubShapeIDPair ,
183+ ) {
184+ let this = this. cast :: < T > ( ) . as_ref ( ) . unwrap ( ) ;
185+ this. on_contact_removed ( & * sub_shape_pair) ;
186+ }
187+ }
188+
126189/// See also: Jolt's [`GroupFilter`](https://jrouwe.github.io/JoltPhysicsDocs/5.1.0/class_group_filter.html) class.
127190pub trait GroupFilter {
128191 fn can_collide ( & self , group_1 : & JPC_CollisionGroup , group_2 : & JPC_CollisionGroup ) -> bool ;
0 commit comments