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-11-11 20:12:42 +00:00
|
|
|
* 3: Shooter <OBJECT>
|
2015-01-25 03:59:20 +00:00
|
|
|
*
|
2016-06-18 09:50:41 +00:00
|
|
|
* Return Value:
|
2015-11-11 20:12:42 +00:00
|
|
|
* Distance to intersection (999 if distance is greater than max) <NUMBER>
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* [[1823.41,5729.05,6.66627], [-0.953255,0.109689,-0.281554], 15, ace_player] call ace_overpressure_fnc_getDistance
|
|
|
|
*
|
2016-01-16 14:04:22 +00:00
|
|
|
* Public: No
|
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 20:12:42 +00:00
|
|
|
params ["_posASL", "_direction", "_maxDistance", "_shooter"];
|
2016-01-16 14:04:22 +00:00
|
|
|
TRACE_4("params",_posASL,_direction,_maxDistance, _shooter);
|
2015-01-11 16:42:31 +00:00
|
|
|
|
2015-11-20 22:13:20 +00:00
|
|
|
private _intersections = lineIntersectsSurfaces [_posASL, _posASL vectorAdd (_direction vectorMultiply _maxDistance), _shooter, objNull, true, 99];
|
2015-02-15 16:14:09 +00:00
|
|
|
|
2015-11-11 20:12:42 +00:00
|
|
|
TRACE_1("lineIntersectsSurfaces",_intersections);
|
2015-01-11 16:42:31 +00:00
|
|
|
|
2015-11-20 22:13:20 +00:00
|
|
|
private _distance = 999;
|
2015-01-11 16:42:31 +00:00
|
|
|
|
2015-11-11 20:12:42 +00:00
|
|
|
{
|
|
|
|
_x params ["_intersectPosASL", "_surfaceNormal", "_intersectObject"];
|
2016-01-16 14:04:22 +00:00
|
|
|
TRACE_3("Intersect",_intersectPosASL,_surfaceNormal,_intersectObject);
|
2016-05-03 00:32:44 +00:00
|
|
|
|
2016-01-16 14:04:22 +00:00
|
|
|
//Hit something solid that can reflect - (Static covers Building) [Need to manually filter out _shoot for FFV shots]
|
|
|
|
if ((isNull _intersectObject) || {(_intersectObject != _shooter) && {(_intersectObject isKindOf "Static") || {_intersectObject isKindOf "AllVehicles"}}}) exitWith {
|
2015-11-11 20:12:42 +00:00
|
|
|
_distance = _posASL vectorDistance _intersectPosASL;
|
|
|
|
TRACE_3("hit solid object",_distance,_intersectObject,typeOf _intersectObject);
|
2015-01-11 16:42:31 +00:00
|
|
|
|
2015-11-11 20:12:42 +00:00
|
|
|
if (isNull _intersectObject) then { //Terrain:
|
|
|
|
// Calculate the angle between the terrain and the back blast direction
|
|
|
|
_angle = 90 - acos (- (_surfaceNormal vectorDotProduct _direction));
|
|
|
|
TRACE_3("Terrain Intersect",_surfaceNormal,_direction,_angle);
|
|
|
|
// Angles is below 25deg, no backblast at all
|
|
|
|
if (_angle < 25) exitWith {_distance = 999};
|
|
|
|
// Angles is below 45deg the distance is increased according to the difference
|
|
|
|
if (_angle < 45) exitWith {_distance = _distance * (5 - 4 * sqrt ((_angle - 25)/20))};
|
|
|
|
// Angles above 45degcreate full backblast
|
|
|
|
};
|
2015-04-03 21:22:04 +00:00
|
|
|
};
|
2015-11-11 20:12:42 +00:00
|
|
|
} forEach _intersections;
|
2015-04-03 21:22:04 +00:00
|
|
|
|
2015-01-25 03:59:20 +00:00
|
|
|
_distance
|