Advertisement
Dimon_UA

Untitled

Oct 4th, 2014
392
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. scriptName "fn_inMarker.sqf";
  2. /*
  3.     File: inTrigger.sqf
  4.     Author: Karel Moricky
  5.  
  6.     Returns:
  7.     Boolean (true when position is in area, false if not).
  8. */
  9. private ["_mrk","_mrkarea","_posx","_posy","_tarea","_tx","_ty","_tdir","_tshape","_in"];
  10.  
  11. _mrk = _this select 0;
  12. _position = _this select 1;
  13.  
  14. _scalarresult = if (count _this > 2) then {_this select 2} else {false};
  15.  
  16. _posx = getMarkerPos _mrk select 0;
  17. _posy = getMarkerPos _mrk select 1;
  18. _mrkarea = getMarkerSize _mrk;
  19. _tx = _mrkarea select 0;
  20. _ty = _mrkarea select 1;
  21. _tdir = markerDir _mrk;
  22. _tshape = markerShape _mrk;
  23. _in = false;
  24.  
  25. if (_tshape == "RECTANGLE") then
  26. {
  27.  
  28.     //--- RECTANGLE
  29.     _difx = (_position select 0) - _posx;
  30.     _dify = (_position select 1) - _posy;
  31.     _dir = atan (_difx / _dify);
  32.     if (_dify < 0) then {_dir = _dir + 180};
  33.     _relativedir = _tdir - _dir;
  34.     _adis = abs (_tx / cos (90 - _relativedir));
  35.     _bdis = abs (_ty / cos _relativedir);
  36.     _borderdis = _adis min _bdis;
  37.     _positiondis = _position distance getMarkerPos _mrk;
  38.  
  39.     _in = if (_scalarresult) then {
  40.         _positiondis - _borderdis;
  41.     } else {
  42.         if (_positiondis < _borderdis) then {true} else {false};
  43.     };
  44.  
  45. };
  46. if (_tshape == "ELLIPSE") then
  47. {
  48.     //--- ELLIPSE
  49.     _e = sqrt(_tx^2 - _ty^2);
  50.     _posF1 = [_posx + (sin (_tdir+90) * _e),_posy + (cos (_tdir+90) * _e)];
  51.     _posF2 = [_posx - (sin (_tdir+90) * _e),_posy - (cos (_tdir+90) * _e)];
  52.     _total = 2 * _tx;
  53.  
  54.     _dis1 = _position distance _posF1;
  55.     _dis2 = _position distance _posF2;
  56.     _in = if (_scalarresult) then {
  57.         (_dis1+_dis2) - _total;
  58.     } else {
  59.         if (_dis1+_dis2 < _total) then {true} else {false};
  60.     };
  61. };
  62.  
  63. _in
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement