Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- scriptName "fn_inarrayMarker.sqf";
- /*
- File: fn_inarrayMarker.sqf
- Author: Karel Moricky
- Edited: Dimon UA
- Description:
- Detects whether is position within array marker area.
- Parameter(s):
- _this select 0: array marker
- _this select 1: Position
- _this select 2: OPTIONAL - scalar result (distance from border)
- Returns:
- Boolean (true when position is in area, false if not).
- */
- //scopeName "main";
- private ["_arraymrk","_mrkarea","_posx","_posy","_tarea","_tx","_ty","_tdir","_tshape","_in"];
- _arraymrk = _this select 0;
- _position = _this select 1;
- _scalarresult = if (count _this > 2) then {_this select 2} else {false};
- {
- _posx = getMarkerPos _x select 0;
- _posy = getMarkerPos _x select 1;
- _mrkarea = getMarkerSize _x;
- _tx = _mrkarea select 0;
- _ty = _mrkarea select 1;
- _tdir = markerDir _x;
- _tshape = markerShape _x;
- _in = false;
- if (_tshape == "RECTANGLE") then
- {
- //--- RECTANGLE
- _difx = (_position select 0) - _posx;
- _dify = (_position select 1) - _posy;
- _dir = atan (_difx / _dify);
- if (_dify < 0) then {_dir = _dir + 180};
- _relativedir = _tdir - _dir;
- _adis = abs (_tx / cos (90 - _relativedir));
- _bdis = abs (_ty / cos _relativedir);
- _borderdis = _adis min _bdis;
- _positiondis = _position distance getMarkerPos _x;
- _in = if (_scalarresult) then {
- _positiondis - _borderdis;
- } else {
- if (_positiondis < _borderdis) then {true} else {false};
- };
- };
- if (_tshape == "ELLIPSE") then
- {
- //--- ELLIPSE
- _e = sqrt(_tx^2 - _ty^2);
- _posF1 = [_posx + (sin (_tdir+90) * _e),_posy + (cos (_tdir+90) * _e)];
- _posF2 = [_posx - (sin (_tdir+90) * _e),_posy - (cos (_tdir+90) * _e)];
- _total = 2 * _tx;
- _dis1 = _position distance _posF1;
- _dis2 = _position distance _posF2;
- _in = if (_scalarresult) then {
- (_dis1+_dis2) - _total;
- } else {
- if (_dis1+_dis2 < _total) then {true} else {false;};
- };
- };
- if _in exitwith { true};
- } foreach _arraymrk;
- _in
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement