コード例 #1
0
    /*
     * Compare a given StrokePath against the templates
     */
    public StrokePath Recognise(StrokePath _path)
    {
        if (templates.Count <= 0)
        {
            return(null);
        }

        float      bestDist = Mathf.Infinity;
        StrokePath bestTemp = null;

        CheckPath(_path.Points(), ref bestDist, ref bestTemp);
        if (_path.FlippedPoints() != null)
        {
            CheckPath(_path.FlippedPoints(), ref bestDist, ref bestTemp);
        }

        //scoreDivisor = 0.5f * Mathf.Sqrt((rescaleSize * rescaleSize) + (rescaleSize * rescaleSize));
        float score = 1f - bestDist / scoreDivisor;

        //Debug.Log("Best distance average: " + bestDist);
        Debug.Log("Score: " + score + " Recognition result: " + bestTemp.Name());

        //if (bestTemp == null || score < recognitionThreshold)
        //{
        //    return "no match";
        //}
        return(bestTemp);
    }
コード例 #2
0
    private void CheckPath(List <Vector2> _points, ref float _bestDist, ref StrokePath _bestTemp)
    {
        foreach (StrokePath t in templates)
        {
            float distance = DistanceAtBestAngle(_points, t.Points(), -theta, theta, thetaDelta);

            if (distance < _bestDist)
            {
                _bestDist = distance;
                _bestTemp = t;
            }
        }
    }
コード例 #3
0
 public override IEnumerable <RecordValues> GetValues()
 {
     if (FillPath != null)
     {
         foreach (RecordValues values in FillPath.GetValues())
         {
             yield return(new RecordValues("Fill " + values.Name, values.Length));
         }
     }
     if (StrokePath != null)
     {
         foreach (RecordValues values in StrokePath.GetValues())
         {
             yield return(new RecordValues("Stroke " + values.Name, values.Length));
         }
     }
 }
コード例 #4
0
    /*
     * Converts templates from XML struct format to StrokePaths
     */
    private List <StrokePath> ConvertTemplates()
    {
        List <StrokePath> convertedTemplates = new List <StrokePath>();

        foreach (Template t in templateList)
        {
            List <Vector2> rawPoints = new List <Vector2>();

            foreach (Point p in t.points)
            {
                rawPoints.Add(new Vector2(p.x, p.y));
                //Debug.Log("X = " + p.x + " Y = " + p.y);
            }

            string name = t.name;
            //string name = t.name.Substring(0, t.name.Length - 2);
            StrokePath newPath = new StrokePath(name, rawPoints, false);
            convertedTemplates.Add(newPath);
        }

        return(convertedTemplates);
    }
コード例 #5
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            previousMousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);

            if (currentPath != null)
            {
                Destroy(currentPath.gameObject);
                Destroy(tempPath.gameObject);
                currentPath = null;
            }
        }

        if (Input.GetMouseButtonUp(0) && drawing)
        {
            StrokePath path       = currentPath.GetStrokePath();
            StrokePath recognised = gesture.Recognise(path);

            // RESULT OF GESTURE RECOGNITION HERE
            // EG create circle/line etc

            drawing = false;


            // draws points to test
            // DRAWS RECOGNISE RESULT
            // Delete section once proper recognition working
            List <Vector2> points = recognised.Points();

            for (int i = 0; i < points.Count; i++)
            {
                points[i] = new Vector2(points[i].x + Screen.width / 2, points[i].y + Screen.height / 2);
            }

            tempPath = Instantiate(drawnPathPrefab, gameObject.transform).GetComponent <DrawnPath>();
            tempPath.Initialize(Camera.main.ScreenToWorldPoint(points[0]), Camera.main.ScreenToWorldPoint(points[1]));

            for (int i = 2; i < points.Count; i++)
            {
                tempPath.AddPoint(Camera.main.ScreenToWorldPoint(points[i]));
            }
        }

        if (Input.GetMouseButton(0))
        {
            Vector2 currentMousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            if (Vector2.Distance(previousMousePos, currentMousePos) > mouseMoveThreshold)
            {
                if (!drawing)
                {
                    currentPath = Instantiate(drawnPathPrefab, gameObject.transform).GetComponent <DrawnPath>();
                    currentPath.Initialize(previousMousePos, currentMousePos);
                    drawing          = true;
                    previousMousePos = currentMousePos;
                }
                else
                {
                    currentPath.AddPoint(currentMousePos);
                    previousMousePos = currentMousePos;
                }
            }
        }
        else
        {
            drawing = false;
        }
    }