From 2b4d8069257fe307235f430223536a2448ce3613 Mon Sep 17 00:00:00 2001 From: esteldunedain Date: Fri, 3 Apr 2015 18:22:04 -0300 Subject: [PATCH] Reduce or eliminate backblast cause by terrain depending on relative slope. Fix #294 --- .../functions/fnc_getDistance.sqf | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/addons/overpressure/functions/fnc_getDistance.sqf b/addons/overpressure/functions/fnc_getDistance.sqf index 4fe380fbaf..905ecbd180 100644 --- a/addons/overpressure/functions/fnc_getDistance.sqf +++ b/addons/overpressure/functions/fnc_getDistance.sqf @@ -15,15 +15,18 @@ EXPLODE_3_PVT(_this,_posASL,_direction,_maxDistance); -private ["_distance", "_interval", "_line", "_intersections"]; +private ["_distance", "_interval", "_line", "_intersections", "_terrainIntersect", "_lastTerrainIntersect"]; _distance = _maxDistance; _interval = _distance; _line = [_posASL, []]; +_terrainIntersect = false; +_lastTerrainIntersect = false; while { _interval > 0.1 } do { + _lastTerrainIntersect = _terrainIntersect; _interval = _interval / 2; _line set [1, _posASL vectorAdd (_direction vectorMultiply _distance)]; @@ -32,9 +35,32 @@ while { _x isKindOf "Static" || {_x isKindOf "AllVehicles"} } count (lineIntersectsWith _line); - _distance = _distance + ([1, -1] select (_intersections > 0 || {terrainIntersectASL _line})) * _interval; + _terrainIntersect = if (_intersections > 0) then { + false + } else { + terrainIntersectASL _line + }; + + _distance = _distance + ([1, -1] select (_intersections > 0 || _terrainIntersect)) * _interval; if (_distance > _maxDistance) exitWith {_distance = 999}; }; +if (_distance > _maxDistance) exitWith {_distance}; + +// If the intersection was with the terrain, check slope +if (_terrainIntersect || _lastTerrainIntersect) exitWith { + 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)); + + //systemChat format ["Angle: %1", _angle]; + // 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 +}; + _distance