Skip to content

Commit

Permalink
rotate scripted optic according to weapon bank (#1162)
Browse files Browse the repository at this point in the history
* rotate scripted optic according to weapon bank

* handle launchers, pistols

* update variable names
  • Loading branch information
commy2 committed Jun 15, 2019
1 parent 0bd78ee commit cd8a239
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions addons/optics/XEH_PREP.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ PREP(changeCarryHandleOpticClass);
PREP(setOpticMagnification);
PREP(setOpticMagnificationHelper);
PREP(setOpticMagnificationHelperZeroing);
PREP(gunBank);
5 changes: 5 additions & 0 deletions addons/optics/fnc_animateScriptedOptic.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ _ctrlBody ctrlSetTextColor [1,1,1,_dayOpacity];
_ctrlBodyNight ctrlSetTextColor [1,1,1,_nightOpacity];
_ctrlBlackScope ctrlShow (GVAR(usePipOptics) && !isPipEnabled);

private _bank = call FUNC(gunBank);
_ctrlReticle ctrlSetAngle [_bank, 0.5, 0.5];
_ctrlBody ctrlSetAngle [_bank, 0.5, 0.5];
_ctrlBodyNight ctrlSetAngle [_bank, 0.5, 0.5];

// zooming reticle
if (isNull (_display displayCtrl IDC_ENABLE_ZOOM)) exitWith {};

Expand Down
35 changes: 35 additions & 0 deletions addons/optics/fnc_gunBank.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "script_component.hpp"
/* ----------------------------------------------------------------------------
Internal Function: cba_optics_fnc_gunBank
Description:
Reports the bank at which the primary weapon is tilted.
Parameters:
None.
Returns:
Leaning angle of avatar.
Examples:
(begin example)
call cba_optics_fnc_gunBank;
(end)
Author:
commy2
---------------------------------------------------------------------------- */

private _unit = [] call CBA_fnc_currentUnit;

private _pelvis = _unit modelToWorldVisualWorld (_unit selectionPosition "Pelvis");
private _camera = _unit modelToWorldVisualWorld (_unit selectionPosition "camera");
private _bodyUp = _pelvis vectorFromTo _camera;

private _weaponDir = _unit weaponDirection currentWeapon _unit;
private _weaponLat = vectorNormalized (_weaponDir vectorCrossProduct _bodyUp);
private _weaponUp = _weaponLat vectorCrossProduct _weaponDir;

private _screenRight = AGLToASL positionCameraToWorld [0,0,0] vectorFromTo AGLToASL positionCameraToWorld [1,0,0];

90 - acos (_screenRight vectorCos _weaponUp) // return

0 comments on commit cd8a239

Please sign in to comment.