diff options
| author | Juan Linietsky | 2015-03-22 01:46:18 -0300 |
|---|---|---|
| committer | Juan Linietsky | 2015-03-22 01:46:18 -0300 |
| commit | c6c72a3c37a44964ec8e6b3353f78635bf588eab (patch) | |
| tree | 07cdc6f2a776dece704cce526cfd15ae04e44360 /servers/physics_2d/space_2d_sw.cpp | |
| parent | 40496dd76ae53c93ef5ea7e56671682a7cae9def (diff) | |
| download | godot-c6c72a3c37a44964ec8e6b3353f78635bf588eab.tar.gz godot-c6c72a3c37a44964ec8e6b3353f78635bf588eab.tar.zst godot-c6c72a3c37a44964ec8e6b3353f78635bf588eab.zip | |
input events on Area2D is now supported
also added a demo showing how this works
Diffstat (limited to 'servers/physics_2d/space_2d_sw.cpp')
| -rw-r--r-- | servers/physics_2d/space_2d_sw.cpp | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/servers/physics_2d/space_2d_sw.cpp b/servers/physics_2d/space_2d_sw.cpp index 9523e8bf8..5aaf9a761 100644 --- a/servers/physics_2d/space_2d_sw.cpp +++ b/servers/physics_2d/space_2d_sw.cpp @@ -45,6 +45,57 @@ _FORCE_INLINE_ static bool _match_object_type_query(CollisionObject2DSW *p_objec } + +int Physics2DDirectSpaceStateSW::intersect_point(const Vector2& p_point,ShapeResult *r_results,int p_result_max,const Set<RID>& p_exclude,uint32_t p_layer_mask,uint32_t p_object_type_mask) { + + if (p_result_max<=0) + return 0; + + Rect2 aabb; + aabb.pos=p_point-Vector2(0.00001,0.00001); + aabb.size=Vector2(0.00002,0.00002); + + int amount = space->broadphase->cull_aabb(aabb,space->intersection_query_results,Space2DSW::INTERSECTION_QUERY_MAX,space->intersection_query_subindex_results); + + int cc=0; + + for(int i=0;i<amount;i++) { + + if (!_match_object_type_query(space->intersection_query_results[i],p_layer_mask,p_object_type_mask)) + continue; + + if (p_exclude.has( space->intersection_query_results[i]->get_self())) + continue; + + const CollisionObject2DSW *col_obj=space->intersection_query_results[i]; + + if (!col_obj->is_pickable()) + continue; + + int shape_idx=space->intersection_query_subindex_results[i]; + + Shape2DSW * shape = col_obj->get_shape(shape_idx); + + Vector2 local_point = (col_obj->get_transform() * col_obj->get_shape_transform(shape_idx)).affine_inverse().xform(p_point); + + if (!shape->contains_point(local_point)) + continue; + + r_results[cc].collider_id=col_obj->get_instance_id(); + if (r_results[cc].collider_id!=0) + r_results[cc].collider=ObjectDB::get_instance(r_results[cc].collider_id); + r_results[cc].rid=col_obj->get_self(); + r_results[cc].shape=shape_idx; + r_results[cc].metadata=col_obj->get_shape_metadata(shape_idx); + + cc++; + } + + return cc; + + +} + bool Physics2DDirectSpaceStateSW::intersect_ray(const Vector2& p_from, const Vector2& p_to,RayResult &r_result,const Set<RID>& p_exclude,uint32_t p_layer_mask,uint32_t p_object_type_mask) { |
