diff options
author | proller <proller@github.com> | 2013-06-30 22:26:01 +0400 |
---|---|---|
committer | proller <proller@github.com> | 2013-06-30 22:48:51 +0400 |
commit | 37ca8854f7d1b16f3b561edd8bf19eaf6dd264d2 (patch) | |
tree | f5a8d16c53d1fe111f0fb02d1b5773363d9b2992 | |
parent | 067888d54943d301c45843858c763d4f81db215d (diff) | |
download | minetest-37ca8854f7d1b16f3b561edd8bf19eaf6dd264d2.tar.gz minetest-37ca8854f7d1b16f3b561edd8bf19eaf6dd264d2.tar.bz2 minetest-37ca8854f7d1b16f3b561edd8bf19eaf6dd264d2.zip |
Fix sand, gravel falling stuck
-rw-r--r-- | src/collision.cpp | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/src/collision.cpp b/src/collision.cpp index 3058426eb..df3878f4c 100644 --- a/src/collision.cpp +++ b/src/collision.cpp @@ -31,6 +31,9 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "main.h" // g_profiler #include "profiler.h" +// float error is 10 - 9.96875 = 0.03125 +#define COLL_ZERO 0.032 + // Helper function: // Checks for collision of a moving aabbox with a static aabbox // Returns -1 if no collision, 0 if X collision, 1 if Y collision, 2 if Z collision @@ -41,9 +44,9 @@ int axisAlignedCollision( { //TimeTaker tt("axisAlignedCollision"); - f32 xsize = (staticbox.MaxEdge.X - staticbox.MinEdge.X); - f32 ysize = (staticbox.MaxEdge.Y - staticbox.MinEdge.Y); - f32 zsize = (staticbox.MaxEdge.Z - staticbox.MinEdge.Z); + f32 xsize = (staticbox.MaxEdge.X - staticbox.MinEdge.X) - COLL_ZERO; // reduce box size for solve collision stuck (flying sand) + f32 ysize = (staticbox.MaxEdge.Y - staticbox.MinEdge.Y); // - COLL_ZERO; // Y - no sense for falling, but maybe try later + f32 zsize = (staticbox.MaxEdge.Z - staticbox.MinEdge.Z) - COLL_ZERO; aabb3f relbox( movingbox.MinEdge.X - staticbox.MinEdge.X, @@ -60,9 +63,9 @@ int axisAlignedCollision( { dtime = - relbox.MaxEdge.X / speed.X; if((relbox.MinEdge.Y + speed.Y * dtime < ysize) && - (relbox.MaxEdge.Y + speed.Y * dtime > 0) && + (relbox.MaxEdge.Y + speed.Y * dtime > COLL_ZERO) && (relbox.MinEdge.Z + speed.Z * dtime < zsize) && - (relbox.MaxEdge.Z + speed.Z * dtime > 0)) + (relbox.MaxEdge.Z + speed.Z * dtime > COLL_ZERO)) return 0; } else if(relbox.MinEdge.X > xsize) @@ -76,9 +79,9 @@ int axisAlignedCollision( { dtime = (xsize - relbox.MinEdge.X) / speed.X; if((relbox.MinEdge.Y + speed.Y * dtime < ysize) && - (relbox.MaxEdge.Y + speed.Y * dtime > 0) && + (relbox.MaxEdge.Y + speed.Y * dtime > COLL_ZERO) && (relbox.MinEdge.Z + speed.Z * dtime < zsize) && - (relbox.MaxEdge.Z + speed.Z * dtime > 0)) + (relbox.MaxEdge.Z + speed.Z * dtime > COLL_ZERO)) return 0; } else if(relbox.MaxEdge.X < 0) @@ -95,9 +98,9 @@ int axisAlignedCollision( { dtime = - relbox.MaxEdge.Y / speed.Y; if((relbox.MinEdge.X + speed.X * dtime < xsize) && - (relbox.MaxEdge.X + speed.X * dtime > 0) && + (relbox.MaxEdge.X + speed.X * dtime > COLL_ZERO) && (relbox.MinEdge.Z + speed.Z * dtime < zsize) && - (relbox.MaxEdge.Z + speed.Z * dtime > 0)) + (relbox.MaxEdge.Z + speed.Z * dtime > COLL_ZERO)) return 1; } else if(relbox.MinEdge.Y > ysize) @@ -111,9 +114,9 @@ int axisAlignedCollision( { dtime = (ysize - relbox.MinEdge.Y) / speed.Y; if((relbox.MinEdge.X + speed.X * dtime < xsize) && - (relbox.MaxEdge.X + speed.X * dtime > 0) && + (relbox.MaxEdge.X + speed.X * dtime > COLL_ZERO) && (relbox.MinEdge.Z + speed.Z * dtime < zsize) && - (relbox.MaxEdge.Z + speed.Z * dtime > 0)) + (relbox.MaxEdge.Z + speed.Z * dtime > COLL_ZERO)) return 1; } else if(relbox.MaxEdge.Y < 0) @@ -130,9 +133,9 @@ int axisAlignedCollision( { dtime = - relbox.MaxEdge.Z / speed.Z; if((relbox.MinEdge.X + speed.X * dtime < xsize) && - (relbox.MaxEdge.X + speed.X * dtime > 0) && + (relbox.MaxEdge.X + speed.X * dtime > COLL_ZERO) && (relbox.MinEdge.Y + speed.Y * dtime < ysize) && - (relbox.MaxEdge.Y + speed.Y * dtime > 0)) + (relbox.MaxEdge.Y + speed.Y * dtime > COLL_ZERO)) return 2; } //else if(relbox.MinEdge.Z > zsize) @@ -146,9 +149,9 @@ int axisAlignedCollision( { dtime = (zsize - relbox.MinEdge.Z) / speed.Z; if((relbox.MinEdge.X + speed.X * dtime < xsize) && - (relbox.MaxEdge.X + speed.X * dtime > 0) && + (relbox.MaxEdge.X + speed.X * dtime > COLL_ZERO) && (relbox.MinEdge.Y + speed.Y * dtime < ysize) && - (relbox.MaxEdge.Y + speed.Y * dtime > 0)) + (relbox.MaxEdge.Y + speed.Y * dtime > COLL_ZERO)) return 2; } //else if(relbox.MaxEdge.Z < 0) |