From 2ffc90d8b4d3f420e57adefbc880183ac0635a7e Mon Sep 17 00:00:00 2001 From: Biliogadafr Date: Sat, 10 Oct 2015 23:28:05 +0300 Subject: Expose softness parameter of pin joint to the editor. --- scene/2d/joints_2d.cpp | 28 +++++++++++++++++++++++++--- scene/2d/joints_2d.h | 6 +++++- 2 files changed, 30 insertions(+), 4 deletions(-) (limited to 'scene/2d') 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(); }; -- cgit v1.2.3