private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { jointMap.Clear(); if (System.Windows.Forms.Control.MouseButtons.HasFlag(MouseButtons.Left)) { KinectDataPoint shoulderCenter = new KinectDataPoint(0, 40, 2000, 320, 240); KinectDataPoint shoulderLeft = new KinectDataPoint(20, 40, 2000, 300, 240); KinectDataPoint shoulderRight = new KinectDataPoint(20, 40, 2000, 340, 240); KinectDataPoint handLeft = new KinectDataPoint(30, 10, 2000, 270, 210); KinectDataPoint handRight = new KinectDataPoint(30, 10, 2000, 350, 210); jointMap[JointType.ShoulderCenter] = shoulderCenter; jointMap[JointType.ShoulderLeft] = shoulderLeft; jointMap[JointType.ShoulderRight] = shoulderRight; jointMap[JointType.HandLeft] = handLeft; jointMap[JointType.HandRight] = handRight; } else if (System.Windows.Forms.Control.MouseButtons.HasFlag(MouseButtons.Right)) { KinectDataPoint shoulderCenter = new KinectDataPoint(0, 40, 2000, 320, 240); KinectDataPoint shoulderLeft = new KinectDataPoint(20, 40, 2000, 300, 240); KinectDataPoint shoulderRight = new KinectDataPoint(20, 40, 2000, 340, 240); KinectDataPoint handLeft = new KinectDataPoint(30, 10, 2000, 270, 180); KinectDataPoint handRight = new KinectDataPoint(30, 10, 2000, 350, 260); jointMap[JointType.ShoulderCenter] = shoulderCenter; jointMap[JointType.ShoulderLeft] = shoulderLeft; jointMap[JointType.ShoulderRight] = shoulderRight; jointMap[JointType.HandLeft] = handLeft; jointMap[JointType.HandRight] = handRight; } }
private bool checkAngle(KinectDataPoint p1, KinectDataPoint p2, InteractionDirection direction, int bodyAngle) { int horizontalAngle = p1.CalcHorizontalAngle(p2); int depthAngle = p1.CalcDepthAngle(p2); bool result = checkUpDown(p1, p2, depthAngle, horizontalAngle, direction) || checkLeftRight(p1, p2, depthAngle, horizontalAngle, bodyAngle, direction); return result; }
public void AddPoint(KinectDataPoint point, JointType joint) { List<KinectDataPoint> queue = getQueue(joint); while (queue.Count > 0 && point.TimeStamp >= queue.First().TimeStamp.AddMilliseconds(maxTime)) { queue.RemoveAt(0); } queue.Add(point); }
public double CalcDistance3D(KinectDataPoint point) { if (null != point) { int x = this.X - point.X; int y = this.Y - point.Y; int z = this.Z - point.Z; return Math.Sqrt((x * x) + (y * y) + (z * z)); } return 0; }
private bool checkLeftRight(KinectDataPoint p1, KinectDataPoint p2, int depthAngle, int horizontalAngle, int bodyAngle, InteractionDirection direction) { if (direction == InteractionDirection.TO_LEFT || direction == InteractionDirection.TO_RIGHT) { if (Math.Abs(bodyAngle - depthAngle) < IConsts.GSwipeDepthAngle) { bool directionOk; if (direction == InteractionDirection.TO_LEFT) { directionOk = (p1.ScreenX > p2.ScreenX); } else { directionOk = (p1.ScreenX < p2.ScreenX); } return (horizontalAngle < IConsts.GSwipeHorizontalAngle) && directionOk; } } return false; }
private void drawHandImage(ImageSource source, KinectDataPoint point, DrawingContext drawingContext) { drawingContext.DrawImage(source, new Rect( point.ScreenX - (source.Width / 2), point.ScreenY - (source.Height / 2), source.Width, source.Height)); }
private bool checkUpDown(KinectDataPoint p1, KinectDataPoint p2, int depthAngle, int horizontalAngle, InteractionDirection direction) { if (direction == InteractionDirection.UP || direction == InteractionDirection.DOWN) { if (depthAngle < IConsts.GSwipeDepthAngle) { bool directionOk; if (direction == InteractionDirection.UP) { directionOk = (p1.ScreenY > p2.ScreenY); } else { directionOk = (p1.ScreenY < p2.ScreenY); } return ((90 - horizontalAngle) < IConsts.GSwipeHorizontalAngle) && directionOk; } } return false; }
private InteractionCircle getDirection(KinectDataPoint[] points) { int refIdx = 0; for (int i = 1; i < points.Length; ++i) { if (points[i].ScreenY < points[refIdx].ScreenY) { refIdx = i; } } KinectDataPoint point = points[refIdx]; KinectDataPoint nexPoint = points[(refIdx + 1) % points.Length]; if (point.ScreenX < nexPoint.ScreenX) { return InteractionCircle.CLOCK_WISE; } return InteractionCircle.COUNTER_CLOCK_WISE; }
public double CalcScreenDistance(KinectDataPoint point) { if (null != point) { int x = this.ScreenX - point.ScreenX; int y = this.ScreenY - point.ScreenY; return Math.Sqrt((x * x) + (y * y)); } return 0; }
public int CalcHorizontalAngle(KinectDataPoint point) { return calcAngle(point, new KinectDataPoint(X, point.Y, Z, 0, 0)); }
public int CalcDepthAngle(KinectDataPoint point) { return calcAngle(point, new KinectDataPoint(this.X, this.Y, point.Z, 0, 0)); }
private int calcAngle(KinectDataPoint point, KinectDataPoint refPoint) { double b = point.CalcDistance3D(refPoint); double c = this.CalcDistance3D(point); return (int)(Math.Acos(b / c) * 180 / Math.PI); }