From dac2017dee8a58c85b8b3218a779260d3b5f4072 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sun, 22 Mar 2015 09:40:26 -0300 Subject: fixes/cleans up -input now correctly works when using viewport scaling -added function to get areas/bodies in given point -added function to get space state directly from world --- servers/physics_2d_server.cpp | 31 +++++++++++++++++++++++++++++++ servers/physics_2d_server.h | 1 + 2 files changed, 32 insertions(+) (limited to 'servers') diff --git a/servers/physics_2d_server.cpp b/servers/physics_2d_server.cpp index 07389bc912..098f890222 100644 --- a/servers/physics_2d_server.cpp +++ b/servers/physics_2d_server.cpp @@ -289,6 +289,36 @@ Array Physics2DDirectSpaceState::_cast_motion(const Ref& p_exclude,uint32_t p_layers,uint32_t p_object_type_mask) { + + Set exclude; + for(int i=0;i ret; + ret.resize(p_max_results); + + int rc = intersect_point(p_point,ret.ptr(),ret.size(),exclude,p_layers,p_object_type_mask); + if (rc==0) + return Array(); + + Array r; + r.resize(rc); + for(int i=0;i &psq, int p_max_results){ Vector ret; @@ -336,6 +366,7 @@ Physics2DDirectSpaceState::Physics2DDirectSpaceState() { void Physics2DDirectSpaceState::_bind_methods() { + ObjectTypeDB::bind_method(_MD("intersect_point","point","max_results","exclude","layer_mask","type_mask"),&Physics2DDirectSpaceState::_intersect_point,DEFVAL(32),DEFVAL(Array()),DEFVAL(0x7FFFFFFF),DEFVAL(TYPE_MASK_COLLISION)); ObjectTypeDB::bind_method(_MD("intersect_ray:Dictionary","from","to","exclude","layer_mask","type_mask"),&Physics2DDirectSpaceState::_intersect_ray,DEFVAL(Array()),DEFVAL(0x7FFFFFFF),DEFVAL(TYPE_MASK_COLLISION)); ObjectTypeDB::bind_method(_MD("intersect_shape","shape:Physics2DShapeQueryParameters","max_results"),&Physics2DDirectSpaceState::_intersect_shape,DEFVAL(32)); ObjectTypeDB::bind_method(_MD("cast_motion","shape:Physics2DShapeQueryParameters"),&Physics2DDirectSpaceState::_cast_motion); diff --git a/servers/physics_2d_server.h b/servers/physics_2d_server.h index 657e5ce441..01670ace7e 100644 --- a/servers/physics_2d_server.h +++ b/servers/physics_2d_server.h @@ -137,6 +137,7 @@ class Physics2DDirectSpaceState : public Object { Dictionary _intersect_ray(const Vector2& p_from, const Vector2& p_to,const Vector& p_exclude=Vector(),uint32_t p_layers=0,uint32_t p_object_type_mask=TYPE_MASK_COLLISION); + Array _intersect_point(const Vector2& p_point,int p_max_results=32,const Vector& p_exclude=Vector(),uint32_t p_layers=0,uint32_t p_object_type_mask=TYPE_MASK_COLLISION); Array _intersect_shape(const Ref &p_shape_query,int p_max_results=32); Array _cast_motion(const Ref &p_shape_query); Array _collide_shape(const Ref &p_shape_query,int p_max_results=32); -- cgit v1.2.3