#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
{
//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,
{
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)
{
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)
{
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)
{
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)
{
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)
{
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)