2015-01-25 03:59:20 +00:00
|
|
|
/*
|
2015-03-24 04:18:00 +00:00
|
|
|
* Author: commy2 and esteldunedain
|
2015-01-25 03:59:20 +00:00
|
|
|
*
|
|
|
|
* Calculate the distance to the first intersection of a line
|
|
|
|
*
|
2015-08-30 05:35:58 +00:00
|
|
|
* Arguments:
|
|
|
|
* 0: Pos ASL of origin (ARRAY>
|
|
|
|
* 1: Direction <ARRAY>
|
|
|
|
* 2: Max distance to search <Number>
|
2015-01-25 03:59:20 +00:00
|
|
|
*
|
|
|
|
* Return value:
|
2015-08-30 05:35:58 +00:00
|
|
|
* Distance to intersection (+- 0.1 m) <NUMBER>
|
2015-01-25 03:59:20 +00:00
|
|
|
*/
|
2015-01-14 04:15:58 +00:00
|
|
|
#include "script_component.hpp"
|
2015-01-11 16:42:31 +00:00
|
|
|
|
2015-11-11 19:24:27 +00:00
|
|
|
params ["_posASL", "_direction", "_maxDistance"];
|
|
|
|
TRACE_3("params",_posASL,_direction,_maxDistance);
|
2015-01-11 16:42:31 +00:00
|
|
|
|
2015-04-03 21:22:04 +00:00
|
|
|
private ["_distance", "_interval", "_line", "_intersections", "_terrainIntersect", "_lastTerrainIntersect"];
|
2015-02-15 16:14:09 +00:00
|
|
|
|
2015-01-11 16:42:31 +00:00
|
|
|
_distance = _maxDistance;
|
2015-01-25 03:59:20 +00:00
|
|
|
_interval = _distance;
|
|
|
|
_line = [_posASL, []];
|
2015-04-03 21:22:04 +00:00
|
|
|
_terrainIntersect = false;
|
|
|
|
_lastTerrainIntersect = false;
|
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-04-03 21:22:04 +00:00
|
|
|
_lastTerrainIntersect = _terrainIntersect;
|
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-04-03 21:22:04 +00:00
|
|
|
_terrainIntersect = if (_intersections > 0) then {
|
|
|
|
false
|
|
|
|
} else {
|
|
|
|
terrainIntersectASL _line
|
|
|
|
};
|
|
|
|
|
|
|
|
_distance = _distance + ([1, -1] select (_intersections > 0 || _terrainIntersect)) * _interval;
|
2015-01-25 03:59:20 +00:00
|
|
|
if (_distance > _maxDistance) exitWith {_distance = 999};
|
2015-01-11 16:42:31 +00:00
|
|
|
};
|
|
|
|
|
2015-11-11 19:24:27 +00:00
|
|
|
TRACE_4("while done",_distance,_maxDistance,_terrainIntersect,_lastTerrainIntersect);
|
|
|
|
|
2015-04-03 21:22:04 +00:00
|
|
|
if (_distance > _maxDistance) exitWith {_distance};
|
|
|
|
|
|
|
|
// If the intersection was with the terrain, check slope
|
2015-11-11 19:24:27 +00:00
|
|
|
if (_terrainIntersect || _lastTerrainIntersect) then {
|
2015-04-03 21:22:04 +00:00
|
|
|
private ["_slope","_angle"];
|
|
|
|
_slope = surfaceNormal (_posASL vectorAdd (_direction vectorMultiply _distance));
|
|
|
|
// Calculate the angle between the terrain and the back blast direction
|
|
|
|
_angle = 90 - acos (- (_slope vectorDotProduct _direction));
|
|
|
|
|
2015-11-11 19:24:27 +00:00
|
|
|
TRACE_3("Terrain Intersect",_slope,_direction,_angle);
|
2015-04-03 21:22:04 +00:00
|
|
|
// Angles is below 25º, no backblast at all
|
|
|
|
if (_angle < 25) exitWith {_distance = 999};
|
|
|
|
// Angles is below 45º the distance is increased according to the difference
|
|
|
|
if (_angle < 45) exitWith {_distance = _distance * (5 - 4 * sqrt ((_angle - 25)/20))};
|
|
|
|
// Angles above 45º create full backblast
|
|
|
|
};
|
|
|
|
|
2015-01-25 03:59:20 +00:00
|
|
|
_distance
|