aboutsummaryrefslogtreecommitdiffstats
path: root/support/hololens/ServoApp/Content/SpatialInputHandler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'support/hololens/ServoApp/Content/SpatialInputHandler.cpp')
-rw-r--r--support/hololens/ServoApp/Content/SpatialInputHandler.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/support/hololens/ServoApp/Content/SpatialInputHandler.cpp b/support/hololens/ServoApp/Content/SpatialInputHandler.cpp
new file mode 100644
index 00000000000..753e8a7efd6
--- /dev/null
+++ b/support/hololens/ServoApp/Content/SpatialInputHandler.cpp
@@ -0,0 +1,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.
+ //
+}