-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
125 lines (119 loc) · 5.52 KB
/
index.html
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<!DOCTYPE html>
<html>
<head>
<title>Leap/jQuery Integration Plugin</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="leap.jquery.js"></script>
<script>
$(document).ready(function() {
//set functions for events that fire when the user does certain things
var handEnters = function() {
$("#actions").text("A hand has entered the FOV");
};
var handExits = function() {
$("#actions").text("A hand has exited the FOV");
};
var onConnect = function() {
$("#main").show();
$("#connection").text("Connected to Leap WebSocket!");
};
var onDisconnect = function() {
$("#main").hide();
$("#connection").text("WebSocket connection closed");
};
var onFrame = function() {
//put the whole object into a var for local use
var leapData = window.leapData;
//this displays the object on the console when you use two hands and point 8 fingers
if(leapData.numHands > 1 && leapData.numPointables > 7) console.dir(leapData);
//display objects - if we display every frame we get a bug in chrome and it slows then chrashes eventually so display 10 times a second instead
if(leapData.frameCount % Math.round(leapData.fps/10) == 0) {
$("#fps").text(Math.round(leapData.fps));
var str = JSON.stringify(leapData, undefined, 2);
$("#output").html("<pre>" + str + "</pre>");
if(leapData.numHands > 0) {
var str = JSON.stringify(leapData.hands[0], undefined, 2);
$("#hand1").html("<pre>" + str + "</pre>");
}
if(leapData.numHands > 1) {
var str = JSON.stringify(leapData.hands[1], undefined, 2);
$("#hand2").html("<pre>" + str + "</pre>");
}
if(leapData.numPointables > 0) {
var str = JSON.stringify(leapData.pointables, undefined, 2);
$("#pointables").html("<pre>" + str + "</pre>");
}
}
};
var onPointerChange = function() {
$("#pointablesNum").text($().leap().numPointables);
};
var onHandChange = function() {
$("#hands").text($().leap().numHands);
};
var onSecondChange = function() {
$("#time").text(parseInt($("#time").text())+1);
};
var onTap = function(pointable) {
$("#actions").text("Tap!");
};
var onPoke = function(pointable) {
$("#actions").text("Poke!");
};
var onGrab = function(hand) {
$("#actions").text("Grabbing!");
};
var onSwipe = function(hand) {
$("#actions").text("Swipe!");
};
var onPush = function(hand) {
$("#actions").text("Push!");
};
//put the functions into an array
var events = {
"onPointerChange" : onPointerChange,
"onHandChange" : onHandChange,
"onHandEnter" : handEnters,
"onHandExit" : handExits,
"onConnect" : onConnect,
"onDisconnect" : onDisconnect,
"onFrame" : onFrame,
"onSecondChange" : onSecondChange,
"onTap" : onTap,
"onPush" : onPush,
"onPoke" : onPoke,
"onSwipe" : onSwipe,
"onGrab" : onGrab
};
//you can change one at a time
//$().leap("setEvent","onHandEnter", handEnters);
//or update any number of them at once
$().leap("setEvents",events);
});
</script>
</head>
<body>
<h1><a href='http://leapgamer.com/leap_motion_jquery_plugin'>LeapGamer.com's</a> Leap jQuery Integration Plugin v0.8</h1>
<p id="connection">WebSocket not connected</p>
<p>FPS: <span id="fps">0</span></p>
<p>Pointables: <span id="pointablesNum">0</span> </p>
<p>Hands: <span id="hands">0</span> </p>
<p>Most Recent Action: <span id="actions"></span> </p>
<p>Time Elapsed: <span id="time">0</span> </p>
<div id="main">
<div style="width:24%; float:left;">
JSON Frame data <span id="output"></span>
</div>
<div style="width:24%; float:left;">
Hand 1: <span id="hand1"></span>
</div>
<div style="width:24%; float:left;">
Hand 2: <span id="hand2"></span>
</div>
<div style="width:24%; float:left;">
Pointables: <span id="pointables"></span>
</div>
</div>
<div class="clear"></div>
</body>
</html>