Camera Tutorial: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (→‎Full example: OFP to {{ofp}})
(Add PiP info)
 
(8 intermediate revisions by the same user not shown)
Line 3: Line 3:


A cinematic camera is what is commonly known as a "cutscene"; the player's input are dismissed and events happen during the video.<br>
A cinematic camera is what is commonly known as a "cutscene"; the player's input are dismissed and events happen during the video.<br>
A camera is '''[[local]]''' to the computer where the script has been called; one player could see a cutscene but still get killed by another player that didn't trigger the video.
A camera is '''[[Multiplayer Scripting#Locality|local]]''' to the computer where the script has been called; one player could see a cutscene but still get killed by another player that didn't trigger the video.




Line 10: Line 10:
The list of all camera commands can be found in the [[:Category:Command Group: Camera Control|Camera command group]] category.
The list of all camera commands can be found in the [[:Category:Command Group: Camera Control|Camera command group]] category.


{{ Important | In '''{{ofp}}''' the "Prepare" commands do not exist.<br>Use their "normal" counterpart instead (e.g [[camPreparePos]] [[camSetPos]], [[camCommitPrepared]] [[camCommit]]).<br>Only [[camCommitted]] is common to both writings.}}
{{Feature|important|
The "Prepare" version of camera commands has been introduced with {{arma1}}. Using this set of commands helps the engine preloading the camera's (future) field of view (see also [[preloadCamera]]).<br><!--
-->'''{{ofp}}''' only features the "Set" version of camera commands; use them instead (e.g [[camPreparePos]] becomes [[camSetPos]], [[camCommitPrepared]] becomes [[camCommit]], etc).<br><!--
-->Only [[camCommitted]] is common to both syntaxes.}}


=== Create the camera ===
=== Create the camera ===


[[private]] _camera = "camera" '''[[camCreate]]''' [[getPosATL]] [[player]];
<sqf>private _camera = "camera" camCreate getPosATL player;</sqf>


=== Enter the camera ===
=== Enter the camera ===


_camera '''[[cameraEffect]]''' ["internal", "back"];
<sqf>_camera cameraEffect ["internal", "back"];</sqf>


=== Select a target ===
=== Select a target ===


==== Object target ====
==== Object target ====
_camera '''[[camPrepareTarget]]''' [[player]]; {{codecomment|// a camera will automatically target the human target's face}}
<sqf>_camera camPrepareTarget player; // a camera will automatically target the human target's face</sqf>


==== Position target ====
==== Position target ====
_camera '''[[camPrepareTarget]]''' [[getPosATL]] [[player]];
<sqf>_camera camPrepareTarget getPosATL player;</sqf>


=== Place the camera ===
=== Place the camera ===


==== World position ====
==== World position ====
_camera '''[[camPreparePos]]''' ([[player]] [[getRelPos]] [5, 0]);
<sqf>_camera camPreparePos (player getRelPos [5, 0]);</sqf>


==== Relative position ====
==== Relative position ====
_camera '''[[camPrepareRelPos]]''' [0,5,0];
<sqf>
_camera camCommitPrepared 0; // required to apply the prepared target first - otherwise a long trip from [0,0,0] is to follow
_camera camPrepareRelPos [0,5,0];
</sqf>


=== Apply camera's Field of View ===
=== Apply camera's Field of View ===


_camera '''[[camPrepareFOV]]''' 0.5; {{codecomment|// standard FOV is 0.7; lesser (e.g 0.5) is zoomed in, greater (e.g 0.9) is zoomed out}}
<sqf>_camera camPrepareFOV 0.5; // standard FOV is 0.7; lesser (e.g 0.5) is zoomed in, greater (e.g 0.9) is zoomed out</sqf>


=== Apply all the changes ===
=== Apply all the changes ===


_camera '''[[camCommitPrepared]]''' 0; {{codecomment|// 0 for immediate change, value in seconds for transition}}
==== Immediately or with transition ====
<sqf>_camera camCommitPrepared 0; // 0 for immediate change, value in seconds for transition</sqf>
 
==== With a loading timeout ====
<sqf>
_camera camPreload 3; // since Armed Assault - instantly moves the camera once preload or timeout is done.
// tells the game to preload the future field of view. 3 here is a timeout, 0 for infinite timeout
</sqf>


=== Check that the commit happened ===
=== Check that the commit happened ===


[[camCommitted]] _camera;
<sqf>camCommitted _camera; // for camCommit/camCommitPrepared usage</sqf>
 
<sqf>camPreloaded _camera; // for camPreload usage</sqf>


=== Leave the camera ===
=== Leave the camera ===


_camera [[cameraEffect]] ["terminate", "back"];
<sqf>_camera cameraEffect ["terminate", "back"];</sqf>


=== Delete the camera ===
=== Delete the camera ===


[[camDestroy]] _camera;
<sqf>camDestroy _camera;</sqf>




Line 60: Line 75:


* A camera of bird type (seagull or crowe) '''cannot''' be controlled ''via'' "Prepare" commands - only camSet* ones.
* A camera of bird type (seagull or crowe) '''cannot''' be controlled ''via'' "Prepare" commands - only camSet* ones.
* A camera of bird type is '''always''' [[camCommitted]] even if it is still moving toward its destination.
* A camera of bird type is '''always''' committed ([[camCommitted]] will always return [[true]]) even if it is still moving toward its destination.




== Full example ==
== Full example ==


=== Standard example ===
{| class="wikitable"
! style="width: 50%" | [[SQF Syntax]]
! [[SQS Syntax]]
|-
|
<sqf>
private _camera = "camera" camCreate [0, 0, 0];
_camera camPrepareTarget player;
_camera camCommitPrepared 0; // needed for relative position
_camera camPrepareRelPos [0, -5, 10];
_camera cameraEffect ["internal", "back"];
_camera camCommitPrepared 0;
waitUntil { camCommitted _camera };
 
_camera camPrepareRelPos [90, 25, 8];
_camera camCommitPrepared 5;
waitUntil { camCommitted _camera };
 
_camera camPrepareRelPos [-90, -5, 5];
_camera camCommitPrepared 3;
waitUntil { camCommitted _camera };
 
sleep 3;
_camera cameraEffect ["terminate", "back"];
camDestroy _camera;
</sqf>
 
|
 
<sqs>
_camera = "camera" camCreate [0, 0, 0]
_camera camSetTarget player
 
_camera camSetRelPos [0, -5, 10]
_camera cameraEffect ["internal", "back"]
_camera camCommit 0
@camCommitted _camera
 
_camera camSetRelPos [90, 25, 8]
_camera camCommit 5
@camCommitted _camera
 
_camera camSetRelPos [-90, -5, 5]
_camera camCommit 3
@camCommitted _camera
 
~3
_camera cameraEffect ["terminate", "back"]
camDestroy _camera
</sqs>
|}
 
 
== Picture-in-Picture ==
 
=== Create Source ===
 
The Picture-in-Picture (PiP) RTT (or R2T, Render to Texture) source can be defined at the {{Link|#Enter the camera}} step; instead of
<sqf>_camera cameraEffect ["internal", "back"];</sqf>
use the following to create a PiP source - multiple sources can be
<sqf>_camera cameraEffect ["internal", "back", "rttName"];</sqf>
 
=== Configure PiP Effects ===
 
A camera effect is set using [[setPiPEffect]] as such:
<sqf>"rttName" setPiPEffect [2]; // sets thermal imaging</sqf>
 
Once all the configuration is done, the PiP texture can be accessed by referencing its name "rttName". For example:
<sqf>
if (!isPiPEnabled) exitWith { systemChat "PiP is not enabled in video options"; };
 
with uiNamespace do // or use disableSerialization
{
private _ctrl = findDisplay 46 createDisplay "RscDisplayEmpty" ctrlCreate ["RscPicture", -1];
_ctrl ctrlSetPosition [safeZoneW * 0.75, safeZoneY, safeZoneW * 0.25, safeZoneH * 0.25];
_ctrl ctrlSetText "#(argb,512,512,1)r2t(rttName,1.0)";
_ctrl ctrlCommit 0;
};
</sqf>


[[private]] _camera = "camera" [[camCreate]] [0, 0, 0];
In order to stop the camera from "broadcasting", use
_camera [[camPrepareTarget]] player;
<sqf>
_camera [[camPrepareRelPos]] [0, -5, 10];
_camera cameraEffect ["terminate", "back", "rttName"]; // terminates "rttName" r2t source
_camera [[cameraEffect]] ["internal", "back"];
_camera cameraEffect ["terminate", "back"]; // terminates all r2t source
_camera [[camCommitPrepared]] 0;
</sqf>
[[waitUntil]] { [[camCommitted]] _camera };
_camera [[camPrepareRelPos]] [90, 25, 8];
_camera [[camCommitPrepared]] 5;
[[waitUntil]] { [[camCommitted]] _camera };
_camera [[camPrepareRelPos]] [-90, -5, 5];
_camera [[camCommitPrepared]] 3;
[[waitUntil]] { [[camCommitted]] _camera };
[[sleep]] 3;
_camera [[cameraEffect]] ["terminate", "back"];
[[camDestroy]] _camera;


=== {{ofp}} SQS example ===
The camera still exists until destroyed with [[camDestroy]].


_camera = "camera" [[camCreate]] [0, 0, 0]
_camera [[camSetTarget]] player
_camera [[camSetRelPos]] [0, -5, 10]
_camera [[cameraEffect]] ["internal", "back"]
_camera [[camCommit]] 0
@[[camCommitted]] _camera
_camera [[camSetRelPos]] [90, 25, 8]
_camera [[camCommit]] 5
@[[camCommitted]] _camera
_camera [[camSetRelPos]] [-90, -5, 5]
_camera [[camCommit]] 3
@[[camCommitted]] _camera
~3
_camera [[cameraEffect]] ["terminate", "back"]
[[camDestroy]] _camera


== See also ==
== See also ==
Line 111: Line 173:
* [[Camera.sqs]]
* [[Camera.sqs]]
* [[Arma 3: Splendid Camera]]&nbsp;/&nbsp;[[BIS_fnc_camera]]
* [[Arma 3: Splendid Camera]]&nbsp;/&nbsp;[[BIS_fnc_camera]]
* [[:Category:Command Group: Camera Control|Command Group: Camera Control]]
* [[BIS_fnc_PIP]]




[[Category:Arma Scripting Tutorials]]
[[Category:Arma Scripting Tutorials]]

Latest revision as of 20:04, 29 July 2022

Basics

A cinematic camera is what is commonly known as a "cutscene"; the player's input are dismissed and events happen during the video.
A camera is local to the computer where the script has been called; one player could see a cutscene but still get killed by another player that didn't trigger the video.


How to

The list of all camera commands can be found in the Camera command group category.

The "Prepare" version of camera commands has been introduced with Armed Assault. Using this set of commands helps the engine preloading the camera's (future) field of view (see also preloadCamera).
Operation Flashpoint only features the "Set" version of camera commands; use them instead (e.g camPreparePos becomes camSetPos, camCommitPrepared becomes camCommit, etc).
Only camCommitted is common to both syntaxes.

Create the camera

private _camera = "camera" camCreate getPosATL player;

Enter the camera

_camera cameraEffect ["internal", "back"];

Select a target

Object target

_camera camPrepareTarget player; // a camera will automatically target the human target's face

Position target

Place the camera

World position

_camera camPreparePos (player getRelPos [5, 0]);

Relative position

_camera camCommitPrepared 0; // required to apply the prepared target first - otherwise a long trip from [0,0,0] is to follow _camera camPrepareRelPos [0,5,0];

Apply camera's Field of View

_camera camPrepareFOV 0.5; // standard FOV is 0.7; lesser (e.g 0.5) is zoomed in, greater (e.g 0.9) is zoomed out

Apply all the changes

Immediately or with transition

_camera camCommitPrepared 0; // 0 for immediate change, value in seconds for transition

With a loading timeout

_camera camPreload 3; // since Armed Assault - instantly moves the camera once preload or timeout is done. // tells the game to preload the future field of view. 3 here is a timeout, 0 for infinite timeout

Check that the commit happened

camCommitted _camera; // for camCommit/camCommitPrepared usage

camPreloaded _camera; // for camPreload usage

Leave the camera

_camera cameraEffect ["terminate", "back"];

Delete the camera

camDestroy _camera;


Specific cases

  • A camera of bird type (seagull or crowe) cannot be controlled via "Prepare" commands - only camSet* ones.
  • A camera of bird type is always committed (camCommitted will always return true) even if it is still moving toward its destination.


Full example

SQF Syntax SQS Syntax

private _camera = "camera" camCreate [0, 0, 0]; _camera camPrepareTarget player; _camera camCommitPrepared 0; // needed for relative position _camera camPrepareRelPos [0, -5, 10]; _camera cameraEffect ["internal", "back"]; _camera camCommitPrepared 0; waitUntil { camCommitted _camera }; _camera camPrepareRelPos [90, 25, 8]; _camera camCommitPrepared 5; waitUntil { camCommitted _camera }; _camera camPrepareRelPos [-90, -5, 5]; _camera camCommitPrepared 3; waitUntil { camCommitted _camera }; sleep 3; _camera cameraEffect ["terminate", "back"]; camDestroy _camera;

_camera = "camera" camCreate [0, 0, 0] _camera camSetTarget player _camera camSetRelPos [0, -5, 10] _camera cameraEffect ["internal", "back"] _camera camCommit 0 @camCommitted _camera _camera camSetRelPos [90, 25, 8] _camera camCommit 5 @camCommitted _camera _camera camSetRelPos [-90, -5, 5] _camera camCommit 3 @camCommitted _camera ~3 _camera cameraEffect ["terminate", "back"] camDestroy _camera


Picture-in-Picture

Create Source

The Picture-in-Picture (PiP) RTT (or R2T, Render to Texture) source can be defined at the Enter the camera step; instead of

_camera cameraEffect ["internal", "back"];

use the following to create a PiP source - multiple sources can be

_camera cameraEffect ["internal", "back", "rttName"];

Configure PiP Effects

A camera effect is set using setPiPEffect as such:

"rttName" setPiPEffect [2]; // sets thermal imaging

Once all the configuration is done, the PiP texture can be accessed by referencing its name "rttName". For example:

if (!isPiPEnabled) exitWith { systemChat "PiP is not enabled in video options"; }; with uiNamespace do // or use disableSerialization { private _ctrl = findDisplay 46 createDisplay "RscDisplayEmpty" ctrlCreate ["RscPicture", -1]; _ctrl ctrlSetPosition [safeZoneW * 0.75, safeZoneY, safeZoneW * 0.25, safeZoneH * 0.25]; _ctrl ctrlSetText "#(argb,512,512,1)r2t(rttName,1.0)"; _ctrl ctrlCommit 0; };

In order to stop the camera from "broadcasting", use

_camera cameraEffect ["terminate", "back", "rttName"]; // terminates "rttName" r2t source _camera cameraEffect ["terminate", "back"]; // terminates all r2t source

The camera still exists until destroyed with camDestroy.


See also