evan 2026.1.4
Evan
Loading...
Searching...
No Matches
XrManageButtonsActions.cpp
1/*
2** ETIB PROJECT, 2026
3** evan
4** File description:
5** XrManageButtonsActions
6*/
7
8#include "evan/openxr/actions/XrManageButtonsActions.hpp"
9#include "evan/openxr/XrDeviceBackend.hpp"
10
12 utility::event::HandButtonEvent::Button buttonType)
13 : _buttonType(buttonType)
14{
15 this->getLogger().info() << "Creating button action for button: "
16 << static_cast<int>(_buttonType);
17}
18
20{
21 this->getLogger().info() << "Destroying button actions...";
22}
23
25// Public Methods //
27
28std::vector<std::shared_ptr<utility::event::Event>>
31 std::shared_ptr<utility::event::HandMotionEvent> handMotionEvent)
32{
33 std::vector<std::shared_ptr<utility::event::Event>> events = {};
34
36 getInfo.action = getAction();
37
40
41 if (state.isActive) {
42 if (state.currentState != _lastState) {
43 _lastState = state.currentState;
44 } else {
45 return events;
46 }
47
48 auto buttonEvent = std::make_shared<utility::event::HandButtonEvent>();
49 buttonEvent->setButton(_buttonType);
50 buttonEvent->setButtonPressed(state.currentState);
51 if (handMotionEvent) {
52 buttonEvent->setAim(handMotionEvent->getAim());
53 buttonEvent->setGrip(handMotionEvent->getGrip());
54 }
55
56 this->getLogger().info()
57 << "Button " << static_cast<int>(_buttonType) << " is "
58 << (state.currentState ? "pressed" : "not pressed")
59 << " at the pose: " << buttonEvent->getGrip();
60
61 events.push_back(std::move(buttonEvent));
62 }
63
64 return events;
65}
66
69{
70 this->getLogger().info() << "Creating button actions...";
71
72 _buttonAAction = std::make_unique<XrButtonAction>(
73 utility::event::HandButtonEvent::Button::A);
74 _buttonBAction = std::make_unique<XrButtonAction>(
75 utility::event::HandButtonEvent::Button::B);
76 _buttonXAction = std::make_unique<XrButtonAction>(
77 utility::event::HandButtonEvent::Button::X);
78 _buttonYAction = std::make_unique<XrButtonAction>(
79 utility::event::HandButtonEvent::Button::Y);
80 _buttonMenuAction = std::make_unique<XrButtonAction>(
81 utility::event::HandButtonEvent::Button::Menu);
82 _buttonSystemAction = std::make_unique<XrButtonAction>(
83 utility::event::HandButtonEvent::Button::System);
84
86 propertiesButtonAAction.actionName = "button_a_action";
87 propertiesButtonAAction.bindingPath = "/user/hand/right/input/a/click";
88 propertiesButtonAAction.actionSet = actionSet;
90 _buttonAAction->createAction(propertiesButtonAAction);
91
92 this->getLogger().info()
93 << "Button A action created with name: "
94 << propertiesButtonAAction.actionName
95 << " and binding path: " << propertiesButtonAAction.bindingPath;
96
98 propertiesButtonBAction.actionName = "button_b_action";
99 propertiesButtonBAction.bindingPath = "/user/hand/right/input/b/click";
100 propertiesButtonBAction.actionSet = actionSet;
102 _buttonBAction->createAction(propertiesButtonBAction);
103
104 this->getLogger().info()
105 << "Button B action created with name: "
106 << propertiesButtonBAction.actionName
107 << " and binding path: " << propertiesButtonBAction.bindingPath;
108
110 propertiesButtonXAction.actionName = "button_x_action";
111 propertiesButtonXAction.bindingPath = "/user/hand/left/input/x/click";
112 propertiesButtonXAction.actionSet = actionSet;
114 _buttonXAction->createAction(propertiesButtonXAction);
115
116 this->getLogger().info()
117 << "Button X action created with name: "
118 << propertiesButtonXAction.actionName
119 << " and binding path: " << propertiesButtonXAction.bindingPath;
120
122 propertiesButtonYAction.actionName = "button_y_action";
123 propertiesButtonYAction.bindingPath = "/user/hand/left/input/y/click";
124 propertiesButtonYAction.actionSet = actionSet;
126 _buttonYAction->createAction(propertiesButtonYAction);
127
128 this->getLogger().info()
129 << "Button Y action created with name: "
130 << propertiesButtonYAction.actionName
131 << " and binding path: " << propertiesButtonYAction.bindingPath;
132
134 propertiesButtonMenuAction.actionName = "button_menu_action";
135 propertiesButtonMenuAction.bindingPath =
136 "/user/hand/right/input/menu/click";
137 propertiesButtonMenuAction.actionSet = actionSet;
139 _buttonMenuAction->createAction(propertiesButtonMenuAction);
140
141 this->getLogger().info()
142 << "Button Menu action created with name: "
143 << propertiesButtonMenuAction.actionName
144 << " and binding path: " << propertiesButtonMenuAction.bindingPath;
145
147 propertiesButtonSystemAction.actionName = "button_system_action";
148 propertiesButtonSystemAction.bindingPath =
149 "/user/hand/right/input/system/click";
150 propertiesButtonSystemAction.actionSet = actionSet;
152 _buttonSystemAction->createAction(propertiesButtonSystemAction);
153
154 this->getLogger().info()
155 << "Button System action created with name: "
156 << propertiesButtonSystemAction.actionName
157 << " and binding path: " << propertiesButtonSystemAction.bindingPath;
158}
159
160std::vector<std::shared_ptr<utility::event::Event>>
163 std::shared_ptr<utility::event::HandMotionEvent> handMotionLeftEvent,
164 std::shared_ptr<utility::event::HandMotionEvent> handMotionRightEvent)
165{
166 std::vector<std::shared_ptr<utility::event::Event>> events;
167
168 auto buttonAEvents =
169 _buttonAAction->getEvent(deviceBackend, handMotionRightEvent);
170 events.insert(events.end(), std::make_move_iterator(buttonAEvents.begin()),
171 std::make_move_iterator(buttonAEvents.end()));
172
173 auto buttonBEvents =
174 _buttonBAction->getEvent(deviceBackend, handMotionRightEvent);
175 events.insert(events.end(), std::make_move_iterator(buttonBEvents.begin()),
176 std::make_move_iterator(buttonBEvents.end()));
177
178 auto buttonXEvents =
179 _buttonXAction->getEvent(deviceBackend, handMotionLeftEvent);
180 events.insert(events.end(), std::make_move_iterator(buttonXEvents.begin()),
181 std::make_move_iterator(buttonXEvents.end()));
182
183 auto buttonYEvents =
184 _buttonYAction->getEvent(deviceBackend, handMotionLeftEvent);
185 events.insert(events.end(), std::make_move_iterator(buttonYEvents.begin()),
186 std::make_move_iterator(buttonYEvents.end()));
187
188 auto buttonMenuEvents =
189 _buttonMenuAction->getEvent(deviceBackend, handMotionLeftEvent);
190 events.insert(events.end(),
191 std::make_move_iterator(buttonMenuEvents.begin()),
192 std::make_move_iterator(buttonMenuEvents.end()));
193
194 auto buttonSystemEvents =
195 _buttonSystemAction->getEvent(deviceBackend, handMotionRightEvent);
196 events.insert(events.end(),
197 std::make_move_iterator(buttonSystemEvents.begin()),
198 std::make_move_iterator(buttonSystemEvents.end()));
199
200 return events;
201}
XrButtonAction(utility::event::HandButtonEvent::Button buttonType=utility::event::HandButtonEvent::Button::Unknown)
Constructs an XrButtonAction instance for a specific button type.
std::vector< std::shared_ptr< utility::event::Event > > getEvent(XrDeviceBackend &deviceBackend, std::shared_ptr< utility::event::HandMotionEvent > handMotionEvent) override
Retrieves the current state of the A button action and generates corresponding events.
The XrDeviceBackend class is responsible for managing the OpenXR device backend, including instance c...
XrManageButtonsActions(XrActionSet actionSet, XrDeviceBackend &deviceBackend)
Constructs an XrManageButtonsActions instance with the specified action set and device backend.
std::vector< std::shared_ptr< utility::event::Event > > getEvents(XrDeviceBackend &deviceBackend, std::shared_ptr< utility::event::HandMotionEvent > handMotionLeftEvent, std::shared_ptr< utility::event::HandMotionEvent > handMotionRightEvent)
Retrieves the current state of the button actions and generates corresponding events.
~XrManageButtonsActions()
Destructor for the XrManageButtonsActions class. This destructor is responsible for cleaning up any r...
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