fn_createHelmetCam.sqf 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. Name: cTab_fnc_createHelmetCam
  3. Author(s):
  4. Gundy, Riouken
  5. Description:
  6. Set up helmet camera and display on supplied render target
  7. Parameters:
  8. 0: STRING - Render target
  9. 1: STRING - Name of unit with helmet camera (format used from `str unitObject`)
  10. Returns:
  11. BOOLEAN - If helmet cam could be set up or not
  12. Example:
  13. ["rendertarget12",str player] spawn cTab_fnc_createHelmetCam;
  14. */
  15. private ["_renderTarget","_data","_newHost","_camOffSet","_targetOffSet","_oldCam","_oldHost","_nop","_target","_cam"];
  16. _renderTarget = _this select 0;
  17. _data = _this select 1;
  18. _newHost = objNull;
  19. _camOffSet = [];
  20. _targetOffSet = [];
  21. // see if given unit name is still in the list of units with valid helmet cams
  22. {
  23. if (_data == str _x) exitWith {_newHost = _x;};
  24. } count cTabHcamlist;
  25. call {
  26. // should unit not be in a vehicle
  27. if (vehicle _newHost isKindOf "CAManBase") exitWith {
  28. _camOffSet = [0.12,0,0.15];
  29. _targetOffSet = [0,8,1];
  30. };
  31. // if unit is in a vehilce, see if 3rd person view is allowed
  32. if (difficultyEnabled "3rdPersonView") exitWith {
  33. _newHost = vehicle _newHost;
  34. // Might want to calculate offsets based on the actual vehicle dimensions in the future
  35. _camOffSet = [0,-8,4];
  36. _targetOffSet = [0,8,2];
  37. };
  38. // if unit is in a vehicle and 3rd person view is not allowed
  39. _newHost = objNull;
  40. };
  41. // if there is no valid unit or we are not allowed to set up a helmet cam in these conditions, drop out of full screen view
  42. if (IsNull _newHost) exitWith {
  43. ["cTab_Tablet_dlg",[["mode","HCAM"]]] call cTab_fnc_setSettings;
  44. false
  45. };
  46. // if there is already a camera, see if its the same one we are about to set up
  47. // if true, render to given target (in case the target has changed), else delete the camera so we can create a new one
  48. if (!isNil "cTabHcams") then {
  49. _oldCam = cTabHcams select 0;
  50. _oldHost = cTabHcams select 2;
  51. if (_oldHost isEqualTo _newHost) then {
  52. _oldCam cameraEffect ["INTERNAL","BACK",_renderTarget];
  53. } else {
  54. _nop = [] call cTab_fnc_deleteHelmetCam;
  55. waitUntil {_nop};
  56. };
  57. };
  58. // only continue if there is no helmet cam currently set up
  59. if (!isNil "cTabHcams") exitWith {true};
  60. _target = "Sign_Sphere10cm_F" createVehicleLocal position player;
  61. hideObject _target;
  62. _target attachTo [_newHost,_targetOffSet];
  63. _cam = "camera" camCreate getPosATL _newHost;
  64. _cam camPrepareFov 0.700;
  65. _cam camPrepareTarget _target;
  66. _cam camCommitPrepared 0;
  67. if (vehicle _newHost == _newHost) then {
  68. _cam attachTo [_newHost,_camOffSet,"Head"];
  69. } else {
  70. _cam attachTo [_newHost,_camOffSet];
  71. };
  72. _cam cameraEffect ["INTERNAL","BACK",_renderTarget];
  73. cTabHcams = [_cam,_target,_newHost];
  74. true