VR-Engage  2.3
Loading...
Searching...
No Matches
commanderHatchControlLogic.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4*******************************************************************************/
5
6//! \file commanderHatchControlLogic.h
7//! \brief Defines the DtCommanderHatchControlLogic component for controlling commander out-of-hatch view.
8//!
9//! This component provides functionality for controlling a vehicle commander's view when
10//! looking from an open hatch, including look direction control and binocular/NVG usage.
11//!
12//! \ingroup vreCommonComponents
13
14#pragma once
15
16#include "stateDefines.h"
18
20
21namespace makVre
22{
24{
25//! \ingroup RoleConfigParams
26//! \defgroup CommanderHatchControlLogicRoleParams Commander Hatch Control Logic Role Parameters
27//! \roleInherits{EntityControlLogicRoleParams}
28//! Configuration Options for commander hatch control logic role.
29//! @{
30
31// (No specific configuration parameters are currently used by DtCommanderHatchControlLogic.)
32
33//! @}
34} // namespace CommanderHatchControlLogicConfig
35
36//! \brief Type identifier for DtCommanderHatchControlLogic component
37constexpr const char* DtCommanderHatchControlLogicType = "DtCommanderHatchControlLogic";
38
39//! \brief Component for controlling commander view from open vehicle hatch
40//!
41//! The DtCommanderHatchControlLogic provides the capability to look around as a human
42//! observer from a point of view on a vehicle (i.e., an open hatch) with support for
43//! binoculars and night vision goggles (NVG). It handles head movement (yaw/pitch) and
44//! equipment toggling (binoculars, NVG).
45//!
46//! Input handler details (for configuring in an SMS input configuration file):
47//!
48//! This class supports the following input handler functions that may be configured
49//! to map to input devices in role input configuration files:
50//! - "yaw": Controls horizontal head rotation
51//! - "pitch": Controls vertical head tilt
52//! - "toggle-binoculars": Toggles binocular use on/off
53//! - "toggle-nvg": Toggles night vision goggles on/off
54//!
55//! The input group name is provided in the role configuration file and is used to
56//! distinguish input handlers when multiple handlers are present on the entity.
57//! The default input group is "commander-hatch".
59{
60public:
61 //! \brief Constructor for DtCommanderHatchControlLogic
62 //!
63 //! Initializes the component with the name "DtCommanderHatchControlLogic" and default values.
64 //! Also checks out the required VR Engage Ground license.
66
67 //! \brief Virtual destructor for DtCommanderHatchControlLogic
69
70 //! \brief Initializes the component with configuration from Lua
71 //!
72 //! Sets up input handlers for "yaw", "pitch", "toggle-binoculars", and "toggle-nvg".
73 //! Initializes state attributes for equipment tracking:
74 //! - "isCivilian": Boolean flag for civilian status (defaults to false)
75 //! - "usingBinoculars": Boolean flag for binocular use (defaults to false)
76 //! - "currentEquipment": Equipment enum value (defaults to NONE)
77 //! - "NVG": Boolean flag for night vision goggles (defaults to false)
78 //!
79 //! \param player Pointer to the player station this component belongs to
80 //! \param config Configuration table containing initialization parameters
81 //! \return True if initialization succeeds, false otherwise
83
84 //! \brief Performs post-initialization setup
85 //!
86 //! Initializes yaw and pitch input to zero to prevent display shaking before any input is applied.
87 //! Sets up a change callback for the "usingBinoculars" state attribute.
88 //!
89 //! \return True if post-initialization succeeds, false otherwise
90 virtual bool postInitialize() override;
91
92 //! \brief Updates the component state
93 //!
94 //! Called each frame to update observer yaw and pitch based on input values.
95 //! Scales input by delta time and current view magnification to maintain consistent
96 //! control regardless of frame rate or zoom level.
97 //!
98 //! \param dt Delta time in seconds since the last tick
99 virtual void tick(double dt) override;
100
101 //! \brief Shuts down the component
102 //!
103 //! Removes menu action message handler and usingBinoculars state attribute change callback.
104 //! Also shuts down the input logic.
105 virtual void shutdown() override;
106
107 //! \brief Returns the component type identifier
108 //! \return The component type string
109 virtual const char* type() const override;
110
111 //! \brief Input handler for horizontal head rotation (yaw)
112 //!
113 //! Stores the input value in myYawInput for processing during tick().
114 //!
115 //! \param val The yaw input value, typically from -1.0 to 1.0
116 virtual void yaw(double val);
117
118 //! \brief Input handler for vertical head tilt (pitch)
119 //!
120 //! Stores the input value in myPitchInput for processing during tick().
121 //!
122 //! \param val The pitch input value, typically from -1.0 to 1.0
123 virtual void pitch(double val);
124
125 //! \brief Toggles binocular use on or off
126 //!
127 //! When triggered with a value of 1.0, toggles the "usingBinoculars" state attribute.
128 //! If binoculars are activated:
129 //! - Sets zoom level to the value of "maxViewMagnification" state attribute
130 //! - Sets "currentEquipment" state attribute to BINOCULARS
131 //! - Disables NVG if active
132 //! If binoculars are deactivated:
133 //! - Sets zoom level to 1.0
134 //!
135 //! \param val The input value, a value of 1.0 triggers the toggle
136 virtual void toggleBinoculars(double val);
137
138 //! \brief Enables or disables binocular-specific input controls
139 //!
140 //! When enabled, loads the "binoculars" input configuration and sets up the
141 //! "zoom" action handler. When disabled, unloads the binoculars input configuration.
142 //!
143 //! \param enabled True to enable binocular controls, false to disable
144 virtual void setBinocularsControls(bool enabled);
145
146 //! \brief Reduces binocular zoom level
147 //!
148 //! Sends a BinocularsZoomByMessage with a negative zoom value.
149 //!
150 //! \param value The amount to zoom out (positive value)
151 virtual void zoomOut(double value);
152
153 //! \brief Increases binocular zoom level
154 //!
155 //! Sends a BinocularsZoomByMessage with a positive zoom value.
156 //!
157 //! \param value The amount to zoom in (positive value)
158 virtual void zoomIn(double value);
159
160 //! \brief Combined input handler for binocular zoom
161 //!
162 //! Routes to zoomIn or zoomOut based on whether the input value is positive or negative.
163 //!
164 //! \param value The zoom input value, positive for zoom in, negative for zoom out
165 virtual void zoom(double value);
166
167 //! \brief Toggles night vision goggles (NVG) on or off
168 //!
169 //! When triggered with a value of 1.0, toggles the "NVG" state attribute.
170 //! If NVG is activated:
171 //! - Disables binoculars if active
172 //! - Resets zoom level to 1.0
173 //!
174 //! \param val The input value, a value of 1.0 triggers the toggle
175 virtual void toggleNVG(double val);
176
177protected:
178 //! \brief Handles menu action messages
179 //!
180 //! Processes menu actions, particularly the "toggleBinoculars" action which
181 //! triggers the toggleBinoculars functionality.
182 //!
183 //! \param msg The message to process
184 //! \return HANDLED if the message was processed, IGNORED otherwise
186
187 //! \brief Callback for changes to the "usingBinoculars" state attribute
188 //!
189 //! Updates the "currentEquipment" state attribute and enables/disables
190 //! binocular-specific input controls based on the new value.
191 //!
192 //! \param usingBinoculars The new value of the usingBinoculars state attribute
193 void onBinocularsChanged(bool usingBinoculars);
194
195protected:
196 //! \brief Input handler logic for processing input device events
198
199 //! \brief Main control group name from configuration
200 //!
201 //! Used to identify the function group when sending joystick messages.
203
204 //! \brief Current yaw input value
205 //!
206 //! Stored during input handler calls and applied during tick().
208
209 //! \brief Current pitch input value
210 //!
211 //! Stored during input handler calls and applied during tick().
213
214 //! \brief Attribute handle storing the current view magnification level for input scaling.
215 //! \vreAttrKey{viewMagnification}
217
218 //! \brief Attribute handle storing the observer's current yaw (azimuth) angle in radians.
219 //! \vreAttrKey{observerYaw}
221
222 //! \brief Attribute handle storing the observer's current pitch (elevation) angle in radians.
223 //! \vreAttrKey{observerPitch}
225
226 //! \brief Attribute handle storing the maximum allowed view magnification.
227 //! \vreAttrKey{maxViewMagnification}
229
230 //! \brief Attribute handle storing the equipment the commander currently has equipped.
231 //! \vreAttrKey{currentEquipment}
233
234 //! \brief Attribute handle indicating whether the commander is currently using binoculars.
235 //! \vreAttrKey{usingBinoculars}
237
238 //! \brief Attribute handle indicating whether night vision goggles are active.
239 //! \vreAttrKey{NVG}
241
242};
243
244} // namespace makVre
Type-specific handle class for attributes.
Definition attributeHandle.h:229
float myYawInput
Current yaw input value.
Definition commanderHatchControlLogic.h:207
void onBinocularsChanged(bool usingBinoculars)
Callback for changes to the "usingBinoculars" state attribute.
DtAttributeHandleType< double > myObserverPitchHandle
Attribute handle storing the observer's current pitch (elevation) angle in radians.
Definition commanderHatchControlLogic.h:224
float myPitchInput
Current pitch input value.
Definition commanderHatchControlLogic.h:212
virtual void toggleBinoculars(double val)
Toggles binocular use on or off.
DtAttributeHandleType< Equipment > myCurrentEquipmentHandle
Attribute handle storing the equipment the commander currently has equipped.
Definition commanderHatchControlLogic.h:232
virtual void zoomIn(double value)
Increases binocular zoom level.
virtual bool postInitialize() override
Performs post-initialization setup.
virtual void tick(double dt) override
Updates the component state.
virtual const char * type() const override
Returns the component type identifier.
DtAttributeHandleType< double > myViewMagnificationHandle
Attribute handle storing the current view magnification level for input scaling.
Definition commanderHatchControlLogic.h:216
virtual void zoom(double value)
Combined input handler for binocular zoom.
DtAttributeHandleType< bool > myIsNVGHandle
Attribute handle indicating whether night vision goggles are active.
Definition commanderHatchControlLogic.h:240
std::string myMainControlGroup
Main control group name from configuration.
Definition commanderHatchControlLogic.h:202
virtual void pitch(double val)
Input handler for vertical head tilt (pitch)
virtual void zoomOut(double value)
Reduces binocular zoom level.
DtAttributeHandleType< double > myObserverYawHandle
Attribute handle storing the observer's current yaw (azimuth) angle in radians.
Definition commanderHatchControlLogic.h:220
virtual void toggleNVG(double val)
Toggles night vision goggles (NVG) on or off.
virtual bool initialize(makVre::DtPlayerStation *player, makVre::DtInitTable &config) override
Initializes the component with configuration from Lua.
virtual void yaw(double val)
Input handler for horizontal head rotation (yaw)
virtual void setBinocularsControls(bool enabled)
Enables or disables binocular-specific input controls.
virtual void shutdown() override
Shuts down the component.
DtCommanderHatchControlLogic()
Constructor for DtCommanderHatchControlLogic.
DtAttributeHandleType< bool > myUsingBinocularsHandle
Attribute handle indicating whether the commander is currently using binoculars.
Definition commanderHatchControlLogic.h:236
DtInputLogic myInputLogic
Input handler logic for processing input device events.
Definition commanderHatchControlLogic.h:197
DtAttributeHandleType< double > myMaxViewMagnificationHandle
Attribute handle storing the maximum allowed view magnification.
Definition commanderHatchControlLogic.h:228
virtual ~DtCommanderHatchControlLogic() override
Virtual destructor for DtCommanderHatchControlLogic.
virtual DtVreMessageResult handleMenuMessage(makVre::DtVreMessage *msg)
Handles menu action messages.
Component that provides entity control functionality.
Definition entityControlLogic.h:64
Table-based access to Lua state for configuration data.
Definition initializer.h:38
Class for managing input configuration and handling in VR-Engage.
Definition inputLogic.h:39
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
Defines the logic for controlling entities in VR-Engage.
Defines export/import macros for the vreCommonComponents library.
#define VRECOMMONCOMPONENTS_DLL
DLL export/import macro for the vreCommonComponents library.
Definition export.h:28
Definition commanderHatchControlLogic.h:24
!
Definition glsVreMessageUtil.h:50
constexpr const char * DtCommanderHatchControlLogicType
Type identifier for DtCommanderHatchControlLogic component.
Definition commanderHatchControlLogic.h:37
DtVreMessageResult
Enumeration of possible message handling results.
Definition vreMessage.h:33
Common enumeration definitions used throughout the VREngage system.