Пример #1
0
        /// <summary>
        /// Converts a Point to node (local) space coordinates. The result is in Points.
        /// @since v0.7.1
        /// </summary>
        public CCPoint convertToNodeSpace(CCPoint worldPoint)
        {
            CCPoint ret;

            if (CCDirector.sharedDirector().ContentScaleFactor == 1)
            {
                ret = CCAffineTransform.CCPointApplyAffineTransform(worldPoint, worldToNodeTransform());
            }
            else
            {
                ret = CCPointExtension.ccpMult(worldPoint, CCDirector.sharedDirector().ContentScaleFactor);
                ret = CCAffineTransform.CCPointApplyAffineTransform(ret, worldToNodeTransform());
                ret = CCPointExtension.ccpMult(ret, 1 / CCDirector.sharedDirector().ContentScaleFactor);
            }

            return(ret);
        }
Пример #2
0
        /// <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 && !m_tAnchorPointInPixels.IsZero)
                {
                    m_tTransform = CCAffineTransform.CCAffineTransformTranslate(m_tTransform, m_tAnchorPointInPixels.x, m_tAnchorPointInPixels.y);
                }

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

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

                if (m_fSkewX != 0f || m_fSkewY != 0f)
                {
                    // 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 == 1f && m_fScaleY == 1f))
                {
                    m_tTransform = CCAffineTransform.CCAffineTransformScale(m_tTransform, m_fScaleX, m_fScaleY);
                }

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

                m_bIsTransformDirty = false;
            }

            return(m_tTransform);
        }
Пример #3
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)));
        }
Пример #4
0
 public static CCAffineTransform CCAffineTransformTranslate(CCAffineTransform t, float tx, float ty)
 {
     return(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));
 }
Пример #5
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);
 }
Пример #6
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
 }
Пример #7
0
 public static CCAffineTransform CCAffineTransformScale(CCAffineTransform t, float sx, float sy)
 {
     return(CCAffineTransformMake(t.a * sx, t.b * sx, t.c * sy, t.d * sy, t.tx, t.ty));
 }
Пример #8
0
 /// <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()));
 }
Пример #9
0
        /// <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, m_tContentSizeInPixels.width, m_tContentSizeInPixels.height);

            return(CCAffineTransform.CCRectApplyAffineTransform(rect, nodeToParentTransform()));
        }
Пример #10
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];
 }
Пример #11
0
 public static Matrix4x4 CGAffineToMatrix(CCAffineTransform t)
 {
     float[] m = new float[16];
     CGAffineToGL(t, ref m);
     return(CGAffineToMatrix(m));
 }