iMSTK
Interactive Medical Simulation Toolkit
imstkOpenVRDeviceClient.cpp
1 /*
2 ** This file is part of the Interactive Medical Simulation Toolkit (iMSTK)
3 ** iMSTK is distributed under the Apache License, Version 2.0.
4 ** See accompanying NOTICE for details.
5 */
6 
7 #include "imstkOpenVRDeviceClient.h"
8 
9 namespace imstk
10 {
11 std::shared_ptr<OpenVRDeviceClient>
12 OpenVRDeviceClient::New(DeviceType deviceType)
13 {
14  return std::shared_ptr<OpenVRDeviceClient>(new OpenVRDeviceClient(deviceType));
15 }
16 
17 void
19 {
20  const int prevButtonState = m_buttons[buttonId];
21  m_buttons[buttonId] = BUTTON_TOUCHED;
22  if (prevButtonState != BUTTON_TOUCHED)
23  {
24  this->postEvent(ButtonEvent(OpenVRDeviceClient::buttonStateChanged(), buttonId, BUTTON_TOUCHED));
25  }
26 }
27 
28 void
29 OpenVRDeviceClient::emitButtonUntouched(const int buttonId)
30 {
31  const int prevButtonState = m_buttons[buttonId];
32  m_buttons[buttonId] = BUTTON_UNTOUCHED;
33  if (prevButtonState != BUTTON_UNTOUCHED)
34  {
35  this->postEvent(ButtonEvent(OpenVRDeviceClient::buttonStateChanged(), buttonId, BUTTON_UNTOUCHED));
36  }
37 }
38 
39 void
40 OpenVRDeviceClient::emitButtonPress(const int buttonId)
41 {
42  const int prevButtonState = m_buttons[buttonId];
43  m_buttons[buttonId] = BUTTON_PRESSED;
44  if (prevButtonState != BUTTON_PRESSED)
45  {
46  this->postEvent(ButtonEvent(OpenVRDeviceClient::buttonStateChanged(), buttonId, BUTTON_PRESSED));
47  }
48 }
49 
50 void
51 OpenVRDeviceClient::emitButtonRelease(const int buttonId)
52 {
53  const int prevButtonState = m_buttons[buttonId];
54  m_buttons[buttonId] = BUTTON_RELEASED;
55  if (prevButtonState != BUTTON_RELEASED)
56  {
57  this->postEvent(ButtonEvent(OpenVRDeviceClient::buttonStateChanged(), buttonId, BUTTON_RELEASED));
58  }
59 }
60 } // namespace imstk
Compound Geometry.
void emitButtonTouched(const int buttonId)
Emit various button events.
OpenVRDeviceClient(DeviceType deviceType)
static std::shared_ptr< OpenVRDeviceClient > New(DeviceType deviceType)
void postEvent(const T &e)
Emits the event Direct observers will be immediately called, in sync Queued observers will receive th...