예제 #1
0
        private void UpdateTexture()
        {
            render.rectTransform.sizeDelta = new Vector2(size * displayMultiplier, size * displayMultiplier);

            Rect tmpRect = new Rect(webCam.width / 2 - rect.width / 2 + rect.x, webCam.height / 2 - rect.height / 2 + rect.y, rect.width, rect.height);

            texture = new Texture2D((int)tmpRect.width, (int)tmpRect.height);

            texture.SetPixels(webCam.GetPixels((int)tmpRect.x, (int)tmpRect.y, (int)tmpRect.width, (int)tmpRect.height));
            //texture.SetPixels(webCam.GetPixels());
            TextureScale.Point(texture, size, size);
            texture.SetPixels(ConvertContrasts(texture.GetPixels()));
            Vector2 centerPos = Center(ref texture) * centerDistance;

            texture.Apply();

            if (rotate)
            {
                SpriteGenerator.Rotate180(ref texture);
            }

            render.texture = texture;

            direction = centerPos;

            displayCenter.localPosition = centerPos;
        }
예제 #2
0
        private void UpdateSprite()
        {
            if (!test)
            {
                if (render)
                {
                    render.rectTransform.sizeDelta = new Vector2(size * displayMultiplier, size * displayMultiplier);
                }

                Rect tmpRect = new Rect(webCam.width / 2 - rect.width / 2 + rect.x, webCam.height / 2 - rect.height / 2 + rect.y, rect.width, rect.height);

                texture = new Texture2D((int)tmpRect.width, (int)tmpRect.height);

                texture.SetPixels(webCam.GetPixels((int)tmpRect.x, (int)tmpRect.y, (int)tmpRect.width, (int)tmpRect.height));
                //texture.SetPixels(webCam.GetPixels());
                TextureScale.Point(texture, size, size);
                texture.SetPixels(ConvertContrasts(texture.GetPixels()));
                texture.Apply();
                if (rotate)
                {
                    SpriteGenerator.Rotate180(ref texture);
                }

                if (!nullDetection)
                {
                    sprite = SpriteGenerator.Generate(texture);
                    sprite.texture.filterMode = FilterMode.Point;
                    sprite.texture.Apply();

                    direction = sprite.PivotDirection();
                }
                else
                {
                    direction = Vector2.zero;
                    Debug.LogWarning("Webcam no longer detects any shape !");
                }
            }
            else
            {
                if (render)
                {
                    render.rectTransform.sizeDelta = new Vector2(webCam.width, webCam.height);
                }
                texture = new Texture2D(webCam.width, webCam.height);
                texture.SetPixels(webCam.GetPixels());
                if (resize)
                {
                    int tmpSize = (int)(size * webCam.width / rect.width);

                    TextureScale.Point(texture, tmpSize, tmpSize * webCam.height / webCam.width);
                    texture.filterMode = FilterMode.Point;
                }
                if (desaturation)
                {
                    texture.SetPixels(ConvertContrasts(texture.GetPixels()));
                }
                texture.Apply();
                if (rotate)
                {
                    SpriteGenerator.Rotate180(ref texture);
                }

                frame.Apply(new Rect(webCam.width / 2 - testRect.width / 2 + testRect.x, webCam.height / 2 - testRect.height / 2 + testRect.y, testRect.width, testRect.height));

                if (nullDetection)
                {
                    Debug.LogWarning("Webcam no longer detects any shape !");
                }
            }
            if (render)
            {
                render.texture = texture;
            }
        }