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 drfrag666
parent e261c73b31
commit b34bc0947e
2 changed files with 45 additions and 1 deletions

View file

@ -96,6 +96,7 @@
#include "actorinlines.h"
#include "vm.h"
#include "i_time.h"
#include "nodebuild.h"
#include <string.h>
@ -1987,10 +1988,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>
inline T VecDiff(const T& v1, const T& v2)
{

View file

@ -664,6 +664,8 @@ struct LevelLocals native
native bool IsCrouchingAllowed() const;
native bool IsFreelookAllowed() const;
native static clearscope bool IsPointInMap(vector3 p);
native static clearscope vector2 Vec2Diff(vector2 v1, vector2 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);