VR-Engage  2.2
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"
16
17#include "vreUtil/virtualDpad.h"
18
21
23
24namespace makVre
25{
26
28{
29//! \ingroup RoleConfigParams
30//! \defgroup HumanVirtualRealityLogicRoleParams Human Virtual Reality Logic Role Parameters
31//! \roleInherits{PlayerComponentRoleParams}
32//! Configuration Options for human virtual reality logic component.
33//! @{
34
35//! \vreRoleParam{rightHanded,bool,true,humanVirtualRealityLogic,Whether the user is right-handed for VR controller handedness mapping.}
36constexpr const char* rightHanded = "rightHanded";
37
38//! @}
39} // namespace HumanVirtualRealityLogicConfig
40
41} // namespace makVre
42
43namespace makVrv
44{
45//! \brief Forward declaration of the display element class
46class DtDe;
47
48//! \brief Forward declaration of the observer class
49class DtObserver;
50
51//! \brief Forward declaration of the virtual reality driver class
52class DtVirtualRealityDriver;
53
54//! \brief Forward declaration of the submit overlay callback class
55class DtSubmitOverlayCallback;
56} // namespace makVrv
57
58namespace makVre
59{
60//! \brief Forward declaration of the action menu logic class
62
63//! \brief Forward declaration of the human VR event processor class
64class DtHumanVrEventProcessor;
65
66//! \brief Forward declaration of the human control logic class
68
69//! \brief Type identifier constant for DtHumanVirtualRealityLogic components
70//!
71//! This constant defines the string identifier used to identify DtHumanVirtualRealityLogic
72//! component types within the VR-Engage framework. It is used for component
73//! registration, type checking, and serialization operations.
74constexpr const char* DtHumanVirtualRealityLogicType = "DtHumanVirtualRealityLogic";
75
76//! \brief Virtual reality logic component for the human role
77//!
78//! DtHumanVirtualRealityLogic manages VR-specific interaction for the human role,
79//! including processing controller input, head tracking, hand tracking, and
80//! providing VR-specific behavior for weapons, movement, and interaction.
81//! It translates VR controller input into appropriate simulation actions.
83{
84public:
85 //! \brief Type alias for the controller state map
87
88 //! \brief Type alias for the controller state bitfield
90
91 //! \brief Type alias for the controller identifier
93
94 //! \brief Type alias for 2D vector used by VR controllers
96
97 //! \brief Type alias for the VR controller state
99
100 //! \brief Default constructor
102
103 //! \brief Virtual destructor
104 virtual ~DtHumanVirtualRealityLogic() override;
105
106 //! \brief Initializes the VR logic component
107 //! \param player Pointer to the player station
108 //! \param config Configuration settings for initialization
109 //! \return True if initialization was successful, false otherwise
111
112 //! \brief Performs post-initialization setup
113 //! \return True if post-initialization was successful, false otherwise
114 virtual bool postInitialize() override;
115
116 //! \brief Updates VR processing for the current frame
117 //! \param dt Delta time since the last frame in seconds
118 virtual void tick(double dt) override;
119
120 //! \brief Cleans up resources when the component is being shut down
121 virtual void shutdown() override;
122
123 //! \brief Returns the component type identifier
124 //! \return String identifier for this component type
125 //!
126 //! Returns the type identifier string for this component, which is used
127 //! by the VR-Engage framework for component identification and management.
128 //! The returned value matches DtHumanVirtualRealityLogicType.
129 virtual const char* type() const override;
130
131 //! \brief Processes controller state updates
132 //! \param stateMap Map of controller states to process
133 virtual void processControllerStates(const ControllerStateMap& stateMap);
134
135 //! \brief Resets the head position in VR
136 //!
137 //! Recenters the VR view based on the current physical head position
138 virtual void resetHeadPos();
139
140 //! \brief Input handler for resetting head position
141 //! \param val Input value (1 to trigger reset)
142 //!
143 //! Handles the reset head position input action from bound controls
144 virtual void handleResetHeadPosInput(int val);
145
146protected:
147 //! \brief Structure for identifying a specific VR controller
149 {
150 //! \brief Constructor
151 //! \param type Controller type bitfield
157
158 Bitfield controllerType; //!< Type of the controller
159 ControllerId controllerId; //!< Unique identifier for the controller
160 };
161
162 //! \brief Starts VR mode
163 //!
164 //! Initializes and enables VR rendering and input
165 virtual void startVr();
166
167 //! \brief Stops VR mode
168 //!
169 //! Disables VR rendering and input
170 virtual void stopVr();
171
172 //! \brief Handles VR head position reset messages
173 //! \param msg Pointer to the message being processed
174 //! \return Message processing result
176
177 //! \brief Handles toggle mixed reality messages
178 //! \param msg Pointer to the message being processed
179 //! \return Message processing result
181
182 //! \brief Handles player state enter messages
183 //! \param msg Pointer to the message being processed
184 //! \return Message processing result
185 //!
186 //! If incoming message is for entering the menu state, disables VR
188
189 //! \brief Handles player state exit messages
190 //! \param msg Pointer to the message being processed
191 //! \return Message processing result
192 //!
193 //! If incoming message is for exiting the menu state, enables VR
195
196 //! \brief Finds a controller in the controller state map
197 //! \param identifier [in,out] Identifier of the controller to find
198 //! \param stateMap Map of controller states to search in
199 //! \return Pointer to the found controller state, or nullptr if not found
200 virtual const ControllerState* findController(ControllerIdentifier& identifier, const ControllerStateMap& stateMap);
201
202 //! \brief Applies yaw rotation input
203 //! \param val Yaw rotation value
204 virtual void yaw(double val);
205
206 //! \brief Pointer to the VR driver
207 makVrv::DtVirtualRealityDriver* myVrDriver;
208
209 //! \brief Pointer to the VR event processor
210 DtHumanVrEventProcessor* myEventProcessor;
211
212 //! \brief Pointer to the human control logic component
214
215 //! \brief Pointer to the action menu logic component
217
218 //! \brief Pointer to the VR overlay callback
219 makVrv::DtSubmitOverlayCallback* myVrOverlay;
220
221 //! \brief Flag indicating if VR is currently enabled
223
224 //! \brief Flag tracking previous VR enabled state
226
227 //! \brief Flag indicating if the player is right-handed
229
230 //! \brief Flag indicating if single-hand aiming is enabled
232
233 //! \brief Flag tracking if hand motion was detected
235
236 //! \brief Flag tracking if a no-motion reset was performed
238
239 //! \brief Identifier for the head/HMD controller
241
242 //! \brief Identifier for the left hand controller
244
245 //! \brief Identifier for the right hand controller
247
248 //! \brief Weapon orientation override in Tait-Bryan angles
249 DtTaitBryan myWeaponOverride;
250
251 //! \brief Counter for frames elapsed since menu was active
253
254 //! \brief Virtual direction pad for VR movement
256
257 //! \brief Last known render order for the main channel
259
260 //! \brief Current heading angle in radians
261 //! \note Temporary variable replicating humanControlLogic until proper VR input support (VRE-3178)
263
264 //! \brief Current yaw angle in radians
265 //! \note Temporary variable replicating humanControlLogic until proper VR input support (VRE-3178)
266 double myYaw;
267
268 //! \brief Current aim yaw angle in radians
269 //! \note Temporary variable replicating humanControlLogic until proper VR input support (VRE-3178)
270 double myAimYaw;
271
272 //! \brief Current aim pitch angle in radians
273 //! \note Temporary variable replicating humanControlLogic until proper VR input support (VRE-3178)
275
276 //! \brief Flag indicating if VR input is available
277 //! \note Temporary variable replicating humanControlLogic until proper VR input support (VRE-3178)
279
280 //! \brief Flag indicating if heading has been initialized
281 //! \note Temporary variable replicating humanControlLogic until proper VR input support (VRE-3178)
283};
284} // namespace makVre
Defines a class that encapsulates the state of a VR controller.
Defines the base class for VR controller event management.
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:95
Control logic component for the human entity.
Definition humanControlLogic.h:138
int myLastMainChannelRenderOrder
Last known render order for the main channel.
Definition humanVirtualRealityLogic.h:258
bool myDidNoHandMotionReset
Flag tracking if a no-motion reset was performed.
Definition humanVirtualRealityLogic.h:237
bool myHasVRInput
Flag indicating if VR input is available.
Definition humanVirtualRealityLogic.h:278
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:252
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:216
makVrv::DtVirtualRealityControllerState::Bitfield Bitfield
Type alias for the controller state bitfield.
Definition humanVirtualRealityLogic.h:89
DtTaitBryan myWeaponOverride
Weapon orientation override in Tait-Bryan angles.
Definition humanVirtualRealityLogic.h:249
bool myVrEnabled
Flag indicating if VR is currently enabled.
Definition humanVirtualRealityLogic.h:222
bool myDidHaveHandMotion
Flag tracking if hand motion was detected.
Definition humanVirtualRealityLogic.h:234
makVrv::DtVirtualRealityEventManager::ControllerStateMap ControllerStateMap
Type alias for the controller state map.
Definition humanVirtualRealityLogic.h:86
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:219
bool myInitializedHeading
Flag indicating if heading has been initialized.
Definition humanVirtualRealityLogic.h:282
double myAimPitch
Current aim pitch angle in radians.
Definition humanVirtualRealityLogic.h:274
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:92
ControllerIdentifier myLeftHandId
Identifier for the left hand controller.
Definition humanVirtualRealityLogic.h:243
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:213
ControllerIdentifier myRightHandId
Identifier for the right hand controller.
Definition humanVirtualRealityLogic.h:246
bool myRightHanded
Flag indicating if the player is right-handed.
Definition humanVirtualRealityLogic.h:228
double myAimYaw
Current aim yaw angle in radians.
Definition humanVirtualRealityLogic.h:270
makVrv::DtVirtualRealityDriver * myVrDriver
Pointer to the VR driver.
Definition humanVirtualRealityLogic.h:207
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:98
DtVirtualDpad myVirtualDpad
Virtual direction pad for VR movement.
Definition humanVirtualRealityLogic.h:255
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:225
double myCurrentHeading
Current heading angle in radians.
Definition humanVirtualRealityLogic.h:262
ControllerIdentifier myHeadId
Identifier for the head/HMD controller.
Definition humanVirtualRealityLogic.h:240
DtHumanVrEventProcessor * myEventProcessor
Pointer to the VR event processor.
Definition humanVirtualRealityLogic.h:210
makVrv::DtVirtualRealityControllerState::DtVector2f DtVector2f
Type alias for 2D vector used by VR controllers.
Definition humanVirtualRealityLogic.h:95
virtual void processControllerStates(const ControllerStateMap &stateMap)
Processes controller state updates.
bool mySingleHandAiming
Flag indicating if single-hand aiming is enabled.
Definition humanVirtualRealityLogic.h:231
virtual void shutdown() override
Cleans up resources when the component is being shut down.
double myYaw
Current yaw angle in radians.
Definition humanVirtualRealityLogic.h:266
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:78
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
Encapsulates the complete state of a virtual reality controller.
Definition DtVirtualRealityControllerState.h:35
DtVector2< float32 > DtVector2f
Type used for 2D vector values.
Definition DtVirtualRealityControllerState.h:52
unsigned long long Bitfield
Type used for bit flags throughout the class.
Definition DtVirtualRealityControllerState.h:41
unsigned int ControllerId
Type used for controller identification.
Definition DtVirtualRealityControllerState.h:46
std::map< unsigned int, DtVirtualRealityControllerState * > ControllerStateMap
Map type that associates controller IDs with their state objects.
Definition DtVirtualRealityEventManager.h:60
constexpr const char * rightHanded
Definition humanVirtualRealityLogic.h:36
Defines export macros for the Human Frontend library.
#define HUMAN_DLL
Definition export.h:19
Definition humanVirtualRealityLogic.h:28
Include export definitions for this library.
Definition glsVreMessageUtil.h:49
constexpr const char * DtHumanVirtualRealityLogicType
Type identifier constant for DtHumanVirtualRealityLogic components.
Definition humanVirtualRealityLogic.h:74
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.
Structure for identifying a specific VR controller.
Definition humanVirtualRealityLogic.h:149
ControllerId controllerId
Unique identifier for the controller.
Definition humanVirtualRealityLogic.h:159
ControllerIdentifier(Bitfield type)
Constructor.
Definition humanVirtualRealityLogic.h:152
Bitfield controllerType
Type of the controller.
Definition humanVirtualRealityLogic.h:158
Provides a virtual directional pad implementation.
Defines the base class for all VREngage messages.