2023-09-12 18:58:10 +00:00
|
|
|
#include "..\script_component.hpp"
|
2015-09-21 11:08:10 +00:00
|
|
|
/*
|
|
|
|
* Author: Ruthberg
|
|
|
|
* Returns the the first intersection with an object between two positions. @todo rewrite using lineIntersectsSurfaces?
|
2015-01-16 23:21:47 +00:00
|
|
|
*
|
2015-09-21 11:08:10 +00:00
|
|
|
* Arguments:
|
|
|
|
* 0: PositionASL <ARRAY>
|
|
|
|
* 1: PositionATL <ARRAY>
|
|
|
|
* 2: Accuracy <NUMBER>
|
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* 0: Intersects <BOOL>
|
|
|
|
* 1: Intersection Position ASL <ARRAY>
|
|
|
|
*
|
2017-06-08 13:31:51 +00:00
|
|
|
* Example:
|
|
|
|
* [[1,2,3], [0,0,5], 5] call ace_common_fnc_getFirstTerrainIntersection
|
|
|
|
*
|
2015-09-21 11:08:10 +00:00
|
|
|
* Public: Yes
|
2015-01-16 23:21:47 +00:00
|
|
|
*/
|
|
|
|
|
2015-09-21 11:08:10 +00:00
|
|
|
params ["_source", "_destination", "_accuracy"];
|
2015-05-14 18:06:06 +00:00
|
|
|
|
2015-12-12 15:48:54 +00:00
|
|
|
private _result = [false, [0, 0, 0]];
|
2015-01-16 23:21:47 +00:00
|
|
|
|
2015-12-12 15:48:54 +00:00
|
|
|
private _distance = _source vectorDistance _destination;
|
2015-01-16 23:21:47 +00:00
|
|
|
|
|
|
|
if (terrainIntersectASL [_source, _destination]) then {
|
2015-12-12 15:48:54 +00:00
|
|
|
private _lower = 0;
|
|
|
|
private _upper = 1;
|
|
|
|
private _mid = 0.5;
|
2015-01-16 23:21:47 +00:00
|
|
|
|
2015-12-12 15:48:54 +00:00
|
|
|
private _dir = _source vectorFromTo _destination;
|
2015-01-16 23:21:47 +00:00
|
|
|
|
2015-01-18 19:09:19 +00:00
|
|
|
while {(_upper - _lower) * _distance > _accuracy} do {
|
|
|
|
_mid = _lower + (_upper - _lower) / 2;
|
2015-01-16 23:21:47 +00:00
|
|
|
|
2015-09-21 11:08:10 +00:00
|
|
|
if (terrainIntersectASL [_source, _source vectorAdd (_dir vectorMultiply (_mid * _distance))]) then {
|
2015-01-18 19:09:19 +00:00
|
|
|
_upper = _mid;
|
|
|
|
} else {
|
|
|
|
_lower = _mid;
|
|
|
|
};
|
|
|
|
};
|
2015-01-16 23:21:47 +00:00
|
|
|
|
2015-01-18 19:09:19 +00:00
|
|
|
_mid = _lower + (_upper - _lower) / 2;
|
|
|
|
_result = [true, _source vectorAdd (_dir vectorMultiply (_mid * _distance))];
|
2015-01-16 23:21:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
_result
|