Class Camera¶
-
class Camera¶
Public Types
Public Functions
-
Camera()¶
-
~Camera()¶
-
void update(float deltaTime)¶
-
bool attach()¶
Attaches the camera for rendering, applying its viewport and scissor.
For surface targets this also attaches the surface and a depth buffer.
- Returns:
false if the camera renders nothing this frame (no or deleted surface target)
-
void detach()¶
Counterpart to ‘attach’, detaches a surface target again.
NOP for cameras rendering to the screen.
-
inline bool isSurfaceAttached() const¶
true if ‘attach’ redirected rendering into a surface, until ‘detach’ is called
-
void applyTargetImages()¶
Records commands to redirect rendering into the camera’s attached surface target.
Only needed for command streams outside of ‘attach’/’detach’, e.g. draw-layers. NOP if no surface target is attached.
-
void restoreTargetImages()¶
Counterpart to ‘applyTargetImages’, records commands to restore the render pipeline’s framebuffer and depth buffer.
NOP if no surface target is attached.
-
inline void reApplyScissor()¶
Re-applies the scissor-area defined via the viewport.
This can be useful if you changed the scissor-area and now wish to reset it.
-
void setScreenArea(int x, int y, int width, int height)¶
-
inline void setPerspective(float newFov)¶
Switches the camera over to a perspective projection.
- Parameters:
newFov – vertical fov in radians
-
inline void setOrthographic(float newOrthoSize)¶
Switches the camera over to an orthographic projection.
- Parameters:
newOrthoSize – vertical half-size of the view volume in world units
-
inline void setProjection(Projection newProjection)¶
Switches between perspective and orthographic projection, keeping the settings (fov / ortho-size) of both.
-
inline Projection getProjection() const¶
-
void setTargetScreen()¶
Renders to the screen (framebuffer) again, undoing ‘setTargetSurface’.
This also restores the viewport to the last area set via ‘setScreenArea’.
-
void setTargetSurface(Object *obj)¶
Renders into the first Surface component of the given object instead of the screen.
If the object is nullptr or has no Surface component, the camera renders nothing. The surface must be in a format the RDP can render to (RGBA16, RGBA32 or I8/CI8).
- Parameters:
obj – object owning a Surface component, or nullptr to render nothing
-
inline void setTargetSurface(surface_t *surf, surface_t *depth = nullptr)¶
Renders into the given raw surface instead of the screen.
If nullptr is passed, the camera renders nothing. The surface must be in a format the RDP can render to (RGBA16, RGBA32 or I8/CI8). Note: the caller must keep the surfaces alive while they are targeted, for automatic lifetime handling target an object with a Surface component instead.
- Parameters:
surf – surface to render into, or nullptr to render nothing
depth – optional depth buffer, must be at least the size of ‘surf’. If nullptr, the main depth buffer is re-used.
-
inline void setTargetSurface(std::nullptr_t)¶
Switches to surface mode without a target, making the camera render nothing.
-
inline bool hasSurfaceTarget() const¶
-
Comp::Surface *resolveTargetSurface() const¶
Resolves the current target Surface component.
- Returns:
component, or nullptr if none is set or its owner was deleted
- void setLookAt(
- const fm_vec3_t &newPos,
- const fm_vec3_t &newTarget,
- const fm_vec3_t &newUp = {0, 1, 0}
Sets new camera values based on a look-at transform.
If you have an arbitrary rotation based camera prefer using ‘setPosRot’.
- Parameters:
newPos – camera eye
newTarget – camera target
newUp – camera up vector (+Y by default)
-
void setPosRot(const fm_vec3_t &newPos, const fm_quat_t &rot)¶
Sets a new camera by position and rotation.
If you have a look-at based camera prefer using ‘setLookAt’.
- Parameters:
pos – camera eye
rot – rotation
-
inline const fm_vec3_t &getTarget() const¶
-
inline const fm_vec3_t &getPos() const¶
-
inline fm_vec3_t getViewDir() const¶
-
inline const fm_mat4_t &getViewMatrix() const¶
-
inline const fm_vec3_t &getUp() const¶
-
fm_vec3_t getScreenPos(const fm_vec3_t &worldPos)¶
Public Members
-
float fov = {}¶
-
float near = {}¶
-
float far = {}¶
-
float aspectRatio = {}¶
-
float orthoSize = {}¶
-
Projection projection = {Projection::PERSPECTIVE}¶
-
uint8_t visMask = {0xFF}¶
-
TargetType targetType = {TargetType::SCREEN}¶
-
uint16_t targetObjId = {0}¶
-
surface_t *targetSurfPtr = {}¶
-
surface_t *targetDepthPtr = {}¶
-
Camera()¶