Example #1
0
        public override CCFiniteTimeAction reverse()
        {
            ccBezierConfig _ccBezierConfig = new ccBezierConfig();

            _ccBezierConfig.endPosition    = CCPointExtension.ccpNeg(this.m_sConfig.endPosition);
            _ccBezierConfig.controlPoint_1 = CCPointExtension.ccpAdd(this.m_sConfig.controlPoint_2, CCPointExtension.ccpNeg(this.m_sConfig.endPosition));
            _ccBezierConfig.controlPoint_2 = CCPointExtension.ccpAdd(this.m_sConfig.controlPoint_1, CCPointExtension.ccpNeg(this.m_sConfig.endPosition));
            return(CCBezierBy.actionWithDuration(this.m_fDuration, _ccBezierConfig));
        }
Example #2
0
        protected override void updateColor()
        {
            base.updateColor();
            float single = CCPointExtension.ccpLength(this.m_AlongVector);

            if (single == 0f)
            {
                return;
            }
            double  num     = Math.Sqrt(2);
            CCPoint cCPoint = new CCPoint(this.m_AlongVector.x / single, this.m_AlongVector.y / single);

            if (this.m_bCompressedInterpolation)
            {
                float single1 = 1f / (Math.Abs(cCPoint.x) + Math.Abs(cCPoint.y));
                cCPoint = CCPointExtension.ccpMult(cCPoint, single1 * (float)num);
            }
            float     mCOpacity  = (float)this.m_cOpacity / 255f;
            ccColor4B _ccColor4B = new ccColor4B()
            {
                r = this.m_tColor.r,
                g = this.m_tColor.g,
                b = this.m_tColor.b,
                a = (byte)((float)this.m_cStartOpacity * mCOpacity)
            };
            ccColor4B _ccColor4B1 = _ccColor4B;
            ccColor4B _ccColor4B2 = new ccColor4B()
            {
                r = this.m_endColor.r,
                g = this.m_endColor.g,
                b = this.m_endColor.b,
                a = (byte)((float)this.m_cEndOpacity * mCOpacity)
            };
            ccColor4B _ccColor4B3 = _ccColor4B2;

            this.m_pSquareColors[0].r = (byte)((double)_ccColor4B3.r + (double)(_ccColor4B1.r - _ccColor4B3.r) * ((num + (double)cCPoint.x + (double)cCPoint.y) / (2 * num)));
            this.m_pSquareColors[0].g = (byte)((double)_ccColor4B3.g + (double)(_ccColor4B1.g - _ccColor4B3.g) * ((num + (double)cCPoint.x + (double)cCPoint.y) / (2 * num)));
            this.m_pSquareColors[0].b = (byte)((double)_ccColor4B3.b + (double)(_ccColor4B1.b - _ccColor4B3.b) * ((num + (double)cCPoint.x + (double)cCPoint.y) / (2 * num)));
            this.m_pSquareColors[0].a = (byte)((double)_ccColor4B3.a + (double)(_ccColor4B1.a - _ccColor4B3.a) * ((num + (double)cCPoint.x + (double)cCPoint.y) / (2 * num)));
            this.m_pSquareColors[1].r = (byte)((double)_ccColor4B3.r + (double)(_ccColor4B1.r - _ccColor4B3.r) * ((num - (double)cCPoint.x + (double)cCPoint.y) / (2 * num)));
            this.m_pSquareColors[1].g = (byte)((double)_ccColor4B3.g + (double)(_ccColor4B1.g - _ccColor4B3.g) * ((num - (double)cCPoint.x + (double)cCPoint.y) / (2 * num)));
            this.m_pSquareColors[1].b = (byte)((double)_ccColor4B3.b + (double)(_ccColor4B1.b - _ccColor4B3.b) * ((num - (double)cCPoint.x + (double)cCPoint.y) / (2 * num)));
            this.m_pSquareColors[1].a = (byte)((double)_ccColor4B3.a + (double)(_ccColor4B1.a - _ccColor4B3.a) * ((num - (double)cCPoint.x + (double)cCPoint.y) / (2 * num)));
            this.m_pSquareColors[2].r = (byte)((double)_ccColor4B3.r + (double)(_ccColor4B1.r - _ccColor4B3.r) * ((num + (double)cCPoint.x - (double)cCPoint.y) / (2 * num)));
            this.m_pSquareColors[2].g = (byte)((double)_ccColor4B3.g + (double)(_ccColor4B1.g - _ccColor4B3.g) * ((num + (double)cCPoint.x - (double)cCPoint.y) / (2 * num)));
            this.m_pSquareColors[2].b = (byte)((double)_ccColor4B3.b + (double)(_ccColor4B1.b - _ccColor4B3.b) * ((num + (double)cCPoint.x - (double)cCPoint.y) / (2 * num)));
            this.m_pSquareColors[2].a = (byte)((double)_ccColor4B3.a + (double)(_ccColor4B1.a - _ccColor4B3.a) * ((num + (double)cCPoint.x - (double)cCPoint.y) / (2 * num)));
            this.m_pSquareColors[3].r = (byte)((double)_ccColor4B3.r + (double)(_ccColor4B1.r - _ccColor4B3.r) * ((num - (double)cCPoint.x - (double)cCPoint.y) / (2 * num)));
            this.m_pSquareColors[3].g = (byte)((double)_ccColor4B3.g + (double)(_ccColor4B1.g - _ccColor4B3.g) * ((num - (double)cCPoint.x - (double)cCPoint.y) / (2 * num)));
            this.m_pSquareColors[3].b = (byte)((double)_ccColor4B3.b + (double)(_ccColor4B1.b - _ccColor4B3.b) * ((num - (double)cCPoint.x - (double)cCPoint.y) / (2 * num)));
            this.m_pSquareColors[3].a = (byte)((double)_ccColor4B3.a + (double)(_ccColor4B1.a - _ccColor4B3.a) * ((num - (double)cCPoint.x - (double)cCPoint.y) / (2 * num)));
            this.vertices[0].Color    = new Microsoft.Xna.Framework.Color((int)this.m_pSquareColors[0].r, (int)this.m_pSquareColors[0].g, (int)this.m_pSquareColors[0].b, (int)this.m_pSquareColors[0].a);
            this.vertices[1].Color    = new Microsoft.Xna.Framework.Color((int)this.m_pSquareColors[1].r, (int)this.m_pSquareColors[1].g, (int)this.m_pSquareColors[1].b, (int)this.m_pSquareColors[1].a);
            this.vertices[2].Color    = new Microsoft.Xna.Framework.Color((int)this.m_pSquareColors[2].r, (int)this.m_pSquareColors[2].g, (int)this.m_pSquareColors[2].b, (int)this.m_pSquareColors[2].a);
            this.vertices[3].Color    = new Microsoft.Xna.Framework.Color((int)this.m_pSquareColors[3].r, (int)this.m_pSquareColors[3].g, (int)this.m_pSquareColors[3].b, (int)this.m_pSquareColors[3].a);
        }
        public static float ccpAngle(CCPoint a, CCPoint b)
        {
            float single = (float)Math.Acos((double)CCPointExtension.ccpDot(CCPointExtension.ccpNormalize(a), CCPointExtension.ccpNormalize(b)));

            if (Math.Abs(single) < ccMacros.FLT_EPSILON)
            {
                return(0f);
            }
            return(single);
        }
        public static CCPoint ccpRotateByAngle(CCPoint v, CCPoint pivot, float angle)
        {
            CCPoint cCPoint = CCPointExtension.ccpSub(v, pivot);
            float   single  = (float)Math.Cos((double)angle);
            float   single1 = (float)Math.Sin((double)angle);
            float   single2 = cCPoint.x;

            cCPoint = CCPointExtension.ccp(single2 * single - cCPoint.y * single1 + pivot.x, single2 * single1 + cCPoint.y * single + pivot.y);
            return(cCPoint);
        }
        public static bool ccpSegmentIntersect(CCPoint A, CCPoint B, CCPoint C, CCPoint D)
        {
            float single  = 0f;
            float single1 = 0f;

            if (CCPointExtension.ccpLineIntersect(A, B, C, D, ref single, ref single1) && single >= 0f && single <= 1f && single1 >= 0f && single1 <= 1f)
            {
                return(true);
            }
            return(false);
        }
Example #6
0
        public bool initWithTarget(CCNode followedNode)
        {
            this.m_pobFollowedNode       = followedNode;
            this.m_bBoundarySet          = false;
            this.m_bBoundaryFullyCovered = false;
            CCSize size = CCDirector.sharedDirector().getWinSize();

            this.m_obFullScreenSize = new CCPoint(size.width, size.height);
            this.m_obHalfScreenSize = CCPointExtension.ccpMult(this.m_obFullScreenSize, 0.5f);
            return(true);
        }
Example #7
0
 public override void update(float dt)
 {
     if (this.m_pTarget != null)
     {
         float single  = dt * (float)((float)this.m_nJumps) % 1f;
         float mHeight = this.m_height * 4f * single * (1f - single);
         mHeight = mHeight + this.m_delta.y * dt;
         float mDelta = this.m_delta.x * dt;
         this.m_pTarget.position = CCPointExtension.ccp(this.m_startPosition.x + mDelta, this.m_startPosition.y + mHeight);
     }
 }
        public static float ccpAngleSigned(CCPoint a, CCPoint b)
        {
            CCPoint cCPoint  = CCPointExtension.ccpNormalize(a);
            CCPoint cCPoint1 = CCPointExtension.ccpNormalize(b);
            float   single   = (float)Math.Atan2((double)(cCPoint.x * cCPoint1.y - cCPoint.y * cCPoint1.x), (double)CCPointExtension.ccpDot(cCPoint, cCPoint1));

            if (Math.Abs(single) < ccMacros.FLT_EPSILON)
            {
                return(0f);
            }
            return(single);
        }
Example #9
0
        public virtual bool init()
        {
            m_bDirty = m_bRecursiveDirty = false;

            // by default use "Self Render".
            // if the sprite is added to an batchnode, then it will automatically switch to "SpriteSheet Render"
            useSelfRender();

            m_bOpacityModifyRGB = true;
            m_nOpacity          = 255;
            m_sColor            = new ccColor3B(255, 255, 255);
            m_sColorUnmodified  = new ccColor3B(255, 255, 255);

            m_sBlendFunc     = new ccBlendFunc();
            m_sBlendFunc.src = ccMacros.CC_BLEND_SRC;
            m_sBlendFunc.dst = ccMacros.CC_BLEND_DST;


            // update texture (calls updateBlendFunc)
            Texture = null;

            // clean the Quad
            m_sQuad = new ccV3F_C4B_T2F_Quad();

            m_bFlipX = m_bFlipY = false;

            // default transform anchor: center
            anchorPoint = (CCPointExtension.ccp(0.5f, 0.5f));

            // zwoptex default values
            m_obOffsetPositionInPixels = new CCPoint();

            m_eHonorParentTransform = ccHonorParentTransform.CC_HONOR_PARENT_TRANSFORM_ALL;
            m_bHasChildren          = false;

            // Atlas: Color
            ccColor4B tmpColor = new ccColor4B(255, 255, 255, 255);

            m_sQuad.bl.colors = tmpColor;
            m_sQuad.br.colors = tmpColor;
            m_sQuad.tl.colors = tmpColor;
            m_sQuad.tr.colors = tmpColor;

            // Atlas: Vertex

            // updated in "useSelfRender"

            // Atlas: TexCoords

            setTextureRectInPixels(new CCRect(), false, new CCSize());

            return(true);
        }
Example #10
0
        public override CCFiniteTimeAction reverse()
        {
            ccBezierConfig r;

            r.endPosition    = CCPointExtension.ccpNeg(m_sConfig.endPosition);
            r.controlPoint_1 = CCPointExtension.ccpAdd(m_sConfig.controlPoint_2, CCPointExtension.ccpNeg(m_sConfig.endPosition));
            r.controlPoint_2 = CCPointExtension.ccpAdd(m_sConfig.controlPoint_1, CCPointExtension.ccpNeg(m_sConfig.endPosition));

            CCBezierBy action = CCBezierBy.actionWithDuration(m_fDuration, r);

            return(action);
        }
Example #11
0
 public override void Update(float dt)
 {
     if (Target != null)
     {
         // Is % equal to fmodf()???
         float frac = (dt * m_nJumps) % 1.0f;
         float y    = m_height * 4 * frac * (1 - frac);
         y += m_delta.Y * dt;
         float x = m_delta.X * dt;
         Target.Position = CCPointExtension.ccp(m_startPosition.X + x, m_startPosition.Y + y);
     }
 }
Example #12
0
        public CCPoint convertToNodeSpaceAR(CCPoint worldPoint)
        {
            CCPoint tAnchorPointInPixels;
            CCPoint point = this.convertToNodeSpace(worldPoint);

            if (CCDirector.sharedDirector().ContentScaleFactor == 1f)
            {
                tAnchorPointInPixels = this.m_tAnchorPointInPixels;
            }
            else
            {
                tAnchorPointInPixels = CCPointExtension.ccpMult(this.m_tAnchorPointInPixels, 1f / CCDirector.sharedDirector().ContentScaleFactor);
            }
            return(CCPointExtension.ccpSub(point, tAnchorPointInPixels));
        }
Example #13
0
 public override void step(float dt)
 {
     if (this.m_bBoundarySet)
     {
         if (!this.m_bBoundaryFullyCovered)
         {
             CCPoint point = CCPointExtension.ccpSub(this.m_obHalfScreenSize, this.m_pobFollowedNode.position);
             base.m_pTarget.position = CCPointExtension.ccp(CCPointExtension.clampf(point.x, this.m_fLeftBoundary, this.m_fRightBoundary), CCPointExtension.clampf(point.y, this.m_fBottomBoundary, this.m_fTopBoundary));
         }
     }
     else
     {
         base.m_pTarget.position = CCPointExtension.ccpSub(this.m_obHalfScreenSize, this.m_pobFollowedNode.position);
     }
 }
Example #14
0
        public bool initWithTarget(CCNode followedNode)
        {
            Debug.Assert(followedNode != null);

            m_pobFollowedNode       = followedNode;
            m_bBoundarySet          = false;
            m_bBoundaryFullyCovered = false;

            CCSize winSize = CCDirector.sharedDirector().getWinSize();

            m_obFullScreenSize = new CCPoint(winSize.width, winSize.height);
            m_obHalfScreenSize = CCPointExtension.ccpMult(m_obFullScreenSize, 0.5f);

            return(true);
        }
Example #15
0
        public CCPoint convertToWorldSpaceAR(CCPoint nodePoint)
        {
            CCPoint tAnchorPointInPixels;

            if (CCDirector.sharedDirector().ContentScaleFactor == 1f)
            {
                tAnchorPointInPixels = this.m_tAnchorPointInPixels;
            }
            else
            {
                tAnchorPointInPixels = CCPointExtension.ccpMult(this.m_tAnchorPointInPixels, 1f / CCDirector.sharedDirector().ContentScaleFactor);
            }
            CCPoint point2 = CCPointExtension.ccpAdd(nodePoint, tAnchorPointInPixels);

            return(this.convertToWorldSpace(point2));
        }
Example #16
0
        /// <summary>
        /// Converts a Point to node (local) space coordinates. The result is in Points.
        /// treating the returned/received node point as anchor relative.
        /// </summary>
        public CCPoint ConvertToNodeSpaceAR(CCPoint worldPoint)
        {
            CCPoint nodePoint = ConvertToNodeSpace(worldPoint);
            CCPoint anchorInPoints;

            if (Director.SharedDirector.ContentScaleFactor == 1)
            {
                anchorInPoints = AnchorPointInPixels;
            }
            else
            {
                anchorInPoints = CCPointExtension.ccpMult(AnchorPointInPixels, 1 / Director.SharedDirector.ContentScaleFactor);
            }

            return(CCPointExtension.ccpSub(nodePoint, anchorInPoints));
        }
Example #17
0
        public static CCPoint ccpIntersectPoint(CCPoint A, CCPoint B, CCPoint C, CCPoint D)
        {
            float single  = 0f;
            float single1 = 0f;

            if (!CCPointExtension.ccpLineIntersect(A, B, C, D, ref single, ref single1))
            {
                return(new CCPoint());
            }
            CCPoint cCPoint = new CCPoint()
            {
                x = A.x + single * (B.x - A.x),
                y = A.y + single * (B.y - A.y)
            };

            return(cCPoint);
        }
Example #18
0
        /// <summary>Converts a Point to world space coordinates. The result is in Points.</summary>
        public CCPoint ConvertToWorldSpace(CCPoint nodePoint)
        {
            CCPoint ret;

            if (Director.SharedDirector.ContentScaleFactor == 1)
            {
                ret = CCAffineTransform.CCPointApplyAffineTransform(nodePoint, nodeToWorldTransform());
            }
            else
            {
                ret = CCPointExtension.ccpMult(nodePoint, Director.SharedDirector.ContentScaleFactor);
                ret = CCAffineTransform.CCPointApplyAffineTransform(ret, nodeToWorldTransform());
                ret = CCPointExtension.ccpMult(ret, 1 / Director.SharedDirector.ContentScaleFactor);
            }

            return(ret);
        }
Example #19
0
 public override void update(float dt)
 {
     if (this.m_pTarget != null)
     {
         float single         = 0f;
         float controlPoint1  = this.m_sConfig.controlPoint_1.x;
         float controlPoint2  = this.m_sConfig.controlPoint_2.x;
         float mSConfig       = this.m_sConfig.endPosition.x;
         float single1        = 0f;
         float controlPoint11 = this.m_sConfig.controlPoint_1.y;
         float controlPoint21 = this.m_sConfig.controlPoint_2.y;
         float mSConfig1      = this.m_sConfig.endPosition.y;
         float single2        = this.bezierat(single, controlPoint1, controlPoint2, mSConfig, dt);
         float single3        = this.bezierat(single1, controlPoint11, controlPoint21, mSConfig1, dt);
         this.m_pTarget.position = CCPointExtension.ccpAdd(this.m_startPosition, CCPointExtension.ccp(single2, single3));
     }
 }
Example #20
0
        /// <summary>
        /// Converts a local Point to world space coordinates.The result is in Points.
        /// treating the returned/received node point as anchor relative.
        /// </summary>
        public CCPoint ConvertToWorldSpaceAR(CCPoint nodePoint)
        {
            CCPoint anchorInPoints;

            if (Director.SharedDirector.ContentScaleFactor == 1)
            {
                anchorInPoints = AnchorPointInPixels;
            }
            else
            {
                anchorInPoints = CCPointExtension.ccpMult(AnchorPointInPixels, 1 / Director.SharedDirector.ContentScaleFactor);
            }

            CCPoint pt = CCPointExtension.ccpAdd(nodePoint, anchorInPoints);

            return(ConvertToWorldSpace(pt));
        }
Example #21
0
        public override void step(float dt)
        {
            if (m_bBoundarySet)
            {
                // whole map fits inside a single screen, no need to modify the position - unless map boundaries are increased
                if (m_bBoundaryFullyCovered)
                {
                    return;
                }

                CCPoint tempPos = CCPointExtension.ccpSub(m_obHalfScreenSize, m_pobFollowedNode.position);
                m_pTarget.position = CCPointExtension.ccp(CCPointExtension.clampf(tempPos.x, m_fLeftBoundary, m_fRightBoundary),
                                                          CCPointExtension.clampf(tempPos.y, m_fBottomBoundary, m_fTopBoundary));
            }
            else
            {
                m_pTarget.position = CCPointExtension.ccpSub(m_obHalfScreenSize, m_pobFollowedNode.position);
            }
        }
Example #22
0
        public override void update(float dt)
        {
            if (m_pTarget != null)
            {
                float xa = 0;
                float xb = m_sConfig.controlPoint_1.x;
                float xc = m_sConfig.controlPoint_2.x;
                float xd = m_sConfig.endPosition.x;

                float ya = 0;
                float yb = m_sConfig.controlPoint_1.y;
                float yc = m_sConfig.controlPoint_2.y;
                float yd = m_sConfig.endPosition.y;

                float x = bezierat(xa, xb, xc, xd, dt);
                float y = bezierat(ya, yb, yc, yd, dt);
                m_pTarget.position = CCPointExtension.ccpAdd(m_startPosition, CCPointExtension.ccp(x, y));
            }
        }
Example #23
0
        public override void Update(float time)
        {
            if (m_bDirty)
            {
                int i, j;

                for (i = 0; i < m_sGridSize.x + 1; ++i)
                {
                    for (j = 0; j < m_sGridSize.y + 1; ++j)
                    {
                        ccVertex3F v    = originalVertex(new ccGridSize(i, j));
                        CCPoint    vect = new CCPoint(m_positionInPixels.X - new CCPoint(v.x, v.y).X, m_positionInPixels.Y - new CCPoint(v.x, v.y).Y);
                        float      r    = CCPointExtension.ccpLength(vect);

                        if (r < m_fRadius)
                        {
                            r = m_fRadius - r;
                            float pre_log = r / m_fRadius;
                            if (pre_log == 0)
                            {
                                pre_log = 0.001f;
                            }

                            float l     = (float)Math.Log(pre_log) * m_fLensEffect;
                            float new_r = (float)Math.Exp(l) * m_fRadius;

                            if (Math.Sqrt((vect.X * vect.X + vect.Y * vect.Y)) > 0)
                            {
                                vect = CCPointExtension.ccpNormalize(vect);

                                CCPoint new_vect = CCPointExtension.ccpMult(vect, new_r);;
                                v.z += CCPointExtension.ccpLength(new_vect) * m_fLensEffect;
                            }
                        }

                        setVertex(new ccGridSize(i, j), v);
                    }
                }

                m_bDirty = false;
            }
        }
Example #24
0
 public override void update(float time)
 {
     for (int i = 0; i < this.m_sGridSize.x + 1; i++)
     {
         for (int j = 0; j < this.m_sGridSize.y + 1; j++)
         {
             ccVertex3F _ccVertex3F = base.originalVertex(new ccGridSize(i, j));
             CCPoint    cCPoint     = CCPointExtension.ccpSub(this.m_positionInPixels, new CCPoint(_ccVertex3F.x, _ccVertex3F.y));
             float      mFRadius    = (float)Math.Sqrt((double)(cCPoint.x * cCPoint.x + cCPoint.y * cCPoint.y));
             if (mFRadius < this.m_fRadius)
             {
                 mFRadius = this.m_fRadius - mFRadius;
                 float      single       = (float)Math.Pow((double)(mFRadius / this.m_fRadius), 2);
                 ccVertex3F _ccVertex3F1 = _ccVertex3F;
                 _ccVertex3F1.z = _ccVertex3F1.z + (float)Math.Sin((double)(time * 3.14159274f * (float)this.m_nWaves * 2f + mFRadius * 0.1f)) * this.m_fAmplitude * this.m_fAmplitudeRate * single;
             }
             base.setVertex(new ccGridSize(i, j), _ccVertex3F);
         }
     }
 }
Example #25
0
        public bool initWithTarget(CCNode followedNode, CCRect rect)
        {
            Debug.Assert(followedNode != null);

            m_pobFollowedNode       = followedNode;
            m_bBoundarySet          = true;
            m_bBoundaryFullyCovered = false;

            CCSize winSize = CCDirector.sharedDirector().getWinSize();

            m_obFullScreenSize = new CCPoint(winSize.width, winSize.height);
            m_obHalfScreenSize = CCPointExtension.ccpMult(m_obFullScreenSize, 0.5f);

            m_fLeftBoundary   = -((rect.origin.x + rect.size.width) - m_obFullScreenSize.x);
            m_fRightBoundary  = -rect.origin.x;
            m_fLeftBoundary   = -rect.origin.y;
            m_fBottomBoundary = -((rect.origin.y + rect.size.height) - m_obFullScreenSize.y);

            if (m_fRightBoundary < m_fLeftBoundary)
            {
                // screen width is larger than world's boundary width
                //set both in the middle of the world
                m_fRightBoundary = m_fLeftBoundary = (m_fLeftBoundary + m_fRightBoundary) / 2;
            }
            if (m_fTopBoundary < m_fBottomBoundary)
            {
                // screen width is larger than world's boundary width
                //set both in the middle of the world
                m_fTopBoundary = m_fBottomBoundary = (m_fTopBoundary + m_fBottomBoundary) / 2;
            }

            if ((m_fTopBoundary == m_fBottomBoundary) && (m_fLeftBoundary == m_fRightBoundary))
            {
                m_bBoundaryFullyCovered = true;
            }

            return(true);
        }
Example #26
0
        public override void update(float time)
        {
            int i, j;

            for (i = 0; i < (m_sGridSize.x + 1); ++i)
            {
                for (j = 0; j < (m_sGridSize.y + 1); ++j)
                {
                    ccVertex3F v    = originalVertex(new ccGridSize(i, j));
                    CCPoint    vect = CCPointExtension.ccpSub(m_positionInPixels, new CCPoint(v.x, v.y));
                    float      r    = (float)Math.Sqrt((vect.x * vect.x + vect.y * vect.y));

                    if (r < m_fRadius)
                    {
                        r = m_fRadius - r;
                        float rate = (float)Math.Pow(r / m_fRadius, 2);
                        v.z += ((float)Math.Sin(time * (float)Math.PI * m_nWaves * 2 + r * 0.1f) * m_fAmplitude * m_fAmplitudeRate * rate);
                    }

                    setVertex(new ccGridSize(i, j), v);
                }
            }
        }
Example #27
0
 public CCScene()
 {
     isRelativeAnchorPoint = false;
     anchorPoint           = CCPointExtension.ccp(0.5f, 0.5f);
     m_eSceneType          = ccSceneFlag.ccNormalScene;
 }
Example #28
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
        }
Example #29
0
 public CCLayer()
 {
     AnchorPoint           = CCPointExtension.ccp(0.5f, 0.5f);
     IsRelativeAnchorPoint = false;
 }
Example #30
0
        public override void update(float dt)
        {
            if (this.m_bIsActive && (this.m_fEmissionRate != 0f))
            {
                float num = 1f / this.m_fEmissionRate;
                this.m_fEmitCounter += dt;
                while ((this.m_uParticleCount < this.m_uTotalParticles) && (this.m_fEmitCounter > num))
                {
                    this.addParticle();
                    this.m_fEmitCounter -= num;
                }
                this.m_fElapsed += dt;
                if ((this.m_fDuration != -1f) && (this.m_fDuration < this.m_fElapsed))
                {
                    this.stopSystem();
                }
            }
            this.m_uParticleIdx = 0;
            CCPoint tPosition = new CCPoint(0f, 0f);

            if (this.m_ePositionType == eParticlePositionType.kCCPositionTypeFree)
            {
                tPosition    = base.convertToWorldSpace(new CCPoint(0f, 0f));
                tPosition.x *= CCDirector.sharedDirector().ContentScaleFactor;
                tPosition.y *= CCDirector.sharedDirector().ContentScaleFactor;
            }
            else if (this.m_ePositionType == eParticlePositionType.kCCPositionTypeRelative)
            {
                tPosition    = base.m_tPosition;
                tPosition.x *= CCDirector.sharedDirector().ContentScaleFactor;
                tPosition.y *= CCDirector.sharedDirector().ContentScaleFactor;
            }
            while (this.m_uParticleIdx < this.m_uParticleCount)
            {
                CCParticle particle = this.m_pParticles[this.m_uParticleIdx];
                particle.timeToLive -= dt;
                if (particle.timeToLive > 0f)
                {
                    CCPoint pos;
                    if (this.m_nEmitterMode == 0)
                    {
                        CCPoint v = new CCPoint(0f, 0f);
                        if ((particle.pos.x != 0f) || (particle.pos.y != 0f))
                        {
                            v = CCPointExtension.ccpNormalize(particle.pos);
                        }
                        CCPoint point4 = v;
                        v = CCPointExtension.ccpMult(v, particle.modeA.radialAccel);
                        float x = point4.x;
                        point4.x = -point4.y;
                        point4.y = x;
                        point4   = CCPointExtension.ccpMult(point4, particle.modeA.tangentialAccel);
                        CCPoint point2 = CCPointExtension.ccpMult(CCPointExtension.ccpAdd(CCPointExtension.ccpAdd(v, point4), this.modeA.gravity), dt);
                        particle.modeA.dir = CCPointExtension.ccpAdd(particle.modeA.dir, point2);
                        point2             = CCPointExtension.ccpMult(particle.modeA.dir, dt);
                        particle.pos       = CCPointExtension.ccpAdd(particle.pos, point2);
                    }
                    else
                    {
                        particle.modeB.angle  += particle.modeB.degreesPerSecond * dt;
                        particle.modeB.radius += particle.modeB.deltaRadius * dt;
                        particle.pos.x         = -((float)Math.Cos((double)particle.modeB.angle)) * particle.modeB.radius;
                        particle.pos.y         = -((float)Math.Sin((double)particle.modeB.angle)) * particle.modeB.radius;
                    }
                    particle.color.r  += particle.deltaColor.r * dt;
                    particle.color.g  += particle.deltaColor.g * dt;
                    particle.color.b  += particle.deltaColor.b * dt;
                    particle.color.a  += particle.deltaColor.a * dt;
                    particle.size     += particle.deltaSize * dt;
                    particle.size      = (0f > particle.size) ? 0f : particle.size;
                    particle.rotation += particle.deltaRotation * dt;
                    if ((this.m_ePositionType == eParticlePositionType.kCCPositionTypeFree) || (this.m_ePositionType == eParticlePositionType.kCCPositionTypeRelative))
                    {
                        CCPoint point6 = CCPointExtension.ccpSub(tPosition, particle.startPos);
                        pos = CCPointExtension.ccpSub(particle.pos, point6);
                    }
                    else
                    {
                        pos = particle.pos;
                    }
                    this.updateQuadWithParticle(particle, pos);
                    this.m_uParticleIdx++;
                }
                else
                {
                    if (this.m_uParticleIdx != (this.m_uParticleCount - 1))
                    {
                        this.m_pParticles[this.m_uParticleIdx].copy(this.m_pParticles[(int)((IntPtr)(this.m_uParticleCount - 1))]);
                    }
                    this.m_uParticleCount--;
                    if ((this.m_uParticleCount == 0) && this.m_bIsAutoRemoveOnFinish)
                    {
                        base.unscheduleUpdate();
                        base.m_pParent.removeChild(this, true);
                        return;
                    }
                }
            }
            this.postStep();
        }