-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #372 from CBATeam/add_viewDir_and_turretDir
add 'CBA_fnc_viewDir', 'CBA_fnc_turretDir'
- Loading branch information
Showing
5 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/* empty */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters