This page has been translated automatically.
UnigineEditor
Interface Overview
Assets Workflow
Settings and Preferences
Working With Projects
Adjusting Node Parameters
Setting Up Materials
Setting Up Properties
Landscape Tool
Using Editor Tools for Specific Tasks
Extending Editor Functionality
Programming
Fundamentals
Setting Up Development Environment
Usage Examples
UnigineScript
C++
C#
UUSL (Unified UNIGINE Shader Language)
File Formats
Rebuilding the Engine Tools
GUI
Double Precision Coordinates
API
Containers
Common Functionality
Controls-Related Classes
Engine-Related Classes
Filesystem Functionality
GUI-Related Classes
Math Functionality
Node-Related Classes
Objects-Related Classes
Networking Functionality
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
IG Plugin
CIGIConnector Plugin
Warning! This version of documentation is OUTDATED, as it describes an older SDK version! Please switch to the documentation for the latest SDK version.
Warning! This version of documentation describes an old SDK version which is no longer supported! Please upgrade to the latest SDK version.

Unigine.Camera Class

The Camera class is used to create a new camera, set it up (set all the required matrices, field of view, masks and so on) and then pass it to an instance of the Viewport class to render an image from this camera.

Notice
An instance of this class is not a node.

A camera instance can have the following masks:

  • Sound Source mask
  • Sound Reverberation mask
  • Viewport mask
  • Reflection Viewport mask

Camera settings can be set up in the Camera Settings in UnigineEditor.

Usage Example

In this example Camera and PlayerSpectator (which inherited from Player class) instances created and added to the current scene. Here is a code from the AppWorldLogic.cs file.

Source code (C#)
namespace UnigineApp
{
	class AppWorldLogic : WorldLogic
	{
		PlayerSpectator playerSpectator;
		Camera camera;

		/* ... */

		public override bool Init()
		{
			/* ... */
			// initialize PlayerSpectator and Camera instances
			playerSpectator = new PlayerSpectator();
			camera = new Camera();

			// specify the necessary camera parameters: FOV, ZNear, ZFar.
			// add the post_sensor_red post-effect to camera
			camera.setFov(110.0f);
			camera.setZNear(0.1f);
			camera.setZFar(10000.0f);
			camera.setPostMaterials("post_sensor_red");

			// set camera to the player
			playerSpectator.setCamera(camera);

			// specify the position and view direction of playerSpectator
			playerSpectator.setViewDirection(new vec3(0.0f, 1.0f, 0.0f));
			playerSpectator.setWorldPosition(new dvec3(-1.6f, -1.7f, 1.7f));

			Game.Player = playerSpectator;

			return 1;
		}
	}
}

Camera Class

Properties

int NumScriptableMaterials#

The total number of scriptable materials attached to the camera.

string PostMaterials#

Names of the current post postprocess materials that are applied after all other postprocess are rendered. they are used after engine.render.getPostMaterials(), if any.
set
Sets post postprocess materials that are applied after all other postprocess are rendered. They are used after engine.render.setPostMaterials(), if any.
set value - Comma-separated names of postprocess materials.

int ReverbMask#

The current bit mask that determines what reverberation zones can be heard. for sound to reverberate, at least one bit of this mask should match a reverb mask of the sound source and a reverb mask of the reverberation zone. masks of a sound source and reverberation zone can match with the camera's one in several bits, not necessarily one.
set
Updates a bit mask that determines what reverberation zones can be heard. For sound to reverberate, at least one bit of this mask should match a reverb mask of the sound source and a reverb mask of the reverberation zone. Masks of a sound source and reverberation zone can match the camera's one in several bits, not necessarily one.
set value - Integer, each bit of which is a mask for reverberating sound sources and reverberation zones.

int SourceMask#

A bit mask that determines what sound channels can be heard. for a sound source to be heard, its mask should match this one in at least one bit. plus, the volume of sound channel in which the sound plays (its number also depends on this mask) should not be equal to 0.
set
Updates a bit mask that determines what sound sources can be heard. For a sound source to be heard, its mask should match this one in at least one bit. Plus, the volume of sound channel in which the sound plays (its number also depends on this mask) should not be equal to 0.
set value - Integer, each bit of which specifies a sound channel.

int ReflectionViewportMask#

The current bit mask for rendering reflections into the camera viewport. reflections are rendered in the camera viewport if masks of reflective materials match this one (one bit at least).
set
Sets a bit mask for rendering reflections into the viewport. Reflections are rendered in the viewport if masks of reflective materials match this one (one bit at least).
set value - Integer, each bit of which is used to set a mask.

int ViewportMask#

The current bit mask for rendering into the viewport. object surfaces, materials, decals, lights and gui objects will be rendered into the viewport only if their viewport mask matches the camera's one (one matching bit is enough).
set
Sets a bit mask for rendering into the viewport. Object surfaces, materials, decals, lights and GUI objects will be rendered into the viewport only if their viewport masks match the camera's one (one matching bit is enough).
set value - Integer, each bit of which is used to set a mask.

bool IsObliqueFrustum#

A value indicating if the viewing frustum is oblique.
set
Enables or disables obliqueness of the viewing frustum.
Notice
It is recommended to set oblique viewing frustum using this method, as it doesn't affect the projection matrix. To specify the near clipping plane use the setObliqueFrustumPlane() method.
set value - 1 to enable oblique viewing frustum; 0 to disable it.

vec4 ObliqueFrustumPlane#

The oblique near clipping plane of the viewing frustum.
set
Sets the oblique near clipping plane of the viewing frustum.
Notice
This method does not affect the projection matrix. To enable the oblique frustum use the setObliqueFrustum() method.
Source code (C#)
// AppWorldLogic.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Unigine;

namespace UnigineApp
{
	class AppWorldLogic : WorldLogic
	{
		/* .. */
		
		public override bool Update()
		{

            float time = Game.Time;
			
				// initializing a plane to be set as a near clipping plane
                dvec4 plane = new dvec4(1.0f, 1.0f, 1.0f, 1.0f + MathLib.Sin(time) * 4.0f);
				
				// getting a camera
                Camera camera = Game.Player.Camera;
                if (camera != null)
                {
					// enabling oblique frustum
                    camera.ObliqueFrustum = true;

					// setting our plane as an oblique near clipping plane
                    camera.ObliqueFrustumPlane = plane;
                }

            return true;
		}
		
		/* .. */
	}
}
set value - World coordinates of the oblique near clipping plane to set (Nx, Ny, Nz, D), where Nx, Ny, Nz - coordinates of the plane normal, D - distance from the origin to the plane.

vec3 Up#

The current up direction of the camera's viewport (i.e. tilt of the camera's viewport).
set
Sets an up direction of the camera's viewport (i.e. tilt of the camera's viewport).
set value - New upward direction vector. The vector is normalized to 1.

float ZFar#

The current distance to the far clipping plane of the camera's viewing frustum.
set
Sets a distance to the far clipping plane of the camera's viewing frustum and updates the projection matrix.
set value - New distance in units. If a negative value is provided, 0 will be used instead.

float ZNear#

The current distance to the near clipping plane of the camera's viewing frustum.
set
Sets a distance to the near clipping plane of the camera's viewing frustum and updates the projection matrix.
set value - New distance in units. If a negative value is provided, 0 will be used instead.

float FocalLength#

The focal length of the physically-based camera lens.
set
Sets a focal length of the physically-based camera lens.
set value - Camera lens focal length.

float FilmGate#

A film gate for the physically-based camera with horizontal fov.
set
Sets a film gate for the physically-based camera with horizontal FOV.
set value - Film gate.

float Fov#

Returns the current vertical field of view of the camera.

Notice
Horizontal FOV cannot be used since it varies depending on the viewport's aspect ratio.

You can use the following formula to calculate horizontal FOV from the vertical one for the given aspect ratio (width/height): FOV_h = 2 × atan ( (width / height) × tan(FOV_v / 2)).

set

Sets a vertical field of view of the camera and updates the projection matrix.

Notice
Horizontal FOV cannot be used since it varies depending on the viewport's aspect ratio.

You can use the following formula to calculate horizontal FOV from the vertical one for the given aspect ratio (width/height): FOV_h = 2 × atan ( (width / height) × tan(FOV_v / 2)).

set value - New vertical field of view in degrees. The provided value will be saturated in the range [0;180].

int FovFixed#

A value indicating which fov component (horizontal or vertical) is currently fixed.

int FovMode#

Sets the value indicating the type of FOV that is used for the camera.
set
Sets the value indicating the type of FOV that is used for the camera:
  • For the classic camera, the vertical FOV should be set. In this case, FOV is directly set in degrees.
  • For the physically-based camera, the horizontal FOV should be set. In this case, FOV is calculated depending on the film gate and focal length of the camera.
set value - FOV_MODE_VERTICAL for the camera with the vertical FOV; FOV_MODE_PHYSICALLY_BASED_CAMERA for the physically-based camera with the horizontal FOV.

mat4 Projection#

The current projection matrix with unit (1.0) aspect ratio.
set
Updates the current projection matrix.
Notice
It is not recommended to use this method for setting obliqueness of the near clipping plane of the frustum, as in this case a number of features (such as clouds, shadows, TAA, a number of engine optimizations, etc.) will not function properly. Please, use the setObliqueFrustum() method instead.

This method allows you to set your camera to use perspective or orthographic projection, depending on your project's requirements.

For example, you can use the following code to set up orthographic projection or perspective projection for your camera depending on a flag value:

Source code (C#)
// AppWorldLogic.cs

namespace UnigineApp
{
	class AppWorldLogic : WorldLogic
	{
		Camera camera;
		Player player;
		/* ... */
		
		// ortho flag - change this value to switch projection type
		int ortho = 0;
		public override bool Init()
		{
			/* ... */
			
			// getting the camera of the current player
			camera = Game.Player.Camera;
	
			// setting up near and far clipping planes and aspect ratio
			float znear = 0.001f;
			float zfar = 10000.0f;
			float aspect = 16.0f / 9.0f;

			if (ortho)
			{
				// setting up orthographic projection
				camera.Projection = MathLib.Ortho(-1.0f, 1.0f, -1.0f, 1.0f, znear, zfar);
			}
			else
			{
				// setting up perspective projection
				camera.Projection = MathLib.Perspective(60.0f, aspect, znear, zfar);
			}
			// setting player's camera
			Player player = Game.Player.Camera = camera;
			
			return true;
		}
	}
}
set value - Projection matrix.

mat4 Offset#

An additional transformation (an offset matrix) set for the camera. this transformation is applied after modelview transformation. the offset matrix does not affect the view matrix or the position of the camera. for example, it can be used to simulate camera shake from an explosion.
set
Sets an additional transformation (an offset matrix) for the camera. This transformation is applied after the modelview transformation. The offset matrix does not affect the view matrix or the position of the camera. For example, the offset matrix can be used to simulate camera shaking from an explosion.
set value - Offset matrix.

vec3 Position#

The current position of the camera. the position vector is stored in the 3rd column of the inverse view matrix.
set
Sets a new position of the camera and updates the modelview and inverse modelview (its 3rd column) matrices.
set value - Camera position in the world space.

mat4 IModelview#

The inverted view matrix of the camera.

mat4 Modelview#

The current view matrix of the camera.
set
Updates a modelview and inverse modelview matrices for the camera.
set value - New view matrix.

Members


static Camera ( ) #

Constructor. Creates a new camera with default settings:

void GetDirectionFromScreen ( out vec3 p0, out vec3 p1, float screen_x, float screen_y, float aspect ) #

Casts the ray from a certain position on the screen.

Arguments

  • out vec3 p0 - Start coordinate of the ray.
  • out vec3 p1 - End coordinate of the ray.
  • float screen_x - X-coordinate of screen, in the [0;1] range, where 0 is the left upper point, 1 is the right lower point.
  • float screen_y - Y-coordinate of screen, in the [0;1] range, where 0 is the left upper point, 1 is the right lower point.
  • float aspect - Screen's aspect ratio (height to width).

vec3 GetDirectionFromScreen ( float screen_x, float screen_y, float aspect ) #

Casts the ray from a certain position on the screen.

Arguments

  • float screen_x - X-coordinate of screen, in the [0;1] range, where 0 is the left upper point, 1 is the right lower point.
  • float screen_y - Y-coordinate of screen, in the [0;1] range, where 0 is the left upper point, 1 is the right lower point.
  • float aspect - Screen's aspect ratio (height to width).

Return value

Point coordinate.

mat4 GetProjectionFromScreen ( float screen_x0, float screen_y0, float screen_x1, float screen_y1, float aspect ) #

Creates a projection matrix out of 2 screen positions. This is required for the frame selection.

Arguments

  • float screen_x0 - X-coordinate of the first screen position, in the [0;1] range, where 0 is the left upper point, 1 is the right lower point.
  • float screen_y0 - Y-coordinate of the first screen position, in the [0;1] range, where 0 is the left upper point, 1 is the right lower point.
  • float screen_x1 - X-coordinate of the second screen position, in the [0;1] range, where 0 is the left upper point, 1 is the right lower point.
  • float screen_y1 - Y-coordinate of the second screen position, in the [0;1] range, where 0 is the left upper point, 1 is the right lower point.
  • float aspect - Screen's aspect ratio (height to width).

Return value

Projection matrix.

int GetScreenPosition ( out float screen_x, out float screen_y, vec3 point, float aspect ) #

Projects the point in world coordinates to the screen. Screen coordinates are written into the first 2 variables passed to the method.

Arguments

  • out float screen_x - X-coordinate of the screen position.
  • out float screen_y - Y-coordinate of the screen position.
  • vec3 point - Point coordinates.
  • float aspect - Aspect ratio (screen height to width).

Return value

1 if the point has been projected successfully; otherwise, 0.

Camera Clone ( ) #

Clones the current camera and saves it to the given camera instance.

Return value

Copy of the camera.

mat4 GetAspectCorrectedProjection ( float aspect ) #

Returns projection matrix after correction for the specified aspect ratio. Currently fixed FOV component is taken into account.

Arguments

  • float aspect - Aspect ratio.

Return value

Projection matrix after correction for the specified aspect ratio.

void AddScriptableMaterial ( Material material ) #

Attaches a new scriptable material to the camera. To apply a scriptable material globally, use the addScriptableMaterial() method of the Render class. The order of execution for scripts assigned to scriptable materials is defined by material's number in the list of the camera.
Notice
Scriptable materials applied globally have their expressions executed before the ones that are applied per-camera.

Arguments

  • Material material - Scriptable material to be attached to the camera.

void RemoveScriptableMaterial ( int num ) #

Removes the scriptable material with the specified number from the camera.

Arguments

int FindScriptableMaterial ( Material material ) #

Returns the number of the specified scriptable material for the camera. This number is camera-specific (valid for this camera only) and determines the order in which the assigned expressions are executed.
Notice
Scriptable materials applied globally have their expressions executed before the ones that are applied per-camera.

Arguments

  • Material material - Scriptable material for which a number is to be found.

Return value

Scriptable material number in the range from 0 to the total number of scriptable materials, or -1 if the specified material was not found.

void SetScriptableMaterial ( int num, Material material ) #

Replaces the scriptable material with the specified number with the new scriptable material specified. The number of material determines the order in which the expressions assigned to it are executed. This number is camera-specific (valid for this camera only).
Notice
Scriptable materials applied globally have their expressions executed before the ones that are applied per-camera.

Arguments

  • int num - Scriptable material number in the range from 0 to the total number of scriptable materials.
  • Material material - New scriptable material to replace the one with the specified number.

Material GetScriptableMaterial ( int num ) #

Returns a scriptable material attached to the camera by its number.

Arguments

Return value

Scriptable material attached to the camera with the specified number.

void SetScriptableMaterialEnabled ( int num, bool enabled ) #

Enables or disables the scriptable material with the specified number. When a material is disabled (inactive), the scripts attached to it are not executed.

Arguments

  • int num - Scriptable material number in the range from 0 to the total number of scriptable materials.
  • bool enabled - 1 to enable the scriptable material with the specified number, 0 to disable it.

bool GetScriptableMaterialEnabled ( int num ) #

Returns a value indicating if the scriptable material with the specified number attached to the camera is enabled (active). When a material is disabled (inactive), the scripts attached to it are not executed.

Arguments

Return value

1 if the scriptable material with the specified number is enabled; otherwise, 0.

void SwapScriptableMaterials ( int num_0, int num_1 ) #

Swaps two scriptable materials with specified numbers. The number of material determines the order in which the expressions assigned to it are executed.
Notice
The number is camera-specific (valid for this camera only).

Arguments

void ClearScriptableMaterials ( ) #

Clears all scriptable materials attached to the camera.
Last update: 2020-04-10
Build: ()