Fix BIS_fnc_lerp causing crash in 3rd person spectator (#5844)

* Fix BIS_fnc_lerp causing crash in 3rd person spectator
* Clarify spectator 3PP camera distance code
This commit is contained in:
PabstMirror 2017-12-03 10:10:48 -06:00 committed by SilentSpike
parent 0d69f6ac67
commit 82aa953e66
2 changed files with 12 additions and 8 deletions

View File

@ -39,7 +39,7 @@ if (_init) then {
// Follow camera related // Follow camera related
GVAR(camDistance) = 0; GVAR(camDistance) = 0;
GVAR(camDistanceTemp) = 0; GVAR(camDistanceTrue) = 0;
GVAR(camYaw) = 0; GVAR(camYaw) = 0;
GVAR(camPitch) = 0; GVAR(camPitch) = 0;
@ -133,7 +133,7 @@ if (_init) then {
GVAR(camHasTarget) = nil; GVAR(camHasTarget) = nil;
GVAR(camTargetInVehicle) = nil; GVAR(camTargetInVehicle) = nil;
GVAR(camDistance) = nil; GVAR(camDistance) = nil;
GVAR(camDistanceTemp) = nil; GVAR(camDistanceTrue) = nil;
GVAR(camYaw) = nil; GVAR(camYaw) = nil;
GVAR(camPitch) = nil; GVAR(camPitch) = nil;
GVAR(camSlow) = nil; GVAR(camSlow) = nil;

View File

@ -18,20 +18,24 @@
#include "script_component.hpp" #include "script_component.hpp"
private _focus = vehicle (param [0, objNull, [objNull]]); private _focus = vehicle (param [0, objNull, [objNull]]);
TRACE_1("cam_prepareTarget",_focus);
if !(isNull _focus) then { if !(isNull _focus) then {
// Interpolate zoom // Zooming takes place smoothly over multiple frames
// _zoom is target set by user, _zoomTrue is actual value each frame
private _zoom = [0, GVAR(camDistance)] select (GVAR(camMode) == MODE_FOLLOW); private _zoom = [0, GVAR(camDistance)] select (GVAR(camMode) == MODE_FOLLOW);
private _zoomTemp = GVAR(camDistanceTemp); private _zoomTrue = GVAR(camDistanceTrue);
if (_zoomTemp != _zoom) then { // Interpolate zoom each frame until desired zoom is reached
_zoomTemp = [_zoomTemp, _zoom, 10, GVAR(camDeltaTime)] call BIS_fnc_lerp; if (_zoomTrue != _zoom) then {
GVAR(camDistanceTemp) = _zoomTemp; _zoomTrue = (_zoomTrue * (1 - GVAR(camDeltaTime) * 10)) + (_zoom * GVAR(camDeltaTime) * 10);
GVAR(camDistanceTrue) = _zoomTrue;
TRACE_2("new zoom",GVAR(camDeltaTime),_zoomTrue);
}; };
// The distance at which to place camera from the focus pivot // The distance at which to place camera from the focus pivot
private _bbd = [_focus] call BIS_fnc_getObjectBBD; private _bbd = [_focus] call BIS_fnc_getObjectBBD;
private _distance = (_bbd select 1) + _zoomTemp; private _distance = (_bbd select 1) + _zoomTrue;
// The pivot on the target vehicle // The pivot on the target vehicle
private _isMan = _focus isKindOf "Man"; private _isMan = _focus isKindOf "Man";