コード例 #1
0
 /// <summary>
 /// Concatenate `t2' to `t1' and return the result:
 /// t' = t1 * t2 */s
 /// </summary>
 /// <param name="t1"></param>
 /// <param name="t2"></param>
 /// <returns></returns>
 public static CCAffineTransform CCAffineTransformConcat(CCAffineTransform t1, CCAffineTransform t2)
 {
     return new CCAffineTransform(t1.a * t2.a + t1.b * t2.c, t1.a * t2.b + t1.b * t2.d, //a,b
                                  t1.c * t2.a + t1.d * t2.c, t1.c * t2.b + t1.d * t2.d, //c,d
                                  t1.tx * t2.a + t1.ty * t2.c + t2.tx, //tx
                                  t1.tx * t2.b + t1.ty * t2.d + t2.ty); //ty
 }
コード例 #2
0
        public static CCAffineTransform CCAffineTransformInvert(CCAffineTransform t)
        {
            float determinant = 1 / (t.a * t.d - t.b * t.c);

            return new CCAffineTransform(determinant * t.d, -determinant * t.b, -determinant * t.c, determinant * t.a,
                                         determinant * (t.c * t.ty - t.d * t.tx), determinant * (t.b * t.tx - t.a * t.ty));
        }
コード例 #3
0
 public static CCSize CCSizeApplyAffineTransform(CCSize size, CCAffineTransform t)
 {
     CCSize s = new CCSize();
     s.width = (float)((double)t.a * size.width + (double)t.c * size.height);
     s.height = (float)((double)t.b * size.width + (double)t.d * size.height);
     return s;
 }
コード例 #4
0
 public static CCPoint CCPointApplyAffineTransform(CCPoint point, CCAffineTransform t)
 {
     CCPoint p = new CCPoint();
     p.x = (float)((double)t.a * point.x + (double)t.c * point.y + t.tx);
     p.y = (float)((double)t.b * point.x + (double)t.d * point.y + t.ty); 
     return p;
 }
コード例 #5
0
        public static void CGAffineToGL(CCAffineTransform t, ref float[] m)
        {
            // | m[0] m[4] m[8]  m[12] |     | m11 m21 m31 m41 |     | a c 0 tx |
            // | m[1] m[5] m[9]  m[13] |     | m12 m22 m32 m42 |     | b d 0 ty |
            // | m[2] m[6] m[10] m[14] | <=> | m13 m23 m33 m43 | <=> | 0 0 1  0 |
            // | m[3] m[7] m[11] m[15] |     | m14 m24 m34 m44 |     | 0 0 0  1 |

            m[2] = m[3] = m[6] = m[7] = m[8] = m[9] = m[11] = m[14] = 0.0f;
            m[10] = m[15] = 1.0f;
            m[0] = t.a; m[4] = t.c; m[12] = t.tx;
            m[1] = t.b; m[5] = t.d; m[13] = t.ty;
        }
コード例 #6
0
ファイル: CCAffineTransform.cs プロジェクト: liwq-net/liwq718
        public static CCAffineTransform CCAffineTransformRotate(CCAffineTransform t, float anAngle)
        {
            float fSin = (float)Math.Sin(anAngle);
            float fCos = (float)Math.Cos(anAngle);

            return CCAffineTransformMake(
                t.a * fCos +
                t.c * fSin,
                t.b * fCos +
                t.d * fSin,
                t.c * fCos - t.a * fSin,
                t.d * fCos - t.b * fSin,
                t.tx, t.ty
                );
        }
コード例 #7
0
        public static CCRect CCRectApplyAffineTransform(CCRect rect, CCAffineTransform anAffineTransform)
        {
            float top    = rect.MinY;
            float left   = rect.MinX;
            float right  = rect.MaxX;
            float bottom = rect.MaxY;

            CCPoint topLeft     = CCPointApplyAffineTransform(new CCPoint(left, top), anAffineTransform);
            CCPoint topRight    = CCPointApplyAffineTransform(new CCPoint(right, top), anAffineTransform);
            CCPoint bottomLeft  = CCPointApplyAffineTransform(new CCPoint(left, bottom), anAffineTransform);
            CCPoint bottomRight = CCPointApplyAffineTransform(new CCPoint(right, bottom), anAffineTransform);

            float minX = Math.Min(Math.Min(topLeft.X, topRight.X), Math.Min(bottomLeft.X, bottomRight.X));
            float maxX = Math.Max(Math.Max(topLeft.X, topRight.X), Math.Max(bottomLeft.X, bottomRight.X));
            float minY = Math.Min(Math.Min(topLeft.Y, topRight.Y), Math.Min(bottomLeft.Y, bottomRight.Y));
            float maxY = Math.Max(Math.Max(topLeft.Y, topRight.Y), Math.Max(bottomLeft.Y, bottomRight.Y));

            return(new CCRect(minX, minY, (maxX - minX), (maxY - minY)));
        }
コード例 #8
0
        public static void CGAffineToGL(CCAffineTransform t, ref float[] m)
        {
            float single  = 0f;
            float single1 = single;

            m[14] = single;
            float single2 = single1;
            float single3 = single2;

            m[11] = single2;
            float single4 = single3;
            float single5 = single4;

            m[9] = single4;
            float single6 = single5;
            float single7 = single6;

            m[8] = single6;
            float single8 = single7;
            float single9 = single8;

            m[7] = single8;
            float single10 = single9;
            float single11 = single10;

            m[6] = single10;
            float single12 = single11;
            float single13 = single12;

            m[3] = single12;
            m[2] = single13;
            float single14 = 1f;
            float single15 = single14;

            m[15] = single14;
            m[10] = single15;
            m[0]  = t.a;
            m[4]  = t.c;
            m[12] = t.tx;
            m[1]  = t.b;
            m[5]  = t.d;
            m[13] = t.ty;
        }
コード例 #9
0
        public static CCRect CCRectApplyAffineTransform(CCRect rect, CCAffineTransform anAffineTransform)
        {
            float top    = CCRect.CCRectGetMinY(rect);
            float left   = CCRect.CCRectGetMinX(rect);
            float right  = CCRect.CCRectGetMaxX(rect);
            float bottom = CCRect.CCRectGetMaxY(rect);

            CCPoint topLeft     = CCPointApplyAffineTransform(new CCPoint(left, top), anAffineTransform);
            CCPoint topRight    = CCPointApplyAffineTransform(new CCPoint(right, top), anAffineTransform);
            CCPoint bottomLeft  = CCPointApplyAffineTransform(new CCPoint(left, bottom), anAffineTransform);
            CCPoint bottomRight = CCPointApplyAffineTransform(new CCPoint(right, bottom), anAffineTransform);

            float minX = Math.Min(Math.Min(topLeft.x, topRight.x), Math.Min(bottomLeft.x, bottomRight.x));
            float maxX = Math.Max(Math.Max(topLeft.x, topRight.x), Math.Max(bottomLeft.x, bottomRight.x));
            float minY = Math.Min(Math.Min(topLeft.y, topRight.y), Math.Min(bottomLeft.y, bottomRight.y));
            float maxY = Math.Max(Math.Max(topLeft.y, topRight.y), Math.Max(bottomLeft.y, bottomRight.y));

            return(new CCRect(minX, minY, (maxX - minX), (maxY - minY)));
        }
コード例 #10
0
        public static CCRect CCRectApplyAffineTransform(CCRect rect, CCAffineTransform anAffineTransform)
        {
            float top = CCRect.CCRectGetMinY(rect);
            float left = CCRect.CCRectGetMinX(rect);
            float right = CCRect.CCRectGetMaxX(rect);
            float bottom = CCRect.CCRectGetMaxY(rect);

            CCPoint topLeft = CCPointApplyAffineTransform(new CCPoint(left, top), anAffineTransform);
            CCPoint topRight = CCPointApplyAffineTransform(new CCPoint(right, top), anAffineTransform);
            CCPoint bottomLeft = CCPointApplyAffineTransform(new CCPoint(left, bottom), anAffineTransform);
            CCPoint bottomRight = CCPointApplyAffineTransform(new CCPoint(right, bottom), anAffineTransform);

            float minX = Math.Min(Math.Min(topLeft.x, topRight.x), Math.Min(bottomLeft.x, bottomRight.x));
            float maxX = Math.Max(Math.Max(topLeft.x, topRight.x), Math.Max(bottomLeft.x, bottomRight.x));
            float minY = Math.Min(Math.Min(topLeft.y, topRight.y), Math.Min(bottomLeft.y, bottomRight.y));
            float maxY = Math.Max(Math.Max(topLeft.y, topRight.y), Math.Max(bottomLeft.y, bottomRight.y));

            return new CCRect(minX, minY, (maxX - minX), (maxY - minY));
        }
コード例 #11
0
ファイル: Node.cs プロジェクト: liwq-net/liwq718
        /// <summary>performs OpenGL view-matrix transformation based on position, scale, rotation and other attributes.</summary>
        public void Transform()
        {
            // transformations

            Application app = Application.SharedApplication;

            // BEGIN alternative -- using cached transform

            if (this._isTransformGLDirty)
            {
                CCAffineTransform t = this.nodeToParentTransform();
                TransformUtils.CGAffineToGL(t, ref _transformGL);
                this._isTransformGLDirty = false;
            }

            this._nodeTransform = TransformUtils.CGAffineToMatrix(this._transformGL);

            if (this._vertexZ > 0)
            {
                this._nodeTransform *= Matrix.CreateRotationZ(_vertexZ);
            }

            // XXX: Expensive calls. Camera should be integrated into the cached affine matrix
            if (this._camera != null && !(this.Grid != null && this.Grid.Active))
            {
                bool translate = (this.AnchorPointInPixels.X != 0.0f || this.AnchorPointInPixels.Y != 0.0f);

                Matrix?matrix = this._camera.locate();
                if (matrix != null)
                {
                    this._nodeTransform = Matrix.CreateTranslation(-AnchorPointInPixels.X, -AnchorPointInPixels.Y, 0) *
                                          matrix.Value *
                                          Matrix.CreateTranslation(AnchorPointInPixels.X, AnchorPointInPixels.Y, 0) *
                                          this._nodeTransform;
                }
            }

            // This is ok here. Visit() will restore the world transform for the next node.
            app.BasicEffect.World = this._nodeTransform * app.BasicEffect.World;
        }
コード例 #12
0
        public void Concat(ref CCAffineTransform m)
        {
            float t_a = a;
            float t_b = b;
            float t_c = c;
            float t_d = d;
            float t_tx = tx;
            float t_ty = ty;

            float m_a = m.a;
            float m_b = m.b;
            float m_c = m.c;
            float m_d = m.d;

            a = m_a * t_a + m_c * t_b;
            b = m_b * t_a + m_d * t_b;
            c = m_a * t_c + m_c * t_d;
            d = m_b * t_c + m_d * t_d;

            tx = m_a * t_tx + m_c * t_ty + m.tx;
            ty = m_b * t_tx + m_d * t_ty + m.ty;
        }
コード例 #13
0
 public static CCPoint CCPointApplyAffineTransform(CCPoint point, CCAffineTransform t)
 {
     return new CCPoint(
         t.a * point.X + t.c * point.Y + t.tx,
         t.b * point.X + t.d * point.Y + t.ty
         );
 }
コード例 #14
0
 public static CCAffineTransform CCAffineTransformScale(CCAffineTransform t, float sx, float sy)
 {
     return new CCAffineTransform(t.a * sx, t.b * sx, t.c * sy, t.d * sy, t.tx, t.ty);
 }
コード例 #15
0
ファイル: CCNode.cs プロジェクト: ChowZenki/cocos2d-x-for-xna
        /// <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 (m_bIsTransformDirty)
            {
                m_tTransform = CCAffineTransform.CCAffineTransformMakeIdentity();

                if (!m_bIsRelativeAnchorPoint && !CCPoint.CCPointEqualToPoint(m_tAnchorPointInPixels, new CCPoint()))
                {
                    m_tTransform = CCAffineTransform.CCAffineTransformTranslate(m_tTransform, m_tAnchorPointInPixels.x, m_tAnchorPointInPixels.y);
                }

                if (!CCPoint.CCPointEqualToPoint(m_tPositionInPixels, new CCPoint()))
                {
                    m_tTransform = CCAffineTransform.CCAffineTransformTranslate(m_tTransform, m_tPositionInPixels.x, m_tPositionInPixels.y);
                }

                if (m_fRotation != 0)
                {
                    m_tTransform = CCAffineTransform.CCAffineTransformRotate(m_tTransform, -ccMacros.CC_DEGREES_TO_RADIANS(m_fRotation));
                }

                if (m_fSkewX != 0 || m_fSkewY != 0)
                {
                    // create a skewed coordinate system
                    CCAffineTransform skew = 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);
                    // apply the skew to the transform
                    m_tTransform = CCAffineTransform.CCAffineTransformConcat(skew, m_tTransform);
                }

                if (!(m_fScaleX == 1 && m_fScaleY == 1))
                {
                    m_tTransform = CCAffineTransform.CCAffineTransformScale(m_tTransform, m_fScaleX, m_fScaleY);
                }

                if (!CCPoint.CCPointEqualToPoint(m_tAnchorPointInPixels, new CCPoint()))
                {
                    m_tTransform = CCAffineTransform.CCAffineTransformTranslate(m_tTransform, -m_tAnchorPointInPixels.x, -m_tAnchorPointInPixels.y);
                }

                m_bIsTransformDirty = false;
            }

            return m_tTransform;
        }
コード例 #16
0
        public override void draw()
        {
            base.draw();

            BlendState oldBlendState = Application.SharedApplication.GraphicsDevice.BlendState;

            BlendState eBlendState = BlendState.AlphaBlend;

            if (this.IsBlendAdditive)
            {
                eBlendState = BlendState.Additive;
            }

            Application.SharedApplication.SpriteBatch.Begin(SpriteSortMode.Deferred, eBlendState);
            for (int i = 0; i < this.ParticleCount; i++)
            {
                CCParticle particle = m_pParticles[i];

                CCPoint uiPoint = CCAffineTransform.CCPointApplyAffineTransform(new CCPoint(), this.nodeToWorldTransform());
                uiPoint = CCPointExtension.ccpAdd(uiPoint, new CCPoint(m_pQuads[i].bl.vertices.x, m_pQuads[i].bl.vertices.y));
                uiPoint = Director.SharedDirector.ConvertToUI(uiPoint);

                Vector2 vecPosition = new Vector2(uiPoint.X, uiPoint.Y);

                Color color = new Color(particle.color.r,
                                        particle.color.g,
                                        particle.color.b,
                                        particle.color.a);

                float scale = 1.0f;
                if (Texture.Texture2D.Width > Texture.Texture2D.Height)
                {
                    scale = particle.size / Texture.Texture2D.Height;
                }
                else
                {
                    scale = particle.size / Texture.Texture2D.Width;
                }

                float rotation = particle.rotation;

                Vector2 origin = new Vector2(Texture.Texture2D.Width / 2, Texture.Texture2D.Height / 2);
                Application.SharedApplication.SpriteBatch.Draw(this.Texture.Texture2D, vecPosition, null, color, rotation, origin, scale, SpriteEffects.None, 0);


                //CCPoint uiPoint = CCAffineTransform.CCPointApplyAffineTransform(new CCPoint(), this.nodeToWorldTransform());
                //uiPoint.x += m_pQuads[i].bl.vertices.x;
                //uiPoint.y += m_pQuads[i].bl.vertices.y;
                //uiPoint = CCDirector.sharedDirector().convertToUI(uiPoint);
                //Vector2 vecPosition = new Vector2(uiPoint.x, uiPoint.y);

                //Color color = new Color(m_pQuads[i].bl.colors.r,
                //                        m_pQuads[i].bl.colors.g,
                //                        m_pQuads[i].bl.colors.b,
                //                        m_pQuads[i].bl.colors.a);

                //Vector2 origin = new Vector2(Texture.Texture2D.Width/2, Texture.Texture2D.Height/2);
                //Application.SharedApplication.SpriteBatch.Draw(this.Texture.Texture2D, vecPosition, null, color, 0, origin, 1.0f, SpriteEffects.None, 0);
            }
            Application.SharedApplication.SpriteBatch.End();

            Application.SharedApplication.GraphicsDevice.BlendState = oldBlendState;

            //    // Default GL states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY
            //    // Needed states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY
            //    // Unneeded states: -
            //    glBindTexture(GL_TEXTURE_2D, m_pTexture->getName());

            //    #define kQuadSize sizeof(m_pQuads[0].bl)


            //    int offset = (int) m_pQuads;

            //    // vertex
            //    int diff = offsetof( ccV2F_C4B_T2F, vertices);
            //    glVertexPointer(2,GL_FLOAT, kQuadSize, (GLvoid*) (offset+diff) );

            //    // color
            //    diff = offsetof( ccV2F_C4B_T2F, colors);
            //    glColorPointer(4, GL_UNSIGNED_BYTE, kQuadSize, (GLvoid*)(offset + diff));

            //    // tex coords
            //    diff = offsetof( ccV2F_C4B_T2F, texCoords);
            //    glTexCoordPointer(2, GL_FLOAT, kQuadSize, (GLvoid*)(offset + diff));


            //    bool newBlend = (m_tBlendFunc.src != CC_BLEND_SRC || m_tBlendFunc.dst != CC_BLEND_DST) ? true : false;
            //    if( newBlend )
            //    {
            //        glBlendFunc( m_tBlendFunc.src, m_tBlendFunc.dst );
            //    }

            //    CCAssert( m_uParticleIdx == m_uParticleCount, "Abnormal error in particle quad");

            //    glDrawElements(GL_TRIANGLES, (GLsizei)(m_uParticleIdx*6), GL_UNSIGNED_SHORT, m_pIndices);

            //    // restore blend state
            //    if( newBlend )
            //        glBlendFunc( CC_BLEND_SRC, CC_BLEND_DST );

            //#if CC_USES_VBO
            //    glBindBuffer(GL_ARRAY_BUFFER, 0);
            //#endif
        }
コード例 #17
0
 public static CCAffineTransform CCAffineTransformScale(CCAffineTransform t, float sx, float sy)
 {
     return(CCAffineTransform.CCAffineTransformMake(t.a * sx, t.b * sx, t.c * sy, t.d * sy, t.tx, t.ty));
 }
コード例 #18
0
 public static void GLToCGAffine(float[] m, CCAffineTransform t)
 {
     t.a = m[0]; t.c = m[4]; t.tx = m[12];
     t.b = m[1]; t.d = m[5]; t.ty = m[13];
 }
コード例 #19
0
 public static Matrix CGAffineToMatrix(CCAffineTransform t)
 {
     float[] singleArray = new float[16];
     TransformUtils.CGAffineToGL(t, ref singleArray);
     return(TransformUtils.CGAffineToMatrix(singleArray));
 }
コード例 #20
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;
        }
コード例 #21
0
ファイル: CCSprite.cs プロジェクト: HarkDev/cocos2d-xna
        public void UpdateTransform()
        {
            Debug.Assert(m_pobBatchNode != null,
                         "updateTransform is only valid when CCSprite is being rendered using an CCSpriteBatchNode");

            // recaculate matrix only if it is dirty
            if (Dirty)
            {
                // If it is not visible, or one of its ancestors is not visible, then do nothing:
                if (!m_bIsVisible ||
                    (m_pParent != null && m_pParent != m_pobBatchNode && ((CCSprite)m_pParent).m_bShouldBeHidden))
                {
                    m_sQuad.BottomRight.Vertices =
                        m_sQuad.TopLeft.Vertices = m_sQuad.TopRight.Vertices = m_sQuad.BottomLeft.Vertices = new CCVertex3F(0, 0, 0);
                    m_bShouldBeHidden = true;
                }
                else
                {
                    m_bShouldBeHidden = false;

                    if (m_pParent == null || m_pParent == m_pobBatchNode)
                    {
                        m_transformToBatch = NodeToParentTransform();
                    }
                    else
                    {
                        Debug.Assert((m_pParent as CCSprite) != null,
                                     "Logic error in CCSprite. Parent must be a CCSprite");
                        m_transformToBatch = CCAffineTransform.CCAffineTransformConcat(NodeToParentTransform(),
                                                                                       ((CCSprite)m_pParent).
                                                                                           m_transformToBatch);
                    }

                    //
                    // calculate the Quad based on the Affine Matrix
                    //

                    CCSize size = m_obRect.Size;

                    float x1 = m_obOffsetPosition.X;
                    float y1 = m_obOffsetPosition.Y;

                    float x2 = x1 + size.Width;
                    float y2 = y1 + size.Height;
                    float x = m_transformToBatch.tx;
                    float y = m_transformToBatch.ty;

                    float cr = m_transformToBatch.a;
                    float sr = m_transformToBatch.b;
                    float cr2 = m_transformToBatch.d;
                    float sr2 = -m_transformToBatch.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.BottomLeft.Vertices = new CCVertex3F(ax, ay, m_fVertexZ);
                    m_sQuad.BottomRight.Vertices = new CCVertex3F(bx, by, m_fVertexZ);
                    m_sQuad.TopLeft.Vertices = new CCVertex3F(dx, dy, m_fVertexZ);
                    m_sQuad.TopRight.Vertices = new CCVertex3F(cx, cy, m_fVertexZ);
                }

                m_pobTextureAtlas.UpdateQuad(ref m_sQuad, m_uAtlasIndex);
                m_bRecursiveDirty = false;
                m_bDirty = false;
            }

            // recursively iterate over children
            if (m_bHasChildren)
            {
                CCNode[] elements = m_pChildren.Elements;
                if (m_pobBatchNode != null)
                {
                    for (int i = 0, count = m_pChildren.count; i < count; i++)
                    {
                        ((CCSprite)elements[i]).UpdateTransform();
                    }
                }
                else
                {
                    for (int i = 0, count = m_pChildren.count; i < count; i++)
                    {
                        var sprite = elements[i] as CCSprite;
                        if (sprite != null)
                        {
                            sprite.UpdateTransform();
                        }
                    }
                }
            }
        }
コード例 #22
0
ファイル: Node.cs プロジェクト: liwq-net/liwq718
 /// <summary>
 /// Returns the inverse world affine transform matrix. The matrix is in Pixels.
 ///@since v0.7.1
 /// </summary>
 public CCAffineTransform worldToNodeTransform()
 {
     return(CCAffineTransform.CCAffineTransformInvert(this.nodeToWorldTransform()));
 }
コード例 #23
0
ファイル: Node.cs プロジェクト: liwq-net/liwq718
        /// <summary>
        /// returns a "local" axis aligned bounding box of the node in pixels.
        /// The returned box is relative only to its parent.
        /// The returned box is in Points.
        /// @since v0.99.5
        /// </summary>
        public CCRect boundingBoxInPixels()
        {
            CCRect rect = new CCRect(0, 0, this._contentSizeInPixels.Width, this._contentSizeInPixels.Height);

            return(CCAffineTransform.CCRectApplyAffineTransform(rect, nodeToParentTransform()));
        }
コード例 #24
0
ファイル: CCNode.cs プロジェクト: eickegao/cocos2d-xna
 public CCAffineTransform ParentToNodeTransform()
 {
     if (m_bIsInverseDirty)
     {
         m_tInverse = CCAffineTransform.CCAffineTransformInvert(NodeToParentTransform());
         m_bIsInverseDirty = false;
     }
     return m_tInverse;
 }
コード例 #25
0
        public static CCAffineTransform CCAffineTransformInvert(CCAffineTransform t)
        {
            float single = 1f / (t.a * t.d - t.b * t.c);

            return(CCAffineTransform.CCAffineTransformMake(single * t.d, -single * t.b, -single * t.c, single * t.a, single * (t.c * t.ty - t.d * t.tx), single * (t.b * t.tx - t.a * t.ty)));
        }
コード例 #26
0
ファイル: Node.cs プロジェクト: liwq-net/liwq718
        /// <summary>
        /// Returns the matrix that transform parent's space coordinates to the node's (local) space coordinates.
        /// The matrix is in Pixels.
        /// @since v0.7.1
        /// </summary>
        public CCAffineTransform parentToNodeTransform()
        {
            if (_isInverseDirty)
            {
                _inverse = CCAffineTransform.CCAffineTransformInvert(this.nodeToParentTransform());
                _isInverseDirty = false;
            }

            return _inverse;
        }
コード例 #27
0
ファイル: CCNode.cs プロジェクト: eickegao/cocos2d-xna
        public CCNode()
        {
            m_fScaleX = 1.0f;
            m_fScaleY = 1.0f;
            m_bIsVisible = true;
            m_nTag = kCCNodeTagInvalid;

            m_tTransform = CCAffineTransform.Identity;
            m_bIsInverseDirty = true;

            // set default scheduler and actionManager
            CCDirector director = CCDirector.SharedDirector;
            m_pActionManager = director.ActionManager;
            m_pScheduler = director.Scheduler;
        }
コード例 #28
0
 public static CCAffineTransform CCAffineTransformConcat(CCAffineTransform t1, CCAffineTransform t2)
 {
     return(CCAffineTransform.CCAffineTransformMake(t1.a * t2.a + t1.b * t2.c, t1.a * t2.b + t1.b * t2.d, t1.c * t2.a + t1.d * t2.c, t1.c * t2.b + t1.d * t2.d, t1.tx * t2.a + t1.ty * t2.c + t2.tx, t1.tx * t2.b + t1.ty * t2.d + t2.ty));
 }
コード例 #29
0
ファイル: Box2DTest.cs プロジェクト: eickegao/cocos2d-xna
        public override CCAffineTransform NodeToParentTransform()
        {
            b2Vec2 pos = m_pBody.Position;

            float x = pos.x * Box2DTestLayer.PTM_RATIO;
            float y = pos.y * Box2DTestLayer.PTM_RATIO;

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

            // Make matrix
            float radians = m_pBody.Angle;
            var c = (float)Math.Cos(radians);
            var s = (float)Math.Sin(radians);

            if (!m_tAnchorPointInPoints.Equals(CCPoint.Zero))
            {
                x += c * -m_tAnchorPointInPoints.X + -s * -m_tAnchorPointInPoints.Y;
                y += s * -m_tAnchorPointInPoints.X + c * -m_tAnchorPointInPoints.Y;
            }

            // Rot, Translate Matrix
            m_tTransform = new CCAffineTransform(c, s,
                                                 -s, c,
                                                 x, y);

            return m_tTransform;
        }
コード例 #30
0
 public static CCAffineTransform CCAffineTransformMakeIdentity()
 {
     return(CCAffineTransform.CCAffineTransformMake(1f, 0f, 0f, 1f, 0f, 0f));
 }
コード例 #31
0
ファイル: CCSprite.cs プロジェクト: chengcong/cocos2d-xna
 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;
         }
     }
 }
コード例 #32
0
 public static CCAffineTransform CCAffineTransformTranslate(CCAffineTransform t, float tx, float ty)
 {
     return(CCAffineTransform.CCAffineTransformMake(t.a, t.b, t.c, t.d, t.tx + t.a * tx + t.c * ty, t.ty + t.b * tx + t.d * ty));
 }
コード例 #33
0
 /// <summary>
 ///  Return true if `t1' and `t2' are equal, false otherwise.
 /// </summary>
 public static bool CCAffineTransformEqualToTransform(CCAffineTransform t1, CCAffineTransform t2)
 {
     return(t1.a == t2.a && t1.b == t2.b && t1.c == t2.c && t1.d == t2.d && t1.tx == t2.tx && t1.ty == t2.ty);
 }
コード例 #34
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;
        }
コード例 #35
0
 /// <summary>
 ///  Return true if `t1' and `t2' are equal, false otherwise. 
 /// </summary>
 public static bool CCAffineTransformEqualToTransform(CCAffineTransform t1, CCAffineTransform t2)
 {
     return (t1.a == t2.a && t1.b == t2.b && t1.c == t2.c && t1.d == t2.d && t1.tx == t2.tx && t1.ty == t2.ty);
 }
コード例 #36
0
        public static CCAffineTransform CCAffineTransformRotate(CCAffineTransform t, float anAngle)
        {
            var fSin = (float) Math.Sin(anAngle);
            var fCos = (float) Math.Cos(anAngle);

            return new CCAffineTransform(t.a * fCos + t.c * fSin,
                                         t.b * fCos + t.d * fSin,
                                         t.c * fCos - t.a * fSin,
                                         t.d * fCos - t.b * fSin,
                                         t.tx,
                                         t.ty);
        }
コード例 #37
0
 public static Matrix CGAffineToMatrix(CCAffineTransform t)
 {
     var m = new float[16];
     CGAffineToGL(t, ref m);
     return CGAffineToMatrix(m);
 }
コード例 #38
0
 public static CCAffineTransform CCAffineTransformTranslate(CCAffineTransform t, float tx, float ty)
 {
     return new CCAffineTransform(t.a, t.b, t.c, t.d, t.tx + t.a * tx + t.c * ty, t.ty + t.b * tx + t.d * ty);
 }
コード例 #39
0
 public static void GLToCGAffine(float[] m, CCAffineTransform t)
 {
     t.a = m[0]; t.c = m[4]; t.tx = m[12];
     t.b = m[1]; t.d = m[5]; t.ty = m[13];
 }
コード例 #40
0
 public void Concat(CCAffineTransform m)
 {
     Concat(ref m);
 }
コード例 #41
0
 public static Matrix CGAffineToMatrix(CCAffineTransform t)
 {
     float[] m = new float[16];
     CGAffineToGL(t, ref m);
     return(CGAffineToMatrix(m));
 }
コード例 #42
0
ファイル: CCNode.cs プロジェクト: chengcong/cocos2d-xna
        public CCRect boundingBoxInPixels()
        {
            CCRect rect = new CCRect(0f, 0f, this.m_tContentSizeInPixels.width, this.m_tContentSizeInPixels.height);

            return(CCAffineTransform.CCRectApplyAffineTransform(rect, this.nodeToParentTransform()));
        }
コード例 #43
0
ファイル: CCNode.cs プロジェクト: eickegao/cocos2d-xna
        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;
        }
コード例 #44
0
 /// <summary>
 /// Concatenate `t2' to `t1' and return the result:
 /// t' = t1 * t2 */s
 /// </summary>
 /// <param name="t1"></param>
 /// <param name="t2"></param>
 /// <returns></returns>
 public static CCAffineTransform CCAffineTransformConcat(CCAffineTransform t1, CCAffineTransform t2)
 {
     return(CCAffineTransformMake(t1.a * t2.a + t1.b * t2.c, t1.a * t2.b + t1.b * t2.d, //a,b
                                  t1.c * t2.a + t1.d * t2.c, t1.c * t2.b + t1.d * t2.d, //c,d
                                  t1.tx * t2.a + t1.ty * t2.c + t2.tx,                  //tx
                                  t1.tx * t2.b + t1.ty * t2.d + t2.ty));                //ty
 }
コード例 #45
0
ファイル: CCAffineTransform.cs プロジェクト: liwq-net/liwq718
        public static CCRect CCRectApplyAffineTransform(CCRect rect, CCAffineTransform anAffineTransform)
        {
            float top = rect.MinY;
            float left = rect.MinX;
            float right = rect.MaxX;
            float bottom = rect.MaxY;

            CCPoint topLeft = CCPointApplyAffineTransform(new CCPoint(left, top), anAffineTransform);
            CCPoint topRight = CCPointApplyAffineTransform(new CCPoint(right, top), anAffineTransform);
            CCPoint bottomLeft = CCPointApplyAffineTransform(new CCPoint(left, bottom), anAffineTransform);
            CCPoint bottomRight = CCPointApplyAffineTransform(new CCPoint(right, bottom), anAffineTransform);

            float minX = Math.Min(Math.Min(topLeft.X, topRight.X), Math.Min(bottomLeft.X, bottomRight.X));
            float maxX = Math.Max(Math.Max(topLeft.X, topRight.X), Math.Max(bottomLeft.X, bottomRight.X));
            float minY = Math.Min(Math.Min(topLeft.Y, topRight.Y), Math.Min(bottomLeft.Y, bottomRight.Y));
            float maxY = Math.Max(Math.Max(topLeft.Y, topRight.Y), Math.Max(bottomLeft.Y, bottomRight.Y));

            return new CCRect(minX, minY, (maxX - minX), (maxY - minY));
        }