summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2018-01-16 13:08:13 +0100
committerGitHub <noreply@github.com>2018-01-16 13:08:13 +0100
commit1968cc445cc3f9dfaa96adc9671c025e0d7b743e (patch)
tree4093e75c903073b10d2ec0801f2de9a394659149
parent3def642a156c19a786d70a1ca5e52f2f9009ff78 (diff)
parentecfe932eb8345c38dd4e35634b3eddba033eb929 (diff)
Merge pull request #15777 from AndreaCatania/p2
Fixed bullet physics body shape scaling
-rw-r--r--modules/bullet/collision_object_bullet.cpp25
1 files changed, 12 insertions, 13 deletions
diff --git a/modules/bullet/collision_object_bullet.cpp b/modules/bullet/collision_object_bullet.cpp
index 873c9c31b7..34aff68a4a 100644
--- a/modules/bullet/collision_object_bullet.cpp
+++ b/modules/bullet/collision_object_bullet.cpp
@@ -160,16 +160,13 @@ int CollisionObjectBullet::get_godot_object_flags() const {
void CollisionObjectBullet::set_transform(const Transform &p_global_transform) {
- btTransform btTrans;
- Basis decomposed_basis;
+ set_body_scale(p_global_transform.basis.get_scale());
- Vector3 decomposed_scale = p_global_transform.get_basis().rotref_posscale_decomposition(decomposed_basis);
+ btTransform bt_transform;
+ G_TO_B(p_global_transform, bt_transform);
+ UNSCALE_BT_BASIS(bt_transform);
- G_TO_B(p_global_transform.get_origin(), btTrans.getOrigin());
- G_TO_B(decomposed_basis, btTrans.getBasis());
-
- set_body_scale(decomposed_scale);
- set_transform__bullet(btTrans);
+ set_transform__bullet(bt_transform);
}
Transform CollisionObjectBullet::get_transform() const {
@@ -317,20 +314,22 @@ void RigidCollisionObjectBullet::on_shapes_changed() {
}
// Insert all shapes
-
+ btVector3 body_scale(get_bt_body_scale());
for (i = 0; i < shapes_size; ++i) {
shpWrapper = &shapes[i];
if (shpWrapper->active) {
if (!shpWrapper->bt_shape) {
- shpWrapper->bt_shape = shpWrapper->shape->create_bt_shape(shpWrapper->scale);
+ shpWrapper->bt_shape = shpWrapper->shape->create_bt_shape(shpWrapper->scale * body_scale);
}
- compoundShape->addChildShape(shpWrapper->transform, shpWrapper->bt_shape);
+
+ btTransform scaled_shape_transform(shpWrapper->transform);
+ scaled_shape_transform.getOrigin() *= body_scale;
+ compoundShape->addChildShape(scaled_shape_transform, shpWrapper->bt_shape);
} else {
- compoundShape->addChildShape(shpWrapper->transform, BulletPhysicsServer::get_empty_shape());
+ compoundShape->addChildShape(btTransform(), BulletPhysicsServer::get_empty_shape());
}
}
- compoundShape->setLocalScaling(get_bt_body_scale());
compoundShape->recalculateLocalAabb();
}