diff options
Diffstat (limited to 'servers/physics')
-rw-r--r-- | servers/physics/body_sw.cpp | 39 | ||||
-rw-r--r-- | servers/physics/body_sw.h | 6 | ||||
-rw-r--r-- | servers/physics/physics_server_sw.cpp | 8 | ||||
-rw-r--r-- | servers/physics/physics_server_sw.h | 4 |
4 files changed, 36 insertions, 21 deletions
diff --git a/servers/physics/body_sw.cpp b/servers/physics/body_sw.cpp index bba4d7a147..7fa7f0a45d 100644 --- a/servers/physics/body_sw.cpp +++ b/servers/physics/body_sw.cpp @@ -422,6 +422,18 @@ void BodySW::_compute_area_gravity_and_dampenings(const AreaSW *p_area) { area_angular_damp += p_area->get_angular_damp(); } +void BodySW::set_axis_lock(PhysicsServer::BodyAxis p_axis, bool lock) { + if (lock) { + locked_axis |= p_axis; + } else { + locked_axis &= ~p_axis; + } +} + +bool BodySW::is_axis_locked(PhysicsServer::BodyAxis p_axis) const { + return locked_axis & p_axis; +} + void BodySW::integrate_forces(real_t p_step) { if (mode == PhysicsServer::BODY_MODE_STATIC) @@ -559,17 +571,19 @@ void BodySW::integrate_velocities(real_t p_step) { if (fi_callback) get_space()->body_add_to_state_query_list(&direct_state_query_list); - //apply axis lock - if (locked_axis[0] || locked_axis[1] || locked_axis[2]) { - for (int i = 0; i < 3; i++) { - if (locked_axis[i]) { - linear_velocity[i] = 0; - biased_linear_velocity[i] = 0; - new_transform.origin[i] = get_transform().origin[i]; - } else { - angular_velocity[i] = 0; - biased_angular_velocity[i] = 0; - } + //apply axis lock linear + for (int i = 0; i < 3; i++) { + if (is_axis_locked((PhysicsServer::BodyAxis)(1 << i))) { + linear_velocity[i] = 0; + biased_linear_velocity[i] = 0; + new_transform.origin[i] = get_transform().origin[i]; + } + } + //apply axis lock angular + for (int i = 0; i < 3; i++) { + if (is_axis_locked((PhysicsServer::BodyAxis)(1 << (i + 3)))) { + angular_velocity[i] = 0; + biased_angular_velocity[i] = 0; } } @@ -742,7 +756,8 @@ BodySW::BodySW() : CollisionObjectSW(TYPE_BODY), active_list(this), inertia_update_list(this), - direct_state_query_list(this) { + direct_state_query_list(this), + locked_axis(0) { mode = PhysicsServer::BODY_MODE_RIGID; active = true; diff --git a/servers/physics/body_sw.h b/servers/physics/body_sw.h index aab6def1a9..b6aa76c70a 100644 --- a/servers/physics/body_sw.h +++ b/servers/physics/body_sw.h @@ -53,7 +53,7 @@ class BodySW : public CollisionObjectSW { real_t angular_damp; real_t gravity_scale; - bool locked_axis[3] = { false, false, false }; + uint16_t locked_axis; real_t kinematic_safe_margin; real_t _inv_mass; @@ -288,8 +288,8 @@ public: _FORCE_INLINE_ Vector3 get_gravity() const { return gravity; } _FORCE_INLINE_ real_t get_bounce() const { return bounce; } - _FORCE_INLINE_ void set_axis_lock(int axis, bool lock) { locked_axis[axis] = lock; } - _FORCE_INLINE_ bool get_axis_lock() const { return locked_axis; } + void set_axis_lock(PhysicsServer::BodyAxis p_axis, bool lock); + bool is_axis_locked(PhysicsServer::BodyAxis p_axis) const; void integrate_forces(real_t p_step); void integrate_velocities(real_t p_step); diff --git a/servers/physics/physics_server_sw.cpp b/servers/physics/physics_server_sw.cpp index 2909308366..0a1d524839 100644 --- a/servers/physics/physics_server_sw.cpp +++ b/servers/physics/physics_server_sw.cpp @@ -794,20 +794,20 @@ void PhysicsServerSW::body_set_axis_velocity(RID p_body, const Vector3 &p_axis_v body->wakeup(); }; -void PhysicsServerSW::body_set_axis_lock(RID p_body, int axis, bool lock) { +void PhysicsServerSW::body_set_axis_lock(RID p_body, BodyAxis p_axis, bool lock) { BodySW *body = body_owner.get(p_body); ERR_FAIL_COND(!body); - body->set_axis_lock(axis, lock); + body->set_axis_lock(p_axis, lock); body->wakeup(); } -bool PhysicsServerSW::body_get_axis_lock(RID p_body) const { +bool PhysicsServerSW::body_is_axis_locked(RID p_body, BodyAxis p_axis) const { const BodySW *body = body_owner.get(p_body); ERR_FAIL_COND_V(!body, 0); - return body->get_axis_lock(); + return body->is_axis_locked(p_axis); } void PhysicsServerSW::body_add_collision_exception(RID p_body, RID p_body_b) { diff --git a/servers/physics/physics_server_sw.h b/servers/physics/physics_server_sw.h index fea6e34ebd..71547f24c8 100644 --- a/servers/physics/physics_server_sw.h +++ b/servers/physics/physics_server_sw.h @@ -203,8 +203,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, int axis, bool p_lock); - virtual bool body_get_axis_lock(RID p_body) const; + virtual void body_set_axis_lock(RID p_body, BodyAxis p_axis, bool p_lock); + virtual bool body_is_axis_locked(RID p_body, BodyAxis p_axis) 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); |