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.
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.
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.Fov = 110.0f;
camera.ZNear = 0.1f;
camera.ZFar = 10000.0f;
// set camera to the player
playerSpectator.Camera = camera;
// specify the position and view direction of playerSpectator
playerSpectator.ViewDirection = new vec3(0.0f, 1.0f, 0.0f);
playerSpectator.WorldPosition = new vec3(-1.6f, -1.7f, 1.7f);
Game.Player = playerSpectator;
return 1;
}
}
}
Camera Class
Enums
PROJECTION_MODE#
Name | Description |
---|---|
PERSPECTIVE = 0 | Perspective projection. |
ORTHOGRAPHIC = 1 | Orthographic projection. |
FOV_FIXED#
Name | Description |
---|---|
VERTICAL = 0 | Vertical FOV component is fixed. |
HORIZONTAL = 1 | Horizontal FOV component is fixed. |
FOV_MODE#
Name | Description |
---|---|
VERTICAL = 0 | Vertical FOV mode. Vertical FOV of the camera is determined by the FOV value. |
PHYSICALLY_BASED_CAMERA = 1 |
Physically based mode. Horizontal FOV of the physically-based camera is calculated using the focal length and film gate values according to the following formula: FOV_h = 2 * atan(film_gate / (2 * focal_length)) * RAD2DEG |
Properties
int NumScriptableMaterials#
int ReverbMask#
int SourceMask#
int ReflectionViewportMask#
int ViewportMask#
bool ObliqueFrustum#
vec4 ObliqueFrustumPlane#
vec3 Up#
float ZFar#
float ZNear#
float FocalLength#
float FilmGate#
float Fov#
Returns the current vertical field of view of the camera.
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)).
Camera.FOV_FIXED FovFixed#
Camera.FOV_MODE FovMode#
mat4 Projection#
mat4 Offset#
vec3 Position#
mat4 IModelview#
mat4 Modelview#
float OrthoHeight#
Camera.PROJECTION_MODE ProjectionMode#
Members
Camera ( ) #
Constructor. Creates a new camera with default settings:- Modelview, inverse modelview and offset matrices are 4×4 identity matrices.
- FOV is 60 degrees.
- Distance to the near clipping plane is 0.1 unit.
- Distance to the far clipping plane is 10000 units.
- Up direction vector is (0,0,1).
- Viewport, reflection, source and reverb masks are set to 00000001.
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.Arguments
- Material material - Scriptable material to be attached to the camera.
void InsertScriptableMaterial ( int num, Material material ) #
Inserts a new scriptable material into the list of the ones assigned to the camera. To apply a scriptable material globally, use the insertScriptableMaterial() method of the Render class. The order of execution for scripts assigned to scriptable materials is defined by material's number in the camera's list.Arguments
- int num - Position at which a new scriptable material is to be inserted.
- Material material - Scriptable material to be inserted.
void RemoveScriptableMaterial ( int num ) #
Removes the scriptable material with the specified number from the camera.Arguments
- int num - Scriptable material number in the range from 0 to the total number of scriptable materials.
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.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).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
- int num - Scriptable material number in the range from 0 to the total number of scriptable materials.
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
- int num - Scriptable material number in the range from 0 to the total number of scriptable materials.
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.Arguments
- int num_0 - Number of the first scriptable material in the range from 0 to the total number of scriptable materials.
- int num_1 - Number of the second scriptable material in the range from 0 to the total number of scriptable materials.
void ClearScriptableMaterials ( ) #
Clears all scriptable materials attached to the camera.Camera Copy ( Camera camera ) #
Copies the parameters from the source camera to this camera instance.Arguments
- Camera camera - Source camera instance.
Return value
This camera instance.void Swap ( Camera camera ) #
Swaps the parameters between the specified camera and this camera instance.Arguments
- Camera camera - Camera instance.