2015-01-16 23:21:47 +00:00
|
|
|
/**
|
|
|
|
* fn_getFirstIntersection.sqf
|
|
|
|
* @Descr: Returns the the first intersection with an object between two positions
|
|
|
|
* @Author: Ruthberg
|
|
|
|
*
|
|
|
|
* @Arguments: [position PositionASL, position PositionASL, accuracy FLOAT]
|
|
|
|
* @Return: [intersects BOOL, intersection PositionASL]
|
|
|
|
* @PublicAPI: true
|
|
|
|
*/
|
|
|
|
#include "script_component.hpp"
|
|
|
|
|
|
|
|
private ["_source", "_destination", "_accuracy", "_distance", "_lower", "_upper", "_mid", "_intersections", "_result"];
|
|
|
|
_source = _this select 0;
|
|
|
|
_destination = _this select 1;
|
|
|
|
_accuracy = _this select 2;
|
|
|
|
|
|
|
|
_result = [false, [0, 0, 0]];
|
|
|
|
|
|
|
|
_distance = _source vectorDistance _destination;
|
|
|
|
|
|
|
|
if (count (lineIntersectsWith [_source, _destination]) > 0) then {
|
2015-01-18 19:09:19 +00:00
|
|
|
_lower = 0;
|
|
|
|
_upper = 1;
|
|
|
|
_mid = 0.5;
|
2015-01-16 23:21:47 +00:00
|
|
|
|
2015-01-18 19:09:19 +00:00
|
|
|
_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-01-18 19:09:19 +00:00
|
|
|
_intersections = count (lineIntersectsWith [_source, _source vectorAdd (_dir vectorMultiply (_mid * _distance))]);
|
2015-01-16 23:21:47 +00:00
|
|
|
|
2015-01-18 19:09:19 +00:00
|
|
|
if (_intersections > 0) then {
|
|
|
|
_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
|