diff options
author | Nils Dagsson Moskopp <nils@dieweltistgarnichtso.net> | 2011-07-14 22:43:22 +0200 |
---|---|---|
committer | Nils Dagsson Moskopp <nils@dieweltistgarnichtso.net> | 2011-07-14 22:43:28 +0200 |
commit | af05e4b2defde537f3b953a7dae0ef44fae225aa (patch) | |
tree | 3f751014432b35df1cc2fd6fb976410e86b70e73 /src/collision.cpp | |
parent | 4415d95c503f083d871abaf84516f2b6487ecb60 (diff) | |
parent | 81535f6277b66c869cda7125b2aeaf99e8078b92 (diff) | |
download | minetest-af05e4b2defde537f3b953a7dae0ef44fae225aa.tar.gz minetest-af05e4b2defde537f3b953a7dae0ef44fae225aa.tar.bz2 minetest-af05e4b2defde537f3b953a7dae0ef44fae225aa.zip |
Merge branch 'upstream/master'
Conflicts:
data/oerkki1.png
src/client.cpp
Diffstat (limited to 'src/collision.cpp')
-rw-r--r-- | src/collision.cpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/collision.cpp b/src/collision.cpp index 63186a84a..01d546284 100644 --- a/src/collision.cpp +++ b/src/collision.cpp @@ -182,4 +182,58 @@ collisionMoveResult collisionMoveSimple(Map *map, f32 pos_max_d, return result; } +collisionMoveResult collisionMovePrecise(Map *map, f32 pos_max_d, + const core::aabbox3d<f32> &box_0, + f32 dtime, v3f &pos_f, v3f &speed_f) +{ + collisionMoveResult final_result; + + // Maximum time increment (for collision detection etc) + // time = distance / speed + f32 dtime_max_increment = pos_max_d / speed_f.getLength(); + + // Maximum time increment is 10ms or lower + if(dtime_max_increment > 0.01) + dtime_max_increment = 0.01; + + // Don't allow overly huge dtime + if(dtime > 2.0) + dtime = 2.0; + + f32 dtime_downcount = dtime; + + u32 loopcount = 0; + do + { + loopcount++; + + f32 dtime_part; + if(dtime_downcount > dtime_max_increment) + { + dtime_part = dtime_max_increment; + dtime_downcount -= dtime_part; + } + else + { + dtime_part = dtime_downcount; + /* + Setting this to 0 (no -=dtime_part) disables an infinite loop + when dtime_part is so small that dtime_downcount -= dtime_part + does nothing + */ + dtime_downcount = 0; + } + + collisionMoveResult result = collisionMoveSimple(map, pos_max_d, + box_0, dtime_part, pos_f, speed_f); + + if(result.touching_ground) + final_result.touching_ground = true; + } + while(dtime_downcount > 0.001); + + + return final_result; +} + |