示例#1
0
        /// <summary>
        /// Draws the trail as a dotted line, fading away with age.
        /// </summary>
        public void Draw(IDraw drawer)
        {
            int index = currentIndex;

            for (int j = 0; j < vertices.Length; j++)
            {
                // index of the next vertex (mod around ring buffer)
                int next = (index + 1) % vertices.Length;

                // "tick mark": every second, draw a segment in a different color
                bool  tick  = ((flags[index] & 2) != 0 || (flags[next] & 2) != 0);
                Color color = tick ? tickColor : trailColor;

                // draw every other segment
                if ((flags[index] & 1) != 0)
                {
                    if (j == 0)
                    {
                        // draw segment from current position to first trail point
                        drawer.LineAlpha(currentPosition, vertices[index], color, 1);
                    }
                    else
                    {
                        // draw trail segments with opacity decreasing with age
                        const float minO     = 0.05f;                     // minimum opacity
                        float       fraction = (float)j / vertices.Length;
                        float       opacity  = (fraction * (1 - minO)) + minO;
                        drawer.LineAlpha(vertices[index], vertices[next], color, opacity);
                    }
                }
                index = next;
            }
        }
示例#2
0
文件: Trail.cs 项目: hgrandry/Mgx
        /// <summary>
        /// Draws the trail as a dotted line, fading away with age.
        /// </summary>
        public void Draw(IDraw drawer)
        {
            int index = _currentIndex;
            for (int j = 0; j < _vertices.Length; j++)
            {
                // index of the next vertex (mod around ring buffer)
                int next = (index + 1) % _vertices.Length;

                // "tick mark": every second, draw a segment in a different color
                bool tick = ((_flags[index] & 2) != 0 || (_flags[next] & 2) != 0);
                Color color = tick ? _tickColor : _trailColor;

                // draw every other segment
                if ((_flags[index] & 1) != 0)
                {
                    if (j == 0)
                    {
                        // draw segment from current position to first trail point
                        drawer.LineAlpha(_currentPosition, _vertices[index], color, 1);
                    }
                    else
                    {
                        // draw trail segments with opacity decreasing with age
                        const float minO = 0.05f; // minimum opacity
                        float fraction = (float)j / _vertices.Length;
                        float opacity = (fraction * (1 - minO)) + minO;
                        drawer.LineAlpha(_vertices[index], _vertices[next], color, opacity);
                    }
                }
                index = next;
            }
        }