diff options
Diffstat (limited to 'scene')
-rw-r--r-- | scene/2d/area_2d.cpp | 21 | ||||
-rw-r--r-- | scene/2d/area_2d.h | 2 | ||||
-rw-r--r-- | scene/2d/physics_body_2d.cpp | 22 | ||||
-rw-r--r-- | scene/2d/physics_body_2d.h | 2 | ||||
-rw-r--r-- | scene/3d/area.cpp | 20 | ||||
-rw-r--r-- | scene/3d/area.h | 2 | ||||
-rw-r--r-- | scene/3d/physics_body.cpp | 23 | ||||
-rw-r--r-- | scene/3d/physics_body.h | 1 |
8 files changed, 93 insertions, 0 deletions
diff --git a/scene/2d/area_2d.cpp b/scene/2d/area_2d.cpp index 33176c4f34..3114106235 100644 --- a/scene/2d/area_2d.cpp +++ b/scene/2d/area_2d.cpp @@ -263,6 +263,25 @@ bool Area2D::is_monitoring_enabled() const { return monitoring; } +Array Area2D::get_overlapping_bodies() const { + + ERR_FAIL_COND_V(!monitoring,Array()); + Array ret; + ret.resize(body_map.size()); + int idx=0; + for (const Map<ObjectID,BodyState>::Element *E=body_map.front();E;E=E->next()) { + Object *obj = ObjectDB::get_instance(E->key()); + if (!obj) { + ret.resize( ret.size() -1 ); //ops + } else { + ret[idx++]=obj; + } + + } + + return ret; +} + void Area2D::_bind_methods() { @@ -290,6 +309,8 @@ void Area2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_enable_monitoring","enable"),&Area2D::set_enable_monitoring); ObjectTypeDB::bind_method(_MD("is_monitoring_enabled"),&Area2D::is_monitoring_enabled); + ObjectTypeDB::bind_method(_MD("get_overlapping_bodies"),&Area2D::get_overlapping_bodies); + ObjectTypeDB::bind_method(_MD("_body_inout"),&Area2D::_body_inout); diff --git a/scene/2d/area_2d.h b/scene/2d/area_2d.h index 85f2b91582..c6210e7c9a 100644 --- a/scene/2d/area_2d.h +++ b/scene/2d/area_2d.h @@ -112,6 +112,8 @@ public: void set_enable_monitoring(bool p_enable); bool is_monitoring_enabled() const; + Array get_overlapping_bodies() const; //function for script + Area2D(); ~Area2D(); diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp index f2f7a15e91..655c6e8bf6 100644 --- a/scene/2d/physics_body_2d.cpp +++ b/scene/2d/physics_body_2d.cpp @@ -618,6 +618,26 @@ RigidBody2D::CCDMode RigidBody2D::get_continuous_collision_detection_mode() cons } +Array RigidBody2D::get_colliding_bodies() const { + + ERR_FAIL_COND_V(!contact_monitor,Array()); + + Array ret; + ret.resize(contact_monitor->body_map.size()); + int idx=0; + for (const Map<ObjectID,BodyState>::Element *E=contact_monitor->body_map.front();E;E=E->next()) { + Object *obj = ObjectDB::get_instance(E->key()); + if (!obj) { + ret.resize( ret.size() -1 ); //ops + } else { + ret[idx++]=obj; + } + + } + + return ret; +} + void RigidBody2D::set_contact_monitor(bool p_enabled) { if (p_enabled==is_contact_monitor_enabled()) @@ -697,6 +717,8 @@ void RigidBody2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("_body_enter_tree"),&RigidBody2D::_body_enter_tree); ObjectTypeDB::bind_method(_MD("_body_exit_tree"),&RigidBody2D::_body_exit_tree); + ObjectTypeDB::bind_method(_MD("get_colliding_bodies"),&RigidBody2D::get_colliding_bodies); + BIND_VMETHOD(MethodInfo("_integrate_forces",PropertyInfo(Variant::OBJECT,"state:Physics2DDirectBodyState"))); ADD_PROPERTY( PropertyInfo(Variant::INT,"mode",PROPERTY_HINT_ENUM,"Rigid,Static,Character,Kinematic"),_SCS("set_mode"),_SCS("get_mode")); diff --git a/scene/2d/physics_body_2d.h b/scene/2d/physics_body_2d.h index 77e909f105..ca7b757497 100644 --- a/scene/2d/physics_body_2d.h +++ b/scene/2d/physics_body_2d.h @@ -229,6 +229,8 @@ public: void set_applied_force(const Vector2& p_force); Vector2 get_applied_force() const; + Array get_colliding_bodies() const; //function for script + RigidBody2D(); ~RigidBody2D(); diff --git a/scene/3d/area.cpp b/scene/3d/area.cpp index 407747fc0d..cb1df78fda 100644 --- a/scene/3d/area.cpp +++ b/scene/3d/area.cpp @@ -255,6 +255,24 @@ bool Area::is_monitoring_enabled() const { } +Array Area::get_overlapping_bodies() const { + + ERR_FAIL_COND_V(!monitoring,Array()); + Array ret; + ret.resize(body_map.size()); + int idx=0; + for (const Map<ObjectID,BodyState>::Element *E=body_map.front();E;E=E->next()) { + Object *obj = ObjectDB::get_instance(E->key()); + if (!obj) { + ret.resize( ret.size() -1 ); //ops + } else { + ret[idx++]=obj; + } + + } + + return ret; +} void Area::_bind_methods() { @@ -283,6 +301,8 @@ void Area::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_enable_monitoring","enable"),&Area::set_enable_monitoring); ObjectTypeDB::bind_method(_MD("is_monitoring_enabled"),&Area::is_monitoring_enabled); + ObjectTypeDB::bind_method(_MD("get_overlapping_bodies"),&Area::get_overlapping_bodies); + ObjectTypeDB::bind_method(_MD("_body_inout"),&Area::_body_inout); diff --git a/scene/3d/area.h b/scene/3d/area.h index 96b8585338..4707b73e1c 100644 --- a/scene/3d/area.h +++ b/scene/3d/area.h @@ -112,6 +112,8 @@ public: void set_enable_monitoring(bool p_enable); bool is_monitoring_enabled() const; + Array get_overlapping_bodies() const; + Area(); ~Area(); diff --git a/scene/3d/physics_body.cpp b/scene/3d/physics_body.cpp index a80fdce64c..21ecac6e3d 100644 --- a/scene/3d/physics_body.cpp +++ b/scene/3d/physics_body.cpp @@ -637,6 +637,27 @@ RigidBody::AxisLock RigidBody::get_axis_lock() const { } +Array RigidBody::get_colliding_bodies() const { + + ERR_FAIL_COND_V(!contact_monitor,Array()); + + Array ret; + ret.resize(contact_monitor->body_map.size()); + int idx=0; + for (const Map<ObjectID,BodyState>::Element *E=contact_monitor->body_map.front();E;E=E->next()) { + Object *obj = ObjectDB::get_instance(E->key()); + if (!obj) { + ret.resize( ret.size() -1 ); //ops + } else { + ret[idx++]=obj; + } + + } + + return ret; +} + + void RigidBody::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_mode","mode"),&RigidBody::set_mode); @@ -688,6 +709,8 @@ void RigidBody::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_axis_lock","axis_lock"),&RigidBody::set_axis_lock); ObjectTypeDB::bind_method(_MD("get_axis_lock"),&RigidBody::get_axis_lock); + ObjectTypeDB::bind_method(_MD("get_colliding_bodies"),&RigidBody::get_colliding_bodies); + BIND_VMETHOD(MethodInfo("_integrate_forces",PropertyInfo(Variant::OBJECT,"state:PhysicsDirectBodyState"))); ADD_PROPERTY( PropertyInfo(Variant::INT,"mode",PROPERTY_HINT_ENUM,"Rigid,Static,Character,Kinematic"),_SCS("set_mode"),_SCS("get_mode")); diff --git a/scene/3d/physics_body.h b/scene/3d/physics_body.h index f9f028e20d..0d1de7f236 100644 --- a/scene/3d/physics_body.h +++ b/scene/3d/physics_body.h @@ -236,6 +236,7 @@ public: void set_axis_lock(AxisLock p_lock); AxisLock get_axis_lock() const; + Array get_colliding_bodies() const; void apply_impulse(const Vector3& p_pos, const Vector3& p_impulse); |