/
pitchrollyaw.html
executable file
·78 lines (47 loc) · 1.54 KB
/
pitchrollyaw.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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Leap Pitch Roll Yaw</title>
<script src="https://js.leapmotion.com/leap-0.6.4.min.js"></script>
<script>
var controllerOptions = {
enableGestures: true
};
Leap.loop(controllerOptions, function(frame){
var handsCount = frame.hands.length;
var fingerCount = 0;
frame.pointables.forEach(function(pointable){
if(pointable.extended) fingerCount++;
});
console.log(handsCount + ","+ fingerCount);
for (var i in frame.hands) {
var hand = frame.hands[i];
console.log(hand);
//setup angles
var TO_RAD = Math.PI / 180;
var TO_DEG = 1 / TO_RAD;
var ROLL = Math.round(hand.roll() * TO_DEG);
var PITCH = Math.round(hand.pitch() * TO_DEG);
var YAW = Math.round(hand.yaw() * TO_DEG);
console.log(ROLL, PITCH, YAW);
//transforms: https://www.w3schools.com/cssref/css3_pr_transform.asp
document.getElementById("rotate").style.transform = "rotate("+ROLL+"deg)";
//var rotation = "rotateX("+ PITCH +"deg) rotateY("+ YAW +"deg) rotateZ("+ -ROLL+"deg)";
//document.getElementById("rotate").style.transform = rotation;
}
});
</script>
<style>
#rotate{
width: 100px;
height: 100px;
background: green;
position: absolute;
}
</style>
</head>
<body>
<div id="rotate"></div>
</body>
</html>