evan 2026.1.4
Evan
Loading...
Searching...
No Matches
XrManageThumbStickActions.cpp
1/*
2** ETIB PROJECT, 2026
3** evan
4** File description:
5** XrManageThumbStickActions
6*/
7
8#include "evan/openxr/actions/XrManageThumbStickActions.hpp"
9#include "evan/openxr/XrDeviceBackend.hpp"
10
12 utility::event::HandEvent::HandType handType)
13 : _handType(handType)
14{
15 this->getLogger().info() << "Creating thumb stick action for hand "
16 << static_cast<int>(handType) << "...";
17}
18
20{
21 this->getLogger().info() << "Destroying thumb stick action for hand "
22 << static_cast<int>(_handType) << "...";
23}
24
26// Public Methods //
28
29std::vector<std::shared_ptr<utility::event::Event>>
32 std::shared_ptr<utility::event::HandMotionEvent> handMotionEvent)
33{
34 std::vector<std::shared_ptr<utility::event::Event>> events = {};
35
37 getInfo.action = getAction();
38
41
42 if (state.isActive) {
43 auto thumbStickEvent =
44 std::make_shared<utility::event::HandThumbStickEvent>();
45 thumbStickEvent->setHandType(_handType);
46 thumbStickEvent->setAxis(state.currentState.x, state.currentState.y);
47
48 this->getLogger().info()
49 << "Thumb stick for hand " << static_cast<int>(_handType)
50 << " is active at position (" + std::to_string(state.currentState.x)
51 + ", " + std::to_string(state.currentState.y) + ")";
52 events.push_back(std::move(thumbStickEvent));
53 }
54 return events;
55}
56
59{
60 this->getLogger().info()
61 << "Creating thumb stick actions for left and right hands...";
62
63 _leftHandThumbStickActions = std::make_unique<XrHandThumbStickAction>(
64 utility::event::HandEvent::HandType::Left);
65 _rightHandThumbStickActions = std::make_unique<XrHandThumbStickAction>(
66 utility::event::HandEvent::HandType::Right);
67
68 // Create actions for left hand thumb stick
70 propertiesLeftThumbStickAction.actionName = "left_thumb_stick_action";
72 "/user/hand/left/input/thumbstick";
73 propertiesLeftThumbStickAction.actionSet = actionSet;
75 _leftHandThumbStickActions->createAction(propertiesLeftThumbStickAction);
76
77 this->getLogger().info()
78 << "Left hand thumb stick action created successfully.";
79
80 // Create actions for right hand thumb stick
82 propertiesRightThumbStickAction.actionName = "right_thumb_stick_action";
84 "/user/hand/right/input/thumbstick";
85 propertiesRightThumbStickAction.actionSet = actionSet;
87 _rightHandThumbStickActions->createAction(propertiesRightThumbStickAction);
88
89 this->getLogger().info()
90 << "Right hand thumb stick action created successfully.";
91}
92
94{
95 this->getLogger().info() << "Destroying thumb stick actions...";
96}
97
99// Public Methods //
101
102std::vector<std::shared_ptr<utility::event::Event>>
105{
106 std::vector<std::shared_ptr<utility::event::Event>> events;
107
108 // Get events from left hand thumb stick actions
109 auto leftHandEvents =
110 _leftHandThumbStickActions->getEvent(deviceBackend, nullptr);
111 events.insert(events.end(), std::make_move_iterator(leftHandEvents.begin()),
112 std::make_move_iterator(leftHandEvents.end()));
113
114 // Get events from right hand thumb stick actions
115 auto rightHandEvents =
116 _rightHandThumbStickActions->getEvent(deviceBackend, nullptr);
117 events.insert(events.end(),
118 std::make_move_iterator(rightHandEvents.begin()),
119 std::make_move_iterator(rightHandEvents.end()));
120
121 return events;
122}
123
125// Private Methods //
The XrDeviceBackend class is responsible for managing the OpenXR device backend, including instance c...
std::vector< std::shared_ptr< utility::event::Event > > getEvent(evan::XrDeviceBackend &deviceBackend, std::shared_ptr< utility::event::HandMotionEvent > handMotionEvent) override
Retrieves the current thumb stick events from the device backend.
XrHandThumbStickAction(utility::event::HandEvent::HandType handType)
Constructs an XrHandThumbStickAction instance for the specified hand type.
~XrHandThumbStickAction()
Destructor for the XrHandThumbStickAction class.
~XrManageThumbStickActions()
Destructor for the XrManageThumbStickActions class.
XrManageThumbStickActions(XrActionSet actionSet, XrDeviceBackend &deviceBackend)
Constructs an XrManageThumbStickActions instance with the specified action set and device backend.
std::vector< std::shared_ptr< utility::event::Event > > getEvents(evan::XrDeviceBackend &deviceBackend)
Retrieves the current thumb stick events from the device backend.
Encapsulates properties required for creating an OpenXR action.
Definition AXrAction.hpp:52
Small result wrapper used by helpers that must return both a status and a value (e....
Definition Error.hpp:89