示例#1
0
    bool RecognizeCustom(CustomGesture gesture)
    {
        gesture.MatchDistance      = 0;
        gesture.MatchScore         = 0;
        gesture.RecognizedTemplate = null;
        gesture.NormalizedPoints.Clear();

        if (gesture.RawPoints.Count < 2)
        {
            return(false);
        }

        gesture.NormalizedPoints.AddRange(normalizer.Apply(gesture.RawPoints, NormalizedPointCount));

        float bestDist = float.PositiveInfinity;

        for (int i = 0; i < normalizedTemplates.Count; ++i)
        {
            NormalizedTemplate template = normalizedTemplates[i];
            float d = 0;
            d = GreedyCloudMatch(gesture.NormalizedPoints, template.Points);
            if (d < bestDist)
            {
                bestDist = d;
                gesture.RecognizedTemplate = template.Source;
            }
        }

        if (gesture.RecognizedTemplate != null)
        {
            gesture.MatchDistance = bestDist;
            gesture.MatchScore    = UnityEngine.Mathf.Max((MaxMatchDistance - bestDist) / MaxMatchDistance, 0.0f);
        }

        if (gesture.MatchScore > 0)
        {
            if ((int)CurActiveSection >= SectionNumber - 1 || SkillCategory.kNone == gesture.SkillTags)
            {
                gesture.Recognizer.ResetMode = GestureResetMode.EndOfTouchSequence;
            }
            else
            {
                gesture.Recognizer.ResetMode = GestureResetMode.NextFrame;
            }
        }
        else
        {
            gesture.Recognizer.ResetMode = GestureResetMode.EndOfTouchSequence;
        }

        return(gesture.MatchScore > 0);
    }
示例#2
0
    public bool AddTemplate(CustomGestureTemplate template)
    {
        if (FindNormalizedTemplate(template) != null)
        {
            Debug.Log("AddTemplate Exist");
            return(false);
        }

        List <Point> points = new List <Point>();

        for (int i = 0; i < template.PointCount; ++i)
        {
            points.Add(new Point(template.GetStrokeId(i), template.GetPosition(i)));
        }

        NormalizedTemplate nt = new NormalizedTemplate();

        nt.Source = template;
        nt.Points = Normalize(points);
        normalizedTemplates.Add(nt);

        if (template.isRotate)
        {
            const float PI    = 3.141592f;
            const float Angle = 1.0f / 180.0f * PI;

            float        ox        = template.GetPosition(template.PointCount / 2).x;
            float        oy        = template.GetPosition(template.PointCount / 2).y;
            List <Point> newPoints = new List <Point>();
            for (int i = (int)template.RotateStep; i < template.RotateAngle; i += (int)template.RotateStep)
            {
                for (int j = 0; j < template.PointCount; ++j)
                {
                    float curAngle = i * Angle;
                    float px       = template.GetPosition(j).x;
                    float py       = template.GetPosition(j).y;
                    float x        = ox - (px - ox) * UnityEngine.Mathf.Cos(curAngle) - (py - oy) * UnityEngine.Mathf.Sin(curAngle);
                    float y        = oy - (px - ox) * UnityEngine.Mathf.Sin(curAngle) + (py - oy) * UnityEngine.Mathf.Cos(curAngle);
                    newPoints.Add(new Point(0, new UnityEngine.Vector2(x, y)));
                }
                NormalizedTemplate newNT = new NormalizedTemplate();
                newNT.Source = template;
                newNT.Points = Normalize(newPoints);
                normalizedTemplates.Add(newNT);
                newPoints.Clear();
            }
        }
        return(true);
    }
    bool RecognizePointCloud(PointCloudGesture gesture)
    {
        debugLastGesture = gesture;

        gesture.MatchDistance      = 0;
        gesture.MatchScore         = 0;
        gesture.RecognizedTemplate = null;
        gesture.NormalizedPoints.Clear();

        if (gesture.RawPoints.Count < 2)
        {
            return(false);
        }

        gesture.NormalizedPoints.AddRange(normalizer.Apply(gesture.RawPoints, NormalizedPointCount));

        float bestDist = float.PositiveInfinity;

        for (int i = 0; i < normalizedTemplates.Count; ++i)
        {
            NormalizedTemplate template = normalizedTemplates[i];
            float d = GreedyCloudMatch(gesture.NormalizedPoints, template.Points);

            if (d < bestDist)
            {
                bestDist = d;
                gesture.RecognizedTemplate = template.Source;
                debugLastMatchedTemplate   = template;
            }
        }

        if (gesture.RecognizedTemplate != null)
        {
            gesture.MatchDistance = bestDist;
            gesture.MatchScore    = Mathf.Max((MaxMatchDistance - bestDist) / MaxMatchDistance, 0.0f);
            //Debug.Log( "Matched: " + recognizedTemplateOut + " dist: " + bestDist + " Score: " + matchScoreOut );
        }

        return(gesture.MatchScore > 0);
    }
示例#4
0
    public bool AddTemplate(PointCloudGestureTemplate template)
    {
        if (FindNormalizedTemplate(template) != null)
        {
            Debug.LogWarning("The PointCloud template " + template.name + " is already present in the list");
            return(false);
        }

        // convert template point entry to recognizer point
        List <Point> points = new List <Point>();

        for (int i = 0; i < template.PointCount; ++i)
        {
            points.Add(new Point(template.GetStrokeId(i), template.GetPosition(i)));
        }

        NormalizedTemplate nt = new NormalizedTemplate();

        nt.Source = template;
        nt.Points = Normalize(points);

        normalizedTemplates.Add(nt);
        return(true);
    }