Class Camera
Describes the camera projection and view. Provides information about how to render scene (viewport location and direction, etc.).
Namespace: FlaxEngine
Assembly: FlaxEngine.CSharp.dll
Syntax
[ActorContextMenu("New/Camera")]
[ActorToolbox("Visuals")]
[Unmanaged]
public sealed class Camera : Actor, ISerializable
Constructors
Camera()
Properties
CustomAspectRatio
Gets or sets the custom aspect ratio. 0 if not use custom value.
Declaration
[EditorOrder(50)]
[Limit(0F, 10F, 0.01F)]
[EditorDisplay("Camera", null)]
[Unmanaged]
public float CustomAspectRatio { get; set; }
Property Value
|
System.Single
|
FarPlane
Gets or sets camera's far plane distance.
Declaration
[EditorOrder(40)]
[Limit(0F, 3.40282347E+38F, 5F)]
[EditorDisplay("Camera", null)]
[ValueCategory]
[Unmanaged]
public float FarPlane { get; set; }
Property Value
|
System.Single
|
FieldOfView
Gets or sets the camera's field of view (in degrees).
Declaration
[EditorOrder(20)]
[Limit(0F, 179F, 1F)]
[EditorDisplay("Camera", "Field Of View")]
[VisibleIf("UsePerspective", false)]
[ValueCategory]
[Unmanaged]
public float FieldOfView { get; set; }
Property Value
|
System.Single
|
Frustum
Gets the frustum.
Declaration
[Unmanaged]
public BoundingFrustum Frustum { get; }
Property Value
|
BoundingFrustum
|
MainCamera
Gets the main camera.
Declaration
[Unmanaged]
public static Camera MainCamera { get; }
Property Value
|
Camera
|
NearPlane
Gets or sets camera's near plane distance.
Declaration
[EditorOrder(30)]
[Limit(0F, 1000F, 0.05F)]
[EditorDisplay("Camera", null)]
[ValueCategory]
[Unmanaged]
public float NearPlane { get; set; }
Property Value
|
System.Single
|
OrthographicScale
Gets or sets the orthographic projection scale.
Declaration
[EditorOrder(60)]
[Limit(0.0001F, 1000F, 0.01F)]
[EditorDisplay("Camera", null)]
[VisibleIf("UsePerspective", true)]
[Unmanaged]
public float OrthographicScale { get; set; }
Property Value
|
System.Single
|
OrthographicSize
Gets or sets the orthographic projection view height (width is based on the aspect ratio). Use 0 for size to be based on the viewport size.
Declaration
[EditorOrder(59)]
[Limit(0F, 3.40282347E+38F, 1F)]
[EditorDisplay("Camera", null)]
[VisibleIf("UsePerspective", true)]
[Unmanaged]
public float OrthographicSize { get; set; }
Property Value
|
System.Single
|
OverrideMainCamera
The overriden main camera.
Declaration
[Unmanaged]
public static Camera OverrideMainCamera { get; set; }
Property Value
|
Camera
|
RenderFlags
Frame rendering flags used to switch between graphics features for this camera.
Declaration
[EditorOrder(110)]
[EditorDisplay("Camera", null)]
[Unmanaged]
public ViewFlags RenderFlags { get; set; }
Property Value
|
ViewFlags
|
RenderLayersMask
The layers mask used for rendering using this camera. Can be used to include or exclude specific actor layers from the drawing.
Declaration
[EditorOrder(100)]
[EditorDisplay("Camera", null)]
[Unmanaged]
public LayersMask RenderLayersMask { get; set; }
Property Value
|
LayersMask
|
RenderMode
Describes frame rendering modes for this camera.
Declaration
[EditorOrder(120)]
[EditorDisplay("Camera", null)]
[Unmanaged]
public ViewMode RenderMode { get; set; }
Property Value
|
ViewMode
|
UsePerspective
Gets or sets the value indicating if camera should use perspective rendering mode, otherwise it will use orthographic projection.
Declaration
[EditorOrder(10)]
[EditorDisplay("Camera", null)]
[Unmanaged]
public bool UsePerspective { get; set; }
Property Value
|
System.Boolean
|
Viewport
Gets the camera viewport.
Declaration
[Unmanaged]
public Viewport Viewport { get; }
Property Value
|
Viewport
|
Remarks
Doesn't include scaling/offset from ViewportRect which is applied to projection matrix in GetMatrices.
ViewportRect
Four values that define where on the screen this camera should be drawn. Measured in normalized coordinates (range 0-1). Order: X, Y, Width, Height. For example (0, 0, 1, 1) means full screen, (0, 0, 0.5, 1) means left half of the screen and (0.5, 0, 0.5, 1) means right half of the screen.
Declaration
[EditorOrder(130)]
[EditorDisplay("Camera", null)]
[Limit(0F, 1F, 0.001F)]
[Unmanaged]
public Float4 ViewportRect { get; set; }
Property Value
|
Float4
|
Methods
ConvertMouseToRay(Float2)
Converts the mouse position to 3D ray.
Declaration
[Unmanaged]
public Ray ConvertMouseToRay(Float2 mousePosition)
Parameters
|
Float2
mousePosition
The mouse position. |
Returns
|
Ray
Mouse ray |
ConvertMouseToRay(Float2, ref Viewport)
Converts the mouse position to 3D ray.
Declaration
[Unmanaged]
public Ray ConvertMouseToRay(Float2 mousePosition, ref Viewport viewport)
Parameters
|
Float2
mousePosition
The mouse position. |
|
Viewport
viewport
The viewport. |
Returns
|
Ray
Mouse ray |
GetMatrices(out Matrix, out Matrix)
Calculates the view and the projection matrices for the camera.
Declaration
[Unmanaged]
public void GetMatrices(out Matrix view, out Matrix projection)
Parameters
|
Matrix
view
The result camera view matrix. |
|
Matrix
projection
The result camera projection matrix. |
GetMatrices(out Matrix, out Matrix, ref Viewport)
Calculates the view and the projection matrices for the camera. Support using custom viewport.
Declaration
[Unmanaged]
public void GetMatrices(out Matrix view, out Matrix projection, ref Viewport viewport)
Parameters
|
Matrix
view
The result camera view matrix. |
|
Matrix
projection
The result camera projection matrix. |
|
Viewport
viewport
The custom output viewport. |
GetMatrices(out Matrix, out Matrix, ref Viewport, ref Vector3)
Calculates the view and the projection matrices for the camera. Support using custom viewport and view origin.
Declaration
[Unmanaged]
public void GetMatrices(out Matrix view, out Matrix projection, ref Viewport viewport, ref Vector3 origin)
Parameters
|
Matrix
view
The result camera view matrix. |
|
Matrix
projection
The result camera projection matrix. |
|
Viewport
viewport
The custom output viewport. |
|
Vector3
origin
The rendering view origin (for relative-to-camera rendering). |
IntersectsItselfEditor(ref Ray, out Single)
Intersection check for editor picking the camera
Declaration
[Unmanaged]
public bool IntersectsItselfEditor(ref Ray ray, out float distance)
Parameters
|
Ray
ray
|
|
System.Single
distance
|
Returns
|
System.Boolean
|
IsPointOnView(Vector3)
Checks if the 3d point of the world is in the camera's field of view.
Declaration
[Unmanaged]
public bool IsPointOnView(Vector3 worldSpaceLocation)
Parameters
|
Vector3
worldSpaceLocation
World Position (XYZ). |
Returns
|
System.Boolean
Returns true if the point is within the field of view. |
ProjectPoint(Vector3, out Float2)
Projects the point from 3D world-space to game window coordinates (in screen pixels for default viewport calculated from Viewport).
Declaration
[Unmanaged]
public void ProjectPoint(Vector3 worldSpaceLocation, out Float2 gameWindowSpaceLocation)
Parameters
|
Vector3
worldSpaceLocation
The input world-space location (XYZ in world). |
|
Float2
gameWindowSpaceLocation
The output game window coordinates (XY in screen pixels). |
ProjectPoint(Vector3, out Float2, ref Viewport)
Projects the point from 3D world-space to the camera viewport-space (in screen pixels for given viewport).
Declaration
[Unmanaged]
public void ProjectPoint(Vector3 worldSpaceLocation, out Float2 cameraViewportSpaceLocation, ref Viewport viewport)
Parameters
|
Vector3
worldSpaceLocation
The input world-space location (XYZ in world). |
|
Float2
cameraViewportSpaceLocation
The output camera viewport-space location (XY in screen pixels). |
|
Viewport
viewport
The viewport. |
UnprojectPoint(Float2, Single, out Vector3)
Converts a game window-space point into a corresponding point in world space.
Declaration
[Unmanaged]
public void UnprojectPoint(Float2 gameWindowSpaceLocation, float depth, out Vector3 worldSpaceLocation)
Parameters
|
Float2
gameWindowSpaceLocation
The input game window coordinates (XY in screen pixels). |
|
System.Single
depth
The input camera-relative depth position (eg. clipping plane). |
|
Vector3
worldSpaceLocation
The output world-space location (XYZ in world). |
UnprojectPoint(Float2, Single, out Vector3, ref Viewport)
Converts a camera viewport-space point into a corresponding point in world space.
Declaration
[Unmanaged]
public void UnprojectPoint(Float2 cameraViewportSpaceLocation, float depth, out Vector3 worldSpaceLocation, ref Viewport viewport)
Parameters
|
Float2
cameraViewportSpaceLocation
The input camera viewport-space location (XY in screen pixels). |
|
System.Single
depth
The input camera-relative depth position (eg. clipping plane). |
|
Vector3
worldSpaceLocation
The output world-space location (XYZ in world). |
|
Viewport
viewport
The viewport. |