Improve angular behaviour of spectator camera

Changes the position calculation of the external spectator camera to correctly retain the pan and tilt of the free camera. Makes transitioning between the two less disorienting for the user.
This commit is contained in:
SilentSpike 2015-09-11 13:44:44 +01:00
parent 77c2b99ee5
commit aa7b6cf39f

View File

@ -20,13 +20,13 @@
// Kill PFH when not in free cam (or display is closed) // Kill PFH when not in free cam (or display is closed)
if (isNil QGVAR(camHandler)) exitWith { [_this select 1] call CBA_fnc_removePerFrameHandler; }; if (isNil QGVAR(camHandler)) exitWith { [_this select 1] call CBA_fnc_removePerFrameHandler; };
private ["_camera","_pan","_tilt","_x","_y","_z"]; private ["_camera","_pan","_tilt"];
_pan = (GVAR(camPan) + 360) % 360; _pan = (GVAR(camPan) + 360) % 360;
_tilt = GVAR(camTilt); _tilt = GVAR(camTilt);
if (GVAR(camMode) == 0) then { if (GVAR(camMode) == 0) then {
private ["_oldPos","_altMod","_zoomMod","_mX","_mY","_mZ"]; private ["_oldPos","_altMod","_zoomMod","_mX","_mY","_mZ","_x","_y","_z"];
_camera = GVAR(freeCamera); _camera = GVAR(freeCamera);
_oldPos = GVAR(camPos); _oldPos = GVAR(camPos);
@ -51,22 +51,25 @@ if (GVAR(camMode) == 0) then {
_camera setDir _pan; _camera setDir _pan;
[_camera, _tilt, 0] call BIS_fnc_setPitchBank; [_camera, _tilt, 0] call BIS_fnc_setPitchBank;
} else { } else {
private ["_unit","_target","_distance"]; private ["_unit","_target","_distance","_vector"];
_camera = GVAR(unitCamera); _camera = GVAR(unitCamera);
_unit = GVAR(camUnit); _unit = GVAR(camUnit);
_target = GVAR(targetCamera); _target = GVAR(targetCamera);
_distance = GVAR(camDistance); _distance = GVAR(camDistance);
_x = sin(_pan)*_distance*cos(_tilt); // Generate a position vector relative to the unit
_y = cos(_pan)*_distance*cos(_tilt); _vector = [0,-_distance*cos(_tilt),0];
_z = sin(_tilt) * (2 * (0.3 max _distance)); _vector = [_vector,[-_pan] call CBA_fnc_simplifyAngle180] call BIS_fnc_rotateVector2D;
_vector = _vector vectorAdd [0,0,_distance*sin(-_tilt)];
// Update the position of the target camera (used for smooth unit tracking) // Update the position of the target camera (used for smooth unit tracking)
_target camSetPos ((_unit modelToWorldVisual [0,0,0]) vectorAdd [0,0,1.5]); _target camSetPos ((_unit modelToWorldVisual [0,0,0]) vectorAdd [0,0,1.5]);
_target camCommit 0; _target camCommit 0;
// Update the relative position of the unit camera // Update the relative position of the unit camera
_camera camSetRelPos [_x, _y, _z]; _camera camSetRelPos _vector;
_camera camCommit 0; _camera camCommit 0;
GVAR(camPos) = getPosASL _camera;
}; };