diff options
author | Andrea Catania <info@andreacatania.com> | 2018-07-23 16:37:07 +0200 |
---|---|---|
committer | Andrea Catania <info@andreacatania.com> | 2018-08-07 19:38:04 +0200 |
commit | 5e65e28eed1398cceb4b77cb99ba6578115953db (patch) | |
tree | 2b4ae296db3d7763f2cf071dc87340ae56585d48 /servers | |
parent | 1ad20dc2f13001d95e91cb2089571028f44db11a (diff) |
Removed physics material combination mode. Added rough and absorbent parameter to material. Fixed 'change' signal connection
Diffstat (limited to 'servers')
-rw-r--r-- | servers/physics/body_pair_sw.cpp | 34 | ||||
-rw-r--r-- | servers/physics/body_sw.cpp | 16 | ||||
-rw-r--r-- | servers/physics/body_sw.h | 8 | ||||
-rw-r--r-- | servers/physics/physics_server_sw.cpp | 14 | ||||
-rw-r--r-- | servers/physics/physics_server_sw.h | 4 | ||||
-rw-r--r-- | servers/physics_2d/body_2d_sw.cpp | 16 | ||||
-rw-r--r-- | servers/physics_2d/body_2d_sw.h | 8 | ||||
-rw-r--r-- | servers/physics_2d/body_pair_2d_sw.cpp | 34 | ||||
-rw-r--r-- | servers/physics_2d/physics_2d_server_sw.cpp | 16 | ||||
-rw-r--r-- | servers/physics_2d/physics_2d_server_sw.h | 4 | ||||
-rw-r--r-- | servers/physics_2d/physics_2d_server_wrap_mt.h | 3 | ||||
-rw-r--r-- | servers/physics_2d_server.h | 13 | ||||
-rw-r--r-- | servers/physics_server.h | 13 |
13 files changed, 4 insertions, 179 deletions
diff --git a/servers/physics/body_pair_sw.cpp b/servers/physics/body_pair_sw.cpp index 5a41b621eb..0ce38e4486 100644 --- a/servers/physics/body_pair_sw.cpp +++ b/servers/physics/body_pair_sw.cpp @@ -212,41 +212,11 @@ bool BodyPairSW::_test_ccd(real_t p_step, BodySW *p_A, int p_shape_A, const Tran } real_t combine_bounce(BodySW *A, BodySW *B) { - const PhysicsServer::CombineMode cm = A->get_bounce_combine_mode(); - - switch (cm) { - case PhysicsServer::COMBINE_MODE_INHERIT: - if (B->get_bounce_combine_mode() != PhysicsServer::COMBINE_MODE_INHERIT) - return combine_bounce(B, A); - // else use MAX [This is used when the two bodies doesn't use physical material] - case PhysicsServer::COMBINE_MODE_MAX: - return MAX(A->get_bounce(), B->get_bounce()); - case PhysicsServer::COMBINE_MODE_MIN: - return MIN(A->get_bounce(), B->get_bounce()); - case PhysicsServer::COMBINE_MODE_MULTIPLY: - return A->get_bounce() * B->get_bounce(); - default: // Is always PhysicsServer::COMBINE_MODE_AVERAGE: - return (A->get_bounce() + B->get_bounce()) / 2; - } + return CLAMP(A->get_bounce() + B->get_bounce(), 0, 1); } real_t combine_friction(BodySW *A, BodySW *B) { - const PhysicsServer::CombineMode cm = A->get_friction_combine_mode(); - - switch (cm) { - case PhysicsServer::COMBINE_MODE_INHERIT: - if (B->get_friction_combine_mode() != PhysicsServer::COMBINE_MODE_INHERIT) - return combine_friction(B, A); - // else use Multiply [This is used when the two bodies doesn't use physical material] - case PhysicsServer::COMBINE_MODE_MULTIPLY: - return A->get_friction() * B->get_friction(); - case PhysicsServer::COMBINE_MODE_MAX: - return MAX(A->get_friction(), B->get_friction()); - case PhysicsServer::COMBINE_MODE_MIN: - return MIN(A->get_friction(), B->get_friction()); - default: // Is always PhysicsServer::COMBINE_MODE_AVERAGE: - return (A->get_friction() + B->get_friction()) / 2; - } + return ABS(MIN(A->get_friction(), B->get_friction())); } bool BodyPairSW::setup(real_t p_step) { diff --git a/servers/physics/body_sw.cpp b/servers/physics/body_sw.cpp index 59f987fc17..cc9681193c 100644 --- a/servers/physics/body_sw.cpp +++ b/servers/physics/body_sw.cpp @@ -423,22 +423,6 @@ void BodySW::_compute_area_gravity_and_dampenings(const AreaSW *p_area) { area_angular_damp += p_area->get_angular_damp(); } -void BodySW::set_combine_mode(PhysicsServer::BodyParameter p_param, PhysicsServer::CombineMode p_mode) { - if (p_param == PhysicsServer::BODY_PARAM_BOUNCE) { - bounce_combine_mode = p_mode; - } else { - friction_combine_mode = p_mode; - } -} - -PhysicsServer::CombineMode BodySW::get_combine_mode(PhysicsServer::BodyParameter p_param) const { - if (p_param == PhysicsServer::BODY_PARAM_BOUNCE) { - return bounce_combine_mode; - } else { - return friction_combine_mode; - } -} - void BodySW::set_axis_lock(PhysicsServer::BodyAxis p_axis, bool lock) { if (lock) { locked_axis |= p_axis; diff --git a/servers/physics/body_sw.h b/servers/physics/body_sw.h index 25eb20f5d8..fd2ab16b84 100644 --- a/servers/physics/body_sw.h +++ b/servers/physics/body_sw.h @@ -49,8 +49,6 @@ class BodySW : public CollisionObjectSW { real_t mass; real_t bounce; real_t friction; - PhysicsServer::CombineMode bounce_combine_mode; - PhysicsServer::CombineMode friction_combine_mode; real_t linear_damp; real_t angular_damp; @@ -300,12 +298,6 @@ public: _FORCE_INLINE_ Vector3 get_gravity() const { return gravity; } _FORCE_INLINE_ real_t get_bounce() const { return bounce; } - void set_combine_mode(PhysicsServer::BodyParameter p_param, PhysicsServer::CombineMode p_mode); - PhysicsServer::CombineMode get_combine_mode(PhysicsServer::BodyParameter p_param) const; - - _FORCE_INLINE_ PhysicsServer::CombineMode get_bounce_combine_mode() const { return bounce_combine_mode; } - _FORCE_INLINE_ PhysicsServer::CombineMode get_friction_combine_mode() const { return friction_combine_mode; } - void set_axis_lock(PhysicsServer::BodyAxis p_axis, bool lock); bool is_axis_locked(PhysicsServer::BodyAxis p_axis) const; diff --git a/servers/physics/physics_server_sw.cpp b/servers/physics/physics_server_sw.cpp index f1e0cbef29..593218dd5d 100644 --- a/servers/physics/physics_server_sw.cpp +++ b/servers/physics/physics_server_sw.cpp @@ -701,20 +701,6 @@ real_t PhysicsServerSW::body_get_param(RID p_body, BodyParameter p_param) const return body->get_param(p_param); }; -void PhysicsServerSW::body_set_combine_mode(RID p_body, BodyParameter p_param, CombineMode p_mode) { - BodySW *body = body_owner.get(p_body); - ERR_FAIL_COND(!body); - - body->set_combine_mode(p_param, p_mode); -} - -PhysicsServer::CombineMode PhysicsServerSW::body_get_combine_mode(RID p_body, BodyParameter p_param) const { - BodySW *body = body_owner.get(p_body); - ERR_FAIL_COND_V(!body, COMBINE_MODE_INHERIT); - - return body->get_combine_mode(p_param); -} - void PhysicsServerSW::body_set_kinematic_safe_margin(RID p_body, real_t p_margin) { BodySW *body = body_owner.get(p_body); ERR_FAIL_COND(!body); diff --git a/servers/physics/physics_server_sw.h b/servers/physics/physics_server_sw.h index d8c73abb16..3f56ba26d0 100644 --- a/servers/physics/physics_server_sw.h +++ b/servers/physics/physics_server_sw.h @@ -188,10 +188,6 @@ public: virtual void body_set_param(RID p_body, BodyParameter p_param, real_t p_value); virtual real_t body_get_param(RID p_body, BodyParameter p_param) const; - /// p_param accept only Bounce and Friction - virtual void body_set_combine_mode(RID p_body, BodyParameter p_param, CombineMode p_mode); - virtual CombineMode body_get_combine_mode(RID p_body, BodyParameter p_param) const; - virtual void body_set_kinematic_safe_margin(RID p_body, real_t p_margin); virtual real_t body_get_kinematic_safe_margin(RID p_body) const; diff --git a/servers/physics_2d/body_2d_sw.cpp b/servers/physics_2d/body_2d_sw.cpp index fcd2a65ee7..aa063d6c1e 100644 --- a/servers/physics_2d/body_2d_sw.cpp +++ b/servers/physics_2d/body_2d_sw.cpp @@ -405,22 +405,6 @@ void Body2DSW::_compute_area_gravity_and_dampenings(const Area2DSW *p_area) { area_angular_damp += p_area->get_angular_damp(); } -void Body2DSW::set_combine_mode(Physics2DServer::BodyParameter p_param, Physics2DServer::CombineMode p_mode) { - if (p_param == Physics2DServer::BODY_PARAM_BOUNCE) { - bounce_combine_mode = p_mode; - } else { - friction_combine_mode = p_mode; - } -} - -Physics2DServer::CombineMode Body2DSW::get_combine_mode(Physics2DServer::BodyParameter p_param) const { - if (p_param == Physics2DServer::BODY_PARAM_BOUNCE) { - return bounce_combine_mode; - } else { - return friction_combine_mode; - } -} - void Body2DSW::integrate_forces(real_t p_step) { if (mode == Physics2DServer::BODY_MODE_STATIC) diff --git a/servers/physics_2d/body_2d_sw.h b/servers/physics_2d/body_2d_sw.h index 301bd6b299..782adf3416 100644 --- a/servers/physics_2d/body_2d_sw.h +++ b/servers/physics_2d/body_2d_sw.h @@ -54,8 +54,6 @@ class Body2DSW : public CollisionObject2DSW { real_t mass; real_t bounce; real_t friction; - Physics2DServer::CombineMode bounce_combine_mode; - Physics2DServer::CombineMode friction_combine_mode; real_t _inv_mass; real_t _inv_inertia; @@ -258,12 +256,6 @@ public: _FORCE_INLINE_ real_t get_linear_damp() const { return linear_damp; } _FORCE_INLINE_ real_t get_angular_damp() const { return angular_damp; } - void set_combine_mode(Physics2DServer::BodyParameter p_param, Physics2DServer::CombineMode p_mode); - Physics2DServer::CombineMode get_combine_mode(Physics2DServer::BodyParameter p_param) const; - - _FORCE_INLINE_ Physics2DServer::CombineMode get_bounce_combine_mode() const { return bounce_combine_mode; } - _FORCE_INLINE_ Physics2DServer::CombineMode get_friction_combine_mode() const { return friction_combine_mode; } - void integrate_forces(real_t p_step); void integrate_velocities(real_t p_step); diff --git a/servers/physics_2d/body_pair_2d_sw.cpp b/servers/physics_2d/body_pair_2d_sw.cpp index be8dcf6fa8..2633edf7bb 100644 --- a/servers/physics_2d/body_pair_2d_sw.cpp +++ b/servers/physics_2d/body_pair_2d_sw.cpp @@ -220,41 +220,11 @@ bool BodyPair2DSW::_test_ccd(real_t p_step, Body2DSW *p_A, int p_shape_A, const } real_t combine_bounce(Body2DSW *A, Body2DSW *B) { - const Physics2DServer::CombineMode cm = A->get_bounce_combine_mode(); - - switch (cm) { - case Physics2DServer::COMBINE_MODE_INHERIT: - if (B->get_bounce_combine_mode() != Physics2DServer::COMBINE_MODE_INHERIT) - return combine_bounce(B, A); - // else use MAX [This is used when the two bodies doesn't use physical material] - case Physics2DServer::COMBINE_MODE_MAX: - return MAX(A->get_bounce(), B->get_bounce()); - case Physics2DServer::COMBINE_MODE_MIN: - return MIN(A->get_bounce(), B->get_bounce()); - case Physics2DServer::COMBINE_MODE_MULTIPLY: - return A->get_bounce() * B->get_bounce(); - default: // Is always Physics2DServer::COMBINE_MODE_AVERAGE: - return (A->get_bounce() + B->get_bounce()) / 2; - } + return CLAMP(A->get_bounce() + B->get_bounce(), 0, 1); } real_t combine_friction(Body2DSW *A, Body2DSW *B) { - const Physics2DServer::CombineMode cm = A->get_friction_combine_mode(); - - switch (cm) { - case Physics2DServer::COMBINE_MODE_INHERIT: - if (B->get_friction_combine_mode() != Physics2DServer::COMBINE_MODE_INHERIT) - return combine_friction(B, A); - // else use Multiply [This is used when the two bodies doesn't use physical material] - case Physics2DServer::COMBINE_MODE_MULTIPLY: - return A->get_friction() * B->get_friction(); - case Physics2DServer::COMBINE_MODE_MAX: - return MAX(A->get_friction(), B->get_friction()); - case Physics2DServer::COMBINE_MODE_MIN: - return MIN(A->get_friction(), B->get_friction()); - default: // Is always Physics2DServer::COMBINE_MODE_AVERAGE: - return (A->get_friction() + B->get_friction()) / 2; - } + return ABS(MIN(A->get_friction(), B->get_friction())); } bool BodyPair2DSW::setup(real_t p_step) { diff --git a/servers/physics_2d/physics_2d_server_sw.cpp b/servers/physics_2d/physics_2d_server_sw.cpp index cfcef8cb04..a473e0beb2 100644 --- a/servers/physics_2d/physics_2d_server_sw.cpp +++ b/servers/physics_2d/physics_2d_server_sw.cpp @@ -789,22 +789,6 @@ real_t Physics2DServerSW::body_get_param(RID p_body, BodyParameter p_param) cons return body->get_param(p_param); }; -void Physics2DServerSW::body_set_combine_mode(RID p_body, BodyParameter p_param, CombineMode p_mode) { - - Body2DSW *body = body_owner.get(p_body); - ERR_FAIL_COND(!body); - - body->set_combine_mode(p_param, p_mode); -} - -Physics2DServer::CombineMode Physics2DServerSW::body_get_combine_mode(RID p_body, BodyParameter p_param) const { - - Body2DSW *body = body_owner.get(p_body); - ERR_FAIL_COND_V(!body, COMBINE_MODE_INHERIT); - - return body->get_combine_mode(p_param); -} - void Physics2DServerSW::body_set_state(RID p_body, BodyState p_state, const Variant &p_variant) { Body2DSW *body = body_owner.get(p_body); diff --git a/servers/physics_2d/physics_2d_server_sw.h b/servers/physics_2d/physics_2d_server_sw.h index bf00746063..e5961b9011 100644 --- a/servers/physics_2d/physics_2d_server_sw.h +++ b/servers/physics_2d/physics_2d_server_sw.h @@ -200,10 +200,6 @@ public: virtual void body_set_param(RID p_body, BodyParameter p_param, real_t p_value); virtual real_t body_get_param(RID p_body, BodyParameter p_param) const; - /// p_param accept only Bounce and Friction - virtual void body_set_combine_mode(RID p_body, BodyParameter p_param, CombineMode p_mode); - virtual CombineMode body_get_combine_mode(RID p_body, BodyParameter p_param) const; - virtual void body_set_state(RID p_body, BodyState p_state, const Variant &p_variant); virtual Variant body_get_state(RID p_body, BodyState p_state) const; diff --git a/servers/physics_2d/physics_2d_server_wrap_mt.h b/servers/physics_2d/physics_2d_server_wrap_mt.h index a85cd5ef8d..3119b930d7 100644 --- a/servers/physics_2d/physics_2d_server_wrap_mt.h +++ b/servers/physics_2d/physics_2d_server_wrap_mt.h @@ -211,9 +211,6 @@ public: FUNC3(body_set_param, RID, BodyParameter, real_t); FUNC2RC(real_t, body_get_param, RID, BodyParameter); - FUNC3(body_set_combine_mode, RID, BodyParameter, CombineMode); - FUNC2RC(CombineMode, body_get_combine_mode, RID, BodyParameter); - FUNC3(body_set_state, RID, BodyState, const Variant &); FUNC2RC(Variant, body_get_state, RID, BodyState); diff --git a/servers/physics_2d_server.h b/servers/physics_2d_server.h index 89c649af49..1d04fbc5c6 100644 --- a/servers/physics_2d_server.h +++ b/servers/physics_2d_server.h @@ -416,19 +416,6 @@ public: virtual void body_set_param(RID p_body, BodyParameter p_param, float p_value) = 0; virtual float body_get_param(RID p_body, BodyParameter p_param) const = 0; - enum CombineMode { - COMBINE_MODE_MAX, - COMBINE_MODE_MIN, - COMBINE_MODE_MULTIPLY, - COMBINE_MODE_AVERAGE, - - COMBINE_MODE_INHERIT /// Inherit from other body or use COMBINE_MODE_MAX (Restitution) COMBINE_MODE_MULTIPLY (Friction) - }; - - /// p_param accept only Bounce and Friction - virtual void body_set_combine_mode(RID p_body, BodyParameter p_param, CombineMode p_mode) = 0; - virtual CombineMode body_get_combine_mode(RID p_body, BodyParameter p_param) const = 0; - //state enum BodyState { BODY_STATE_TRANSFORM, diff --git a/servers/physics_server.h b/servers/physics_server.h index 91e7f58319..8ecf17c0e6 100644 --- a/servers/physics_server.h +++ b/servers/physics_server.h @@ -399,19 +399,6 @@ public: virtual void body_set_param(RID p_body, BodyParameter p_param, float p_value) = 0; virtual float body_get_param(RID p_body, BodyParameter p_param) const = 0; - enum CombineMode { - COMBINE_MODE_MAX, - COMBINE_MODE_MIN, - COMBINE_MODE_MULTIPLY, - COMBINE_MODE_AVERAGE, - - COMBINE_MODE_INHERIT /// Inherit from other body or use COMBINE_MODE_MAX (Restitution) COMBINE_MODE_MULTIPLY (Friction) - }; - - /// p_param accept only Bounce and Friction - virtual void body_set_combine_mode(RID p_body, BodyParameter p_param, CombineMode p_mode) = 0; - virtual CombineMode body_get_combine_mode(RID p_body, BodyParameter p_param) const = 0; - virtual void body_set_kinematic_safe_margin(RID p_body, real_t p_margin) = 0; virtual real_t body_get_kinematic_safe_margin(RID p_body) const = 0; |