Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rotate scripted optic according to weapon bank #1162

Merged
merged 4 commits into from
Jun 15, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 _aim = _unit modelToWorldVisualWorld (_unit selectionPosition "Pelvis");
private _cam = _unit modelToWorldVisualWorld (_unit selectionPosition "camera");
private _up = _aim vectorFromTo _cam;

private _wDir = _unit weaponDirection primaryWeapon _unit;
private _wLat = vectorNormalized (_wDir vectorCrossProduct _up);
private _wUp = _wLat vectorCrossProduct _wDir;

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

90 - acos (_right vectorCos _wUp) // return