Advertisement
Guest User

Untitled

a guest
Jan 27th, 2015
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. scriptName "fn_inarrayMarker.sqf";
  2. /*
  3. File: fn_inarrayMarker.sqf
  4. Author: Karel Moricky
  5. Edited: Dimon UA
  6.  
  7. Description:
  8. Detects whether is position within array marker area.
  9.  
  10. Parameter(s):
  11. _this select 0: array marker
  12. _this select 1: Position
  13. _this select 2: OPTIONAL - scalar result (distance from border)
  14.  
  15. Returns:
  16. Boolean (true when position is in area, false if not).
  17. */
  18. //scopeName "main";
  19. private ["_arraymrk","_mrkarea","_posx","_posy","_tarea","_tx","_ty","_tdir","_tshape","_in"];
  20.  
  21. _arraymrk = _this select 0;
  22. _position = _this select 1;
  23.  
  24. _scalarresult = if (count _this > 2) then {_this select 2} else {false};
  25.  
  26. {
  27. _posx = getMarkerPos _x select 0;
  28. _posy = getMarkerPos _x select 1;
  29. _mrkarea = getMarkerSize _x;
  30. _tx = _mrkarea select 0;
  31. _ty = _mrkarea select 1;
  32. _tdir = markerDir _x;
  33. _tshape = markerShape _x;
  34. _in = false;
  35.  
  36. if (_tshape == "RECTANGLE") then
  37. {
  38.  
  39. //--- RECTANGLE
  40. _difx = (_position select 0) - _posx;
  41. _dify = (_position select 1) - _posy;
  42. _dir = atan (_difx / _dify);
  43. if (_dify < 0) then {_dir = _dir + 180};
  44. _relativedir = _tdir - _dir;
  45. _adis = abs (_tx / cos (90 - _relativedir));
  46. _bdis = abs (_ty / cos _relativedir);
  47. _borderdis = _adis min _bdis;
  48. _positiondis = _position distance getMarkerPos _x;
  49.  
  50. _in = if (_scalarresult) then {
  51. _positiondis - _borderdis;
  52. } else {
  53. if (_positiondis < _borderdis) then {true} else {false};
  54. };
  55. };
  56. if (_tshape == "ELLIPSE") then
  57. {
  58. //--- ELLIPSE
  59. _e = sqrt(_tx^2 - _ty^2);
  60. _posF1 = [_posx + (sin (_tdir+90) * _e),_posy + (cos (_tdir+90) * _e)];
  61. _posF2 = [_posx - (sin (_tdir+90) * _e),_posy - (cos (_tdir+90) * _e)];
  62. _total = 2 * _tx;
  63.  
  64. _dis1 = _position distance _posF1;
  65. _dis2 = _position distance _posF2;
  66. _in = if (_scalarresult) then {
  67. (_dis1+_dis2) - _total;
  68. } else {
  69. if (_dis1+_dis2 < _total) then {true} else {false;};
  70. };
  71. };
  72. if _in exitwith { true};
  73. } foreach _arraymrk;
  74. _in
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement