diff --git a/source/src/physics.cpp b/source/src/physics.cpp index bfb02623..6079df6f 100644 --- a/source/src/physics.cpp +++ b/source/src/physics.cpp @@ -59,6 +59,17 @@ float raycube(const vec &o, const vec &ray, vec &surface) return dist; } +bool raycubelos(const vec &from, const vec &to, float margin) +{ + vec dir(to); + dir.sub(from); + float limit = dir.magnitude(); + dir.mul(1.0f/limit); + vec surface; + float dist = raycube(from, dir, surface); + return dist > max(limit - margin, 0.0f); +} + physent *hitplayer = NULL; bool plcollide(physent *d, physent *o, float &headspace, float &hi, float &lo) // collide with physent diff --git a/source/src/protos.h b/source/src/protos.h index 88206bb8..916910f2 100644 --- a/source/src/protos.h +++ b/source/src/protos.h @@ -499,6 +499,7 @@ extern uchar *readmcfggz(char *name, int *size, int *sizegz); // physics extern float raycube(const vec &o, const vec &ray, vec &surface); +extern bool raycubelos(const vec &from, const vec &to, float margin = 0); extern void moveplayer(physent *pl, int moveres, bool local); extern void moveplayer(physent *pl, int moveres, bool local, int curtime); extern void movebounceent(bounceent *p, int moveres, bool local);