예제 #1
0
        public virtual CCAffineTransform NodeToParentTransform()
        {
            if (m_bIsTransformDirty)
            {
                // Translate values
                float x = m_tPosition.X;
                float y = m_tPosition.Y;

                if (m_bIgnoreAnchorPointForPosition)
                {
                    x += m_tAnchorPointInPoints.X;
                    y += m_tAnchorPointInPoints.Y;
                }

                // Rotation values
                float c = 1, s = 0;
                if (m_fRotation != 0.0f)
                {
                    float radians = -CCMacros.CCDegreesToRadians(m_fRotation);
                    c = (float)Math.Cos(radians);
                    s = (float)Math.Sin(radians);
                }

                bool needsSkewMatrix = (m_fSkewX != 0f || m_fSkewY != 0f);


                // optimization:
                // inline anchor point calculation if skew is not needed
                if (!needsSkewMatrix && !m_tAnchorPointInPoints.Equals(CCPoint.Zero))
                {
                    x += c * -m_tAnchorPointInPoints.X * m_fScaleX + -s * -m_tAnchorPointInPoints.Y * m_fScaleY;
                    y += s * -m_tAnchorPointInPoints.X * m_fScaleX + c * -m_tAnchorPointInPoints.Y * m_fScaleY;
                }

                // Build Transform Matrix
                //m_tTransform = new CCAffineTransform(
                //    c * m_fScaleX, s * m_fScaleX,
                //    -s * m_fScaleY, c * m_fScaleY,
                //    x, y);

                // Build Transform Matrix
                m_tTransform.a  = c * m_fScaleX;
                m_tTransform.b  = s * m_fScaleX;
                m_tTransform.c  = -s * m_fScaleY;
                m_tTransform.d  = c * m_fScaleY;
                m_tTransform.tx = x;
                m_tTransform.ty = y;

                // XXX: Try to inline skew
                // If skew is needed, apply skew and then anchor point
                if (needsSkewMatrix)
                {
                    var skewMatrix = new CCAffineTransform(
                        1.0f, (float)Math.Tan(CCMacros.CCDegreesToRadians(m_fSkewY)),
                        (float)Math.Tan(CCMacros.CCDegreesToRadians(m_fSkewX)), 1.0f,
                        0.0f, 0.0f);

                    m_tTransform = CCAffineTransform.CCAffineTransformConcat(skewMatrix, m_tTransform);

                    // adjust anchor point
                    if (!m_tAnchorPointInPoints.Equals(CCPoint.Zero))
                    {
                        m_tTransform = CCAffineTransform.CCAffineTransformTranslate(m_tTransform,
                                                                                    -m_tAnchorPointInPoints.X,
                                                                                    -m_tAnchorPointInPoints.Y);
                    }
                }

                m_bIsTransformDirty = false;
            }

            return(m_tTransform);
        }
예제 #2
0
 public void DrawCircle(CCPoint center, float radius, CCColor4B color)
 {
     DrawCircle(center, radius, CCMacros.CCDegreesToRadians(360f), 360, color);
 }