mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
getDistance - use lineIntersectsSurfaces
This commit is contained in:
parent
391bfc160a
commit
9b2c79e7e1
@ -48,7 +48,7 @@ _affected = (ASLtoAGL _position) nearEntities ["CAManBase", _backblastRange];
|
|||||||
|
|
||||||
// Damage to the firer
|
// Damage to the firer
|
||||||
private "_distance";
|
private "_distance";
|
||||||
_distance = [_position, _direction, _backblastRange] call FUNC(getDistance);
|
_distance = [_position, _direction, _backblastRange, _firer] call FUNC(getDistance);
|
||||||
|
|
||||||
TRACE_1("Distance",_distance);
|
TRACE_1("Distance",_distance);
|
||||||
|
|
||||||
|
@ -7,62 +7,45 @@
|
|||||||
* 0: Pos ASL of origin (ARRAY>
|
* 0: Pos ASL of origin (ARRAY>
|
||||||
* 1: Direction <ARRAY>
|
* 1: Direction <ARRAY>
|
||||||
* 2: Max distance to search <Number>
|
* 2: Max distance to search <Number>
|
||||||
|
* 3: Shooter <OBJECT>
|
||||||
*
|
*
|
||||||
* Return value:
|
* Return value:
|
||||||
* Distance to intersection (+- 0.1 m) <NUMBER>
|
* 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"
|
#include "script_component.hpp"
|
||||||
|
|
||||||
params ["_posASL", "_direction", "_maxDistance"];
|
params ["_posASL", "_direction", "_maxDistance", "_shooter"];
|
||||||
TRACE_3("params",_posASL,_direction,_maxDistance);
|
TRACE_3("params",_posASL,_direction,_maxDistance);
|
||||||
|
|
||||||
private ["_distance", "_interval", "_line", "_intersections", "_terrainIntersect", "_lastTerrainIntersect"];
|
local _intersections = lineIntersectsSurfaces [_posASL, _posASL vectorAdd (_direction vectorMultiply _maxDistance), _shooter, objNull, true, 99];
|
||||||
|
|
||||||
_distance = _maxDistance;
|
TRACE_1("lineIntersectsSurfaces",_intersections);
|
||||||
_interval = _distance;
|
|
||||||
_line = [_posASL, []];
|
|
||||||
_terrainIntersect = false;
|
|
||||||
_lastTerrainIntersect = false;
|
|
||||||
|
|
||||||
while {
|
local _distance = 999;
|
||||||
_interval > 0.1
|
|
||||||
} do {
|
|
||||||
_lastTerrainIntersect = _terrainIntersect;
|
|
||||||
_interval = _interval / 2;
|
|
||||||
|
|
||||||
_line set [1, _posASL vectorAdd (_direction vectorMultiply _distance)];
|
{
|
||||||
|
_x params ["_intersectPosASL", "_surfaceNormal", "_intersectObject"];
|
||||||
|
|
||||||
_intersections = {
|
//Hit something solid that can reflect - (Static covers Building)
|
||||||
_x isKindOf "Static" || {_x isKindOf "AllVehicles"}
|
if ((isNull _intersectObject) || {(_intersectObject isKindOf "Static") || {_intersectObject isKindOf "AllVehicles"}}) exitWith {
|
||||||
} count (lineIntersectsWith _line);
|
_distance = _posASL vectorDistance _intersectPosASL;
|
||||||
|
TRACE_3("hit solid object",_distance,_intersectObject,typeOf _intersectObject);
|
||||||
|
|
||||||
_terrainIntersect = if (_intersections > 0) then {
|
if (isNull _intersectObject) then { //Terrain:
|
||||||
false
|
|
||||||
} else {
|
|
||||||
terrainIntersectASL _line
|
|
||||||
};
|
|
||||||
|
|
||||||
_distance = _distance + ([1, -1] select (_intersections > 0 || _terrainIntersect)) * _interval;
|
|
||||||
if (_distance > _maxDistance) exitWith {_distance = 999};
|
|
||||||
};
|
|
||||||
|
|
||||||
TRACE_4("while done",_distance,_maxDistance,_terrainIntersect,_lastTerrainIntersect);
|
|
||||||
|
|
||||||
if (_distance > _maxDistance) exitWith {_distance};
|
|
||||||
|
|
||||||
// If the intersection was with the terrain, check slope
|
|
||||||
if (_terrainIntersect || _lastTerrainIntersect) then {
|
|
||||||
private ["_slope","_angle"];
|
|
||||||
_slope = surfaceNormal (_posASL vectorAdd (_direction vectorMultiply _distance));
|
|
||||||
// Calculate the angle between the terrain and the back blast direction
|
// Calculate the angle between the terrain and the back blast direction
|
||||||
_angle = 90 - acos (- (_slope vectorDotProduct _direction));
|
_angle = 90 - acos (- (_surfaceNormal vectorDotProduct _direction));
|
||||||
|
TRACE_3("Terrain Intersect",_surfaceNormal,_direction,_angle);
|
||||||
TRACE_3("Terrain Intersect",_slope,_direction,_angle);
|
// Angles is below 25deg, no backblast at all
|
||||||
// Angles is below 25º, no backblast at all
|
|
||||||
if (_angle < 25) exitWith {_distance = 999};
|
if (_angle < 25) exitWith {_distance = 999};
|
||||||
// Angles is below 45º the distance is increased according to the difference
|
// Angles is below 45deg the distance is increased according to the difference
|
||||||
if (_angle < 45) exitWith {_distance = _distance * (5 - 4 * sqrt ((_angle - 25)/20))};
|
if (_angle < 45) exitWith {_distance = _distance * (5 - 4 * sqrt ((_angle - 25)/20))};
|
||||||
// Angles above 45º create full backblast
|
// Angles above 45degcreate full backblast
|
||||||
};
|
};
|
||||||
|
};
|
||||||
|
} forEach _intersections;
|
||||||
|
|
||||||
_distance
|
_distance
|
||||||
|
Loading…
Reference in New Issue
Block a user