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