Skip to content

Commit

Permalink
Fix BIS_fnc_lerp causing crash in 3rd person spectator (#5844)
Browse files Browse the repository at this point in the history
* Fix BIS_fnc_lerp causing crash in 3rd person spectator
* Clarify spectator 3PP camera distance code
  • Loading branch information
PabstMirror authored and kymckay committed Dec 3, 2017
1 parent 410e669 commit 69220ac
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
4 changes: 2 additions & 2 deletions addons/spectator/functions/fnc_cam.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ if (_init) then {

// Follow camera related
GVAR(camDistance) = 0;
GVAR(camDistanceTemp) = 0;
GVAR(camDistanceTrue) = 0;
GVAR(camYaw) = 0;
GVAR(camPitch) = 0;

Expand Down Expand Up @@ -133,7 +133,7 @@ if (_init) then {
GVAR(camHasTarget) = nil;
GVAR(camTargetInVehicle) = nil;
GVAR(camDistance) = nil;
GVAR(camDistanceTemp) = nil;
GVAR(camDistanceTrue) = nil;
GVAR(camYaw) = nil;
GVAR(camPitch) = nil;
GVAR(camSlow) = nil;
Expand Down
16 changes: 10 additions & 6 deletions addons/spectator/functions/fnc_cam_prepareTarget.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,24 @@
#include "script_component.hpp"

private _focus = vehicle (param [0, objNull, [objNull]]);
TRACE_1("cam_prepareTarget",_focus);

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 _zoomTemp = GVAR(camDistanceTemp);
private _zoomTrue = GVAR(camDistanceTrue);

if (_zoomTemp != _zoom) then {
_zoomTemp = [_zoomTemp, _zoom, 10, GVAR(camDeltaTime)] call BIS_fnc_lerp;
GVAR(camDistanceTemp) = _zoomTemp;
// Interpolate zoom each frame until desired zoom is reached
if (_zoomTrue != _zoom) then {
_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
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
private _isMan = _focus isKindOf "Man";
Expand Down

0 comments on commit 69220ac

Please sign in to comment.