VR-Engage  2.3
Loading...
Searching...
No Matches
humanVirtualRealityLogic.h
Go to the documentation of this file.
1/******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4******************************************************************************/
5
6//! \file humanVirtualRealityLogic.h
7//! \brief Defines DtHumanVirtualRealityLogic for managing human-specific VR interaction
8//! \ingroup vreHumanFrontend
9
10#pragma once
11
13
15#include "vreUtil/attribute.h"
17
18#include "vreUtil/virtualDpad.h"
19
23
26
27namespace makVre
28{
29
31{
32//! \ingroup RoleConfigParams
33//! \defgroup HumanVirtualRealityLogicRoleParams Human Virtual Reality Logic Role Parameters
34//! \roleInherits{PlayerComponentRoleParams}
35//! Configuration Options for human virtual reality logic component.
36//! @{
37
38//! \vreRoleParam{rightHanded,bool,true,humanVirtualRealityLogic,Whether the user is right-handed for VR controller handedness mapping.}
39constexpr const char* rightHanded = "rightHanded";
40
41//! @}
42} // namespace HumanVirtualRealityLogicConfig
43
44} // namespace makVre
45
46namespace makVrv
47{
48//! \brief Forward declaration of the display element class
49class DtDe;
50
51//! \brief Forward declaration of the observer class
52class DtObserver;
53
54//! \brief Forward declaration of the virtual reality driver class
55class DtVirtualRealityDriver;
56
57//! \brief Forward declaration of the submit overlay callback class
58class DtSubmitOverlayCallback;
59} // namespace makVrv
60
61namespace makVre
62{
63//! \brief Forward declaration of the action menu logic class
65
66//! \brief Forward declaration of the human VR event processor class
67class DtHumanVrEventProcessor;
68
69//! \brief Forward declaration of the human control logic class
71
72//! \brief Type identifier constant for DtHumanVirtualRealityLogic components
73//!
74//! This constant defines the string identifier used to identify DtHumanVirtualRealityLogic
75//! component types within the VR-Engage framework. It is used for component
76//! registration, type checking, and serialization operations.
77constexpr const char* DtHumanVirtualRealityLogicType = "DtHumanVirtualRealityLogic";
78
79//! \brief Virtual reality logic component for the human role
80//!
81//! DtHumanVirtualRealityLogic manages VR-specific interaction for the human role,
82//! including processing controller input, head tracking, hand tracking, and
83//! providing VR-specific behavior for weapons, movement, and interaction.
84//! It translates VR controller input into appropriate simulation actions.
86{
87public:
88 //! \brief Type alias for the controller state map
90
91 //! \brief Type alias for the controller state bitfield
93
94 //! \brief Type alias for the controller identifier
96
97 //! \brief Type alias for 2D vector used by VR controllers
99
100 //! \brief Type alias for the VR controller state
102
103 //! \brief Default constructor
105
106 //! \brief Virtual destructor
107 virtual ~DtHumanVirtualRealityLogic() override;
108
109 //! \brief Initializes the VR logic component
110 //! \param player Pointer to the player station
111 //! \param config Configuration settings for initialization
112 //! \return True if initialization was successful, false otherwise
114
115 //! \brief Performs post-initialization setup
116 //! \return True if post-initialization was successful, false otherwise
117 virtual bool postInitialize() override;
118
119 //! \brief Updates VR processing for the current frame
120 //! \param dt Delta time since the last frame in seconds
121 virtual void tick(double dt) override;
122
123 //! \brief Cleans up resources when the component is being shut down
124 virtual void shutdown() override;
125
126 //! \brief Returns the component type identifier
127 //! \return String identifier for this component type
128 //!
129 //! Returns the type identifier string for this component, which is used
130 //! by the VR-Engage framework for component identification and management.
131 //! The returned value matches DtHumanVirtualRealityLogicType.
132 virtual const char* type() const override;
133
134 //! \brief Processes controller state updates
135 //! \param stateMap Map of controller states to process
136 virtual void processControllerStates(const ControllerStateMap& stateMap);
137
138 //! \brief Resets the head position in VR
139 //!
140 //! Recenters the VR view based on the current physical head position
141 virtual void resetHeadPos();
142
143 //! \brief Input handler for resetting head position
144 //! \param val Input value (1 to trigger reset)
145 //!
146 //! Handles the reset head position input action from bound controls
147 virtual void handleResetHeadPosInput(int val);
148
149protected:
150 //! \brief Structure for identifying a specific VR controller
152 {
153 //! \brief Constructor
154 //! \param type Controller type bitfield
160
161 Bitfield controllerType; //!< Type of the controller
162 ControllerId controllerId; //!< Unique identifier for the controller
163 };
164
165 //! \brief Starts VR mode
166 //!
167 //! Initializes and enables VR rendering and input
168 virtual void startVr();
169
170 //! \brief Stops VR mode
171 //!
172 //! Disables VR rendering and input
173 virtual void stopVr();
174
175 //! \brief Handles VR head position reset messages
176 //! \param msg Pointer to the message being processed
177 //! \return Message processing result
179
180 //! \brief Handles toggle mixed reality messages
181 //! \param msg Pointer to the message being processed
182 //! \return Message processing result
184
185 //! \brief Handles player state enter messages
186 //! \param msg Pointer to the message being processed
187 //! \return Message processing result
188 //!
189 //! If incoming message is for entering the menu state, disables VR
191
192 //! \brief Handles player state exit messages
193 //! \param msg Pointer to the message being processed
194 //! \return Message processing result
195 //!
196 //! If incoming message is for exiting the menu state, enables VR
198
199 //! \brief Finds a controller in the controller state map
200 //! \param identifier [in,out] Identifier of the controller to find
201 //! \param stateMap Map of controller states to search in
202 //! \return Pointer to the found controller state, or nullptr if not found
203 virtual const ControllerState* findController(ControllerIdentifier& identifier, const ControllerStateMap& stateMap);
204
205 //! \brief Applies yaw rotation input
206 //! \param val Yaw rotation value
207 virtual void yaw(double val);
208
209 //! \brief Pointer to the VR driver
210 makVrv::DtVirtualRealityDriver* myVrDriver;
211
212 //! \brief Pointer to the VR event processor
213 DtHumanVrEventProcessor* myEventProcessor;
214
215 //! \brief Pointer to the human control logic component
217
218 //! \brief Pointer to the action menu logic component
220
221 //! \brief Pointer to the VR overlay callback
222 makVrv::DtSubmitOverlayCallback* myVrOverlay;
223
224 //! \brief Tracks temporary virtual reality settings applied by this component.
226
227 //! \brief Flag indicating if VR is currently enabled
229
230 //! \brief Flag tracking previous VR enabled state
232
233 //! \brief Flag indicating if the player is right-handed
235
236 //! \brief Flag indicating if single-hand aiming is enabled
238
239 //! \brief Flag tracking if hand motion was detected
241
242 //! \brief Flag tracking if a no-motion reset was performed
244
245 //! \brief Identifier for the head/HMD controller
247
248 //! \brief Identifier for the left hand controller
250
251 //! \brief Identifier for the right hand controller
253
254 //! \brief Weapon orientation override in Tait-Bryan angles
255 DtTaitBryan myWeaponOverride;
256
257 //! \brief Counter for frames elapsed since menu was active
259
260 //! \brief Virtual direction pad for VR movement
262
263 //! \brief Last known render order for the main channel
265
266 //! \brief Current heading angle in radians
267 //! \note Temporary variable replicating humanControlLogic until proper VR input support (VRE-3178)
269
270 //! \brief Current yaw angle in radians
271 //! \note Temporary variable replicating humanControlLogic until proper VR input support (VRE-3178)
272 double myYaw;
273
274 //! \brief Current aim yaw angle in radians
275 //! \note Temporary variable replicating humanControlLogic until proper VR input support (VRE-3178)
276 double myAimYaw;
277
278 //! \brief Current aim pitch angle in radians
279 //! \note Temporary variable replicating humanControlLogic until proper VR input support (VRE-3178)
281
282 //! \brief Flag indicating if VR input is available
283 //! \note Temporary variable replicating humanControlLogic until proper VR input support (VRE-3178)
285
286 //! \brief Flag indicating if heading has been initialized
287 //! \note Temporary variable replicating humanControlLogic until proper VR input support (VRE-3178)
289
290 //! \brief Handle for current weapon name.
291 //! \vreAttrKey{currentWeapon}
293
294 //! \brief Handle for current equipment.
295 //! \vreAttrKey{currentEquipment}
297
298 //! \brief Handle for the menu manager.
299 //! \vreAttrKey{menuManager}
301
302 //! \brief Handle for aiming state.
303 //! \vreAttrKey{aiming}
305
306 //! \brief Handle for binocular usage state.
307 //! \vreAttrKey{usingBinoculars}
309
310
311};
312} // namespace makVre
Defines a class that encapsulates the state of a VR controller.
Defines the base class for VR controller event management.
Defines the menu management system for VR-Engage.
Provides attribute handling system for hierarchical data storage and manipulation.
A class that simulates a directional pad from analog inputs.
Definition virtualDpad.h:22
Component for managing entity interaction menus and their logic.
Definition actionMenuLogic.h:101
Type-specific handle class for attributes.
Definition attributeHandle.h:229
Control logic component for the human entity.
Definition humanControlLogic.h:142
int myLastMainChannelRenderOrder
Last known render order for the main channel.
Definition humanVirtualRealityLogic.h:264
bool myDidNoHandMotionReset
Flag tracking if a no-motion reset was performed.
Definition humanVirtualRealityLogic.h:243
bool myHasVRInput
Flag indicating if VR input is available.
Definition humanVirtualRealityLogic.h:284
virtual void tick(double dt) override
Updates VR processing for the current frame.
virtual void handleResetHeadPosInput(int val)
Input handler for resetting head position.
int myFramesSinceMenu
Counter for frames elapsed since menu was active.
Definition humanVirtualRealityLogic.h:258
virtual makVre::DtVreMessageResult handleEnterPlayerState(makVre::DtVreMessage *msg)
Handles player state enter messages.
virtual makVre::DtVreMessageResult handleToggleMixedReality(makVre::DtVreMessage *msg)
Handles toggle mixed reality messages.
makVre::DtActionMenuLogic * myMenuLogic
Pointer to the action menu logic component.
Definition humanVirtualRealityLogic.h:219
makVrv::DtVirtualRealityControllerState::Bitfield Bitfield
Type alias for the controller state bitfield.
Definition humanVirtualRealityLogic.h:92
DtTaitBryan myWeaponOverride
Weapon orientation override in Tait-Bryan angles.
Definition humanVirtualRealityLogic.h:255
bool myVrEnabled
Flag indicating if VR is currently enabled.
Definition humanVirtualRealityLogic.h:228
bool myDidHaveHandMotion
Flag tracking if hand motion was detected.
Definition humanVirtualRealityLogic.h:240
makVrv::DtVirtualRealityEventManager::ControllerStateMap ControllerStateMap
Type alias for the controller state map.
Definition humanVirtualRealityLogic.h:89
virtual makVre::DtVreMessageResult handleResetVrHeadPos(makVre::DtVreMessage *msg)
Handles VR head position reset messages.
makVrv::DtSubmitOverlayCallback * myVrOverlay
Pointer to the VR overlay callback.
Definition humanVirtualRealityLogic.h:222
bool myInitializedHeading
Flag indicating if heading has been initialized.
Definition humanVirtualRealityLogic.h:288
double myAimPitch
Current aim pitch angle in radians.
Definition humanVirtualRealityLogic.h:280
virtual makVre::DtVreMessageResult handleExitPlayerState(makVre::DtVreMessage *msg)
Handles player state exit messages.
makVrv::DtVirtualRealityControllerState::ControllerId ControllerId
Type alias for the controller identifier.
Definition humanVirtualRealityLogic.h:95
DtAttributeHandleType< bool > myAimingAttr
Handle for aiming state.
Definition humanVirtualRealityLogic.h:304
ControllerIdentifier myLeftHandId
Identifier for the left hand controller.
Definition humanVirtualRealityLogic.h:249
DtAttributeHandleType< DtMenuManager * > myMenuManagerAttr
Handle for the menu manager.
Definition humanVirtualRealityLogic.h:300
DtHumanVirtualRealityLogic()
Default constructor.
virtual bool postInitialize() override
Performs post-initialization setup.
virtual void yaw(double val)
Applies yaw rotation input.
virtual void stopVr()
Stops VR mode.
virtual void startVr()
Starts VR mode.
DtHumanControlLogic * myHumanLogic
Pointer to the human control logic component.
Definition humanVirtualRealityLogic.h:216
DtAttributeHandleType< bool > myUsingBinocularsAttr
Handle for binocular usage state.
Definition humanVirtualRealityLogic.h:308
ControllerIdentifier myRightHandId
Identifier for the right hand controller.
Definition humanVirtualRealityLogic.h:252
bool myRightHanded
Flag indicating if the player is right-handed.
Definition humanVirtualRealityLogic.h:234
double myAimYaw
Current aim yaw angle in radians.
Definition humanVirtualRealityLogic.h:276
makVrv::DtVirtualRealityDriver * myVrDriver
Pointer to the VR driver.
Definition humanVirtualRealityLogic.h:210
virtual const ControllerState * findController(ControllerIdentifier &identifier, const ControllerStateMap &stateMap)
Finds a controller in the controller state map.
makVrv::DtVirtualRealityControllerState ControllerState
Type alias for the VR controller state.
Definition humanVirtualRealityLogic.h:101
DtAttributeHandleType< Equipment > myCurrentEquipmentAttr
Handle for current equipment.
Definition humanVirtualRealityLogic.h:296
DtVirtualDpad myVirtualDpad
Virtual direction pad for VR movement.
Definition humanVirtualRealityLogic.h:261
virtual const char * type() const override
Returns the component type identifier.
virtual ~DtHumanVirtualRealityLogic() override
Virtual destructor.
virtual void resetHeadPos()
Resets the head position in VR.
virtual bool initialize(makVre::DtPlayerStation *player, makVre::DtInitTable &config) override
Initializes the VR logic component.
bool myVrWasEnabled
Flag tracking previous VR enabled state.
Definition humanVirtualRealityLogic.h:231
DtSettingsOverrideGuard mySettingsOverrideGuard
Tracks temporary virtual reality settings applied by this component.
Definition humanVirtualRealityLogic.h:225
DtAttributeHandleType< std::string > myCurrentWeaponAttr
Handle for current weapon name.
Definition humanVirtualRealityLogic.h:292
double myCurrentHeading
Current heading angle in radians.
Definition humanVirtualRealityLogic.h:268
ControllerIdentifier myHeadId
Identifier for the head/HMD controller.
Definition humanVirtualRealityLogic.h:246
DtHumanVrEventProcessor * myEventProcessor
Pointer to the VR event processor.
Definition humanVirtualRealityLogic.h:213
makVrv::DtVirtualRealityControllerState::DtVector2f DtVector2f
Type alias for 2D vector used by VR controllers.
Definition humanVirtualRealityLogic.h:98
virtual void processControllerStates(const ControllerStateMap &stateMap)
Processes controller state updates.
bool mySingleHandAiming
Flag indicating if single-hand aiming is enabled.
Definition humanVirtualRealityLogic.h:237
virtual void shutdown() override
Cleans up resources when the component is being shut down.
double myYaw
Current yaw angle in radians.
Definition humanVirtualRealityLogic.h:272
Table-based access to Lua state for configuration data.
Definition initializer.h:38
Base class for all role components in VR-Engage.
Definition playerComponent.h:102
virtual DtPlayerStation & player()
Gets the player station.
Class for managing the user interface for engaged roles.
Definition playerStation.h:51
Tracks temporary settings overrides and conditionally restores them.
Definition settingsOverrideGuard.h:180
Abstract base class for all VREngage messages.
Definition vreMessage.h:50
Encapsulates the complete state of a virtual reality controller.
Definition DtVirtualRealityControllerState.h:34
DtVector2< float32 > DtVector2f
Type used for 2D vector values.
Definition DtVirtualRealityControllerState.h:51
unsigned long long Bitfield
Type used for bit flags throughout the class.
Definition DtVirtualRealityControllerState.h:40
unsigned int ControllerId
Type used for controller identification.
Definition DtVirtualRealityControllerState.h:45
std::map< unsigned int, DtVirtualRealityControllerState * > ControllerStateMap
Map type that associates controller IDs with their state objects.
Definition DtVirtualRealityEventManager.h:59
constexpr const char * rightHanded
Definition humanVirtualRealityLogic.h:39
Defines export macros for the Human Frontend library.
#define HUMAN_DLL
Definition export.h:19
Definition humanVirtualRealityLogic.h:31
!
Definition glsVreMessageUtil.h:50
constexpr const char * DtHumanVirtualRealityLogicType
Type identifier constant for DtHumanVirtualRealityLogic components.
Definition humanVirtualRealityLogic.h:77
DtVreMessageResult
Enumeration of possible message handling results.
Definition vreMessage.h:33
Definition appLauncherComponent.h:28
Defines the DtPlayerComponent base class for VR-Engage role components.
Defines a guard for temporary, non-persistent settings overrides.
Common enumeration definitions used throughout the VREngage system.
Structure for identifying a specific VR controller.
Definition humanVirtualRealityLogic.h:152
ControllerId controllerId
Unique identifier for the controller.
Definition humanVirtualRealityLogic.h:162
ControllerIdentifier(Bitfield type)
Constructor.
Definition humanVirtualRealityLogic.h:155
Bitfield controllerType
Type of the controller.
Definition humanVirtualRealityLogic.h:161
Provides a virtual directional pad implementation.
Defines the base class for all VREngage messages.