2023-09-12 18:58:10 +00:00
|
|
|
#include "..\script_component.hpp"
|
2022-05-17 16:55:09 +00:00
|
|
|
/*
|
2023-04-30 21:03:35 +00:00
|
|
|
* Author: PabstMirror
|
|
|
|
* Runs each frame while inside of a vehicle with viewports
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* 0: PFEH Args <ARRAY>
|
|
|
|
* 0: Player <OBJECT>
|
|
|
|
* 1: Vehicle <OBJECT>
|
|
|
|
* 2: Viewport configuration <ARRAY>
|
|
|
|
* 3: Viewport index shown (-1 for none) <NUMBER>
|
|
|
|
* 4: Last visionmode <NUMBER>
|
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* [] call ace_viewports_fnc_eachFrame
|
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
2022-05-17 16:55:09 +00:00
|
|
|
|
|
|
|
params ["_args", "_pfID"];
|
|
|
|
_args params ["_player", "_vehicle", "_viewports", "_shownIndex", "_lastVisionMode"];
|
|
|
|
|
|
|
|
private _newIndex = -1;
|
|
|
|
if (cba_events_control) then {
|
|
|
|
if (cameraView != "INTERNAL") exitWith {};
|
|
|
|
if (isTurnedOut _player) exitWith {};
|
2024-06-18 14:08:03 +00:00
|
|
|
if !([_player, _vehicle, []] call EFUNC(common,canInteractWith)) exitWith {};
|
2022-05-17 16:55:09 +00:00
|
|
|
|
|
|
|
BEGIN_COUNTER(newIndex);
|
|
|
|
if ((_shownIndex > -1) && {currentVisionMode _player != _lastVisionMode}) then {
|
|
|
|
// Vision Mode Changed - Force stop cam and restart
|
|
|
|
call FUNC(viewCleanup);
|
|
|
|
_shownIndex = -1;
|
|
|
|
};
|
|
|
|
|
2024-03-07 21:08:13 +00:00
|
|
|
([_player] call FUNC(getSeatInfo)) params ["_role", "", "", "_compartment"];
|
2023-04-30 21:03:35 +00:00
|
|
|
|
2022-05-17 16:55:09 +00:00
|
|
|
private _newIndexAngle = 45; // Controls the max angle
|
|
|
|
private _eyesPosASL = AGLtoASL (positionCameraToWorld [0, 0, 0]);
|
|
|
|
private _eyesDir = (AGLtoASL (positionCameraToWorld [0, 0, 1])) vectorDiff _eyesPosASL;
|
|
|
|
{
|
|
|
|
_x params ["", "", "_camLocation", "", "_screenLocation", "_maxDistance", "_compartments", "_roles"];
|
|
|
|
|
|
|
|
private _viewASL = AGLtoASL (_vehicle modelToWorldVisual _screenLocation);
|
|
|
|
private _viewDiff = _viewASL vectorDiff _eyesPosASL;
|
|
|
|
private _viewAngle = acos (_viewDiff vectorCos _eyesDir);
|
|
|
|
#ifdef DEBUG_MODE_FULL
|
|
|
|
systemChat format ["%1: %2 @ %3",_forEachIndex,round _viewAngle, vectorMagnitude _viewDiff];
|
|
|
|
#endif
|
|
|
|
if (
|
2023-04-30 21:03:35 +00:00
|
|
|
(_viewAngle < _newIndexAngle)
|
2024-03-07 21:08:13 +00:00
|
|
|
&& {(_compartments isEqualTo []) || {(toLowerANSI _compartment) in _compartments}}
|
|
|
|
&& {(_roles isEqualTo []) || {(toLowerANSI _role) in _roles}}
|
2022-05-17 16:55:09 +00:00
|
|
|
&& {(vectorMagnitude _viewDiff) < _maxDistance}
|
|
|
|
) then {
|
|
|
|
_newIndex = _forEachIndex;
|
|
|
|
_newIndexAngle = _viewAngle;
|
|
|
|
};
|
|
|
|
} forEach _viewports;
|
|
|
|
END_COUNTER(newIndex);
|
|
|
|
};
|
|
|
|
|
|
|
|
if (_shownIndex == _newIndex) exitWith {}; // No-change - fast exit
|
|
|
|
|
|
|
|
if (_shownIndex > -1) then {
|
|
|
|
call FUNC(viewCleanup);
|
|
|
|
};
|
|
|
|
|
|
|
|
if (_newIndex > -1) then {
|
|
|
|
[_vehicle, _viewports # _newIndex, currentVisionMode _player] call FUNC(viewCreate);
|
|
|
|
_args set [4, currentVisionMode _player];
|
|
|
|
};
|
|
|
|
|
|
|
|
_args set [3, _newIndex];
|