From 7e238e849f6d1013980ff36ca1563f2a823515b0 Mon Sep 17 00:00:00 2001 From: Lee Salzman Date: Sun, 14 Sep 2008 01:08:50 +0000 Subject: [PATCH] line of sight finding git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@2579 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/physics.cpp | 11 +++++++++++ source/src/protos.h | 1 + 2 files changed, 12 insertions(+) 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);