Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- [_v, _player_size, _building, _size] call DO_POLYGONS_INTERSECT"
- 0 - player
- 1 - player size
- 0 - player w
- 1 - player h
- 2 - player offset x
- 3 - player offset y
- 2 - building
- 3 - building size
- 0 - building w
- 1 - building h
- 2 - building offset x
- 3 - building offset y
- */
- private ["_pos1", "_d1", "_sind1", "_cosd1", "_x1", "_y1", "_w1", "_h1", "_pos2", "_d2", "_sind2", "_cosd2", "_x2", "_y2", "_w2", "_h2","_polygons", "_count", "_i", "_terminate", "_polygon", "_i1", "_count2", "_i2", "_p1", "_p2", "_normal", "_minA", "_maxA", "_j", "_count3", "_projected", "_minB", "_maxB"];
- _pos1 = getPos (_this select 0);
- _d1 = getDir (_this select 0);
- _sind1 = sin _d1;
- _cosd1 = cos _d1;
- _x1 = (_pos1 select 0) + ((_this select 1) select 3)*_sind1 + ((_this select 1) select 2)*_cosd1;
- _y1 = (_pos1 select 1) + ((_this select 1) select 3)*_cosd1 - ((_this select 1) select 2)*_sind1;
- _w1 = (_this select 1) select 0;
- _h1 = (_this select 1) select 1;
- _pos2 = getPos (_this select 2);
- _d2 = getDir (_this select 2);
- _sind2 = sin _d2;
- _cosd2 = cos _d2;
- _x2 = (_pos2 select 0) + ((_this select 3) select 3)*_sind2 + ((_this select 3) select 2)*_cosd2;
- _y2 = (_pos2 select 1) + ((_this select 3) select 3)*_cosd2 - ((_this select 3) select 2)*_sind2;
- _w2 = (_this select 3) select 0;
- _h2 = (_this select 3) select 1;
- _polygons =
- [
- [
- [_x1 + -_h1*_sind1 + -_w1*_cosd1, _y1 + -_h1*_cosd1 - -_w1*_sind1],
- [_x1 + -_h1*_sind1 + _w1*_cosd1, _y1 + -_h1*_cosd1 - _w1*_sind1],
- [_x1 + _h1*_sind1 + _w1*_cosd1, _y1 + _h1*_cosd1 - _w1*_sind1],
- [_x1 + _h1*_sind1 + -_w1*_cosd1, _y1 + _h1*_cosd1 - -_w1*_sind1]
- ]
- ,
- [
- [_x2 + -_h2*_sind2 + -_w2*_cosd2, _y2 + -_h2*_cosd2 - -_w2*_sind2],
- [_x2 + -_h2*_sind2 + _w2*_cosd2, _y2 + -_h2*_cosd2 - _w2*_sind2],
- [_x2 + _h2*_sind2 + _w2*_cosd2, _y2 + _h2*_cosd2 - _w2*_sind2],
- [_x2 + _h2*_sind2 + -_w2*_cosd2, _y2 + _h2*_cosd2 - -_w2*_sind2]
- ]
- ];
- //https://stackoverflow.com/questions/10962379/how-to-check-intersection-between-2-rotated-rectangles
- //private ["_polygons", "_count", "_i", "_terminate", "_polygon", "_i1", "_count2", "_i2", "_p1", "_p2", "_normal", "_minA", "_maxA", "_j", "_count3", "_projected", "_minB", "_maxB"];
- _i = -1;
- _count = count _polygons;
- _terminate = false;
- while "_i=_i+1; _i < _count && !_terminate" do
- {
- _polygon = _polygons select _i;
- _i1 = -1;
- _count2 = count _polygon;
- while "_i1=_i1+1; _i1 < _count2 && !_terminate" do
- {
- _i2 = (_i1 + 1) % _count2;
- _p1 = _polygon select _i1;
- _p2 = _polygon select _i2;
- _normal = [(_p2 select 1) - (_p1 select 1), (_p1 select 0) - (_p2 select 0)];
- _minA = nil;
- _maxA = nil;
- _j = -1;
- _count3 = count (_polygons select 0);
- while "_j=_j+1; _j < _count3" do
- {
- _projected = (_normal select 0) * (((_polygons select 0) select _j) select 0) + (_normal select 1) * (((_polygons select 0) select _j) select 1);
- if (Format ["%1",_minA]=="scalar bool array string 0xfcffffef") then {
- _minA = _projected
- } else {
- if (_projected < _minA) then {_minA = _projected}
- };
- if (Format ["%1",_maxA]=="scalar bool array string 0xfcffffef") then {
- _maxA = _projected
- } else {
- if (_projected > _maxA) then {_maxA = _projected}
- }
- };
- _j = -1;
- _minB = nil;
- _maxB = nil;
- _count3 = count (_polygons select 1);
- while "_j=_j+1; _j < _count3" do
- {
- _projected = (_normal select 0) * (((_polygons select 1) select _j) select 0) + (_normal select 1) * (((_polygons select 1) select _j) select 1);
- if (Format ["%1",_minB]=="scalar bool array string 0xfcffffef") then {
- _minB = _projected
- } else {
- if (_projected < _minB) then {_minB = _projected}
- };
- if (Format ["%1",_maxB]=="scalar bool array string 0xfcffffef") then {
- _maxB = _projected
- } else {
- if (_projected > _maxB) then {_maxB = _projected}
- }
- };
- if (_maxA < _minB || _maxB < _minA) then {_terminate=true}
- }
- };
- if (_terminate) then {false} else {true}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement