diff options
-rw-r--r-- | modules/bullet/collision_object_bullet.cpp | 11 | ||||
-rw-r--r-- | modules/bullet/collision_object_bullet.h | 4 | ||||
-rw-r--r-- | modules/bullet/rigid_body_bullet.cpp | 13 |
3 files changed, 20 insertions, 8 deletions
diff --git a/modules/bullet/collision_object_bullet.cpp b/modules/bullet/collision_object_bullet.cpp index da3a4b73cf..88d4108f82 100644 --- a/modules/bullet/collision_object_bullet.cpp +++ b/modules/bullet/collision_object_bullet.cpp @@ -76,11 +76,17 @@ bool equal(real_t first, real_t second) { void CollisionObjectBullet::set_body_scale(const Vector3 &p_new_scale) { if (!equal(p_new_scale[0], body_scale[0]) || !equal(p_new_scale[1], body_scale[1]) || !equal(p_new_scale[2], body_scale[2])) { - G_TO_B(p_new_scale, body_scale); + body_scale = p_new_scale; on_body_scale_changed(); } } +btVector3 CollisionObjectBullet::get_bt_body_scale() const { + btVector3 s; + G_TO_B(body_scale, s); + return s; +} + void CollisionObjectBullet::on_body_scale_changed() { } @@ -160,6 +166,7 @@ void CollisionObjectBullet::set_transform(const Transform &p_global_transform) { Transform CollisionObjectBullet::get_transform() const { Transform t; B_TO_G(get_transform__bullet(), t); + t.basis.scale(body_scale); return t; } @@ -302,7 +309,7 @@ void RigidCollisionObjectBullet::on_shapes_changed() { } } - compoundShape->setLocalScaling(body_scale); + compoundShape->setLocalScaling(get_bt_body_scale()); compoundShape->recalculateLocalAabb(); } diff --git a/modules/bullet/collision_object_bullet.h b/modules/bullet/collision_object_bullet.h index 51e48909e4..7d4659b64e 100644 --- a/modules/bullet/collision_object_bullet.h +++ b/modules/bullet/collision_object_bullet.h @@ -114,7 +114,7 @@ protected: bool m_isStatic; bool ray_pickable; btCollisionObject *bt_collision_object; - btVector3 body_scale; + Vector3 body_scale; SpaceBullet *space; VSet<RID> exceptions; @@ -146,6 +146,8 @@ public: _FORCE_INLINE_ bool is_ray_pickable() const { return ray_pickable; } void set_body_scale(const Vector3 &p_new_scale); + const Vector3 &get_body_scale() const { return body_scale; } + btVector3 get_bt_body_scale() const; virtual void on_body_scale_changed(); void add_collision_exception(const CollisionObjectBullet *p_ignoreCollisionObject); diff --git a/modules/bullet/rigid_body_bullet.cpp b/modules/bullet/rigid_body_bullet.cpp index b134bd3a36..b9621a0585 100644 --- a/modules/bullet/rigid_body_bullet.cpp +++ b/modules/bullet/rigid_body_bullet.cpp @@ -198,6 +198,8 @@ void RigidBodyBullet::KinematicUtilities::copyAllOwnerShapes() { const CollisionObjectBullet::ShapeWrapper *shape_wrapper; + btVector3 owner_body_scale(owner->get_bt_body_scale()); + for (int i = shapes_count - 1; 0 <= i; --i) { shape_wrapper = &shapes_wrappers[i]; if (!shape_wrapper->active) { @@ -210,28 +212,29 @@ void RigidBodyBullet::KinematicUtilities::copyAllOwnerShapes() { switch (shape_wrapper->shape->get_type()) { case PhysicsServer::SHAPE_SPHERE: { SphereShapeBullet *sphere = static_cast<SphereShapeBullet *>(shape_wrapper->shape); - kin_shape_ref = ShapeBullet::create_shape_sphere(sphere->get_radius() * owner->body_scale[0] + safe_margin); + kin_shape_ref = ShapeBullet::create_shape_sphere(sphere->get_radius() * owner_body_scale[0] + safe_margin); break; } case PhysicsServer::SHAPE_BOX: { BoxShapeBullet *box = static_cast<BoxShapeBullet *>(shape_wrapper->shape); - kin_shape_ref = ShapeBullet::create_shape_box((box->get_half_extents() * owner->body_scale) + btVector3(safe_margin, safe_margin, safe_margin)); + kin_shape_ref = ShapeBullet::create_shape_box((box->get_half_extents() * owner_body_scale) + btVector3(safe_margin, safe_margin, safe_margin)); break; } case PhysicsServer::SHAPE_CAPSULE: { CapsuleShapeBullet *capsule = static_cast<CapsuleShapeBullet *>(shape_wrapper->shape); - kin_shape_ref = ShapeBullet::create_shape_capsule(capsule->get_radius() * owner->body_scale[0] + safe_margin, capsule->get_height() * owner->body_scale[1] + safe_margin); + + kin_shape_ref = ShapeBullet::create_shape_capsule(capsule->get_radius() * owner_body_scale[0] + safe_margin, capsule->get_height() * owner_body_scale[1] + safe_margin); break; } case PhysicsServer::SHAPE_CONVEX_POLYGON: { ConvexPolygonShapeBullet *godot_convex = static_cast<ConvexPolygonShapeBullet *>(shape_wrapper->shape); kin_shape_ref = ShapeBullet::create_shape_convex(godot_convex->vertices); - kin_shape_ref->setLocalScaling(owner->body_scale + btVector3(safe_margin, safe_margin, safe_margin)); + kin_shape_ref->setLocalScaling(owner_body_scale + btVector3(safe_margin, safe_margin, safe_margin)); break; } case PhysicsServer::SHAPE_RAY: { RayShapeBullet *godot_ray = static_cast<RayShapeBullet *>(shape_wrapper->shape); - kin_shape_ref = ShapeBullet::create_shape_ray(godot_ray->length * owner->body_scale[1] + safe_margin); + kin_shape_ref = ShapeBullet::create_shape_ray(godot_ray->length * owner_body_scale[1] + safe_margin); break; } default: |