Skip to content

Commit

Permalink
Merge pull request #372 from CBATeam/add_viewDir_and_turretDir
Browse files Browse the repository at this point in the history
add 'CBA_fnc_viewDir', 'CBA_fnc_turretDir'
  • Loading branch information
Killswitch00 committed Jun 10, 2016
2 parents f5f9462 + b326623 commit 5fb56b2
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 0 deletions.
2 changes: 2 additions & 0 deletions addons/common/CfgFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class CfgFunctions {
F_FILEPATH(vehicleRole);
F_FILEPATH(turretPath);
F_FILEPATH(turretPathWeapon);
F_FILEPATH(viewDir);
F_FILEPATH(turretDir);
};

class Anims {
Expand Down
52 changes: 52 additions & 0 deletions addons/common/fnc_turretDir.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/* ----------------------------------------------------------------------------
Function: CBA_fnc_turretDir
Description:
Reports azimuth and inclination of a vehicles turret.
Parameters:
_vehicle - The Vehicle. <OBJECT>
_turret - A Turret. (e.g. [0] for "main turret") <ARRAY>
_relativeToModel - false (default): report directions relative to world, true: relative to model <BOOLEAN>
Returns:
Azimuth + Inclination <ARRAY>
0: _azimuth (0-360 degree) <NUMBER>
1: _inclination (180 to -180 degree, 0: forward) <NUMBER>
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]
56 changes: 56 additions & 0 deletions addons/common/fnc_viewDir.sqf
Original file line number Diff line number Diff line change
@@ -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. <OBJECT>
_weapon - Weapon. (optional, use the weapons direction instead) <STRING>
Returns:
Azimuth + Inclination <ARRAY>
0: _azimuth (0-360 degree, 0/360: North, 90: East, 180: South, 270: West) <NUMBER>
1: _inclination (180 to -180 degree, 0: horizontally forward) <NUMBER>
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]
1 change: 1 addition & 0 deletions addons/common/fnc_viewDir_Linux.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* empty */
1 change: 1 addition & 0 deletions addons/linux/CfgFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class CfgFunctions {
F_FILEPATH(common,vehicleRole);
F_FILEPATH(common,turretPath);
F_FILEPATH(common,turretPathWeapon);
F_FILEPATH(common,viewDir);
};

class Inventory {
Expand Down

0 comments on commit 5fb56b2

Please sign in to comment.