TouchEventVisualizer.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using bbiwarg.Detectors.Touch;
  7. using bbiwarg.Utility;
  8. namespace bbiwarg.Graphics
  9. {
  10. class TouchEventVisualizer
  11. {
  12. public OutputImage OutputImage { get; private set; }
  13. private List<Vector2D> touchPositions;
  14. private int width, height;
  15. public TouchEventVisualizer(int width, int height)
  16. {
  17. touchPositions = new List<Vector2D>();
  18. this.width = width;
  19. this.height = height;
  20. }
  21. public void addPalmTouchEvent(PalmTouchEvent e)
  22. {
  23. Vector2D pos = new Vector2D((int) (e.RelativePalmPosition.X * width), (int) (e.RelativePalmPosition.Y * height));
  24. touchPositions.Add(pos);
  25. }
  26. public void updateImage()
  27. {
  28. OutputImage = new OutputImage(width, height);
  29. for (int i = 1; i < touchPositions.Count; ++i)
  30. {
  31. OutputImage.drawLineSegment(new LineSegment2D(touchPositions[i - 1], touchPositions[i]), 255, 255, 255);
  32. }
  33. if (touchPositions.Count != 0)
  34. OutputImage.fillCircle(touchPositions.Last<Vector2D>().IntX, touchPositions.Last<Vector2D>().IntY, 3, 255, 0, 0);
  35. }
  36. public void Reset()
  37. {
  38. touchPositions.Clear();
  39. OutputImage = new OutputImage(width, height);
  40. }
  41. }
  42. }