Beispiel #1
0
 protected void getTransformValues(transformValues_ tv)
 {
     tv.pos      = m_tPositionInPixels;
     tv.scale.x  = m_fScaleX;
     tv.scale.y  = m_fScaleY;
     tv.rotation = m_fRotation;
     tv.skew.x   = m_fSkewX;
     tv.skew.y   = m_fSkewY;
     tv.ap       = m_tAnchorPointInPixels;
     tv.visible  = m_bIsVisible;
 }
Beispiel #2
0
 protected void getTransformValues(transformValues_ tv)
 {
     tv.pos      = _positionInPixels;
     tv.scale.X  = _scaleX;
     tv.scale.Y  = _scaleY;
     tv.rotation = _rotation;
     tv.skew.X   = _skewX;
     tv.skew.Y   = _skewY;
     tv.ap       = AnchorPointInPixels;
     tv.visible  = Visible;
 }
Beispiel #3
0
 protected void getTransformValues(transformValues_ tv)
 {
     tv.pos = _positionInPixels;
     tv.scale.X = _scaleX;
     tv.scale.Y = _scaleY;
     tv.rotation = _rotation;
     tv.skew.X = _skewX;
     tv.skew.Y = _skewY;
     tv.ap = AnchorPointInPixels;
     tv.visible = Visible;
 }
Beispiel #4
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 (!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;
            }

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

                matrix = CCAffineTransform.CCAffineTransformMake(c * _scaleX, s * _scaleX,
                    -s * _scaleY, c * _scaleY,
                    _positionInPixels.X, _positionInPixels.Y);
                if (_skewX > 0 || _skewY > 0)
                {
                    CCAffineTransform skewMatrix = 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);
                    matrix = CCAffineTransform.CCAffineTransformConcat(skewMatrix, matrix);
                }
                matrix = CCAffineTransform.CCAffineTransformTranslate(matrix, -AnchorPointInPixels.X, -AnchorPointInPixels.Y);
            }
            else // parent_ != batchNode_
            {
                // else do affine transformation according to the HonorParentTransform
                matrix = CCAffineTransform.CCAffineTransformMakeIdentity();
                ccHonorParentTransform prevHonor = ccHonorParentTransform.CC_HONOR_PARENT_TRANSFORM_ALL;

                Node 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, -CCUtils.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(CCUtils.CC_DEGREES_TO_RADIANS(tv.skew.Y)),
                            (float)Math.Tan(CCUtils.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, _vertexZ);
            m_sQuad.br.vertices = new ccVertex3F((float)bx, (float)by, _vertexZ);
            m_sQuad.tl.vertices = new ccVertex3F((float)dx, (float)dy, _vertexZ);
            m_sQuad.tr.vertices = new ccVertex3F((float)cx, (float)cy, _vertexZ);

            m_pobTextureAtlas.updateQuad(m_sQuad, m_uAtlasIndex);

            m_bDirty = m_bRecursiveDirty = false;
        }
Beispiel #5
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;
        }
 protected void getTransformValues(transformValues_ tv)
 {
     tv.pos = m_tPositionInPixels;
     tv.scale.x = m_fScaleX;
     tv.scale.y = m_fScaleY;
     tv.rotation = m_fRotation;
     tv.skew.x = m_fSkewX;
     tv.skew.y = m_fSkewY;
     tv.ap = m_tAnchorPointInPixels;
     tv.visible = m_bIsVisible;
 }
Beispiel #7
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;
         }
     }
 }