Ejemplo n.º 1
0
        public void PrepareStrip(Vector2[] positions, float[] rotations, StripColorFunction colorFunction, StripHalfWidthFunction widthFunction, Vector2 offsetForAllPositions = default(Vector2), int?expectedVertexPairsAmount = null, bool includeBacksides = false)
        {
            int num  = positions.Length;
            int num2 = _vertexAmountCurrentlyMaintained = num * 2;

            if (_vertices.Length < num2)
            {
                Array.Resize(ref _vertices, num2);
            }
            int num3 = num;

            if (expectedVertexPairsAmount.HasValue)
            {
                num3 = expectedVertexPairsAmount.Value;
            }
            for (int i = 0; i < num; i++)
            {
                if (positions[i] == Vector2.Zero)
                {
                    num = i - 1;
                    _vertexAmountCurrentlyMaintained = num * 2;
                    break;
                }
                Vector2 pos = positions[i] + offsetForAllPositions;
                float   rot = MathHelper.WrapAngle(rotations[i]);
                int     indexOnVertexArray = i * 2;
                float   progressOnStrip    = (float)i / (float)(num3 - 1);
                AddVertex(colorFunction, widthFunction, pos, rot, indexOnVertexArray, progressOnStrip);
            }
            PrepareIndices(num, includeBacksides);
        }
Ejemplo n.º 2
0
        private void AddVertex(StripColorFunction colorFunction, StripHalfWidthFunction widthFunction, Vector2 pos, float rot, int indexOnVertexArray, float progressOnStrip)
        {
            while (indexOnVertexArray + 1 >= _vertices.Length)
            {
                Array.Resize(ref _vertices, _vertices.Length * 2);
            }
            Color   color = colorFunction(progressOnStrip);
            float   num   = widthFunction(progressOnStrip);
            Vector2 value = MathHelper.WrapAngle(rot - (float)Math.PI / 2f).ToRotationVector2() * num;

            _vertices[indexOnVertexArray].Position     = pos + value;
            _vertices[indexOnVertexArray + 1].Position = pos - value;
            _vertices[indexOnVertexArray].TexCoord     = new Vector3(progressOnStrip, num, num);
            _vertices[indexOnVertexArray + 1].TexCoord = new Vector3(progressOnStrip, 0f, num);
            _vertices[indexOnVertexArray].Color        = color;
            _vertices[indexOnVertexArray + 1].Color    = color;
        }
Ejemplo n.º 3
0
        public void PrepareStripWithProceduralPadding(Vector2[] positions, float[] rotations, StripColorFunction colorFunction, StripHalfWidthFunction widthFunction, Vector2 offsetForAllPositions = default(Vector2), bool includeBacksides = false)
        {
            int num = positions.Length;

            _temporaryPositionsCache.Clear();
            _temporaryRotationsCache.Clear();
            for (int i = 0; i < num && !(positions[i] == Vector2.Zero); i++)
            {
                Vector2 vector = positions[i];
                float   num2   = MathHelper.WrapAngle(rotations[i]);
                _temporaryPositionsCache.Add(vector);
                _temporaryRotationsCache.Add(num2);
                if (i + 1 >= num || !(positions[i + 1] != Vector2.Zero))
                {
                    continue;
                }
                Vector2 vector2 = positions[i + 1];
                float   num3    = MathHelper.WrapAngle(rotations[i + 1]);
                int     num4    = (int)(Math.Abs(MathHelper.WrapAngle(num3 - num2)) / ((float)Math.PI / 12f));
                if (num4 != 0)
                {
                    float   num5   = vector.Distance(vector2);
                    Vector2 value  = vector + num2.ToRotationVector2() * num5;
                    Vector2 value2 = vector2 + num3.ToRotationVector2() * (0f - num5);
                    int     num6   = num4 + 2;
                    float   num7   = 1f / (float)num6;
                    Vector2 target = vector;
                    for (float num8 = num7; num8 < 1f; num8 += num7)
                    {
                        Vector2 vector3 = Vector2.CatmullRom(value, vector, vector2, value2, num8);
                        float   item    = MathHelper.WrapAngle(vector3.DirectionTo(target).ToRotation());
                        _temporaryPositionsCache.Add(vector3);
                        _temporaryRotationsCache.Add(item);
                        target = vector3;
                    }
                }
            }
            int count = _temporaryPositionsCache.Count;

            for (int j = 0; j < count; j++)
            {
                Vector2 pos = _temporaryPositionsCache[j] + offsetForAllPositions;
                float   rot = _temporaryRotationsCache[j];
                int     indexOnVertexArray = j * 2;
                float   progressOnStrip    = (float)j / (float)(count - 1);
                AddVertex(colorFunction, widthFunction, pos, rot, indexOnVertexArray, progressOnStrip);
            }
            _vertexAmountCurrentlyMaintained = count * 2;
            PrepareIndices(count, includeBacksides);
        }