diff options
author | Juan Linietsky <reduzio@gmail.com> | 2014-02-19 11:57:14 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2014-02-19 11:57:14 -0300 |
commit | d7d65fa2f2b51d03f7bdfcbceedca99188ce979c (patch) | |
tree | fecdf1bfa39ba5a4895b4dbf340a3b68098c109a /servers/physics_2d/broad_phase_2d_hash_grid.cpp | |
parent | 8c1731b67995add31361ae526b0e6af76346181e (diff) |
-improved physics ccd
-html5 exporter works again
-disable repeat on image loader by default
-can change shape offset en tileset, texture offset was broken
Diffstat (limited to 'servers/physics_2d/broad_phase_2d_hash_grid.cpp')
-rw-r--r-- | servers/physics_2d/broad_phase_2d_hash_grid.cpp | 37 |
1 files changed, 33 insertions, 4 deletions
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<bool use_aabb,bool use_segment> +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*,RC>::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<false,true>(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<false,true>(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<true,false>(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) { |