Fixed bullet physics body shape scaling
This commit is contained in:
parent
05b1843818
commit
ecfe932eb8
1 changed files with 12 additions and 13 deletions
|
@ -160,16 +160,13 @@ int CollisionObjectBullet::get_godot_object_flags() const {
|
||||||
|
|
||||||
void CollisionObjectBullet::set_transform(const Transform &p_global_transform) {
|
void CollisionObjectBullet::set_transform(const Transform &p_global_transform) {
|
||||||
|
|
||||||
btTransform btTrans;
|
set_body_scale(p_global_transform.basis.get_scale());
|
||||||
Basis decomposed_basis;
|
|
||||||
|
|
||||||
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());
|
set_transform__bullet(bt_transform);
|
||||||
G_TO_B(decomposed_basis, btTrans.getBasis());
|
|
||||||
|
|
||||||
set_body_scale(decomposed_scale);
|
|
||||||
set_transform__bullet(btTrans);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Transform CollisionObjectBullet::get_transform() const {
|
Transform CollisionObjectBullet::get_transform() const {
|
||||||
|
@ -317,20 +314,22 @@ void RigidCollisionObjectBullet::on_shapes_changed() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert all shapes
|
// Insert all shapes
|
||||||
|
btVector3 body_scale(get_bt_body_scale());
|
||||||
for (i = 0; i < shapes_size; ++i) {
|
for (i = 0; i < shapes_size; ++i) {
|
||||||
shpWrapper = &shapes[i];
|
shpWrapper = &shapes[i];
|
||||||
if (shpWrapper->active) {
|
if (shpWrapper->active) {
|
||||||
if (!shpWrapper->bt_shape) {
|
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 {
|
} else {
|
||||||
compoundShape->addChildShape(shpWrapper->transform, BulletPhysicsServer::get_empty_shape());
|
compoundShape->addChildShape(btTransform(), BulletPhysicsServer::get_empty_shape());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
compoundShape->setLocalScaling(get_bt_body_scale());
|
|
||||||
compoundShape->recalculateLocalAabb();
|
compoundShape->recalculateLocalAabb();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue