2018-09-17 19:19:29 +00:00
|
|
|
#include "script_component.hpp"
|
2017-08-12 13:25:48 +00:00
|
|
|
/*
|
|
|
|
* Author: Nelson Duarte, SilentSpike
|
|
|
|
* Moves the spectator camera to a position relative to the camera focus.
|
|
|
|
* Used for 3PP camera and teleporting, etc.
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* 0: New Target <OBJECT>
|
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* [player] call ace_spectator_fnc_cam_prepareTarget
|
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
|
|
|
|
|
|
|
private _focus = vehicle (param [0, objNull, [objNull]]);
|
2017-12-03 16:10:48 +00:00
|
|
|
TRACE_1("cam_prepareTarget",_focus);
|
2017-08-12 13:25:48 +00:00
|
|
|
|
|
|
|
if !(isNull _focus) then {
|
2017-12-03 16:10:48 +00:00
|
|
|
// Zooming takes place smoothly over multiple frames
|
|
|
|
// _zoom is target set by user, _zoomTrue is actual value each frame
|
2017-08-12 13:25:48 +00:00
|
|
|
private _zoom = [0, GVAR(camDistance)] select (GVAR(camMode) == MODE_FOLLOW);
|
2017-12-03 16:10:48 +00:00
|
|
|
private _zoomTrue = GVAR(camDistanceTrue);
|
2017-08-12 13:25:48 +00:00
|
|
|
|
2017-12-03 16:10:48 +00:00
|
|
|
// 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);
|
2017-08-12 13:25:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// The distance at which to place camera from the focus pivot
|
|
|
|
private _bbd = [_focus] call BIS_fnc_getObjectBBD;
|
2017-12-03 16:10:48 +00:00
|
|
|
private _distance = (_bbd select 1) + _zoomTrue;
|
2017-08-12 13:25:48 +00:00
|
|
|
|
|
|
|
// The pivot on the target vehicle
|
|
|
|
private _isMan = _focus isKindOf "Man";
|
|
|
|
private _height = if !(_isMan) then { (_bbd select 2) / 3 } else { switch (stance _focus) do { case "STAND": {1.4}; case "CROUCH": {0.8}; default {0.4}; }; };
|
|
|
|
|
2021-10-10 13:37:05 +00:00
|
|
|
private _center = if (_isMan) then { _focus modelToWorldVisualWorld (_focus selectionPosition "Spine3") } else { _focus modelToWorldVisualWorld [0,0,_height] };
|
2017-08-12 13:25:48 +00:00
|
|
|
|
|
|
|
// Set dummy location and rotation
|
|
|
|
private _dummy = GVAR(camDummy);
|
|
|
|
|
|
|
|
_dummy setPosASL _center;
|
|
|
|
[_dummy, [GVAR(camYaw), GVAR(camPitch), 0]] call BIS_fnc_setObjectRotation;
|
|
|
|
|
|
|
|
// Apply location and rotation to camera
|
2021-10-10 13:37:05 +00:00
|
|
|
GVAR(camera) setPosASL (_dummy modelToWorldVisualWorld [0, -_distance, 0]);
|
2017-08-12 13:25:48 +00:00
|
|
|
GVAR(camera) setVectorDirAndUp [vectorDirVisual _dummy, vectorUpVisual _dummy];
|
|
|
|
};
|