2015-01-25 03:59:20 +00:00
|
|
|
/*
|
2015-02-15 16:14:09 +00:00
|
|
|
* Author: commy2 and CAA-Picard
|
2015-01-25 03:59:20 +00:00
|
|
|
*
|
|
|
|
* Calculate the distance to the first intersection of a line
|
|
|
|
*
|
|
|
|
* Argument:
|
|
|
|
* 0: Pos ASL of origin (Array)
|
|
|
|
* 1: Direction (Array)
|
|
|
|
* 2: Max distance to search (Number)
|
|
|
|
*
|
|
|
|
* Return value:
|
|
|
|
* Distance to intersection (+- 0.1 m)
|
|
|
|
*/
|
2015-01-14 04:15:58 +00:00
|
|
|
#include "script_component.hpp"
|
2015-01-11 16:42:31 +00:00
|
|
|
|
2015-01-25 03:59:20 +00:00
|
|
|
EXPLODE_3_PVT(_this,_posASL,_direction,_maxDistance);
|
2015-01-11 16:42:31 +00:00
|
|
|
|
2015-02-15 16:14:09 +00:00
|
|
|
private ["_distance", "_interval", "_line", "_intersections"];
|
|
|
|
|
2015-01-11 16:42:31 +00:00
|
|
|
_distance = _maxDistance;
|
2015-01-25 03:59:20 +00:00
|
|
|
_interval = _distance;
|
|
|
|
_line = [_posASL, []];
|
2015-01-11 16:42:31 +00:00
|
|
|
|
|
|
|
while {
|
2015-01-25 03:59:20 +00:00
|
|
|
_interval > 0.1
|
2015-01-11 16:42:31 +00:00
|
|
|
} do {
|
2015-01-25 03:59:20 +00:00
|
|
|
_interval = _interval / 2;
|
2015-01-11 16:42:31 +00:00
|
|
|
|
2015-01-25 03:59:20 +00:00
|
|
|
_line set [1, _posASL vectorAdd (_direction vectorMultiply _distance)];
|
2015-01-11 16:42:31 +00:00
|
|
|
|
2015-01-25 03:59:20 +00:00
|
|
|
_intersections = {
|
|
|
|
_x isKindOf "Static" || {_x isKindOf "AllVehicles"}
|
|
|
|
} count (lineIntersectsWith _line);
|
2015-01-11 16:42:31 +00:00
|
|
|
|
2015-01-25 03:59:20 +00:00
|
|
|
_distance = _distance + ([1, -1] select (_intersections > 0 || {terrainIntersectASL _line})) * _interval;
|
|
|
|
|
|
|
|
if (_distance > _maxDistance) exitWith {_distance = 999};
|
2015-01-11 16:42:31 +00:00
|
|
|
};
|
|
|
|
|
2015-01-25 03:59:20 +00:00
|
|
|
_distance
|