Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- File: ffa_func_line_algorithm.sqf
- Author: Wikipedia
- Used Bresenham's line algorithm.
- Edit: Dimon UA
- Description:
- Creating line
- Parameter(s):
- _this select 0: position (Array)
- _this select 1: position (Array)
- Returns:
- Array - format Position2D
- */
- ffa_func_line_algorithm = {
- line_algorithm = {
- private ["_pos", "_this", "_end", "_angle", "_xstart", "_ystart", "_xend", "_yend", "_dx", "_dy", "_ind", "_incx",
- "_incy", "_pdx", "_pdy", "_es", "_el", "_x", "_y", "_err", "_arr"];
- _pos = (_this select 0) select 0;
- _end = (_this select 0) select 1;
- _step = _this select 1;
- _ind = 0;
- _angle =[_pos, _end] call BIS_fnc_dirTo;
- _xstart = _pos select 0;
- _ystart = _pos select 1;
- _xend = _end select 0;
- _yend = _end select 1;
- _dx = _xend - _xstart;//проекция на ось икс
- _dy = _yend - _ystart;//проекция на ось игрек
- if (_dx < 0) then {
- _incx =-1;
- }else{
- _incx =1;
- };
- /*
- * Определяем, в какую сторону нужно будет сдвигаться. Если dx < 0, т.е. отрезок идёт
- * справа налево по иксу, то incx будет равен -1.
- * Это будет использоваться в цикле постороения.
- */
- if (_dy < 0) then {
- _incy =-1;
- }else{
- _incy =1;
- };
- /*
- * Аналогично. Если рисуем отрезок снизу вверх -
- * это будет отрицательный сдвиг для y (иначе - положительный).
- */
- _dx = abs _dx;
- _dy = abs _dy;
- if (_dx > _dy) then
- //определяем наклон отрезка:
- {
- /*
- * Если dx > dy, то значит отрезок "вытянут" вдоль оси икс, т.е. он скорее длинный, чем высокий.
- * Значит в цикле нужно будет идти по икс (строчка el = dx;), значит "протягивать" прямую по иксу
- * надо в соответствии с тем, слева направо и справа налево она идёт (pdx = incx;), при этом
- * по y сдвиг такой отсутствует.
- */
- _pdx = _incx; _pdy = 0;
- _es = _dy; _el = _dx;
- }
- else//случай, когда прямая скорее "высокая", чем длинная, т.е. вытянута по оси y
- {
- _pdx = 0; _pdy = _incy;
- _es = _dx; _el = _dy;//тогда в цикле будем двигаться по y
- };
- _x = _xstart;
- _y = _ystart;
- _err = _el/2;
- _arr=[];
- for "_i" from 0 to (_el-1) do
- {
- _err =_err - _es;
- if (_err < 0) then
- {
- _err =_err + _el;
- _x=_x + _incx;//сдвинуть прямую (сместить вверх или вниз, если цикл проходит по иксам)
- _y=_y + _incy;//или сместить влево-вправо, если цикл проходит по y
- }
- else
- {
- _x =_x + _pdx;//продолжить тянуть прямую дальше, т.е. сдвинуть влево или вправо, если
- _y =_y + _pdy;//цикл идёт по иксу; сдвинуть вверх или вниз, если по y
- };
- _ind =_ind +1;
- if (_ind == _step) then {
- _arr set [count _arr,[_x,_y,_angle]]; _ind = 0;};
- };
- _arr
- };
- private ["_arr1"];
- _arr1 = [];
- {
- if (_forEachIndex != (count (_this select 0) - 1)) then {
- _arr1 set [count _arr1,([[_x, (_this select 0) select (_forEachIndex +1)],(_this select 1)] call line_algorithm)];
- };
- } foreach (_this select 0);
- _arr1
- };
- private ["_pos", "_step", "_dir", "_name", "_color", "_icon", "_type", "_local", "_array", "_index", "_m", "_x"];
- _pos = _this select 0;
- _step = _this select 1;
- if (!isnil {_this select 2}) then {_dir =_this select 2;}else{_dir =0;};
- if (!isnil {_this select 3}) then {_name =_this select 3;}else{_name ="markername";};
- if (!isnil {_this select 4}) then {_color =_this select 4;}else{_color ="Colorblue";};
- if (!isnil {_this select 5}) then {_icon =_this select 5;}else{_icon ="ICON";};
- if (!isnil {_this select 6}) then {_type =_this select 6;}else{_type ="group_11";};
- if (!isnil {_this select 7}) then {_local =_this select 7;}else{_local =false;};
- _array = [_pos,_step] call ffa_func_line_algorithm;
- if (!isnil "_local" && {_local}) then {
- {
- _index = str _forEachIndex;
- {
- _m = createMarkerlocal[_name +_index+ (str _forEachIndex), [ _x select 0,_x select 1]];
- _m setMarkerShapelocal _icon;
- _m setMarkerTypelocal _type;
- _m setMarkerDirlocal ((_x select 2) +_dir);
- _m setmarkercolorlocal _color;
- } foreach _x;
- } foreach _array;
- }else{
- {
- _index = str _forEachIndex;
- {
- _m = createMarker[_name +_index+ (str _forEachIndex), [ _x select 0,_x select 1]];
- _m setMarkerShape _icon;
- _m setMarkerType _type;
- _m setMarkerDir ((_x select 2) +_dir);
- _m setmarkercolor _color;
- } foreach _x;
- } foreach _array;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement