AnchorPoint

class rlogic::AnchorPoint : public rlogic::LogicNode

Anchor point is a rlogic::LogicNode which calculates viewport coordinates (and depth) of a Ramses node’s origin. The projected coordinates are accessible via its output property and can be linked to another logic node. Anchor point requires a rlogic::RamsesNodeBinding and a rlogic::RamsesCameraBinding at creation time, see rlogic::LogicEngine::createAnchorPoint.

The update logic retrieves a model matrix from the provided Ramses node (via its binding), a projection and view matrix from the provided Ramses camera (via its binding) and projects a point (0, 0, 0) (which represents origin of the given node’s local space) using those matrices: projectedPoint = projectionMatrix * viewMatrix * modelMatrix * (0, 0, 0, 1) Perspective correction will be applied (relevant only if using perspective camera) and then the result is transformed into viewport space of the given camera, i.e. the final values are coordinates within the camera viewport.

This means that if the given Ramses node represents a transformation of a renderable mesh, the anchor point will calculate where in viewport (or on screen if viewport matches screen dimensions) the origin of the mesh would be rendered. This can be useful for example for 2D overlay graphical elements or text following a 3D object.

  • Property output:

    • viewportCoords (rlogic::EPropertyType::Vec2f)

      • provides [viewportCoordX, viewportCoordY] representing the [X,Y] coordinates of the projected node transformation in viewport space

      • note that it is up to user if and how he decides to round the floating point values to snap to discrete pixels

      • note that the coordinates will not be clamped to the viewport, so viewport coordinates can be negative or larger than viewport width/height if the tracked object is outside of frustum

    • depth (float)

      • non-linear depth in [0,1] range (if within frustum), 0 at near plane, 1 at far plane of the camera frustum (equivalent to the actual value stored in depth buffer for depth testing)

      • note that the depth can be outside of the [0,1] range if the tracked object is outside of frustum

Important note on update order dependency: Unlike other logic nodes the calculation done inside AnchorPoint does not depend on input properties but on states in Ramses scene instead

  • namely node transformations and camera settings. Imagine a case where AnchorPoint tracks a Ramses node and this node’s ancestor (in transformation topology) is being animated by a logic node (animation or script), i.e. the animation indirectly affects the result of AnchorPoint. As this dependency is outside of Ramses logic network (it is in Ramses transformation topology) and identifying it in runtime (can change every frame) by querying Ramses is not feasible, the proper ordering of logic network update is NOT guaranteed in such case. It means the AnchorPoint calculation might be executed first before the animation is and thus giving incorrect (old) result. If you end up using such setup, please use a workaround: UPDATE the rlogic::LogicEngine TWICE, right after each other in every frame/update iteration.

Performance remark: Unlike other logic nodes AnchorPoint does not use dirtiness mechanism monitoring node’s inputs which then updates the outputs only if anything changed. Anchor point depends on Ramses objects and their states, which cannot be easily monitored and therefore it has to be updated every time rlogic::LogicEngine::update is called. For this reason it is highly recommended to keep the number of anchor nodes to a necessary minimum.

Public Functions

const ramses::Node &getRamsesNode() const

Returns given ramses node which is used to calculate coordinates.

Return

Ramses node to track

const ramses::Camera &getRamsesCamera() const

Returns given ramses camera which is used to calculate coordinates.

Return

Ramses camera associated with node to track

AnchorPoint(std::unique_ptr<internal::AnchorPointImpl> impl) noexcept

Constructor of AnchorPoint. User is not supposed to call this - AnchorPoints are created by other factory classes

Parameters

~AnchorPoint() noexcept override

Destructor of AnchorPoint.

AnchorPoint(const AnchorPoint&) = delete

Copy Constructor of AnchorPoint is deleted because AnchorPoints are not supposed to be copied

AnchorPoint(AnchorPoint&&) = delete

Move Constructor of AnchorPoint is deleted because AnchorPoints are not supposed to be moved

AnchorPoint &operator=(const AnchorPoint&) = delete

Assignment operator of AnchorPoint is deleted because AnchorPoints are not supposed to be copied

AnchorPoint &operator=(AnchorPoint&&) = delete

Move assignment operator of AnchorPoint is deleted because AnchorPoints are not supposed to be moved

Public Members

internal::AnchorPointImpl &m_anchorPointImpl

Implementation of AnchorPoint