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