|
VR-Engage
2.2
|
Purpose: This example integrates custom input devices with VR-Engage through implementation of the DtInputDevice interface. It covers the complete pattern for receiving device events, translating them to VR-Engage input data, and integrating with the input mapping system.
Observable Behavior: When running this example, you will see a virtual on-screen gamepad appear in the VR-Engage UI. Touch or mouse interaction with gamepad buttons and analog sticks generates input events, with input from the virtual gamepad mapped to player controls via standard input configuration. Gamepad visibility is managed automatically during state transitions.
Prerequisites: Understanding of Input and Control and familiarity with frontend input patterns. Knowledge of event-driven programming and callback patterns is required, along with basic Qt/QML understanding for UI integration.
Related Examples: Input mapping examples in VR-Engage documentation provide additional context.
This example implements custom input device integration through the DtInputDevice interface for non-standard hardware. It serves as a template for integrating any custom device using serial, network, or proprietary APIs. For complete input system details, see Input and Control.
The example covers the input device factory pattern for registering custom devices with VR-Engage's input system. The device lifecycle is managed automatically by the input manager with integration into input mapping configuration files.
Event queue processing collects asynchronous device events and processes them in sync with frame ticks. Events are gathered between ticks and processed during the tick, demonstrating proper timing for input processing.
The implementation includes QML-C++ integration using Qt Quick for custom input UI. The virtual gamepad is implemented in QML while C++ receives events via Q_INVOKABLE methods.
The plugin registers the custom input device class with VR-Engage's factory:
The device is automatically instantiated during app startup, with the tick() method called by the input manager at the appropriate time. No manual device lifecycle management is required.
The input device initializes and registers for events from the virtual gamepad:
The input manager reference is saved during initialization since it's needed later to send processed events. Callback registration enables event-driven device integration, while proper cleanup in shutdown() prevents resource leaks. This pattern works for any device that provides a callback or event-based API.
Device events are collected asynchronously and queued for processing:
Key Points:
Queued events are processed during the frame tick:
Input processing is synchronized with the simulation frame, ensuring consistent behavior. The input manager matches events to active action map layers, processing them in arrival order (FIFO). All pending input is handled before the next frame begins.
The example includes a QML-based virtual gamepad for demonstration:
The Q_INVOKABLE macro makes the method callable from QML, enabling the QML UI to provide a touch-friendly gamepad interface. This pattern demonstrates how to wrap any custom device API—in real implementations, you would replace the virtual gamepad calls with actual device driver interactions.
Build the example (see Environment Setup & Build Guide):
Install the plugin to the VR-Engage installation:
This copies the plugin to <VR-Engage-Install-Dir>\plugins64\vrEngage\release\exampleInputDevice.dll
Verify installation:
The toolkit installer (or cmake --install when building from source) deploys the required support files into the VR-Engage installation. These files must be present for the example to function correctly:
QML UI files (<VR-Engage-Install-Dir>\data\UI\virtualGamepad\): The virtual gamepad QML files define the on-screen gamepad interface. The main.qml file and its supporting assets are loaded at runtime by DtQtQuickRenderer when the input device initializes.
Input mapping configuration (<VR-Engage-Install-Dir>\data\simulationModelSets\examples\inputDevice\input\human\touch.lua): This Lua configuration file defines how events from the "Virtual Gamepad" device are mapped to player actions (movement, combat, parachuting, and related controls). It is loaded as part of the humanInput.lua configuration in the example simulation model set.
The input device is automatically instantiated when the plugin loads. The example simulation model set enables the virtual gamepad by loading input/humanInput.lua, which in turn includes input/human/touch.lua. That Lua file defines the action mappings for the "Virtual Gamepad" device.
When you use the example custom settings file exampleInputDevice.lua, two application-level settings are overridden in the playerStationApp table:
playerStationApp.defaultSimulationModelSets is set to:"$(DATA_DIR)/simulationModelSets/examples/inputDevice.sms"playerStationApp.inputSettingsPath is set to:"$(DATA_DIR)/simulationModelSets/examples/inputDevice/input/"humanInput.lua and human/touch.lua) from the example's input directory instead of the default VR-Engage input configuration.For reference, the touch.lua configuration includes mappings such as:
This means that, when the example simulation model set is selected and inputSettingsPath is pointed at the example's input directory, the virtual gamepad is already wired to standard human movement and combat actions without additional configuration. For more details on input mapping configuration, see Input and Control.
The recommended way to run this example is to use the provided custom settings script exampleInputDevice.lua, which sets both the default simulation model set and the input settings path as described above.
After installing the example, this file is available at:
<VR-Engage-Install-Dir>\appData\scripts\exampleInputDevice.luaFrom the VR-Engage bin64 directory, you can launch with:
Alternatively, you can specify an absolute path:
Using the custom settings file ensures that both playerStationApp.defaultSimulationModelSets and playerStationApp.inputSettingsPath are configured consistently for the inputDevice example.
If you prefer to override these settings directly on the command line instead of using the Lua file, you can pass them via --setting:
Verification:
*.log file in the MAK log directory, typically C:/MAK/logs) for device registration: Plugin not loading:
<VR-Engage-Install-Dir>\plugins64\vrEngage\release\*.log file in the MAK log directory) for load errorsVirtual gamepad not visible:
data/UI/ directoryInput not mapped to controls:
<VR-Engage-Install-Dir>\data\simulationModelSets\examples\inputDevice\input\\ (for example, human/touch.lua)Events not processed:
| Class | Base Class | Purpose | Header |
|---|---|---|---|
DtQmlGamepadInputDevice | DtInputDevice | Custom input device implementation | qmlGamepadInputDevice.h |
DtQmlGampad | QObject | QML virtual gamepad interface | qmlGamepad.h |
DtInputDevice::init() - Device initialization with input managerDtInputDevice::tick() - Frame-synchronized input processingDtInputDevice::shutdown() - Device cleanupDtInputDeviceFactory::addCreator() - Register custom device classDtVreInputManager::processInput() - Submit input events for processingDtVreInputManager::simulationTime() - Get current simulation timestampexampleInputDevice.dll (Windows)plugins64/vrEngage/release/Related Documentation: