Merge pull request #16424 from AndreaCatania/phyj

Added physics API in order to enable/disable collisions between rigidbody attached to a joint with bullet physics bullet
This commit is contained in:
Rémi Verschelde 2018-02-13 15:26:04 +01:00 committed by GitHub
commit eefb58a892
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 121 additions and 13 deletions

View file

@ -70,8 +70,8 @@
return RID(); \
}
#define AddJointToSpace(body, joint, disableCollisionsBetweenLinkedBodies) \
body->get_space()->add_constraint(joint, disableCollisionsBetweenLinkedBodies);
#define AddJointToSpace(body, joint) \
body->get_space()->add_constraint(joint, joint->is_disabled_collisions_between_bodies());
// <--------------- Joint creation asserts
btEmptyShape *BulletPhysicsServer::emptyShape(ShapeBullet::create_shape_empty());
@ -987,6 +987,20 @@ int BulletPhysicsServer::joint_get_solver_priority(RID p_joint) const {
return 0;
}
void BulletPhysicsServer::joint_disable_collisions_between_bodies(RID p_joint, const bool p_disable) {
JointBullet *joint = joint_owner.get(p_joint);
ERR_FAIL_COND(!joint);
joint->disable_collisions_between_bodies(p_disable);
}
bool BulletPhysicsServer::joint_is_disabled_collisions_between_bodies(RID p_joint) const {
JointBullet *joint(joint_owner.get(p_joint));
ERR_FAIL_COND_V(!joint, false);
return joint->is_disabled_collisions_between_bodies();
}
RID BulletPhysicsServer::joint_create_pin(RID p_body_A, const Vector3 &p_local_A, RID p_body_B, const Vector3 &p_local_B) {
RigidBodyBullet *body_A = rigid_body_owner.get(p_body_A);
ERR_FAIL_COND_V(!body_A, RID());
@ -1003,7 +1017,7 @@ RID BulletPhysicsServer::joint_create_pin(RID p_body_A, const Vector3 &p_local_A
ERR_FAIL_COND_V(body_A == body_B, RID());
JointBullet *joint = bulletnew(PinJointBullet(body_A, p_local_A, body_B, p_local_B));
AddJointToSpace(body_A, joint, true);
AddJointToSpace(body_A, joint);
CreateThenReturnRID(joint_owner, joint);
}
@ -1071,7 +1085,7 @@ RID BulletPhysicsServer::joint_create_hinge(RID p_body_A, const Transform &p_hin
ERR_FAIL_COND_V(body_A == body_B, RID());
JointBullet *joint = bulletnew(HingeJointBullet(body_A, body_B, p_hinge_A, p_hinge_B));
AddJointToSpace(body_A, joint, true);
AddJointToSpace(body_A, joint);
CreateThenReturnRID(joint_owner, joint);
}
@ -1091,7 +1105,7 @@ RID BulletPhysicsServer::joint_create_hinge_simple(RID p_body_A, const Vector3 &
ERR_FAIL_COND_V(body_A == body_B, RID());
JointBullet *joint = bulletnew(HingeJointBullet(body_A, body_B, p_pivot_A, p_pivot_B, p_axis_A, p_axis_B));
AddJointToSpace(body_A, joint, true);
AddJointToSpace(body_A, joint);
CreateThenReturnRID(joint_owner, joint);
}
@ -1143,7 +1157,7 @@ RID BulletPhysicsServer::joint_create_slider(RID p_body_A, const Transform &p_lo
ERR_FAIL_COND_V(body_A == body_B, RID());
JointBullet *joint = bulletnew(SliderJointBullet(body_A, body_B, p_local_frame_A, p_local_frame_B));
AddJointToSpace(body_A, joint, true);
AddJointToSpace(body_A, joint);
CreateThenReturnRID(joint_owner, joint);
}
@ -1177,7 +1191,7 @@ RID BulletPhysicsServer::joint_create_cone_twist(RID p_body_A, const Transform &
}
JointBullet *joint = bulletnew(ConeTwistJointBullet(body_A, body_B, p_local_frame_A, p_local_frame_B));
AddJointToSpace(body_A, joint, true);
AddJointToSpace(body_A, joint);
CreateThenReturnRID(joint_owner, joint);
}
@ -1213,7 +1227,7 @@ RID BulletPhysicsServer::joint_create_generic_6dof(RID p_body_A, const Transform
ERR_FAIL_COND_V(body_A == body_B, RID());
JointBullet *joint = bulletnew(Generic6DOFJointBullet(body_A, body_B, p_local_frame_A, p_local_frame_B, true));
AddJointToSpace(body_A, joint, true);
AddJointToSpace(body_A, joint);
CreateThenReturnRID(joint_owner, joint);
}

View file

@ -290,6 +290,9 @@ public:
virtual void joint_set_solver_priority(RID p_joint, int p_priority);
virtual int joint_get_solver_priority(RID p_joint) const;
virtual void joint_disable_collisions_between_bodies(RID p_joint, const bool p_disable);
virtual bool joint_is_disabled_collisions_between_bodies(RID p_joint) const;
virtual RID joint_create_pin(RID p_body_A, const Vector3 &p_local_A, RID p_body_B, const Vector3 &p_local_B);
virtual void pin_joint_set_param(RID p_joint, PinJointParam p_param, float p_value);

View file

@ -39,7 +39,8 @@
ConstraintBullet::ConstraintBullet() :
space(NULL),
constraint(NULL) {}
constraint(NULL),
disabled_collisions_between_bodies(true) {}
void ConstraintBullet::setup(btTypedConstraint *p_constraint) {
constraint = p_constraint;
@ -53,3 +54,12 @@ void ConstraintBullet::set_space(SpaceBullet *p_space) {
void ConstraintBullet::destroy_internal_constraint() {
space->remove_constraint(this);
}
void ConstraintBullet::disable_collisions_between_bodies(const bool p_disabled) {
disabled_collisions_between_bodies = p_disabled;
if (space) {
space->remove_constraint(this);
space->add_constraint(this, disabled_collisions_between_bodies);
}
}

View file

@ -49,6 +49,7 @@ class ConstraintBullet : public RIDBullet {
protected:
SpaceBullet *space;
btTypedConstraint *constraint;
bool disabled_collisions_between_bodies;
public:
ConstraintBullet();
@ -57,6 +58,9 @@ public:
virtual void set_space(SpaceBullet *p_space);
virtual void destroy_internal_constraint();
void disable_collisions_between_bodies(const bool p_disabled);
_FORCE_INLINE_ bool is_disabled_collisions_between_bodies() const { return disabled_collisions_between_bodies; }
public:
virtual ~ConstraintBullet() {
bulletdelete(constraint);