diff options
author | Juan Linietsky <reduzio@gmail.com> | 2015-10-17 09:45:16 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2015-10-17 09:45:16 -0300 |
commit | 426909e26b28d32c1efd64193c41d6fc745fb097 (patch) | |
tree | 5dd9a0119696f627c5dc08bd6edcd3b1a4186686 /scene/2d | |
parent | 782444d3668ea1edbb2758ae851c343afe9c8538 (diff) | |
parent | 2ffc90d8b4d3f420e57adefbc880183ac0635a7e (diff) |
Merge pull request #2594 from Biliogadafr/PinSoftness
Expose softness parameter of pin joint to the editor.
Diffstat (limited to 'scene/2d')
-rw-r--r-- | scene/2d/joints_2d.cpp | 28 | ||||
-rw-r--r-- | scene/2d/joints_2d.h | 6 |
2 files changed, 30 insertions, 4 deletions
diff --git a/scene/2d/joints_2d.cpp b/scene/2d/joints_2d.cpp index c1e91c2ecd..1df936535f 100644 --- a/scene/2d/joints_2d.cpp +++ b/scene/2d/joints_2d.cpp @@ -126,7 +126,7 @@ void Joint2D::_bind_methods() { ADD_PROPERTY( PropertyInfo( Variant::NODE_PATH, "node_a"), _SCS("set_node_a"),_SCS("get_node_a") ); ADD_PROPERTY( PropertyInfo( Variant::NODE_PATH, "node_b"), _SCS("set_node_b"),_SCS("get_node_b") ); - ADD_PROPERTY( PropertyInfo( Variant::REAL, "bias/bias",PROPERTY_HINT_RANGE,"0,0.9,0.01"), _SCS("set_bias"),_SCS("get_bias") ); + ADD_PROPERTY( PropertyInfo( Variant::REAL, "bias/bias",PROPERTY_HINT_RANGE,"0,0.9,0.001"), _SCS("set_bias"),_SCS("get_bias") ); } @@ -175,15 +175,37 @@ RID PinJoint2D::_configure_joint() { //add a collision exception between both Physics2DServer::get_singleton()->body_add_collision_exception(body_a->get_rid(),body_b->get_rid()); } + RID pj = Physics2DServer::get_singleton()->pin_joint_create(get_global_transform().get_origin(),body_a->get_rid(),body_b?body_b->get_rid():RID()); + Physics2DServer::get_singleton()->pin_joint_set_param(pj, Physics2DServer::PIN_JOINT_SOFTNESS, softness); + return pj; - return Physics2DServer::get_singleton()->pin_joint_create(get_global_transform().get_origin(),body_a->get_rid(),body_b?body_b->get_rid():RID()); +} + +void PinJoint2D::set_softness(real_t p_softness) { + + softness=p_softness; + update(); + if (get_joint().is_valid()) + Physics2DServer::get_singleton()->pin_joint_set_param(get_joint(), Physics2DServer::PIN_JOINT_SOFTNESS, p_softness); } +real_t PinJoint2D::get_softness() const { -PinJoint2D::PinJoint2D() { + return softness; +} + +void PinJoint2D::_bind_methods() { + + ObjectTypeDB::bind_method(_MD("set_softness","softness"), &PinJoint2D::set_softness); + ObjectTypeDB::bind_method(_MD("get_softness"), &PinJoint2D::get_softness); + ADD_PROPERTY( PropertyInfo( Variant::REAL, "softness", PROPERTY_HINT_EXP_RANGE,"0.00,16,0.01"), _SCS("set_softness"), _SCS("get_softness")); +} + +PinJoint2D::PinJoint2D() { + softness = 0; } diff --git a/scene/2d/joints_2d.h b/scene/2d/joints_2d.h index ac72c6ce59..908e3a158e 100644 --- a/scene/2d/joints_2d.h +++ b/scene/2d/joints_2d.h @@ -72,13 +72,17 @@ class PinJoint2D : public Joint2D { OBJ_TYPE(PinJoint2D,Joint2D); + real_t softness; + protected: void _notification(int p_what); virtual RID _configure_joint(); + static void _bind_methods(); public: - + void set_softness(real_t p_stiffness); + real_t get_softness() const; PinJoint2D(); }; |