Skip to content

Commit

Permalink
Merge pull request #39735 from AndreaCatania/bullet_phy_add_api
Browse files Browse the repository at this point in the history
Added BulletPhysics APIs to return internal objects.
  • Loading branch information
akien-mga authored Jul 7, 2020
2 parents 624eff4 + a2b5e79 commit 480cb25
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 15 deletions.
27 changes: 21 additions & 6 deletions modules/bullet/bullet_physics_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,14 +561,14 @@ void BulletPhysicsServer3D::body_clear_shapes(RID p_body) {
}

void BulletPhysicsServer3D::body_attach_object_instance_id(RID p_body, ObjectID p_id) {
CollisionObjectBullet *body = get_collisin_object(p_body);
CollisionObjectBullet *body = get_collision_object(p_body);
ERR_FAIL_COND(!body);

body->set_instance_id(p_id);
}

ObjectID BulletPhysicsServer3D::body_get_object_instance_id(RID p_body) const {
CollisionObjectBullet *body = get_collisin_object(p_body);
CollisionObjectBullet *body = get_collision_object(p_body);
ERR_FAIL_COND_V(!body, ObjectID());

return body->get_instance_id();
Expand Down Expand Up @@ -1567,7 +1567,17 @@ int BulletPhysicsServer3D::get_process_info(ProcessInfo p_info) {
return 0;
}

CollisionObjectBullet *BulletPhysicsServer3D::get_collisin_object(RID p_object) const {
SpaceBullet *BulletPhysicsServer3D::get_space(RID p_rid) const {
ERR_FAIL_COND_V_MSG(space_owner.owns(p_rid) == false, nullptr, "The RID is not valid.");
return space_owner.getornull(p_rid);
}

ShapeBullet *BulletPhysicsServer3D::get_shape(RID p_rid) const {
ERR_FAIL_COND_V_MSG(shape_owner.owns(p_rid) == false, nullptr, "The RID is not valid.");
return shape_owner.getornull(p_rid);
}

CollisionObjectBullet *BulletPhysicsServer3D::get_collision_object(RID p_object) const {
if (rigid_body_owner.owns(p_object)) {
return rigid_body_owner.getornull(p_object);
}
Expand All @@ -1577,15 +1587,20 @@ CollisionObjectBullet *BulletPhysicsServer3D::get_collisin_object(RID p_object)
if (soft_body_owner.owns(p_object)) {
return soft_body_owner.getornull(p_object);
}
return nullptr;
ERR_FAIL_V_MSG(nullptr, "The RID is no valid.");
}

RigidCollisionObjectBullet *BulletPhysicsServer3D::get_rigid_collisin_object(RID p_object) const {
RigidCollisionObjectBullet *BulletPhysicsServer3D::get_rigid_collision_object(RID p_object) const {
if (rigid_body_owner.owns(p_object)) {
return rigid_body_owner.getornull(p_object);
}
if (area_owner.owns(p_object)) {
return area_owner.getornull(p_object);
}
return nullptr;
ERR_FAIL_V_MSG(nullptr, "The RID is no valid.");
}

JointBullet *BulletPhysicsServer3D::get_joint(RID p_rid) const {
ERR_FAIL_COND_V_MSG(joint_owner.owns(p_rid) == false, nullptr, "The RID is not valid.");
return joint_owner.getornull(p_rid);
}
10 changes: 5 additions & 5 deletions modules/bullet/bullet_physics_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -405,11 +405,11 @@ class BulletPhysicsServer3D : public PhysicsServer3D {

virtual int get_process_info(ProcessInfo p_info);

CollisionObjectBullet *get_collisin_object(RID p_object) const;
RigidCollisionObjectBullet *get_rigid_collisin_object(RID p_object) const;

/// Internal APIs
public:
SpaceBullet *get_space(RID p_rid) const;
ShapeBullet *get_shape(RID p_rid) const;
CollisionObjectBullet *get_collision_object(RID p_object) const;
RigidCollisionObjectBullet *get_rigid_collision_object(RID p_object) const;
JointBullet *get_joint(RID p_rid) const;
};

#endif
2 changes: 1 addition & 1 deletion modules/bullet/space_bullet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ bool BulletPhysicsDirectSpaceState::rest_info(RID p_shape, const Transform &p_sh
}

Vector3 BulletPhysicsDirectSpaceState::get_closest_point_to_object_volume(RID p_object, const Vector3 p_point) const {
RigidCollisionObjectBullet *rigid_object = space->get_physics_server()->get_rigid_collisin_object(p_object);
RigidCollisionObjectBullet *rigid_object = space->get_physics_server()->get_rigid_collision_object(p_object);
ERR_FAIL_COND_V(!rigid_object, Vector3());

btVector3 out_closest_point(0, 0, 0);
Expand Down
9 changes: 6 additions & 3 deletions modules/bullet/space_bullet.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,12 @@ class SpaceBullet : public RIDBullet {
real_t get_delta_time() { return delta_time; }
void step(real_t p_delta_time);

_FORCE_INLINE_ btBroadphaseInterface *get_broadphase() { return broadphase; }
_FORCE_INLINE_ btCollisionDispatcher *get_dispatcher() { return dispatcher; }
_FORCE_INLINE_ btSoftBodyWorldInfo *get_soft_body_world_info() { return soft_body_world_info; }
_FORCE_INLINE_ btBroadphaseInterface *get_broadphase() const { return broadphase; }
_FORCE_INLINE_ btDefaultCollisionConfiguration *get_collision_configuration() const { return collisionConfiguration; }
_FORCE_INLINE_ btCollisionDispatcher *get_dispatcher() const { return dispatcher; }
_FORCE_INLINE_ btConstraintSolver *get_solver() const { return solver; }
_FORCE_INLINE_ btDiscreteDynamicsWorld *get_dynamic_world() const { return dynamicsWorld; }
_FORCE_INLINE_ btSoftBodyWorldInfo *get_soft_body_world_info() const { return soft_body_world_info; }
_FORCE_INLINE_ bool is_using_soft_world() { return soft_body_world_info; }

/// Used to set some parameters to Bullet world
Expand Down

0 comments on commit 480cb25

Please sign in to comment.