Esempio n. 1
0
        IEnumerator RecognizeCoroutine(GestureData data, System.Action <RecognitionResult> callback, bool normalizeScale)
        {
            RecognitionResult result = null;

            //runs recocnition in another thread to avoid framerate drop

            var thread = new System.Threading.Thread(() => {
                var normData = NormalizeData(data, normalizeScale);
                var found    = findPattern(normData, normalizeScale);
                result       = found;
            });

            thread.Start();

            while (thread.IsAlive)
            {
                yield return(null);
            }

            callback.Invoke(result);
        }
Esempio n. 2
0
        public void OnEndDrag(PointerEventData eventData)
        {
            data.LastLine.points.Add(FixedPosition(eventData.position));
            UpdateLines();

            for (int size = data.lines.Count; size >= 1 && size >= minLines; size--)
            {
                //last [size] lines
                var sizedData = new GestureData()
                {
                    lines = data.lines.GetRange(data.lines.Count - size, size)
                };

                RecognitionResult result = recognizer.Recognize(sizedData);
                result.gestureData = sizedData;

                if (result.gesture != null && result.score.score >= scoreToAccept)
                {
                    OnRecognize.Invoke(result);
                    if (clearNotRecognizedLines)
                    {
                        data = sizedData;
                        UpdateLines();
                    }
                    break;
                }
                else
                {
                    OnRecognize.Invoke(RecognitionResult.Empty);
                }
            }

            //Added: Stijn
            if (clearImmediatly)
            {
                data.lines.Clear();
                UpdateLines();
            }
        }
        IEnumerator OnEndDragCoroutine(PointerEventData eventData)
        {
            if (!in3D)
            {
                var fixedPos = FixedPosition(eventData.position);

                if (fixedPos.x != -999f && fixedPos.y != -999f)
                {
                    data.LastLine.points.Add(fixedPos);
                }
                UpdateLines();
            }
            else
            {
                var fixedPos = FixedPosition3D(eventData.position);

                if (fixedPos.x != -999f && fixedPos.y != -999f)
                {
                    data.LastLine.points3D.Add(fixedPos);
                    if (player.transform.forward == Vector3.right || player.transform.forward == -Vector3.right)
                    {
                        data.LastLine.points.Add(new Vector2(fixedPos.z, fixedPos.y));
                    }
                    else
                    {
                        data.LastLine.points.Add(new Vector2(fixedPos.x, fixedPos.y));
                    }
                }

                UpdateLines();
            }



            for (int size = data.lines.Count; size >= 1 && size >= minLines; size--)
            {
                //last [size] lines
                var sizedData = new GestureData()
                {
                    lines = data.lines.GetRange(data.lines.Count - size, size)
                };

                var sizedNormalizedData = sizedData;


                //Fixed Area is never going to be used, so that line below is commented out as it throws an unnecessary error
                if (fixedArea)
                {
                    var rect = this.rectTransform.rect;
                    sizedNormalizedData = new GestureData()
                    {
                        lines = sizedData.lines.Select(line => new GestureLine()
                        {
                            closedLine = line.closedLine,
                            //points = line.points.Select(p => Rect.PointToNormalized(rect, this.rectTransform.InverseTransformPoint(p))).ToList()
                        }).ToList()
                    };
                }

                RecognitionResult result = null;

                //run in another thread

                var thread = new System.Threading.Thread(() =>
                {
                    result = recognizer.Recognize(sizedNormalizedData, normalizeScale: !fixedArea);
                });

                thread.Start();

                while (thread.IsAlive)
                {
                    yield return(null);
                }

                if (result.gesture != null && result.score.score >= scoreToAccept)
                {
                    OnRecognize.Invoke(result, this);
                    if (clearNotRecognizedLines)
                    {
                        data = sizedData;
                        UpdateLines();
                    }
                    break;
                }
                else
                {
                    if (data.lines.Count > 1)
                    {
                        OnRecognize.Invoke(RecognitionResult.Empty, this);
                    }
                }
            }

            yield return(null);
        }
Esempio n. 4
0
        IEnumerator OnEndDragCoroutine(List <PointerEventData> eventData)
        {
            //Debug.Log("OnEndDragRoutine");

            // zeichnet eine letzte linie an der mausposition
            // deaktiviert da erkennung verzögert wird
            //data.LastLine.points.Add(FixedPosition(eventData.position));
            //UpdateLines();

            for (int size = data.lines.Count; size >= 1 && size >= minLines; size--)
            {
                //last [size] lines
                var sizedData = new GestureData()
                {
                    lines = data.lines.GetRange(data.lines.Count - size, size)
                };

                var sizedNormalizedData = sizedData;

                if (fixedArea)
                {
                    var rect = this.rectTransform.rect;
                    sizedNormalizedData = new GestureData()
                    {
                        lines = sizedData.lines.Select(line => new GestureLine()
                        {
                            closedLine = line.closedLine,
                            points     = line.points.Select(p => Rect.PointToNormalized(rect, this.rectTransform.InverseTransformPoint(p))).ToList()
                        }).ToList()
                    };
                }

                RecognitionResult result = null;
                //run in another thread

                var thread = new System.Threading.Thread(() =>
                {
                    result = recognizer.Recognize(sizedNormalizedData, normalizeScale: !fixedArea);
                });
                thread.Start();
                while (thread.IsAlive)
                {
                    yield return(null);
                }

                if (result.gesture != null && result.score.score >= scoreToAccept)
                {
                    recognized   = true;
                    clearCounter = 0;
                    OnRecognize.Invoke(result, sizedNormalizedData);
                    if (clearNotRecognizedLines)
                    {
                        data = sizedData;
                        UpdateLines();
                    }
                    break;
                }
                else
                {
                    OnRecognize.Invoke(RecognitionResult.Empty, null);
                }
            }
            yield return(null);
        }
Esempio n. 5
0
        IEnumerator OnEndDragCoroutine(PointerEventData eventData)
        {
            data.LastLine.points.Add(FixedPosition(eventData.position));
            UpdateLines();

            for (int size = data.lines.Count; size >= 1 && size >= minLines; size--)
            {
                //last [size] lines
                var sizedData = new GestureData()
                {
                    lines = data.lines.GetRange(data.lines.Count - size, size)
                };

                var sizedNormalizedData = sizedData;

                if (fixedArea)
                {
                    var rect = this.rectTransform.rect;
                    sizedNormalizedData = new GestureData()
                    {
                        lines = sizedData.lines.Select(line => new GestureLine()
                        {
                            closedLine = line.closedLine,
                            points     = line.points.Select(p => Rect.PointToNormalized(rect, this.rectTransform.InverseTransformPoint(p))).ToList()
                        }).ToList()
                    };
                }

                RecognitionResult result = null;

                //run in another thread

                var thread = new System.Threading.Thread(() => {
                    result = recognizer.Recognize(sizedNormalizedData, normalizeScale: !fixedArea);
                });
                thread.Start();
                while (thread.IsAlive)
                {
                    yield return(null);
                }

                //USE THIS TO SNATCH THE SCORE to turn on boolean thing that allowws to go to next page!!! omg
                if (result.gesture != null && result.score.score >= scoreToAccept)
                {
                    OnRecognize.Invoke(result);
                    puzzleSolved = true;

                    // pm.canTurnPage[pm.page] = true;


                    if (clearNotRecognizedLines)
                    {
                        data = sizedData;
                        UpdateLines();
                    }
                    break;
                }
                else
                {
                    OnRecognize.Invoke(RecognitionResult.Empty);
                }
            }

            yield return(null);
        }
 public GestureEventArgs(RecognitionResult result)
 {
     this.Result = result;
 }