2015-01-11 16:42:31 +00:00
|
|
|
/*
|
|
|
|
* Author: commy2
|
|
|
|
* 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:
|
|
|
|
* 0: Messurement Accuracy <NUMBER>
|
|
|
|
* 1: Maximal messure distance <NUMBER>
|
|
|
|
* 2: Minimal messure distance (default: nil) <NUMBER>
|
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* Distance in meters <NUMBER>
|
2015-01-11 16:42:31 +00:00
|
|
|
*
|
2015-09-21 11:08:10 +00:00
|
|
|
* Public: Yes
|
2015-01-11 16:42:31 +00:00
|
|
|
*/
|
2015-01-13 19:56:02 +00:00
|
|
|
#include "script_component.hpp"
|
2015-01-11 16:42:31 +00:00
|
|
|
|
2015-09-21 11:08:10 +00:00
|
|
|
params ["_interval", "_maxDistance", "_minDistance"];
|
2015-01-11 16:42:31 +00:00
|
|
|
|
2015-09-21 11:08:10 +00:00
|
|
|
private ["_position", "_laser", "_line", "_distance", "_iteration"];
|
2015-01-11 16:42:31 +00:00
|
|
|
|
|
|
|
_position = ATLToASL positionCameraToWorld [0, 0, 0];
|
|
|
|
_position set [2, (_position select 2) - (getTerrainHeightASL _position min 0)];
|
|
|
|
|
|
|
|
_laser = + _position;
|
|
|
|
_line = [_position, _laser];
|
|
|
|
|
|
|
|
_distance = _maxDistance;
|
|
|
|
_iteration = _distance;
|
|
|
|
|
|
|
|
while {
|
2015-05-14 18:06:06 +00:00
|
|
|
_iteration > _interval / 2
|
2015-01-11 16:42:31 +00:00
|
|
|
} do {
|
2015-05-14 18:06:06 +00:00
|
|
|
_iteration = _iteration / 2;
|
2015-01-11 16:42:31 +00:00
|
|
|
|
2015-05-14 18:06:06 +00:00
|
|
|
_laser = ATLToASL positionCameraToWorld [0, 0, _distance];
|
|
|
|
_laser set [2, (_laser select 2) - (getTerrainHeightASL _laser min 0)];
|
|
|
|
_line set [1, _laser];
|
2015-01-11 16:42:31 +00:00
|
|
|
|
2015-05-14 18:06:06 +00:00
|
|
|
_distance = _distance + (([1, -1] select (lineIntersects (_line + [vehicle ACE_player]) || {terrainIntersectASL _line})) * _iteration);
|
2015-01-11 16:42:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
_distance = _interval * round (_distance / _interval);
|
|
|
|
|
|
|
|
_distance = _distance min _maxDistance;
|
|
|
|
|
2015-09-21 11:08:10 +00:00
|
|
|
if (!isNil "_minDistance") then {_distance = _distance max _minDistance};
|
2015-01-11 16:42:31 +00:00
|
|
|
|
|
|
|
_distance
|