2023-09-12 18:58:10 +00:00
|
|
|
#include "..\script_component.hpp"
|
2016-11-15 18:15:25 +00:00
|
|
|
/*
|
|
|
|
* Author: PabstMirror
|
|
|
|
* Find a target within the optic range
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* 0: Last Target (seeds the scan) <OBJECT>
|
2017-06-08 13:31:51 +00:00
|
|
|
* 1: Max Range (meters) <NUMBER>
|
2016-11-15 18:15:25 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* Target <OBJECT>
|
|
|
|
*
|
|
|
|
* Example:
|
2017-06-08 13:31:51 +00:00
|
|
|
* [bob, 5] call ace_javelin_fnc_getTarget
|
2016-11-15 18:15:25 +00:00
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
|
|
|
|
|
|
|
params ["_lastTarget", "_maxRange"];
|
|
|
|
|
|
|
|
scopeName "main";
|
|
|
|
|
|
|
|
private _viewASL = AGLtoASL positionCameraToWorld [0,0,0];
|
|
|
|
private _viewDir = _viewASL vectorFromTo (AGLtoASL positionCameraToWorld [0,0,1]);
|
|
|
|
|
|
|
|
// Attempt to lock onto current target if it is still valid
|
|
|
|
if (!isNull _lastTarget) then {
|
|
|
|
private _aimASL = aimPos _lastTarget;
|
2017-06-08 13:31:51 +00:00
|
|
|
|
2016-11-15 18:15:25 +00:00
|
|
|
if ((_viewASL vectorDistance _aimASL) > _maxRange) exitWith {};
|
2017-06-08 13:31:51 +00:00
|
|
|
if ((acos ((_viewASL vectorFromTo _aimASL) vectorDotProduct _viewDir)) > 0.6) exitWith {};
|
|
|
|
|
2016-11-15 18:15:25 +00:00
|
|
|
private _relAngle = (_lastTarget getRelDir _viewASL);
|
2017-06-08 13:31:51 +00:00
|
|
|
|
2016-11-15 18:15:25 +00:00
|
|
|
for "_xOffset" from -2.5 to 2.5 step 0.5 do {
|
|
|
|
for "_yOffset" from -2 to 1 step 0.5 do {
|
|
|
|
// Find test points in the model based on the angle that we are viewing it from (not true 3d projection, but not bad)
|
2021-10-10 13:37:05 +00:00
|
|
|
private _testPosASL = _lastTarget modelToWorldWorld [_xOffset * - cos _relAngle, _xOffset * sin _relAngle, _yOffset];
|
2016-11-15 18:15:25 +00:00
|
|
|
private _intersectionsToCursorTarget = lineIntersectsSurfaces [_viewASL, _testPosASL, ace_player, vehicle ace_player, true, 1];
|
|
|
|
// drawIcon3D ["\A3\ui_f\data\map\markers\military\dot_CA.paa", [[0,1,1,1], [1,0,1,1]] select (count _intersectionsToCursorTarget), (ASLtoAGL _testPosASL), 0.25, 0.25, 0, "", 0.5, 0.025, "TahomaB"];
|
2021-02-27 17:05:05 +00:00
|
|
|
if (_intersectionsToCursorTarget isNotEqualTo []) then {
|
2016-11-15 18:15:25 +00:00
|
|
|
(_intersectionsToCursorTarget select 0) params ["", "", "_intersectedObject"];
|
|
|
|
if (_intersectedObject isKindOf "AllVehicles") then {
|
|
|
|
_intersectedObject breakOut "main";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
// Try cursorObject/Target as they are very fast
|
|
|
|
if ((cursorObject isKindOf "AllVehicles") && {(cursorObject distance ace_player) < _maxRange}) then {
|
|
|
|
private _intersectionsToCursorTarget = lineIntersectsSurfaces [_viewASL, aimPos cursorObject, ace_player, cursorObject, true, 1];
|
|
|
|
if (_intersectionsToCursorTarget isEqualTo []) then {
|
|
|
|
cursorObject breakOut "main";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
if ((cursorTarget isKindOf "AllVehicles") && {(cursorObject distance ace_player) < _maxRange}) then {
|
|
|
|
private _intersectionsToCursorTarget = lineIntersectsSurfaces [_viewASL, aimPos cursorTarget, ace_player, cursorTarget, true, 1];
|
|
|
|
if (_intersectionsToCursorTarget isEqualTo []) then {
|
|
|
|
cursorTarget breakOut "main";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
// Attempt to scan using multiple rayscasts - This is expensive (n^2) and care should be given to balance accuracy vs speed
|
|
|
|
for "_xOffset" from -14 to 14 step 2 do {
|
|
|
|
for "_yOffset" from -12 to 12 step 4 do {
|
|
|
|
private _testPosASL = AGLtoASL (positionCameraToWorld [_xOffset, _yOffset, _maxRange]);
|
|
|
|
private _intersectionsToCursorTarget = lineIntersectsSurfaces [_viewASL, _testPosASL, ace_player, vehicle ace_player, true, 1];
|
|
|
|
// drawIcon3D ["\A3\ui_f\data\map\markers\military\dot_CA.paa", [[0,1,0,1], [1,0,0,1]] select (count _intersectionsToCursorTarget), (ASLtoAGL _testPosASL), 0.25, 0.25, 0, "", 0.5, 0.025, "TahomaB"];
|
2021-02-27 17:05:05 +00:00
|
|
|
if (_intersectionsToCursorTarget isNotEqualTo []) then {
|
2016-11-15 18:15:25 +00:00
|
|
|
(_intersectionsToCursorTarget select 0) params ["", "", "_intersectedObject"];
|
|
|
|
if (_intersectedObject isKindOf "AllVehicles") then {
|
|
|
|
_intersectedObject breakOut "main";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
objNull
|