2023-09-12 18:58:10 +00:00
|
|
|
#include "..\script_component.hpp"
|
2016-10-08 10:55:30 +00:00
|
|
|
/*
|
|
|
|
* Author: Nou, PabstMirror
|
2017-09-22 15:33:08 +00:00
|
|
|
* Shoots a ray from a source to a direction and finds first intersction and distance.
|
2016-10-08 10:55:30 +00:00
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* 0: Origin position ASL <ARRAY>
|
|
|
|
* 1: Direction (normalized) <ARRAY>
|
2017-09-22 15:33:08 +00:00
|
|
|
* 2: Ignore 1 (e.g. Player's vehicle) <OBJECT> (default: objNull)
|
|
|
|
* 2: Ignore 2 (e.g. Player's vehicle) <OBJECT> (default: objNull)
|
2016-10-08 10:55:30 +00:00
|
|
|
*
|
2017-06-08 13:31:51 +00:00
|
|
|
* Return Value:
|
|
|
|
* [posASL, distance] - pos will be nil if no intersection <ARRAY>
|
2016-10-08 10:55:30 +00:00
|
|
|
*
|
|
|
|
* Example:
|
2017-09-22 15:33:08 +00:00
|
|
|
* [getPosASL player, [0,1,0], player] call ace_laser_fnc_shootRay
|
2016-10-08 10:55:30 +00:00
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
2016-05-30 16:37:03 +00:00
|
|
|
|
2016-10-08 10:55:30 +00:00
|
|
|
BEGIN_COUNTER(shootRay);
|
|
|
|
|
|
|
|
params ["_posASL", "_dir", ["_ignoreVehicle1", objNull], ["_ignoreVehicle2", objNull]];
|
2024-02-05 17:04:24 +00:00
|
|
|
// TRACE_2("ray origin:",_posASL,_dir);
|
2016-10-08 10:55:30 +00:00
|
|
|
|
|
|
|
private _distance = 0;
|
|
|
|
private _resultPos = nil;
|
|
|
|
|
|
|
|
private _farPoint = _posASL vectorAdd (_dir vectorMultiply 10000);
|
|
|
|
private _intersects = lineIntersectsSurfaces [_posASL, _farPoint, _ignoreVehicle1, _ignoreVehicle2];
|
2017-08-03 17:50:29 +00:00
|
|
|
// workaround for lineIntersectsSurfaces using a hardcoded max distance of 5000m. New max distance 15000m
|
|
|
|
if (_intersects isEqualTo []) then {
|
|
|
|
_intersects = lineIntersectsSurfaces [_posASL vectorAdd (_dir vectorMultiply 5000), _farPoint vectorAdd (_dir vectorMultiply 5000), _ignoreVehicle1, _ignoreVehicle2];
|
|
|
|
if (_intersects isEqualTo []) then {
|
|
|
|
_intersects = lineIntersectsSurfaces [_posASL vectorAdd (_dir vectorMultiply 10000), _farPoint vectorAdd (_dir vectorMultiply 10000), _ignoreVehicle1, _ignoreVehicle2];
|
|
|
|
};
|
|
|
|
};
|
2016-10-08 10:55:30 +00:00
|
|
|
|
2021-02-27 17:05:05 +00:00
|
|
|
if (_intersects isNotEqualTo []) then {
|
2016-10-08 10:55:30 +00:00
|
|
|
(_intersects select 0) params ["_intersectPosASL", "", "_intersectObject"];
|
|
|
|
// Move back slightly to prevents issues with it going below terrain
|
|
|
|
_distance = (_posASL vectorDistance _intersectPosASL) - 0.005;
|
|
|
|
_resultPos = _posASL vectorAdd (_dir vectorMultiply _distance);
|
|
|
|
};
|
|
|
|
|
2024-02-05 17:04:24 +00:00
|
|
|
TRACE_3("",_resultPos,_distance,_intersects);
|
2016-10-08 10:55:30 +00:00
|
|
|
|
|
|
|
#ifdef DRAW_LASER_INFO
|
2020-02-11 22:43:20 +00:00
|
|
|
if (!isNil "_resultPos") then {
|
2016-10-08 10:55:30 +00:00
|
|
|
private _text = [_distance, 4, 0] call CBA_fnc_formatNumber;
|
|
|
|
drawIcon3D ["\a3\ui_f\data\IGUI\Cfg\Cursors\selectover_ca.paa", [0, 1, 0, 1], ASLtoAGL _resultPos, 0.5, 0.5, 0, _text, 0.4, 0.025, "TahomaB"];
|
|
|
|
drawLine3D [ASLtoAGL _posASL, ASLtoAGL _resultPos, [0,1,0,1]];
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
END_COUNTER(shootRay);
|
|
|
|
[_resultPos, _distance];
|