2018-09-17 19:19:29 +00:00
|
|
|
#include "script_component.hpp"
|
2015-01-11 16:42:31 +00:00
|
|
|
/*
|
2016-01-19 23:06:06 +00:00
|
|
|
* Author: VKing
|
2015-01-11 16:42:31 +00:00
|
|
|
* Get the distance to the next object the player is looking at. Used for laser distance measurements.
|
|
|
|
*
|
2015-09-21 11:08:10 +00:00
|
|
|
* Arguments:
|
2016-01-19 23:06:06 +00:00
|
|
|
* 0: Measurement Accuracy (default: 1) <NUMBER>
|
|
|
|
* 1: Maximum measure distance (default: 5000) <NUMBER>
|
|
|
|
* 2: Minimum measure distance (default: 0) <NUMBER>
|
2015-09-21 11:08:10 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* Distance in meters <NUMBER>
|
2015-01-11 16:42:31 +00:00
|
|
|
*
|
2017-06-08 13:31:51 +00:00
|
|
|
* Example:
|
|
|
|
* [5,20000,56] call ace_common_fnc_getTargetDistance
|
|
|
|
*
|
2015-09-21 11:08:10 +00:00
|
|
|
* Public: Yes
|
2015-01-11 16:42:31 +00:00
|
|
|
*/
|
|
|
|
|
2016-01-19 23:06:06 +00:00
|
|
|
params [["_accuracy",1], ["_maxDistance",5000], ["_minDistance",0]];
|
2015-01-11 16:42:31 +00:00
|
|
|
|
2016-01-19 23:06:06 +00:00
|
|
|
private _camPosition = AGLToASL positionCameraToWorld [0, 0, 0];
|
|
|
|
private _aimLinePos = AGLToASL positionCameraToWorld [0, 0, _maxDistance];
|
2015-01-11 16:42:31 +00:00
|
|
|
|
2016-01-19 23:06:06 +00:00
|
|
|
private _LIS = lineIntersectsSurfaces [_camPosition, _aimLinePos];
|
2015-01-11 16:42:31 +00:00
|
|
|
|
2016-01-19 23:06:06 +00:00
|
|
|
private _distance = 0;
|
|
|
|
if (count _LIS > 0) then {
|
|
|
|
_distance = _camPosition vectorDistance ((_LIS select 0) select 0);
|
|
|
|
} else {
|
|
|
|
_distance = _maxDistance;
|
2015-01-11 16:42:31 +00:00
|
|
|
};
|
|
|
|
|
2016-01-21 23:01:13 +00:00
|
|
|
_distance = _distance max _minDistance;
|
2015-01-11 16:42:31 +00:00
|
|
|
|
2016-01-21 23:01:13 +00:00
|
|
|
_accuracy = _accuracy max 1;
|
2016-01-19 23:06:06 +00:00
|
|
|
_distance = (round (_distance/_accuracy)) * _accuracy;
|
2015-01-11 16:42:31 +00:00
|
|
|
|
|
|
|
_distance
|