Added vector diff functions to ZScript LevelLocals class

Vec2Diff() and Vec3Diff() work like Actor’s Vec2To() and Vec3To() but use arbitrary points
This commit is contained in:
Major Cooke 2017-12-31 19:02:14 -06:00 committed by alexey.lysiuk
parent c4648a2b1c
commit c3c1e76e8a
2 changed files with 49 additions and 0 deletions

View File

@ -1954,6 +1954,52 @@ DEFINE_ACTION_FUNCTION(FLevelLocals, SetInterMusic)
return 0;
}
//==========================================================================
//
//
//==========================================================================
template <typename T>
inline T VecDiff(const T& v1, const T& v2)
{
T result = v2 - v1;
if (level.subsectors.Size() > 0)
{
const sector_t *const sec1 = P_PointInSector(v1);
const sector_t *const sec2 = P_PointInSector(v2);
if (nullptr != sec1 && nullptr != sec2)
{
result += Displacements.getOffset(sec2->PortalGroup, sec1->PortalGroup);
}
}
return result;
}
DEFINE_ACTION_FUNCTION(FLevelLocals, Vec2Diff)
{
PARAM_PROLOGUE;
PARAM_FLOAT(x1);
PARAM_FLOAT(y1);
PARAM_FLOAT(x2);
PARAM_FLOAT(y2);
ACTION_RETURN_VEC2(VecDiff(DVector2(x1, y1), DVector2(x2, y2)));
}
DEFINE_ACTION_FUNCTION(FLevelLocals, Vec3Diff)
{
PARAM_PROLOGUE;
PARAM_FLOAT(x1);
PARAM_FLOAT(y1);
PARAM_FLOAT(z1);
PARAM_FLOAT(x2);
PARAM_FLOAT(y2);
PARAM_FLOAT(z2);
ACTION_RETURN_VEC3(VecDiff(DVector3(x1, y1, z1), DVector3(x2, y2, z2)));
}
//==========================================================================
//
//

View File

@ -552,6 +552,9 @@ struct LevelLocals native
native bool IsJumpingAllowed() const;
native bool IsCrouchingAllowed() const;
native bool IsFreelookAllowed() const;
native static clearscope vector2 Vec2Diff(vector2 v1, vector2 v2);
native static clearscope vector3 Vec3Diff(vector3 v1, vector3 v2);
String TimeFormatted(bool totals = false)
{