fn_createUavCam.sqf 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. Name: cTab_fnc_createUavCam
  3. Author(s):
  4. Gundy
  5. Description:
  6. Set up UAV camera and display on supplied render target
  7. Modified to include lessons learned from KK's excellent tutorial: http://killzonekid.com/arma-scripting-tutorials-uav-r2t-and-pip/
  8. Parameters:
  9. 0: STRING - Name of UAV (format used from `str uavObject`)
  10. 1: ARRAY - List of arrays with seats with render targets
  11. 0: INTEGER - Seat
  12. 0 = DRIVER
  13. 1 = GUNNER
  14. 1: STRING - Name of render target
  15. Returns:
  16. BOOLEAN - If UAV cam could be set up or not
  17. Example:
  18. [str _uavVehicle,[[0,"rendertarget8"],[1,"rendertarget9"]]] call cTab_fnc_createUavCam;
  19. */
  20. private ["_renderTarget","_data","_seat","_uav","_uavCams","_seatName","_camPosMemPt","_camDirMemPt","_cam"];
  21. _uav = objNull;
  22. _data = _this select 0;
  23. // see if given UAV name is still in the list of valid UAVs
  24. {
  25. if (_data == str _x) exitWith {_uav = _x;};
  26. } count cTabUAVlist;
  27. // remove exisitng UAV cameras
  28. [] call cTab_fnc_deleteUAVcam;
  29. // exit if requested UAV could not be found
  30. if (isNull _uav) exitWith {false};
  31. // exit if requested UAV is not alive
  32. if (!alive _uav) exitWith {false};
  33. _uavCams = _this select 1;
  34. {
  35. _seat = _x select 0;
  36. _renderTarget = _x select 1;
  37. // check existing cameras
  38. _cam = objNull;
  39. _camPosMemPt = "";
  40. _camDirMemPt = "";
  41. _seatName = call {
  42. if (_seat == 0) exitWith {"Driver"};
  43. if (_seat == 1) exitWith {"Gunner"};
  44. ""
  45. };
  46. if (_seatName != "") then {
  47. // retrieve memory point names from vehicle config
  48. _camPosMemPt = getText (configFile >> "CfgVehicles" >> typeOf _uav >> "uavCamera" + _seatName + "Pos");
  49. _camDirMemPt = getText (configFile >> "CfgVehicles" >> typeOf _uav >> "uavCamera" + _seatName + "Dir");
  50. };
  51. // If memory points could be retrieved, create camera
  52. if ((_camPosMemPt != "") && (_camDirMemPt != "")) then {
  53. _cam = "camera" camCreate [0,0,0];
  54. _cam attachTo [_uav,[0,0,0],_camPosMemPt];
  55. // set up cam on render target
  56. _cam cameraEffect ["INTERNAL","BACK",_renderTarget];
  57. call {
  58. if (_seat == 1) exitWith {
  59. _renderTarget setPiPEffect [2]; // IR mode
  60. _cam camSetFov 0.1; // set zoom
  61. };
  62. _cam camSetFov 0.5; // set default zoom
  63. };
  64. 0 = cTabUAVcams pushBack [_uav,_renderTarget,_cam,_camPosMemPt,_camDirMemPt];
  65. };
  66. } count _uavCams;
  67. // set up event handler
  68. if !(cTabUAVcams isEqualTo []) exitWith {
  69. if (isNil "cTabUavEventHandle") then {
  70. cTabUavEventHandle = addMissionEventHandler ["Draw3D",{
  71. {
  72. if !(isNil "_x") then {
  73. _uav = _x select 0;
  74. _cam = _x select 2;
  75. if (alive _uav) then {
  76. _dir = (_uav selectionPosition (_x select 3)) vectorFromTo (_uav selectionPosition (_x select 4));
  77. _cam setVectorDirAndUp [_dir,_dir vectorCrossProduct [-(_dir select 1), _dir select 0, 0]];
  78. } else {
  79. [_cam] call cTab_fnc_deleteUAVcam;
  80. };
  81. };
  82. } count cTabUAVcams;
  83. }];
  84. };
  85. cTabActUav = _uav;
  86. true
  87. };
  88. false