Example #1
0
            /// <summary>
            /// Creats a texture based on the given Quad. The created texture represents
            /// the black frame for the camera. The texture is given to the ScreenOverlay
            /// component. The ScreenOverlay component is Unity standart asset
            /// image-after-effect.
            /// This function comes from the old CAVE Asset.
            /// </summary>
            /// <param name="frame">Quad</param>
            private void CreatePixelMask(Quad frame)
            {
                Texture2D texture = new Texture2D(cam.pixelWidth, cam.pixelHeight);

                Color[] pixels = texture.GetPixels();

                for (int x = 0; x < texture.width; ++x)
                {
                    for (int y = 0; y < texture.height; ++y)
                    {
                        int pos = (y * texture.width) + x;

                        pixels[pos] = Color.black;

                        Vector2 position = new Vector2((float)x / texture.width, (float)y / texture.height);

                        if (frame.Contains(position))
                        {
                            pixels[pos].a = 0.0f;
                        }
                    }
                }

                texture.SetPixels(pixels);
                texture.Apply();

                GetComponent <UnityStandardAssets.ImageEffects.ScreenOverlay>().texture = texture;
            }
    public void ImportFrom(DsonTypes.UvSet uvSet)
    {
        string name = uvSet.name;

        var uvs = uvSet.uvs.values
                  .Select(values => new Vector2(values[0], values[1]))
                  .ToArray();

        Quad[] uvFaces = (Quad[])geometry.Faces.Clone();
        foreach (int[] values in uvSet.polygon_vertex_indices)
        {
            int faceIdx   = values[0];
            int vertexIdx = values[1];
            int uvIdx     = values[2];

            Quad face = uvFaces[faceIdx];

            if (!face.Contains(vertexIdx))
            {
                throw new InvalidOperationException("face doesn't contain vertex to override");
            }

            Quad replacementFace = face.Map(idx => idx == vertexIdx ? uvIdx : idx);
            uvFaces[faceIdx] = replacementFace;
        }

        var recipe = new UvSetRecipe(name, uvs, uvFaces);

        recipes.Add(recipe);
    }
    void createPixelMask(Quad frame)
    {
        //Debug.Log("Screen: " + Screen.width +" / " + Screen.height);

        Texture2D texture = new Texture2D((int)cam.pixelWidth, (int)cam.pixelHeight);

        //Texture2D texture = new Texture2D(Screen.width, Screen.height);

        // get pixel array (better performance)
        Color[] pixels = texture.GetPixels();

        // set all pixels to black.
        // set pixels that are inside the frame to transparent

        int textureWidth  = texture.width;
        int textureHeight = texture.height;


        //Debug.Log("Textur: " + textureWidth + " / " +textureHeight);

        for (int x = 0; x < textureWidth; x++)
        {
            for (int y = 0; y < textureHeight; y++)
            {
                int pos = (y * textureWidth) + x;

                pixels[pos] = Color.black;

                //				pixels[pos].a = 1;
                Vector2 position = new Vector2((float)x / textureWidth, (float)y / textureHeight);
                if (frame.Contains(position))
                {
                    pixels[pos].a = 0;
                }
            }
        }

        // upload texture to vram
        texture.SetPixels(pixels);
        texture.Apply();

        // adjust the texture size and assign texture to GUITexture component
        Rect tmpRect = new Rect(0, 0, 1, 1);

        tmpRect.x = textureWidth / 2;
        tmpRect.y = textureHeight / 2;

        //pixelMaskLayer.GetComponent<RawImage>(). = tmpRect;
        //pixelMaskLayer.
        Sprite maskSprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f));

        pixelMask.sprite = maskSprite;
        //pixelMaskLayer.GetComponent<RawImage> ().enabled = true;;
    }
Example #4
0
        private void checkBounds()
        {
            if (tablet.Value == null)
            {
                return;
            }

            // allow for some degree of floating point error, as we don't care about being perfect here.
            const float lenience = 0.5f;

            var tabletArea = new Quad(-lenience, -lenience, tablet.Value.Size.X + lenience * 2, tablet.Value.Size.Y + lenience * 2);

            var halfUsableArea = areaSize.Value / 2;
            var offset         = areaOffset.Value;

            var usableAreaQuad = new Quad(
                new Vector2(-halfUsableArea.X, -halfUsableArea.Y),
                new Vector2(halfUsableArea.X, -halfUsableArea.Y),
                new Vector2(-halfUsableArea.X, halfUsableArea.Y),
                new Vector2(halfUsableArea.X, halfUsableArea.Y)
                );

            var matrix = Matrix3X3 <float> .Identity;

            MatrixExtensions.TranslateFromLeft(ref matrix, offset);
            MatrixExtensions.RotateFromLeft(ref matrix, MathUtils.DegreesToRadians(rotation.Value));

            usableAreaQuad *= matrix;

            IsWithinBounds =
                tabletArea.Contains(usableAreaQuad.TopLeft) &&
                tabletArea.Contains(usableAreaQuad.TopRight) &&
                tabletArea.Contains(usableAreaQuad.BottomLeft) &&
                tabletArea.Contains(usableAreaQuad.BottomRight);

            usableFill.FadeColour(IsWithinBounds ? colour.Blue : colour.RedLight, 100);
        }
Example #5
0
    public void CreateMask(Quad frame)
    {
        Logger.Log("Erstelle Pixelmaske.");

        // create a new texture that is fullscreen sized
        if (texture != null)
        {
            Object.DestroyImmediate(texture);
        }

        texture = new Texture2D(Screen.width, Screen.height);

        // get pixel array (better performance)
        Color[] pixels = texture.GetPixels();

        // set all pixels to black.
        // set pixels that are inside the frame to transparent
        for (int x = 0; x < texture.width; x++)
        {
            for (int y = 0; y < texture.height; y++)
            {
                int pos = (y * texture.width) + x;

                pixels[pos] = Color.black;

                //				pixels[pos].a = 1;
                Vector2 position = new Vector2((float)x / Screen.width, (float)y / Screen.height);
                if (frame.Contains(position))
                {
                    pixels[pos].a = 0;
                }
            }
        }

        // upload texture to vram
        texture.SetPixels(pixels);
        texture.Apply();

        // adjust the texture size and assign texture to GUITexture component
        guiTexture.pixelInset = new Rect(0, 0, texture.width, texture.height);
        guiTexture.texture    = texture;

        gameObject.SetActive(true);
    }
Example #6
0
    public void CreateMask(Quad frame)
    {
        Logger.Log("Erstelle Pixelmaske.");

        // create a new texture that is fullscreen sized
        if (texture != null)
            Object.DestroyImmediate(texture);

        texture = new Texture2D(Screen.width, Screen.height);

        // get pixel array (better performance)
        Color[] pixels = texture.GetPixels();

        // set all pixels to black.
        // set pixels that are inside the frame to transparent
        for (int x = 0; x < texture.width; x++)
        {
            for (int y = 0; y < texture.height; y++)
            {
                int pos = (y * texture.width) + x;

                pixels[pos] = Color.black;

                //				pixels[pos].a = 1;
                Vector2 position = new Vector2((float)x / Screen.width, (float)y / Screen.height);
                if (frame.Contains(position))
                {
                    pixels[pos].a = 0;
                }
            }
        }

        // upload texture to vram
        texture.SetPixels(pixels);
        texture.Apply();

        // adjust the texture size and assign texture to GUITexture component
        guiTexture.pixelInset = new Rect(0, 0, texture.width, texture.height);
        guiTexture.texture = texture;

        gameObject.SetActive(true);
    }
        private bool Search(Point pt, out double foundVal)
        {
            var grid = DataSource.Grid;

            foundVal = 0;

            int  width = DataSource.Width;
            int  height = DataSource.Height;
            bool found = false;
            int  i = 0, j = 0;

            for (i = 0; i < width - 1; i++)
            {
                for (j = 0; j < height - 1; j++)
                {
                    Quad quad = new Quad(
                        grid[i, j],
                        grid[i, j + 1],
                        grid[i + 1, j + 1],
                        grid[i + 1, j]);
                    if (quad.Contains(pt))
                    {
                        found     = true;
                        foundQuad = quad;
                        foundI    = i;
                        foundJ    = j;

                        break;
                    }
                }
                if (found)
                {
                    break;
                }
            }
            if (!found)
            {
                foundQuad = null;
                return(false);
            }

            var data = DataSource.Data;

            double x = pt.X;
            double y = pt.Y;
            Vector A = grid[i, j + 1].ToVector();                                       // @TODO: in common case add a sorting of points:
            Vector B = grid[i + 1, j + 1].ToVector();                                   //   maxA ___K___ B
            Vector C = grid[i + 1, j].ToVector();                                       //      |         |
            Vector D = grid[i, j].ToVector();                                           //      M    P    N
            double a = data[i, j + 1];                                                  //		|         |
            double b = data[i + 1, j + 1];                                              //		В ___L____Сmin
            double c = data[i + 1, j];
            double d = data[i, j];

            Vector K, L;
            double k, l;

            if (x >= A.X)
            {
                k = Interpolate(A, B, a, b, K = new Vector(x, GetY(A, B, x)));
            }
            else
            {
                k = Interpolate(D, A, d, a, K = new Vector(x, GetY(D, A, x)));
            }

            if (x >= C.X)
            {
                l = Interpolate(C, B, c, b, L = new Vector(x, GetY(C, B, x)));
            }
            else
            {
                l = Interpolate(D, C, d, c, L = new Vector(x, GetY(D, C, x)));
            }

            foundVal = Interpolate(L, K, l, k, new Vector(x, y));
            return(!Double.IsNaN(foundVal));
        }
Example #8
0
        /// <summary>
        /// Selects all hitobjects that are present within the area of a <see cref="Quad"/>.
        /// </summary>
        /// <param name="screenSpaceQuad">The selection <see cref="Quad"/>.</param>
        // Todo: If needed we can severely reduce allocations in this method
        private void selectQuad(Quad screenSpaceQuad)
        {
            var expectedSelection = playfield.HitObjects.Objects.Where(h => h.IsAlive && h.IsPresent && screenSpaceQuad.Contains(h.SelectionPoint)).ToList();

            var toRemove = selectedHitObjects.Except(expectedSelection).ToList();

            foreach (var obj in toRemove)
            {
                deselect(obj);
            }

            expectedSelection.ForEach(h => select(h));
        }
Example #9
0
 /// <summary>
 /// Selects all hitobjects that are present within the area of a <see cref="Quad"/>.
 /// </summary>
 /// <param name="screenSpaceQuad">The selection <see cref="Quad"/>.</param>
 private void selectQuad(Quad screenSpaceQuad)
 {
     foreach (var obj in playfield.HitObjects.Objects.Where(h => h.IsAlive && h.IsPresent && screenSpaceQuad.Contains(h.SelectionPoint)))
     {
         selectedHitObjects.Add(obj);
     }
 }