From ff04ca898115da5b3ae2c54f103fe38b279701ae Mon Sep 17 00:00:00 2001 From: esteldunedain Date: Thu, 18 Feb 2016 20:20:02 -0300 Subject: [PATCH 1/3] Uniformize interaction distance for vehicle. Distance is now aprox 4m from the bounding box of the vehicle, consistent with interaction with people. --- .../functions/fnc_renderActionPoints.sqf | 6 +- .../functions/fnc_renderBaseMenu.sqf | 3 +- addons/interaction/CfgVehicles.hpp | 16 ++-- addons/interaction/XEH_preInit.sqf | 1 + .../functions/fnc_getVehiclePos.sqf | 75 +++++++++++++++++++ 5 files changed, 90 insertions(+), 11 deletions(-) create mode 100644 addons/interaction/functions/fnc_getVehiclePos.sqf diff --git a/addons/interact_menu/functions/fnc_renderActionPoints.sqf b/addons/interact_menu/functions/fnc_renderActionPoints.sqf index 1d42f38c6c..99c32ac81b 100644 --- a/addons/interact_menu/functions/fnc_renderActionPoints.sqf +++ b/addons/interact_menu/functions/fnc_renderActionPoints.sqf @@ -16,8 +16,8 @@ GVAR(currentOptions) = []; private _player = ACE_player; -private _cameraPosASL = AGLtoASL (positionCameraToWorld [0, 0, 0]); -private _cameraDir = (AGLtoASL (positionCameraToWorld [0, 0, 1])) vectorDiff _cameraPosASL; +GVAR(cameraPosASL) = AGLtoASL (positionCameraToWorld [0, 0, 0]); +GVAR(cameraDir) = (AGLtoASL (positionCameraToWorld [0, 0, 1])) vectorDiff GVAR(cameraPosASL); private _fnc_renderNearbyActions = { // Render all nearby interaction menus @@ -32,7 +32,7 @@ private _fnc_renderNearbyActions = { private _target = _x; // Quick oclussion test. Skip objects more than 1 m behind the camera plane - private _lambda = ((getPosASL _x) vectorDiff _cameraPosASL) vectorDotProduct _cameraDir; + private _lambda = ((getPosASL _x) vectorDiff GVAR(cameraPosASL)) vectorDotProduct GVAR(cameraDir); if ((_lambda > -1) && {!isObjectHidden _target}) then { private _numInteractions = 0; // Prevent interacting with yourself or your own vehicle diff --git a/addons/interact_menu/functions/fnc_renderBaseMenu.sqf b/addons/interact_menu/functions/fnc_renderBaseMenu.sqf index 57ded33be0..b08a1e45ad 100644 --- a/addons/interact_menu/functions/fnc_renderBaseMenu.sqf +++ b/addons/interact_menu/functions/fnc_renderBaseMenu.sqf @@ -90,9 +90,8 @@ if (_activeActionTree isEqualTo []) exitWith {false}; BEGIN_COUNTER(fnc_renderMenus); -// IGNORE_PRIVATE_WARNING(_cameraPosASL,_cameraDir); if (count _pos > 2) then { - _sPos pushBack (((AGLtoASL _pos) vectorDiff _cameraPosASL) vectorDotProduct _cameraDir); + _sPos pushBack (((AGLtoASL _pos) vectorDiff GVAR(cameraPosASL)) vectorDotProduct GVAR(cameraDir)); } else { _sPos pushBack 0; }; diff --git a/addons/interaction/CfgVehicles.hpp b/addons/interaction/CfgVehicles.hpp index f37e80ff33..a789045430 100644 --- a/addons/interaction/CfgVehicles.hpp +++ b/addons/interaction/CfgVehicles.hpp @@ -307,8 +307,9 @@ class CfgVehicles { class ACE_Actions { class ACE_MainActions { displayName = CSTRING(MainAction); + position = QUOTE(call DFUNC(getVehiclePos)); selection = ""; - distance = 10; + distance = 4; condition = "true"; class ACE_Passengers { displayName = CSTRING(Passengers); @@ -333,8 +334,9 @@ class CfgVehicles { class ACE_Actions { class ACE_MainActions { displayName = CSTRING(MainAction); + position = QUOTE(call DFUNC(getVehiclePos)); selection = ""; - distance = 10; + distance = 4; condition = "true"; class ACE_Passengers { displayName = CSTRING(Passengers); @@ -360,8 +362,9 @@ class CfgVehicles { class ACE_Actions { class ACE_MainActions { displayName = CSTRING(MainAction); + position = QUOTE(call DFUNC(getVehiclePos)); selection = ""; - distance = 10; + distance = 4; condition = "true"; class ACE_Passengers { displayName = CSTRING(Passengers); @@ -387,7 +390,7 @@ class CfgVehicles { class ACE_MainActions { displayName = CSTRING(MainAction); selection = ""; - distance = 10; + distance = 4; condition = "true"; class ACE_Passengers { displayName = CSTRING(Passengers); @@ -413,8 +416,9 @@ class CfgVehicles { class ACE_Actions { class ACE_MainActions { displayName = CSTRING(MainAction); + position = QUOTE(call DFUNC(getVehiclePos)); selection = ""; - distance = 10; + distance = 4; condition = "true"; class ACE_Push { @@ -449,7 +453,7 @@ class CfgVehicles { class ACE_MainActions { displayName = CSTRING(MainAction); selection = "gunnerview"; - distance = 2; + distance = 4; condition = "true"; class ACE_Passengers { displayName = CSTRING(Passengers); diff --git a/addons/interaction/XEH_preInit.sqf b/addons/interaction/XEH_preInit.sqf index 258567482d..6220307788 100644 --- a/addons/interaction/XEH_preInit.sqf +++ b/addons/interaction/XEH_preInit.sqf @@ -5,6 +5,7 @@ ADDON = false; // interaction menu PREP(addPassengerActions); PREP(addPassengersActions); +PREP(getVehiclePos); PREP(getWeaponPos); PREP(moduleInteraction); PREP(removeTag); diff --git a/addons/interaction/functions/fnc_getVehiclePos.sqf b/addons/interaction/functions/fnc_getVehiclePos.sqf new file mode 100644 index 0000000000..207279539f --- /dev/null +++ b/addons/interaction/functions/fnc_getVehiclePos.sqf @@ -0,0 +1,75 @@ +/* + * Author: esteldunedain + * Return a suitable position for the action point for the given target vehicle + * + * Arguments: + * None (uses local variable _target) + * + * Return value: + * Children actions + * + * Example: + * call ace_interaction_fnc_getWeaponPos + * + * Public: No + */ +#include "script_component.hpp" +// IGNORE_PRIVATE_WARNING(_target); + +private _bb = boundingBoxReal _target; +_bb params ["_p1",""]; +private _relPos = _target worldToModelVisual ASLToAGL EGVAR(interact_menu,cameraPosASL); +#ifdef DEBUG_MODE_FULL + _relPos = _target worldToModelVisual ASLToAGL eyePos ACE_player; +#endif +_relPos params ["_dx", "_dy", "_dz"]; + +private _ndx = (abs _dx) / ((abs (_p1 select 0)) - 1); +private _ndy = (abs _dy) / ((abs (_p1 select 1)) - 1); +private _ndz = (abs _dz) / ((abs (_p1 select 2)) - 1); + +private "_pos"; +if (_ndx > _ndy) then { + if (_ndx > _ndz) then { + // _ndx is greater, will colide with x plane first + _pos = _relPos vectorMultiply ((1 / _ndx) min 0.8); + } else { + // _ndz is greater, will colide with z plane first + _pos = _relPos vectorMultiply ((1 / _ndz) min 0.8); + }; +} else { + if (_ndy > _ndz) then { + // _ndy is greater, will colide with y plane first + _pos = _relPos vectorMultiply ((1 / _ndy) min 0.8); + } else { + // _ndz is greater, will colide with z plane first + _pos = _relPos vectorMultiply ((1 / _ndz) min 0.8); + }; +}; +TRACE_3("",_bb,_relPos, _pos); +_pos + +/////////////////// +// The code belows works very well for cursor mode, but not at all in normal mode +// maybe it could be enabled by default only for that mode +/* +if (cursorObject isEqualTo _target) exitWith { + private _dest = EGVAR(interact_menu,cameraPosASL) vectorAdd (EGVAR(interact_menu,cameraDir) vectorMultiply 50); + private _origin = EGVAR(interact_menu,cameraPosASL); + //private _origin = EGVAR(interact_menu,cameraPosASL) vectorAdd [0, 0, -0.35] vectorDiff (EGVAR(interact_menu,cameraDir) vectorMultiply 1.5); + //private _dest = AGLtoASL (_target modelToWorldVisual [0,0,0]); + private _results = lineIntersectsSurfaces [_origin, _dest, ACE_player, objNull, true, 5]; + private _finalPos = [0,0,0]; + { + _x params ["_pos", "", "_obj"]; + TRACE_3("",_forEachIndex,_obj,_target); + if (_obj isEqualTo _target) exitWith { + _finalPos = _target worldToModelVisual ASLtoAGL (_pos vectorAdd (EGVAR(interact_menu,cameraDir) vectorMultiply 1.0)); + }; + } forEach _results; + _finalPos +}; +[0,0,0] +*/ +/////////////////// + From cfc046ce714ea264f8e128131049ffea8a568bdf Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Tue, 14 Jun 2016 19:37:22 -0500 Subject: [PATCH 2/3] Fix Merge --- addons/interaction/XEH_PREP.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/addons/interaction/XEH_PREP.hpp b/addons/interaction/XEH_PREP.hpp index be6158cdd5..db6b1d3298 100644 --- a/addons/interaction/XEH_PREP.hpp +++ b/addons/interaction/XEH_PREP.hpp @@ -2,6 +2,7 @@ // interaction menu PREP(addPassengerActions); PREP(addPassengersActions); +PREP(getVehiclePos); PREP(getWeaponPos); PREP(moduleInteraction); From 81c8ea54c396bb6e9b97aa3819f689ecece9e129 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Tue, 14 Jun 2016 23:30:58 -0500 Subject: [PATCH 3/3] getVehPos - Tweak heli width, and put at eye level --- .../functions/fnc_getVehiclePos.sqf | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/addons/interaction/functions/fnc_getVehiclePos.sqf b/addons/interaction/functions/fnc_getVehiclePos.sqf index 207279539f..1b8ebc69f6 100644 --- a/addons/interaction/functions/fnc_getVehiclePos.sqf +++ b/addons/interaction/functions/fnc_getVehiclePos.sqf @@ -9,7 +9,7 @@ * Children actions * * Example: - * call ace_interaction_fnc_getWeaponPos + * call ace_interaction_fnc_getVehiclePos * * Public: No */ @@ -17,16 +17,20 @@ // IGNORE_PRIVATE_WARNING(_target); private _bb = boundingBoxReal _target; -_bb params ["_p1",""]; +(_bb select 0) params ["_bbX", "_bbY", "_bbZ"]; + +//Helicopter's rotors distort the bounding box, assume a max of 3 meters width for the body +if (_target isKindOf "Helicopter") then {_bbX = (_bbx min 3) max -3;}; + private _relPos = _target worldToModelVisual ASLToAGL EGVAR(interact_menu,cameraPosASL); #ifdef DEBUG_MODE_FULL _relPos = _target worldToModelVisual ASLToAGL eyePos ACE_player; #endif _relPos params ["_dx", "_dy", "_dz"]; -private _ndx = (abs _dx) / ((abs (_p1 select 0)) - 1); -private _ndy = (abs _dy) / ((abs (_p1 select 1)) - 1); -private _ndz = (abs _dz) / ((abs (_p1 select 2)) - 1); +private _ndx = (abs _dx) / ((abs (_bbx)) - 1); +private _ndy = (abs _dy) / ((abs (_bbY)) - 1); +private _ndz = (abs _dz) / ((abs (_bbZ)) - 1); private "_pos"; if (_ndx > _ndy) then { @@ -46,7 +50,9 @@ if (_ndx > _ndy) then { _pos = _relPos vectorMultiply ((1 / _ndz) min 0.8); }; }; -TRACE_3("",_bb,_relPos, _pos); +//Set max height at player's eye level (prevent very high interactin point on choppers) +_pos set [2, (_pos select 2) min _dz]; +TRACE_4("",_bb,_bbX,_relPos, _pos); _pos ///////////////////