2014-04-28 08:43:15 +08:00
|
|
|
package leap
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
)
|
|
|
|
|
2016-12-01 18:28:22 +08:00
|
|
|
// Gesture is a Leap Motion gesture tht has been detected
|
2014-04-28 08:43:15 +08:00
|
|
|
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"`
|
|
|
|
}
|
|
|
|
|
2016-12-01 18:28:22 +08:00
|
|
|
// Hand is a Leap Motion hand tht has been detected
|
2014-04-28 08:43:15 +08:00
|
|
|
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"`
|
|
|
|
}
|
|
|
|
|
2016-12-01 18:28:22 +08:00
|
|
|
// Pointable is a Leap Motion pointing motion tht has been detected
|
2014-04-28 08:43:15 +08:00
|
|
|
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"`
|
|
|
|
}
|
|
|
|
|
2016-12-01 18:28:22 +08:00
|
|
|
// InteractionBox is the area within which the gestural interaction has been detected
|
2014-04-28 08:43:15 +08:00
|
|
|
type InteractionBox struct {
|
|
|
|
Center []int `json:"center"`
|
|
|
|
Size []float64 `json:"size"`
|
|
|
|
}
|
|
|
|
|
2016-12-01 18:28:22 +08:00
|
|
|
// Frame is the base representation returned that holds every other objects
|
2014-04-28 08:43:15 +08:00
|
|
|
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"`
|
|
|
|
}
|
|
|
|
|
2014-10-17 23:43:48 +08:00
|
|
|
// X returns hand x value
|
2014-04-28 08:43:15 +08:00
|
|
|
func (h *Hand) X() float64 {
|
|
|
|
return h.PalmPosition[0]
|
|
|
|
}
|
2014-10-17 23:43:48 +08:00
|
|
|
|
|
|
|
// Y returns hand y value
|
2014-04-28 08:43:15 +08:00
|
|
|
func (h *Hand) Y() float64 {
|
|
|
|
return h.PalmPosition[1]
|
|
|
|
}
|
2014-10-17 23:43:48 +08:00
|
|
|
|
|
|
|
// Z returns hand z value
|
2014-04-28 08:43:15 +08:00
|
|
|
func (h *Hand) Z() float64 {
|
|
|
|
return h.PalmPosition[2]
|
|
|
|
}
|
|
|
|
|
2014-10-17 23:43:48 +08:00
|
|
|
// ParseFrame converts json data to a Frame
|
2016-09-26 03:36:01 +08:00
|
|
|
func (l *Driver) ParseFrame(data []byte) Frame {
|
2014-04-28 08:43:15 +08:00
|
|
|
var frame Frame
|
|
|
|
json.Unmarshal(data, &frame)
|
|
|
|
return frame
|
|
|
|
}
|