summaryrefslogtreecommitdiff
path: root/servers
diff options
context:
space:
mode:
authorAndrea Catania <info@andreacatania.com>2018-02-16 17:48:07 +0100
committerAndrea Catania <info@andreacatania.com>2018-02-16 17:48:07 +0100
commita930797c31d4ee1a00e03cfc1055fd4cb8af9a14 (patch)
treec6cae5e080a6f9170e5831cbcf3caa021aaea4e1 /servers
parentda612c324cec8c4f6bfcef9b35406ea215e699f6 (diff)
Added Physics state APIs
Diffstat (limited to 'servers')
-rw-r--r--servers/physics/body_sw.h11
-rw-r--r--servers/physics_server.cpp2
-rw-r--r--servers/physics_server.h2
3 files changed, 15 insertions, 0 deletions
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;