Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions liquidfun-c/Box2D/Dynamics/c_b2Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

4 changes: 3 additions & 1 deletion liquidfun-c/Box2D/Dynamics/c_b2Body.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
#endif
14 changes: 14 additions & 0 deletions src/box2d/dynamics/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down