Add ZScript method LevelLocals.SphericalCoords.

It computes spherical coordinates from one point in the world to another. Useful for checking whether one actor is inside another actor's view cone.
This commit is contained in:
argv-minus-one 2018-08-20 16:31:52 -07:00 committed by drfrag666
parent d729e31603
commit 66933d6b91
2 changed files with 25 additions and 0 deletions

View file

@ -2026,6 +2026,30 @@ DEFINE_ACTION_FUNCTION(FLevelLocals, Vec3Diff)
ACTION_RETURN_VEC3(VecDiff(DVector3(x1, y1, z1), DVector3(x2, y2, z2)));
}
DEFINE_ACTION_FUNCTION(FLevelLocals, SphericalCoords)
{
PARAM_PROLOGUE;
PARAM_FLOAT(viewpointX);
PARAM_FLOAT(viewpointY);
PARAM_FLOAT(viewpointZ);
PARAM_FLOAT(targetX);
PARAM_FLOAT(targetY);
PARAM_FLOAT(targetZ);
PARAM_ANGLE_DEF(viewYaw);
PARAM_ANGLE_DEF(viewPitch);
PARAM_BOOL_DEF(absolute);
DVector3 viewpoint(viewpointX, viewpointY, viewpointZ);
DVector3 target(targetX, targetY, targetZ);
auto vecTo = absolute ? target - viewpoint : VecDiff(viewpoint, target);
ACTION_RETURN_VEC3(DVector3(
deltaangle(vecTo.Angle(), viewYaw).Degrees,
deltaangle(-vecTo.Pitch(), viewPitch).Degrees,
vecTo.Length()
));
}
DEFINE_ACTION_FUNCTION(FLevelLocals, Vec2Offset)
{
PARAM_PROLOGUE;

View file

@ -662,6 +662,7 @@ struct LevelLocals native
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);
native static clearscope vector2 Vec2Offset(vector2 pos, vector2 dir, bool absolute = false);
native static clearscope vector3 Vec2OffsetZ(vector2 pos, vector2 dir, double atz, bool absolute = false);