diff options
-rw-r--r-- | demos/2d/area_input/input.gd | 4 | ||||
-rw-r--r-- | demos/2d/area_input/input.scn | bin | 2886 -> 2886 bytes | |||
-rw-r--r-- | scene/main/viewport.cpp | 6 | ||||
-rw-r--r-- | scene/resources/world.cpp | 6 | ||||
-rw-r--r-- | scene/resources/world.h | 2 | ||||
-rw-r--r-- | scene/resources/world_2d.cpp | 9 | ||||
-rw-r--r-- | scene/resources/world_2d.h | 4 | ||||
-rw-r--r-- | servers/physics_2d_server.cpp | 31 | ||||
-rw-r--r-- | servers/physics_2d_server.h | 1 |
9 files changed, 57 insertions, 6 deletions
diff --git a/demos/2d/area_input/input.gd b/demos/2d/area_input/input.gd index acecd095ed..3f719fc853 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 Binary files differindex 0bb3a18834..1a2dcbc5f4 100644 --- a/demos/2d/area_input/input.scn +++ b/demos/2d/area_input/input.scn diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 18b8b46d90..ee400ae6d5 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 880a3a32e3..30cf58bdd8 100644 --- a/scene/resources/world.cpp +++ b/scene/resources/world.cpp @@ -307,6 +307,11 @@ Ref<Environment> 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 60b3b99ab0..b10cadd6e0 100644 --- a/scene/resources/world.h +++ b/scene/resources/world.h @@ -75,6 +75,8 @@ public: void set_environment(const Ref<Environment>& p_environment); Ref<Environment> 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 0dd6a3d5e7..43a7af4bfd 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 3feb23495d..865ec28fe9 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 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<Physics2DShapeQueryParam return ret; } + +Array Physics2DDirectSpaceState::_intersect_point(const Vector2& p_point,int p_max_results,const Vector<RID>& p_exclude,uint32_t p_layers,uint32_t p_object_type_mask) { + + Set<RID> exclude; + for(int i=0;i<p_exclude.size();i++) + exclude.insert(p_exclude[i]); + + Vector<ShapeResult> 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<rc;i++) { + + Dictionary d; + d["rid"]=ret[i].rid; + d["collider_id"]=ret[i].collider_id; + d["collider"]=ret[i].collider; + d["shape"]=ret[i].shape; + d["metadata"]=ret[i].metadata; + r[i]=d; + } + return r; + +} + Array Physics2DDirectSpaceState::_collide_shape(const Ref<Physics2DShapeQueryParameters> &psq, int p_max_results){ Vector<Vector2> 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<RID>& p_exclude=Vector<RID>(),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<RID>& p_exclude=Vector<RID>(),uint32_t p_layers=0,uint32_t p_object_type_mask=TYPE_MASK_COLLISION); Array _intersect_shape(const Ref<Physics2DShapeQueryParameters> &p_shape_query,int p_max_results=32); Array _cast_motion(const Ref<Physics2DShapeQueryParameters> &p_shape_query); Array _collide_shape(const Ref<Physics2DShapeQueryParameters> &p_shape_query,int p_max_results=32); |