Camera¶
Description¶
Camera defines the viewpoint from which the scene is rendered. It supports both orthographic (2D) and perspective (3D) projection, a look-at target, manual navigation helpers (walk, slide, orbit), and render-to-texture via an internal Framebuffer.
Inherits: Object → EntityHandle
Properties¶
| Type | Name | Default | Languages |
|---|---|---|---|
| CameraType | type | ORTHOGRAPHIC |
C++ | Lua |
| bool | autoResize | true |
C++ | Lua |
| float | nearClip | 0.1 |
C++ | Lua |
| float | farClip | 1000.0 |
C++ | Lua |
| float | leftClip | — | C++ | Lua |
| float | rightClip | — | C++ | Lua |
| float | bottomClip | — | C++ | Lua |
| float | topClip | — | C++ | Lua |
| float | aspect | — | C++ | Lua |
| float | yfov | 60.0° |
C++ | Lua |
| Vector3 | target | (0,0,0) |
C++ | Lua |
| Vector3 | up | (0,1,0) |
C++ | Lua |
| bool | renderToTexture | false |
C++ | Lua |
| bool | transparentSort | true |
C++ | Lua |
Methods¶
| Returns | Name | Languages |
|---|---|---|
| void | activate | C++ | Lua |
| void | setOrtho | C++ | Lua |
| void | setPerspective | C++ | Lua |
| void | setAutoResize | C++ | Lua |
| bool | isAutoResize | C++ | Lua |
| void | setNearClip | C++ | Lua |
| float | getNearClip | C++ | Lua |
| void | setFarClip | C++ | Lua |
| float | getFarClip | C++ | Lua |
| void | setLeftClip | C++ | Lua |
| float | getLeftClip | C++ | Lua |
| void | setRightClip | C++ | Lua |
| float | getRightClip | C++ | Lua |
| void | setBottomClip | C++ | Lua |
| float | getBottomClip | C++ | Lua |
| void | setTopClip | C++ | Lua |
| float | getTopClip | C++ | Lua |
| void | setAspect | C++ | Lua |
| float | getAspect | C++ | Lua |
| void | setYFov | C++ | Lua |
| float | getYFov | C++ | Lua |
| void | setType | C++ | Lua |
| CameraType | getType | C++ | Lua |
| void | setTarget | C++ | Lua |
| Vector3 | getTarget | C++ | Lua |
| void | disableTarget | C++ | Lua |
| bool | isUsingTarget | C++ | Lua |
| void | setUp | C++ | Lua |
| Vector3 | getUp | C++ | Lua |
| Vector3 | getDirection | C++ | Lua |
| Vector3 | getRight | C++ | Lua |
| Vector3 | getWorldTarget | C++ | Lua |
| Vector3 | getWorldDirection | C++ | Lua |
| Vector3 | getWorldUp | C++ | Lua |
| Vector3 | getWorldRight | C++ | Lua |
| Matrix4 | getViewMatrix | C++ | Lua |
| Matrix4 | getProjectionMatrix | C++ | Lua |
| Matrix4 | getViewProjectionMatrix | C++ | Lua |
| void | rotateView | C++ | Lua |
| void | rotatePosition | C++ | Lua |
| void | elevateView | C++ | Lua |
| void | elevatePosition | C++ | Lua |
| void | walkForward | C++ | Lua |
| void | zoom | C++ | Lua |
| void | slide | C++ | Lua |
| void | slideForward | C++ | Lua |
| void | slideUp | C++ | Lua |
| void | setRenderToTexture | C++ | Lua |
| bool | isRenderToTexture | C++ | Lua |
| Framebuffer* | getFramebuffer | C++ | Lua |
| void | setFramebufferSize | C++ | Lua |
| void | setFramebufferFilter | C++ | Lua |
| void | setTransparentSort | C++ | Lua |
| bool | isTransparentSort | C++ | Lua |
| Ray | screenToRay | C++ | Lua |
| float | getDistanceFromTarget | C++ | Lua |
| void | updateCamera | C++ | Lua |
Enumerations¶
CameraType¶
- ORTHOGRAPHIC — Parallel projection; objects do not shrink with distance. Used for 2D games and UI.
- PERSPECTIVE — Frustum projection; objects appear smaller with distance. Used for 3D scenes.
Property details¶
type¶
- Setter:
void setType(CameraType type) - Getter:
CameraType getType() const
Switches between orthographic and perspective projection. Setting the type does not automatically recalculate clip planes; use setOrtho or setPerspective for that.
autoResize¶
- Setter:
void setAutoResize(bool autoResize) - Getter:
bool isAutoResize() const
When true (default), the projection is automatically recalculated when the canvas size changes. Disable if you manage the projection matrix manually.
nearClip / farClip¶
- Setters:
void setNearClip(float nearValue)/void setFarClip(float farValue) - Getters:
float getNearClip() const/float getFarClip() const
Near and far clip plane distances. Objects closer than nearClip or further than farClip are not rendered. Tighten these bounds to maximise depth-buffer precision.
leftClip / rightClip / bottomClip / topClip¶
Orthographic frustum extents. Set via setOrtho or individually. In auto-resize mode the engine keeps these aligned to the canvas.
aspect¶
- Setter:
void setAspect(float aspect) - Getter:
float getAspect() const
Width-to-height ratio for perspective projection. In auto-resize mode the engine updates this automatically.
yfov¶
- Setter:
void setYFov(float yfov) - Getter:
float getYFov() const
Vertical field-of-view in degrees (when Engine::useDegrees is true). Affects how wide the perspective frustum opens.
target¶
- Setter:
void setTarget(Vector3 target)/void setTarget(float x, float y, float z) - Getter:
Vector3 getTarget() const
Look-at point in local space. When set, the camera orientation is computed each frame so the camera always faces this point. Disable with disableTarget.
up¶
- Setter:
void setUp(Vector3 up)/void setUp(float x, float y, float z) - Getter:
Vector3 getUp() const
Local up vector used when computing the view matrix from a target. Defaults to (0, 1, 0).
renderToTexture¶
- Setter:
void setRenderToTexture(bool renderToTexture) - Getter:
bool isRenderToTexture() const
When true, the camera renders to an internal Framebuffer instead of the main window surface. Retrieve the framebuffer with getFramebuffer() and pass it to a Mesh::setTexture call to create render-to-texture effects.
transparentSort¶
- Setter:
void setTransparentSort(bool transparentSort) - Getter:
bool isTransparentSort() const
Enables back-to-front depth sorting for transparent objects from this camera's viewpoint. Disable for orthographic UI cameras where order is determined by hierarchy.
Method details¶
activate¶
void activate()
Makes this camera the active camera in its scene. Equivalent to calling scene.setCamera(this).
setOrtho¶
void setOrtho(float left, float right, float bottom, float top, float nearValue, float farValue)
Configures the camera for orthographic projection with explicit clip planes. All objects within the box (left, right, bottom, top, near, far) are rendered.
setPerspective¶
void setPerspective(float yfov, float aspect, float nearValue, float farValue)
Configures the camera for perspective (3D) projection.
- yfov — Vertical field-of-view in degrees.
- aspect — Width ÷ height ratio.
- nearValue — Near clip plane distance (keep as large as possible).
- farValue — Far clip plane distance.
setTarget / disableTarget / isUsingTarget¶
void setTarget(Vector3 target)— Sets the look-at point. Activates target mode.void disableTarget()— Removes the look-at constraint and allows free rotation.bool isUsingTarget() const— Returnstruewhile target mode is active.
getDirection / getRight¶
Vector3 getDirection() const— Local forward vector in camera space.Vector3 getRight() const— Local right vector in camera space.
Use getWorldDirection(), getWorldUp(), getWorldRight() for world-space equivalents.
getViewMatrix / getProjectionMatrix / getViewProjectionMatrix¶
Computed matrices ready to pass to shaders or custom render pipelines.
rotateView¶
void rotateView(float angle)
Rotates the camera's look direction around the up axis by angle degrees (yaw). The camera position stays fixed.
rotatePosition¶
void rotatePosition(float angle)
Orbits the camera's position around the current target by angle degrees. Useful for orbit camera controllers.
elevateView¶
void elevateView(float angle)
Tilts the camera's look direction up or down (pitch) by angle degrees. Position stays fixed.
elevatePosition¶
void elevatePosition(float angle)
Moves the camera position up or down along a sphere centered at target. Useful for orbit elevation.
walkForward¶
void walkForward(float distance)
Moves the camera forward along its look direction by distance units.
zoom¶
void zoom(float distance)
Moves the camera position along the direction toward target by distance units. A positive value zooms in; negative zooms out.
slide / slideForward / slideUp¶
void slide(float distance)— Strafes along the local right vector.void slideForward(float distance)— Moves along the local forward vector.void slideUp(float distance)— Moves along the local up vector.
screenToRay¶
Ray screenToRay(float x, float y)
Converts a screen-space position (in canvas pixels) to a world-space Ray for mouse picking.
getDistanceFromTarget¶
float getDistanceFromTarget() const
Returns the distance between the camera position and the current target point. Useful for zoom limits in orbit controllers.
setRenderToTexture / getFramebuffer / setFramebufferSize / setFramebufferFilter¶
Configure render-to-texture mode.
void setRenderToTexture(bool renderToTexture)— Enable/disable off-screen rendering.Framebuffer* getFramebuffer()— Returns the internal framebuffer; valid only aftersetRenderToTexture(true).void setFramebufferSize(int width, int height)— Overrides the framebuffer resolution (defaults to canvas size).void setFramebufferFilter(TextureFilter filter)— Sets the sampling filter for the output texture.
updateCamera¶
void updateCamera()
Forces an immediate recalculation of view and projection matrices. Called automatically each frame; call manually only when you need a fresh matrix outside the normal update cycle.