From: proller Date: Sun, 30 Jun 2013 18:26:01 +0000 (+0400) Subject: Fix sand, gravel falling stuck X-Git-Tag: 0.4.8~369 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=37ca8854f7d1b16f3b561edd8bf19eaf6dd264d2;p=oweals%2Fminetest.git Fix sand, gravel falling stuck --- 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)