1: using Microsoft.Kinect;
2:
3: namespace ElBruno.Rocket.Ui
4: {
5: class KinectRocketGestures
6: {
7: private readonly Skeleton _skeleton;
8: private readonly Rocket _rocket;
9:
10: public KinectRocketGestures(Skeleton skeleton, Rocket rocket)
11: {
12: _skeleton = skeleton;
13: _rocket = rocket;
14: }
15:
16: public string ValidateGestures()
17: {
18: var gesture = @"Not defined";
19: // STOP
20: // Right hand and Left hand hanging at the side
21: if (_skeleton.Joints[JointType.HandRight].Position.Y < _skeleton.Joints[JointType.HipCenter].Position.Y &&
22: _skeleton.Joints[JointType.HandLeft].Position.Y < _skeleton.Joints[JointType.HipCenter].Position.Y)
23: {
24: _rocket.StopAll();
25: _rocket.StopFiring();
26: _rocket.StopMovements();
27: gesture = @"STOP";
28: return gesture;
29: }
30:
31: // FIRE
32: if (_skeleton.Joints[JointType.HandLeft].Position.Y > _skeleton.Joints[JointType.Head].Position.Y)
33: {
34: gesture = @"FIRE";
35: _rocket.FireOnce();
36: }
37:
38: // MOVE RIGHT OR LEFT
39: // Right hand in front of right shoulder
40: // Right hand below shoulder height but above hip height
41: if (
42: (_skeleton.Joints[JointType.HandRight].Position.Z < _skeleton.Joints[JointType.ElbowRight].Position.Z &&
43: _skeleton.Joints[JointType.HandLeft].Position.Y < _skeleton.Joints[JointType.HipCenter].Position.Y)
44: &&
45: (_skeleton.Joints[JointType.HandRight].Position.Y < _skeleton.Joints[JointType.Head].Position.Y &&
46: _skeleton.Joints[JointType.HandRight].Position.Y > _skeleton.Joints[JointType.HipCenter].Position.Y)
47: )
48: {
49: // Right hand right of right shoulder
50: if (_skeleton.Joints[JointType.HandRight].Position.X > _skeleton.Joints[JointType.ShoulderRight].Position.X)
51: {
52: gesture = @"MOVE RIGHT";
53: _rocket.MoveRight();
54: }
55: // Right hand left of left Shoulder
56: if (_skeleton.Joints[JointType.HandRight].Position.X < _skeleton.Joints[JointType.ShoulderLeft].Position.X)
57: {
58: gesture = @"MOVE LEFT";
59: _rocket.MoveLeft();
60: }
61: }
62:
63: // MOVE UP OR DOWN
64: // Right hand in front of body with Left hand hanging at the side
65: // Right hand between shoulders
66: if (
67: (_skeleton.Joints[JointType.HandRight].Position.Z < _skeleton.Joints[JointType.ShoulderCenter].Position.Z &&
68: _skeleton.Joints[JointType.HandLeft].Position.Y < _skeleton.Joints[JointType.HipCenter].Position.Y)
69: &&
70: (_skeleton.Joints[JointType.HandRight].Position.X < _skeleton.Joints[JointType.ShoulderRight].Position.X &&
71: _skeleton.Joints[JointType.HandRight].Position.X > _skeleton.Joints[JointType.ShoulderLeft].Position.X)
72: )
73: {
74: // Right hand above the shoulders
75: if (_skeleton.Joints[JointType.HandRight].Position.Y > _skeleton.Joints[JointType.ShoulderCenter].Position.Y)
76: {
77: gesture = @"MOVE UP";
78: _rocket.MoveUp();
79: }
80: // Right hand below the chest/gut
81: if (_skeleton.Joints[JointType.HandRight].Position.Y < _skeleton.Joints[JointType.Spine].Position.Y)
82: {
83: gesture = @"MOVE DOWN";
84: _rocket.MoveDown();
85: }
86: return gesture;
87: }
88: }
89: }
90: }