MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / KinectBody

Class KinectBody

src/main/java/trace/input/KinectBody.kt:7–72  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5import trace.sound.OSCIn
6
7class KinectBody {
8
9 class Body {
10 val joints = mutableMapOf<String, Vec3>()
11 val previous = mutableMapOf<String, Vec3>()
12 }
13
14 companion object {
15 private var osc: OSCIn
16
17 var bodies = listOf<Body>()
18
19 init {
20 osc = OSCIn(8900)
21 RunLoop.main.mainLoop.attach {
22
23 val bb = mutableMapOf<Int, Body>()
24
25 osc.values.forEach { k, v ->
26
27 try {
28 val p = k.split("/")
29 if (p[1]=="num")return@forEach
30 val body = p[1].toInt()
31 val joint = p[2]
32 val axis = when (p[3]) {
33 "x" -> 0
34 "y" -> 1
35 "z" -> 2
36 else -> throw NumberFormatException()
37 }
38
39 bb.computeIfAbsent(body) {
40 Body()
41 }.joints.computeIfAbsent(joint) { Vec3() }!![axis] = (v as List<Number>)[0].toDouble()
42
43
44 } catch (e: Exception) {
45 println(k + " " + v)
46// e.printStackTrace()
47 }
48
49 }
50
51 bb.forEach { t, u ->
52 if (bodies.size <= t) {
53 u.joints.forEach { name, pos ->
54 u.previous[name] = Vec3(pos)
55 }
56 } else {
57 val o = bodies[t]
58 u.joints.forEach { name, pos ->
59 if (o.joints.contains(name)) {
60 u.previous[name] = Vec3(o.joints[name])
61 } else u.previous[name] = Vec3(pos)
62 }
63 }
64 }

Callers

nothing calls this directly

Calls 8

OSCInClass · 0.85
BodyClass · 0.85
computeIfAbsentMethod · 0.80
Vec3Class · 0.50
attachMethod · 0.45
forEachMethod · 0.45
splitMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected