From 1735047e3c851a4bc5fc05d9cca6acc5ea0aa7cd Mon Sep 17 00:00:00 2001 From: esteldunedain Date: Sat, 2 May 2015 14:37:58 -0300 Subject: [PATCH] Make closer action points oclude farther ones. Improves the clutter of the interact menu when interating with a person from the side. Close #738 --- addons/interact_menu/XEH_preInit.sqf | 1 + .../functions/fnc_renderActionPoints.sqf | 36 +++++++++++++++++-- .../functions/fnc_renderBaseMenu.sqf | 8 +++-- 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/addons/interact_menu/XEH_preInit.sqf b/addons/interact_menu/XEH_preInit.sqf index 3d67dab6a9..ee0ffe9504 100644 --- a/addons/interact_menu/XEH_preInit.sqf +++ b/addons/interact_menu/XEH_preInit.sqf @@ -66,6 +66,7 @@ GVAR(expandedTime) = diag_tickTime; GVAR(iconCtrls) = []; GVAR(iconCount) = 0; +GVAR(collectedActionPoints) = []; GVAR(foundActions) = []; GVAR(lastTimeSearchedActions) = -1000; diff --git a/addons/interact_menu/functions/fnc_renderActionPoints.sqf b/addons/interact_menu/functions/fnc_renderActionPoints.sqf index 8e6cb7d390..c12cbe8c16 100644 --- a/addons/interact_menu/functions/fnc_renderActionPoints.sqf +++ b/addons/interact_menu/functions/fnc_renderActionPoints.sqf @@ -17,13 +17,13 @@ GVAR(currentOptions) = []; private ["_player","_numInteractObjects","_numInteractions","_actionsVarName","_classActions","_target","_player","_action","_cameraPos","_cameraDir", "_lambda", "_nearestObjects", "_pos"]; _player = ACE_player; +_cameraPos = (positionCameraToWorld [0, 0, 0]) call EFUNC(common,positionToASL); +_cameraDir = ((positionCameraToWorld [0, 0, 1]) call EFUNC(common,positionToASL)) vectorDiff _cameraPos; + _fnc_renderNearbyActions = { // Render all nearby interaction menus #define MAXINTERACTOBJECTS 3 - _cameraPos = (positionCameraToWorld [0, 0, 0]) call EFUNC(common,positionToASL); - _cameraDir = ((positionCameraToWorld [0, 0, 1]) call EFUNC(common,positionToASL)) vectorDiff _cameraPos; - GVAR(foundActions) = []; GVAR(lastTimeSearchedActions) = diag_tickTime; @@ -114,6 +114,8 @@ _fnc_renderSelfActions = { }; +GVAR(collectedActionPoints) resize 0; + // Render nearby actions, unit self actions or vehicle self actions as appropiate if (GVAR(openedMenuType) == 0) then { @@ -132,3 +134,31 @@ if (GVAR(openedMenuType) == 0) then { } else { ACE_player call _fnc_renderSelfActions; }; + +if (count GVAR(collectedActionPoints) > 1) then { + // Do the oclusion pass + + // Order action points according to z + // @todo: after 1.43 is released switch BIS_fnc_sortBy with sort + GVAR(collectedActionPoints) = [GVAR(collectedActionPoints),[],{_x select 0},"ASCEND"] call BIS_fnc_sortBy; + //GVAR(collectedActionPoints) sort true; + + private ["_i","_j","_delta"]; + for [{_i = count GVAR(collectedActionPoints) - 1}, {_i > 0}, {_i = _i - 1}] do { + for [{_j = _i - 1}, {_j >= 0}, {_j = _j - 1}] do { + // Check if action point _i is ocluded by _j + _delta = vectorNormalized ((GVAR(collectedActionPoints) select _i select 1) vectorDiff (GVAR(collectedActionPoints) select _j select 1)); + + // If _i is inside a cone with 20ยบ half angle with origin on _j + if (_delta select 2 > 0.94) exitWith { + GVAR(collectedActionPoints) deleteAt _i; + }; + }; + }; +}; + +// Render the non-ocluded points +{ + EXPLODE_3_PVT(_x,_z,_sPos,_activeActionTree); + [[], _activeActionTree, _sPos, [180,360]] call FUNC(renderMenu); +} forEach GVAR(collectedActionPoints); diff --git a/addons/interact_menu/functions/fnc_renderBaseMenu.sqf b/addons/interact_menu/functions/fnc_renderBaseMenu.sqf index 4daa4a5c90..913a361941 100644 --- a/addons/interact_menu/functions/fnc_renderBaseMenu.sqf +++ b/addons/interact_menu/functions/fnc_renderBaseMenu.sqf @@ -93,11 +93,13 @@ _fnc_print = { // Check if there's something left for rendering if (count _activeActionTree == 0) exitWith {false}; -//EXPLODE_2_PVT(_activeActionTree,_actionData,_actionChildren); - BEGIN_COUNTER(fnc_renderMenus); -[[], _activeActionTree, _sPos, [180,360]] call FUNC(renderMenu); +// IGNORE_PRIVATE_WARNING(_cameraPos,_cameraDir); +_sPos pushBack (((_pos call EFUNC(common,positionToASL)) vectorDiff _cameraPos) vectorDotProduct _cameraDir); + +// Add action point for oclusion and rendering +GVAR(collectedActionPoints) pushBack [_sPos select 2, _sPos, _activeActionTree]; END_COUNTER(fnc_renderMenus);