Skip to content
This repository has been archived by the owner on Jun 29, 2024. It is now read-only.

Commit

Permalink
update skewing and scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
Ughuuu committed Jul 26, 2023
1 parent 7331b9a commit a7ec131
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- Fix concave polygon
- Add support for conveyer belt
- Add build for web but not enabled yet (bug in godot-cpp)
- Update/fix support for skewing/scaling for shapes.

## [v0.3](https://github.com/godot-box2d/godot-box2d/releases/tag/v0.3)

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ A [box2D](https://github.com/erincatto/box2d) physics server for [Godot Engine](

In godot would result a collision, but would be very weird, as only one of the objects would receive collision restution.

- Shape scaling and skewing:
- Circles and capsules only support uniform scaling and don't support skewing

## Missing/Not implemented

- Skewed shapes
Expand Down
8 changes: 8 additions & 0 deletions src/bodies/box2d_collision_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ void Box2DCollisionObject::reset_mass_properties() {
//mass_data = body->GetMassData();
mass_data.mass = 1.0f;
body->SetMassData(&mass_data);
mass_data.center = body->GetLocalCenter();
mass_data.I = body->GetMassData().I;
} else {
mass_data.mass = 1.0f;
Expand All @@ -35,6 +36,7 @@ void Box2DCollisionObject::set_mass(real_t p_mass) {
mass_data.mass = p_mass;
if (body) {
body->SetMassData(&mass_data);
mass_data.center = body->GetLocalCenter();
mass_data.I = body->GetMassData().I;
}
}
Expand All @@ -51,6 +53,7 @@ void Box2DCollisionObject::set_inertia(real_t p_inertia) {
mass_data.I = godot_to_box2d(godot_to_box2d(p_inertia));
if (body) {
body->SetMassData(&mass_data);
mass_data.center = body->GetLocalCenter();
mass_data.I = body->GetMassData().I;
}
}
Expand All @@ -64,6 +67,7 @@ void Box2DCollisionObject::set_center_of_mass(Vector2 p_center_of_mass) {
godot_to_box2d(p_center_of_mass, mass_data.center);
if (body) {
body->SetMassData(&mass_data);
mass_data.center = body->GetLocalCenter();
mass_data.I = body->GetMassData().I;
}
}
Expand Down Expand Up @@ -807,6 +811,9 @@ void Box2DCollisionObject::_update_shapes() {
mass_data = body->GetMassData();
// revert mass
mass_data.mass = old_mass;
// TODO only do this if we need to automatically compute local center.
mass_data.center = body->GetLocalCenter();
//mass_data.center = b2Vec2_zero;
body->SetMassData(&mass_data);
//space->get_broadphase()->move(s.bpid, shape_aabb);
}
Expand Down Expand Up @@ -890,6 +897,7 @@ void Box2DCollisionObject::set_b2Body(b2Body *p_body) {
// set additional properties here
if (body) {
body->SetMassData(&mass_data);
mass_data.center = body->GetLocalCenter();
mass_data.I = body->GetMassData().I;
body->SetAwake(true);
//recreate_shapes();
Expand Down

0 comments on commit a7ec131

Please sign in to comment.