VR-Engage  2.2
Loading...
Searching...
No Matches
humanObserverUpdater.h
Go to the documentation of this file.
1/******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4******************************************************************************/
5
6//! \file humanObserverUpdater.h
7//! \brief Defines DtHumanObserverUpdater for managing human-specific observer behavior
8//! \ingroup vreHumanFrontend
9
10#pragma once
11
13
15
17
20
21#include <vrvCore/DtUniqueID.h>
22
23namespace makVre
24{
25
27{
28//! \ingroup RoleConfigParams
29//! \defgroup HumanObserverUpdaterRoleParams Human Observer Updater Role Parameters
30//! \roleInherits{PlayerComponentRoleParams}
31//! Configuration Options for human observer updater component.
32//! @{
33
34//! \vreRoleParam{attachModeTransitionSpeed,double,8.0,humanObserverUpdater,Speed of transitions when changing attachment modes.}
35constexpr const char* attachModeTransitionSpeed = "attachModeTransitionSpeed";
36
37//! \vreRoleParam{cutToFirstPersonDist,double,0.4,humanObserverUpdater,Distance threshold for cutting to first-person view.}
38constexpr const char* cutToFirstPersonDist = "cutToFirstPersonDist";
39
40//! \vreRoleParam{nightVisionSensorMode,string,NVG,humanObserverUpdater,Sensor mode name for night vision goggles.}
41constexpr const char* nightVisionSensorMode = "nightVisionSensorMode";
42
43//! \vreRoleParam{offsets,table,{},humanObserverUpdater,Table of observer offset configurations for different postures and view modes.}
44constexpr const char* offsets = "offsets";
45
46//! \vreRoleParam{postureChangeSpeed,double,2.0,humanObserverUpdater,Speed of observer position changes when posture changes.}
47constexpr const char* postureChangeSpeed = "postureChangeSpeed";
48
49//! \vreRoleParam{scopeChannelName,string,RemoteView,humanObserverUpdater,Channel name for scope rendering.}
50constexpr const char* scopeChannelName = "scopeChannelName";
51
52//! \vreRoleParam{scopeWalkingPitch,double,-45.0,humanObserverUpdater,Pitch angle for scope view when walking.}
53constexpr const char* scopeWalkingPitch = "scopeWalkingPitch";
54
55//! \vreRoleParam{thirdPersonAimSpeed,double,9.0,humanObserverUpdater,Speed of observer movements in third-person aiming mode.}
56constexpr const char* thirdPersonAimSpeed = "thirdPersonAimSpeed";
57
58//! @}
59} // namespace HumanObserverUpdaterConfig
60
61} // namespace makVre
62
63namespace makVrv
64{
65//! \brief Forward declaration of the display element class
66class DtDe;
67
68//! \brief Forward declaration of the observer class
69class DtObserver;
70
71//! \brief Forward declaration of the scene object class
72class DtSceneObject;
73}; // namespace makVrv
74
75namespace makVre
76{
77//! \brief Forward declaration of the initialization table class
78class DtInitTable;
79
80//! \brief Forward declaration of the entity resolver class
82
83//! \brief Type identifier for DtHumanObserverUpdater component
84constexpr const char* DtHumanObserverUpdaterType = "DtHumanObserverUpdater";
85
86//! \brief Observer updater component for the human role
87//!
88//! DtHumanObserverUpdater manages the observer (camera) behavior for the human role,
89//! including handling different view modes, player postures, attachments, and special
90//! effects like NVG and flashlights. It handles positioning, orientation, and updates
91//! of the observer based on the player state.
93{
94public:
95 //! \brief Default constructor
97
98 //! \brief Virtual destructor
99 virtual ~DtHumanObserverUpdater() override;
100
101 //! \brief Initializes the observer updater component
102 //! \param player Pointer to the player station
103 //! \param config Configuration settings for initialization
104 //! \return True if initialization was successful, false otherwise
105 virtual bool initialize(DtPlayerStation* player, DtInitTable& config) override;
106
107 //! \brief Performs post-initialization setup
108 //! \return True if post-initialization was successful, false otherwise
109 virtual bool postInitialize() override;
110
111 //! \brief Updates the observer for the current frame
112 //! \param dt Delta time since the last frame in seconds
113 virtual void tick(double dt) override;
114
115 //! \brief Cleans up resources when the component is being shut down
116 virtual void shutdown() override;
117
118 //! \brief Returns the component type identifier
119 //! \return The component type string
120 virtual const char* type() const override;
121
122 //! \brief Gets the current observer attachment mode
123 //! \return Current observer attachment mode
125
126protected:
127 //! \brief Updates the observer attachment offset based on current state
128 //! \param dt Delta time since the last frame in seconds
129 void updateAttachmentOffset(double dt);
130
131 //! \brief Gets the current pitch angle of the player
132 //! \return Current pitch angle in radians
133 double getPitch();
134
135 //! \brief Gets the current yaw angle of the player
136 //! \return Current yaw angle in radians
137 double getYaw();
138
139 //! \brief Gets the current camera offset from the player
140 //! \return Camera offset vector
141 DtVector getCameraOffset();
142
143 //! \brief Updates the target zoom level based on current observer state and equipment
144 //!
145 //! This function calculates and sets the appropriate zoom level based on the current
146 //! observer attach mode, aiming state, and equipped weapon type. When aiming from
147 //! first person view (and not using VR), it applies equipment-specific zoom levels:
148 //! - Guns: Uses currentGunZoomLevel attribute (default 2.2x if not set)
149 //! - Launchers: Uses viewMagnification attribute (default 1.0x if not set)
150 //! When not aiming or not in first person mode, zoom is reset to 1.0x.
151 //!
152 //! \note This function modifies the myTargetZoom member variable
153 //! \note VR mode disables zoom functionality
154 //! \note Gun zoom levels are now configured per weapon via currentGunZoomLevel attribute
155 virtual void updateZoomLevel();
156
157 //! \brief Rotates a vector by the specified pitch and yaw angles
158 //! \param localSpineToCamera Vector to rotate
159 //! \param pitch Pitch angle in radians
160 //! \param yaw Yaw angle in radians
161 //! \return Rotated vector
162 DtVector rotateVector(const DtVector& localSpineToCamera, double pitch, double yaw = 0.0);
163
164 //! \brief Updates the observer position and orientation based on current state
166
167 //! \brief Updates the scope observer properties
168 //! \param observer Pointer to the scope observer to update
169 void updateScopeObserver(makVrv::DtObserver* observer);
170
171 //! \brief Updates the observer view magnification (zoom)
172 //! \param dt Delta time since the last frame in seconds
174
175 //! \brief Sets the destination offset for the observer
176 //! \param mode Observer attachment mode
177 //! \param posture Current human posture
179
180 //! \brief Updates the flashlight state based on current player state
181 virtual void updateFlashlightState();
182
183 //! \brief Updates the compass display state
184 //!
185 //! Updates DisplayCompass state attribute in the DtObserverModeManager, with value
186 //! of the makVre::DtState attribute "compass". This shows/hides the built-in VR-Vantage
187 //! compass widget.
188 virtual void updateCompassState();
189
190 //! \brief Handles changes in night vision goggles state
191 //! \param nvg True if NVG is enabled, false otherwise
192 virtual void onNVGChanged(bool nvg);
193
194 //! \brief Checks if the observer pitch is at an angle above the terrain
195 //! \return True if the observer pitch is above the threshold (0.8), false otherwise
196 virtual bool observerPitchCheck();
197
198 //! \brief Updates state attributes based on current observer state
199 virtual void updateStateAttributes() override;
200
201 //! \brief Handles observer mode setting changes
202 //! \param mode Observer mode that changed
203 //! \param setting Setting that changed
204 //!
205 //! Called when an observer mode's setting changes; if it's the mode our observer is
206 //! using and the setting is DisplayCompass, update corresponding state attribute.
207 virtual void slot_observerModeSettingChanged(int mode, int setting);
208
209protected:
210 //! \brief Pointer to the managed observer
211 makVrv::DtObserver* myObserver;
212
213 //! \brief Unique ID of the player element
214 makVrv::DtUniqueID myPlayerElementID;
215
216 //! \brief Flag indicating if the observer is currently attached
218
219 //! \brief Position of the spine end point
220 //!
221 //! These two should really be pulled from the gun/arms model
222 //! once vrvDiguy can getLinkPosition
224
225 //! \brief Vector from spine to camera position
227
228 //! \brief Distance threshold for switching to first-person view
230
231 //! \brief Speed of posture change transition
233
234 //! \brief Speed of attachment mode transition
236
237 //! \brief Speed of third-person aiming transition
239
240 //! \brief Structure representing an observer offset configuration
241 struct Offset
242 {
243 DtVector pos; //!< Position offset vector
244 HumanPosture posture; //!< Human posture associated with this offset
245 ObserverAttachMode mode; //!< Observer attachment mode associated with this offset
246
247 //! \brief Equality comparison operator
248 //! \param other Offset to compare with
249 //! \return True if offsets are equal, false otherwise
250 bool operator==(const Offset& other)
251 {
252 return pos == other.pos && posture == other.posture && mode == other.mode;
253 }
254
255 //! \brief Inequality comparison operator
256 //! \param other Offset to compare with
257 //! \return True if offsets are not equal, false otherwise
258 bool operator!=(const Offset& other)
259 {
260 return pos != other.pos || posture != other.posture || mode != other.mode;
261 }
262
263 //! \brief Assignment operator
264 //! \param other Offset to assign from
265 //! \return Reference to this offset
266 Offset& operator=(const Offset& other)
267 {
268 pos = other.pos;
269 posture = other.posture;
270 mode = other.mode;
271 return *this;
272 }
273 };
274 //! \brief Map of observer offsets indexed by a combined posture and mode key
275 std::map<int, Offset> myOffsets;
276
277 //! \brief Builds a lookup key for the offset map from posture and mode
278 //! \param mode Observer attachment mode
279 //! \param posture Human posture
280 //! \return Combined integer key for offset lookup
281 int buildOffsetKey(ObserverAttachMode mode, HumanPosture posture) { return int(mode) | (int(posture) << 16); }
282 //! \brief Previous observer offset
284
285 //! \brief Current observer offset
287
288 //! \brief Target destination observer offset
290
291 //! \brief Flag indicating if posture has changed this frame
293
294 //! \brief Target zoom level for the observer
296
297 //! \brief Interpolator for smooth zoom transitions
299
300 //! \brief Last known state of the flashlight
302
303 //! \brief Last known state of the compass
305
306 //! \brief Last known state of night vision goggles
308
309 //! \brief Last flashlight pitch angle
311
312 //! \brief Last flashlight yaw angle
314
315 //! \brief Flag indicating if using VR mode
317
318 //! \brief Interpolator for first-person model translation offset
320
321 //! \brief Interpolator for first-person model rotation offset
323
324 //! \brief Flag indicating if the player was aiming in the previous frame
326
327 //! \brief Name of the scope channel
329
330 //! \brief Scope walking pitch adjustment
332
333 //! \brief Maximum allowed observer pitch angle
335
336 //! \brief Name of the observer mode to use for NVG
337 //!
338 //! DtObserverMode to use for night vision goggles mode
340};
341} // namespace makVre
Entity resolution and mapping system.
Definition entityResolver.h:52
double myScopeWalkingPitch
Scope walking pitch adjustment.
Definition humanObserverUpdater.h:331
bool myPostureChanged
Flag indicating if posture has changed this frame.
Definition humanObserverUpdater.h:292
makVre::DtLinearInterpolator< DtVector > * myFirstPersonModelTranslationOffsetInterpolator
Interpolator for first-person model translation offset.
Definition humanObserverUpdater.h:319
double getPitch()
Gets the current pitch angle of the player.
DtVector mySpineEndPosition
Position of the spine end point.
Definition humanObserverUpdater.h:223
int buildOffsetKey(ObserverAttachMode mode, HumanPosture posture)
Builds a lookup key for the offset map from posture and mode.
Definition humanObserverUpdater.h:281
DtHumanObserverUpdater()
Default constructor.
virtual void onNVGChanged(bool nvg)
Handles changes in night vision goggles state.
bool myLastNVGState
Last known state of night vision goggles.
Definition humanObserverUpdater.h:307
bool myLastFlashlightState
Last known state of the flashlight.
Definition humanObserverUpdater.h:301
void updateAttachmentOffset(double dt)
Updates the observer attachment offset based on current state.
Offset myDestinationOffset
Target destination observer offset.
Definition humanObserverUpdater.h:289
double myThirdPersonAimSpeed
Speed of third-person aiming transition.
Definition humanObserverUpdater.h:238
bool myObserverIsAttached
Flag indicating if the observer is currently attached.
Definition humanObserverUpdater.h:217
virtual void updateZoomLevel()
Updates the target zoom level based on current observer state and equipment.
void updateObserverPositionAndOrientation()
Updates the observer position and orientation based on current state.
makVrv::DtUniqueID myPlayerElementID
Unique ID of the player element.
Definition humanObserverUpdater.h:214
double myTargetZoom
Target zoom level for the observer.
Definition humanObserverUpdater.h:295
virtual ~DtHumanObserverUpdater() override
Virtual destructor.
double myLastFlashlightYaw
Last flashlight yaw angle.
Definition humanObserverUpdater.h:313
Offset myCurrentOffset
Current observer offset.
Definition humanObserverUpdater.h:286
double myAttachModeSpeed
Speed of attachment mode transition.
Definition humanObserverUpdater.h:235
bool myLastCompassState
Last known state of the compass.
Definition humanObserverUpdater.h:304
bool myWasAiming
Flag indicating if the player was aiming in the previous frame.
Definition humanObserverUpdater.h:325
double myPostureChangeSpeed
Speed of posture change transition.
Definition humanObserverUpdater.h:232
virtual void updateStateAttributes() override
Updates state attributes based on current observer state.
double myLastFlashlightPitch
Last flashlight pitch angle.
Definition humanObserverUpdater.h:310
DtVector getCameraOffset()
Gets the current camera offset from the player.
Offset myPriorOffset
Previous observer offset.
Definition humanObserverUpdater.h:283
makVre::DtLinearInterpolator< DtVector > * myFirstPersonModelRotateOffsetInterpolator
Interpolator for first-person model rotation offset.
Definition humanObserverUpdater.h:322
std::string myScopeChannelName
Name of the scope channel.
Definition humanObserverUpdater.h:328
double getYaw()
Gets the current yaw angle of the player.
void updateObserverViewMagnification(double dt)
Updates the observer view magnification (zoom)
virtual const char * type() const override
Returns the component type identifier.
virtual void tick(double dt) override
Updates the observer for the current frame.
virtual void shutdown() override
Cleans up resources when the component is being shut down.
bool myUsingVr
Flag indicating if using VR mode.
Definition humanObserverUpdater.h:316
DtVector rotateVector(const DtVector &localSpineToCamera, double pitch, double yaw=0.0)
Rotates a vector by the specified pitch and yaw angles.
DtVector mySpineToCameraVector
Vector from spine to camera position.
Definition humanObserverUpdater.h:226
std::string myNightVisionSensorMode
Name of the observer mode to use for NVG.
Definition humanObserverUpdater.h:339
double myCutToFirstPersonDist
Distance threshold for switching to first-person view.
Definition humanObserverUpdater.h:229
virtual bool initialize(DtPlayerStation *player, DtInitTable &config) override
Initializes the observer updater component.
virtual bool observerPitchCheck()
Checks if the observer pitch is at an angle above the terrain.
makVrv::DtObserver * myObserver
Pointer to the managed observer.
Definition humanObserverUpdater.h:211
void updateScopeObserver(makVrv::DtObserver *observer)
Updates the scope observer properties.
virtual bool postInitialize() override
Performs post-initialization setup.
double myMaxObserverPitch
Maximum allowed observer pitch angle.
Definition humanObserverUpdater.h:334
virtual void slot_observerModeSettingChanged(int mode, int setting)
Handles observer mode setting changes.
std::map< int, Offset > myOffsets
Map of observer offsets indexed by a combined posture and mode key.
Definition humanObserverUpdater.h:275
virtual void updateFlashlightState()
Updates the flashlight state based on current player state.
virtual ObserverAttachMode getAttachMode()
Gets the current observer attachment mode.
makVre::DtLinearInterpolator< double > * myZoomInterpolator
Interpolator for smooth zoom transitions.
Definition humanObserverUpdater.h:298
virtual void updateCompassState()
Updates the compass display state.
virtual void setDestinationOffset(ObserverAttachMode mode, HumanPosture posture)
Sets the destination offset for the observer.
Table-based access to Lua state for configuration data.
Definition initializer.h:38
Linear interpolation template class.
Definition linearInterpolator.h:23
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
Base component for managing observer parameters and view settings.
constexpr const char * postureChangeSpeed
Definition humanObserverUpdater.h:47
constexpr const char * cutToFirstPersonDist
Definition humanObserverUpdater.h:38
constexpr const char * thirdPersonAimSpeed
Definition humanObserverUpdater.h:56
constexpr const char * scopeChannelName
Definition humanObserverUpdater.h:50
constexpr const char * nightVisionSensorMode
Definition humanObserverUpdater.h:41
constexpr const char * offsets
Definition humanObserverUpdater.h:44
constexpr const char * attachModeTransitionSpeed
Definition humanObserverUpdater.h:35
constexpr const char * scopeWalkingPitch
Definition humanObserverUpdater.h:53
Defines export macros for the Human Frontend library.
#define HUMAN_DLL
Definition export.h:19
Provides a template class for linear interpolation between values.
Definition humanObserverUpdater.h:27
Include export definitions for this library.
Definition glsVreMessageUtil.h:49
ObserverAttachMode
Enumeration of camera/observer attachment offsets.
Definition stateDefines.h:44
HumanPosture
Enumeration of human posture states.
Definition stateDefines.h:30
constexpr const char * DtHumanObserverUpdaterType
Type identifier for DtHumanObserverUpdater component.
Definition humanObserverUpdater.h:84
Definition appLauncherComponent.h:28
Common enumeration definitions used throughout the VREngage system.
Structure representing an observer offset configuration.
Definition humanObserverUpdater.h:242
bool operator==(const Offset &other)
Equality comparison operator.
Definition humanObserverUpdater.h:250
bool operator!=(const Offset &other)
Inequality comparison operator.
Definition humanObserverUpdater.h:258
Offset & operator=(const Offset &other)
Assignment operator.
Definition humanObserverUpdater.h:266
DtVector pos
Position offset vector.
Definition humanObserverUpdater.h:243
HumanPosture posture
Human posture associated with this offset.
Definition humanObserverUpdater.h:244
ObserverAttachMode mode
Observer attachment mode associated with this offset.
Definition humanObserverUpdater.h:245
Defines the base class for all VREngage messages.