diff options
Diffstat (limited to 'modules/bullet')
25 files changed, 232 insertions, 200 deletions
diff --git a/modules/bullet/area_bullet.cpp b/modules/bullet/area_bullet.cpp index 54024b4f90..fad6f52cea 100644 --- a/modules/bullet/area_bullet.cpp +++ b/modules/bullet/area_bullet.cpp @@ -37,19 +37,19 @@ #include "collision_object_bullet.h" #include "space_bullet.h" -AreaBullet::AreaBullet() - : RigidCollisionObjectBullet(CollisionObjectBullet::TYPE_AREA), - monitorable(true), - isScratched(false), - spOv_mode(PhysicsServer::AREA_SPACE_OVERRIDE_DISABLED), - spOv_gravityPoint(false), - spOv_gravityPointDistanceScale(0), - spOv_gravityPointAttenuation(1), - spOv_gravityVec(0, -1, 0), - spOv_gravityMag(10), - spOv_linearDump(0.1), - spOv_angularDump(1), - spOv_priority(0) { +AreaBullet::AreaBullet() : + RigidCollisionObjectBullet(CollisionObjectBullet::TYPE_AREA), + monitorable(true), + isScratched(false), + spOv_mode(PhysicsServer::AREA_SPACE_OVERRIDE_DISABLED), + spOv_gravityPoint(false), + spOv_gravityPointDistanceScale(0), + spOv_gravityPointAttenuation(1), + spOv_gravityVec(0, -1, 0), + spOv_gravityMag(10), + spOv_linearDump(0.1), + spOv_angularDump(1), + spOv_priority(0) { btGhost = bulletnew(btGhostObject); btGhost->setCollisionShape(compoundShape); diff --git a/modules/bullet/area_bullet.h b/modules/bullet/area_bullet.h index f6e3b7e902..95ce62bfed 100644 --- a/modules/bullet/area_bullet.h +++ b/modules/bullet/area_bullet.h @@ -47,8 +47,8 @@ public: ObjectID event_callback_id; StringName event_callback_method; - InOutEventCallback() - : event_callback_id(0) {} + InOutEventCallback() : + event_callback_id(0) {} }; enum OverlapState { @@ -62,10 +62,12 @@ public: CollisionObjectBullet *object; OverlapState state; - OverlappingObjectData() - : object(NULL), state(OVERLAP_STATE_ENTER) {} - OverlappingObjectData(CollisionObjectBullet *p_object, OverlapState p_state) - : object(p_object), state(p_state) {} + OverlappingObjectData() : + object(NULL), + state(OVERLAP_STATE_ENTER) {} + OverlappingObjectData(CollisionObjectBullet *p_object, OverlapState p_state) : + object(p_object), + state(p_state) {} OverlappingObjectData(const OverlappingObjectData &other) { operator=(other); } diff --git a/modules/bullet/btRayShape.cpp b/modules/bullet/btRayShape.cpp index ac95faaac6..bbd2b19677 100644 --- a/modules/bullet/btRayShape.cpp +++ b/modules/bullet/btRayShape.cpp @@ -33,9 +33,9 @@ #include "LinearMath/btAabbUtil2.h" #include "math/math_funcs.h" -btRayShape::btRayShape(btScalar length) - : btConvexInternalShape(), - m_shapeAxis(0, 0, 1) { +btRayShape::btRayShape(btScalar length) : + btConvexInternalShape(), + m_shapeAxis(0, 0, 1) { m_shapeType = CUSTOM_CONVEX_SHAPE_TYPE; setLength(length); } diff --git a/modules/bullet/bullet_physics_server.cpp b/modules/bullet/bullet_physics_server.cpp index 7f95d16ba6..339dccce33 100644 --- a/modules/bullet/bullet_physics_server.cpp +++ b/modules/bullet/bullet_physics_server.cpp @@ -78,10 +78,10 @@ void BulletPhysicsServer::_bind_methods() { //ClassDB::bind_method(D_METHOD("DoTest"), &BulletPhysicsServer::DoTest); } -BulletPhysicsServer::BulletPhysicsServer() - : PhysicsServer(), - active(true), - active_spaces_count(0) {} +BulletPhysicsServer::BulletPhysicsServer() : + PhysicsServer(), + active(true), + active_spaces_count(0) {} BulletPhysicsServer::~BulletPhysicsServer() {} @@ -723,15 +723,15 @@ void BulletPhysicsServer::body_set_axis_velocity(RID p_body, const Vector3 &p_ax body->set_linear_velocity(v); } -void BulletPhysicsServer::body_set_axis_lock(RID p_body, PhysicsServer::BodyAxisLock p_lock) { +void BulletPhysicsServer::body_set_axis_lock(RID p_body, int axis, bool p_lock) { RigidBodyBullet *body = rigid_body_owner.get(p_body); ERR_FAIL_COND(!body); - body->set_axis_lock(p_lock); + body->set_axis_lock(axis, p_lock); } -PhysicsServer::BodyAxisLock BulletPhysicsServer::body_get_axis_lock(RID p_body) const { +bool BulletPhysicsServer::body_get_axis_lock(RID p_body) const { const RigidBodyBullet *body = rigid_body_owner.get(p_body); - ERR_FAIL_COND_V(!body, BODY_AXIS_LOCK_DISABLED); + ERR_FAIL_COND_V(!body, 0); return body->get_axis_lock(); } @@ -798,7 +798,7 @@ bool BulletPhysicsServer::body_is_omitting_force_integration(RID p_body) const { void BulletPhysicsServer::body_set_force_integration_callback(RID p_body, Object *p_receiver, const StringName &p_method, const Variant &p_udata) { RigidBodyBullet *body = rigid_body_owner.get(p_body); ERR_FAIL_COND(!body); - body->set_force_integration_callback(p_receiver->get_instance_id(), p_method, p_udata); + body->set_force_integration_callback(p_receiver ? p_receiver->get_instance_id() : ObjectID(0), p_method, p_udata); } void BulletPhysicsServer::body_set_ray_pickable(RID p_body, bool p_enable) { diff --git a/modules/bullet/bullet_physics_server.h b/modules/bullet/bullet_physics_server.h index ad8137ee2f..ed5acb9041 100644 --- a/modules/bullet/bullet_physics_server.h +++ b/modules/bullet/bullet_physics_server.h @@ -226,8 +226,8 @@ public: virtual void body_apply_torque_impulse(RID p_body, const Vector3 &p_impulse); virtual void body_set_axis_velocity(RID p_body, const Vector3 &p_axis_velocity); - virtual void body_set_axis_lock(RID p_body, BodyAxisLock p_lock); - virtual BodyAxisLock body_get_axis_lock(RID p_body) const; + virtual void body_set_axis_lock(RID p_body, int axis, bool p_lock); + virtual bool body_get_axis_lock(RID p_body) const; virtual void body_add_collision_exception(RID p_body, RID p_body_b); virtual void body_remove_collision_exception(RID p_body, RID p_body_b); diff --git a/modules/bullet/collision_object_bullet.cpp b/modules/bullet/collision_object_bullet.cpp index 5e878b0ee4..da3a4b73cf 100644 --- a/modules/bullet/collision_object_bullet.cpp +++ b/modules/bullet/collision_object_bullet.cpp @@ -50,8 +50,14 @@ void CollisionObjectBullet::ShapeWrapper::set_transform(const btTransform &p_tra transform = p_transform; } -CollisionObjectBullet::CollisionObjectBullet(Type p_type) - : RIDBullet(), space(NULL), type(p_type), collisionsEnabled(true), m_isStatic(false), bt_collision_object(NULL), body_scale(1., 1., 1.) {} +CollisionObjectBullet::CollisionObjectBullet(Type p_type) : + RIDBullet(), + space(NULL), + type(p_type), + collisionsEnabled(true), + m_isStatic(false), + bt_collision_object(NULL), + body_scale(1., 1., 1.) {} CollisionObjectBullet::~CollisionObjectBullet() { // Remove all overlapping @@ -165,8 +171,9 @@ const btTransform &CollisionObjectBullet::get_transform__bullet() const { return bt_collision_object->getWorldTransform(); } -RigidCollisionObjectBullet::RigidCollisionObjectBullet(Type p_type) - : CollisionObjectBullet(p_type), compoundShape(bulletnew(btCompoundShape(enableDynamicAabbTree, initialChildCapacity))) { +RigidCollisionObjectBullet::RigidCollisionObjectBullet(Type p_type) : + CollisionObjectBullet(p_type), + compoundShape(bulletnew(btCompoundShape(enableDynamicAabbTree, initialChildCapacity))) { } RigidCollisionObjectBullet::~RigidCollisionObjectBullet() { diff --git a/modules/bullet/collision_object_bullet.h b/modules/bullet/collision_object_bullet.h index 153b8ea5bc..51e48909e4 100644 --- a/modules/bullet/collision_object_bullet.h +++ b/modules/bullet/collision_object_bullet.h @@ -70,16 +70,22 @@ public: btTransform transform; bool active; - ShapeWrapper() - : shape(NULL), bt_shape(NULL), active(true) {} - - ShapeWrapper(ShapeBullet *p_shape, const btTransform &p_transform, bool p_active) - : shape(p_shape), bt_shape(NULL), active(p_active) { + ShapeWrapper() : + shape(NULL), + bt_shape(NULL), + active(true) {} + + ShapeWrapper(ShapeBullet *p_shape, const btTransform &p_transform, bool p_active) : + shape(p_shape), + bt_shape(NULL), + active(p_active) { set_transform(p_transform); } - ShapeWrapper(ShapeBullet *p_shape, const Transform &p_transform, bool p_active) - : shape(p_shape), bt_shape(NULL), active(p_active) { + ShapeWrapper(ShapeBullet *p_shape, const Transform &p_transform, bool p_active) : + shape(p_shape), + bt_shape(NULL), + active(p_active) { set_transform(p_transform); } ~ShapeWrapper(); diff --git a/modules/bullet/cone_twist_joint_bullet.cpp b/modules/bullet/cone_twist_joint_bullet.cpp index f6ac40e001..7ae5e79645 100644 --- a/modules/bullet/cone_twist_joint_bullet.cpp +++ b/modules/bullet/cone_twist_joint_bullet.cpp @@ -35,8 +35,8 @@ #include "bullet_utilities.h" #include "rigid_body_bullet.h" -ConeTwistJointBullet::ConeTwistJointBullet(RigidBodyBullet *rbA, RigidBodyBullet *rbB, const Transform &rbAFrame, const Transform &rbBFrame) - : JointBullet() { +ConeTwistJointBullet::ConeTwistJointBullet(RigidBodyBullet *rbA, RigidBodyBullet *rbB, const Transform &rbAFrame, const Transform &rbBFrame) : + JointBullet() { btTransform btFrameA; G_TO_B(rbAFrame, btFrameA); if (rbB) { diff --git a/modules/bullet/constraint_bullet.cpp b/modules/bullet/constraint_bullet.cpp index 08fc36f274..505579ce9b 100644 --- a/modules/bullet/constraint_bullet.cpp +++ b/modules/bullet/constraint_bullet.cpp @@ -33,8 +33,9 @@ #include "collision_object_bullet.h" #include "space_bullet.h" -ConstraintBullet::ConstraintBullet() - : space(NULL), constraint(NULL) {} +ConstraintBullet::ConstraintBullet() : + space(NULL), + constraint(NULL) {} void ConstraintBullet::setup(btTypedConstraint *p_constraint) { constraint = p_constraint; diff --git a/modules/bullet/generic_6dof_joint_bullet.cpp b/modules/bullet/generic_6dof_joint_bullet.cpp index 647396c24c..28928bd861 100644 --- a/modules/bullet/generic_6dof_joint_bullet.cpp +++ b/modules/bullet/generic_6dof_joint_bullet.cpp @@ -35,8 +35,8 @@ #include "bullet_utilities.h" #include "rigid_body_bullet.h" -Generic6DOFJointBullet::Generic6DOFJointBullet(RigidBodyBullet *rbA, RigidBodyBullet *rbB, const Transform &frameInA, const Transform &frameInB, bool useLinearReferenceFrameA) - : JointBullet() { +Generic6DOFJointBullet::Generic6DOFJointBullet(RigidBodyBullet *rbA, RigidBodyBullet *rbB, const Transform &frameInA, const Transform &frameInB, bool useLinearReferenceFrameA) : + JointBullet() { btTransform btFrameA; G_TO_B(frameInA, btFrameA); diff --git a/modules/bullet/godot_collision_configuration.cpp b/modules/bullet/godot_collision_configuration.cpp index 4e4228cc48..136fb2ee74 100644 --- a/modules/bullet/godot_collision_configuration.cpp +++ b/modules/bullet/godot_collision_configuration.cpp @@ -34,8 +34,8 @@ #include "BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h" #include "godot_ray_world_algorithm.h" -GodotCollisionConfiguration::GodotCollisionConfiguration(const btDiscreteDynamicsWorld *world, const btDefaultCollisionConstructionInfo &constructionInfo) - : btDefaultCollisionConfiguration(constructionInfo) { +GodotCollisionConfiguration::GodotCollisionConfiguration(const btDiscreteDynamicsWorld *world, const btDefaultCollisionConstructionInfo &constructionInfo) : + btDefaultCollisionConfiguration(constructionInfo) { void *mem = NULL; diff --git a/modules/bullet/godot_collision_dispatcher.cpp b/modules/bullet/godot_collision_dispatcher.cpp index ea75e4eef4..e0ca29a8f3 100644 --- a/modules/bullet/godot_collision_dispatcher.cpp +++ b/modules/bullet/godot_collision_dispatcher.cpp @@ -34,8 +34,8 @@ const int GodotCollisionDispatcher::CASTED_TYPE_AREA = static_cast<int>(CollisionObjectBullet::TYPE_AREA); -GodotCollisionDispatcher::GodotCollisionDispatcher(btCollisionConfiguration *collisionConfiguration) - : btCollisionDispatcher(collisionConfiguration) {} +GodotCollisionDispatcher::GodotCollisionDispatcher(btCollisionConfiguration *collisionConfiguration) : + btCollisionDispatcher(collisionConfiguration) {} bool GodotCollisionDispatcher::needsCollision(const btCollisionObject *body0, const btCollisionObject *body1) { if (body0->getUserIndex() == CASTED_TYPE_AREA || body1->getUserIndex() == CASTED_TYPE_AREA) { diff --git a/modules/bullet/godot_motion_state.h b/modules/bullet/godot_motion_state.h index 5111807394..62ea472446 100644 --- a/modules/bullet/godot_motion_state.h +++ b/modules/bullet/godot_motion_state.h @@ -51,10 +51,10 @@ class GodotMotionState : public btMotionState { RigidBodyBullet *owner; public: - GodotMotionState(RigidBodyBullet *p_owner) - : bodyKinematicWorldTransf(btMatrix3x3(1., 0., 0., 0., 1., 0., 0., 0., 1.), btVector3(0., 0., 0.)), - bodyCurrentWorldTransform(btMatrix3x3(1., 0., 0., 0., 1., 0., 0., 0., 1.), btVector3(0., 0., 0.)), - owner(p_owner) {} + GodotMotionState(RigidBodyBullet *p_owner) : + bodyKinematicWorldTransf(btMatrix3x3(1., 0., 0., 0., 1., 0., 0., 0., 1.), btVector3(0., 0., 0.)), + bodyCurrentWorldTransform(btMatrix3x3(1., 0., 0., 0., 1., 0., 0., 0., 1.), btVector3(0., 0., 0.)), + owner(p_owner) {} /// IMPORTANT DON'T USE THIS FUNCTION TO KNOW THE CURRENT BODY TRANSFORM /// This class is used internally by Bullet diff --git a/modules/bullet/godot_ray_world_algorithm.cpp b/modules/bullet/godot_ray_world_algorithm.cpp index 98daf8398e..ba13903548 100644 --- a/modules/bullet/godot_ray_world_algorithm.cpp +++ b/modules/bullet/godot_ray_world_algorithm.cpp @@ -34,18 +34,18 @@ #include "btRayShape.h" #include "collision_object_bullet.h" -GodotRayWorldAlgorithm::CreateFunc::CreateFunc(const btDiscreteDynamicsWorld *world) - : m_world(world) {} - -GodotRayWorldAlgorithm::SwappedCreateFunc::SwappedCreateFunc(const btDiscreteDynamicsWorld *world) - : m_world(world) {} - -GodotRayWorldAlgorithm::GodotRayWorldAlgorithm(const btDiscreteDynamicsWorld *world, btPersistentManifold *mf, const btCollisionAlgorithmConstructionInfo &ci, const btCollisionObjectWrapper *body0Wrap, const btCollisionObjectWrapper *body1Wrap, bool isSwapped) - : btActivatingCollisionAlgorithm(ci, body0Wrap, body1Wrap), - m_manifoldPtr(mf), - m_ownManifold(false), - m_world(world), - m_isSwapped(isSwapped) {} +GodotRayWorldAlgorithm::CreateFunc::CreateFunc(const btDiscreteDynamicsWorld *world) : + m_world(world) {} + +GodotRayWorldAlgorithm::SwappedCreateFunc::SwappedCreateFunc(const btDiscreteDynamicsWorld *world) : + m_world(world) {} + +GodotRayWorldAlgorithm::GodotRayWorldAlgorithm(const btDiscreteDynamicsWorld *world, btPersistentManifold *mf, const btCollisionAlgorithmConstructionInfo &ci, const btCollisionObjectWrapper *body0Wrap, const btCollisionObjectWrapper *body1Wrap, bool isSwapped) : + btActivatingCollisionAlgorithm(ci, body0Wrap, body1Wrap), + m_manifoldPtr(mf), + m_ownManifold(false), + m_world(world), + m_isSwapped(isSwapped) {} GodotRayWorldAlgorithm::~GodotRayWorldAlgorithm() { if (m_ownManifold && m_manifoldPtr) { diff --git a/modules/bullet/godot_result_callbacks.h b/modules/bullet/godot_result_callbacks.h index ba5142676b..5750dc2acd 100644 --- a/modules/bullet/godot_result_callbacks.h +++ b/modules/bullet/godot_result_callbacks.h @@ -52,8 +52,10 @@ struct GodotClosestRayResultCallback : public btCollisionWorld::ClosestRayResult bool m_pickRay; public: - GodotClosestRayResultCallback(const btVector3 &rayFromWorld, const btVector3 &rayToWorld, const Set<RID> *p_exclude) - : btCollisionWorld::ClosestRayResultCallback(rayFromWorld, rayToWorld), m_exclude(p_exclude), m_pickRay(false) {} + GodotClosestRayResultCallback(const btVector3 &rayFromWorld, const btVector3 &rayToWorld, const Set<RID> *p_exclude) : + btCollisionWorld::ClosestRayResultCallback(rayFromWorld, rayToWorld), + m_exclude(p_exclude), + m_pickRay(false) {} virtual bool needsCollision(btBroadphaseProxy *proxy0) const; }; @@ -66,8 +68,11 @@ public: int count; const Set<RID> *m_exclude; - GodotAllConvexResultCallback(PhysicsDirectSpaceState::ShapeResult *p_results, int p_resultMax, const Set<RID> *p_exclude) - : m_results(p_results), m_exclude(p_exclude), m_resultMax(p_resultMax), count(0) {} + GodotAllConvexResultCallback(PhysicsDirectSpaceState::ShapeResult *p_results, int p_resultMax, const Set<RID> *p_exclude) : + m_results(p_results), + m_exclude(p_exclude), + m_resultMax(p_resultMax), + count(0) {} virtual bool needsCollision(btBroadphaseProxy *proxy0) const; @@ -79,8 +84,10 @@ public: const RigidBodyBullet *m_self_object; const bool m_ignore_areas; - GodotKinClosestConvexResultCallback(const btVector3 &convexFromWorld, const btVector3 &convexToWorld, const RigidBodyBullet *p_self_object, bool p_ignore_areas) - : btCollisionWorld::ClosestConvexResultCallback(convexFromWorld, convexToWorld), m_self_object(p_self_object), m_ignore_areas(p_ignore_areas) {} + GodotKinClosestConvexResultCallback(const btVector3 &convexFromWorld, const btVector3 &convexToWorld, const RigidBodyBullet *p_self_object, bool p_ignore_areas) : + btCollisionWorld::ClosestConvexResultCallback(convexFromWorld, convexToWorld), + m_self_object(p_self_object), + m_ignore_areas(p_ignore_areas) {} virtual bool needsCollision(btBroadphaseProxy *proxy0) const; }; @@ -90,8 +97,9 @@ public: const Set<RID> *m_exclude; int m_shapeId; - GodotClosestConvexResultCallback(const btVector3 &convexFromWorld, const btVector3 &convexToWorld, const Set<RID> *p_exclude) - : btCollisionWorld::ClosestConvexResultCallback(convexFromWorld, convexToWorld), m_exclude(p_exclude) {} + GodotClosestConvexResultCallback(const btVector3 &convexFromWorld, const btVector3 &convexToWorld, const Set<RID> *p_exclude) : + btCollisionWorld::ClosestConvexResultCallback(convexFromWorld, convexToWorld), + m_exclude(p_exclude) {} virtual bool needsCollision(btBroadphaseProxy *proxy0) const; @@ -106,8 +114,12 @@ public: int m_count; const Set<RID> *m_exclude; - GodotAllContactResultCallback(btCollisionObject *p_self_object, PhysicsDirectSpaceState::ShapeResult *p_results, int p_resultMax, const Set<RID> *p_exclude) - : m_self_object(p_self_object), m_results(p_results), m_exclude(p_exclude), m_resultMax(p_resultMax), m_count(0) {} + GodotAllContactResultCallback(btCollisionObject *p_self_object, PhysicsDirectSpaceState::ShapeResult *p_results, int p_resultMax, const Set<RID> *p_exclude) : + m_self_object(p_self_object), + m_results(p_results), + m_exclude(p_exclude), + m_resultMax(p_resultMax), + m_count(0) {} virtual bool needsCollision(btBroadphaseProxy *proxy0) const; @@ -123,8 +135,12 @@ public: int m_count; const Set<RID> *m_exclude; - GodotContactPairContactResultCallback(btCollisionObject *p_self_object, Vector3 *p_results, int p_resultMax, const Set<RID> *p_exclude) - : m_self_object(p_self_object), m_results(p_results), m_exclude(p_exclude), m_resultMax(p_resultMax), m_count(0) {} + GodotContactPairContactResultCallback(btCollisionObject *p_self_object, Vector3 *p_results, int p_resultMax, const Set<RID> *p_exclude) : + m_self_object(p_self_object), + m_results(p_results), + m_exclude(p_exclude), + m_resultMax(p_resultMax), + m_count(0) {} virtual bool needsCollision(btBroadphaseProxy *proxy0) const; @@ -141,8 +157,12 @@ public: btVector3 m_rest_info_bt_point; const Set<RID> *m_exclude; - GodotRestInfoContactResultCallback(btCollisionObject *p_self_object, PhysicsDirectSpaceState::ShapeRestInfo *p_result, const Set<RID> *p_exclude) - : m_self_object(p_self_object), m_result(p_result), m_exclude(p_exclude), m_collided(false), m_min_distance(0) {} + GodotRestInfoContactResultCallback(btCollisionObject *p_self_object, PhysicsDirectSpaceState::ShapeRestInfo *p_result, const Set<RID> *p_exclude) : + m_self_object(p_self_object), + m_result(p_result), + m_exclude(p_exclude), + m_collided(false), + m_min_distance(0) {} virtual bool needsCollision(btBroadphaseProxy *proxy0) const; @@ -158,12 +178,12 @@ struct GodotDeepPenetrationContactResultCallback : public btManifoldResult { btScalar m_most_penetrated_distance; - GodotDeepPenetrationContactResultCallback(const btCollisionObjectWrapper *body0Wrap, const btCollisionObjectWrapper *body1Wrap) - : btManifoldResult(body0Wrap, body1Wrap), - m_pointCollisionObject(NULL), - m_penetration_distance(0), - m_other_compound_shape_index(0), - m_most_penetrated_distance(1e20) {} + GodotDeepPenetrationContactResultCallback(const btCollisionObjectWrapper *body0Wrap, const btCollisionObjectWrapper *body1Wrap) : + btManifoldResult(body0Wrap, body1Wrap), + m_pointCollisionObject(NULL), + m_penetration_distance(0), + m_other_compound_shape_index(0), + m_most_penetrated_distance(1e20) {} void reset() { m_pointCollisionObject = NULL; diff --git a/modules/bullet/hinge_joint_bullet.cpp b/modules/bullet/hinge_joint_bullet.cpp index bb70babd99..d3288807b3 100644 --- a/modules/bullet/hinge_joint_bullet.cpp +++ b/modules/bullet/hinge_joint_bullet.cpp @@ -35,8 +35,8 @@ #include "bullet_utilities.h" #include "rigid_body_bullet.h" -HingeJointBullet::HingeJointBullet(RigidBodyBullet *rbA, RigidBodyBullet *rbB, const Transform &frameA, const Transform &frameB) - : JointBullet() { +HingeJointBullet::HingeJointBullet(RigidBodyBullet *rbA, RigidBodyBullet *rbB, const Transform &frameA, const Transform &frameB) : + JointBullet() { btTransform btFrameA; G_TO_B(frameA, btFrameA); @@ -53,8 +53,8 @@ HingeJointBullet::HingeJointBullet(RigidBodyBullet *rbA, RigidBodyBullet *rbB, c setup(hingeConstraint); } -HingeJointBullet::HingeJointBullet(RigidBodyBullet *rbA, RigidBodyBullet *rbB, const Vector3 &pivotInA, const Vector3 &pivotInB, const Vector3 &axisInA, const Vector3 &axisInB) - : JointBullet() { +HingeJointBullet::HingeJointBullet(RigidBodyBullet *rbA, RigidBodyBullet *rbB, const Vector3 &pivotInA, const Vector3 &pivotInB, const Vector3 &axisInA, const Vector3 &axisInB) : + JointBullet() { btVector3 btPivotA; btVector3 btAxisA; diff --git a/modules/bullet/joint_bullet.cpp b/modules/bullet/joint_bullet.cpp index be544f89bf..c8d91aa257 100644 --- a/modules/bullet/joint_bullet.cpp +++ b/modules/bullet/joint_bullet.cpp @@ -32,7 +32,7 @@ #include "joint_bullet.h" #include "space_bullet.h" -JointBullet::JointBullet() - : ConstraintBullet() {} +JointBullet::JointBullet() : + ConstraintBullet() {} JointBullet::~JointBullet() {} diff --git a/modules/bullet/pin_joint_bullet.cpp b/modules/bullet/pin_joint_bullet.cpp index cd9e9a4557..8c74fcbc94 100644 --- a/modules/bullet/pin_joint_bullet.cpp +++ b/modules/bullet/pin_joint_bullet.cpp @@ -34,8 +34,8 @@ #include "bullet_types_converter.h" #include "rigid_body_bullet.h" -PinJointBullet::PinJointBullet(RigidBodyBullet *p_body_a, const Vector3 &p_pos_a, RigidBodyBullet *p_body_b, const Vector3 &p_pos_b) - : JointBullet() { +PinJointBullet::PinJointBullet(RigidBodyBullet *p_body_a, const Vector3 &p_pos_a, RigidBodyBullet *p_body_b, const Vector3 &p_pos_b) : + JointBullet() { if (p_body_b) { btVector3 btPivotA; diff --git a/modules/bullet/rigid_body_bullet.cpp b/modules/bullet/rigid_body_bullet.cpp index f5ab8221e3..843bdab31f 100644 --- a/modules/bullet/rigid_body_bullet.cpp +++ b/modules/bullet/rigid_body_bullet.cpp @@ -176,9 +176,9 @@ PhysicsDirectSpaceState *BulletPhysicsDirectBodyState::get_space_state() { return body->get_space()->get_direct_state(); } -RigidBodyBullet::KinematicUtilities::KinematicUtilities(RigidBodyBullet *p_owner) - : owner(p_owner), - safe_margin(0.001) { +RigidBodyBullet::KinematicUtilities::KinematicUtilities(RigidBodyBullet *p_owner) : + owner(p_owner), + safe_margin(0.001) { } RigidBodyBullet::KinematicUtilities::~KinematicUtilities() { @@ -250,22 +250,22 @@ void RigidBodyBullet::KinematicUtilities::just_delete_shapes(int new_size) { shapes.resize(new_size); } -RigidBodyBullet::RigidBodyBullet() - : RigidCollisionObjectBullet(CollisionObjectBullet::TYPE_RIGID_BODY), - kinematic_utilities(NULL), - gravity_scale(1), - mass(1), - linearDamp(0), - angularDamp(0), - can_sleep(true), - force_integration_callback(NULL), - isTransformChanged(false), - maxCollisionsDetection(0), - collisionsCount(0), - maxAreasWhereIam(10), - areaWhereIamCount(0), - countGravityPointSpaces(0), - isScratchedSpaceOverrideModificator(false) { +RigidBodyBullet::RigidBodyBullet() : + RigidCollisionObjectBullet(CollisionObjectBullet::TYPE_RIGID_BODY), + kinematic_utilities(NULL), + gravity_scale(1), + mass(1), + linearDamp(0), + angularDamp(0), + can_sleep(true), + force_integration_callback(NULL), + isTransformChanged(false), + maxCollisionsDetection(0), + collisionsCount(0), + maxAreasWhereIam(10), + areaWhereIamCount(0), + countGravityPointSpaces(0), + isScratchedSpaceOverrideModificator(false) { godotMotionState = bulletnew(GodotMotionState(this)); @@ -277,7 +277,7 @@ RigidBodyBullet::RigidBodyBullet() setupBulletCollisionObject(btBody); set_mode(PhysicsServer::BODY_MODE_RIGID); - set_axis_lock(PhysicsServer::BODY_AXIS_LOCK_DISABLED); + set_axis_lock(0, locked_axis[0]); areasWhereIam.resize(maxAreasWhereIam); for (int i = areasWhereIam.size() - 1; 0 <= i; --i) { @@ -498,25 +498,25 @@ void RigidBodyBullet::set_mode(PhysicsServer::BodyMode p_mode) { switch (p_mode) { case PhysicsServer::BODY_MODE_KINEMATIC: mode = PhysicsServer::BODY_MODE_KINEMATIC; - set_axis_lock(axis_lock); // Reload axis lock + set_axis_lock(0, locked_axis[0]); // Reload axis lock _internal_set_mass(0); init_kinematic_utilities(); break; case PhysicsServer::BODY_MODE_STATIC: mode = PhysicsServer::BODY_MODE_STATIC; - set_axis_lock(axis_lock); // Reload axis lock + set_axis_lock(0, locked_axis[0]); // Reload axis lock _internal_set_mass(0); break; case PhysicsServer::BODY_MODE_RIGID: { mode = PhysicsServer::BODY_MODE_RIGID; - set_axis_lock(axis_lock); // Reload axis lock + set_axis_lock(0, locked_axis[0]); // Reload axis lock _internal_set_mass(0 == mass ? 1 : mass); scratch_space_override_modificator(); break; } case PhysicsServer::BODY_MODE_CHARACTER: { mode = PhysicsServer::BODY_MODE_CHARACTER; - set_axis_lock(axis_lock); // Reload axis lock + set_axis_lock(0, locked_axis[0]); // Reload axis lock _internal_set_mass(0 == mass ? 1 : mass); scratch_space_override_modificator(); break; @@ -655,22 +655,14 @@ Vector3 RigidBodyBullet::get_applied_torque() const { return gTotTorq; } -void RigidBodyBullet::set_axis_lock(PhysicsServer::BodyAxisLock p_lock) { - axis_lock = p_lock; +void RigidBodyBullet::set_axis_lock(int axis, bool p_lock) { + locked_axis[axis] = p_lock; - if (PhysicsServer::BODY_AXIS_LOCK_DISABLED == axis_lock) { - btBody->setLinearFactor(btVector3(1., 1., 1.)); + btBody->setLinearFactor(btVector3(locked_axis[0] ? 0 : 1., locked_axis[1] ? 0 : 1., locked_axis[2] ? 0 : 1.)); + if (locked_axis[0] || locked_axis[1] || locked_axis[2]) + btBody->setAngularFactor(btVector3(locked_axis[0] ? 1. : 0, locked_axis[1] ? 1. : 0, locked_axis[2] ? 1. : 0)); + else btBody->setAngularFactor(btVector3(1., 1., 1.)); - } else if (PhysicsServer::BODY_AXIS_LOCK_X == axis_lock) { - btBody->setLinearFactor(btVector3(0., 1., 1.)); - btBody->setAngularFactor(btVector3(1., 0., 0.)); - } else if (PhysicsServer::BODY_AXIS_LOCK_Y == axis_lock) { - btBody->setLinearFactor(btVector3(1., 0., 1.)); - btBody->setAngularFactor(btVector3(0., 1., 0.)); - } else if (PhysicsServer::BODY_AXIS_LOCK_Z == axis_lock) { - btBody->setLinearFactor(btVector3(1., 1., 0.)); - btBody->setAngularFactor(btVector3(0., 0., 1.)); - } if (PhysicsServer::BODY_MODE_CHARACTER == mode) { /// When character lock angular @@ -678,17 +670,8 @@ void RigidBodyBullet::set_axis_lock(PhysicsServer::BodyAxisLock p_lock) { } } -PhysicsServer::BodyAxisLock RigidBodyBullet::get_axis_lock() const { - btVector3 vec = btBody->getLinearFactor(); - if (0. == vec.x()) { - return PhysicsServer::BODY_AXIS_LOCK_X; - } else if (0. == vec.y()) { - return PhysicsServer::BODY_AXIS_LOCK_Y; - } else if (0. == vec.z()) { - return PhysicsServer::BODY_AXIS_LOCK_Z; - } else { - return PhysicsServer::BODY_AXIS_LOCK_DISABLED; - } +bool RigidBodyBullet::get_axis_lock() const { + return locked_axis; } void RigidBodyBullet::set_continuous_collision_detection(bool p_enable) { diff --git a/modules/bullet/rigid_body_bullet.h b/modules/bullet/rigid_body_bullet.h index ab3c3e58b2..fde8b21e17 100644 --- a/modules/bullet/rigid_body_bullet.h +++ b/modules/bullet/rigid_body_bullet.h @@ -156,8 +156,8 @@ public: class btConvexShape *shape; btTransform transform; - KinematicShape() - : shape(NULL) {} + KinematicShape() : + shape(NULL) {} const bool is_active() const { return shape; } }; @@ -184,7 +184,7 @@ private: KinematicUtilities *kinematic_utilities; PhysicsServer::BodyMode mode; - PhysicsServer::BodyAxisLock axis_lock; + bool locked_axis[3] = { false, false, false }; GodotMotionState *godotMotionState; btRigidBody *btBody; real_t mass; @@ -269,8 +269,8 @@ public: void set_applied_torque(const Vector3 &p_torque); Vector3 get_applied_torque() const; - void set_axis_lock(PhysicsServer::BodyAxisLock p_lock); - PhysicsServer::BodyAxisLock get_axis_lock() const; + void set_axis_lock(int axis, bool p_lock); + bool get_axis_lock() const; /// Doc: /// http://www.bulletphysics.org/mediawiki-1.5.8/index.php?title=Anti_tunneling_by_Motion_Clamping diff --git a/modules/bullet/shape_bullet.cpp b/modules/bullet/shape_bullet.cpp index f51af93a31..572a3b4476 100644 --- a/modules/bullet/shape_bullet.cpp +++ b/modules/bullet/shape_bullet.cpp @@ -130,8 +130,8 @@ btRayShape *ShapeBullet::create_shape_ray(real_t p_length) { /* PLANE */ -PlaneShapeBullet::PlaneShapeBullet() - : ShapeBullet() {} +PlaneShapeBullet::PlaneShapeBullet() : + ShapeBullet() {} void PlaneShapeBullet::set_data(const Variant &p_data) { setup(p_data); @@ -158,8 +158,8 @@ btCollisionShape *PlaneShapeBullet::create_bt_shape() { /* Sphere */ -SphereShapeBullet::SphereShapeBullet() - : ShapeBullet() {} +SphereShapeBullet::SphereShapeBullet() : + ShapeBullet() {} void SphereShapeBullet::set_data(const Variant &p_data) { setup(p_data); @@ -183,8 +183,8 @@ btCollisionShape *SphereShapeBullet::create_bt_shape() { } /* Box */ -BoxShapeBullet::BoxShapeBullet() - : ShapeBullet() {} +BoxShapeBullet::BoxShapeBullet() : + ShapeBullet() {} void BoxShapeBullet::set_data(const Variant &p_data) { setup(p_data); @@ -211,8 +211,8 @@ btCollisionShape *BoxShapeBullet::create_bt_shape() { /* Capsule */ -CapsuleShapeBullet::CapsuleShapeBullet() - : ShapeBullet() {} +CapsuleShapeBullet::CapsuleShapeBullet() : + ShapeBullet() {} void CapsuleShapeBullet::set_data(const Variant &p_data) { Dictionary d = p_data; @@ -244,8 +244,8 @@ btCollisionShape *CapsuleShapeBullet::create_bt_shape() { /* Convex polygon */ -ConvexPolygonShapeBullet::ConvexPolygonShapeBullet() - : ShapeBullet() {} +ConvexPolygonShapeBullet::ConvexPolygonShapeBullet() : + ShapeBullet() {} void ConvexPolygonShapeBullet::set_data(const Variant &p_data) { setup(p_data); @@ -286,8 +286,9 @@ btCollisionShape *ConvexPolygonShapeBullet::create_bt_shape() { /* Concave polygon */ -ConcavePolygonShapeBullet::ConcavePolygonShapeBullet() - : ShapeBullet(), meshShape(NULL) {} +ConcavePolygonShapeBullet::ConcavePolygonShapeBullet() : + ShapeBullet(), + meshShape(NULL) {} ConcavePolygonShapeBullet::~ConcavePolygonShapeBullet() { if (meshShape) { @@ -359,8 +360,8 @@ btCollisionShape *ConcavePolygonShapeBullet::create_bt_shape() { /* Height map shape */ -HeightMapShapeBullet::HeightMapShapeBullet() - : ShapeBullet() {} +HeightMapShapeBullet::HeightMapShapeBullet() : + ShapeBullet() {} void HeightMapShapeBullet::set_data(const Variant &p_data) { ERR_FAIL_COND(p_data.get_type() != Variant::DICTIONARY); @@ -411,8 +412,9 @@ btCollisionShape *HeightMapShapeBullet::create_bt_shape() { } /* Ray shape */ -RayShapeBullet::RayShapeBullet() - : ShapeBullet(), length(1) {} +RayShapeBullet::RayShapeBullet() : + ShapeBullet(), + length(1) {} void RayShapeBullet::set_data(const Variant &p_data) { setup(p_data); diff --git a/modules/bullet/slider_joint_bullet.cpp b/modules/bullet/slider_joint_bullet.cpp index 2da65677f5..f1d60679ec 100644 --- a/modules/bullet/slider_joint_bullet.cpp +++ b/modules/bullet/slider_joint_bullet.cpp @@ -35,8 +35,8 @@ #include "bullet_utilities.h" #include "rigid_body_bullet.h" -SliderJointBullet::SliderJointBullet(RigidBodyBullet *rbA, RigidBodyBullet *rbB, const Transform &frameInA, const Transform &frameInB) - : JointBullet() { +SliderJointBullet::SliderJointBullet(RigidBodyBullet *rbA, RigidBodyBullet *rbB, const Transform &frameInA, const Transform &frameInB) : + JointBullet() { btTransform btFrameA; G_TO_B(frameInA, btFrameA); if (rbB) { diff --git a/modules/bullet/soft_body_bullet.cpp b/modules/bullet/soft_body_bullet.cpp index 64ef7bfad2..ef5c8cac6f 100644 --- a/modules/bullet/soft_body_bullet.cpp +++ b/modules/bullet/soft_body_bullet.cpp @@ -36,8 +36,18 @@ #include "scene/3d/immediate_geometry.h" -SoftBodyBullet::SoftBodyBullet() - : CollisionObjectBullet(CollisionObjectBullet::TYPE_SOFT_BODY), mass(1), simulation_precision(5), stiffness(0.5f), pressure_coefficient(50), damping_coefficient(0.005), drag_coefficient(0.005), bt_soft_body(NULL), soft_shape_type(SOFT_SHAPETYPE_NONE), isScratched(false), soft_body_shape_data(NULL) { +SoftBodyBullet::SoftBodyBullet() : + CollisionObjectBullet(CollisionObjectBullet::TYPE_SOFT_BODY), + mass(1), + simulation_precision(5), + stiffness(0.5f), + pressure_coefficient(50), + damping_coefficient(0.005), + drag_coefficient(0.005), + bt_soft_body(NULL), + soft_shape_type(SOFT_SHAPETYPE_NONE), + isScratched(false), + soft_body_shape_data(NULL) { test_geometry = memnew(ImmediateGeometry); diff --git a/modules/bullet/space_bullet.cpp b/modules/bullet/space_bullet.cpp index d8c8cab17a..c1f6e81734 100644 --- a/modules/bullet/space_bullet.cpp +++ b/modules/bullet/space_bullet.cpp @@ -50,8 +50,9 @@ #include "ustring.h" #include <assert.h> -BulletPhysicsDirectSpaceState::BulletPhysicsDirectSpaceState(SpaceBullet *p_space) - : PhysicsDirectSpaceState(), space(p_space) {} +BulletPhysicsDirectSpaceState::BulletPhysicsDirectSpaceState(SpaceBullet *p_space) : + PhysicsDirectSpaceState(), + space(p_space) {} int BulletPhysicsDirectSpaceState::intersect_point(const Vector3 &p_point, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude, uint32_t p_collision_mask) { @@ -330,18 +331,18 @@ Vector3 BulletPhysicsDirectSpaceState::get_closest_point_to_object_volume(RID p_ } } -SpaceBullet::SpaceBullet(bool p_create_soft_world) - : broadphase(NULL), - dispatcher(NULL), - solver(NULL), - collisionConfiguration(NULL), - dynamicsWorld(NULL), - soft_body_world_info(NULL), - ghostPairCallback(NULL), - godotFilterCallback(NULL), - gravityDirection(0, -1, 0), - gravityMagnitude(10), - contactDebugCount(0) { +SpaceBullet::SpaceBullet(bool p_create_soft_world) : + broadphase(NULL), + dispatcher(NULL), + solver(NULL), + collisionConfiguration(NULL), + dynamicsWorld(NULL), + soft_body_world_info(NULL), + ghostPairCallback(NULL), + godotFilterCallback(NULL), + gravityDirection(0, -1, 0), + gravityMagnitude(10), + contactDebugCount(0) { create_empty_world(p_create_soft_world); direct_access = memnew(BulletPhysicsDirectSpaceState(this)); @@ -939,14 +940,14 @@ bool SpaceBullet::test_body_motion(RigidBodyBullet *p_body, const Transform &p_f r_result->collider_shape = r_recover_result.other_compound_shape_index; r_result->collision_local_shape = r_recover_result.local_shape_most_recovered; -//{ /// Add manifold point to manage collisions -// btPersistentManifold* manifold = dynamicsWorld->getDispatcher()->getNewManifold(p_body->getBtBody(), btRigid); -// btManifoldPoint manifoldPoint(result_callabck.m_pointWorld, result_callabck.m_pointWorld, result_callabck.m_pointNormalWorld, result_callabck.m_penetration_distance); -// manifoldPoint.m_index0 = r_result->collision_local_shape; -// manifoldPoint.m_index1 = r_result->collider_shape; -// manifold->addManifoldPoint(manifoldPoint); -// p_body->get_kinematic_utilities()->m_generatedManifold.push_back(manifold); -//} + //{ /// Add manifold point to manage collisions + // btPersistentManifold* manifold = dynamicsWorld->getDispatcher()->getNewManifold(p_body->getBtBody(), btRigid); + // btManifoldPoint manifoldPoint(result_callabck.m_pointWorld, result_callabck.m_pointWorld, result_callabck.m_pointNormalWorld, result_callabck.m_penetration_distance); + // manifoldPoint.m_index0 = r_result->collision_local_shape; + // manifoldPoint.m_index1 = r_result->collider_shape; + // manifold->addManifoldPoint(manifoldPoint); + // p_body->get_kinematic_utilities()->m_generatedManifold.push_back(manifold); + //} #if debug_test_motion Vector3 sup_line2; @@ -979,10 +980,10 @@ public: Vector<btCollisionObject *> result_collision_objects; public: - RecoverPenetrationBroadPhaseCallback(const btCollisionObject *p_self_collision_object, uint32_t p_collision_layer, uint32_t p_collision_mask) - : self_collision_object(p_self_collision_object), - collision_layer(p_collision_layer), - collision_mask(p_collision_mask) {} + RecoverPenetrationBroadPhaseCallback(const btCollisionObject *p_self_collision_object, uint32_t p_collision_layer, uint32_t p_collision_mask) : + self_collision_object(p_self_collision_object), + collision_layer(p_collision_layer), + collision_mask(p_collision_mask) {} virtual ~RecoverPenetrationBroadPhaseCallback() {} diff --git a/modules/bullet/space_bullet.h b/modules/bullet/space_bullet.h index 99bcfb8563..e5267c01a9 100644 --- a/modules/bullet/space_bullet.h +++ b/modules/bullet/space_bullet.h @@ -185,8 +185,8 @@ private: const btCollisionObject *other_collision_object; int local_shape_most_recovered; - RecoverResult() - : hasPenetration(false) {} + RecoverResult() : + hasPenetration(false) {} }; bool recover_from_penetration(RigidBodyBullet *p_body, const btTransform &p_from, btVector3 &r_recover_position, RecoverResult *r_recover_result = NULL); |