Jump to content

Recommended Posts

Hey guys,
 
I m thinking about doing a picture in picture bullet cam.
What I ve found upto now is KK's tutorial A Simple Bullet Cam and this command BIS_fnc_liveFeed.
Now I m riddling how to combine that the right way.
KK's Code:

player addEventHandler ["Fired", {
    _null = _this spawn {
        _missile = _this select 6;
        _cam = "camera" camCreate (position player); 
        _cam cameraEffect ["External", "Back"];
        waitUntil {
            if (isNull _missile) exitWith {true};
            _cam camSetTarget _missile;
            _cam camSetRelPos [0,-3,0];
            _cam camCommit 0;
        };
        sleep 0.4;      
        _cam cameraEffect ["Terminate", "Back"];
        camDestroy _cam;
    };
}];

BIS_fnc_liveFeed:

/*
	
	Description:
	Display a live feed.
	
	Parameters:
		_this select 0: OBJECT or ARRAY - Live feed source
		_this select 1: OBJECT or ARRAY - Live feed target
		_this select 2: OBJECT - Player that will see the feed
		_this select 3 (Optional): NUMBER - Live feed effects (-1: reset, 0: normal (default), 1: night vision, 2: thermal imaging)
	
	Returns:
	True if successful, false if not.
*/

// Doesn't need to be run on a dedicated server

I think I ve to integrate that BIS function into KKs code block. That shouldnt be the problem.
My problem is that idk how to use that functions paramteters correctly.
 
0: source - is that an object where the camera is mounted on?
1: target - is that the object the camera is looking at?
2: player - is the feed automatically rendered on the players screen in a little frame? is there a way to manipulate that frame in size and position?
3: effects - okay thats clear for me :-)
 
Any help would be appreciated.

Share this post


Link to post
Share on other sites

Source is where the cam is created. The fnc creates the camera itself so no need for you to create it. 

Target is obj cam is looking at

Pretty sure it auto renders in that lil screen, @larrow posted what im assuming is a good solution for moving/resizing in this thread https://forums.bistudio.com/topic/182321-increasing-bis-fnc-livefeed-display-size/

Been a while since i messed with it so im only like 90% of all this

  • Like 1

Share this post


Link to post
Share on other sites

Thanks alot soolie that was very helpful.

Here is my full working bullet pip cam:

 

bis_fnc_pip_stream =

/*
This function is same as BIS_liveFeed but I had to insert disableSerialization in it to prevent error popup.
*/

{disableSerialization;private _fnc_scriptNameParent = if (isNil '_fnc_scriptName') then {'BIS_fnc_liveFeed'} else 
{_fnc_scriptName};private _fnc_scriptName = 'BIS_fnc_liveFeed';scriptName _fnc_scriptName;
if (isDedicated) 
exitWith {"Not dedicated server compatible" call BIS_fnc_error; false};
private ["_source"];_source = _this param [0, objNull, [objNull, []]];
if (typeName _source == typeName objNull) then {_source = [_source];
{if (isNull _x) then {_source = _source - [_x]}} forEach _source;};
if (count _source == 0) exitWith {"Invalid source defined" call BIS_fnc_error; false};
if (count _source == 1) then {_source = _source select 0};private ["_target"];_target = _this param [1, objNull, 
[objNull, []]];if (typeName _target == typeName objNull) then {_target = [_target];
{if (isNull _x) then {_target = _target - [_x]}} forEach _target;};
if (count _target == 0) exitWith {"Invalid target defined" call BIS_fnc_error; false};
if (count _target == 1) then {_target = _target select 0};
[] call BIS_fnc_liveFeedTerminate;private ["_player"];_player = _this param [2, objNull, [objNull]];
if (isNull _player) exitWith {"Invalid player unit defined" call BIS_fnc_error; false};
if (local _player) then {disableSerialization;
BIS_liveFeed = ["livefeedrendertarget0",[_source,_target],_player] call BIS_fnc_PIP;private ["_mode"];_mode = _this param [3, 0, [0]];_mode call BIS_fnc_liveFeedEffects;
[] spawn {scriptName "BIS_fnc_liveFeed: transition in";disableSerialization;
waitUntil {!(isNull (uiNamespace getVariable "BIS_fnc_PIP_RscPIP"))};private ["_disp"];_disp = uiNamespace getVariable "BIS_fnc_PIP_RscPIP";
for "_i" from 12 to 0 step - 1 do {
private ["_ctrl"];
_ctrl = _disp displayCtrl (2400 + _i);
_ctrl ctrlSetPosition ctrlPosition (_disp displayCtrl 2300);_ctrl ctrlCommit 0;uiSleep 0.03;_ctrl ctrlSetPosition [0,0,0,0];_ctrl ctrlCommit 0;};};};true};

fnc_resizePIP =

/*
 I got this function from this BI forum post of larrow
 https://forums.bistudio.com/topic/182321-increasing-bis-fnc-livefeed-display-size/#entry2876393
 I dont know if he is the author but he seems to.	
*/
{
	_dispPos = [ _this, 0, [ 0, 0 ], [ [] ], [ 2 ] ] call BIS_fnc_param;
	_scale = [ _this, 1, 1, [ 0 ] ] call BIS_fnc_param;
	_display = uiNamespace getVariable "BIS_fnc_PIP_RscPIP";
	_basePos = ctrlPosition ( _display displayCtrl 2300 );
	_baseScale = ctrlScale ( _display displayCtrl 2300 );
	_scaleDiff = _scale / _baseScale;
	{
		_ctrl = _x;
		_pos = ctrlPosition _ctrl;
		_pos resize 2;
		{
			_diff = _x - ( _basePos select _forEachIndex );

			_newpos = ( _dispPos select _forEachIndex ) + ( _diff * _scaleDiff );

			_pos set [ _forEachIndex, _newpos ];

		}forEach _pos;

		_ctrl ctrlSetPosition _pos;

		_ctrl ctrlSetScale _scale;

		_ctrl ctrlCommit 0;

	}forEach allControls _display;
};

(vehicle player) addEventHandler ["Fired", 
{
 if (isNil "BULLET_CAM") then
 {
  BULLET_CAM = true;
 
  _null = _this spawn 
  {
   _pencil = objNull;
   _bullet =  _this select 6;
   _pencil = "Land_PencilRed_F" createVehicle [0,0,100];
  
   waitUntil{!isNull _pencil};

   _pencil enableSimulation false;
   _pencil hideObject true;

   if(!(isNull _bullet) and !(isNull _pencil) and (isNil "BIS_liveFeed")) then
   {
    [ _pencil, _bullet, player, 0] call bis_fnc_pip_stream;
    [ [ 0.8, 0.6 ], 1.6 ] call fnc_resizePIP;
   };

   waitUntil
   {
    _pencil attachTo [_bullet, [0,-40,20]];

    [_pencil, [0,0,0]] call BIS_fnc_liveFeedSetSource; 
 
    if(!isNull _bullet) then
    {
     [_bullet] call BIS_fnc_liveFeedSetTarget; 
    };
    isNull (_bullet)
   };
   sleep 5;
 [] call BIS_fnc_liveFeedTerminate;
   deleteVehicle _pencil;
   BULLET_CAM = nil;
  };
 };
}];

Any advice how to optimize the code is appreciated as always :-)

  • Like 1

Share this post


Link to post
Share on other sites

if u use this EH instead of that above then u will have pip bullet cam for rockets/missiles, arty shells and bombs only.
canons, machine guns, rifles, hand guns, grenade launchers  and so on are excluded.

(vehicle player) addEventHandler ["Fired", 
{
 if (isNil "BULLET_CAM") then
 {
  BULLET_CAM = true;

 _ammo_class = typeOf (_this select 6);
 _air_fric = getNumber(configFile >> "CfgAmmo" >> _ammo_class >> "airFriction");
 _max_speed = getNumber(configFile >> "CfgAmmo" >> _ammo_class >> "maxSpeed");

 if((_air_fric < 0) and !(_max_speed > 0)) exitWith {BULLET_CAM = nil;};

  _null = _this spawn 
  {
   _pencil = objNull;
   _bullet =  _this select 6;
   _pencil = "Land_PencilRed_F" createVehicle [0,0,100];
  
   waitUntil{!isNull _pencil};

   _pencil enableSimulation false;
   _pencil hideObject true;

   if(!(isNull _bullet) and !(isNull _pencil) and (isNil "BIS_liveFeed")) then
   {
    [ _pencil, _bullet, player, 0] call bis_fnc_pip_stream;
    [ [ 0.8, 0.6 ], 1.6 ] call fnc_resizePIP;
   };

   waitUntil
   {
    _pencil attachTo [_bullet, [0,-30,15]];

    [_pencil, [0,0,0]] call BIS_fnc_liveFeedSetSource; 
 
    if(!isNull _bullet) then
    {
     [_bullet] call BIS_fnc_liveFeedSetTarget; 
    };
    isNull (_bullet)
   };
   sleep 5;
   [] call BIS_fnc_liveFeedTerminate;
   deleteVehicle _pencil;
   BULLET_CAM = nil;
  };
 };
}];

Share this post


Link to post
Share on other sites

I wonder if it is possible to tweak the setting of a pip cam with e.g. camSetFov but I dont know how to get the cam object.

what I know is how to get the display this can be done with:

_display = uiNamespace getVariable "BIS_fnc_PIP_RscPIP";

is it possible to get the camera object for the display? or any other way to get that cam of sthe pip stream?

 

EDIT:

I know the position of the camera. Is it possible to do this and get the camera object?

_radius = 1;
_array = _known_position nearEntities ["camera", _radius];
_cam_object = _array select 0;
Edited by sarogahtyp

Share this post


Link to post
Share on other sites

Im really stuck here. I cant get the camera object with non of the near commands.
I tested nearEntities, nearObjects and nearSupplies.

I need some help to get the camera object for the PIP cam which is created with BIS_fnc_liveFeed.

 

EDIT:

seems that I already had that object. its BIS_liveFeed

 

camSetFov is not working but i think the reason is that I ve to learn some more about manipulating camera settings.

 

EDIT2: I got it working

Edited by sarogahtyp

Share this post


Link to post
Share on other sites

Can you post what you did? Im interested in full results . please... Thanks

Share this post


Link to post
Share on other sites

there isnt more to tell.

BIS_liveFeed camPrepareFov 0.1;

BIS_liveFeed camCommitPrepared 0;

sets full zoom for pip cam. if u have further questions then just ask.

 

 

EDIT:

Got an improvement suggestion from Grumpy via PM

 

Quote

Hey, saw your pip bulletcam script in some post with a code snippet from kk.

You can improve the quality of the cam following the bullet by using a stacked onEachFrame eventhandler, so it will be way more fluid, especially during low fps, since it's alyways in sync with the fps.

I adapted it like that:


_firer = player;
_eh = _firer addeventhandler ["Fired",{

	params ["_firer","_weapon","_muzzle","_mode","_ammo","_magazine","_projectile"];

	_firer removeEventHandler ["Fired",_thisEventHandler];

	_nul = [_firer,_projectile] spawn {

		params ["_firer","_projectile"];
		_cam = "camera" camcreate getposatl _projectile;
		_cam cameraeffect ["internal","back"];
		_cam camCommitPrepared 0;

		_ID = ((missionNamespace getVariable ["GOM_fnc_bulletCamID",0]) + 1);
		missionNamespace setVariable ["GOM_fnc_bulletCamID",_ID];

		[_ID, "onEachFrame", {

			params ["_projectile","_cam","_ID"];

				_cam camSetTarget _projectile;
	            _cam camSetRelPos [0,-3,1];
				_cam camCommitPrepared 0;

			if (isNull _projectile) then {

				_cam cameraeffect ["terminate","back"];
				camdestroy _cam;
				[_ID, "onEachFrame"] call BIS_fnc_removeStackedEventHandler;
			};
		},[_projectile,_cam,_ID]] call BIS_fnc_addStackedEventHandler;
	};
}];

 

Edited by sarogahtyp

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×