VR-Engage  2.3
Loading...
Searching...
No Matches
virtualRealityLogic.h
Go to the documentation of this file.
1/******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4******************************************************************************/
5
6//! \file virtualRealityLogic.h
7//! \brief Component for managing VR hardware integration and controller input
8//! \ingroup vreCommonComponents
9
10#pragma once
11
13
16
18#include "vreUtil/virtualDpad.h"
20
21
24
25namespace makVrv
26{
27class DtDe;
28class DtObserver;
29class DtVirtualRealityDriver;
30class DtSubmitOverlayCallback;
31} // namespace makVrv
32
33namespace makVre
34{
35
36class DtVirtualRealityEventProcessor;
38
40{
41//! \ingroup RoleConfigParams
42//! \defgroup VirtualRealityLogicRoleParams Virtual Reality Logic Role Parameters
43//! \roleInherits{PlayerComponentRoleParams}
44//! Configuration Options for virtual reality logic role.
45//! @{
46
47//! \vreRoleParam{rightHanded,bool,true,virtualRealityLogic,Determines whether the user is right-handed for controller orientation settings.}
48constexpr const char* rightHanded = "rightHanded";
49
50//! @}
51} // namespace VirtualRealityLogicConfig
52
53//! \brief Type identifier for DtVirtualRealityLogic component
54constexpr const char* DtVirtualRealityLogicType = "DtVirtualRealityLogic";
55
56//! \brief Component that integrates VR hardware with the simulation environment
57//!
58//! DtVirtualRealityLogic manages the connection between VR hardware (headsets and
59//! controllers) and the simulation, processing controller input events and managing
60//! the VR view state. It handles controller tracking, head position resetting,
61//! menu interactions, and mixed reality mode toggling. This component enables
62//! and disables VR mode during player state transitions, such as when entering menus.
64{
65public:
66 //! \brief Type alias for a map of controller IDs to controller state pointers
68
69 //! \brief Type alias for controller type bitfield values
71
72 //! \brief Type alias for controller identifier values
74
75 //! \brief Type alias for 2D vector used in controller inputs
77
78 //! \brief Type alias for virtual reality controller state
80
81 //! \brief Constructor for DtVirtualRealityLogic
82 //!
83 //! Initializes the component with default settings for controller identification
84 //! and tracking state
86
87 //! \brief Virtual destructor for DtVirtualRealityLogic
88 virtual ~DtVirtualRealityLogic() override;
89
90 //! \brief Initializes the virtual reality logic component
91 //! \param player Pointer to the player station this component belongs to
92 //! \param config Configuration table containing VR settings
93 //! \return True if initialization succeeded, false otherwise
94 //!
95 //! Sets up the VR driver connection, configures input handlers, and establishes
96 //! message handlers for VR-related events
98 //! \brief Called every frame to update the VR state
99 //! \param dt Delta time since the last frame in seconds
100 //!
101 //! Monitors VR enabled state changes, updates controller tracking,
102 //! and manages overlay visibility
103 virtual void tick(double dt) override;
104 //! \brief Shuts down the virtual reality logic component
105 //!
106 //! Stops VR mode, disconnects message handlers, and performs cleanup operations
107 virtual void shutdown() override;
108
109 //! \brief Returns the type identifier for this component
110 //! \return The type string for DtVirtualRealityLogic
111 virtual const char* type() const override;
112
113 //! \brief Processes the current state of all tracked VR controllers
114 //! \param controllers Map of controller IDs to their current state
115 //!
116 //! Handles controller discovery/loss events, processes button presses and
117 //! thumbstick movements, and translates them into simulation actions
118 virtual void processControllerStates(const ControllerStateMap& controllers);
119
120 //! \brief Resets the HMD head position tracking
121 //!
122 //! Calls the VR driver to reset the head position and orientation reference
123 virtual void resetHeadPos();
124
125 //! \brief Input handler for resetting head position
126 //! \param val Input value (1 to trigger reset)
127 //!
128 //! Handles the reset head position input action from bound controls
129 virtual void handleResetHeadPosInput(int val);
130
131protected:
132 //! \brief Structure for identifying and tracking VR controllers
133 //!
134 //! Contains both the controller type (HMD, left hand, right hand) and
135 //! its unique identifier used for consistent tracking between frames
137 {
138 //! \brief Constructor that initializes with a controller type
139 //! \param type Bitfield value representing the controller type
145
146 //! \brief Type of the controller (HMD, left hand, right hand)
148
149 //! \brief Unique identifier for the controller instance
151 };
152
153 //! \brief Starts VR mode
154 //!
155 //! Assigns observers to the HMD, sets up event handlers, configures
156 //! post-processing, and updates state attributes
157 virtual void startVr();
158
159 //! \brief Stops VR mode
160 //!
161 //! Removes event handlers, cleans up resources, and resets channel render orders
162 virtual void stopVr();
163
164 //! \brief Handles reset VR head position message
165 //! \param msg The reset head position message
166 //! \return Message handling result indicating if the message was handled
167 //!
168 //! Processes request to reset the VR headset position tracking
170
171 //! \brief Handles toggle mixed reality message
172 //! \param msg The toggle mixed reality message
173 //! \return Message handling result indicating if the message was handled
174 //!
175 //! Toggles between normal VR and mixed reality mode
177
178 //! \brief Handles player entering a state
179 //! \param msg The enter player state message
180 //! \return Message handling result indicating if the message was handled
181 //!
182 //! Processes state changes, particularly disabling VR when entering the menu state
184
185 //! \brief Handles player exiting a state
186 //! \param msg The exit player state message
187 //! \return Message handling result indicating if the message was handled
188 //!
189 //! Processes state changes, particularly re-enabling VR when exiting the menu state
190 //! if VR was previously enabled
192
193 //! \brief Finds a controller in the controller state map
194 //! \param identifier Controller identifier to find and update with current ID
195 //! \param controllers Map of controller IDs to their current state
196 //! \return Pointer to the controller state if found, nullptr otherwise
197 //!
198 //! Locates a controller either by cached ID or by searching for a matching type,
199 //! updating the identifier's controllerId if found
201 ControllerIdentifier& identifier, const ControllerStateMap& controllers);
202
203 //! \brief Pointer to the VR driver for hardware interaction
204 makVrv::DtVirtualRealityDriver* myVrDriver;
205
206 //! \brief Processor for VR controller events
207 DtVirtualRealityEventProcessor* myEventProcessor;
208
209 //! \brief Menu logic component for handling VR menu interactions
211
212 //! \brief Callback for submitting overlay graphics to VR display
213 makVrv::DtSubmitOverlayCallback* myVrOverlay;
214
215 //! \brief Tracks temporary virtual reality settings applied by this component.
217
218 //! \brief Flag indicating if VR is currently enabled
220
221 //! \brief Flag indicating if VR was enabled before entering a menu
223
224 //! \brief Flag indicating if the player uses right hand as dominant
226
227 //! \brief Flag tracking if hand motion was detected in the current frame
229
230 //! \brief Identifier for the HMD controller
232
233 //! \brief Identifier for the left hand controller
235
236 //! \brief Identifier for the right hand controller
238
239 //! \brief Counter for frames elapsed since menu interaction
241
242 //! \brief Virtual D-pad for converting analog input to digital directions
244
245 //! \brief Input logic for mapping actions to VR functions
247
248 //! \brief Cached render order for the main channel to restore when exiting VR
250};
251
252} // namespace makVre
Defines a class that encapsulates the state of a VR controller.
Defines the base class for VR controller event management.
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
Table-based access to Lua state for configuration data.
Definition initializer.h:38
Class for managing input configuration and handling in VR-Engage.
Definition inputLogic.h:39
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
virtual void tick(double dt) override
Called every frame to update the VR state.
virtual const char * type() const override
Returns the type identifier for this component.
virtual bool initialize(makVre::DtPlayerStation *player, makVre::DtInitTable &config) override
Initializes the virtual reality logic component.
makVrv::DtVirtualRealityDriver * myVrDriver
Pointer to the VR driver for hardware interaction.
Definition virtualRealityLogic.h:204
ControllerIdentifier myRightHandId
Identifier for the right hand controller.
Definition virtualRealityLogic.h:237
bool myRightHanded
Flag indicating if the player uses right hand as dominant.
Definition virtualRealityLogic.h:225
int myFramesSinceMenu
Counter for frames elapsed since menu interaction.
Definition virtualRealityLogic.h:240
makVrv::DtVirtualRealityEventManager::ControllerStateMap ControllerStateMap
Type alias for a map of controller IDs to controller state pointers.
Definition virtualRealityLogic.h:67
bool myVrWasEnabled
Flag indicating if VR was enabled before entering a menu.
Definition virtualRealityLogic.h:222
virtual void shutdown() override
Shuts down the virtual reality logic component.
virtual void stopVr()
Stops VR mode.
virtual void resetHeadPos()
Resets the HMD head position tracking.
makVrv::DtSubmitOverlayCallback * myVrOverlay
Callback for submitting overlay graphics to VR display.
Definition virtualRealityLogic.h:213
makVrv::DtVirtualRealityControllerState::ControllerId ControllerId
Type alias for controller identifier values.
Definition virtualRealityLogic.h:73
makVrv::DtVirtualRealityControllerState::DtVector2f DtVector2f
Type alias for 2D vector used in controller inputs.
Definition virtualRealityLogic.h:76
bool myDidHaveHandMotion
Flag tracking if hand motion was detected in the current frame.
Definition virtualRealityLogic.h:228
virtual void startVr()
Starts VR mode.
int myLastMainChannelRenderOrder
Cached render order for the main channel to restore when exiting VR.
Definition virtualRealityLogic.h:249
DtVirtualRealityLogic()
Constructor for DtVirtualRealityLogic.
makVrv::DtVirtualRealityControllerState ControllerState
Type alias for virtual reality controller state.
Definition virtualRealityLogic.h:79
virtual makVre::DtVreMessageResult handleToggleMixedReality(makVre::DtVreMessage *msg)
Handles toggle mixed reality message.
virtual makVre::DtVreMessageResult handleEnterPlayerState(makVre::DtVreMessage *msg)
Handles player entering a state.
virtual void processControllerStates(const ControllerStateMap &controllers)
Processes the current state of all tracked VR controllers.
virtual void handleResetHeadPosInput(int val)
Input handler for resetting head position.
ControllerIdentifier myHeadId
Identifier for the HMD controller.
Definition virtualRealityLogic.h:231
virtual makVre::DtVreMessageResult handleExitPlayerState(makVre::DtVreMessage *msg)
Handles player exiting a state.
makVrv::DtVirtualRealityControllerState::Bitfield Bitfield
Type alias for controller type bitfield values.
Definition virtualRealityLogic.h:70
virtual makVre::DtVreMessageResult handleResetVrHeadPos(makVre::DtVreMessage *msg)
Handles reset VR head position message.
ControllerIdentifier myLeftHandId
Identifier for the left hand controller.
Definition virtualRealityLogic.h:234
DtVirtualDpad myVirtualDpad
Virtual D-pad for converting analog input to digital directions.
Definition virtualRealityLogic.h:243
DtInputLogic myInputLogic
Input logic for mapping actions to VR functions.
Definition virtualRealityLogic.h:246
DtVirtualRealityEventProcessor * myEventProcessor
Processor for VR controller events.
Definition virtualRealityLogic.h:207
DtSettingsOverrideGuard mySettingsOverrideGuard
Tracks temporary virtual reality settings applied by this component.
Definition virtualRealityLogic.h:216
DtActionMenuLogic * myMenuLogic
Menu logic component for handling VR menu interactions.
Definition virtualRealityLogic.h:210
bool myVrEnabled
Flag indicating if VR is currently enabled.
Definition virtualRealityLogic.h:219
virtual const ControllerState * findController(ControllerIdentifier &identifier, const ControllerStateMap &controllers)
Finds a controller in the controller state map.
virtual ~DtVirtualRealityLogic() override
Virtual destructor for DtVirtualRealityLogic.
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 virtualRealityLogic.h:48
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 virtualRealityLogic.h:40
!
Definition glsVreMessageUtil.h:50
constexpr const char * DtVirtualRealityLogicType
Type identifier for DtVirtualRealityLogic component.
Definition virtualRealityLogic.h:54
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.
Structure for identifying and tracking VR controllers.
Definition virtualRealityLogic.h:137
ControllerIdentifier(Bitfield type)
Constructor that initializes with a controller type.
Definition virtualRealityLogic.h:140
Bitfield controllerType
Type of the controller (HMD, left hand, right hand)
Definition virtualRealityLogic.h:147
ControllerId controllerId
Unique identifier for the controller instance.
Definition virtualRealityLogic.h:150
Provides a virtual directional pad implementation.
Defines the base class for all VREngage messages.