VR-Engage  2.2
Loading...
Searching...
No Matches
lookAroundInputLogic.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4*******************************************************************************/
5
6//! \file lookAroundInputLogic.h
7//! \brief Input component for controlling view orientation and equipment in vehicle roles
8//! \ingroup vreCommonComponents
9
10#pragma once
11
14#include "vreUtil/attribute.h"
15
17
18namespace makVrv
19{
20class DtDe;
21}
22
23namespace makVre
24{
26
27//! \brief Input component that enables looking around from a vehicle hatch
28//!
29//! DtLookAroundInputLogic provides the capability to look around as a human
30//! observer from a point of view on a vehicle (i.e., an open hatch) with options
31//! for binoculars and night vision. It handles inputs for view orientation,
32//! equipment toggling, and mouse/joystick controls.
33//!
34//! Input handler details (for configuring in an SMS input configuration file):
35//! - Input group: "look-around"
36//! - Handler functions: "yaw", "pitch", "joystickYaw", "joystickPitch",
37//! "toggle-binoculars", "toggle-nvg", "reset-view", "enable-free-look"
39{
40public:
41 //! \brief Constructor for DtLookAroundInputLogic
42 //! \param de Reference to the distributed environment
43 //! \param updater Reference to the associated observer updater
44 //!
45 //! Initializes input state with default values and establishes connection
46 //! with the corresponding observer updater
48
49 //! \brief Virtual destructor for DtLookAroundInputLogic
50 virtual ~DtLookAroundInputLogic() override;
51
52 //! \brief Initializes the look-around input component
53 //!
54 //! Sets up message handlers, loads input configurations, configures input action handlers,
55 //! and enables mouse control by default
56 virtual void initialize() override;
57
58 //! \brief Shuts down the look-around input component
59 //!
60 //! Removes message handlers, cleans up input configurations, and disables mouse control
61 virtual void shutdown() override;
62
63 //! \brief Called every frame to update view orientation based on input
64 //! \param dt Delta time since the last frame in seconds
65 //!
66 //! Updates state attributes "observerYaw" and "observerPitch" based on mouse and joystick inputs,
67 //! applying appropriate scaling based on delta time and view magnification
68 virtual void tick(double dt);
69
70 //! \brief Handles mouse-based yaw (horizontal rotation) input
71 //! \param val Input value for yaw rate (-1.0 to 1.0)
72 //!
73 //! Caches the yaw input value to be applied during tick(), but only
74 //! if the player is not a spectator and look-around mode is active
75 virtual void yaw(double val);
76
77 //! \brief Handles mouse-based pitch (vertical rotation) input
78 //! \param val Input value for pitch rate (-1.0 to 1.0)
79 //!
80 //! Caches the pitch input value to be applied during tick(), but only
81 //! if the player is not a spectator and look-around mode is active
82 virtual void pitch(double val);
83
84 //! \brief Handles joystick-based yaw (horizontal rotation) input
85 //! \param val Input value for yaw rate (-1.0 to 1.0)
86 //!
87 //! Caches the joystick yaw input value to be applied during tick()
88 virtual void joystickYaw(double val);
89
90 //! \brief Handles joystick-based pitch (vertical rotation) input
91 //! \param val Input value for pitch rate (-1.0 to 1.0)
92 //!
93 //! Caches the joystick pitch input value to be applied during tick()
94 virtual void joystickPitch(double val);
95
96 //! \brief Toggles binoculars on or off
97 //! \param val Input value (1.0 to toggle binoculars)
98 //!
99 //! If incoming value is 1.0, toggles binoculars on/off:
100 //! - If toggled on, sets zoom level to "maxViewMagnification" state attribute
101 //! - If toggled off, sets zoom level to 1.0
102 //! - Disables NVG if it is enabled when binoculars are toggled on
103 //! - New zoom level is sent in a BinocularsZoomToMessage
104 virtual void toggleBinoculars(double val);
105
106 //! \brief Enables or disables binocular-specific input controls
107 //! \param enabled True to enable binocular controls, false to disable
108 //!
109 //! Loads or unloads binocular-specific input configuration based on the enabled state
110 virtual void setBinocularsControls(bool enabled);
111
112 //! \brief Decreases binocular zoom level
113 //! \param value Amount to decrease zoom by
114 //!
115 //! Sends a BinocularsZoomByMessage with a negative zoom value
116 virtual void zoomOut(double value);
117
118 //! \brief Increases binocular zoom level
119 //! \param value Amount to increase zoom by
120 //!
121 //! Sends a BinocularsZoomByMessage with a positive zoom value
122 virtual void zoomIn(double value);
123
124 //! \brief Handles continuous zoom level input
125 //! \param value Input value (-1.0 to 1.0) for zoom direction and speed
126 //!
127 //! Calls zoomIn for positive values or zoomOut for negative values
128 virtual void zoom(double value);
129
130 //! \brief Toggles night vision goggles (NVG) on or off
131 //! \param val Input value (1.0 to toggle NVG)
132 //!
133 //! If incoming value is 1.0, toggles NVG on/off:
134 //! - If toggled on, disables binoculars if they are active and sets "NVG" attribute to true
135 //! - If toggled off, sets "NVG" attribute to false
136 //! - Has no effect if NVG is not enabled in the component configuration
137 virtual void toggleNVG(double val);
138
139 //! \brief Toggles mouse control on or off
140 //! \param val Input value (1.0 to toggle mouse control)
141 //!
142 //! Inverts the current mouse control state if the input value is 1.0
143 virtual void toggleMouseControl(float val);
144
145 //! \brief Enables mouse control
146 //! \param val Input value (1.0 to enable mouse control)
147 //!
148 //! Enables mouse control if it's not already enabled and the input value is 1.0
149 virtual void enableMouseControl(float val);
150
151 //! \brief Handles focus state change messages
152 //! \param message The focus state message
153 //! \return Message handling result indicating if the message was handled
154 //!
155 //! Updates mouse control based on application focus state
157
158 //! \brief Sets the mouse control enabled state
159 //! \param enabled True to enable mouse control, false to disable
160 //!
161 //! Sends a ToggleMouseControlMessage with the new state
162 virtual void setMouseControlEnabled(bool enabled);
163
164 //! \brief Checks if mouse control is currently enabled
165 //! \return True if mouse control is enabled, false otherwise
166 virtual bool isMouseControlEnabled();
167
168 //! \brief Checks if mouse control support is allowed
169 //! \return True if mouse control support is allowed, false otherwise
170 //!
171 //! This differs from isMouseControlEnabled() in that it determines whether
172 //! mouse control is supported at all, not just whether it's currently active
173 virtual bool isMouseControlSupportAllowed() const;
174
175 //! \brief Sets whether mouse control support is allowed
176 //! \param enable True to allow mouse control support, false to disallow
177 //!
178 //! Controls whether mouse control functionality is available at all
179 virtual void setMouseControlSupportAllowed(bool enable);
180
181 //! \brief Returns the view to its initial orientation
182 //! \param value Input value (1.0 to reset view)
183 //!
184 //! If the input value is 1.0, resets the observer view to its initial orientation
185 virtual void returnToInitialView(float value);
186
187 //! \brief Enables or disables free-look mode
188 //! \param val Input value (1.0 to enable, 0.0 to disable)
189 //!
190 //! Controls whether the player can freely look around, and resets
191 //! input values when free-look is disabled
192 virtual void freeLook(double val);
193
194protected:
195 //! \brief Handles menu action messages
196 //! \param msg The menu action message
197 //! \return Message handling result indicating if the message was handled
198 //!
199 //! If the incoming message action is "toggleBinoculars", calls toggleBinoculars(1)
201
202 //! \brief Callback for changes to the usingBinoculars attribute
203 //! \param usingBinoculars New value of the usingBinoculars attribute
204 //!
205 //! Updates the currentEquipment attribute and binoculars controls
206 //! based on the new binoculars state
207 void onBinocularsChanged(bool usingBinoculars);
208
209protected:
210 //! \brief Name of the entity this component is controlling
211 std::string myEntityName;
212
213 //! \brief Reference to the distributed environment
214 makVrv::DtDe& myDe;
215
216 //! \brief Class name for logging and identification
217 std::string myClassName;
218
219 //! \brief Path to the input configuration file
220 std::string myInputConfigFile;
221
222 //! \brief Flag indicating if mouse control is currently enabled
224
225 //! \brief Flag indicating if mouse control is supported at all
227
228 //! \brief Reference to the associated look-around observer updater
229 //!
230 //! Used to communicate with the observer component that this input logic controls
232
233 //! \brief Cached mouse yaw input value
235
236 //! \brief Cached mouse pitch input value
238
239 //! \brief Cached joystick yaw input value
241
242 //! \brief Cached joystick pitch input value
244
245 //! \brief Flag indicating if joystick input is currently active
247
248 //! \brief Member-scope instance of Attribute callback manager
249 //!
250 //! Used to manage Attribute change callback connections and ensure that all
251 //! callbacks are unregistered when this class instance is destroyed.
253};
254
255} // namespace makVre
Provides attribute handling system for hierarchical data storage and manipulation.
Definition attributeCallback.h:166
DtInputLogic()
Constructor.
virtual void joystickYaw(double val)
Handles joystick-based yaw (horizontal rotation) input.
virtual void toggleBinoculars(double val)
Toggles binoculars on or off.
virtual void setMouseControlEnabled(bool enabled)
Sets the mouse control enabled state.
DtLookAroundObserverUpdater & myUpdater
Reference to the associated look-around observer updater.
Definition lookAroundInputLogic.h:231
virtual void yaw(double val)
Handles mouse-based yaw (horizontal rotation) input.
float myJoystickYawInput
Cached joystick yaw input value.
Definition lookAroundInputLogic.h:240
bool myMouseControlEnabled
Flag indicating if mouse control is currently enabled.
Definition lookAroundInputLogic.h:223
virtual void enableMouseControl(float val)
Enables mouse control.
virtual void setBinocularsControls(bool enabled)
Enables or disables binocular-specific input controls.
virtual void toggleNVG(double val)
Toggles night vision goggles (NVG) on or off.
bool myMouseControlSupportAllowed
Flag indicating if mouse control is supported at all.
Definition lookAroundInputLogic.h:226
float myMouseYawInput
Cached mouse yaw input value.
Definition lookAroundInputLogic.h:234
virtual bool isMouseControlEnabled()
Checks if mouse control is currently enabled.
makVrv::DtDe & myDe
Reference to the distributed environment.
Definition lookAroundInputLogic.h:214
virtual void joystickPitch(double val)
Handles joystick-based pitch (vertical rotation) input.
std::string myEntityName
Name of the entity this component is controlling.
Definition lookAroundInputLogic.h:211
virtual DtVreMessageResult handleMenuMessage(makVre::DtVreMessage *msg)
Handles menu action messages.
virtual void zoomIn(double value)
Increases binocular zoom level.
virtual ~DtLookAroundInputLogic() override
Virtual destructor for DtLookAroundInputLogic.
virtual void freeLook(double val)
Enables or disables free-look mode.
DtAttributeCallbackManager myAttributeCallbacks
Member-scope instance of Attribute callback manager.
Definition lookAroundInputLogic.h:252
bool myJoystickMoving
Flag indicating if joystick input is currently active.
Definition lookAroundInputLogic.h:246
void onBinocularsChanged(bool usingBinoculars)
Callback for changes to the usingBinoculars attribute.
float myJoystickPitchInput
Cached joystick pitch input value.
Definition lookAroundInputLogic.h:243
virtual void returnToInitialView(float value)
Returns the view to its initial orientation.
virtual void tick(double dt)
Called every frame to update view orientation based on input.
virtual bool isMouseControlSupportAllowed() const
Checks if mouse control support is allowed.
virtual void initialize() override
Initializes the look-around input component.
virtual void pitch(double val)
Handles mouse-based pitch (vertical rotation) input.
virtual makVre::DtVreMessageResult handleFocusMessage(makVre::DtVreMessage *message)
Handles focus state change messages.
virtual void toggleMouseControl(float val)
Toggles mouse control on or off.
virtual void zoom(double value)
Handles continuous zoom level input.
virtual void shutdown() override
Shuts down the look-around input component.
DtLookAroundInputLogic(makVrv::DtDe &de, DtLookAroundObserverUpdater &updater)
Constructor for DtLookAroundInputLogic.
float myMousePitchInput
Cached mouse pitch input value.
Definition lookAroundInputLogic.h:237
virtual void setMouseControlSupportAllowed(bool enable)
Sets whether mouse control support is allowed.
virtual void zoomOut(double value)
Decreases binocular zoom level.
std::string myClassName
Class name for logging and identification.
Definition lookAroundInputLogic.h:217
std::string myInputConfigFile
Path to the input configuration file.
Definition lookAroundInputLogic.h:220
Component that manages observer orientation and equipment visuals.
Definition lookAroundObserverUpdater.h:158
Abstract base class for all VREngage messages.
Definition vreMessage.h:50
Defines export/import macros for the vreCommonComponents library.
#define VRECOMMONCOMPONENTS_DLL
DLL export/import macro for the vreCommonComponents library.
Definition export.h:28
Defines the DtInputLogic class for handling input in VR-Engage.
Include export definitions for this library.
Definition glsVreMessageUtil.h:49
DtVreMessageResult
Enumeration of possible message handling results.
Definition vreMessage.h:33
Definition appLauncherComponent.h:28
makVrv::DtDe * de()
Gets the display element pointer used by the plugin.
Defines the base class for all VREngage messages.