void Update()
    {
        if(Input.GetMouseButton(0))
        {
            //This next line moves our empty gameobject so the trail renderer can draw a line for us.
            transform.position = Camera.main.ScreenToWorldPoint (new Vector3 (Input.mousePosition.x,Input.mousePosition.y,10));

            HyperGlyph.AddPoint(Input.mousePosition);
        }

        if(Input.GetMouseButtonUp(0))
            match = HyperGlyph.Recognize();
    }
示例#2
0
    /// <summary>
    /// This will run the recognizer on a given list of points and return the results.\n
    /// After the recognition is run the internal path will be cleared.
    /// You can use this function if you are building your own paths of points,
    /// maybe from Kinect, Plastation move, or other input devices. 
    /// </summary>
    /// <returns>The results of the recognition.</returns>	
    public static HyperGlyphResult Recognize(List<Vector2> points)
    {
        HyperGlyphResult result = new HyperGlyphResult();
        result.bounds = FindBounds(points);
        result.direction =FindDirection(points);

        int indexOfBestMatch = -1;
        float score = 0;

        if (ResampledTemplates.Count == 0)
        {
            Debug.LogWarning("No templates loaded so no glyphs to match.\n");
            result.glyphname = "Unknown";
            result.score = 0.0f;
            return result;
        }
        if(!Ready)
        {
            Debug.LogWarning("Recognizer Not ready.\n");
            result.glyphname = "Recognizer Not ready";
            result.score = 0.0f;
            return result;
        }

        points = Normalize(points);

        List<Vector2> tempvectors = new List<Vector2>();
        List<Vector2>  vectors = BuildVectors(points);

        float bestDifference = Mathf.Infinity;

        for (int i = 0; i < ResampledTemplates.Count; i++)
        {
            tempvectors = BuildVectors(ResampledTemplates[i].Points);
            //Debug.Log("Template: " +ResampledTemplates[i].Name);
            float difference = VectorPathDifference(vectors, tempvectors);

          	if (difference < bestDifference)
            {
                bestDifference = difference;
                indexOfBestMatch = i;
            }
        }

        score = Mathf.Abs((1.0f - (bestDifference/180.0f)) * 100.0f);

        if (-1 == indexOfBestMatch)
        {
            //Debug.Log("Couldn't find a good match.\n");
            result.glyphname = "Unknown";
            result.score = 0.0f;
            return result;
        }
        //Debug.Log("Best match found is " + ResampledTemplates[indexOfBestMatch].Name + " Confidence = " + score + "%");
        result.glyphname = ResampledTemplates[indexOfBestMatch].Name;
        result.score = score;
        return result;
    }
示例#3
0
 public void Recognize()
 {
     match = HyperGlyph.Recognize();
 }
示例#4
0
 /// <summary>
 /// This will run the recognizer on whatever is stored in it's internal path storage and return the results.\n
 /// After the recognition is run the internal path will be cleared.
 /// </summary>
 /// <returns>The results of the recognition.</returns>
 public static HyperGlyphResult Recognize()
 {
     result = Recognize(InputPath);
     InputPath.Clear();
     return result;
 }
    void Update()
    {
        count = Input.touchCount;

        if(count > 0)
        {
            //int numberOfGestureTouch = 0;
            if(count == 1)
            {
                numberOfGestureTouch = 0;
            }
            else if(count == 2)
            {
                numberOfGestureTouch = 1;
            }
            else if(count == 3)
            {
                numberOfGestureTouch = 2;
            }
            currentGestureTouch = Input.GetTouch(numberOfGestureTouch);

            //if(currentGestureTouch.phase == TouchPhase.Moved && currentGestureTouch.position.y >= Screen.height * 0.25 && currentGestureTouch.position.y <= Screen.height)
            if(currentGestureTouch.phase == TouchPhase.Moved && !gesturesLockTextureRight.HitTest(currentGestureTouch.position) && !gesturesLockTextureLeft.HitTest(currentGestureTouch.position) && currentGestureTouch.position.y >= Screen.height * 0.1)
            {
                touchStarted = true;
                //transform.position = GesturesCamera.ScreenToWorldPoint(new Vector3(Input.GetTouch(numberOfGestureTouch).position.x, Input.GetTouch(numberOfGestureTouch).position.y, 1));
                transform.position = GesturesCamera.ScreenToWorldPoint(Vector3.Lerp(transform.position, new Vector3(currentGestureTouch.position.x, currentGestureTouch.position.y, 1), 10000*Time.deltaTime));

                //if(Input.mousePosition.y >= 160 && Input.mousePosition.y <= 320)
                //{
                //This next line moves our empty gameobject so the trail renderer can draw a line for us.
                    //transform.position = Camera.main.ScreenToWorldPoint(new Vector3(Input.GetTouch(numberOfGestureTouch).position.x, Input.GetTouch(numberOfGestureTouch).position.y, 10));
                    //transform.position = GesturesCamera.ScreenToWorldPoint(new Vector3(Input.GetTouch(numberOfGestureTouch).position.x, Input.GetTouch(numberOfGestureTouch).position.y, 1));

                HyperGlyph.AddPoint(currentGestureTouch.position);
                //}
            }
            if(currentGestureTouch.phase == TouchPhase.Ended && touchStarted == true)
            {
                //player.animation.CrossFade(magicAnimation.name, 0.3f, PlayMode.StopAll);
                GameObject magicParticlesEffect = Instantiate(doingMagicParticlesEffect, new Vector3(player.transform.position.x, player.transform.position.y + 2, player.transform.position.z), Quaternion.identity) as GameObject;
                magicParticlesEffect.transform.parent = player.transform;

                match = HyperGlyph.Recognize();

                if(match.glyphname == "Line")
                {
                    magicsFactory.getMagicEffect(PlayerPrefs.GetString("Magic0"));
                    if(PlayerPrefs.GetString("Magic0") == "Stun")
                    {
                        magicsFactory.disableMagicEffect("Stun", 6.0f);
                    }
                }

                if(match.glyphname == "A")
                {
                    magicsFactory.getMagicEffect(PlayerPrefs.GetString("Magic1"));
                    if(PlayerPrefs.GetString("Magic1") == "Stun")
                    {
                        magicsFactory.disableMagicEffect("Stun", 6.0f);
                    }
                }

                if(match.glyphname == "Z")
                {
                    magicsFactory.getMagicEffect(PlayerPrefs.GetString("Magic2"));
                    if(PlayerPrefs.GetString("Magic2") == "Stun")
                    {
                        magicsFactory.disableMagicEffect("Stun", 6.0f);
                    }
                }

                if(match.glyphname == "Square")
                {
                    magicsFactory.getMagicEffect(PlayerPrefs.GetString("Magic3"));
                    if(PlayerPrefs.GetString("Magic3") == "Stun")
                    {
                        magicsFactory.disableMagicEffect("Stun", 6.0f);
                    }

                }

                if(match.glyphname == "U")
                {
                    magicsFactory.getMagicEffect(PlayerPrefs.GetString("Magic4"));
                    if(PlayerPrefs.GetString("Magic4") == "Stun")
                    {
                        magicsFactory.disableMagicEffect("Stun", 6.0f);
                    }
                }
                /*
                if(match.glyphname == "Stun")
                {
                    magicsFactory.getMagicEffect("Stun");
                    magicsFactory.disableMagicEffect("Stun", 3.0f); //disabling the magic effect should be after the cooldown that's assigned to it from the store according to upgrades
                }
                if(match.glyphname == "LightningStrike")
                {
                    magicsFactory.getMagicEffect("LightningStrike");
                }
                if(match.glyphname == "Tornado")
                {
                    magicsFactory.getMagicEffect("Tornado");
                }
                if(match.glyphname == "Crowstorm")
                {
                    magicsFactory.getMagicEffect("Crowstorm");
                }
                if(match.glyphname == "DustStorm")
                {
                    magicsFactory.getMagicEffect("DustStorm");
                }
                if(match.glyphname == "Fire")
                {
                    magicsFactory.getMagicEffect("Fire");
                }
                if(match.glyphname == "HolyFire")
                {
                    magicsFactory.getMagicEffect("HolyFire");
                }
                if(match.glyphname == "Starfall")
                {
                    magicsFactory.getMagicEffect("Starfall");
                }
                if(match.glyphname == "Electricity")
                {
                    magicsFactory.getMagicEffect("Electricity");
                }
                */
                touchStarted = false;
            }
        }
    }