Camera
Enumerations
- FovAxis
Axis for apply FoV (Field of view) or orhographic size.
Usage of FovAxis Vertical can be useful for 2D render when you want to keep vertical FoV(orhographic size) constant
- Values:
Horizontal = 0 - FoV or orhographic size will be applied to horizontal axis, vertical axis will be rescaled according to aspect ratio.
Vertical = 1 - FoV or orhographic size will be applied to vertical axis, horizontal axis will be rescaled according to aspect ratio.
Classes
- Camera : NativeComponent
This component is used to define a camera in a 3D scene. Without camera on the scene, it won’t be rendered. It contains a view frustum, limited by clipping planes, defines by znear and zfar properties. Objects closer than znear or farther than zfar are clipped and not rendered by the camera.
To add this module to your project, add the following line to your project file:
require engine.core_components.camera_component // or require engine.core
Usage example:
// create node at float3(0, 0, -10) position
var node = create_node(NodeData(position=float3(0, 0, -10)))
// camera with field of view of 60 degrees and zfar clipping plane at a distance of 1000
add_component(node, new Camera(fov=60.0 * PI / 180.0, zfar = 1000.))
- Camera.screenToRay(screen_position: float2): Ray
Converts screen coordinates to a ray in world space.
- Arguments:
screen_position : float2 - the screen coordinates to convert
- Returns:
Ray - a Ray object representing the converted ray
- Camera.worldToScreen(world_position: float3): float3
Converts a world position to screen coordinates.
- Arguments:
world_position : float3 - the world position to convert
- Returns:
float3 - a float3 representing the converted screen coordinates, z represents the depth
- Camera.screenToWorldDepth(screen_position: float2; linear_depth: float): float3
Converts screen coordinates to a world position with a specified linear depth.
- Arguments:
screen_position : float2 - the screen coordinates to convert
linear_depth : float - distance from camera, if z is zero result is undefined for perspective camera
- Returns:
float3 - a float3 representing the converted world position
- Camera.screenToWorld(screen_position: float2): float3
Converts screen coordinates to a world position.
- Arguments:
screen_position : float2 - the screen coordinates to convert
- Returns:
float3 - a float3 representing the converted world position, distance is set to the camera’s near plane
- Properties:
- Camera.znear: float
- Camera.znear =(value: float)
near clipping plane distance. Must be greater than 0. Default is 0.01.
- Arguments:
value : float
- Camera.zfar: float
- Camera.zfar =(value: float)
far clipping plane distance. Must be greater than znear. Default is 10000.
- Arguments:
value : float
- Camera.fov: float
- Camera.fov =(value: float)
field of view in radians. Default is PI * 0.49. ~= 88 degrees.
- Arguments:
value : float
- Camera.fovAxis: FovAxis
- Camera.fovAxis =(value: FovAxis)
is used to specify which axis the fov is along. Default is FovAxis Horizontal.
- Arguments:
value : FovAxis
- Camera.orthographic: bool
- Camera.orthographic =(value: bool)
orthographic projection. Default is false. If true, the camera will use orthographic projection instead of perspective projection.
- Arguments:
value : bool
- Camera.orthographicSize: float
- Camera.orthographicSize =(value: float)
orthographic size. Must be greater than 0. Default is 100.
- Arguments:
value : float
- Camera.viewport: float4
- Camera.viewport =(value: float4)
viewport area float4(x, y, width, height). Default is (0, 0, 1, 1). The rectangle is defined by the upper left corner and the size of the rectangle.
- Arguments:
value : float4
- Camera.backgroundColor: float3
- Camera.backgroundColor =(value: float3)
background color. Default is (0.25, 0.25, 0.25).
- Arguments:
value : float3
- Camera.renderTargetId: TextureId
- Camera.renderTargetId =(value: TextureId)
target to render to. Default is 0.
- Arguments:
value : TextureId
- Camera.layerIdx: int
- Camera.layerIdx =(value: int)
layer of camera. Can be used to exclude some meshes from render. See MeshVisibility. Default is 0.
- Arguments:
value : int
- Camera.renderSettings: NodeId
- Camera.renderSettings =(value: NodeId)
specified render settings node. Default is NodeId() which means default render settings.
- Arguments:
value : NodeId
- Camera.worldToScreenTransform: float4x4
world to screen matrix. This matrix is used to convert world space coordinates to screen space coordinates.
- Camera.screenToWorldTransform: float4x4
screen to world matrix. This matrix is used to convert screen space coordinates to world space coordinates.
- Camera.projection: float4x4
projection matrix. This matrix used for projection position from frustum to unit box.