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 /scene/resources | |
parent | 1ad20dc2f13001d95e91cb2089571028f44db11a (diff) |
Removed physics material combination mode. Added rough and absorbent parameter to material. Fixed 'change' signal connection
Diffstat (limited to 'scene/resources')
-rw-r--r-- | scene/resources/physics_material.cpp | 76 | ||||
-rw-r--r-- | scene/resources/physics_material.h | 32 |
2 files changed, 47 insertions, 61 deletions
diff --git a/scene/resources/physics_material.cpp b/scene/resources/physics_material.cpp index de3cfd1371..dc5ca1aef6 100644 --- a/scene/resources/physics_material.cpp +++ b/scene/resources/physics_material.cpp @@ -29,66 +29,48 @@ /*************************************************************************/ #include "physics_material.h" -bool PhysicsMaterial::_set(const StringName &p_name, const Variant &p_value) { - if (p_name == "bounce") { - set_bounce(p_value); - } else if (p_name == "bounce_combine_mode") { - set_bounce_combine_mode(static_cast<PhysicsServer::CombineMode>(int(p_value))); - } else if (p_name == "friction") { - set_friction(p_value); - } else if (p_name == "friction_combine_mode") { - set_friction_combine_mode(static_cast<PhysicsServer::CombineMode>(int(p_value))); - } else { - return false; - } +void PhysicsMaterial::_bind_methods() { - emit_changed(); - return true; -} + ClassDB::bind_method(D_METHOD("set_friction", "friction"), &PhysicsMaterial::set_friction); + ClassDB::bind_method(D_METHOD("get_friction"), &PhysicsMaterial::get_friction); -bool PhysicsMaterial::_get(const StringName &p_name, Variant &r_ret) const { - if (p_name == "bounce") { - r_ret = bounce; - } else if (p_name == "bounce_combine_mode") { - r_ret = int(bounce_combine_mode); - } else if (p_name == "friction") { - r_ret = friction; - } else if (p_name == "friction_combine_mode") { - r_ret = int(friction_combine_mode); - } else { - return false; - } + ClassDB::bind_method(D_METHOD("set_rough", "rough"), &PhysicsMaterial::set_rough); + ClassDB::bind_method(D_METHOD("is_rough"), &PhysicsMaterial::is_rough); - return true; -} + ClassDB::bind_method(D_METHOD("set_bounce", "bounce"), &PhysicsMaterial::set_bounce); + ClassDB::bind_method(D_METHOD("get_bounce"), &PhysicsMaterial::get_bounce); -void PhysicsMaterial::_get_property_list(List<PropertyInfo> *p_list) const { - p_list->push_back(PropertyInfo(Variant::REAL, "bounce")); - p_list->push_back(PropertyInfo(Variant::INT, "bounce_combine_mode", PROPERTY_HINT_ENUM, "Max,Min,Multiply,Average")); - p_list->push_back(PropertyInfo(Variant::REAL, "friction")); - p_list->push_back(PropertyInfo(Variant::INT, "friction_combine_mode", PROPERTY_HINT_ENUM, "Max,Min,Multiply,Average")); -} + ClassDB::bind_method(D_METHOD("set_absorbent", "absorbent"), &PhysicsMaterial::set_absorbent); + ClassDB::bind_method(D_METHOD("is_absorbent"), &PhysicsMaterial::is_absorbent); -void PhysicsMaterial::_bind_methods() {} + ADD_PROPERTY(PropertyInfo(Variant::REAL, "friction"), "set_friction", "get_friction"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "rough"), "set_rough", "is_rough"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "bounce"), "set_bounce", "get_bounce"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "absorbent"), "set_absorbent", "is_absorbent"); +} -void PhysicsMaterial::set_bounce(real_t p_val) { - bounce = p_val; +void PhysicsMaterial::set_friction(real_t p_val) { + friction = p_val; + emit_changed(); } -void PhysicsMaterial::set_bounce_combine_mode(PhysicsServer::CombineMode p_val) { - bounce_combine_mode = p_val; +void PhysicsMaterial::set_rough(bool p_val) { + rough = p_val; + emit_changed(); } -void PhysicsMaterial::set_friction(real_t p_val) { - friction = p_val; +void PhysicsMaterial::set_bounce(real_t p_val) { + bounce = p_val; + emit_changed(); } -void PhysicsMaterial::set_friction_combine_mode(PhysicsServer::CombineMode p_val) { - friction_combine_mode = p_val; +void PhysicsMaterial::set_absorbent(bool p_val) { + absorbent = p_val; + emit_changed(); } PhysicsMaterial::PhysicsMaterial() : + friction(1), + rough(false), bounce(0), - bounce_combine_mode(PhysicsServer::COMBINE_MODE_MAX), - friction(0), - friction_combine_mode(PhysicsServer::COMBINE_MODE_MULTIPLY) {} + absorbent(false) {} diff --git a/scene/resources/physics_material.h b/scene/resources/physics_material.h index a6cb8c288e..dfe48d94cf 100644 --- a/scene/resources/physics_material.h +++ b/scene/resources/physics_material.h @@ -39,30 +39,34 @@ class PhysicsMaterial : public Resource { OBJ_SAVE_TYPE(PhysicsMaterial); RES_BASE_EXTENSION("PhyMat"); - real_t bounce; - PhysicsServer::CombineMode bounce_combine_mode; real_t friction; - PhysicsServer::CombineMode friction_combine_mode; + bool rough; + real_t bounce; + bool absorbent; protected: - bool _set(const StringName &p_name, const Variant &p_value); - bool _get(const StringName &p_name, Variant &r_ret) const; - void _get_property_list(List<PropertyInfo> *p_list) const; - static void _bind_methods(); public: + void set_friction(real_t p_val); + _FORCE_INLINE_ real_t get_friction() const { return friction; } + + void set_rough(bool p_val); + _FORCE_INLINE_ bool is_rough() const { return rough; } + + _FORCE_INLINE_ real_t computed_friction() const { + return rough ? -friction : friction; + } + void set_bounce(real_t p_val); _FORCE_INLINE_ real_t get_bounce() const { return bounce; } - void set_bounce_combine_mode(PhysicsServer::CombineMode p_val); - _FORCE_INLINE_ PhysicsServer::CombineMode get_bounce_combine_mode() const { return bounce_combine_mode; } - - void set_friction(real_t p_val); - _FORCE_INLINE_ real_t get_friction() const { return friction; } + void set_absorbent(bool p_val); + _FORCE_INLINE_ bool is_absorbent() const { return absorbent; } - void set_friction_combine_mode(PhysicsServer::CombineMode p_val); - _FORCE_INLINE_ PhysicsServer::CombineMode get_friction_combine_mode() const { return friction_combine_mode; } + _FORCE_INLINE_ real_t computed_bounce() const { + return absorbent ? -bounce : bounce; + } PhysicsMaterial(); }; |