From d7d65fa2f2b51d03f7bdfcbceedca99188ce979c Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Wed, 19 Feb 2014 11:57:14 -0300 Subject: -improved physics ccd -html5 exporter works again -disable repeat on image loader by default -can change shape offset en tileset, texture offset was broken --- servers/physics_2d/broad_phase_2d_hash_grid.cpp | 37 ++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 4 deletions(-) (limited to 'servers/physics_2d/broad_phase_2d_hash_grid.cpp') diff --git a/servers/physics_2d/broad_phase_2d_hash_grid.cpp b/servers/physics_2d/broad_phase_2d_hash_grid.cpp index 10da376dfd..129c9ecb9c 100644 --- a/servers/physics_2d/broad_phase_2d_hash_grid.cpp +++ b/servers/physics_2d/broad_phase_2d_hash_grid.cpp @@ -378,7 +378,8 @@ int BroadPhase2DHashGrid::get_subindex(ID p_id) const { return E->get().subindex; } -void BroadPhase2DHashGrid::_cull(const Point2i p_cell,CollisionObject2DSW** p_results,int p_max_results,int *p_result_indices,int &index) { +template +void BroadPhase2DHashGrid::_cull(const Point2i p_cell,const Rect2& p_aabb,const Point2& p_from, const Point2& p_to,CollisionObject2DSW** p_results,int p_max_results,int *p_result_indices,int &index) { PosKey pk; @@ -411,10 +412,18 @@ void BroadPhase2DHashGrid::_cull(const Point2i p_cell,CollisionObject2DSW** p_re continue; E->key()->pass=pass; + + if (use_aabb && !p_aabb.intersects(E->key()->aabb)) + continue; + + if (use_segment && !E->key()->aabb.intersects_segment(p_from,p_to)) + continue; + p_results[index]=E->key()->owner; p_result_indices[index]=E->key()->subindex; index++; + } for(Map::Element *E=pb->static_object_set.front();E;E=E->next()) { @@ -425,6 +434,12 @@ void BroadPhase2DHashGrid::_cull(const Point2i p_cell,CollisionObject2DSW** p_re if (E->key()->pass==pass) continue; + if (use_aabb && !p_aabb.intersects(E->key()->aabb)) + continue; + + if (use_segment && !E->key()->aabb.intersects_segment(p_from,p_to)) + continue; + E->key()->pass=pass; p_results[index]=E->key()->owner; p_result_indices[index]=E->key()->subindex; @@ -468,7 +483,7 @@ int BroadPhase2DHashGrid::cull_segment(const Vector2& p_from, const Vector2& p_t max.y= (Math::floor(pos.y + 1)*cell_size - p_from.y) / dir.y; int cullcount=0; - _cull(pos,p_results,p_max_results,p_result_indices,cullcount); + _cull(pos,Rect2(),p_from,p_to,p_results,p_max_results,p_result_indices,cullcount); bool reached_x=false; bool reached_y=false; @@ -502,7 +517,7 @@ int BroadPhase2DHashGrid::cull_segment(const Vector2& p_from, const Vector2& p_t reached_y=true; } - _cull(pos,p_results,p_max_results,p_result_indices,cullcount); + _cull(pos,Rect2(),p_from,p_to,p_results,p_max_results,p_result_indices,cullcount); if (reached_x && reached_y) break; @@ -515,8 +530,22 @@ int BroadPhase2DHashGrid::cull_segment(const Vector2& p_from, const Vector2& p_t int BroadPhase2DHashGrid::cull_aabb(const Rect2& p_aabb,CollisionObject2DSW** p_results,int p_max_results,int *p_result_indices) { + pass++; + + Point2i from = (p_aabb.pos/cell_size).floor(); + Point2i to = ((p_aabb.pos+p_aabb.size)/cell_size).floor(); + int cullcount=0; + + for(int i=from.x;i<=to.x;i++) { + + for(int j=from.y;j<=to.y;j++) { - return 0; + _cull(Point2i(i,j),p_aabb,Point2(),Point2(),p_results,p_max_results,p_result_indices,cullcount); + } + + } + + return cullcount; } void BroadPhase2DHashGrid::set_pair_callback(PairCallback p_pair_callback,void *p_userdata) { -- cgit v1.2.3