VR-Engage  2.2
Loading...
Searching...
No Matches
lookAroundObserverUpdater.h
Go to the documentation of this file.
1/******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4******************************************************************************/
5
6//! \file lookAroundObserverUpdater.h
7//! \brief Component that handles observer view orientation and equipment effects
8//! \ingroup vreCommonComponents
9
10#pragma once
11
12/*
13 * The following parameters are available for configuration from the component
14 * entry in a role configuration file:
15 *
16 * -- Global variables
17 * enableBinoculars = false; -- should enable nightvision when using this updater
18 * enableNVG = false; -- should enable nightvision when using this updater
19 * enableLookAround = true; -- If this is set to true, then all the saved views in the supplementalSavedViewData will
20 * enable freelook snapBackTimeMouse = 0.25; -- Time in seconds that will snap back the observer to the initial
21 * viewpoint when controlling with mouse. snapBackTimeJoystick = 0.1; -- Time in seconds that will snap back the
22 * observer to the initial viewpoint when controlling with joystick. pitchRange = {min = -45, max = 80}; -- Degrees in
23 * both directions. yawRange = {min = -120, max = 120}; -- Degrees in both directions. observerName = "Observer 1"; --
24 * name of observer, defaults to "Observer 1".
25 *
26 * -- If the SavedViews updater is not present, these values are where the observer with attach to.
27 * attachedLocationOffset = { x = 0.45, y = -0.25, z = 1.25 }; -- x, y, z offset from the center point in meters.
28 * Coordinates are +x is to the right, +y is to the front, and +z is up. attachedOrientationOffset = { x = 0.0, y = 0.0,
29 * z = 0.0, w = 1.0 }; -- Orientation of the observer relative to the attached model.
30 *
31 * -- If the SavedViews updater is present, this savedData provides additional configuration for finer control
32 * supplementalSavedViewData = {
33 * ["SAVED_VIEW_NAME"] = {
34 * enableLookAround = true; -- will enable look around for this view. If not specified, will use the default one
35 * above. pitchRange = {min = -45, max = 80}; -- Degrees in both directions. If not specified, will use the default one
36 * above. yawRange = {min = -120, max = 120}; -- Degrees in both directions. If not specified, will use the default one
37 * above.
38 * };
39 * ...
40 * };
41 */
42
43#include "stateDefines.h"
44
47
49
52
53#include <matrix/vlVector.h>
54#include <matrix/vlQuaternion.h>
55
56#include <string>
57
58namespace makVrv
59{
60class DtDe;
61class DtEntityFacade;
62class DtObserver;
63class DtSceneObject;
64class DtVirtualRealityDriver;
65}; // namespace makVrv
66
68{
69//! \ingroup RoleConfigParams
70//! \defgroup LookAroundObserverUpdaterRoleParams Look Around Observer Updater Role Parameters
71//! \roleInherits{ObserverUpdaterRoleParams}
72//! Configuration Options for look around observer updater role.
73//! @{
74
75//! \vreRoleParam{attachedLocationOffset,DtVector,"DtVector::zero()",lookAroundObserverUpdater,Position offset from the center point in meters for observer attachment.}
76constexpr const char* attachedLocationOffset = "attachedLocationOffset";
77
78//! \vreRoleParam{attachedOrientationOffset,DtQuaternion,"DtQuaternion()",lookAroundObserverUpdater,Orientation offset of the observer relative to the attached model.}
79constexpr const char* attachedOrientationOffset = "attachedOrientationOffset";
80
81//! \vreRoleParam{enableBinoculars,bool,false,lookAroundObserverUpdater,Enable binoculars functionality when using this updater.}
82constexpr const char* enableBinoculars = "enableBinoculars";
83
84//! \vreRoleParam{enableLookAround,bool,false,lookAroundObserverUpdater,Enable freelook capability for observer movement.}
85constexpr const char* enableLookAround = "enableLookAround";
86
87//! \vreRoleParam{enableNVG,bool,false,lookAroundObserverUpdater,Enable night vision goggles when using this updater.}
88constexpr const char* enableNVG = "enableNVG";
89
90//! \vreRoleParam{observerName,string,"Observer 1",lookAroundObserverUpdater,Name of the observer to use for view management.}
91constexpr const char* observerName = "observerName";
92
93//! \vreRoleParam{pitchRange,table,"",lookAroundObserverUpdater,Table defining min/max pitch angles in degrees for observer movement.}
94constexpr const char* pitchRange = "pitchRange";
95
96//! \vreRoleParam{snapBackTimeJoystick,double,0.1,lookAroundObserverUpdater,Time in seconds to snap back observer to initial viewpoint when using joystick.}
97constexpr const char* snapBackTimeJoystick = "snapBackTimeJoystick";
98
99//! \vreRoleParam{snapBackTimeMouse,double,0.25,lookAroundObserverUpdater,Time in seconds to snap back observer to initial viewpoint when using mouse.}
100constexpr const char* snapBackTimeMouse = "snapBackTimeMouse";
101
102//! \vreRoleParam{supplementalSavedViewData,table,"",lookAroundObserverUpdater,Additional configuration data for saved views with look-around settings.}
103constexpr const char* supplementalSavedViewData = "supplementalSavedViewData";
104
105//! \vreRoleParam{yawRange,table,"",lookAroundObserverUpdater,Table defining min/max yaw angles in degrees for observer movement.}
106constexpr const char* yawRange = "yawRange";
107
108//! @}
109} // namespace LookAroundObserverUpdaterConfig
110
111//! \brief Structure containing configuration data for a saved view
112//!
113//! Stores the name, look-around capabilities, and observer rotation limits
114//! for specific saved views in a vehicle
116{
117 //! \brief Constructor that initializes the saved view with a name
118 //! \param name The name of the saved view
119 explicit SavedViewData(std::string name)
120 : savedViewName(name)
121 , enableLookAround() {};
122
123 //! \brief The name of the saved view
124 std::string savedViewName;
125
126 //! \brief Flag indicating if look-around functionality is enabled for this view
128
129 //! \brief Range of vertical rotation (pitch) allowed for this view
131
132 //! \brief Range of horizontal rotation (yaw) allowed for this view
134};
135
136namespace makVre
137{
138
139//! \brief Type identifier for DtLookAroundObserverUpdater component
140constexpr const char* DtLookAroundObserverUpdaterType = "DtLookAroundObserverUpdater";
141
142//! \brief Component that manages observer orientation and equipment visuals
143//!
144//! DtLookAroundObserverUpdater updates the visual aspects of the player's view.
145//! It orients the observer based on input and provides support for special equipment
146//! visual effects like binoculars (with zooming capability) and night vision goggles.
147//! It can be configured to work with saved views and to limit the range of movement
148//! for different viewing positions.
149//!
150//! The component supports:
151//! - Configurable yaw and pitch ranges for head movement
152//! - Binoculars with zoom capability
153//! - Night vision goggles with special visual effects
154//! - Look-around functionality with mouse or joystick control
155//! - VR head tracking integration
156//! - Saved view positions with per-view configuration
158{
159public:
160 //! \brief Constructor for DtLookAroundObserverUpdater
161 //!
162 //! Initializes component state with default values
164
165 //! \brief Virtual destructor for DtLookAroundObserverUpdater
167
168 //! \brief Initializes the look-around observer updater component
169 //! \param player Pointer to the player station this component belongs to
170 //! \param config Configuration table containing observer settings
171 //! \return True if initialization succeeded, false otherwise
172 //!
173 //! Initializes member variables from the configuration table, caches pointer to the observer,
174 //! adds handlers for PlayerCreatedMessage, and creates the input logic component
175 virtual bool initialize(DtPlayerStation* player, DtInitTable& config) override;
176
177 //! \brief Called every frame to update the observer orientation and visual effects
178 //! \param dt Delta time since the last frame in seconds
179 //!
180 //! Updates the observer's orientation based on input, manages binoculars and NVG effects,
181 //! and handles smooth transitions between different states
182 virtual void tick(double dt) override;
183
184 //! \brief Performs post-initialization after all components are initialized
185 //! \return True if post-initialization succeeded, false otherwise
186 //!
187 //! Sets up saved view handling, initializes binoculars and NVG state,
188 //! and configures VR support if enabled
189 virtual bool postInitialize() override;
190
191 //! \brief Shuts down the look-around observer updater component
192 //!
193 //! Shuts down the input logic component, removes message handlers and
194 //! attribute callbacks, and performs cleanup operations
195 virtual void shutdown() override;
196
197 //! \brief Returns the type identifier for this component
198 //! \return The type string for DtLookAroundObserverUpdater
199 virtual const char* type() const override;
200
201 //! \brief Updates the binoculars zoom state
202 //! \param dt Delta time since the last frame in seconds
203 //!
204 //! Checks for the "viewMagnification" state attribute and creates, updates,
205 //! or deletes the zoom interpolator as needed. Updates the observer view
206 //! magnification based on the interpolator's current value for smooth transitions.
207 virtual void updateBinocularsState(double dt);
208
209 //! \brief Updates the night vision goggles (NVG) state
210 //!
211 //! Checks for the "NVG" state attribute and applies the appropriate
212 //! sensor mode to the observer when the state changes
213 virtual void updateNVGState();
214
215 //! \brief Updates the observer's orientation state
216 //! \param dT Delta time since the last frame in seconds
217 //!
218 //! Handles both VR and non-VR observer orientation updates, including
219 //! interpolation for smooth transitions when returning to initial views
220 virtual void updateObserverState(double dT);
221
222 //! \brief Resets the observer to its initial orientation
223 //! \param period Time in seconds for the smooth transition (default:.25 seconds)
224 //!
225 //! Creates an interpolator to smoothly transition from the current view
226 //! back to the initial saved view orientation
227 void resetToInitialView(double period = 0.25);
228 //! \brief Refreshes the observer yaw and pitch values
229 //!
230 //! Updates the observer's orientation attributes based on the current saved view
231 //! or attached orientation offset, and sets appropriate range limits
233
234 //! \brief Gets the current pitch range limits
235 //! \return Reference to the pitch range structure
236 virtual const ObserverRange& getPitchRange();
237
238 //! \brief Gets the current yaw range limits
239 //! \return Reference to the yaw range structure
240 virtual const ObserverRange& getYawRange();
241
242 //! \brief Checks if look-around functionality is enabled
243 //! \return True if look-around is enabled, false otherwise
244 virtual bool isLookAroundEnabled() const;
245
246 //! \brief Checks if binoculars functionality is enabled
247 //! \return True if binoculars are enabled, false otherwise
248 virtual bool isBinocularsEnabled() const;
249
250 //! \brief Checks if night vision goggles functionality is enabled
251 //! \return True if NVG is enabled, false otherwise
252 virtual bool isNVGEnabled() const;
253
254 //! \brief Gets the associated input logic component
255 //! \return Shared pointer to the input logic component
256 std::shared_ptr<DtLookAroundInputLogic> getInputLogic();
257
258 //! \brief Checks if the player is currently looking around
259 //! \return True if looking around is active and enabled, false otherwise
260 virtual bool isLookingAround() const;
261
262 //! \brief Enables or disables active looking around
263 //! \param look True to enable looking around, false to disable
264 //! \param mouse True if input is from mouse, false if from joystick
265 //!
266 //! When disabling looking around, initiates a smooth transition back
267 //! to the initial view orientation
268 virtual void setLookingAround(bool look, bool mouse = true);
269
270protected:
271 //! \brief Handles changes to the current view name
272 //! \param viewName The new view name
273 //!
274 //! Called when the current view changes, refreshes observer orientation
275 //! and updates range limits based on the new view
276 virtual void onCurrentViewNameChanged(const std::string& viewName);
277
278 //! \brief Handles player creation messages
279 //! \param msg The player created message
280 //! \return Message handling result indicating the message was handled
281 //!
282 //! Calls setupObserver() to set up the observer attachment details
284
285 //! \brief Sets up the observer's attachment to the player entity
286 //!
287 //! Configures the observer attachment as AttachTypeMimic, with the part
288 //! and location/rotation offsets specified in the configuration
289 virtual void setupObserver();
290
291protected:
292 //! \brief Shared pointer to the associated input logic component
293 std::shared_ptr<DtLookAroundInputLogic> myInputLogic;
294
295 //! \brief Pointer to the observer being controlled
296 makVrv::DtObserver* myObserver;
297
298 //! \brief Interpolator for smooth zoom level transitions
300
301 //! \brief Position offset from the attachment point
303
304 //! \brief Orientation offset from the attachment point
306
307 //! \brief Flag indicating if binoculars functionality is enabled
309
310 //! \brief Flag indicating if night vision goggles functionality is enabled
312
313 //! \brief Flag indicating if look-around functionality is enabled
315
316 //! \brief Last known state of night vision goggles
318
319 //! \brief Flag indicating if the player is currently looking around
321
322 //! \brief Current yaw range limits in radians
324
325 //! \brief Current pitch range limits in radians
327
328 //! \brief Default yaw range limits in radians
330
331 //! \brief Default pitch range limits in radians
333
334 //! \brief Time in seconds to transition back to initial view when using mouse
336
337 //! \brief Time in seconds to transition back to initial view when using joystick
339
340 //! \brief Flag indicating if saved views system is in use
342
343 //! \brief Last active sensor view mode
345
346 //! \brief Collection of supplemental configuration data for saved views
347 std::vector<SavedViewData> mySupplementalSavedViewData;
348
349 //! \brief Interpolator for smooth transitions between observer orientations
351
352 //! \brief Flag indicating if VR mode is enabled
354
355 //! \brief Pointer to the VR driver if VR is enabled
356 makVrv::DtVirtualRealityDriver* myVrDriver;
357};
358} // namespace makVre
Provides a template class for Bezier curve-based interpolation.
Bezier curve-based interpolation template class.
Definition bezierInterpolator.h:24
Table-based access to Lua state for configuration data.
Definition initializer.h:38
Linear interpolation template class.
Definition linearInterpolator.h:23
bool myEnableLookAround
Flag indicating if look-around functionality is enabled.
Definition lookAroundObserverUpdater.h:314
virtual void updateBinocularsState(double dt)
Updates the binoculars zoom state.
bool myEnableBinoculars
Flag indicating if binoculars functionality is enabled.
Definition lookAroundObserverUpdater.h:308
SensorViews myLastSensorViewMode
Last active sensor view mode.
Definition lookAroundObserverUpdater.h:344
virtual void setupObserver()
Sets up the observer's attachment to the player entity.
virtual void updateNVGState()
Updates the night vision goggles (NVG) state.
DtLookAroundObserverUpdater()
Constructor for DtLookAroundObserverUpdater.
DtQuaternion myAttachedOrientationOffset
Orientation offset from the attachment point.
Definition lookAroundObserverUpdater.h:305
virtual bool postInitialize() override
Performs post-initialization after all components are initialized.
ObserverRange myDefaultYawRange
Default yaw range limits in radians.
Definition lookAroundObserverUpdater.h:329
virtual bool isLookAroundEnabled() const
Checks if look-around functionality is enabled.
virtual void onCurrentViewNameChanged(const std::string &viewName)
Handles changes to the current view name.
ObserverRange myDefaultPitchRange
Default pitch range limits in radians.
Definition lookAroundObserverUpdater.h:332
void resetToInitialView(double period=0.25)
Resets the observer to its initial orientation.
double mySnapBackTimeJoystick
Time in seconds to transition back to initial view when using joystick.
Definition lookAroundObserverUpdater.h:338
virtual void shutdown() override
Shuts down the look-around observer updater component.
virtual bool isBinocularsEnabled() const
Checks if binoculars functionality is enabled.
void refreshObserverYawAndPitch()
Refreshes the observer yaw and pitch values.
std::vector< SavedViewData > mySupplementalSavedViewData
Collection of supplemental configuration data for saved views.
Definition lookAroundObserverUpdater.h:347
std::shared_ptr< DtLookAroundInputLogic > myInputLogic
Shared pointer to the associated input logic component.
Definition lookAroundObserverUpdater.h:293
virtual ~DtLookAroundObserverUpdater() override
Virtual destructor for DtLookAroundObserverUpdater.
makVrv::DtObserver * myObserver
Pointer to the observer being controlled.
Definition lookAroundObserverUpdater.h:296
bool myLastNVGState
Last known state of night vision goggles.
Definition lookAroundObserverUpdater.h:317
std::shared_ptr< DtLookAroundInputLogic > getInputLogic()
Gets the associated input logic component.
double mySnapBackTimeMouse
Time in seconds to transition back to initial view when using mouse.
Definition lookAroundObserverUpdater.h:335
virtual void updateObserverState(double dT)
Updates the observer's orientation state.
virtual const ObserverRange & getPitchRange()
Gets the current pitch range limits.
bool myUseSavedViews
Flag indicating if saved views system is in use.
Definition lookAroundObserverUpdater.h:341
virtual const char * type() const override
Returns the type identifier for this component.
virtual void setLookingAround(bool look, bool mouse=true)
Enables or disables active looking around.
virtual bool isLookingAround() const
Checks if the player is currently looking around.
virtual const ObserverRange & getYawRange()
Gets the current yaw range limits.
ObserverRange myCurrentPitchRange
Current pitch range limits in radians.
Definition lookAroundObserverUpdater.h:326
virtual void tick(double dt) override
Called every frame to update the observer orientation and visual effects.
makVre::DtBezierInterpolator< DtVector > * myObserverInterpolator
Interpolator for smooth transitions between observer orientations.
Definition lookAroundObserverUpdater.h:350
makVre::DtLinearInterpolator< double > * myZoomInterpolator
Interpolator for smooth zoom level transitions.
Definition lookAroundObserverUpdater.h:299
bool myLookingAround
Flag indicating if the player is currently looking around.
Definition lookAroundObserverUpdater.h:320
DtVector myAttachedLocationOffset
Position offset from the attachment point.
Definition lookAroundObserverUpdater.h:302
virtual bool isNVGEnabled() const
Checks if night vision goggles functionality is enabled.
bool myEnableNVG
Flag indicating if night vision goggles functionality is enabled.
Definition lookAroundObserverUpdater.h:311
virtual makVre::DtVreMessageResult handlePlayerCreated(makVre::DtVreMessage *msg)
Handles player creation messages.
virtual bool initialize(DtPlayerStation *player, DtInitTable &config) override
Initializes the look-around observer updater component.
makVrv::DtVirtualRealityDriver * myVrDriver
Pointer to the VR driver if VR is enabled.
Definition lookAroundObserverUpdater.h:356
ObserverRange myCurrentYawRange
Current yaw range limits in radians.
Definition lookAroundObserverUpdater.h:323
bool myVrEnabled
Flag indicating if VR mode is enabled.
Definition lookAroundObserverUpdater.h:353
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 * snapBackTimeJoystick
Definition lookAroundObserverUpdater.h:97
constexpr const char * supplementalSavedViewData
Definition lookAroundObserverUpdater.h:103
constexpr const char * enableLookAround
Definition lookAroundObserverUpdater.h:85
constexpr const char * snapBackTimeMouse
Definition lookAroundObserverUpdater.h:100
constexpr const char * attachedOrientationOffset
Definition lookAroundObserverUpdater.h:79
constexpr const char * pitchRange
Definition lookAroundObserverUpdater.h:94
constexpr const char * enableBinoculars
Definition lookAroundObserverUpdater.h:82
constexpr const char * observerName
Definition lookAroundObserverUpdater.h:91
constexpr const char * attachedLocationOffset
Definition lookAroundObserverUpdater.h:76
constexpr const char * enableNVG
Definition lookAroundObserverUpdater.h:88
constexpr const char * yawRange
Definition lookAroundObserverUpdater.h:106
#define VRECOMMONCOMPONENTS_DLL
DLL export/import macro for the vreCommonComponents library.
Definition export.h:28
Provides a template class for linear interpolation between values.
Input component for controlling view orientation and equipment in vehicle roles.
Definition lookAroundObserverUpdater.h:68
Include export definitions for this library.
Definition glsVreMessageUtil.h:49
constexpr const char * DtLookAroundObserverUpdaterType
Type identifier for DtLookAroundObserverUpdater component.
Definition lookAroundObserverUpdater.h:140
DtVreMessageResult
Enumeration of possible message handling results.
Definition vreMessage.h:33
SensorViews
Enumeration of available sensor view modes.
Definition stateDefines.h:18
Definition appLauncherComponent.h:28
Common enumeration definitions used throughout the VREngage system.
Structure representing a range of rotation values for observer movement.
Definition observerUpdater.h:47
ObserverRange pitchRange
Range of vertical rotation (pitch) allowed for this view.
Definition lookAroundObserverUpdater.h:130
ObserverRange yawRange
Range of horizontal rotation (yaw) allowed for this view.
Definition lookAroundObserverUpdater.h:133
bool enableLookAround
Flag indicating if look-around functionality is enabled for this view.
Definition lookAroundObserverUpdater.h:127
SavedViewData(std::string name)
Constructor that initializes the saved view with a name.
Definition lookAroundObserverUpdater.h:119
std::string savedViewName
The name of the saved view.
Definition lookAroundObserverUpdater.h:124
Defines the base class for all VREngage messages.