VR-Engage  2.2
Loading...
Searching...
No Matches
commanderObserverUpdater.h
Go to the documentation of this file.
1/******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4******************************************************************************/
5
6//! \file commanderObserverUpdater.h
7//! \brief Defines the DtCommanderObserverUpdater component for managing commander view and sensor modes.
8//!
9//! This component manages the observer for a vehicle commander, handling attachment to
10//! specific vehicle parts, orientation, zoom, and sensor mode switching.
11//!
12//! \ingroup vreCommonComponents
13
14#pragma once
15
16#include "stateDefines.h"
17
19
22
23#include <matrix/vlVector.h>
24#include <matrix/vlQuaternion.h>
25
26namespace makVrv
27{
28class DtDe;
29class DtEntityFacade;
30class DtObserver;
31class DtSceneObject;
32}; // namespace makVrv
33
35{
36//! \ingroup RoleConfigParams
37//! \defgroup CommanderObserverUpdaterRoleParams Commander Observer Updater Role Parameters
38//! \roleInherits{ObserverUpdaterRoleParams}
39//! Configuration Options for commander observer updater role.
40//! @{
41
42//! \vreRoleParam{attachOffset,DtVector,"DtVector::zero()",commanderObserverUpdater,Position offset from the attachment part for the observer.}
43constexpr const char* attachOffset = "attachOffset";
44
45//! \vreRoleParam{attachPart,int,5376,commanderObserverUpdater,Part number of the vehicle to attach the observer to.}
46constexpr const char* attachPart = "attachPart";
47
48//! \vreRoleParam{oriOffset,DtQuaternion,"DtQuaternion(0,0,0,1)",commanderObserverUpdater,Orientation offset for the observer relative to the attachment part.}
49constexpr const char* oriOffset = "oriOffset";
50
51//! \vreRoleParam{sensorModes,table,"",commanderObserverUpdater,Table mapping sensor mode names to VR-Vantage sensor identifiers.}
52constexpr const char* sensorModes = "sensorModes";
53
54//! @}
55} // namespace CommanderObserverUpdaterConfig
56
57namespace makVre
58{
59
60//! \brief Type identifier for DtCommanderObserverUpdater component
61constexpr const char* DtCommanderObserverUpdaterType = "DtCommanderObserverUpdater";
62
63//! \brief Component for managing commander observer and sensor systems
64//!
65//! The DtCommanderObserverUpdater manages the visual aspects of a vehicle commander's
66//! view. It handles attachment to specific vehicle parts, orientation control,
67//! sensor mode switching, and updates the observer state based on vehicle damage state.
68//!
69//! This component supports multiple sensor modes (Visual, NVG, Thermal White/Black)
70//! that can be configured in the role file.
72{
73public:
74 //! \brief Constructor for DtCommanderObserverUpdater
75 //!
76 //! Initializes the component with default values including no attachment,
77 //! Visual sensor mode, and empty sensor mode map.
79
80 //! \brief Virtual destructor for DtCommanderObserverUpdater
81 virtual ~DtCommanderObserverUpdater() override;
82
83 //! \brief Initializes the component with configuration from Lua
84 //!
85 //! Reads configuration values including attachment part, position/orientation offsets,
86 //! and available sensor modes. Sets up the observer and message handlers for
87 //! PlayerCreatedMessage and ResetMessage.
88 //!
89 //! Also populates the mySensorModes map with configured sensor types and their
90 //! corresponding VR-Vantage sensor names.
91 //!
92 //! \param player Pointer to the player station this component belongs to
93 //! \param config Configuration table containing initialization parameters
94 //! \return True if initialization succeeds, false otherwise
95 virtual bool initialize(DtPlayerStation* player, DtInitTable& config) override;
96
97 //! \brief Updates the observer's position, orientation, and sensor mode
98 //!
99 //! Called each frame to update the observer position based on entity position,
100 //! read observer orientation from state attributes, update sensor mode based on
101 //! the "currentSensor" state attribute, and handle the entity destruction state.
102 //!
103 //! \param dt Delta time in seconds since the last tick
104 virtual void tick(double dt) override;
105
106 //! \brief Shuts down the component
107 //!
108 //! Removes message handlers and resets the observer to default settings.
109 //! Also switches the observer back to the Visual sensor mode.
110 virtual void shutdown() override;
111
112 //! \brief Returns the component type identifier
113 //! \return The component type string
114 virtual const char* type() const override;
115
116protected:
117 //! \brief Handles player created messages
118 //!
119 //! Called when a player is created in the simulation. Calls resetObserver()
120 //! to re-attach the observer to the entity.
121 //!
122 //! \param msg The player created message
123 //! \return HANDLED to indicate the message was processed
125
126 //! \brief Handles reset messages
127 //!
128 //! Called when a reset message is received. Calls resetObserver()
129 //! to re-attach the observer to the entity.
130 //!
131 //! \param msg The reset message
132 //! \return HANDLED to indicate the message was processed
134
135 //! \brief Resets and re-attaches the observer to the entity
136 //!
137 //! Configures the observer to use AttachTypeMimic, attaches it to the player's element,
138 //! and sets the part attachment and offset values.
140
141 //! \brief Updates the observer's sensor mode
142 //!
143 //! Checks the "currentSensor" state attribute and updates the observer's sensor mode
144 //! if it has changed. Also updates the "currentSensorName" state attribute.
145 //! Uses the VR-Engage sensor mode mapper to convert role-specific sensor names
146 //! to VR-Vantage sensor names.
148
149 //! \brief Handles entity destruction state changes
150 //!
151 //! Monitors the "ownship.damageState" attribute. When the entity is destroyed,
152 //! switches to Visual mode, resets zoom, and changes the attachment type.
153 //! When the entity is restored, calls resetObserver() to restore normal operation.
155
156 //! \brief Flag indicating if the observer is attached to an entity
158
159 //! \brief Cached pointer to the observer being controlled
160 makVrv::DtObserver* myObserver;
161
162 //! \brief Interpolator for smooth zoom transitions
163 //!
164 //! Created as needed when zoom level changes and deleted when transition completes
166
167 //! \brief DIS part enumeration value for the vehicle part to attach the observer to
168 //!
169 //! Defaults to 5376 (primary radar system 1, representing commander sensor)
171
172 //! \brief Position offset from the attachment part
173 //!
174 //! Vector offset in meters from the attachment point
176
177 //! \brief Orientation offset from the attachment part
178 //!
179 //! Quaternion representing orientation offset from the attachment point
180 DtQuaternion myOriOffest;
181
182 //! \brief Last known sensor view mode
183 //!
184 //! Used to detect changes in sensor mode to avoid unnecessary updates
186
187 //! \brief Map of SensorViews enums to VR-Engage sensor mode names
188 //!
189 //! This map links the enumerated sensor types (VISUAL, NVG, etc.) to their
190 //! corresponding VR-Engage sensor mode names configured in the role file.
191 std::map<enum SensorViews, std::string> mySensorModes;
192};
193} // namespace makVre
virtual makVre::DtVreMessageResult handlePlayerReset(makVre::DtVreMessage *msg)
Handles reset messages.
virtual void tick(double dt) override
Updates the observer's position, orientation, and sensor mode.
bool myAttached
Flag indicating if the observer is attached to an entity.
Definition commanderObserverUpdater.h:157
void updateSensor()
Updates the observer's sensor mode.
SensorViews myLastSensorViewMode
Last known sensor view mode.
Definition commanderObserverUpdater.h:185
DtVector myAttachedOffset
Position offset from the attachment part.
Definition commanderObserverUpdater.h:175
makVrv::DtObserver * myObserver
Cached pointer to the observer being controlled.
Definition commanderObserverUpdater.h:160
DtQuaternion myOriOffest
Orientation offset from the attachment part.
Definition commanderObserverUpdater.h:180
void updateDestroyed()
Handles entity destruction state changes.
virtual bool initialize(DtPlayerStation *player, DtInitTable &config) override
Initializes the component with configuration from Lua.
std::map< enum SensorViews, std::string > mySensorModes
Map of SensorViews enums to VR-Engage sensor mode names.
Definition commanderObserverUpdater.h:191
DtLinearInterpolator< double > * myZoomInterpolator
Interpolator for smooth zoom transitions.
Definition commanderObserverUpdater.h:165
virtual const char * type() const override
Returns the component type identifier.
virtual ~DtCommanderObserverUpdater() override
Virtual destructor for DtCommanderObserverUpdater.
void resetObserver()
Resets and re-attaches the observer to the entity.
virtual makVre::DtVreMessageResult handlePlayerCreated(makVre::DtVreMessage *msg)
Handles player created messages.
int myAttachPart
DIS part enumeration value for the vehicle part to attach the observer to.
Definition commanderObserverUpdater.h:170
DtCommanderObserverUpdater()
Constructor for DtCommanderObserverUpdater.
virtual void shutdown() override
Shuts down the component.
Table-based access to Lua state for configuration data.
Definition initializer.h:38
Linear interpolation template class.
Definition linearInterpolator.h:23
DtObserverUpdater()
Default constructor for DtObserverUpdater.
virtual DtPlayerStation & player()
Gets the player station.
Class for managing the user interface for engaged roles.
Definition playerStation.h:51
Abstract base class for all VREngage messages.
Definition vreMessage.h:50
Base component for managing observer parameters and view settings.
constexpr const char * attachPart
Definition commanderObserverUpdater.h:46
constexpr const char * sensorModes
Definition commanderObserverUpdater.h:52
constexpr const char * attachOffset
Definition commanderObserverUpdater.h:43
constexpr const char * oriOffset
\vreRoleParam{oriOffset,DtQuaternion,"DtQuaternion(0,0,0,1)",commanderObserverUpdater,...
Definition commanderObserverUpdater.h:49
#define VRECOMMONCOMPONENTS_DLL
DLL export/import macro for the vreCommonComponents library.
Definition export.h:28
Provides a template class for linear interpolation between values.
Definition commanderObserverUpdater.h:35
Include export definitions for this library.
Definition glsVreMessageUtil.h:49
DtVreMessageResult
Enumeration of possible message handling results.
Definition vreMessage.h:33
constexpr const char * DtCommanderObserverUpdaterType
Type identifier for DtCommanderObserverUpdater component.
Definition commanderObserverUpdater.h:61
SensorViews
Enumeration of available sensor view modes.
Definition stateDefines.h:18
Definition appLauncherComponent.h:28
Common enumeration definitions used throughout the VREngage system.
Defines the base class for all VREngage messages.