Merge pull request #16751 from AndreaCatania/moreAPIs

Added Physics state APIs
This commit is contained in:
Rémi Verschelde 2018-02-19 20:22:18 +01:00 committed by GitHub
commit be67f2e4ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 0 deletions

View File

@ -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);
}

View File

@ -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);

View File

@ -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); }

View File

@ -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);

View File

@ -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;