2018-09-17 19:19:29 +00:00
|
|
|
#include "script_component.hpp"
|
2016-10-08 10:55:30 +00:00
|
|
|
/*
|
|
|
|
* Author: Nou
|
2017-09-22 15:33:08 +00:00
|
|
|
* Shoots multiple rays in a dispersion pattern.
|
2016-10-08 10:55:30 +00:00
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* 0: Origin position ASL <ARRAY>
|
|
|
|
* 1: Direction (normalized) <ARRAY>
|
2017-09-22 15:33:08 +00:00
|
|
|
* 2: Divergence (mils) <NUMBER> (default: 0.3)
|
|
|
|
* 3: Count at each divergence level <NUMBER> (default: 3)
|
|
|
|
* 4: Ignore vehicle 1 (e.g. Player's vehicle) <OBJECT> (default: objNull)
|
2016-10-08 10:55:30 +00:00
|
|
|
*
|
2017-06-08 13:31:51 +00:00
|
|
|
* Return Value:
|
|
|
|
* [_longestReturn, _shortestReturn, _resultPositions] <ARRAY>
|
2016-10-08 10:55:30 +00:00
|
|
|
*
|
|
|
|
* Example:
|
2017-09-22 15:33:08 +00:00
|
|
|
* [getPosASL player, [0,1,0]] call ace_laser_fnc_shootCone
|
2016-10-08 10:55:30 +00:00
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
2016-05-30 16:37:03 +00:00
|
|
|
|
2016-10-08 10:55:30 +00:00
|
|
|
BEGIN_COUNTER(shootCone);
|
2016-05-30 16:37:03 +00:00
|
|
|
|
2016-10-08 10:55:30 +00:00
|
|
|
params ["_pos", "_vec", ["_divergence", 0.3], ["_count", 3], ["_ignoreObj1", objNull]];
|
|
|
|
|
|
|
|
private _longestReturn = -1000000000;
|
|
|
|
private _shortestReturn = 1000000000;
|
|
|
|
private _resultPositions = [];
|
|
|
|
private _p1 = [0,0,0];
|
|
|
|
private _p2 = +_vec;
|
|
|
|
private _p = (_vec call CBA_fnc_vect2polar);
|
|
|
|
private _v = [(_p select 0), (_p select 1), (_p select 2)+90] call CBA_fnc_polar2vect;
|
|
|
|
private _cp = _vec vectorCrossProduct _v;
|
|
|
|
|
|
|
|
private _vecRotateMap = [_cp, _p1, _p2] call FUNC(rotateVectLineGetMap);
|
|
|
|
|
|
|
|
// Check first with a perfect ray to the center
|
|
|
|
private _result = [_pos, _vec, _ignoreObj1] call FUNC(shootRay);
|
|
|
|
private _resultPos = _result select 0;
|
|
|
|
|
|
|
|
if (!isNil "_resultPos") then {
|
|
|
|
private _distance = _result select 1;
|
|
|
|
if (_distance < _shortestReturn) then { _shortestReturn = _distance; };
|
|
|
|
if (_distance > _longestReturn) then { _longestReturn = _distance; };
|
2016-05-30 16:37:03 +00:00
|
|
|
_resultPositions pushBack _result;
|
|
|
|
};
|
|
|
|
|
2016-10-08 10:55:30 +00:00
|
|
|
private _pos2 = _pos vectorAdd (_vec vectorMultiply 1000);
|
|
|
|
// Try at 3 radius (full, half, quarter of specified divergence)
|
2016-05-30 16:37:03 +00:00
|
|
|
{
|
2016-10-08 10:55:30 +00:00
|
|
|
private _radOffset = random 360;
|
|
|
|
for "_i" from 1 to ceil(_count*_x) do { // Will always do at least 1
|
|
|
|
private _offset = [_vecRotateMap, (((360/_count)*_i)+_radOffset) mod 360] call FUNC(rotateVectLine);
|
|
|
|
private _offsetPos = _pos2 vectorAdd (_offset vectorMultiply (_divergence*_x));
|
2017-06-08 13:31:51 +00:00
|
|
|
|
2016-10-08 10:55:30 +00:00
|
|
|
private _offsetVector = _pos vectorFromTo _offsetPos;
|
|
|
|
_result = [_pos, _offsetVector, _ignoreObj1] call FUNC(shootRay);
|
2016-05-30 16:37:03 +00:00
|
|
|
_resultPos = _result select 0;
|
2016-10-08 10:55:30 +00:00
|
|
|
if (!isNil "_resultPos") then {
|
|
|
|
private _distance = _result select 1;
|
|
|
|
if (_distance < _shortestReturn) then { _shortestReturn = _distance; };
|
|
|
|
if (_distance > _longestReturn) then { _longestReturn = _distance; };
|
2016-05-30 16:37:03 +00:00
|
|
|
_resultPositions pushBack _result;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
} forEach [1,0.5,0.25];
|
2016-10-08 10:55:30 +00:00
|
|
|
|
|
|
|
END_COUNTER(shootCone);
|
|
|
|
|
|
|
|
[_longestReturn, _shortestReturn, _resultPositions];
|