Browse Source

Fixed bullet get_transform scale

AndreaCatania 7 năm trước cách đây
mục cha
commit
5cfc98cace

+ 9 - 2
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) {
 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])) {
 	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();
 		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() {
 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 CollisionObjectBullet::get_transform() const {
 	Transform t;
 	Transform t;
 	B_TO_G(get_transform__bullet(), t);
 	B_TO_G(get_transform__bullet(), t);
+	t.basis.scale(body_scale);
 	return t;
 	return t;
 }
 }
 
 
@@ -302,7 +309,7 @@ void RigidCollisionObjectBullet::on_shapes_changed() {
 		}
 		}
 	}
 	}
 
 
-	compoundShape->setLocalScaling(body_scale);
+	compoundShape->setLocalScaling(get_bt_body_scale());
 	compoundShape->recalculateLocalAabb();
 	compoundShape->recalculateLocalAabb();
 }
 }
 
 

+ 3 - 1
modules/bullet/collision_object_bullet.h

@@ -114,7 +114,7 @@ protected:
 	bool m_isStatic;
 	bool m_isStatic;
 	bool ray_pickable;
 	bool ray_pickable;
 	btCollisionObject *bt_collision_object;
 	btCollisionObject *bt_collision_object;
-	btVector3 body_scale;
+	Vector3 body_scale;
 	SpaceBullet *space;
 	SpaceBullet *space;
 
 
 	VSet<RID> exceptions;
 	VSet<RID> exceptions;
@@ -146,6 +146,8 @@ public:
 	_FORCE_INLINE_ bool is_ray_pickable() const { return ray_pickable; }
 	_FORCE_INLINE_ bool is_ray_pickable() const { return ray_pickable; }
 
 
 	void set_body_scale(const Vector3 &p_new_scale);
 	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();
 	virtual void on_body_scale_changed();
 
 
 	void add_collision_exception(const CollisionObjectBullet *p_ignoreCollisionObject);
 	void add_collision_exception(const CollisionObjectBullet *p_ignoreCollisionObject);

+ 8 - 5
modules/bullet/rigid_body_bullet.cpp

@@ -198,6 +198,8 @@ void RigidBodyBullet::KinematicUtilities::copyAllOwnerShapes() {
 
 
 	const CollisionObjectBullet::ShapeWrapper *shape_wrapper;
 	const CollisionObjectBullet::ShapeWrapper *shape_wrapper;
 
 
+	btVector3 owner_body_scale(owner->get_bt_body_scale());
+
 	for (int i = shapes_count - 1; 0 <= i; --i) {
 	for (int i = shapes_count - 1; 0 <= i; --i) {
 		shape_wrapper = &shapes_wrappers[i];
 		shape_wrapper = &shapes_wrappers[i];
 		if (!shape_wrapper->active) {
 		if (!shape_wrapper->active) {
@@ -210,28 +212,29 @@ void RigidBodyBullet::KinematicUtilities::copyAllOwnerShapes() {
 		switch (shape_wrapper->shape->get_type()) {
 		switch (shape_wrapper->shape->get_type()) {
 			case PhysicsServer::SHAPE_SPHERE: {
 			case PhysicsServer::SHAPE_SPHERE: {
 				SphereShapeBullet *sphere = static_cast<SphereShapeBullet *>(shape_wrapper->shape);
 				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;
 				break;
 			}
 			}
 			case PhysicsServer::SHAPE_BOX: {
 			case PhysicsServer::SHAPE_BOX: {
 				BoxShapeBullet *box = static_cast<BoxShapeBullet *>(shape_wrapper->shape);
 				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;
 				break;
 			}
 			}
 			case PhysicsServer::SHAPE_CAPSULE: {
 			case PhysicsServer::SHAPE_CAPSULE: {
 				CapsuleShapeBullet *capsule = static_cast<CapsuleShapeBullet *>(shape_wrapper->shape);
 				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;
 				break;
 			}
 			}
 			case PhysicsServer::SHAPE_CONVEX_POLYGON: {
 			case PhysicsServer::SHAPE_CONVEX_POLYGON: {
 				ConvexPolygonShapeBullet *godot_convex = static_cast<ConvexPolygonShapeBullet *>(shape_wrapper->shape);
 				ConvexPolygonShapeBullet *godot_convex = static_cast<ConvexPolygonShapeBullet *>(shape_wrapper->shape);
 				kin_shape_ref = ShapeBullet::create_shape_convex(godot_convex->vertices);
 				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;
 				break;
 			}
 			}
 			case PhysicsServer::SHAPE_RAY: {
 			case PhysicsServer::SHAPE_RAY: {
 				RayShapeBullet *godot_ray = static_cast<RayShapeBullet *>(shape_wrapper->shape);
 				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;
 				break;
 			}
 			}
 			default:
 			default: