forked from hybridgroup/gobot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser.go
88 lines (78 loc) · 2.82 KB
/
parser.go
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
package leap
import (
"encoding/json"
)
type Gesture struct {
Direction []float64 `json:"direction"`
Duration int `json:"duration"`
Hands []Hand `json:"hands"`
ID int `json:"id"`
Pointables []Pointable `json:"pointables"`
Position []float64 `json:"position"`
Speed float64 `json:"speed"`
StartPosition []float64 `json:"StartPosition"`
State string `json:"state"`
Type string `json:"type"`
}
type Hand struct {
Direction []float64 `json:"direction"`
ID int `json:"id"`
PalmNormal []float64 `json:"palmNormal"`
PalmPosition []float64 `json:"PalmPosition"`
PalmVelocity []float64 `json:"PalmVelocity"`
R [][]float64 `json:"r"`
S float64 `json:"s"`
SphereCenter []float64 `json:"sphereCenter"`
SphereRadius float64 `json:"sphereRadius"`
StabilizedPalmPosition []float64 `json:"stabilizedPalmPosition"`
T []float64 `json:"t"`
TimeVisible float64 `json:"TimeVisible"`
}
type Pointable struct {
Direction []float64 `json:"direction"`
HandID int `json:"handId"`
ID int `json:"id"`
Length float64 `json:"length"`
StabilizedTipPosition []float64 `json:"stabilizedTipPosition"`
TimeVisible float64 `json:"timeVisible"`
TipPosition []float64 `json:"tipPosition"`
TipVelocity []float64 `json:"tipVelocity"`
Tool bool `json:"tool"`
TouchDistance float64 `json:"touchDistance"`
TouchZone string `json:"touchZone"`
}
type InteractionBox struct {
Center []int `json:"center"`
Size []float64 `json:"size"`
}
// Base representation returned that holds every other objects
type Frame struct {
CurrentFrameRate float64 `json:"currentFrameRate"`
Gestures []Gesture `json:"gestures"`
Hands []Hand `json:"hands"`
ID int `json:"id"`
InteractionBox InteractionBox `json:"interactionBox"`
Pointables []Pointable `json:"pointables"`
R [][]float64 `json:"r"`
S float64 `json:"s"`
T []float64 `json:"t"`
Timestamp int `json:"timestamp"`
}
// X returns hand x value
func (h *Hand) X() float64 {
return h.PalmPosition[0]
}
// Y returns hand y value
func (h *Hand) Y() float64 {
return h.PalmPosition[1]
}
// Z returns hand z value
func (h *Hand) Z() float64 {
return h.PalmPosition[2]
}
// ParseFrame converts json data to a Frame
func (l *LeapMotionDriver) ParseFrame(data []byte) Frame {
var frame Frame
json.Unmarshal(data, &frame)
return frame
}