VR-Engage  2.2
Loading...
Searching...
No Matches
commanderHatchViewUpdater.h
Go to the documentation of this file.
1/******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4******************************************************************************/
5
6//! \file commanderHatchViewUpdater.h
7//! \brief Defines the DtCommanderHatchViewUpdater component for managing commander view visuals.
8//!
9//! This component handles the visual aspects of a commander-hatch role, including observer orientation,
10//! binocular effects (zooming, reticle overlay), and night vision mode switching.
11//!
12//! \ingroup vreCommonComponents
13
14#pragma once
15
19
20#include <matrix/vlVector.h>
21#include <matrix/vlQuaternion.h>
22
23namespace makVrv
24{
25class DtDe;
26class DtEntityFacade;
27class DtObserver;
28class DtSceneObject;
29}; // namespace makVrv
30
31namespace makVre
32{
33
35{
36//! \ingroup RoleConfigParams
37//! \defgroup CommanderHatchViewUpdaterRoleParams Commander Hatch View Updater Role Parameters
38//! \roleInherits{PlayerComponentRoleParams}
39//! Configuration Options for commander hatch view updater component.
40//! @{
41
42//! \vreRoleParam{attachedLocationOffset,DtVector,DtVector::zero(),commanderHatchViewUpdater,Position offset from the attachment point for the observer camera in vehicle coordinates.}
43constexpr const char* attachedLocationOffset = "attachedLocationOffset";
44
45//! \vreRoleParam{observerName,string,Observer 1,commanderHatchViewUpdater,Name of the observer to control for the commander hatch view.}
46constexpr const char* observerName = "observerName";
47
48//! \vreRoleParam{partAttachment,int,-1,commanderHatchViewUpdater,DIS enumeration for the vehicle part to attach the eyepoint to (-1 for base vehicle).}
49constexpr const char* partAttachment = "partAttachment";
50
51//! \vreRoleParam{pitchRange,table,"",commanderHatchViewUpdater,Table defining min/max pitch angles in degrees for observer movement. Contains 'min' and 'max' keys.}
52constexpr const char* pitchRange = "pitchRange";
53
54//! \vreRoleParam{yawRange,table,"",commanderHatchViewUpdater,Table defining min/max yaw angles in degrees for observer movement. Contains 'min' and 'max' keys.}
55constexpr const char* yawRange = "yawRange";
56
57//! @}
58} // namespace CommanderHatchViewUpdaterConfig
59
60//! \brief Type identifier for DtCommanderHatchViewUpdater component
61constexpr const char* DtCommanderHatchViewUpdaterType = "DtCommanderHatchViewUpdater";
62
63//! \brief Component for managing visual aspects of a commander-hatch role
64//!
65//! The DtCommanderHatchViewUpdater updates the visual aspects of the commander-hatch
66//! role. It orients the observer based on state attributes and provides specialized
67//! visual effects such as binocular zoom and night vision goggles.
68//!
69//! The following parameters are available for configuration in the role file:
70//! - "observerName": Name of the observer to control (defaults to "Observer 1")
71//! - "partAttachment": DIS enumeration for the vehicle part to attach the eyepoint
72//! (defaults to -1, which represents the base part/vehicle itself)
73//! - "attachedLocationOffset": Vector offset from attachment point in meters
74//! (coordinates: +x right, +y front, +z up)
76{
77public:
78 //! \brief Constructor for DtCommanderHatchViewUpdater
79 //!
80 //! Initializes the component with default values including identity rotation offset
81 //! and no zoom interpolator.
83
84 //! \brief Virtual destructor for DtCommanderHatchViewUpdater
85 virtual ~DtCommanderHatchViewUpdater() override;
86
87 //! \brief Initializes the component with configuration from Lua
88 //!
89 //! Reads configuration values including observer name, part attachment ID,
90 //! and attached location offset. Caches a pointer to the observer and adds
91 //! handlers for PlayerCreatedMessage and ResetMessage.
92 //!
93 //! \param player Pointer to the player station this component belongs to
94 //! \param config Configuration table containing initialization parameters
95 //! \return True if initialization succeeds, false otherwise
96 virtual bool initialize(DtPlayerStation* player, DtInitTable& config) override;
97
98 //! \brief Updates the visual aspects of the commander view
99 //!
100 //! Reads "observerYaw" and "observerPitch" state attributes and updates the observer's
101 //! attached orientation accordingly. Calls updateBinocularsState() to handle zoom effects
102 //! and updateNVGState() to handle night vision mode switching.
103 //!
104 //! \param dt Delta time in seconds since the last tick
105 virtual void tick(double dt) override;
106
107 //! \brief Updates binocular zoom effects
108 //!
109 //! Checks the "viewMagnification" state attribute and manages the zoom interpolator
110 //! to create smooth transitions between zoom levels. Creates the interpolator when needed,
111 //! updates its endpoint if the target zoom changes, and applies the interpolated value
112 //! to the observer's view magnification.
113 //!
114 //! \param dt Delta time in seconds since the last tick
115 void updateBinocularsState(double dt);
116
117 //! \brief Updates night vision goggles state
118 //!
119 //! Checks the boolean "NVG" state attribute and, if it has changed since the last update,
120 //! sets the observer's sensor mode accordingly. When NVG is activated, uses the VR-Engage
121 //! sensor mode mapper to find the appropriate VR-Vantage sensor mode.
123
124 //! \brief Shuts down the component
125 //!
126 //! Removes message handlers for PlayerCreatedMessage and ResetMessage.
127 virtual void shutdown() override;
128
129 //! \brief Returns the component type identifier
130 //! \return The component type string
131 virtual const char* type() const override;
132
133protected:
134 //! \brief Handles player created messages
135 //!
136 //! Called when a player is created in the simulation. Calls setupObserver()
137 //! to configure the observer attachment details.
138 //!
139 //! \param msg The player created message
140 //! \return HANDLED to indicate the message was processed
142
143 //! \brief Handles reset messages
144 //!
145 //! This method currently has no implementation (TODO in the code).
146 //!
147 //! \param msg The reset message
148 //! \return HANDLED to indicate the message was processed
150
151 //! \brief Sets up observer attachment configuration
152 //!
153 //! Configures the observer with AttachTypeMimic, attaching it to the player's element
154 //! with the part and location/rotation offsets specified in the role config file.
155 virtual void setupObserver();
156
157protected:
158 //! \brief DIS enumeration for the vehicle part to attach the eyepoint to
159 //!
160 //! Defaults to -1, which represents the base part (the vehicle itself).
162
163 //! \brief Offset vector from the attachment point in meters
164 //!
165 //! Coordinates are: +x right, +y front, +z up
167
168 //! \brief Rotation offset quaternion from the attachment point
169 //!
170 //! Defaults to identity quaternion (1,0,0,0) - no rotation
172
173 //! \brief Interpolator for smooth zoom transitions
174 //!
175 //! Created as needed when zoom level changes and deleted when transition completes
177
178 //! \brief Cached pointer to the observer being controlled
179 makVrv::DtObserver* myObserver;
180
181 //! \brief Flag indicating whether observer rotation is constrained
182 //!
183 //! When true, observer yaw and pitch are clamped to the ranges defined
184 //! by myYawRange and myPitchRange. Set to true if either pitchRange or
185 //! yawRange configuration parameters are provided.
187
188 //! \brief Yaw range limits in radians
190
191 //! \brief Pitch range limits in radians
193
194 //! \brief Tracks the last known state of night vision goggles
195 //!
196 //! Used to detect changes in NVG state to avoid unnecessary sensor mode changes
198};
199} // namespace makVre
DtCommanderHatchViewUpdater()
Constructor for DtCommanderHatchViewUpdater.
int myPartAttachment
DIS enumeration for the vehicle part to attach the eyepoint to.
Definition commanderHatchViewUpdater.h:161
ObserverRange myPitchRange
Pitch range limits in radians.
Definition commanderHatchViewUpdater.h:192
DtQuaternion myAttachedRotationOffset
Rotation offset quaternion from the attachment point.
Definition commanderHatchViewUpdater.h:171
virtual makVre::DtVreMessageResult handlePlayerReset(makVre::DtVreMessage *msg)
Handles reset messages.
virtual ~DtCommanderHatchViewUpdater() override
Virtual destructor for DtCommanderHatchViewUpdater.
ObserverRange myYawRange
Yaw range limits in radians.
Definition commanderHatchViewUpdater.h:189
void updateNVGState()
Updates night vision goggles state.
makVre::DtLinearInterpolator< double > * myZoomInterpolator
Interpolator for smooth zoom transitions.
Definition commanderHatchViewUpdater.h:176
DtVector myAttachedLocationOffset
Offset vector from the attachment point in meters.
Definition commanderHatchViewUpdater.h:166
virtual bool initialize(DtPlayerStation *player, DtInitTable &config) override
Initializes the component with configuration from Lua.
makVrv::DtObserver * myObserver
Cached pointer to the observer being controlled.
Definition commanderHatchViewUpdater.h:179
bool myLastNVGState
Tracks the last known state of night vision goggles.
Definition commanderHatchViewUpdater.h:197
virtual const char * type() const override
Returns the component type identifier.
virtual void setupObserver()
Sets up observer attachment configuration.
virtual void shutdown() override
Shuts down the component.
void updateBinocularsState(double dt)
Updates binocular zoom effects.
bool myLimitObserverRange
Flag indicating whether observer rotation is constrained.
Definition commanderHatchViewUpdater.h:186
virtual makVre::DtVreMessageResult handlePlayerCreated(makVre::DtVreMessage *msg)
Handles player created messages.
virtual void tick(double dt) override
Updates the visual aspects of the commander view.
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 * partAttachment
Definition commanderHatchViewUpdater.h:49
constexpr const char * attachedLocationOffset
Definition commanderHatchViewUpdater.h:43
constexpr const char * observerName
Definition commanderHatchViewUpdater.h:46
constexpr const char * yawRange
Definition commanderHatchViewUpdater.h:55
constexpr const char * pitchRange
Definition commanderHatchViewUpdater.h:52
#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 commanderHatchViewUpdater.h:35
Include export definitions for this library.
Definition glsVreMessageUtil.h:49
constexpr const char * DtCommanderHatchViewUpdaterType
Type identifier for DtCommanderHatchViewUpdater component.
Definition commanderHatchViewUpdater.h:61
DtVreMessageResult
Enumeration of possible message handling results.
Definition vreMessage.h:33
Definition appLauncherComponent.h:28
Structure representing a range of rotation values for observer movement.
Definition observerUpdater.h:47
Defines the base class for all VREngage messages.