Advertisement
BobTheHunted

relative_rotation.sqf

Sep 24th, 2018
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQF 2.33 KB | None | 0 0
  1. // nul = [[object array], [pitch, bank, yaw], height] execVM "relative_rotation.sqf"
  2. // example: [[obj1, obj2], [90, 0, 0], 0] execVM "relative_rotation.sqf";
  3.  
  4. private _InputObjects = _this select 0;
  5. private _PitchAmount  = (_this select 1) select 0;
  6. private _BankAmount   = (_this select 1) select 1;
  7. private _YawAmount    = (_this select 1) select 2;
  8. private _AdjustHeight = _this select 2;
  9.  
  10. // https://community.bistudio.com/wiki/BIS_fnc_setPitchBank ffur2007slx2_5
  11. fnc_SetPitchBankYaw =
  12. {
  13.     private ["_object","_rotations","_aroundX","_aroundY","_aroundZ","_dirX","_dirY","_dirZ","_upX","_upY","_upZ","_dir","_up","_dirXTemp",
  14.     "_upXTemp"];
  15.     _object = _this select 0;
  16.     _rotations = _this select 1;
  17.     _aroundX = _rotations select 0;
  18.     _aroundY = _rotations select 1;
  19.     _aroundZ = (360 - (_rotations select 2)) - 360;
  20.     _dirX = 0;
  21.     _dirY = 1;
  22.     _dirZ = 0;
  23.     _upX = 0;
  24.     _upY = 0;
  25.     _upZ = 1;
  26.     if (_aroundX != 0) then {
  27.         _dirY = cos _aroundX;
  28.         _dirZ = sin _aroundX;
  29.         _upY = -sin _aroundX;
  30.         _upZ = cos _aroundX;
  31.     };
  32.     if (_aroundY != 0) then {
  33.         _dirX = _dirZ * sin _aroundY;
  34.         _dirZ = _dirZ * cos _aroundY;
  35.         _upX = _upZ * sin _aroundY;
  36.         _upZ = _upZ * cos _aroundY;
  37.     };
  38.     if (_aroundZ != 0) then {
  39.         _dirXTemp = _dirX;
  40.         _dirX = (_dirXTemp* cos _aroundZ) - (_dirY * sin _aroundZ);
  41.         _dirY = (_dirY * cos _aroundZ) + (_dirXTemp * sin _aroundZ);        
  42.         _upXTemp = _upX;
  43.         _upX = (_upXTemp * cos _aroundZ) - (_upY * sin _aroundZ);
  44.         _upY = (_upY * cos _aroundZ) + (_upXTemp * sin _aroundZ);      
  45.     };
  46.     _dir = [_dirX,_dirY,_dirZ];
  47.     _up = [_upX,_upY,_upZ];
  48.     _object setVectorDirAndUp [_dir,_up];
  49. };
  50.  
  51. {
  52.     private _pos = position _x;
  53.     private _pinObj = "Sign_Arrow_Large_Blue_F" createVehicle position _x;
  54.     _pinObj setDir getDir _x;
  55.     _pinObj setPos position _x;
  56.     _pinObj setVectorDir vectorDir _x;
  57.     _pinObj setVectorUp vectorUp _x;
  58.     _x setPos [_pos select 0, _pos select 1, (_pos select 2) + _AdjustHeight];
  59.     private _attached = [_x, _pinObj] call BIS_fnc_attachToRelative;
  60.     private _adjusted = [_x, [_PitchAmount, _BankAmount, _YawAmount]] call fnc_SetPitchBankYaw;
  61.     sleep 1;
  62.     detach _x;
  63.     deleteVehicle _pinObj;
  64. } forEach _InputObjects;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement