12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using bbiwarg.Images;
- namespace bbiwarg.Detectors.Touch
- {
- class TouchTracker
- {
- private TouchImage touchImage;
- private List<TouchEvent>[] detectedTouchEvents;
- private int framesUntilTracked;
- public List<TouchEvent> TrackedTouchEvents;
- public TouchTracker()
- {
- framesUntilTracked = 2;
- detectedTouchEvents = new List<TouchEvent>[framesUntilTracked];
- for (int i = 0; i < framesUntilTracked; i++)
- {
- detectedTouchEvents[i] = new List<TouchEvent>();
- }
- }
- public void setDetectedTouchEventsThisFrame(List<TouchEvent> touchEventsThisFrame, TouchImage touchImage)
- {
- this.touchImage = touchImage;
- for (int i = (framesUntilTracked - 1); i > 0; i--)
- {
- detectedTouchEvents[i] = detectedTouchEvents[i - 1];
- }
- detectedTouchEvents[0] = touchEventsThisFrame;
- findTrackedTouches();
- }
- private void findTrackedTouches()
- {
- TrackedTouchEvents = new List<TouchEvent>();
- foreach (TouchEvent te in detectedTouchEvents[0])
- {
- bool tracked = true;
- for (int i = 1; i < framesUntilTracked; i++)
- {
- if (!hasSimilarTouchEventInFrame(te, i)) tracked = false;
- }
- if (tracked)
- {
- touchImage.setStateAt(te.Position, TouchImageState.touchTracked);
- TrackedTouchEvents.Add(te);
-
- }
- }
- }
- private bool hasSimilarTouchEventInFrame(TouchEvent touchEvent, int frame)
- {
- foreach (TouchEvent te in detectedTouchEvents[frame])
- {
- if (touchEvent.isSimilarTo(te))
- return true;
- }
- return false;
- }
- }
- }
|