Merge pull request #37350 from aaronfranke/force-impulse
Refactor physics force and impulse code to use (force, position) order
This commit is contained in:
commit
67e4082b1e
35 changed files with 180 additions and 176 deletions
|
|
@ -638,8 +638,9 @@ void RigidBody3D::add_central_force(const Vector3 &p_force) {
|
|||
PhysicsServer3D::get_singleton()->body_add_central_force(get_rid(), p_force);
|
||||
}
|
||||
|
||||
void RigidBody3D::add_force(const Vector3 &p_force, const Vector3 &p_pos) {
|
||||
PhysicsServer3D::get_singleton()->body_add_force(get_rid(), p_force, p_pos);
|
||||
void RigidBody3D::add_force(const Vector3 &p_force, const Vector3 &p_position) {
|
||||
PhysicsServer3D *singleton = PhysicsServer3D::get_singleton();
|
||||
singleton->body_add_force(get_rid(), p_force, p_position);
|
||||
}
|
||||
|
||||
void RigidBody3D::add_torque(const Vector3 &p_torque) {
|
||||
|
|
@ -650,8 +651,9 @@ void RigidBody3D::apply_central_impulse(const Vector3 &p_impulse) {
|
|||
PhysicsServer3D::get_singleton()->body_apply_central_impulse(get_rid(), p_impulse);
|
||||
}
|
||||
|
||||
void RigidBody3D::apply_impulse(const Vector3 &p_pos, const Vector3 &p_impulse) {
|
||||
PhysicsServer3D::get_singleton()->body_apply_impulse(get_rid(), p_pos, p_impulse);
|
||||
void RigidBody3D::apply_impulse(const Vector3 &p_impulse, const Vector3 &p_position) {
|
||||
PhysicsServer3D *singleton = PhysicsServer3D::get_singleton();
|
||||
singleton->body_apply_impulse(get_rid(), p_impulse, p_position);
|
||||
}
|
||||
|
||||
void RigidBody3D::apply_torque_impulse(const Vector3 &p_impulse) {
|
||||
|
|
@ -782,11 +784,11 @@ void RigidBody3D::_bind_methods() {
|
|||
ClassDB::bind_method(D_METHOD("set_axis_velocity", "axis_velocity"), &RigidBody3D::set_axis_velocity);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("add_central_force", "force"), &RigidBody3D::add_central_force);
|
||||
ClassDB::bind_method(D_METHOD("add_force", "force", "position"), &RigidBody3D::add_force);
|
||||
ClassDB::bind_method(D_METHOD("add_force", "force", "position"), &RigidBody3D::add_force, Vector3());
|
||||
ClassDB::bind_method(D_METHOD("add_torque", "torque"), &RigidBody3D::add_torque);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("apply_central_impulse", "impulse"), &RigidBody3D::apply_central_impulse);
|
||||
ClassDB::bind_method(D_METHOD("apply_impulse", "position", "impulse"), &RigidBody3D::apply_impulse);
|
||||
ClassDB::bind_method(D_METHOD("apply_impulse", "impulse", "position"), &RigidBody3D::apply_impulse, Vector3());
|
||||
ClassDB::bind_method(D_METHOD("apply_torque_impulse", "impulse"), &RigidBody3D::apply_torque_impulse);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_sleeping", "sleeping"), &RigidBody3D::set_sleeping);
|
||||
|
|
@ -1372,8 +1374,8 @@ void PhysicalBone3D::apply_central_impulse(const Vector3 &p_impulse) {
|
|||
PhysicsServer3D::get_singleton()->body_apply_central_impulse(get_rid(), p_impulse);
|
||||
}
|
||||
|
||||
void PhysicalBone3D::apply_impulse(const Vector3 &p_pos, const Vector3 &p_impulse) {
|
||||
PhysicsServer3D::get_singleton()->body_apply_impulse(get_rid(), p_pos, p_impulse);
|
||||
void PhysicalBone3D::apply_impulse(const Vector3 &p_impulse, const Vector3 &p_position) {
|
||||
PhysicsServer3D::get_singleton()->body_apply_impulse(get_rid(), p_impulse, p_position);
|
||||
}
|
||||
|
||||
void PhysicalBone3D::reset_physics_simulation_state() {
|
||||
|
|
@ -2099,7 +2101,7 @@ void PhysicalBone3D::_direct_state_changed(Object *p_state) {
|
|||
|
||||
void PhysicalBone3D::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("apply_central_impulse", "impulse"), &PhysicalBone3D::apply_central_impulse);
|
||||
ClassDB::bind_method(D_METHOD("apply_impulse", "position", "impulse"), &PhysicalBone3D::apply_impulse);
|
||||
ClassDB::bind_method(D_METHOD("apply_impulse", "impulse", "position"), &PhysicalBone3D::apply_impulse, Vector3());
|
||||
|
||||
ClassDB::bind_method(D_METHOD("_direct_state_changed"), &PhysicalBone3D::_direct_state_changed);
|
||||
|
||||
|
|
|
|||
|
|
@ -234,11 +234,11 @@ public:
|
|||
Array get_colliding_bodies() const;
|
||||
|
||||
void add_central_force(const Vector3 &p_force);
|
||||
void add_force(const Vector3 &p_force, const Vector3 &p_pos);
|
||||
void add_force(const Vector3 &p_force, const Vector3 &p_position = Vector3());
|
||||
void add_torque(const Vector3 &p_torque);
|
||||
|
||||
void apply_central_impulse(const Vector3 &p_impulse);
|
||||
void apply_impulse(const Vector3 &p_pos, const Vector3 &p_impulse);
|
||||
void apply_impulse(const Vector3 &p_impulse, const Vector3 &p_position = Vector3());
|
||||
void apply_torque_impulse(const Vector3 &p_impulse);
|
||||
|
||||
virtual String get_configuration_warning() const;
|
||||
|
|
@ -597,7 +597,7 @@ public:
|
|||
bool get_axis_lock(PhysicsServer3D::BodyAxis p_axis) const;
|
||||
|
||||
void apply_central_impulse(const Vector3 &p_impulse);
|
||||
void apply_impulse(const Vector3 &p_pos, const Vector3 &p_impulse);
|
||||
void apply_impulse(const Vector3 &p_impulse, const Vector3 &p_position = Vector3());
|
||||
|
||||
void reset_physics_simulation_state();
|
||||
void reset_to_rest_position();
|
||||
|
|
|
|||
|
|
@ -794,7 +794,7 @@ void VehicleBody3D::_update_friction(PhysicsDirectBodyState3D *s) {
|
|||
s->get_transform().origin;
|
||||
|
||||
if (m_forwardImpulse[wheel] != real_t(0.)) {
|
||||
s->apply_impulse(rel_pos, m_forwardWS[wheel] * (m_forwardImpulse[wheel]));
|
||||
s->apply_impulse(m_forwardWS[wheel] * (m_forwardImpulse[wheel]), rel_pos);
|
||||
}
|
||||
if (m_sideImpulse[wheel] != real_t(0.)) {
|
||||
PhysicsBody3D *groundObject = wheelInfo.m_raycastInfo.m_groundObject;
|
||||
|
|
@ -812,7 +812,7 @@ void VehicleBody3D::_update_friction(PhysicsDirectBodyState3D *s) {
|
|||
#else
|
||||
rel_pos[1] *= wheelInfo.m_rollInfluence; //?
|
||||
#endif
|
||||
s->apply_impulse(rel_pos, sideImp);
|
||||
s->apply_impulse(sideImp, rel_pos);
|
||||
|
||||
//apply friction impulse on the ground
|
||||
//todo
|
||||
|
|
@ -850,10 +850,9 @@ void VehicleBody3D::_direct_state_changed(Object *p_state) {
|
|||
suspensionForce = wheel.m_maxSuspensionForce;
|
||||
}
|
||||
Vector3 impulse = wheel.m_raycastInfo.m_contactNormalWS * suspensionForce * step;
|
||||
Vector3 relpos = wheel.m_raycastInfo.m_contactPointWS - state->get_transform().origin;
|
||||
Vector3 relative_position = wheel.m_raycastInfo.m_contactPointWS - state->get_transform().origin;
|
||||
|
||||
state->apply_impulse(relpos, impulse);
|
||||
//getRigidBody()->applyImpulse(impulse, relpos);
|
||||
state->apply_impulse(impulse, relative_position);
|
||||
}
|
||||
|
||||
_update_friction(state);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue