diff --git a/liquidfun-c/Box2D/Dynamics/c_b2Body.cpp b/liquidfun-c/Box2D/Dynamics/c_b2Body.cpp index d3e1adb..c6ce731 100644 --- a/liquidfun-c/Box2D/Dynamics/c_b2Body.cpp +++ b/liquidfun-c/Box2D/Dynamics/c_b2Body.cpp @@ -39,5 +39,12 @@ extern "C" { return self->GetLocalPoint(worldPoint); } + void b2Body_ApplyForce(b2Body* self, const b2Vec2& force, const b2Vec2& point, bool wake) { + self->ApplyForce(force, point, wake); + } + + void b2Body_ApplyForceToCenter(b2Body* self, const b2Vec2& force, bool wake) { + self->ApplyForceToCenter(force, wake); + } } // extern C diff --git a/liquidfun-c/Box2D/Dynamics/c_b2Body.h b/liquidfun-c/Box2D/Dynamics/c_b2Body.h index 162d8a7..d25b770 100644 --- a/liquidfun-c/Box2D/Dynamics/c_b2Body.h +++ b/liquidfun-c/Box2D/Dynamics/c_b2Body.h @@ -14,8 +14,10 @@ extern "C" { void* b2Body_GetUserData(const b2Body* self); b2World* b2Body_GetWorld(b2Body* self); b2Vec2 b2Body_GetLocalPoint(const b2Body* self, const b2Vec2& worldPoint); + void b2Body_ApplyForce(b2Body* self, const b2Vec2& force, const b2Vec2& point, bool wake); + void b2Body_ApplyForceToCenter(b2Body* self, const b2Vec2& force, bool wake); #ifdef __cplusplus } // extern C #endif -#endif \ No newline at end of file +#endif diff --git a/src/box2d/dynamics/body.rs b/src/box2d/dynamics/body.rs index eee3090..8f89296 100644 --- a/src/box2d/dynamics/body.rs +++ b/src/box2d/dynamics/body.rs @@ -111,6 +111,8 @@ extern { fn b2Body_GetUserData(this: *const B2Body) -> usize; fn b2Body_GetWorld(this: *const B2Body) -> *mut B2World; fn b2Body_GetLocalPoint(this: *const B2Body, worldPoint: &Vec2) -> Vec2; + fn b2Body_ApplyForce(this: *mut B2Body, force: &Vec2, point: &Vec2, wake: bool); + fn b2Body_ApplyForceToCenter(this: *mut B2Body, force: &Vec2, wake: bool); } /// A rigid body. These are created via b2World::CreateBody. @@ -193,6 +195,18 @@ impl Body { } } + pub fn apply_force(&self, force: &Vec2, point: &Vec2, wake: bool) { + unsafe { + b2Body_ApplyForce(self.ptr, force, point, wake); + } + } + + pub fn apply_force_to_center(&self, force: &Vec2, wake: bool) { + unsafe { + b2Body_ApplyForceToCenter(self.ptr, force, wake); + } + } + /// Get the user data pointer that was provided in the body definition. pub fn get_user_data(&self) -> usize { unsafe {