From f4a836bee0ca0f9cc2ea0460fd8ea8981b891e8c Mon Sep 17 00:00:00 2001 From: commy2 Date: Sun, 5 Jun 2016 15:42:17 +0200 Subject: [PATCH 1/2] 'CBA_fnc_viewDir', 'CBA_fnc_turretDir' --- addons/common/CfgFunctions.hpp | 2 ++ addons/common/fnc_turretDir.sqf | 52 +++++++++++++++++++++++++++ addons/common/fnc_viewDir.sqf | 56 +++++++++++++++++++++++++++++ addons/common/fnc_viewDir_Linux.sqf | 1 + addons/linux/CfgFunctions.hpp | 4 +++ 5 files changed, 115 insertions(+) create mode 100644 addons/common/fnc_turretDir.sqf create mode 100644 addons/common/fnc_viewDir.sqf create mode 100644 addons/common/fnc_viewDir_Linux.sqf diff --git a/addons/common/CfgFunctions.hpp b/addons/common/CfgFunctions.hpp index d37741af2..505466822 100644 --- a/addons/common/CfgFunctions.hpp +++ b/addons/common/CfgFunctions.hpp @@ -46,6 +46,8 @@ class CfgFunctions { F_FILEPATH(vehicleRole); F_FILEPATH(turretPath); F_FILEPATH(turretPathWeapon); + F_FILEPATH(viewDir); + F_FILEPATH(turretDir); }; class Anims { diff --git a/addons/common/fnc_turretDir.sqf b/addons/common/fnc_turretDir.sqf new file mode 100644 index 000000000..79e037685 --- /dev/null +++ b/addons/common/fnc_turretDir.sqf @@ -0,0 +1,52 @@ +/* ---------------------------------------------------------------------------- +Function: CBA_fnc_turretDir + +Description: + Reports azimuth and inclination of a vehicles turret. + +Parameters: + _vehicle - The Vehicle. + _turret - A Turret. (e.g. [0] for "main turret") + _relativeToModel - false (default): report directions relative to world, true: relative to model + +Returns: + Azimuth + Inclination + 0: _azimuth (0-360 degree) + 1: _inclination (180 to -180 degree, 0: forward) + +Examples: + (begin example) + [vehicle player, [0], true] call CBA_fnc_turretDir + (end) + +Author: + commy2 +---------------------------------------------------------------------------- */ +#include "script_component.hpp" +SCRIPT(turretDir); + +params [["_vehicle", objNull, [objNull]], ["_turret", [-1], [[]]], ["_relativeToModel", false, [false]]]; + +private _turretConfig = [_vehicle, _turret] call CBA_fnc_getTurret; + +private _gunBeg = _vehicle selectionPosition getText (_turretConfig >> "gunBeg"); +private _gunEnd = _vehicle selectionPosition getText (_turretConfig >> "gunEnd"); + +if !(_relativeToModel) then { + _gunBeg = _vehicle modelToWorld _gunBeg; + _gunEnd = _vehicle modelToWorld _gunEnd; +}; + +private _turretDir = _gunEnd vectorFromTo _gunBeg; + +_turretDir params ["_dirX", "_dirY", "_dirZ"]; + +private _azimuth = _dirX atan2 _dirY; + +if (_azimuth < 0) then { + ADD(_azimuth,360); +}; + +private _inclination = asin _dirZ; + +[_azimuth, _inclination] diff --git a/addons/common/fnc_viewDir.sqf b/addons/common/fnc_viewDir.sqf new file mode 100644 index 000000000..6444c9f6b --- /dev/null +++ b/addons/common/fnc_viewDir.sqf @@ -0,0 +1,56 @@ +/* ---------------------------------------------------------------------------- +Function: CBA_fnc_viewDir + +Description: + Reports azimuth and inclination of a units head or weapon direction. + +Parameters: + _vehicle - The Unit or Vehicle. + _weapon - Weapon. (optional, use the weapons direction instead) + +Returns: + Azimuth + Inclination + 0: _azimuth (0-360 degree, 0/360: North, 90: East, 180: South, 270: West) + 1: _inclination (180 to -180 degree, 0: horizontally forward) + +Examples: + (begin example) + player call CBA_fnc_viewDir; + [player, currentWeapon player] call CBA_fnc_viewDir; + [vehicle player, "M2HB"] call CBA_fnc_viewDir; + (end) + +Author: + commy2 +---------------------------------------------------------------------------- */ +#include "script_component.hpp" +SCRIPT(viewDir); + +params [["_vehicle", objNull, [objNull]], ["_weapon", nil, [""]]]; + +private _viewVector = [0,0,0]; + +if (isNil "_weapon") then { + // no weapon mode + if (_vehicle call CBA_fnc_isPerson) then { + // soldiers + _viewVector = getCameraViewDirection _vehicle; + } else { + // vehicles + _viewVector = vectorDir _vehicle; + }; +} else { + _viewVector = _vehicle weaponDirection _weapon; +}; + +_viewVector params ["_dirX", "_dirY", "_dirZ"]; + +private _azimuth = _dirX atan2 _dirY; + +if (_azimuth < 0) then { + ADD(_azimuth,360); +}; + +private _inclination = asin _dirZ; + +[_azimuth, _inclination] diff --git a/addons/common/fnc_viewDir_Linux.sqf b/addons/common/fnc_viewDir_Linux.sqf new file mode 100644 index 000000000..40a8c178f --- /dev/null +++ b/addons/common/fnc_viewDir_Linux.sqf @@ -0,0 +1 @@ +/* empty */ diff --git a/addons/linux/CfgFunctions.hpp b/addons/linux/CfgFunctions.hpp index 659a88b64..30ecb44b2 100644 --- a/addons/linux/CfgFunctions.hpp +++ b/addons/linux/CfgFunctions.hpp @@ -23,6 +23,10 @@ class CfgFunctions { F_FILEPATH(common,addBinocularMagazine); }; + class Ui { + F_FILEPATH(common,viewDir); + }; + class Events { F_FILEPATH(events,addPlayerEventHandler); F_FILEPATH(events,addKeyHandler); From b326623c94d585b209e81aa72281db56c959e69a Mon Sep 17 00:00:00 2001 From: commy2 Date: Wed, 8 Jun 2016 20:39:16 +0200 Subject: [PATCH 2/2] linux version was in wrong category --- addons/linux/CfgFunctions.hpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/addons/linux/CfgFunctions.hpp b/addons/linux/CfgFunctions.hpp index 30ecb44b2..5717bd0da 100644 --- a/addons/linux/CfgFunctions.hpp +++ b/addons/linux/CfgFunctions.hpp @@ -14,6 +14,7 @@ class CfgFunctions { F_FILEPATH(common,vehicleRole); F_FILEPATH(common,turretPath); F_FILEPATH(common,turretPathWeapon); + F_FILEPATH(common,viewDir); }; class Inventory { @@ -23,10 +24,6 @@ class CfgFunctions { F_FILEPATH(common,addBinocularMagazine); }; - class Ui { - F_FILEPATH(common,viewDir); - }; - class Events { F_FILEPATH(events,addPlayerEventHandler); F_FILEPATH(events,addKeyHandler);