mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
52 lines
1.9 KiB
Plaintext
52 lines
1.9 KiB
Plaintext
/*
|
|
* Author: commy2 and esteldunedain
|
|
*
|
|
* Calculate the distance to the first intersection of a line
|
|
*
|
|
* Arguments:
|
|
* 0: Pos ASL of origin (ARRAY>
|
|
* 1: Direction <ARRAY>
|
|
* 2: Max distance to search <Number>
|
|
* 3: Shooter <OBJECT>
|
|
*
|
|
* Return value:
|
|
* 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
|
|
*
|
|
*/
|
|
#include "script_component.hpp"
|
|
|
|
params ["_posASL", "_direction", "_maxDistance", "_shooter"];
|
|
TRACE_3("params",_posASL,_direction,_maxDistance);
|
|
|
|
private _intersections = lineIntersectsSurfaces [_posASL, _posASL vectorAdd (_direction vectorMultiply _maxDistance), _shooter, objNull, true, 99];
|
|
|
|
TRACE_1("lineIntersectsSurfaces",_intersections);
|
|
|
|
private _distance = 999;
|
|
|
|
{
|
|
_x params ["_intersectPosASL", "_surfaceNormal", "_intersectObject"];
|
|
|
|
//Hit something solid that can reflect - (Static covers Building)
|
|
if ((isNull _intersectObject) || {(_intersectObject isKindOf "Static") || {_intersectObject isKindOf "AllVehicles"}}) exitWith {
|
|
_distance = _posASL vectorDistance _intersectPosASL;
|
|
TRACE_3("hit solid object",_distance,_intersectObject,typeOf _intersectObject);
|
|
|
|
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
|
|
};
|
|
};
|
|
} forEach _intersections;
|
|
|
|
_distance
|