esp::gfx::RenderCamera class

Derived classes

class CubeMapCamera

Public types

enum class Flag: unsigned int { FrustumCulling = 1 << 0, ObjectsOnly = 1 << 1, UseDrawableIdAsObjectId = 1 << 2, ClearDepth = 1 << 3, ClearColor = 1 << 4, ClearObjectId = 1 << 5 }
Rendering Flags.
using Flags = Corrade::Containers::EnumSet<Flag>
using DrawableTransforms = std::vector<std::pair<std::reference_wrapper<Magnum::SceneGraph::Drawable3D>, Magnum::Matrix4>>

Constructors, destructors, conversion operators

RenderCamera(scene::SceneNode& node) explicit
Constructor.
RenderCamera(scene::SceneNode& node, const vec3f& eye, const vec3f& target, const vec3f& up)
Constructor.
RenderCamera(scene::SceneNode& node, const Magnum::Vector3& eye, const Magnum::Vector3& target, const Magnum::Vector3& up)
Constructor.
~RenderCamera() defaulted override
destructor do nothing, let magnum handle the camera

Public functions

auto resetViewingParameters(const Magnum::Vector3& eye, const Magnum::Vector3& target, const Magnum::Vector3& up) -> RenderCamera& virtual
Reset the initial viewing parameters of the camera.
auto isInSceneGraph(const scene::SceneGraph& sceneGraph) -> bool
Tell if the camera is attached to the scene graph.
auto node() -> scene::SceneNode&
Get the scene node being attached to.
auto node() const -> const scene::SceneNode&
Get a const ref to the scene node being attached to.
auto object() -> scene::SceneNode&
auto object() const -> const scene::SceneNode&
auto setProjectionMatrix(int width, int height, Mn::Matrix4& projMat) -> RenderCamera&
Set precalculated projection matrix for this RenderCamera.
auto setProjectionMatrix(int width, int height, float znear, float zfar, Mn::Deg hfov) -> RenderCamera&
Set precalculated projection matrix for this RenderCamera.
auto setOrthoProjectionMatrix(int width, int height, float znear, float zfar, float scale) -> RenderCamera&
Set projection matrix for Orthographic camera.
auto draw(MagnumDrawableGroup& drawables, Flags flags = {}) -> uint32_t
Overload function to render the drawables.
auto draw(DrawableTransforms& drawableTransforms, Flags flags = {}) -> uint32_t
auto cull(DrawableTransforms& drawableTransforms) -> size_t
performs the frustum culling
auto removeNonObjects(DrawableTransforms& drawableTransforms) -> size_t
Cull Drawables for SceneNodes which are not OBJECT type.
auto filterTransforms(DrawableTransforms& drawableTransforms, Flags flags = {}) -> size_t
auto useDrawableIds() const -> bool
if the "immediate" following rendering pass is to use drawable ids as the object ids. By default, it uses the semantic_id, stored in the drawable's scene graph node, if no "per-vertex" object id is used.
auto unproject(const Mn::Vector2i& viewportPosition, bool normalized = true) -> esp::geo::Ray
Unproject a 2D viewport point to a 3D ray with origin at camera position. Ray direction is optionally normalized. Non-normalized rays originate at the camera location and terminate at a view plane one unit down the Z axis.
auto getPreviousNumVisibleDrawables() const -> size_t
Query the cached number of Drawables visible after frustum culling for the most recent render pass.

Protected variables

Mn::Matrix4 invertedProjectionMatrix
size_t previousNumVisibleDrawables_
bool useDrawableIds_

Enum documentation

enum class esp::gfx::RenderCamera::Flag: unsigned int

Rendering Flags.

Enumerators
FrustumCulling

Cull Drawables with bounding boxes not intersecting the camera frustum.

ObjectsOnly

Cull Drawables not attached to SceneNodes with scene::SceneNodeType::OBJECT.

UseDrawableIdAsObjectId

Use drawable id as the object id in the following rendering pass Internally, it is not a state machine, which means user needs to set it every frame if she needs the drawable ids. If not set, by default, it would use the semantic id (if "per vertex object id" is not set)

ClearDepth

Clear depth, used in the sub-class CubeMapCamera

ClearColor

Clear color, used in the sub-class CubeMapCamera

ClearObjectId

Clear object id, used in the sub-class CubeMapCamera

Function documentation

esp::gfx::RenderCamera::RenderCamera(scene::SceneNode& node) explicit

Constructor.

Parameters
node the scene node to which the camera is attached

esp::gfx::RenderCamera::RenderCamera(scene::SceneNode& node, const vec3f& eye, const vec3f& target, const vec3f& up)

Constructor.

Parameters
node the scene node to which the camera is attached
eye the eye position (in PARENT node space)
target the target position (in PARENT node space)
up the up direction (in PARENT node space) NOTE: it will override any relative transformation w.r.t its parent node

esp::gfx::RenderCamera::RenderCamera(scene::SceneNode& node, const Magnum::Vector3& eye, const Magnum::Vector3& target, const Magnum::Vector3& up)

Constructor.

Parameters
node the scene node to which the camera is attached
eye the eye position (in PARENT node space)
target the target position (in PARENT node space)
up the up direction (in PARENT node space) NOTE: it will override any relative transformation w.r.t its parent node

RenderCamera& esp::gfx::RenderCamera::resetViewingParameters(const Magnum::Vector3& eye, const Magnum::Vector3& target, const Magnum::Vector3& up) virtual

Reset the initial viewing parameters of the camera.

Parameters
eye the eye position (in PARENT node space)
target the target position (in PARENT node space)
up the up direction (in PARENT node space)
Returns Reference to self (for method chaining) NOTE: it will override any relative transformation w.r.t its parent node

bool esp::gfx::RenderCamera::isInSceneGraph(const scene::SceneGraph& sceneGraph)

Tell if the camera is attached to the scene graph.

Returns true if it is attached to this scene graph, otherwise false

scene::SceneNode& esp::gfx::RenderCamera::object()

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

const scene::SceneNode& esp::gfx::RenderCamera::object() const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

RenderCamera& esp::gfx::RenderCamera::setProjectionMatrix(int width, int height, Mn::Matrix4& projMat)

Set precalculated projection matrix for this RenderCamera.

Parameters
width The width of the viewport
height The height of the viewport
projMat The projection matrix to use.
Returns A reference to this RenderCamera

RenderCamera& esp::gfx::RenderCamera::setProjectionMatrix(int width, int height, float znear, float zfar, Mn::Deg hfov)

Set precalculated projection matrix for this RenderCamera.

Parameters
width The width of the viewport
height The height of the viewport
znear The location of the near clipping plane
zfar The location of the far clipping plane
hfov The horizontal field of view.
Returns A reference to this RenderCamera

RenderCamera& esp::gfx::RenderCamera::setOrthoProjectionMatrix(int width, int height, float znear, float zfar, float scale)

Set projection matrix for Orthographic camera.

Parameters
width The width of the viewport
height The height of the viewport
znear The location of the near clipping plane
zfar The location of the far clipping plane
scale A multiplier to scale the size of the resultant image.
Returns A reference to this RenderCamera

uint32_t esp::gfx::RenderCamera::draw(MagnumDrawableGroup& drawables, Flags flags = {})

Overload function to render the drawables.

Parameters
drawables a drawable group containing all the drawables
flags state flags to direct drawing
Returns the number of drawables that are drawn

size_t esp::gfx::RenderCamera::cull(DrawableTransforms& drawableTransforms)

performs the frustum culling

Parameters
drawableTransforms a vector of pairs of Drawable3D object and its absolute transformation
Returns the number of drawables that are not culled

NOTE: user are not encouraged to call this function directly. The preferred way is to enable the frustum culling by calling setFrustumCullingEnabled and then call draw

size_t esp::gfx::RenderCamera::removeNonObjects(DrawableTransforms& drawableTransforms)

Cull Drawables for SceneNodes which are not OBJECT type.

Parameters
drawableTransforms a vector of pairs of Drawable3D object and its absolute transformation
Returns the number of drawables that are not culled

bool esp::gfx::RenderCamera::useDrawableIds() const

if the "immediate" following rendering pass is to use drawable ids as the object ids. By default, it uses the semantic_id, stored in the drawable's scene graph node, if no "per-vertex" object id is used.

Returns true, if it is to use drawable ids as the object ids in the following rendering pass, otherwise false

esp::geo::Ray esp::gfx::RenderCamera::unproject(const Mn::Vector2i& viewportPosition, bool normalized = true)

Unproject a 2D viewport point to a 3D ray with origin at camera position. Ray direction is optionally normalized. Non-normalized rays originate at the camera location and terminate at a view plane one unit down the Z axis.

Parameters
viewportPosition The 2D point on the viewport to unproject ([0,width], [0,height]).
normalized If true(default), normalize ray direction.
Returns a esp::geo::Ray with unit length direction or zero direction if failed.

Variable documentation

Mn::Matrix4 esp::gfx::RenderCamera::invertedProjectionMatrix protected

cached inverted projection matrix to save compute on repeated calls (e.g. to unproject) without moving the camera