Added IsPointInMap(Vector3 p).

- Checks if a point is inside the map geometry or not.
This commit is contained in:
Major Cooke 2018-11-07 14:03:32 -06:00 committed by Rachael Alexanderson
parent 4eecaada67
commit 9ff7f338fd
2 changed files with 45 additions and 1 deletions

View file

@ -85,6 +85,7 @@
#include "g_levellocals.h" #include "g_levellocals.h"
#include "actorinlines.h" #include "actorinlines.h"
#include "i_time.h" #include "i_time.h"
#include "nodebuild.h"
void STAT_StartNewGame(const char *lev); void STAT_StartNewGame(const char *lev);
void STAT_ChangeLevel(const char *newl); void STAT_ChangeLevel(const char *newl);
@ -2004,10 +2005,51 @@ void FLevelLocals::SetMusicVolume(float f)
} }
//========================================================================== //==========================================================================
// IsPointInMap
// //
// // Checks to see if a point is inside the void or not.
// Made by dpJudas, modified and implemented by Major Cooke
//========================================================================== //==========================================================================
bool IsPointInMap(DVector3 p)
{
subsector_t *subsector = R_PointInSubsector(FLOAT2FIXED(p.X), FLOAT2FIXED(p.Y));
if (!subsector) return false;
for (uint32_t i = 0; i < subsector->numlines; i++)
{
// Skip single sided lines.
seg_t *seg = subsector->firstline + i;
if (seg->backsector != nullptr) continue;
int sx = (int)seg->v1->fX();
int sy = (int)seg->v1->fY();
int dx = (int)seg->v2->fX() - sx;
int dy = (int)seg->v2->fY() - sy;
int res = FNodeBuilder::PointOnSide(sx, sy, (int)p.X, (int)p.Y, dx, dy);
bool pointOnSide = (res > 0);
if (!pointOnSide) return false;
}
double ceilingZ = subsector->sector->ceilingplane.ZatPoint(p.X, p.Y);
if (p.Z > ceilingZ) return false;
double floorZ = subsector->sector->floorplane.ZatPoint(p.X, p.Y);
if (p.Z < floorZ) return false;
return true;
}
DEFINE_ACTION_FUNCTION(FLevelLocals, IsPointInMap)
{
PARAM_PROLOGUE;
PARAM_FLOAT(x);
PARAM_FLOAT(y);
PARAM_FLOAT(z);
ACTION_RETURN_BOOL(IsPointInMap(DVector3(x,y,z)));
}
template <typename T> template <typename T>
inline T VecDiff(const T& v1, const T& v2) inline T VecDiff(const T& v1, const T& v2)
{ {

View file

@ -670,6 +670,8 @@ struct LevelLocals native
native bool IsCrouchingAllowed() const; native bool IsCrouchingAllowed() const;
native bool IsFreelookAllowed() const; native bool IsFreelookAllowed() const;
native static clearscope bool IsPointInMap(vector3 p);
native static clearscope vector2 Vec2Diff(vector2 v1, vector2 v2); native static clearscope vector2 Vec2Diff(vector2 v1, vector2 v2);
native static clearscope vector3 Vec3Diff(vector3 v1, vector3 v2); native static clearscope vector3 Vec3Diff(vector3 v1, vector3 v2);
native static clearscope vector3 SphericalCoords(vector3 viewpoint, vector3 targetPos, vector2 viewAngles = (0, 0), bool absolute = false); native static clearscope vector3 SphericalCoords(vector3 viewpoint, vector3 targetPos, vector2 viewAngles = (0, 0), bool absolute = false);