aboutsummaryrefslogtreecommitdiffstats
path: root/support/hololens/ServoApp/Content/SpatialInputHandler.cpp
blob: 753e8a7efd62465068e1c66d9f3a4e985feb6090 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "pch.h"
#include "SpatialInputHandler.h"
#include <functional>

using namespace Immersive;

using namespace std::placeholders;
using namespace winrt::Windows::Foundation;
using namespace winrt::Windows::UI::Input::Spatial;

// Creates and initializes a GestureRecognizer that listens to a Person.
SpatialInputHandler::SpatialInputHandler() {
  // The interaction manager provides an event that informs the app when
  // spatial interactions are detected.
  m_interactionManager = SpatialInteractionManager::GetForCurrentView();

  // Bind a handler to the SourcePressed event.
  m_sourcePressedEventToken = m_interactionManager.SourcePressed(
      bind(&SpatialInputHandler::OnSourcePressed, this, _1, _2));

  //
  // TODO: Expand this class to use other gesture-based input events as
  // applicable to
  //       your app.
  //
}

SpatialInputHandler::~SpatialInputHandler() {
  // Unregister our handler for the OnSourcePressed event.
  m_interactionManager.SourcePressed(m_sourcePressedEventToken);
}

// Checks if the user performed an input gesture since the last call to this
// method. Allows the main update loop to check for asynchronous changes to the
// user input state.
SpatialInteractionSourceState SpatialInputHandler::CheckForInput() {
  SpatialInteractionSourceState sourceState = m_sourceState;
  m_sourceState = nullptr;
  return sourceState;
}

void SpatialInputHandler::OnSourcePressed(
    SpatialInteractionManager const &,
    SpatialInteractionSourceEventArgs const &args) {
  m_sourceState = args.State();

  //
  // TODO: In your app or game engine, rewrite this method to queue
  //       input events in your input class or event handler.
  //
}