Leviathan  0.8.0.0
Leviathan game engine
Leviathan::LeapListener Class Reference

#include <LeapListener.h>

+ Inheritance diagram for Leviathan::LeapListener:

Public Member Functions

 LeapListener (LeapManager *owner)
 
 ~LeapListener ()
 
void onInit (const Leap::Controller &control) override
 
void onConnect (const Leap::Controller &control) override
 
void onDisconnect (const Leap::Controller &control) override
 
void onExit (const Leap::Controller &control) override
 
void onFrame (const Leap::Controller &control) override
 
void onFocusGained (const Leap::Controller &control) override
 
void onFocusLost (const Leap::Controller &control) override
 
DLLEXPORT bool IsConnected ()
 

Protected Member Functions

void HandleFrame (const Leap::Frame &frame, const Leap::Controller &control)
 Handles a frame retrieved from the Leap or notified by frame event. More...
 

Detailed Description

Definition at line 10 of file LeapListener.h.

Constructor & Destructor Documentation

◆ LeapListener()

Leviathan::LeapListener::LeapListener ( LeapManager owner)

Definition at line 11 of file LeapListener.cpp.

11  : Owner(owner), HandledFrames(0){
12 
13  // Set everything to default //
14  Connected = false;
15  Focused = false;
16 }

◆ ~LeapListener()

Leviathan::LeapListener::~LeapListener ( )

Definition at line 18 of file LeapListener.cpp.

18  {
19 }

Member Function Documentation

◆ HandleFrame()

void Leviathan::LeapListener::HandleFrame ( const Leap::Frame &  frame,
const Leap::Controller &  control 
)
protected

Handles a frame retrieved from the Leap or notified by frame event.

Definition at line 73 of file LeapListener.cpp.

75 {
76  ++HandledFrames;
77 
78  // TODO: report these frames to someplace
79 
80 
81 
82  // process the frame gestures //
83  const GestureList gestures = frame.gestures();
84  for(int i = 0; i < gestures.count(); i++){
85  // get current gesture //
86  Gesture gesture = gestures[i];
87  // switch based on type and process //
88  switch(gesture.type()) {
89  case Gesture::TYPE_CIRCLE:
90  {
91  // instantiate correct gesture subclass //
92  CircleGesture circle = gesture;
93 
94  // Calculate angle difference since last frame //
95  float sweptAngle = 0;
96  if(circle.state() != Gesture::STATE_START){
97  // retrieve this gesture in last frame based on id //
98  CircleGesture previousgesturestate = CircleGesture(control.frame(1).gesture(circle.id()));
99  // get progress change and change it to a radian angle //
100  sweptAngle = (float)((circle.progress() -
101  previousgesturestate.progress())*2*PI);
102 
103  (void)sweptAngle;
104  }
105 
106 
107 
108  }
109  break;
110  case Gesture::TYPE_SWIPE:
111  {
112  // instantiate correct gesture subclass //
113  const SwipeGesture swipe = gesture;
114 
115 
116  // Check for shutdown left swipe //
117  if(swipe.direction().x < -0.6){
118  if(swipe.durationSeconds() >= 0.04f){
119 
120  auto change = swipe.startPosition()-swipe.position();
121 
122  if(change.x >= 40){
123 
124  Logger::Get()->Info("LeapManager: Input: swipe threshold passed, "
125  "shutting down");
126 
127  Leviathan::LeviathanApplication::GetApp()->MarkAsClosing();
128  }
129 
130  }
131  }
132  }
133  break;
134  case Gesture::TYPE_KEY_TAP:
135  {
136  // instantiate correct gesture subclass //
137  KeyTapGesture tap = gesture;
138 
139 
140  }
141  break;
142  case Gesture::TYPE_SCREEN_TAP:
143  {
144  // instantiate correct gesture subclass //
145  ScreenTapGesture screentap = gesture;
146  }
147  break;
148  default:
149  Logger::Get()->Error("LeapListener: unknown gesture type: "+
150  Convert::ToString(gesture.type()));
151  break;
152  }
153  }
154 }
DLLEXPORT void Info(const std::string &data) override
Definition: Logger.cpp:164
static std::string ToString(const T &val)
Definition: Convert.h:72
static DLLEXPORT Logger * Get()
Definition: Logger.cpp:106
constexpr float PI
Definition: Define.h:58
DLLEXPORT void Error(const std::string &data) override
Definition: Logger.cpp:177

◆ IsConnected()

DLLEXPORT bool Leviathan::LeapListener::IsConnected ( )
inline

Definition at line 25 of file LeapListener.h.

25  {
26  return Connected;
27  }

◆ onConnect()

void Leviathan::LeapListener::onConnect ( const Leap::Controller &  control)
override

Definition at line 26 of file LeapListener.cpp.

26  {
27 
28  control.enableGesture(Gesture::TYPE_CIRCLE);
29  control.enableGesture(Gesture::TYPE_KEY_TAP);
30  control.enableGesture(Gesture::TYPE_SCREEN_TAP);
31  control.enableGesture(Gesture::TYPE_SWIPE);
32 
33  Connected = true;
34 
35  if(!control.isGestureEnabled(Gesture::TYPE_SWIPE)){
36 
37  assert(0 && "leap gesture fail");
38  }
39 
40  Logger::Get()->Info("LeapListener: connected");
41 }
DLLEXPORT void Info(const std::string &data) override
Definition: Logger.cpp:164
static DLLEXPORT Logger * Get()
Definition: Logger.cpp:106

◆ onDisconnect()

void Leviathan::LeapListener::onDisconnect ( const Leap::Controller &  control)
override

Definition at line 43 of file LeapListener.cpp.

43  {
44  // SDK Note: not dispatched when running in a debugger
45  Connected = false;
46 
47  Logger::Get()->Info("LeapListener: disconnected");
48 }
DLLEXPORT void Info(const std::string &data) override
Definition: Logger.cpp:164
static DLLEXPORT Logger * Get()
Definition: Logger.cpp:106

◆ onExit()

void Leviathan::LeapListener::onExit ( const Leap::Controller &  control)
override

Definition at line 50 of file LeapListener.cpp.

50  {
51  Connected = false;
52 }

◆ onFocusGained()

void Leviathan::LeapListener::onFocusGained ( const Leap::Controller &  control)
override

Definition at line 61 of file LeapListener.cpp.

61  {
62 
63  Logger::Get()->Info("LeapListener: gained focus");
64  Focused = true;
65 }
DLLEXPORT void Info(const std::string &data) override
Definition: Logger.cpp:164
static DLLEXPORT Logger * Get()
Definition: Logger.cpp:106

◆ onFocusLost()

void Leviathan::LeapListener::onFocusLost ( const Leap::Controller &  control)
override

Definition at line 67 of file LeapListener.cpp.

67  {
68 
69  Logger::Get()->Info("LeapListener: lost focus");
70  Focused = false;
71 }
DLLEXPORT void Info(const std::string &data) override
Definition: Logger.cpp:164
static DLLEXPORT Logger * Get()
Definition: Logger.cpp:106

◆ onFrame()

void Leviathan::LeapListener::onFrame ( const Leap::Controller &  control)
override

Definition at line 54 of file LeapListener.cpp.

54  {
55  // get most recent frame //
56  const Frame frame = control.frame();
57 
58  HandleFrame(frame, control);
59 }
void HandleFrame(const Leap::Frame &frame, const Leap::Controller &control)
Handles a frame retrieved from the Leap or notified by frame event.

◆ onInit()

void Leviathan::LeapListener::onInit ( const Leap::Controller &  control)
override

Definition at line 21 of file LeapListener.cpp.

21  {
22 
23  Logger::Get()->Info("LeapListener: initialized");
24 }
DLLEXPORT void Info(const std::string &data) override
Definition: Logger.cpp:164
static DLLEXPORT Logger * Get()
Definition: Logger.cpp:106

The documentation for this class was generated from the following files: