VR-Engage  2.2
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
17
19
20namespace makVre
21{
23{
24//! \ingroup RoleConfigParams
25//! \defgroup CommanderHatchControlLogicRoleParams Commander Hatch Control Logic Role Parameters
26//! \roleInherits{EntityControlLogicRoleParams}
27//! Configuration Options for commander hatch control logic role.
28//! @{
29
30// (No specific configuration parameters are currently used by DtCommanderHatchControlLogic.)
31
32//! @}
33} // namespace CommanderHatchControlLogicConfig
34
35//! \brief Type identifier for DtCommanderHatchControlLogic component
36constexpr const char* DtCommanderHatchControlLogicType = "DtCommanderHatchControlLogic";
37
38//! \brief Component for controlling commander view from open vehicle hatch
39//!
40//! The DtCommanderHatchControlLogic provides the capability to look around as a human
41//! observer from a point of view on a vehicle (i.e., an open hatch) with support for
42//! binoculars and night vision goggles (NVG). It handles head movement (yaw/pitch) and
43//! equipment toggling (binoculars, NVG).
44//!
45//! Input handler details (for configuring in an SMS input configuration file):
46//!
47//! This class supports the following input handler functions that may be configured
48//! to map to input devices in role input configuration files:
49//! - "yaw": Controls horizontal head rotation
50//! - "pitch": Controls vertical head tilt
51//! - "toggle-binoculars": Toggles binocular use on/off
52//! - "toggle-nvg": Toggles night vision goggles on/off
53//!
54//! The input group name is provided in the role configuration file and is used to
55//! distinguish input handlers when multiple handlers are present on the entity.
56//! The default input group is "commander-hatch".
58{
59public:
60 //! \brief Constructor for DtCommanderHatchControlLogic
61 //!
62 //! Initializes the component with the name "DtCommanderHatchControlLogic" and default values.
63 //! Also checks out the required VR Engage Ground license.
65
66 //! \brief Virtual destructor for DtCommanderHatchControlLogic
68
69 //! \brief Initializes the component with configuration from Lua
70 //!
71 //! Sets up input handlers for "yaw", "pitch", "toggle-binoculars", and "toggle-nvg".
72 //! Initializes state attributes for equipment tracking:
73 //! - "isCivilian": Boolean flag for civilian status (defaults to false)
74 //! - "usingBinoculars": Boolean flag for binocular use (defaults to false)
75 //! - "currentEquipment": Equipment enum value (defaults to NONE)
76 //! - "NVG": Boolean flag for night vision goggles (defaults to false)
77 //!
78 //! \param player Pointer to the player station this component belongs to
79 //! \param config Configuration table containing initialization parameters
80 //! \return True if initialization succeeds, false otherwise
82
83 //! \brief Performs post-initialization setup
84 //!
85 //! Initializes yaw and pitch input to zero to prevent display shaking before any input is applied.
86 //! Sets up a change callback for the "usingBinoculars" state attribute.
87 //!
88 //! \return True if post-initialization succeeds, false otherwise
89 virtual bool postInitialize() override;
90
91 //! \brief Updates the component state
92 //!
93 //! Called each frame to update observer yaw and pitch based on input values.
94 //! Scales input by delta time and current view magnification to maintain consistent
95 //! control regardless of frame rate or zoom level.
96 //!
97 //! \param dt Delta time in seconds since the last tick
98 virtual void tick(double dt) override;
99
100 //! \brief Shuts down the component
101 //!
102 //! Removes menu action message handler and usingBinoculars state attribute change callback.
103 //! Also shuts down the input logic.
104 virtual void shutdown() override;
105
106 //! \brief Returns the component type identifier
107 //! \return The component type string
108 virtual const char* type() const override;
109
110 //! \brief Input handler for horizontal head rotation (yaw)
111 //!
112 //! Stores the input value in myYawInput for processing during tick().
113 //!
114 //! \param val The yaw input value, typically from -1.0 to 1.0
115 virtual void yaw(double val);
116
117 //! \brief Input handler for vertical head tilt (pitch)
118 //!
119 //! Stores the input value in myPitchInput for processing during tick().
120 //!
121 //! \param val The pitch input value, typically from -1.0 to 1.0
122 virtual void pitch(double val);
123
124 //! \brief Toggles binocular use on or off
125 //!
126 //! When triggered with a value of 1.0, toggles the "usingBinoculars" state attribute.
127 //! If binoculars are activated:
128 //! - Sets zoom level to the value of "maxViewMagnification" state attribute
129 //! - Sets "currentEquipment" state attribute to BINOCULARS
130 //! - Disables NVG if active
131 //! If binoculars are deactivated:
132 //! - Sets zoom level to 1.0
133 //!
134 //! \param val The input value, a value of 1.0 triggers the toggle
135 virtual void toggleBinoculars(double val);
136
137 //! \brief Enables or disables binocular-specific input controls
138 //!
139 //! When enabled, loads the "binoculars" input configuration and sets up the
140 //! "zoom" action handler. When disabled, unloads the binoculars input configuration.
141 //!
142 //! \param enabled True to enable binocular controls, false to disable
143 virtual void setBinocularsControls(bool enabled);
144
145 //! \brief Reduces binocular zoom level
146 //!
147 //! Sends a BinocularsZoomByMessage with a negative zoom value.
148 //!
149 //! \param value The amount to zoom out (positive value)
150 virtual void zoomOut(double value);
151
152 //! \brief Increases binocular zoom level
153 //!
154 //! Sends a BinocularsZoomByMessage with a positive zoom value.
155 //!
156 //! \param value The amount to zoom in (positive value)
157 virtual void zoomIn(double value);
158
159 //! \brief Combined input handler for binocular zoom
160 //!
161 //! Routes to zoomIn or zoomOut based on whether the input value is positive or negative.
162 //!
163 //! \param value The zoom input value, positive for zoom in, negative for zoom out
164 virtual void zoom(double value);
165
166 //! \brief Toggles night vision goggles (NVG) on or off
167 //!
168 //! When triggered with a value of 1.0, toggles the "NVG" state attribute.
169 //! If NVG is activated:
170 //! - Disables binoculars if active
171 //! - Resets zoom level to 1.0
172 //!
173 //! \param val The input value, a value of 1.0 triggers the toggle
174 virtual void toggleNVG(double val);
175
176protected:
177 //! \brief Handles menu action messages
178 //!
179 //! Processes menu actions, particularly the "toggleBinoculars" action which
180 //! triggers the toggleBinoculars functionality.
181 //!
182 //! \param msg The message to process
183 //! \return HANDLED if the message was processed, IGNORED otherwise
185
186 //! \brief Callback for changes to the "usingBinoculars" state attribute
187 //!
188 //! Updates the "currentEquipment" state attribute and enables/disables
189 //! binocular-specific input controls based on the new value.
190 //!
191 //! \param usingBinoculars The new value of the usingBinoculars state attribute
192 void onBinocularsChanged(bool usingBinoculars);
193
194protected:
195 //! \brief Input handler logic for processing input device events
197
198 //! \brief Main control group name from configuration
199 //!
200 //! Used to identify the function group when sending joystick messages.
202
203 //! \brief Current yaw input value
204 //!
205 //! Stored during input handler calls and applied during tick().
207
208 //! \brief Current pitch input value
209 //!
210 //! Stored during input handler calls and applied during tick().
212};
213
214} // namespace makVre
float myYawInput
Current yaw input value.
Definition commanderHatchControlLogic.h:206
void onBinocularsChanged(bool usingBinoculars)
Callback for changes to the "usingBinoculars" state attribute.
float myPitchInput
Current pitch input value.
Definition commanderHatchControlLogic.h:211
virtual void toggleBinoculars(double val)
Toggles binocular use on or off.
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.
virtual void zoom(double value)
Combined input handler for binocular zoom.
std::string myMainControlGroup
Main control group name from configuration.
Definition commanderHatchControlLogic.h:201
virtual void pitch(double val)
Input handler for vertical head tilt (pitch)
virtual void zoomOut(double value)
Reduces binocular zoom level.
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.
DtInputLogic myInputLogic
Input handler logic for processing input device events.
Definition commanderHatchControlLogic.h:196
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:60
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:35
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:23
Include export definitions for this library.
Definition glsVreMessageUtil.h:49
constexpr const char * DtCommanderHatchControlLogicType
Type identifier for DtCommanderHatchControlLogic component.
Definition commanderHatchControlLogic.h:36
DtVreMessageResult
Enumeration of possible message handling results.
Definition vreMessage.h:33