Esempio n. 1
0
        /** override functions */
        // optional
        public override bool TouchBegan(CCTouch pTouch, CCEvent pEvent)
        {
            if (!Visible)
            {
                return(false);
            }

            CCPoint frameOriginal = Parent.ConvertToWorldSpace(Position);
            var     frame         = new CCRect(frameOriginal.X, frameOriginal.Y, m_tViewSize.Width, m_tViewSize.Height);

            //dispatcher does not know about clipping. reject touches outside visible bounds.
            if (m_pTouches.Count > 2 ||
                m_bTouchMoved ||
                !frame.ContainsPoint(m_pContainer.ConvertToWorldSpace(m_pContainer.ConvertTouchToNodeSpace(pTouch))))
            {
                return(false);
            }

            if (!m_pTouches.Contains(pTouch))
            {
                m_pTouches.Add(pTouch);
            }

            if (m_pTouches.Count == 1)
            {
                // scrolling
                m_tTouchPoint     = ConvertTouchToNodeSpace(pTouch);
                m_bTouchMoved     = false;
                m_bDragging       = true; //dragging started
                m_tScrollDistance = new CCPoint(0.0f, 0.0f);
                m_fTouchLength    = 0.0f;
            }
            else if (m_pTouches.Count == 2)
            {
                m_tTouchPoint = CCPoint.Midpoint(ConvertTouchToNodeSpace(m_pTouches[0]),
                                                 ConvertTouchToNodeSpace(m_pTouches[1]));
                m_fTouchLength = CCPoint.Distance(m_pContainer.ConvertTouchToNodeSpace(m_pTouches[0]),
                                                  m_pContainer.ConvertTouchToNodeSpace(m_pTouches[1]));
                m_bDragging = false;
            }
            return(true);
        }
Esempio n. 2
0
        /** override functions */
        // optional
        public override bool TouchBegan(CCTouch pTouch)
        {
            if (!Visible)
            {
                return(false);
            }

            CCRect frame = GetViewRect();

            //dispatcher does not know about clipping. reject touches outside visible bounds.
            if (m_pTouches.Count > 2 ||
                m_bTouchMoved ||
                !frame.ContainsPoint(m_pContainer.ConvertToWorldSpace(m_pContainer.ConvertTouchToNodeSpace(pTouch))))
            {
                return(false);
            }

            if (!m_pTouches.Contains(pTouch))
            {
                m_pTouches.Add(pTouch);
            }

            if (m_pTouches.Count == 1)
            {
                // scrolling
                m_tTouchPoint     = ConvertTouchToNodeSpace(pTouch);
                m_bTouchMoved     = false;
                m_bDragging       = true; //dragging started
                m_tScrollDistance = CCPoint.Zero;
                m_fTouchLength    = 0.0f;
            }
            else if (m_pTouches.Count == 2)
            {
                m_tTouchPoint = CCPoint.Midpoint(ConvertTouchToNodeSpace(m_pTouches[0]),
                                                 ConvertTouchToNodeSpace(m_pTouches[1]));
                m_fTouchLength = CCPoint.Distance(m_pContainer.ConvertTouchToNodeSpace(m_pTouches[0]),
                                                  m_pContainer.ConvertTouchToNodeSpace(m_pTouches[1]));
                m_bDragging = false;
            }
            return(true);
        }
        private void VertexLineToPolygon(CCPoint[] points, float stroke, CCV3F_C4B_T2F[] vertices, int offset, int nuPoints)
        {
            nuPoints += offset;
            if (nuPoints <= 1)
            {
                return;
            }

            stroke *= 0.5f;

            int idx;
            int nuPointsMinus = nuPoints - 1;

            float rad70  = MathHelper.ToRadians(70);
            float rad170 = MathHelper.ToRadians(170);

            for (int i = offset; i < nuPoints; i++)
            {
                idx = i * 2;
                CCPoint p1 = points[i];
                CCPoint perpVector;

                if (i == 0)
                {
                    perpVector = CCPoint.Perp(CCPoint.Normalize(p1 - points[i + 1]));
                }
                else if (i == nuPointsMinus)
                {
                    perpVector = CCPoint.Perp(CCPoint.Normalize(points[i - 1] - p1));
                }
                else
                {
                    CCPoint p2 = points[i + 1];
                    CCPoint p0 = points[i - 1];

                    CCPoint p2p1 = CCPoint.Normalize(p2 - p1);
                    CCPoint p0p1 = CCPoint.Normalize(p0 - p1);

                    // Calculate angle between vectors
                    var angle = (float)Math.Acos(CCPoint.Dot(p2p1, p0p1));

                    if (angle < rad70)
                    {
                        perpVector = CCPoint.Perp(CCPoint.Normalize(CCPoint.Midpoint(p2p1, p0p1)));
                    }
                    else if (angle < rad170)
                    {
                        perpVector = CCPoint.Normalize(CCPoint.Midpoint(p2p1, p0p1));
                    }
                    else
                    {
                        perpVector = CCPoint.Perp(CCPoint.Normalize(p2 - p0));
                    }
                }

                perpVector = perpVector * stroke;

                vertices[idx].Vertices     = new CCVertex3F(p1.X + perpVector.X, p1.Y + perpVector.Y, 0);
                vertices[idx + 1].Vertices = new CCVertex3F(p1.X - perpVector.X, p1.Y - perpVector.Y, 0);
            }

            // Validate vertexes
            offset = (offset == 0) ? 0 : offset - 1;
            for (int i = offset; i < nuPointsMinus; i++)
            {
                idx = i * 2;
                int idx1 = idx + 2;

                CCVertex3F p1 = vertices[idx].Vertices;
                CCVertex3F p2 = vertices[idx + 1].Vertices;
                CCVertex3F p3 = vertices[idx1].Vertices;
                CCVertex3F p4 = vertices[idx1 + 1].Vertices;

                float s;
                bool  fixVertex = !ccVertexLineIntersect(p1.X, p1.Y, p4.X, p4.Y, p2.X, p2.Y, p3.X, p3.Y, out s);
                if (!fixVertex)
                {
                    if (s < 0.0f || s > 1.0f)
                    {
                        fixVertex = true;
                    }
                }

                if (fixVertex)
                {
                    vertices[idx1].Vertices     = p4;
                    vertices[idx1 + 1].Vertices = p3;
                }
            }
        }