2023-09-12 18:58:10 +00:00
|
|
|
#include "..\script_component.hpp"
|
2017-08-12 13:25:48 +00:00
|
|
|
/*
|
2023-08-17 10:02:17 +00:00
|
|
|
* Author: Nelson Duarte, kymckay
|
2017-08-12 13:25:48 +00:00
|
|
|
* Handles camera initialisation and destruction
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* 0: Init/Terminate <BOOL>
|
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* [true] call ace_spectator_fnc_cam
|
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
|
|
|
|
|
|
|
params ["_init"];
|
2017-11-04 16:03:51 +00:00
|
|
|
TRACE_1("cam",_init);
|
2017-08-12 13:25:48 +00:00
|
|
|
|
|
|
|
// No change
|
|
|
|
if (_init isEqualTo !isNil QGVAR(camera)) exitWith {};
|
|
|
|
|
|
|
|
// Note that init and destroy intentionally happen in reverse order
|
|
|
|
// Init: Vars > Camera > Camera Stuff
|
|
|
|
// Destroy: Camera Stuff > Camera > Vars
|
|
|
|
if (_init) then {
|
|
|
|
// Start tracking camera attributes if not pre-set by public function
|
|
|
|
ISNILS(GVAR(camMode),MODE_FREE);
|
|
|
|
ISNILS(GVAR(camVision),VISION_NORM);
|
2017-08-30 15:36:53 +00:00
|
|
|
ISNILS(GVAR(camFocus),objNull);
|
2017-08-12 13:25:48 +00:00
|
|
|
|
|
|
|
// Ticking related
|
|
|
|
GVAR(camDeltaTime) = 0;
|
|
|
|
GVAR(camLastTickTime) = 0;
|
|
|
|
GVAR(camHasTarget) = false;
|
|
|
|
GVAR(camTargetInVehicle) = false;
|
|
|
|
|
|
|
|
// Follow camera related
|
|
|
|
GVAR(camDistance) = 0;
|
2017-12-03 16:10:48 +00:00
|
|
|
GVAR(camDistanceTrue) = 0;
|
2017-08-12 13:25:48 +00:00
|
|
|
GVAR(camYaw) = 0;
|
|
|
|
GVAR(camPitch) = 0;
|
|
|
|
|
|
|
|
// Toggles
|
|
|
|
GVAR(camSlow) = false;
|
|
|
|
GVAR(camLights) = [];
|
|
|
|
GVAR(camLight) = false;
|
|
|
|
|
|
|
|
// Handle pre-set pos and dir (delete GVARs when done)
|
|
|
|
private _pos = if (isNil QGVAR(camPos)) then {eyePos player} else {GVAR(camPos)};
|
|
|
|
private _dir = if (isNil QGVAR(camDir)) then {getDirVisual player} else {GVAR(camDir)};
|
|
|
|
GVAR(camPos) = nil;
|
|
|
|
GVAR(camDir) = nil;
|
|
|
|
|
|
|
|
// Create the camera (CamCurator required for engine driven controls)
|
|
|
|
private _camera = "CamCurator" camCreate _pos;
|
|
|
|
|
|
|
|
if (isNull _camera) exitWith { ERROR("Camera wasn't created successfully"); };
|
|
|
|
|
|
|
|
// Switch to the camera and set its attributes
|
|
|
|
_camera cameraEffect ["internal", "back"];
|
|
|
|
_camera setPosASL _pos;
|
|
|
|
_camera setDir _dir;
|
|
|
|
_camera camCommand "maxPitch 89";
|
|
|
|
_camera camCommand "minPitch -89";
|
|
|
|
_camera camCommand format ["speedDefault %1", SPEED_DEFAULT];
|
|
|
|
_camera camCommand format ["speedMax %1", SPEED_FAST];
|
|
|
|
_camera camCommand "ceilingHeight 5000";
|
|
|
|
cameraEffectEnableHUD true;
|
|
|
|
|
|
|
|
// If camera followed terrain it would be annoying to track units, etc.
|
|
|
|
_camera camCommand "atl off";
|
|
|
|
|
|
|
|
// Camera speed should be consistent irrespective of height (painfully slow otherwise)
|
|
|
|
_camera camCommand "surfaceSpeed off";
|
|
|
|
|
|
|
|
// Store camera
|
|
|
|
GVAR(camera) = _camera;
|
|
|
|
|
2017-12-07 21:45:30 +00:00
|
|
|
// Create agent used to fix draw3D in free camera for case where player is perma-dead
|
|
|
|
GVAR(camAgentFree) = createAgent [QGVAR(virtual), [0,0,0], [], 0, "NONE"];
|
|
|
|
GVAR(camAgentFree) enableSimulation false; // Prevent falling into water
|
|
|
|
|
2017-08-12 13:25:48 +00:00
|
|
|
// Create dummy target used for follow camera
|
2017-08-30 15:36:53 +00:00
|
|
|
GVAR(camDummy) = "Logic" createVehicleLocal getPosASLVisual GVAR(camFocus);
|
2017-08-12 13:25:48 +00:00
|
|
|
|
|
|
|
// Handle initial camera mode limitation
|
|
|
|
if !(GVAR(camMode) in GVAR(availableModes)) then {
|
|
|
|
GVAR(camMode) = GVAR(availableModes) select 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
// If inital camera mode is not free cam and no focus, find initial focus
|
2017-08-30 15:36:53 +00:00
|
|
|
if (GVAR(camMode) != MODE_FREE && isNull GVAR(camFocus)) then {
|
2017-08-12 13:25:48 +00:00
|
|
|
[true] call FUNC(setFocus);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Set the initial camera mode (could be pre-set or limited)
|
|
|
|
[GVAR(camMode)] call FUNC(cam_setCameraMode);
|
|
|
|
|
|
|
|
// Handle initial vision mode limitation
|
|
|
|
if !(GVAR(camVision) in GVAR(availableVisions)) then {
|
|
|
|
GVAR(camVision) = GVAR(availableVisions) select 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Set the initial vision mode (could be pre-set or limited)
|
|
|
|
[GVAR(camVision)] call FUNC(cam_setVisionMode);
|
|
|
|
|
|
|
|
// Start ticking (follow camera requires EachFrame to avoid jitter)
|
|
|
|
GVAR(camTick) = addMissionEventHandler ["EachFrame", {call FUNC(cam_tick)}];
|
|
|
|
} else {
|
|
|
|
// Stop ticking
|
|
|
|
removeMissionEventHandler ["EachFrame", GVAR(camTick)];
|
|
|
|
GVAR(camTick) = nil;
|
|
|
|
|
|
|
|
// Return to player view
|
|
|
|
if !(isNull GVAR(camera)) then {
|
|
|
|
GVAR(camera) cameraEffect ["terminate", "back"];
|
|
|
|
deleteVehicle GVAR(camera);
|
|
|
|
};
|
|
|
|
player switchCamera "internal";
|
|
|
|
|
|
|
|
// Remove camera variable
|
|
|
|
GVAR(camera) = nil;
|
|
|
|
|
2017-12-07 21:45:30 +00:00
|
|
|
// Destroy free camera agent
|
|
|
|
deleteVehicle GVAR(camAgentFree);
|
|
|
|
GVAR(camAgentFree) = nil;
|
|
|
|
|
2017-08-12 13:25:48 +00:00
|
|
|
// Destroy dummy target
|
2017-12-07 21:45:30 +00:00
|
|
|
deleteVehicle GVAR(camDummy);
|
2017-08-12 13:25:48 +00:00
|
|
|
GVAR(camDummy) = nil;
|
|
|
|
|
|
|
|
// Stop tracking everything
|
2024-07-17 08:42:37 +00:00
|
|
|
{ deleteVehicle _x; } forEach GVAR(camLights);
|
|
|
|
GVAR(camLights) = nil;
|
|
|
|
|
2017-08-12 13:25:48 +00:00
|
|
|
GVAR(camMode) = nil;
|
|
|
|
GVAR(camVision) = nil;
|
2017-08-30 15:36:53 +00:00
|
|
|
GVAR(camFocus) = nil;
|
2017-08-12 13:25:48 +00:00
|
|
|
GVAR(camDeltaTime) = nil;
|
|
|
|
GVAR(camLastTickTime) = nil;
|
|
|
|
GVAR(camHasTarget) = nil;
|
|
|
|
GVAR(camTargetInVehicle) = nil;
|
|
|
|
GVAR(camDistance) = nil;
|
2017-12-03 16:10:48 +00:00
|
|
|
GVAR(camDistanceTrue) = nil;
|
2017-08-12 13:25:48 +00:00
|
|
|
GVAR(camYaw) = nil;
|
|
|
|
GVAR(camPitch) = nil;
|
|
|
|
GVAR(camSlow) = nil;
|
|
|
|
GVAR(camLight) = nil;
|
|
|
|
};
|