Camera
in package
Table of Contents
Properties
- $allowInterpolation : bool
- If enabled, the camera will interpolate its position and orientation from the previous frame to the current frame given the delta time.
- $farPlane : float
- The cameras far plane distance This is the distance from the camera to the far clipping plane, aka the furthest distance at which objects will be rendered.
- $fieldOfView : float
- The cameras field of view (FOV)
- $flipViewportY : bool
- Flip the viewport on the y axis The camera by default uses y+ as up, this will flip the viewport to use y- as up.
- $nearPlane : float
- The cameras near plane distance This is the distance from the camera to the near clipping plane, aka the closest distance at which objects will be rendered.
- $projectionMode : CameraProjectionMode
- The cameras projection mode
- $staticWorldHeight : float
- Fixed world height in units for orthographic static world projection mode
- $transform : Transform
- The camera's transform / location, orientation in space
- $zoom : float
- Camera Zoom
- $interpolationTransformAlloc : Transform
- Internal holder for a temporary transform instance used for interpolation
- $lfCameraPos : Vec3
- Holds the cameras position from the last frame
- $lfCameraRot : Quat
- Holds the cameras orientation from the last frame
- $projectionMatrixAlloc : Mat4
- Internal holder for the projection view matrix
Methods
- __construct() : mixed
- Camera constructor.
- createCameraData() : CameraData
- Creates and returns a camera data instance for the given render target and delta time.
- finalizeFrame() : void
- Calling this method will store the current camera position and orientation as the previous frame. This is used for interpolation.
- getModelMatrix() : Mat4
- Returns the model matrix of the camera This is basically the inverse of the cameras view matrix.
- getProjectionMatrix() : Mat4
- Calculates and retuns the cameras projection matrix.
- getSSDirection() : Vec3
- Calculates and returns the ray direction of the camera at the given screen position.
- getSSPointFromWS() : Vec2
- Returns a screen space position from the given world space position.
- getSSRay() : Ray
- Creates a Ray instance from the camera at the given screen position.
- getViewMatrix() : Mat4
- Calculates and returns the cameras view matrix. The matrix is inverted on the fly so cache the result if you need to use it multiple times.
- getViewport() : Viewport
- Returns a viewport for the given render target This will only work for orthographic projection modes.
- getViewProjectionMatrix() : Mat4
- Calculates and returns the cameras view projection matrix.
- getWSPointFromSS() : Vec2
- Returns a world space position from the given screen space position.
- transformVGSpace() : void
- Will translate and scale the given VGContext to match the cameras viewport.
Properties
$allowInterpolation
If enabled, the camera will interpolate its position and orientation from the previous frame to the current frame given the delta time.
public
bool
$allowInterpolation
= true
When enabled you will have to call finalizeFrame at the end of each frame.
$farPlane
The cameras far plane distance This is the distance from the camera to the far clipping plane, aka the furthest distance at which objects will be rendered.
public
float
$farPlane
= 65536.0
$fieldOfView
The cameras field of view (FOV)
public
float
$fieldOfView
= 45.0
$flipViewportY
Flip the viewport on the y axis The camera by default uses y+ as up, this will flip the viewport to use y- as up.
public
bool
$flipViewportY
= false
When you want to use the camera with a vector graphics context you will want to flip the viewport.
$nearPlane
The cameras near plane distance This is the distance from the camera to the near clipping plane, aka the closest distance at which objects will be rendered.
public
float
$nearPlane
= 0.1
$projectionMode
The cameras projection mode
public
CameraProjectionMode
$projectionMode
$staticWorldHeight
Fixed world height in units for orthographic static world projection mode
public
float
$staticWorldHeight
= 100.0
$transform
The camera's transform / location, orientation in space
public
Transform
$transform
$zoom
Camera Zoom
public
float
$zoom
= 1.0
Only applies to orthographic projection modes and vg contexts.
$interpolationTransformAlloc
Internal holder for a temporary transform instance used for interpolation
private
Transform
$interpolationTransformAlloc
$lfCameraPos
Holds the cameras position from the last frame
private
Vec3
$lfCameraPos
$lfCameraRot
Holds the cameras orientation from the last frame
private
Quat
$lfCameraRot
$projectionMatrixAlloc
Internal holder for the projection view matrix
private
Mat4
$projectionMatrixAlloc
Methods
__construct()
Camera constructor.
public
__construct(CameraProjectionMode $mode[, Transform|null $transform = null ]) : mixed
Parameters
- $mode : CameraProjectionMode
-
The cameras projection mode
- $transform : Transform|null = null
-
The inital cameras transform, note this is by reference! (Its PHP..)
createCameraData()
Creates and returns a camera data instance for the given render target and delta time.
public
createCameraData(RenderTarget $renderTarget[, float $compensation = 0.0 ]) : CameraData
Parameters
- $renderTarget : RenderTarget
- $compensation : float = 0.0
Return values
CameraDatafinalizeFrame()
Calling this method will store the current camera position and orientation as the previous frame. This is used for interpolation.
public
finalizeFrame() : void
getModelMatrix()
Returns the model matrix of the camera This is basically the inverse of the cameras view matrix.
public
getModelMatrix([float $deltaTime = 0.0 ]) : Mat4
Parameters
- $deltaTime : float = 0.0
Return values
Mat4 —The model matrix of the camera
getProjectionMatrix()
Calculates and retuns the cameras projection matrix.
public
getProjectionMatrix(RenderTarget $renderTarget) : Mat4
Parameters
- $renderTarget : RenderTarget
-
The render target to calculate the projection matrix for
Return values
Mat4 —A copy of the calculated projection matrix
getSSDirection()
Calculates and returns the ray direction of the camera at the given screen position.
public
getSSDirection(RenderTarget $renderTarget, Vec2 $screenPos) : Vec3
Warning: This method is rather expensive, use it sparingly.
Parameters
- $renderTarget : RenderTarget
- $screenPos : Vec2
Return values
Vec3getSSPointFromWS()
Returns a screen space position from the given world space position.
public
getSSPointFromWS(Viewport $viewport, Vec2 $viewSpacePos) : Vec2
Parameters
- $viewport : Viewport
- $viewSpacePos : Vec2
Return values
Vec2getSSRay()
Creates a Ray instance from the camera at the given screen position.
public
getSSRay(RenderTarget $renderTarget, Vec2 $screenPos) : Ray
Warning: This method is rather expensive, use it sparingly.
Parameters
- $renderTarget : RenderTarget
- $screenPos : Vec2
Return values
RaygetViewMatrix()
Calculates and returns the cameras view matrix. The matrix is inverted on the fly so cache the result if you need to use it multiple times.
public
getViewMatrix([float $deltaTime = 0.0 ]) : Mat4
Parameters
- $deltaTime : float = 0.0
-
The delta time since the last frame
Return values
Mat4 —A copy of the calculated view matrix
getViewport()
Returns a viewport for the given render target This will only work for orthographic projection modes.
public
getViewport(RenderTarget $renderTarget) : Viewport
Parameters
- $renderTarget : RenderTarget
-
The render target to calculate the viewport for
Return values
Viewport —The calculated viewport
getViewProjectionMatrix()
Calculates and returns the cameras view projection matrix.
public
getViewProjectionMatrix(RenderTarget $renderTarget[, float $deltaTime = 0.0 ]) : Mat4
Parameters
- $renderTarget : RenderTarget
- $deltaTime : float = 0.0
Return values
Mat4getWSPointFromSS()
Returns a world space position from the given screen space position.
public
getWSPointFromSS(Viewport $viewport, Vec2 $screenSpacePos) : Vec2
Parameters
- $viewport : Viewport
- $screenSpacePos : Vec2
Return values
Vec2transformVGSpace()
Will translate and scale the given VGContext to match the cameras viewport.
public
transformVGSpace(Viewport $viewport, VGContext $vg) : void
Parameters
- $viewport : Viewport
- $vg : VGContext