diff --git a/demos/2d/area_input/input.gd b/demos/2d/area_input/input.gd index acecd095ed3..3f719fc853e 100644 --- a/demos/2d/area_input/input.gd +++ b/demos/2d/area_input/input.gd @@ -1,10 +1,6 @@ extends Area2D -# member variables here, example: -# var a=2 -# var b="textvar" - #virtual from CollisionObject2D (also available as signal) func _input_event(viewport, event, shape_idx): #convert event to local coordinates diff --git a/demos/2d/area_input/input.scn b/demos/2d/area_input/input.scn index 0bb3a18834a..1a2dcbc5f44 100644 Binary files a/demos/2d/area_input/input.scn and b/demos/2d/area_input/input.scn differ diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 18b8b46d903..ee400ae6d5a 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -104,8 +104,10 @@ void Viewport::_update_stretch_transform() { stretch_transform.scale(scale); stretch_transform.elements[2]=size_override_margin*scale; + } else { + stretch_transform=Matrix32(); } @@ -1076,8 +1078,9 @@ Matrix32 Viewport::_get_input_pre_xform() const { ERR_FAIL_COND_V(to_screen_rect.size.x==0,pre_xf); ERR_FAIL_COND_V(to_screen_rect.size.y==0,pre_xf); - pre_xf.scale(rect.size/to_screen_rect.size); + pre_xf.elements[2]=-to_screen_rect.pos; + pre_xf.scale(rect.size/to_screen_rect.size); } else { pre_xf.elements[2]=-rect.pos; @@ -1141,6 +1144,7 @@ void Viewport::_make_input_local(InputEvent& ev) { } break; } + } diff --git a/scene/resources/world.cpp b/scene/resources/world.cpp index 880a3a32e36..30cf58bdd87 100644 --- a/scene/resources/world.cpp +++ b/scene/resources/world.cpp @@ -307,6 +307,11 @@ Ref World::get_environment() const { } +PhysicsDirectSpaceState *World::get_direct_space_state() { + + return PhysicsServer::get_singleton()->space_get_direct_state(space); +} + void World::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_space"),&World::get_space); @@ -314,6 +319,7 @@ void World::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_sound_space"),&World::get_sound_space); ObjectTypeDB::bind_method(_MD("set_environment","env:Environment"),&World::set_environment); ObjectTypeDB::bind_method(_MD("get_environment:Environment"),&World::get_environment); + ObjectTypeDB::bind_method(_MD("get_direct_space_state:PhysicsDirectSpaceState"),&World::get_direct_space_state); ADD_PROPERTY(PropertyInfo(Variant::OBJECT,"environment",PROPERTY_HINT_RESOURCE_TYPE,"Environment"),_SCS("set_environment"),_SCS("get_environment")); } diff --git a/scene/resources/world.h b/scene/resources/world.h index 60b3b99ab0c..b10cadd6e08 100644 --- a/scene/resources/world.h +++ b/scene/resources/world.h @@ -75,6 +75,8 @@ public: void set_environment(const Ref& p_environment); Ref get_environment() const; + PhysicsDirectSpaceState *get_direct_space_state(); + World(); ~World(); diff --git a/scene/resources/world_2d.cpp b/scene/resources/world_2d.cpp index 0dd6a3d5e7b..43a7af4bfd4 100644 --- a/scene/resources/world_2d.cpp +++ b/scene/resources/world_2d.cpp @@ -352,8 +352,17 @@ void World2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_canvas"),&World2D::get_canvas); ObjectTypeDB::bind_method(_MD("get_space"),&World2D::get_space); ObjectTypeDB::bind_method(_MD("get_sound_space"),&World2D::get_sound_space); + + ObjectTypeDB::bind_method(_MD("get_direct_space_state:Physics2DDirectSpaceState"),&World2D::get_direct_space_state); + } +Physics2DDirectSpaceState *World2D::get_direct_space_state() { + + return Physics2DServer::get_singleton()->space_get_direct_state(space); +} + + World2D::World2D() { canvas = VisualServer::get_singleton()->canvas_create(); diff --git a/scene/resources/world_2d.h b/scene/resources/world_2d.h index 3feb23495da..865ec28fe99 100644 --- a/scene/resources/world_2d.h +++ b/scene/resources/world_2d.h @@ -30,7 +30,7 @@ #define WORLD_2D_H #include "resource.h" - +#include "servers/physics_2d_server.h" class SpatialIndexer2D; class VisibilityNotifier2D; @@ -68,6 +68,8 @@ public: RID get_space(); RID get_sound_space(); + Physics2DDirectSpaceState *get_direct_space_state(); + World2D(); ~World2D(); }; diff --git a/servers/physics_2d_server.cpp b/servers/physics_2d_server.cpp index 07389bc912c..098f890222f 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 657e5ce4419..01670ace7e5 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);