示例#1
0
 public CCAffineTransform nodeToParentTransform()
 {
     if (this.m_bIsTransformDirty)
     {
         this.m_tTransform = CCAffineTransform.CCAffineTransformMakeIdentity();
         if (!this.m_bIsRelativeAnchorPoint && !this.m_tAnchorPointInPixels.IsZero)
         {
             this.m_tTransform = CCAffineTransform.CCAffineTransformTranslate(this.m_tTransform, this.m_tAnchorPointInPixels.x, this.m_tAnchorPointInPixels.y);
         }
         if (!this.m_tPositionInPixels.IsZero)
         {
             this.m_tTransform = CCAffineTransform.CCAffineTransformTranslate(this.m_tTransform, this.m_tPositionInPixels.x, this.m_tPositionInPixels.y);
         }
         if (this.m_fRotation != 0f)
         {
             this.m_tTransform = CCAffineTransform.CCAffineTransformRotate(this.m_tTransform, -ccMacros.CC_DEGREES_TO_RADIANS(this.m_fRotation));
         }
         if ((this.m_fSkewX != 0f) || (this.m_fSkewY != 0f))
         {
             CCAffineTransform transform = CCAffineTransform.CCAffineTransformMake(1f, (float)Math.Tan((double)ccMacros.CC_DEGREES_TO_RADIANS(this.m_fSkewY)), (float)Math.Tan((double)ccMacros.CC_DEGREES_TO_RADIANS(this.m_fSkewX)), 1f, 0f, 0f);
             this.m_tTransform = CCAffineTransform.CCAffineTransformConcat(transform, this.m_tTransform);
         }
         if ((this.m_fScaleX != 1f) || (this.m_fScaleY != 1f))
         {
             this.m_tTransform = CCAffineTransform.CCAffineTransformScale(this.m_tTransform, this.m_fScaleX, this.m_fScaleY);
         }
         if (!this.m_tAnchorPointInPixels.IsZero)
         {
             this.m_tTransform = CCAffineTransform.CCAffineTransformTranslate(this.m_tTransform, -this.m_tAnchorPointInPixels.x, -this.m_tAnchorPointInPixels.y);
         }
         this.m_bIsTransformDirty = false;
     }
     return(this.m_tTransform);
 }
示例#2
0
文件: Node.cs 项目: liwq-net/liwq718
        /// <summary>
        /// Returns the matrix that transform the node's (local) space coordinates into the parent's space coordinates.
        /// The matrix is in Pixels.
        /// @since v0.7.1
        /// </summary>
        public CCAffineTransform nodeToParentTransform()
        {
            if (_isTransformDirty)
            {
                _transform = CCAffineTransform.CCAffineTransformMakeIdentity();

                if (!IsRelativeAnchorPoint && !AnchorPointInPixels.IsZero)
                {
                    _transform = CCAffineTransform.CCAffineTransformTranslate(_transform, AnchorPointInPixels.X, AnchorPointInPixels.Y);
                }

                if (!_positionInPixels.IsZero)
                {
                    _transform = CCAffineTransform.CCAffineTransformTranslate(_transform, _positionInPixels.X, _positionInPixels.Y);
                }

                if (_rotation != 0f)
                {
                    _transform = CCAffineTransform.CCAffineTransformRotate(_transform, -CCUtils.CC_DEGREES_TO_RADIANS(_rotation));
                }

                if (_skewX != 0f || _skewY != 0f)
                {
                    // create a skewed coordinate system
                    CCAffineTransform skew = CCAffineTransform.CCAffineTransformMake(1.0f,
                                                                                     (float)Math.Tan(CCUtils.CC_DEGREES_TO_RADIANS(_skewY)),
                                                                                     (float)Math.Tan(CCUtils.CC_DEGREES_TO_RADIANS(_skewX)), 1.0f, 0.0f, 0.0f);
                    // apply the skew to the transform
                    _transform = CCAffineTransform.CCAffineTransformConcat(skew, _transform);
                }

                if (!(_scaleX == 1f && _scaleY == 1f))
                {
                    _transform = CCAffineTransform.CCAffineTransformScale(_transform, _scaleX, _scaleY);
                }

                if (!AnchorPointInPixels.IsZero)
                {
                    _transform = CCAffineTransform.CCAffineTransformTranslate(_transform, -AnchorPointInPixels.X, -AnchorPointInPixels.Y);
                }

                _isTransformDirty = false;
            }

            return(_transform);
        }
示例#3
0
        // BatchNode methods

        /// <summary>
        /// updates the quad according the the rotation, position, scale values.
        /// </summary>
        public void updateTransform()
        {
            Debug.Assert(m_bUsesBatchNode != null);

            // optimization. Quick return if not dirty
            if (!m_bDirty)
            {
                return;
            }

            CCAffineTransform matrix;

            // Optimization: if it is not visible, then do nothing
            if (!m_bIsVisible)
            {
                m_sQuad.br.vertices = m_sQuad.tl.vertices = m_sQuad.tr.vertices = m_sQuad.bl.vertices = new ccVertex3F(0, 0, 0);
                m_pobTextureAtlas.updateQuad(m_sQuad, m_uAtlasIndex);
                //m_bDirty = m_bRecursiveDirty = false;
                return;
            }

            // Optimization: If parent is batchnode, or parent is nil
            // build Affine transform manually
            if (m_pParent == null || m_pParent == m_pobBatchNode)
            {
                float radians = -ccMacros.CC_DEGREES_TO_RADIANS(m_fRotation);
                float c       = (float)Math.Cos(radians);
                float s       = (float)Math.Sin(radians);

                matrix = CCAffineTransform.CCAffineTransformMake(c * m_fScaleX, s * m_fScaleX,
                                                                 -s * m_fScaleY, c * m_fScaleY,
                                                                 m_tPositionInPixels.x, m_tPositionInPixels.y);
                if (m_fSkewX > 0 || m_fSkewY > 0)
                {
                    CCAffineTransform skewMatrix = CCAffineTransform.CCAffineTransformMake(1.0f, (float)Math.Tan(ccMacros.CC_DEGREES_TO_RADIANS(m_fSkewY)),
                                                                                           (float)Math.Tan(ccMacros.CC_DEGREES_TO_RADIANS(m_fSkewX)), 1.0f,
                                                                                           0.0f, 0.0f);
                    matrix = CCAffineTransform.CCAffineTransformConcat(skewMatrix, matrix);
                }
                matrix = CCAffineTransform.CCAffineTransformTranslate(matrix, -m_tAnchorPointInPixels.x, -m_tAnchorPointInPixels.y);
            }
            else // parent_ != batchNode_
            {
                // else do affine transformation according to the HonorParentTransform
                matrix = CCAffineTransform.CCAffineTransformMakeIdentity();
                ccHonorParentTransform prevHonor = ccHonorParentTransform.CC_HONOR_PARENT_TRANSFORM_ALL;

                CCNode p = this;
                while (p != null && p is CCSprite && p != m_pobBatchNode)
                {
                    // Might happen. Issue #1053
                    // how to implement, we can not use dynamic
                    // CCAssert( [p isKindOfClass:[CCSprite class]], @"CCSprite should be a CCSprite subclass. Probably you initialized an sprite with a batchnode, but you didn't add it to the batch node." );
                    transformValues_ tv = new transformValues_();
                    ((CCSprite)p).getTransformValues(tv);

                    // If any of the parents are not visible, then don't draw this node
                    if (!tv.visible)
                    {
                        m_sQuad.br.vertices = m_sQuad.tl.vertices = m_sQuad.tr.vertices = m_sQuad.bl.vertices = new ccVertex3F(0, 0, 0);
                        m_pobTextureAtlas.updateQuad(m_sQuad, m_uAtlasIndex);
                        m_bDirty = m_bRecursiveDirty = false;

                        return;
                    }

                    CCAffineTransform newMatrix = CCAffineTransform.CCAffineTransformMakeIdentity();

                    // 2nd: Translate, Skew, Rotate, Scale
                    if ((int)prevHonor != 0 & (int)ccHonorParentTransform.CC_HONOR_PARENT_TRANSFORM_TRANSLATE != 0)
                    {
                        newMatrix = CCAffineTransform.CCAffineTransformTranslate(newMatrix, tv.pos.x, tv.pos.y);
                    }

                    if ((int)prevHonor != 0 & (int)ccHonorParentTransform.CC_HONOR_PARENT_TRANSFORM_ROTATE != 0)
                    {
                        newMatrix = CCAffineTransform.CCAffineTransformRotate(newMatrix, -ccMacros.CC_DEGREES_TO_RADIANS(tv.rotation));
                    }

                    if ((int)prevHonor != 0 & (int)ccHonorParentTransform.CC_HONOR_PARENT_TRANSFORM_SKEW != 0)
                    {
                        CCAffineTransform skew = CCAffineTransform.CCAffineTransformMake(1.0f,
                                                                                         (float)Math.Tan(ccMacros.CC_DEGREES_TO_RADIANS(tv.skew.y)),
                                                                                         (float)Math.Tan(ccMacros.CC_DEGREES_TO_RADIANS(tv.skew.x)), 1.0f, 0.0f, 0.0f);
                        // apply the skew to the transform
                        newMatrix = CCAffineTransform.CCAffineTransformConcat(skew, newMatrix);
                    }

                    if ((int)prevHonor != 0 & (int)ccHonorParentTransform.CC_HONOR_PARENT_TRANSFORM_SCALE != 0)
                    {
                        newMatrix = CCAffineTransform.CCAffineTransformScale(newMatrix, tv.scale.x, tv.scale.y);
                    }

                    // 3rd: Translate anchor point
                    newMatrix = CCAffineTransform.CCAffineTransformTranslate(newMatrix, -tv.ap.x, -tv.ap.y);

                    // 4th: Matrix multiplication
                    matrix = CCAffineTransform.CCAffineTransformConcat(matrix, newMatrix);

                    prevHonor = ((CCSprite)p).honorParentTransform;

                    p = p.parent;
                }
            }

            //
            // calculate the Quad based on the Affine Matrix
            //
            CCSize size = m_obRectInPixels.size;

            float x1 = m_obOffsetPositionInPixels.x;
            float y1 = m_obOffsetPositionInPixels.y;

            float x2 = x1 + size.width;
            float y2 = y1 + size.height;
            float x  = matrix.tx;
            float y  = matrix.ty;

            float cr  = matrix.a;
            float sr  = matrix.b;
            float cr2 = matrix.d;
            float sr2 = -matrix.c;
            float ax  = x1 * cr - y1 * sr2 + x;
            float ay  = x1 * sr + y1 * cr2 + y;

            float bx = x2 * cr - y1 * sr2 + x;
            float by = x2 * sr + y1 * cr2 + y;

            float cx = x2 * cr - y2 * sr2 + x;
            float cy = x2 * sr + y2 * cr2 + y;

            float dx = x1 * cr - y2 * sr2 + x;
            float dy = x1 * sr + y2 * cr2 + y;

            m_sQuad.bl.vertices = new ccVertex3F((float)ax, (float)ay, m_fVertexZ);
            m_sQuad.br.vertices = new ccVertex3F((float)bx, (float)by, m_fVertexZ);
            m_sQuad.tl.vertices = new ccVertex3F((float)dx, (float)dy, m_fVertexZ);
            m_sQuad.tr.vertices = new ccVertex3F((float)cx, (float)cy, m_fVertexZ);

            m_pobTextureAtlas.updateQuad(m_sQuad, m_uAtlasIndex);

            m_bDirty = m_bRecursiveDirty = false;
        }
示例#4
0
 public void updateTransform()
 {
     if (this.m_bDirty)
     {
         if (!base.m_bIsVisible)
         {
             this.m_sQuad.br.vertices = this.m_sQuad.tl.vertices = this.m_sQuad.tr.vertices = this.m_sQuad.bl.vertices = new ccVertex3F(0f, 0f, 0f);
             this.m_pobTextureAtlas.updateQuad(this.m_sQuad, this.m_uAtlasIndex);
         }
         else
         {
             CCAffineTransform transform;
             if ((base.m_pParent == null) || (base.m_pParent == this.m_pobBatchNode))
             {
                 float num  = -ccMacros.CC_DEGREES_TO_RADIANS(base.m_fRotation);
                 float num2 = (float)Math.Cos((double)num);
                 float num3 = (float)Math.Sin((double)num);
                 transform = CCAffineTransform.CCAffineTransformMake(num2 * base.m_fScaleX, num3 * base.m_fScaleX, -num3 * base.m_fScaleY, num2 * base.m_fScaleY, base.m_tPositionInPixels.x, base.m_tPositionInPixels.y);
                 if ((base.m_fSkewX > 0f) || (base.m_fSkewY > 0f))
                 {
                     transform = CCAffineTransform.CCAffineTransformConcat(CCAffineTransform.CCAffineTransformMake(1f, (float)Math.Tan((double)ccMacros.CC_DEGREES_TO_RADIANS(base.m_fSkewY)), (float)Math.Tan((double)ccMacros.CC_DEGREES_TO_RADIANS(base.m_fSkewX)), 1f, 0f, 0f), transform);
                 }
                 transform = CCAffineTransform.CCAffineTransformTranslate(transform, -base.m_tAnchorPointInPixels.x, -base.m_tAnchorPointInPixels.y);
             }
             else
             {
                 transform = CCAffineTransform.CCAffineTransformMakeIdentity();
                 ccHonorParentTransform honorParentTransform = ccHonorParentTransform.CC_HONOR_PARENT_TRANSFORM_ALL;
                 for (CCNode node = this; ((node != null) && (node is CCSprite)) && (node != this.m_pobBatchNode); node = node.parent)
                 {
                     transformValues_ tv = new transformValues_();
                     ((CCSprite)node).getTransformValues(tv);
                     if (!tv.visible)
                     {
                         this.m_sQuad.br.vertices = this.m_sQuad.tl.vertices = this.m_sQuad.tr.vertices = this.m_sQuad.bl.vertices = new ccVertex3F(0f, 0f, 0f);
                         this.m_pobTextureAtlas.updateQuad(this.m_sQuad, this.m_uAtlasIndex);
                         this.m_bDirty = this.m_bRecursiveDirty = false;
                         return;
                     }
                     CCAffineTransform t = CCAffineTransform.CCAffineTransformMakeIdentity();
                     if (honorParentTransform != ((ccHonorParentTransform)0))
                     {
                         t = CCAffineTransform.CCAffineTransformTranslate(t, tv.pos.x, tv.pos.y);
                     }
                     if (honorParentTransform != ((ccHonorParentTransform)0))
                     {
                         t = CCAffineTransform.CCAffineTransformRotate(t, -ccMacros.CC_DEGREES_TO_RADIANS(tv.rotation));
                     }
                     if (honorParentTransform != ((ccHonorParentTransform)0))
                     {
                         t = CCAffineTransform.CCAffineTransformConcat(CCAffineTransform.CCAffineTransformMake(1f, (float)Math.Tan((double)ccMacros.CC_DEGREES_TO_RADIANS(tv.skew.y)), (float)Math.Tan((double)ccMacros.CC_DEGREES_TO_RADIANS(tv.skew.x)), 1f, 0f, 0f), t);
                     }
                     if (honorParentTransform != ((ccHonorParentTransform)0))
                     {
                         t = CCAffineTransform.CCAffineTransformScale(t, tv.scale.x, tv.scale.y);
                     }
                     t                    = CCAffineTransform.CCAffineTransformTranslate(t, -tv.ap.x, -tv.ap.y);
                     transform            = CCAffineTransform.CCAffineTransformConcat(transform, t);
                     honorParentTransform = ((CCSprite)node).honorParentTransform;
                 }
             }
             CCSize size  = this.m_obRectInPixels.size;
             float  x     = this.m_obOffsetPositionInPixels.x;
             float  y     = this.m_obOffsetPositionInPixels.y;
             float  num6  = x + size.width;
             float  num7  = y + size.height;
             float  tx    = transform.tx;
             float  ty    = transform.ty;
             float  a     = transform.a;
             float  b     = transform.b;
             float  d     = transform.d;
             float  num13 = -transform.c;
             float  inx   = ((x * a) - (y * num13)) + tx;
             float  iny   = ((x * b) + (y * d)) + ty;
             float  num16 = ((num6 * a) - (y * num13)) + tx;
             float  num17 = ((num6 * b) + (y * d)) + ty;
             float  num18 = ((num6 * a) - (num7 * num13)) + tx;
             float  num19 = ((num6 * b) + (num7 * d)) + ty;
             float  num20 = ((x * a) - (num7 * num13)) + tx;
             float  num21 = ((x * b) + (num7 * d)) + ty;
             this.m_sQuad.bl.vertices = new ccVertex3F(inx, iny, base.m_fVertexZ);
             this.m_sQuad.br.vertices = new ccVertex3F(num16, num17, base.m_fVertexZ);
             this.m_sQuad.tl.vertices = new ccVertex3F(num20, num21, base.m_fVertexZ);
             this.m_sQuad.tr.vertices = new ccVertex3F(num18, num19, base.m_fVertexZ);
             this.m_pobTextureAtlas.updateQuad(this.m_sQuad, this.m_uAtlasIndex);
             this.m_bDirty = this.m_bRecursiveDirty = false;
         }
     }
 }