Esempio n. 1
0
        public static TextureShapeType GetTextureShapeType(Vector2[] texCoords, bool isForTriangle)
        {
            bool isClockwise = !(MathC.CalculateArea(texCoords) > 0.0f);

            if (isForTriangle)
            {
                Vector2 midPoint = (texCoords[0] + texCoords[1] + texCoords[2]) * (1.0f / 3.0f);

                // Determine closest edge to the mid
                float distance0 = (texCoords[0] - midPoint).LengthSquared();
                float distance1 = (texCoords[1] - midPoint).LengthSquared();
                float distance2 = (texCoords[2] - midPoint).LengthSquared();

                byte closeEdgeIndex = 0;
                if (distance1 < Math.Min(distance0, distance2))
                {
                    closeEdgeIndex = 1;
                }
                if (distance2 < Math.Min(distance0, distance1))
                {
                    closeEdgeIndex = 2;
                }

                // Determine case
                Vector2 toClosestEdge = texCoords[closeEdgeIndex] - midPoint;
                if (toClosestEdge.X < 0)
                {
                    if (toClosestEdge.Y < 0)
                    { // Negative X, Negative Y
                        // +---+
                        // |  /
                        // | /
                        // |/
                        // +
                        if (isClockwise)
                        {
                            return((TextureShapeType)0); //static constexpr Diverse::Vec<2, float> Triangle0[3] = { { 0.5f, 0.5f }, { -0.5f, 0.5f }, { 0.5f, -0.5f } };
                        }
                        else
                        {
                            return((TextureShapeType)5); //static constexpr Diverse::Vec<2, float> Triangle5[3] = { { 0.5f, 0.5f }, { 0.5f, -0.5f }, { -0.5f, 0.5f } };
                        }
                    }
                    else
                    { // Negative X, Postive Y
                        // +
                        // |\
                        // | \
                        // |  \
                        // +---+
                        if (isClockwise)
                        {
                            return((TextureShapeType)3); //static constexpr Diverse::Vec<2, float> Triangle3[3] = { { 0.5f, -0.5f }, { 0.5f, 0.5f }, { -0.5f, -0.5f } };
                        }
                        else
                        {
                            return((TextureShapeType)6); //static constexpr Diverse::Vec<2, float> Triangle6[3] = { { 0.5f, -0.5f }, { -0.5f, -0.5f }, { 0.5f, 0.5f } };
                        }
                    }
                }
                else
                if (toClosestEdge.Y < 0)
                { // Postive X, Negative Y
                  // +---+
                  //  \  |
                  //   \ |
                  //    \|
                  //     +
                    if (isClockwise)
                    {
                        return((TextureShapeType)1); //static constexpr Diverse::Vec<2, float> Triangle1[3] = { { -0.5f, 0.5f }, { -0.5f, -0.5f }, { 0.5f, 0.5f } };
                    }
                    else
                    {
                        return((TextureShapeType)4); //static constexpr Diverse::Vec<2, float> Triangle4[3] = { { -0.5f, 0.5f }, { 0.5f, 0.5f }, { -0.5f, -0.5f } };
                    }
                }
                else
                { // Postive X, Postive Y
                  //     +
                  //    /|
                  //   / |
                  //  /  |
                  // +---+
                    if (isClockwise)
                    {
                        return((TextureShapeType)2); //static constexpr Diverse::Vec<2, float> Triangle2[3] = { { -0.5f, -0.5f }, { 0.5f, -0.5f }, { -0.5f, 0.5f } };
                    }
                    else
                    {
                        return((TextureShapeType)7); //static constexpr Diverse::Vec<2, float> Triangle7[3] = { { -0.5f, -0.5f }, { -0.5f, 0.5f }, { 0.5f, -0.5f } };
                    }
                }
            }
            else if (!isClockwise)
            {
                return((TextureShapeType)1);
            }
            else
            {
                return((TextureShapeType)0);
            }
        }