From 2eb547a52e0ea26e6809005797298539b967dca6 Mon Sep 17 00:00:00 2001 From: commy2 Date: Thu, 15 Jan 2015 19:01:27 +0100 Subject: [PATCH] some advanced vector modes, macros --- addons/main/script_macros.hpp | 3 + addons/vector/XEH_preInit.sqf | 14 ++-- .../fnc_getRelativeAzimuthDistance.sqf | 53 +++++++++++++ .../functions/fnc_modeDistanceAzimuth.sqf | 47 ----------- .../functions/fnc_modeDistanceHeight.sqf | 56 ------------- addons/vector/functions/fnc_onKeyDown.sqf | 8 ++ addons/vector/functions/fnc_showP1.sqf | 23 ++++++ .../fnc_showRelativeAzimuthDistance.sqf | 74 ++++++++++++++++++ addons/vector/rsc/{dp.paa => vector_p.paa} | Bin 9 files changed, 170 insertions(+), 108 deletions(-) create mode 100644 addons/vector/functions/fnc_getRelativeAzimuthDistance.sqf delete mode 100644 addons/vector/functions/fnc_modeDistanceAzimuth.sqf delete mode 100644 addons/vector/functions/fnc_modeDistanceHeight.sqf create mode 100644 addons/vector/functions/fnc_showP1.sqf create mode 100644 addons/vector/functions/fnc_showRelativeAzimuthDistance.sqf rename addons/vector/rsc/{dp.paa => vector_p.paa} (100%) diff --git a/addons/main/script_macros.hpp b/addons/main/script_macros.hpp index 9b243c54a5..ee8dc66220 100644 --- a/addons/main/script_macros.hpp +++ b/addons/main/script_macros.hpp @@ -198,6 +198,9 @@ #define SETMVAR(var1,var2) missionNamespace SETVAR_SYS(var1,var2) #define SETUVAR(var1,var2) uiNamespace SETVAR_SYS(var1,var2) +#define GETVARD(var1,var2) GETMVAR(GVAR(var1),var2) +#define GETEVARD(var1,var2,var3) GETMVAR(EGVAR(var1,var2),var3) + #ifdef DISABLE_COMPILE_CACHE #define PREP(fncName) DFUNC(fncName) = compile preprocessFileLineNumbers QUOTE(PATHTOF(functions\DOUBLES(fnc,fncName).sqf)) diff --git a/addons/vector/XEH_preInit.sqf b/addons/vector/XEH_preInit.sqf index 8f35478045..c3c3576797 100644 --- a/addons/vector/XEH_preInit.sqf +++ b/addons/vector/XEH_preInit.sqf @@ -3,28 +3,32 @@ PREP(abort); PREP(config); PREP(convertFOS); -PREP(modeFallOfShort); -PREP(modeRelativeAzimuthDistance); -PREP(modeRelativeDistance); -PREP(modeRelativeDistanceHeight); PREP(settings); PREP(tabAzimuthKey); PREP(tabDistanceKey); +///// PREP(clearDisplay); PREP(convertToTexturesDegree); PREP(convertToTexturesDistance); + PREP(getDirection); PREP(getDistance); PREP(getHeightDistance); +PREP(getRelativeAzimuthDistance); + PREP(onKeyDown); PREP(onKeyHold); PREP(onKeyUp); + PREP(showAzimuth); PREP(showAzimuthInclination); -PREP(showCenter); PREP(showHeightDistance); PREP(showDistance); +PREP(showRelativeAzimuthDistance); + +PREP(showCenter); +PREP(showP1); GVAR(holdKeyHandler) = -1; GVAR(isKeyDownAzimuth) = false; diff --git a/addons/vector/functions/fnc_getRelativeAzimuthDistance.sqf b/addons/vector/functions/fnc_getRelativeAzimuthDistance.sqf new file mode 100644 index 0000000000..328650ec41 --- /dev/null +++ b/addons/vector/functions/fnc_getRelativeAzimuthDistance.sqf @@ -0,0 +1,53 @@ +// by commy2 +#include "script_component.hpp" + +_distanceP1 = call AGM_Vector_fnc_getDistance; +_directionP1 = call AGM_Vector_fnc_getDirection; +_azimuthP1 = _directionP1 select 0; +_inclinationP1 = _directionP1 select 1; + +_ctrlDigitE1 ctrlSetText "\AGM_Vector\rsc\d1.paa"; +_ctrlDigitE2 ctrlSetText "\AGM_Vector\rsc\d-.paa"; +_ctrlDigitE3 ctrlSetText "\AGM_Vector\rsc\dP.paa"; + +waitUntil {!(AGM_vectorKey select 0)}; + +_distanceP2 = call AGM_Vector_fnc_getDistance; +_directionP2 = call AGM_Vector_fnc_getDirection; +_azimuthP2 = _directionP2 select 0; +_inclinationP2 = _directionP2 select 1; + +_relDirection = sqrt ((_azimuthP1 - _azimuthP2)^2 + (_inclinationP1 - _inclinationP2)^2); +_relDistance = sqrt (_distanceP1^2 + _distanceP2^2 - 2 * _distanceP1 * _distanceP2 * cos _relDirection); +_relHeight = (sin _inclinationP1 * _distanceP1) - (sin _inclinationP2 * _distanceP2); +_relLenght = sqrt (_relDistance^2 - _relHeight^2); if (str(_relLenght) == "-1.#IND") then {_relLenght = 0}; + +_lenghtP1 = cos _inclinationP1 * _distanceP1; +_lenghtP2 = cos _inclinationP2 * _distanceP2; +_relAzimuth = (sin _azimuthP2 * _lenghtP2 - sin _azimuthP1 * _lenghtP1) atan2 (cos _azimuthP2 * _lenghtP2 - cos _azimuthP1 * _lenghtP1); +if (_relAzimuth < 0) then {_relAzimuth = _relAzimuth + 360}; + +if (_distanceP1 == -9999 || {_distanceP2 == -9999}) then { + _relDistance = -9999; + _relAzimuth = -9999; +}; + +_digits = _relLenght call AGM_Vector_fnc_convertDistance; +_ctrlDigit1 ctrlSetText (_digits select 0); +_ctrlDigit2 ctrlSetText (_digits select 1); +_ctrlDigit3 ctrlSetText (_digits select 2); +_ctrlDigit4 ctrlSetText (_digits select 3); + +_digits = _relAzimuth call AGM_Vector_fnc_convertDegree; +_ctrlDigit5 ctrlSetText (_digits select 0); +_ctrlDigit6 ctrlSetText (_digits select 1); +_ctrlDigit7 ctrlSetText (_digits select 2); +_ctrlDigit8 ctrlSetText (_digits select 3); + +_ctrlVectorCenter ctrlShow false; + +_ctrlDigitE1 ctrlShow false; +_ctrlDigitE2 ctrlShow false; +_ctrlDigitE3 ctrlShow false; + +AGM_isVectorReady = true; diff --git a/addons/vector/functions/fnc_modeDistanceAzimuth.sqf b/addons/vector/functions/fnc_modeDistanceAzimuth.sqf deleted file mode 100644 index 1f0aa0edb4..0000000000 --- a/addons/vector/functions/fnc_modeDistanceAzimuth.sqf +++ /dev/null @@ -1,47 +0,0 @@ -// by commy2 -#include "script_component.hpp" - -private["_dlgVector", "_ctrlVectorCenter", "_ctrlDigit1", "_ctrlDigit2", "_ctrlDigit3", "_ctrlDigit4", "_ctrlDigit5", "_ctrlDigit6", "_ctrlDigit7", "_ctrlDigit8", "_time", "_direction", "_azimuth", "_exit", "_distance", "_digits"]; - -disableSerialization; -_dlgVector = uiNamespace getVariable "AGM_dlgVector"; -_ctrlVectorCenter = _dlgVector displayCtrl 1; -_ctrlDigit1 = _dlgVector displayCtrl 11; -_ctrlDigit2 = _dlgVector displayCtrl 12; -_ctrlDigit3 = _dlgVector displayCtrl 13; -_ctrlDigit4 = _dlgVector displayCtrl 14; -_ctrlDigit5 = _dlgVector displayCtrl 15; -_ctrlDigit6 = _dlgVector displayCtrl 16; -_ctrlDigit7 = _dlgVector displayCtrl 17; -_ctrlDigit8 = _dlgVector displayCtrl 18; - -_ctrlVectorCenter ctrlSetText "\AGM_Vector\rsc\Vector_Center.paa"; - -_time = -1; -waitUntil { - if (time > _time + 0.5) then { - _direction = call AGM_Vector_fnc_getDirection; - _azimuth = _direction select 0; - - _digits = _azimuth call AGM_Vector_fnc_convertDegree; - _ctrlDigit5 ctrlSetText (_digits select 0); - _ctrlDigit6 ctrlSetText (_digits select 1); - _ctrlDigit7 ctrlSetText (_digits select 2); - _ctrlDigit8 ctrlSetText (_digits select 3); - - _time = time; - }; - !(AGM_vectorKey select 0) && {!(AGM_vectorKey select 1)} -}; - -_distance = call AGM_Vector_fnc_getDistance; - -_digits = _distance call AGM_Vector_fnc_convertDistance; -_ctrlDigit1 ctrlSetText (_digits select 0); -_ctrlDigit2 ctrlSetText (_digits select 1); -_ctrlDigit3 ctrlSetText (_digits select 2); -_ctrlDigit4 ctrlSetText (_digits select 3); - -_ctrlVectorCenter ctrlShow false; - -AGM_isVectorReady = true; diff --git a/addons/vector/functions/fnc_modeDistanceHeight.sqf b/addons/vector/functions/fnc_modeDistanceHeight.sqf deleted file mode 100644 index 3f7753f886..0000000000 --- a/addons/vector/functions/fnc_modeDistanceHeight.sqf +++ /dev/null @@ -1,56 +0,0 @@ -// by commy2 -#include "script_component.hpp" - -private["_dlgVector", "_ctrlVectorCenter", "_ctrlDigit1", "_ctrlDigit2", "_ctrlDigit3", "_ctrlDigit4", "_ctrlDigit5", "_ctrlDigit6", "_ctrlDigit7", "_ctrlDigit8", "_direction", "_azimuth", "_exit", "_distance", "_digits", "_inclination", "_height", "_lenght"]; - -disableSerialization; -_dlgVector = uiNamespace getVariable "AGM_dlgVector"; -_ctrlVectorCenter = _dlgVector displayCtrl 1; -_ctrlDigit1 = _dlgVector displayCtrl 11; -_ctrlDigit2 = _dlgVector displayCtrl 12; -_ctrlDigit3 = _dlgVector displayCtrl 13; -_ctrlDigit4 = _dlgVector displayCtrl 14; -_ctrlDigit5 = _dlgVector displayCtrl 15; -_ctrlDigit6 = _dlgVector displayCtrl 16; -_ctrlDigit7 = _dlgVector displayCtrl 17; -_ctrlDigit8 = _dlgVector displayCtrl 18; - -_ctrlVectorCenter ctrlSetText "\AGM_Vector\rsc\Vector_Center.paa"; - -_exit = false; -waitUntil { - if (AGM_vectorKey select 0) then {_exit = true}; - !(AGM_vectorKey select 1) || {_exit} -}; -if (_exit) exitWith { - waitUntil {!(AGM_vectorKey select 0)}; - AGM_Vector_scriptHandle = 0 spawn AGM_Vector_fnc_modeRelativeDistanceHeight; -}; - -_distance = call AGM_Vector_fnc_getDistance; -_direction = call AGM_Vector_fnc_getDirection; -_azimuth = _direction select 0; -_inclination = _direction select 1; - -_height = sin _inclination * _distance; -_lenght = cos _inclination * _distance; -if (_distance == -9999) then { - _height = -9999; - _lenght = -9999; -}; - -_digits = _height call AGM_Vector_fnc_convertDistance; -_ctrlDigit1 ctrlSetText (_digits select 0); -_ctrlDigit2 ctrlSetText (_digits select 1); -_ctrlDigit3 ctrlSetText (_digits select 2); -_ctrlDigit4 ctrlSetText (_digits select 3); - -_digits = _lenght call AGM_Vector_fnc_convertDistance; -_ctrlDigit5 ctrlSetText (_digits select 0); -_ctrlDigit6 ctrlSetText (_digits select 1); -_ctrlDigit7 ctrlSetText (_digits select 2); -_ctrlDigit8 ctrlSetText (_digits select 3); - -_ctrlVectorCenter ctrlShow false; - -AGM_isVectorReady = true; diff --git a/addons/vector/functions/fnc_onKeyDown.sqf b/addons/vector/functions/fnc_onKeyDown.sqf index a062103eba..5e6681011f 100644 --- a/addons/vector/functions/fnc_onKeyDown.sqf +++ b/addons/vector/functions/fnc_onKeyDown.sqf @@ -31,6 +31,10 @@ switch (_this select 0) do { GVAR(keyDownTimeAzimuth) = diag_tickTime; if (diag_tickTime > GVAR(keyDownTimeDistance) + 0.5) then { + if (GETVARD(isKeyDownDistance,false)) exitWith { + hint "P1 relative distance mode"; + }; + ["distance"] call FUNC(clearDisplay); "azimuth" call _fnc_setPFH; } else { @@ -52,6 +56,10 @@ switch (_this select 0) do { GVAR(keyDownTimeDistance) = diag_tickTime; if (diag_tickTime > GVAR(keyDownTimeAzimuth) + 0.5) then { + if (GETVARD(isKeyDownAzimuth,false)) exitWith { + hint "P1 relative azimuth + non-slope distance mode"; + }; + ["azimuth"] call FUNC(clearDisplay); "distance" call _fnc_setPFH; } else { diff --git a/addons/vector/functions/fnc_showP1.sqf b/addons/vector/functions/fnc_showP1.sqf new file mode 100644 index 0000000000..0e9f6b0bcd --- /dev/null +++ b/addons/vector/functions/fnc_showP1.sqf @@ -0,0 +1,23 @@ +/* + +by commy2 + +Shows or hides the vectors center square thingy. + +*/ +#include "script_component.hpp" + +private "_dlgVector"; + +disableSerialization; +_dlgVector = GETUVAR(ACE_dlgVector,displayNull); + +if (_this select 0) then { + (_dlgVector displayCtrl 1321) ctrlSetText QUOTE(PATHTOF(rsc\vector_1.paa)); + (_dlgVector displayCtrl 1322) ctrlSetText QUOTE(PATHTOF(rsc\vector_minus.paa)); + (_dlgVector displayCtrl 1323) ctrlSetText QUOTE(PATHTOF(rsc\vector_p.paa)); +} else { + (_dlgVector displayCtrl 1321) ctrlSetText ""; + (_dlgVector displayCtrl 1322) ctrlSetText ""; + (_dlgVector displayCtrl 1323) ctrlSetText ""; +}; diff --git a/addons/vector/functions/fnc_showRelativeAzimuthDistance.sqf b/addons/vector/functions/fnc_showRelativeAzimuthDistance.sqf new file mode 100644 index 0000000000..051c21abfb --- /dev/null +++ b/addons/vector/functions/fnc_showRelativeAzimuthDistance.sqf @@ -0,0 +1,74 @@ + + +// by commy2 +#include "script_component.hpp" + +private["_dlgVector", "_ctrlVectorCenter", "_ctrlDigit1", "_ctrlDigit2", "_ctrlDigit3", "_ctrlDigit4", "_ctrlDigit5", "_ctrlDigit6", "_ctrlDigit7", "_ctrlDigit8", "_ctrlDigitE1", "_ctrlDigitE2", "_ctrlDigitE3", "_distanceP1", "_directionP1", "_azimuthP1", "_inclinationP1", "_directionP2", "_azimuthP2", "_distanceP2", "_inclinationP2", "_digits", "_relDirection", "_relDistance", "_relHeight", "_relLenght", "_digits0", "_digits1", "_digits2", "_lenghtP1", "_lenghtP2", "_relAzimuth"]; + +disableSerialization; +_dlgVector = uiNamespace getVariable "AGM_dlgVector"; +_ctrlVectorCenter = _dlgVector displayCtrl 1; +_ctrlDigit1 = _dlgVector displayCtrl 11; +_ctrlDigit2 = _dlgVector displayCtrl 12; +_ctrlDigit3 = _dlgVector displayCtrl 13; +_ctrlDigit4 = _dlgVector displayCtrl 14; +_ctrlDigit5 = _dlgVector displayCtrl 15; +_ctrlDigit6 = _dlgVector displayCtrl 16; +_ctrlDigit7 = _dlgVector displayCtrl 17; +_ctrlDigit8 = _dlgVector displayCtrl 18; +_ctrlDigitE1 = _dlgVector displayCtrl 21; +_ctrlDigitE2 = _dlgVector displayCtrl 22; +_ctrlDigitE3 = _dlgVector displayCtrl 23; + +_ctrlVectorCenter ctrlSetText "\AGM_Vector\rsc\Vector_Center.paa"; + +_distanceP1 = call AGM_Vector_fnc_getDistance; +_directionP1 = call AGM_Vector_fnc_getDirection; +_azimuthP1 = _directionP1 select 0; +_inclinationP1 = _directionP1 select 1; + +_ctrlDigitE1 ctrlSetText "\AGM_Vector\rsc\d1.paa"; +_ctrlDigitE2 ctrlSetText "\AGM_Vector\rsc\d-.paa"; +_ctrlDigitE3 ctrlSetText "\AGM_Vector\rsc\dP.paa"; + +waitUntil {!(AGM_vectorKey select 0)}; + +_distanceP2 = call AGM_Vector_fnc_getDistance; +_directionP2 = call AGM_Vector_fnc_getDirection; +_azimuthP2 = _directionP2 select 0; +_inclinationP2 = _directionP2 select 1; + +_relDirection = sqrt ((_azimuthP1 - _azimuthP2)^2 + (_inclinationP1 - _inclinationP2)^2); +_relDistance = sqrt (_distanceP1^2 + _distanceP2^2 - 2 * _distanceP1 * _distanceP2 * cos _relDirection); +_relHeight = (sin _inclinationP1 * _distanceP1) - (sin _inclinationP2 * _distanceP2); +_relLenght = sqrt (_relDistance^2 - _relHeight^2); if (str(_relLenght) == "-1.#IND") then {_relLenght = 0}; + +_lenghtP1 = cos _inclinationP1 * _distanceP1; +_lenghtP2 = cos _inclinationP2 * _distanceP2; +_relAzimuth = (sin _azimuthP2 * _lenghtP2 - sin _azimuthP1 * _lenghtP1) atan2 (cos _azimuthP2 * _lenghtP2 - cos _azimuthP1 * _lenghtP1); +if (_relAzimuth < 0) then {_relAzimuth = _relAzimuth + 360}; + +if (_distanceP1 == -9999 || {_distanceP2 == -9999}) then { + _relDistance = -9999; + _relAzimuth = -9999; +}; + +_digits = _relLenght call AGM_Vector_fnc_convertDistance; +_ctrlDigit1 ctrlSetText (_digits select 0); +_ctrlDigit2 ctrlSetText (_digits select 1); +_ctrlDigit3 ctrlSetText (_digits select 2); +_ctrlDigit4 ctrlSetText (_digits select 3); + +_digits = _relAzimuth call AGM_Vector_fnc_convertDegree; +_ctrlDigit5 ctrlSetText (_digits select 0); +_ctrlDigit6 ctrlSetText (_digits select 1); +_ctrlDigit7 ctrlSetText (_digits select 2); +_ctrlDigit8 ctrlSetText (_digits select 3); + +_ctrlVectorCenter ctrlShow false; + +_ctrlDigitE1 ctrlShow false; +_ctrlDigitE2 ctrlShow false; +_ctrlDigitE3 ctrlShow false; + +AGM_isVectorReady = true; diff --git a/addons/vector/rsc/dp.paa b/addons/vector/rsc/vector_p.paa similarity index 100% rename from addons/vector/rsc/dp.paa rename to addons/vector/rsc/vector_p.paa