diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2018-02-19 20:22:18 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-19 20:22:18 +0100 |
commit | be67f2e4ba1bc2d36a9705328cf0b87aada9c3d7 (patch) | |
tree | 04c428098201e3baa8555f0733d43ce8ad90f0c1 | |
parent | 6d99975707e51b5925c847fac4e88a55d5981408 (diff) | |
parent | a930797c31d4ee1a00e03cfc1055fd4cb8af9a14 (diff) |
Merge pull request #16751 from AndreaCatania/moreAPIs
Added Physics state APIs
-rw-r--r-- | modules/bullet/rigid_body_bullet.cpp | 8 | ||||
-rw-r--r-- | modules/bullet/rigid_body_bullet.h | 2 | ||||
-rw-r--r-- | servers/physics/body_sw.h | 11 | ||||
-rw-r--r-- | servers/physics_server.cpp | 2 | ||||
-rw-r--r-- | servers/physics_server.h | 2 |
5 files changed, 25 insertions, 0 deletions
diff --git a/modules/bullet/rigid_body_bullet.cpp b/modules/bullet/rigid_body_bullet.cpp index f96218ef46..75b4cc054a 100644 --- a/modules/bullet/rigid_body_bullet.cpp +++ b/modules/bullet/rigid_body_bullet.cpp @@ -114,10 +114,18 @@ Transform BulletPhysicsDirectBodyState::get_transform() const { return body->get_transform(); } +void BulletPhysicsDirectBodyState::add_central_force(const Vector3 &p_force) { + body->apply_central_force(p_force); +} + void BulletPhysicsDirectBodyState::add_force(const Vector3 &p_force, const Vector3 &p_pos) { body->apply_force(p_force, p_pos); } +void BulletPhysicsDirectBodyState::add_torque(const Vector3 &p_torque) { + body->apply_torque(p_torque); +} + void BulletPhysicsDirectBodyState::apply_impulse(const Vector3 &p_pos, const Vector3 &p_j) { body->apply_impulse(p_pos, p_j); } diff --git a/modules/bullet/rigid_body_bullet.h b/modules/bullet/rigid_body_bullet.h index c4a9676bdd..2d529f6dc7 100644 --- a/modules/bullet/rigid_body_bullet.h +++ b/modules/bullet/rigid_body_bullet.h @@ -110,7 +110,9 @@ public: virtual void set_transform(const Transform &p_transform); virtual Transform get_transform() const; + virtual void add_central_force(const Vector3 &p_force); virtual void add_force(const Vector3 &p_force, const Vector3 &p_pos); + virtual void add_torque(const Vector3 &p_torque); virtual void apply_impulse(const Vector3 &p_pos, const Vector3 &p_j); virtual void apply_torque_impulse(const Vector3 &p_j); diff --git a/servers/physics/body_sw.h b/servers/physics/body_sw.h index e8ea5531e5..fd2ab16b84 100644 --- a/servers/physics/body_sw.h +++ b/servers/physics/body_sw.h @@ -245,12 +245,21 @@ public: biased_angular_velocity += _inv_inertia_tensor.xform(p_j); } + _FORCE_INLINE_ void add_central_force(const Vector3 &p_force) { + + applied_force += p_force; + } + _FORCE_INLINE_ void add_force(const Vector3 &p_force, const Vector3 &p_pos) { applied_force += p_force; applied_torque += p_pos.cross(p_force); } + _FORCE_INLINE_ void add_torque(const Vector3 &p_torque) { + applied_torque += p_torque; + } + void set_active(bool p_active); _FORCE_INLINE_ bool is_active() const { return active; } @@ -401,7 +410,9 @@ public: virtual void set_transform(const Transform &p_transform) { body->set_state(PhysicsServer::BODY_STATE_TRANSFORM, p_transform); } virtual Transform get_transform() const { return body->get_transform(); } + virtual void add_central_force(const Vector3 &p_force) { body->add_central_force(p_force); } virtual void add_force(const Vector3 &p_force, const Vector3 &p_pos) { body->add_force(p_force, p_pos); } + virtual void add_torque(const Vector3 &p_torque) { body->add_torque(p_torque); } virtual void apply_impulse(const Vector3 &p_pos, const Vector3 &p_j) { body->apply_impulse(p_pos, p_j); } virtual void apply_torque_impulse(const Vector3 &p_j) { body->apply_torque_impulse(p_j); } diff --git a/servers/physics_server.cpp b/servers/physics_server.cpp index 9d4807fcf0..db5e14043c 100644 --- a/servers/physics_server.cpp +++ b/servers/physics_server.cpp @@ -92,7 +92,9 @@ void PhysicsDirectBodyState::_bind_methods() { ClassDB::bind_method(D_METHOD("set_transform", "transform"), &PhysicsDirectBodyState::set_transform); ClassDB::bind_method(D_METHOD("get_transform"), &PhysicsDirectBodyState::get_transform); + ClassDB::bind_method(D_METHOD("add_central_force", "force"), &PhysicsDirectBodyState::add_central_force); ClassDB::bind_method(D_METHOD("add_force", "force", "position"), &PhysicsDirectBodyState::add_force); + ClassDB::bind_method(D_METHOD("add_torque", "torque"), &PhysicsDirectBodyState::add_torque); ClassDB::bind_method(D_METHOD("apply_impulse", "position", "j"), &PhysicsDirectBodyState::apply_impulse); ClassDB::bind_method(D_METHOD("apply_torqe_impulse", "j"), &PhysicsDirectBodyState::apply_torque_impulse); diff --git a/servers/physics_server.h b/servers/physics_server.h index 2ac405293e..c21aa32f6c 100644 --- a/servers/physics_server.h +++ b/servers/physics_server.h @@ -63,7 +63,9 @@ public: virtual void set_transform(const Transform &p_transform) = 0; virtual Transform get_transform() const = 0; + virtual void add_central_force(const Vector3 &p_force) = 0; virtual void add_force(const Vector3 &p_force, const Vector3 &p_pos) = 0; + virtual void add_torque(const Vector3 &p_torque) = 0; virtual void apply_impulse(const Vector3 &p_pos, const Vector3 &p_j) = 0; virtual void apply_torque_impulse(const Vector3 &p_j) = 0; |