Ejemplo n.º 1
0
        /// <summary>
        /// Called by the <see cref="LineDrawingTool" /> when the touch associated with this line begins on the <see cref="DrawingSurface" />.
        /// </summary>
        public void OnTouchBegan(DrawingSurface surface, Color color, Touch touch, LineOptions options)
        {
            // get position
            Vector2 position = CameraUtils.TouchToWorldPoint(touch, surface.Transform, surface.Camera);

            position = surface.Transform.parent.InverseTransformPoint(position);

            // reset points
            m_Points           = m_Points ?? new LinePoint[16];
            m_PointCount       = 0;
            m_SmoothPoints     = m_SmoothPoints ?? new LinePoint[1024];
            m_SmoothPointCount = 0;

            // reset
            m_Cap.Reset(options.Overdraw);
            m_Segment.Reset(options.Overdraw);
            m_Velocity.Reset(position, options.VelocityMin, options.VelocityMax, options.VelocitySmoothing);

            // add point
            LinePoint point = default(LinePoint);

            point.Color    = color;
            point.Position = position;
            point.Weight   = Mathf.Lerp(options.WeightMin, options.WeightMax, m_Velocity.Factor);
            AddPoint(point);

            // set flags
            m_IsDirty     = true;
            m_CapRequired = true;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Called by the <see cref="LineDrawingTool" /> when the touch associated with this line moves on the <see cref="DrawingSurface" />.
        /// </summary>
        public void OnTouchMoved(DrawingSurface surface, Color color, Touch touch, LineOptions options)
        {
            // get position
            Vector2 position = CameraUtils.TouchToWorldPoint(touch, surface.Transform, surface.Camera);

            position = surface.Transform.parent.InverseTransformPoint(position);

            // update
            m_Velocity.Update(position);

            // add point
            LinePoint point = default(LinePoint);

            point.Color    = color;
            point.Position = position;
            point.Weight   = Mathf.Lerp(options.WeightMin, options.WeightMax, m_Velocity.Factor);
            AddPoint(point);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Transforms the array of points into verts, colors and triangles and adds them to
        /// the geometry object (called by the <see cref="LineDrawingTool" /> each time it
        /// renders to the <see cref="DrawingSurface" />.
        /// </summary>
        public void OnRender(LineGeometry geometry, LineOptions options)
        {
            if (m_IsDirty && m_PointCount > 0)
            {
                // apply bezier smoothing
                GenerateSmoothPoints();
                int         count  = (m_SmoothPointCount > 0 ? m_SmoothPointCount : m_PointCount);
                LinePoint[] points = (m_SmoothPointCount > 0 ? m_SmoothPoints : m_Points);

                // add cap
                if (m_CapRequired)
                {
                    m_Cap.Update(points[count - 1]);
                    m_Cap.Apply(geometry);
                }

                // add points
                for (int index = 1; index < count; index++)
                {
                    // add segement
                    m_Segment.Update(points[index - 1], points[index - 0]);
                    m_Segment.Apply(geometry);

                    // add a cap when the direction changes
                    if (Vector2.Dot(m_Segment.NormalA, m_Segment.NormalB) < 0)
                    {
                        m_Cap.Update(points[index - 1]);
                        m_Cap.Apply(geometry);
                    }
                }

                // consume points
                if (m_PointCount > 2)
                {
                    m_Points[0]  = m_Points[m_PointCount - 2];
                    m_Points[1]  = m_Points[m_PointCount - 1];
                    m_PointCount = 2;
                }

                // clear flags
                m_CapRequired = false;
                m_IsDirty     = false;
            }
        }