void CCTwirl::update(float time) { int i, j; CCPoint c = m_position; for (i = 0; i < (m_sGridSize.width+1); ++i) { for (j = 0; j < (m_sGridSize.height+1); ++j) { ccVertex3F v = originalVertex(ccp(i ,j)); CCPoint avg = ccp(i-(m_sGridSize.width/2.0f), j-(m_sGridSize.height/2.0f)); float r = ccpLength(avg); float amp = 0.1f * m_fAmplitude * m_fAmplitudeRate; float a = r * cosf( (float)M_PI/2.0f + time * (float)M_PI * m_nTwirls * 2 ) * amp; CCPoint d = ccp( sinf(a) * (v.y-c.y) + cosf(a) * (v.x-c.x), cosf(a) * (v.y-c.y) - sinf(a) * (v.x-c.x)); v.x = c.x + d.x; v.y = c.y + d.y; setVertex(ccp(i ,j), v); } } }
void CCTwirl::update(ccTime time) { int i, j; CCPoint c = m_positionInPixels; for (i = 0; i < (m_sGridSize.x+1); ++i) { for (j = 0; j < (m_sGridSize.y+1); ++j) { ccVertex3F v = originalVertex(ccg(i ,j)); CCPoint avg = ccp(i-(m_sGridSize.x/2.0f), j-(m_sGridSize.y/2.0f)); CGFloat r = ccpLength(avg); CGFloat amp = 0.1f * m_fAmplitude * m_fAmplitudeRate; CGFloat a = r * cosf( (CGFloat)M_PI/2.0f + time * (CGFloat)M_PI * m_nTwirls * 2 ) * amp; CCPoint d; d.x = sinf(a) * (v.y-c.y) + cosf(a) * (v.x-c.x); d.y = cosf(a) * (v.y-c.y) - sinf(a) * (v.x-c.x); v.x = c.x + d.x; v.y = c.y + d.y; setVertex(ccg(i ,j), v); } } }
void LFTwirl::preCalculateDistance() { setPosition(m_pTarget->getPosition()); // gridDistanceArray = new float[ (m_sGridSize.x + 1) * (m_sGridSize.y + 1) ]; //Richard // 原先类型为int 现在CCSize为float 墙砖为int gridDistanceArray = new float[ ((int)m_sGridSize.width + 1) * ((int)m_sGridSize.height + 1) ]; int i, j; int index = 0; for (i = 0; i < m_sGridSize.width + 1; ++i) { for (j = 0; j < m_sGridSize.height + 1; ++j) { ccVertex3F v = originalVertex(ccp(i, j)); CCPoint relativedPos = ccp(v.x - m_position.x,v.y - m_position.y); float dis = ccpLength(relativedPos) + 1.0f; gridDistanceArray[index] = dis; index ++; } } // setPosition(m_pTarget->getPosition()); }
void CCShaky3D::update(float time) { #ifdef Hunter timerCounter++; if(timerCounter % 10 != 0) return; #endif // Hunter CC_UNUSED_PARAM(time); int i, j; for (i = 0; i < (m_sGridSize.width+1); ++i) { for (j = 0; j < (m_sGridSize.height+1); ++j) { ccVertex3F v = originalVertex(ccp(i ,j)); v.x += (rand() % (m_nRandrange*2)) - m_nRandrange; v.y += (rand() % (m_nRandrange*2)) - m_nRandrange; if (m_bShakeZ) { v.z += (rand() % (m_nRandrange*2)) - m_nRandrange; } setVertex(ccp(i, j), v); } } }
/* * Update each tick * Time is the percentage of the way through the duration */ void CCPageTurn3D::update(ccTime time) { float tt = MAX(0, time - 0.25f); float deltaAy = (tt * tt * 500); float ay = -100 - deltaAy; float deltaTheta = - (float) M_PI_2 * sqrtf( time) ; float theta = /*0.01f */ + (float) M_PI_2 +deltaTheta; float sinTheta = sinf(theta); float cosTheta = cosf(theta); for (int i = 0; i <= m_sGridSize.width; ++i) { for (int j = 0; j <= m_sGridSize.height; ++j) { // Get original vertex ccVertex3F p = originalVertex(ccp(i ,j)); float R = sqrtf((p.x * p.x) + ((p.y - ay) * (p.y - ay))); float r = R * sinTheta; float alpha = asinf( p.x / R ); float beta = alpha / sinTheta; float cosBeta = cosf( beta ); // If beta > PI then we've wrapped around the cone // Reduce the radius to stop these points interfering with others if (beta <= M_PI) { p.x = ( r * sinf(beta)); } else { // Force X = 0 to stop wrapped // points p.x = 0; } p.y = ( R + ay - ( r * (1 - cosBeta) * sinTheta)); // We scale z here to avoid the animation being // too much bigger than the screen due to perspectve transform p.z = (r * ( 1 - cosBeta ) * cosTheta) / 7;// "100" didn't work for // Stop z coord from dropping beneath underlying page in a transition // issue #751 if( p.z < 0.5f ) { p.z = 0.5f; } // Set new coords setVertex(ccp(i, j), p); } } }
void CCWaves3D::update(ccTime 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(ccg(i ,j)); v.z += (sinf((CGFloat)M_PI * time * m_nWaves * 2 + (v.y+v.x) * .01f) * m_fAmplitude * m_fAmplitudeRate); CCLog("v.z offset is %f\n", (sinf((CGFloat)M_PI * time * m_nWaves * 2 + (v.y+v.x) * .01f) * m_fAmplitude * m_fAmplitudeRate)); setVertex(ccg(i, j), v); } } }
void CCWaves3D::update(float time) { int i, j; for (i = 0; i < m_sGridSize.width + 1; ++i) { for (j = 0; j < m_sGridSize.height + 1; ++j) { ccVertex3F v = originalVertex(ccp(i ,j)); v.z += (sinf((float)M_PI * time * m_nWaves * 2 + (v.y+v.x) * 0.01f) * m_fAmplitude * m_fAmplitudeRate); //CCLOG("v.z offset is %f\n", (sinf((float)M_PI * time * m_nWaves * 2 + (v.y+v.x) * .01f) * m_fAmplitude * m_fAmplitudeRate)); setVertex(ccp(i, j), v); } } }
void CCLiquid::update(ccTime time) { int i, j; for (i = 1; i < m_sGridSize.x; ++i) { for (j = 1; j < m_sGridSize.y; ++j) { ccVertex3F v = originalVertex(ccg(i, j)); v.x = (v.x + (sinf(time * (CGFloat)M_PI * m_nWaves * 2 + v.x * .01f) * m_fAmplitude * m_fAmplitudeRate)); v.y = (v.y + (sinf(time * (CGFloat)M_PI * m_nWaves * 2 + v.y * .01f) * m_fAmplitude * m_fAmplitudeRate)); setVertex(ccg(i, j), v); } } }
void LFTwirl::update(float time) { //// 优化部分 //{ // flag ++; // if (flag % 2 != 0) // return; // flag = 0; //} int i, j; int index = 0; for (i = 0; i < m_sGridSize.width + 1; ++i) { for (j = 0; j < m_sGridSize.height + 1; ++j) { ccVertex3F v = originalVertex(ccp(i, j)); CCPoint relativedPos = ccp(v.x - m_position.x,v.y - m_position.y); CCPoint newPos; float dis = 0.0f; if (gridDistanceArray) { dis = gridDistanceArray[index];index++; }else { dis = ccpLength(relativedPos) + 1.0f; } // 基于相对中心坐标计算 { float tempAngle = mAngle; tempAngle = tempAngle / dis * (mRadius*10);// 跟半径成反比,半径越大,转动角度越小 newPos = ccpRotateByAngle(relativedPos,ccp(1,0),CC_DEGREES_TO_RADIANS(tempAngle)); newPos.x *= mScale; newPos.y *= mScale; } v.x = newPos.x + m_position.x ; v.y = newPos.y + m_position.y; setVertex(ccp(i, j), v); } } mScale *= mScaleFactor; mAngle += mAngleFactor; }
void CCLens3D::update(float time) { CC_UNUSED_PARAM(time); if (m_bDirty) { int i, j; for (i = 0; i < m_sGridSize.width + 1; ++i) { for (j = 0; j < m_sGridSize.height + 1; ++j) { ccVertex3F v = originalVertex(ccp(i, j)); CCPoint vect = ccpSub(m_tPoint, ccp(v.x, v.y)); float r = 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 = logf(pre_log) * m_fLensEffect; float new_r = expf( l ) * m_fRadius; if (ccpLength(vect) > 0) { vect = ccpNormalize(vect); CCPoint new_vect = ccpMult(vect, new_r); v.z += (m_bConcave ? -1.0f : 1.0f) * ccpLength(new_vect) * m_fLensEffect; } } setVertex(ccp(i, j), v); } } m_bDirty = false; } }
void CCLens3D::update(ccTime time) { CC_UNUSED_PARAM(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(ccg(i, j)); CCPoint vect = ccpSub(m_positionInPixels, ccp(v.x, v.y)); CGFloat r = ccpLength(vect); if (r < m_fRadius) { r = m_fRadius - r; CGFloat pre_log = r / m_fRadius; if ( pre_log == 0 ) { pre_log = 0.001f; } float l = logf(pre_log) * m_fLensEffect; float new_r = expf( l ) * m_fRadius; if (ccpLength(vect) > 0) { vect = ccpNormalize(vect); CCPoint new_vect = ccpMult(vect, new_r); v.z += ccpLength(new_vect) * m_fLensEffect; } } setVertex(ccg(i, j), v); } } m_bDirty = false; } }
void CCShaky3D::update(cocos2d::ccTime 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(ccg(i ,j)); v.x += (rand() % (m_nRandrange*2)) - m_nRandrange; v.y += (rand() % (m_nRandrange*2)) - m_nRandrange; if (m_bShakeZ) { v.z += (rand() % (m_nRandrange*2)) - m_nRandrange; } setVertex(ccg(i, j), v); } } }
void CCShaky3D::update(float time) { CC_UNUSED_PARAM(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(ccg(i ,j)); v.x += (rand() % (m_nRandrange*2)) - m_nRandrange; v.y += (rand() % (m_nRandrange*2)) - m_nRandrange; if (m_bShakeZ) { v.z += (rand() % (m_nRandrange*2)) - m_nRandrange; } setVertex(ccg(i, j), v); } } }
void CCRipple3D::update(float time) { int i, j; for (i = 0; i < (m_sGridSize.width+1); ++i) { for (j = 0; j < (m_sGridSize.height+1); ++j) { ccVertex3F v = originalVertex(ccp(i, j)); CCPoint vect = ccpSub(m_tPoint, ccp(v.x,v.y)); float r = ccpLength(vect); if (r < m_fRadius) { r = m_fRadius - r; float rate = powf(r / m_fRadius, 2); v.z += (sinf( time*(float)M_PI * m_nWaves * 2 + r * 0.1f) * m_fAmplitude * m_fAmplitudeRate * rate); } setVertex(ccp(i, j), v); } } }
void CCRipple3D::update(ccTime 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(ccg(i, j)); CCPoint vect = ccpSub(m_positionInPixels, ccp(v.x,v.y)); CGFloat r = ccpLength(vect); if (r < m_fRadius) { r = m_fRadius - r; CGFloat rate = powf(r / m_fRadius, 2); v.z += (sinf( time*(CGFloat)M_PI * m_nWaves * 2 + r * 0.1f) * m_fAmplitude * m_fAmplitudeRate * rate); } setVertex(ccg(i, j), v); } } }
void CCWaves::update(ccTime 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(ccg(i, j)); if (m_bVertical) { v.x = (v.x + (sinf(time * (CGFloat)M_PI * m_nWaves * 2 + v.y * .01f) * m_fAmplitude * m_fAmplitudeRate)); } if (m_bHorizontal) { v.y = (v.y + (sinf(time * (CGFloat)M_PI * m_nWaves * 2 + v.x * .01f) * m_fAmplitude * m_fAmplitudeRate)); } setVertex(ccg(i, j), v); } } }
void CCFlipX3D::update(ccTime time) { CGFloat angle = (CGFloat)M_PI * time; // 180 degrees CGFloat mz = sinf(angle); angle = angle / 2.0f; // x calculates degrees from 0 to 90 CGFloat mx = cosf(angle); ccVertex3F v0, v1, v, diff; v0 = originalVertex(ccg(1, 1)); v1 = originalVertex(ccg(0, 0)); CGFloat x0 = v0.x; CGFloat x1 = v1.x; CGFloat x; ccGridSize a, b, c, d; if ( x0 > x1 ) { // Normal Grid a = ccg(0,0); b = ccg(0,1); c = ccg(1,0); d = ccg(1,1); x = x0; } else { // Reversed Grid c = ccg(0,0); d = ccg(0,1); a = ccg(1,0); b = ccg(1,1); x = x1; } diff.x = ( x - x * mx ); diff.z = fabsf( floorf( (x * mz) / 4.0f ) ); // bottom-left v = originalVertex(a); v.x = diff.x; v.z += diff.z; setVertex(a, v); // upper-left v = originalVertex(b); v.x = diff.x; v.z += diff.z; setVertex(b, v); // bottom-right v = originalVertex(c); v.x -= diff.x; v.z -= diff.z; setVertex(c, v); // upper-right v = originalVertex(d); v.x -= diff.x; v.z -= diff.z; setVertex(d, v); }
void CCFlipY3D::update(ccTime time) { CGFloat angle = (CGFloat)M_PI * time; // 180 degrees CGFloat mz = sinf( angle ); angle = angle / 2.0f; // x calculates degrees from 0 to 90 CGFloat my = cosf(angle); ccVertex3F v0, v1, v, diff; v0 = originalVertex(ccg(1, 1)); v1 = originalVertex(ccg(0, 0)); CGFloat y0 = v0.y; CGFloat y1 = v1.y; CGFloat y; ccGridSize a, b, c, d; if (y0 > y1) { // Normal Grid a = ccg(0,0); b = ccg(0,1); c = ccg(1,0); d = ccg(1,1); y = y0; } else { // Reversed Grid b = ccg(0,0); a = ccg(0,1); d = ccg(1,0); c = ccg(1,1); y = y1; } diff.y = y - y * my; diff.z = fabsf(floorf((y * mz) / 4.0f)); // bottom-left v = originalVertex(a); v.y = diff.y; v.z += diff.z; setVertex(a, v); // upper-left v = originalVertex(b); v.y -= diff.y; v.z -= diff.z; setVertex(b, v); // bottom-right v = originalVertex(c); v.y = diff.y; v.z += diff.z; setVertex(c, v); // upper-right v = originalVertex(d); v.y -= diff.y; v.z -= diff.z; setVertex(d, v); }