2015-07-16 16:01:04 +00:00
|
|
|
/*
|
2015-07-17 15:45:16 +00:00
|
|
|
* Author: F3 Project, Head, SilentSpike
|
2015-07-18 15:59:05 +00:00
|
|
|
* Handles free camera manipulation according to input
|
2015-07-16 16:01:04 +00:00
|
|
|
*
|
|
|
|
* Arguments:
|
2015-07-19 01:25:52 +00:00
|
|
|
* 0: Parameters <ANY>
|
|
|
|
* 1: PFH handle <NUMBER>
|
2015-07-16 16:01:04 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* None <NIL>
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* [ace_spectator_fnc_handleCamera, 0] call CBA_fnc_addPerFrameHandler;
|
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
|
|
|
|
2015-07-15 11:11:19 +00:00
|
|
|
#include "script_component.hpp"
|
|
|
|
|
2015-07-18 15:59:05 +00:00
|
|
|
// Kill PFH when not in free cam (or display is closed)
|
2015-07-18 16:06:13 +00:00
|
|
|
if (isNil QGVAR(camHandler)) exitWith { [_this select 1] call CBA_fnc_removePerFrameHandler; };
|
2015-07-15 13:33:11 +00:00
|
|
|
|
2015-09-11 12:44:44 +00:00
|
|
|
private ["_camera","_pan","_tilt"];
|
2015-07-18 17:46:46 +00:00
|
|
|
|
2015-09-09 22:21:49 +00:00
|
|
|
_pan = (GVAR(camPan) + 360) % 360;
|
|
|
|
_tilt = GVAR(camTilt);
|
2015-08-08 17:41:38 +00:00
|
|
|
|
2015-09-09 22:21:49 +00:00
|
|
|
if (GVAR(camMode) == 0) then {
|
2015-09-11 12:44:44 +00:00
|
|
|
private ["_oldPos","_altMod","_zoomMod","_mX","_mY","_mZ","_x","_y","_z"];
|
2015-09-09 22:21:49 +00:00
|
|
|
_camera = GVAR(freeCamera);
|
|
|
|
_oldPos = GVAR(camPos);
|
2015-08-29 15:03:43 +00:00
|
|
|
|
2015-09-09 22:21:49 +00:00
|
|
|
// Dolly/Boom amount should be influnced by zoom level (it should really be exponential)
|
|
|
|
// Dollying should also slow as the camera gets close to the ground
|
|
|
|
_zoomMod = (GVAR(camZoom) * 0.8) max 1;
|
|
|
|
_altMod = ((((getPos _camera) select 2) * 0.05) max 0.1) min 1;
|
2015-07-15 11:11:19 +00:00
|
|
|
|
2015-09-09 22:21:49 +00:00
|
|
|
_mX = (GVAR(camDolly) select 0) * _altMod / _zoomMod;
|
|
|
|
_mY = (GVAR(camDolly) select 1) * _altMod / _zoomMod;
|
|
|
|
_mZ = GVAR(camBoom) / _zoomMod;
|
|
|
|
|
|
|
|
_x = (_oldPos select 0) + (_mX * cos(_pan)) + (_mY * sin(_pan));
|
|
|
|
_y = (_oldPos select 1) - (_mX * sin(_pan)) + (_mY * cos(_pan));
|
|
|
|
_z = (_oldPos select 2) + _mZ;
|
|
|
|
|
|
|
|
// Prevent camera going under terrain
|
|
|
|
GVAR(camPos) = [_x,_y,_z max (getTerrainHeightASL [_x,_y])];
|
|
|
|
|
|
|
|
// Update camera position and rotation
|
|
|
|
_camera setPosASL GVAR(camPos);
|
|
|
|
_camera setDir _pan;
|
|
|
|
[_camera, _tilt, 0] call BIS_fnc_setPitchBank;
|
|
|
|
} else {
|
2015-09-11 12:44:44 +00:00
|
|
|
private ["_unit","_target","_distance","_vector"];
|
2015-09-09 22:21:49 +00:00
|
|
|
_camera = GVAR(unitCamera);
|
|
|
|
|
|
|
|
_unit = GVAR(camUnit);
|
|
|
|
_target = GVAR(targetCamera);
|
|
|
|
_distance = GVAR(camDistance);
|
|
|
|
|
2015-09-11 12:44:44 +00:00
|
|
|
// Generate a position vector relative to the unit
|
|
|
|
_vector = [0,-_distance*cos(_tilt),0];
|
|
|
|
_vector = [_vector,[-_pan] call CBA_fnc_simplifyAngle180] call BIS_fnc_rotateVector2D;
|
|
|
|
_vector = _vector vectorAdd [0,0,_distance*sin(-_tilt)];
|
2015-07-15 11:11:19 +00:00
|
|
|
|
2015-09-09 22:21:49 +00:00
|
|
|
// Update the position of the target camera (used for smooth unit tracking)
|
2018-01-17 11:36:10 +00:00
|
|
|
_target camSetPos ((_unit modelToWorldVisual [0,0,0]) vectorAdd [0,0,1.5]);
|
2015-12-21 16:05:48 +00:00
|
|
|
_target camCommit 0;
|
2015-07-15 11:33:32 +00:00
|
|
|
|
2015-09-09 22:21:49 +00:00
|
|
|
// Update the relative position of the unit camera
|
2015-09-11 12:44:44 +00:00
|
|
|
_camera camSetRelPos _vector;
|
2015-09-09 22:21:49 +00:00
|
|
|
_camera camCommit 0;
|
2015-09-11 12:44:44 +00:00
|
|
|
|
|
|
|
GVAR(camPos) = getPosASL _camera;
|
2015-09-09 22:21:49 +00:00
|
|
|
};
|