VR-Engage  2.3
Loading...
Searching...
No Matches
makVre::DtEntityOverlayComponent Class Reference

Detailed Description

This component demonstrates how to:

  • Track multiple entities in the simulation
  • Project 3D world positions to 2D screen coordinates each frame
  • Update QML overlays with entity information via the attribute store
  • Handle entities going on/off screen

The component inherits from DtQtQuickOverlay and combines QML overlay rendering with entity tracking logic. Each frame, it:

  1. Queries entity positions from the EntityResolver
  2. Projects 3D positions to screen coordinates using the main channel
  3. Updates the player attribute store with screen positions + entity data
  4. QML reactively displays items at the calculated positions
See also
DtQtQuickOverlay for QML overlay base functionality
DtPlayerAttributeStore for reactive data binding with QML

#include <entityOverlayComponent.h>

Inheritance diagram for makVre::DtEntityOverlayComponent:
[legend]

Public Member Functions

 DtEntityOverlayComponent ()
 
virtual ~DtEntityOverlayComponent () override
 
virtual const char * type () const override
 
virtual bool initialize (DtPlayerStation *player, DtInitTable &config) override
 
virtual bool postInitialize () override
 
virtual void tick (double dt) override
 
virtual void shutdown () override
 
virtual void initdoc (QQuickItem *rootItem) override
 
- Public Member Functions inherited from makVre::DtQtQuickOverlay
 DtQtQuickOverlay ()
 
virtual ~DtQtQuickOverlay () override
 
virtual void setRoot (QQuickItem *root)
 
virtual DtVreMessageResult handleEnterPlayerState (DtVreMessage *msg)
 
virtual DtVreMessageResult handleExitPlayerState (DtVreMessage *msg)
 
virtual void setVisibility (bool visible)
 
virtual bool isVisible ()
 
virtual void setMenuState (bool on)
 
- Public Member Functions inherited from makVre::DtPlayerComponent
 DtPlayerComponent ()
 
virtual ~DtPlayerComponent ()
 
bool componentReady () const
 
void setComponentReady (bool ready)
 
virtual DtInitTickStatus finalizeInitTick (double dt)
 
virtual void setName (const std::string &name)
 
virtual const std::string & name ()
 
virtual DtPlayerStation & player ()
 
virtual DtAttributeHandle & playerAttributeStore ()
 
virtual const DtAttributeHandle & playerAttributeStore () const
 
virtual const DtAttributeHandle & ownshipState () const
 
virtual void setExtendedData (const std::string &key, const std::string &value, DtEntityIdentifier entity=DtEntityIdentifier::nullId())
 

Protected Member Functions

virtual void updateEntityData ()
 
virtual void populateEntityData (EntityOverlayInfo &info, DtAttributeHandle &entityRootAttr)
 
virtual void ensureEntityTracked (const DtUUID &uuid, const std::string &entityIdStr)
 
virtual void getEntityTopWorldPosition (DtAttributeHandle &entityAttrRoot, makVrv::DtSceneObject *sceneObj, DtVector &sceneObjPoint, DtVector &worldPoint) const
 
virtual void removeStaleTrackedEntities (const SensorContactsMap &contacts)
 
virtual double computeScreenHeightOffset (const DtVector &sceneObjPoint, double heightAboveEntity, makVrv::DtSceneObject *sceneObj, double baseScreenY) const
 
virtual void onOverlayEnabledChanged (bool enabled)
 
- Protected Member Functions inherited from makVre::DtQtQuickOverlay
virtual void updateVals (double dt)
 
virtual void disconnect ()
 
virtual bool buildConnections (DtInitTable &connections)
 
virtual void onVisibilityAttributeChanged (bool on)
 
virtual void removeModelSetAndSkyFromChannel ()
 
virtual void restoreModelSetAndSkyToChannel ()
 
- Protected Member Functions inherited from makVre::DtPlayerComponent
virtual void initializeStateAttributes ()
 

Protected Attributes

DtAttributeHandleType< SensorContactsMap > mySensorContactsAttr
 
TrackedEntitiesMap myTrackedEntitesMap
 
std::unordered_set< std::string > myExternalEntityAttributes
 
QObject * myQmlDataObject
 
double myAdditionalHeightAboveEntity
 
std::string mySensorName
 
DtAttributeHandleType< bool > myOverlayEnabledAttr
 
- Protected Attributes inherited from makVre::DtQtQuickOverlay
DtInitTable myBindQmlPropertyToAttribute
 
QQuickItem * myRoot
 
std::string myTargetWindow
 
std::vector< Connection > myConnections
 
std::string myQmlFile
 
std::string myQmlDataItemName
 
bool myIsInMenuState
 
bool myCachedVisibility
 
DtAttributeHandleType< bool > myVisibilityAttribute
 
bool myRenderOverlayOnly
 
bool myWantSceneHidden
 
makVrv::DtOsgChannel * myChannel
 
makVrv::DtObserverObject * myObserver
 
QObject myQObject
 
bool myHasTickFunction
 
bool myShowInMenus = false
 
- Protected Attributes inherited from makVre::DtPlayerComponent
bool myComponentReady = true
 
std::string myName
 
DtInitTable myConfig
 
DtPlayerStation * myPlayer
 
makVrv::DtDe * myDe
 
DtEntityResolver * myResolver
 
DtAttributeCallbackManager myAttributeCallbacks
 
DtVreMessageHandlerGroup myMessageHandlers
 

Constructor & Destructor Documentation

◆ DtEntityOverlayComponent()

makVre::DtEntityOverlayComponent::DtEntityOverlayComponent ( )

Constructor.

◆ ~DtEntityOverlayComponent()

virtual makVre::DtEntityOverlayComponent::~DtEntityOverlayComponent ( )
overridevirtual

Destructor.

Member Function Documentation

◆ type()

virtual const char * makVre::DtEntityOverlayComponent::type ( ) const
overridevirtual

Returns the component type identifier.

Returns
Component type string used for factory registration

Reimplemented from makVre::DtQtQuickOverlay.

◆ initialize()

virtual bool makVre::DtEntityOverlayComponent::initialize ( DtPlayerStation * player,
DtInitTable & config )
overridevirtual

Initializes the component with player and configuration.

Parameters
playerPointer to the player station
configConfiguration table with component settings
Returns
True if initialization succeeded, false otherwise

Reimplemented from makVre::DtQtQuickOverlay.

Reimplemented in DtEntityHealthBarOverlay.

References makVre::DtPlayerComponent::player().

◆ postInitialize()

virtual bool makVre::DtEntityOverlayComponent::postInitialize ( )
overridevirtual

Performs post-initialization after all components are created.

Returns
True if post-initialization succeeded, false otherwise

Sets up the QML overlay and discovers entities to track

Reimplemented from makVre::DtQtQuickOverlay.

◆ tick()

virtual void makVre::DtEntityOverlayComponent::tick ( double dt)
overridevirtual

Per-frame update called by the player station.

Parameters
dtDelta time since last tick in seconds

Updates entity positions and projects them to screen coordinates

Reimplemented from makVre::DtQtQuickOverlay.

◆ shutdown()

virtual void makVre::DtEntityOverlayComponent::shutdown ( )
overridevirtual

Cleanup when component is being destroyed.

Reimplemented from makVre::DtQtQuickOverlay.

◆ initdoc()

virtual void makVre::DtEntityOverlayComponent::initdoc ( QQuickItem * rootItem)
overridevirtual

Called when QML root item is loaded.

Parameters
rootItemThe root QML item

Overridden to get a reference to the QML data object for direct property setting

Reimplemented from makVre::DtQtQuickOverlay.

◆ updateEntityData()

virtual void makVre::DtEntityOverlayComponent::updateEntityData ( )
protectedvirtual

Discovers and updates entity-specific data each frame (proof of concept)

Queries EntityResolver each frame to rebuild the list of entities to track and fetches entity-specific information from the simulation (health, position, etc.)

◆ populateEntityData()

virtual void makVre::DtEntityOverlayComponent::populateEntityData ( EntityOverlayInfo & info,
DtAttributeHandle & entityRootAttr )
protectedvirtual

Populates overlay-specific data fields for a tracked entity.

Parameters
infoOverlay info structure to populate
entityRootAttrRoot attribute handle for the tracked entity

Reimplemented in DtEntityHealthBarOverlay.

◆ ensureEntityTracked()

virtual void makVre::DtEntityOverlayComponent::ensureEntityTracked ( const DtUUID & uuid,
const std::string & entityIdStr )
protectedvirtual

Ensures an entity is registered in the tracked entities cache.

Parameters
uuidThe entity's UUID from the sensor contacts
entityIdStrThe entity identifier string for attribute store lookup

◆ getEntityTopWorldPosition()

virtual void makVre::DtEntityOverlayComponent::getEntityTopWorldPosition ( DtAttributeHandle & entityAttrRoot,
makVrv::DtSceneObject * sceneObj,
DtVector & sceneObjPoint,
DtVector & worldPoint ) const
protectedvirtual

Computes the world-space position of the top center of an entity's bounding volume.

Parameters
entityAttrRootRoot attribute handle for the entity
sceneObjThe entity's scene object for coordinate transformation
[out]sceneObjPointThe resulting scene-object-space position
[out]worldPointThe resulting world (database) coordinates

◆ removeStaleTrackedEntities()

virtual void makVre::DtEntityOverlayComponent::removeStaleTrackedEntities ( const SensorContactsMap & contacts)
protectedvirtual

Removes tracked entities that are no longer present in the sensor contacts.

Parameters
contactsThe current sensor contacts to check against

◆ computeScreenHeightOffset()

virtual double makVre::DtEntityOverlayComponent::computeScreenHeightOffset ( const DtVector & sceneObjPoint,
double heightAboveEntity,
makVrv::DtSceneObject * sceneObj,
double baseScreenY ) const
protectedvirtual

Converts a world-space height offset above an entity into a screen-space pixel offset.

Parameters
sceneObjPointThe entity's position in scene-object coordinates
heightAboveEntityThe height offset in meters to convert
sceneObjThe scene object used for coordinate transformation
baseScreenYThe base screen Y coordinate (OpenGL convention) of the entity
Returns
The equivalent offset in screen-space pixels (QML Y-down convention)

◆ onOverlayEnabledChanged()

virtual void makVre::DtEntityOverlayComponent::onOverlayEnabledChanged ( bool enabled)
protectedvirtual

Responds to runtime overlay visibility changes from the player attribute store.

Parameters
enabledTrue to show overlays, false to hide them

Member Data Documentation

◆ mySensorContactsAttr

DtAttributeHandleType<SensorContactsMap> makVre::DtEntityOverlayComponent::mySensorContactsAttr
protected

Sensor contacts used to discover entities that should receive overlays.

Attribute Store Keysensors.annotation-proximity-sensor.contacts

◆ myTrackedEntitesMap

TrackedEntitiesMap makVre::DtEntityOverlayComponent::myTrackedEntitesMap
protected

Cached per-entity attribute handles for currently tracked contacts.

◆ myExternalEntityAttributes

std::unordered_set<std::string> makVre::DtEntityOverlayComponent::myExternalEntityAttributes
protected

Attribute paths to keep synchronized for tracked external entities.

◆ myQmlDataObject

QObject* makVre::DtEntityOverlayComponent::myQmlDataObject
protected

Pointer to the QML data object for direct property updates.

◆ myAdditionalHeightAboveEntity

double makVre::DtEntityOverlayComponent::myAdditionalHeightAboveEntity
protected

Base world-space height offset in meters applied above each entity.

◆ mySensorName

std::string makVre::DtEntityOverlayComponent::mySensorName
protected

Name of the sensor to read contacts from in the attribute store.

◆ myOverlayEnabledAttr

DtAttributeHandleType<bool> makVre::DtEntityOverlayComponent::myOverlayEnabledAttr
protected

Player attribute controlling whether entity overlays are visible.

Attribute Store KeyshowEntityOverlays

The documentation for this class was generated from the following file: