2525 ****************************************************************************/
2626
2727cc . RAND_MAX = 0xffffff ;
28- cc . rand = function ( ) {
29- return Math . random ( ) * cc . RAND_MAX ;
28+ cc . rand = function ( ) {
29+ return Math . random ( ) * cc . RAND_MAX ;
3030} ;
3131/**
3232 * cc.Waves3D action
@@ -38,7 +38,7 @@ cc.Waves3D = cc.Grid3DAction.extend(/** @lends cc.Waves3D# */{
3838 _amplitude :null ,
3939 _amplitudeRate :null ,
4040
41- ctor :function ( ) {
41+ ctor :function ( ) {
4242 cc . GridAction . prototype . ctor . call ( this ) ;
4343
4444 this . _waves = 0 ;
@@ -98,7 +98,7 @@ cc.Waves3D = cc.Grid3DAction.extend(/** @lends cc.Waves3D# */{
9898
9999 update :function ( time ) {
100100 var locGridSize = this . _gridSize ;
101- var locAmplitude = this . _amplitude , locPos = cc . p ( 0 , 0 ) ;
101+ var locAmplitude = this . _amplitude , locPos = cc . p ( 0 , 0 ) ;
102102 var locAmplitudeRate = this . _amplitudeRate , locWaves = this . _waves ;
103103 for ( var i = 0 ; i < locGridSize . width + 1 ; ++ i ) {
104104 for ( var j = 0 ; j < locGridSize . height + 1 ; ++ j ) {
@@ -164,9 +164,11 @@ cc.FlipX3D = cc.Grid3DAction.extend(/** @lends cc.Waves3D# */{
164164 var mx = Math . cos ( angle ) ;
165165
166166 var diff = new cc . Vertex3F ( ) ;
167-
168- var v0 = this . originalVertex ( cc . p ( 1 , 1 ) ) ;
169- var v1 = this . originalVertex ( cc . p ( 0 , 0 ) ) ;
167+ var tempVer = cc . p ( 0 , 0 ) ;
168+ tempVer . x = tempVer . y = 1 ;
169+ var v0 = this . originalVertex ( tempVer ) ;
170+ tempVer . x = tempVer . y = 0 ;
171+ var v1 = this . originalVertex ( tempVer ) ;
170172
171173 var x0 = v0 . x ;
172174 var x1 = v1 . x ;
@@ -243,8 +245,11 @@ cc.FlipY3D = cc.FlipX3D.extend(/** @lends cc.FlipY3D# */{
243245
244246 var diff = new cc . Vertex3F ( ) ;
245247
246- var v0 = this . originalVertex ( cc . p ( 1 , 1 ) ) ;
247- var v1 = this . originalVertex ( cc . p ( 0 , 0 ) ) ;
248+ var tempP = cc . p ( 0 , 0 ) ;
249+ tempP . x = tempP . y = 1 ;
250+ var v0 = this . originalVertex ( tempP ) ;
251+ tempP . x = tempP . y = 0 ;
252+ var v1 = this . originalVertex ( tempP ) ;
248253
249254 var y0 = v0 . y ;
250255 var y1 = v1 . y ;
@@ -322,10 +327,10 @@ cc.Lens3D = cc.Grid3DAction.extend(/** @lends cc.Lens3D# */{
322327 _concave :false ,
323328 _dirty :false ,
324329
325- ctor :function ( ) {
330+ ctor :function ( ) {
326331 cc . GridAction . prototype . ctor . call ( this ) ;
327332
328- this . _position = null ;
333+ this . _position = cc . p ( 0 , 0 ) ;
329334 this . _radius = 0 ;
330335 this . _lensEffect = 0 ;
331336 this . _concave = false ;
@@ -352,7 +357,7 @@ cc.Lens3D = cc.Grid3DAction.extend(/** @lends cc.Lens3D# */{
352357 * Set whether lens is concave
353358 * @param {Boolean } concave
354359 */
355- setConcave :function ( concave ) {
360+ setConcave :function ( concave ) {
356361 this . _concave = concave ;
357362 } ,
358363
@@ -385,7 +390,8 @@ cc.Lens3D = cc.Grid3DAction.extend(/** @lends cc.Lens3D# */{
385390 */
386391 initWithDuration :function ( duration , gridSize , position , radius ) {
387392 if ( cc . Grid3DAction . prototype . initWithDuration . call ( this , duration , gridSize ) ) {
388- this . _position = cc . p ( - 1 , - 1 ) ;
393+ this . _position . x = - 1 ;
394+ this . _position . y = - 1 ;
389395 this . setPosition ( position ) ;
390396 this . _radius = radius ;
391397 this . _lensEffect = 0.7 ;
@@ -399,27 +405,35 @@ cc.Lens3D = cc.Grid3DAction.extend(/** @lends cc.Lens3D# */{
399405 if ( this . _dirty ) {
400406 var locGridSizeWidth = this . _gridSize . width , locGridSizeHeight = this . _gridSize . height ;
401407 var locRadius = this . _radius , locLensEffect = this . _lensEffect ;
402- var locPos = cc . p ( 0 , 0 ) ;
408+ var locPos = cc . p ( 0 , 0 ) ;
409+ var vect = cc . p ( 0 , 0 ) ;
410+ var v , r , l , new_r , pre_log ;
403411 for ( var i = 0 ; i < locGridSizeWidth + 1 ; ++ i ) {
404412 for ( var j = 0 ; j < locGridSizeHeight + 1 ; ++ j ) {
405413 locPos . x = i ;
406414 locPos . y = j ;
407- var v = this . originalVertex ( locPos ) ;
408- var vect = cc . pSub ( this . _position , v ) ;
409- var r = cc . pLength ( vect ) ;
415+ v = this . originalVertex ( locPos ) ;
416+ vect . x = this . _position . x - v . x ;
417+ vect . y = this . _position . y - v . y ;
418+ r = cc . pLength ( vect ) ;
410419
411420 if ( r < locRadius ) {
412421 r = locRadius - r ;
413- var pre_log = r / locRadius ;
422+ pre_log = r / locRadius ;
414423 if ( pre_log == 0 )
415424 pre_log = 0.001 ;
416425
417- var l = Math . log ( pre_log ) * locLensEffect ;
418- var new_r = Math . exp ( l ) * locRadius ;
426+ l = Math . log ( pre_log ) * locLensEffect ;
427+ new_r = Math . exp ( l ) * locRadius ;
428+
429+ r = cc . pLength ( vect ) ;
430+ if ( r > 0 ) {
431+ vect . x = vect . x / r ;
432+ vect . y = vect . y / r ;
419433
420- if ( cc . pLength ( vect ) > 0 ) {
421- vect = cc . pNormalize ( vect ) ;
422- v . z += cc . pLength ( cc . pMult ( vect , new_r ) ) * locLensEffect ;
434+ vect . x = vect . x * new_r ;
435+ vect . y = vect . y * new_r ;
436+ v . z += cc . pLength ( vect ) * locLensEffect ;
423437 }
424438 }
425439 this . setVertex ( locPos , v ) ;
@@ -457,7 +471,7 @@ cc.Ripple3D = cc.Grid3DAction.extend(/** @lends cc.Ripple3D# */{
457471 _amplitude :null ,
458472 _amplitudeRate :null ,
459473
460- ctor :function ( ) {
474+ ctor :function ( ) {
461475 cc . GridAction . prototype . ctor . call ( this ) ;
462476
463477 this . _position = null ;
@@ -539,14 +553,18 @@ cc.Ripple3D = cc.Grid3DAction.extend(/** @lends cc.Ripple3D# */{
539553
540554 update :function ( time ) {
541555 var locGridSizeWidth = this . _gridSize . width , locGridSizeHeight = this . _gridSize . height ;
542- var locPos = cc . p ( 0 , 0 ) , locRadius = this . _radius ;
556+ var locPos = cc . p ( 0 , 0 ) , locRadius = this . _radius ;
543557 var locWaves = this . _waves , locAmplitude = this . _amplitude , locAmplitudeRate = this . _amplitudeRate ;
558+ var v , r , tempPos = cc . p ( 0 , 0 ) ;
544559 for ( var i = 0 ; i < ( locGridSizeWidth + 1 ) ; ++ i ) {
545560 for ( var j = 0 ; j < ( locGridSizeHeight + 1 ) ; ++ j ) {
546561 locPos . x = i ;
547562 locPos . y = j ;
548- var v = this . originalVertex ( locPos ) ;
549- var r = cc . pLength ( cc . pSub ( this . _position , v ) ) ;
563+ v = this . originalVertex ( locPos ) ;
564+
565+ tempPos . x = this . _position . x - v . x ;
566+ tempPos . y = this . _position . y - v . y ;
567+ r = cc . pLength ( tempPos ) ;
550568
551569 if ( r < locRadius ) {
552570 r = locRadius - r ;
@@ -584,7 +602,7 @@ cc.Shaky3D = cc.Grid3DAction.extend(/** @lends cc.Shaky3D# */{
584602 _randRange :null ,
585603 _shakeZ :null ,
586604
587- ctor :function ( ) {
605+ ctor :function ( ) {
588606 cc . GridAction . prototype . ctor . call ( this ) ;
589607
590608 this . _randRange = 0 ;
@@ -610,12 +628,13 @@ cc.Shaky3D = cc.Grid3DAction.extend(/** @lends cc.Shaky3D# */{
610628
611629 update :function ( time ) {
612630 var locGridSizeWidth = this . _gridSize . width , locGridSizeHeight = this . _gridSize . height ;
613- var locRandRange = this . _randRange , locShakeZ = this . _shakeZ , locP = cc . p ( 0 , 0 ) ;
631+ var locRandRange = this . _randRange , locShakeZ = this . _shakeZ , locP = cc . p ( 0 , 0 ) ;
632+ var v ;
614633 for ( var i = 0 ; i < ( locGridSizeWidth + 1 ) ; ++ i ) {
615634 for ( var j = 0 ; j < ( locGridSizeHeight + 1 ) ; ++ j ) {
616635 locP . x = i ;
617636 locP . y = j ;
618- var v = this . originalVertex ( locP ) ;
637+ v = this . originalVertex ( locP ) ;
619638 v . x += ( cc . rand ( ) % ( locRandRange * 2 ) ) - locRandRange ;
620639 v . y += ( cc . rand ( ) % ( locRandRange * 2 ) ) - locRandRange ;
621640 if ( locShakeZ )
@@ -650,7 +669,7 @@ cc.Liquid = cc.Grid3DAction.extend(/** @lends cc.Liquid# */{
650669 _amplitude :null ,
651670 _amplitudeRate :null ,
652671
653- ctor :function ( ) {
672+ ctor :function ( ) {
654673 cc . GridAction . prototype . ctor . call ( this ) ;
655674
656675 this . _waves = 0 ;
@@ -709,13 +728,14 @@ cc.Liquid = cc.Grid3DAction.extend(/** @lends cc.Liquid# */{
709728 } ,
710729
711730 update :function ( time ) {
712- var locSizeWidth = this . _gridSize . width , locSizeHeight = this . _gridSize . height , locPos = cc . p ( 0 , 0 ) ;
731+ var locSizeWidth = this . _gridSize . width , locSizeHeight = this . _gridSize . height , locPos = cc . p ( 0 , 0 ) ;
713732 var locWaves = this . _waves , locAmplitude = this . _amplitude , locAmplitudeRate = this . _amplitudeRate ;
733+ var v ;
714734 for ( var i = 1 ; i < locSizeWidth ; ++ i ) {
715735 for ( var j = 1 ; j < locSizeHeight ; ++ j ) {
716736 locPos . x = i ;
717737 locPos . y = j ;
718- var v = this . originalVertex ( locPos ) ;
738+ v = this . originalVertex ( locPos ) ;
719739 v . x = ( v . x + ( Math . sin ( time * Math . PI * locWaves * 2 + v . x * .01 ) * locAmplitude * locAmplitudeRate ) ) ;
720740 v . y = ( v . y + ( Math . sin ( time * Math . PI * locWaves * 2 + v . y * .01 ) * locAmplitude * locAmplitudeRate ) ) ;
721741 this . setVertex ( locPos , v ) ;
@@ -750,7 +770,7 @@ cc.Waves = cc.Grid3DAction.extend(/** @lends cc.Waves# */{
750770 _vertical :null ,
751771 _horizontal :null ,
752772
753- ctor :function ( ) {
773+ ctor :function ( ) {
754774 cc . GridAction . prototype . ctor . call ( this ) ;
755775
756776 this . _waves = 0 ;
@@ -815,14 +835,15 @@ cc.Waves = cc.Grid3DAction.extend(/** @lends cc.Waves# */{
815835 } ,
816836
817837 update :function ( time ) {
818- var locSizeWidth = this . _gridSize . width , locSizeHeight = this . _gridSize . height , locPos = cc . p ( 0 , 0 ) ;
838+ var locSizeWidth = this . _gridSize . width , locSizeHeight = this . _gridSize . height , locPos = cc . p ( 0 , 0 ) ;
819839 var locVertical = this . _vertical , locHorizontal = this . _horizontal ;
820840 var locWaves = this . _waves , locAmplitude = this . _amplitude , locAmplitudeRate = this . _amplitudeRate ;
841+ var v ;
821842 for ( var i = 0 ; i < locSizeWidth + 1 ; ++ i ) {
822843 for ( var j = 0 ; j < locSizeHeight + 1 ; ++ j ) {
823844 locPos . x = i ;
824845 locPos . y = j ;
825- var v = this . originalVertex ( locPos ) ;
846+ v = this . originalVertex ( locPos ) ;
826847 if ( locVertical )
827848 v . x = ( v . x + ( Math . sin ( time * Math . PI * locWaves * 2 + v . y * .01 ) * locAmplitude * locAmplitudeRate ) ) ;
828849 if ( locHorizontal )
@@ -862,7 +883,7 @@ cc.Twirl = cc.Grid3DAction.extend({
862883 _amplitude :null ,
863884 _amplitudeRate :null ,
864885
865- ctor :function ( ) {
886+ ctor :function ( ) {
866887 cc . GridAction . prototype . ctor . call ( this ) ;
867888
868889 this . _position = null ;
@@ -933,22 +954,26 @@ cc.Twirl = cc.Grid3DAction.extend({
933954
934955 update :function ( time ) {
935956 var c = this . _position ;
936- var locSizeWidth = this . _gridSize . width , locSizeHeight = this . _gridSize . height , locPos = cc . p ( 0 , 0 ) ;
957+ var locSizeWidth = this . _gridSize . width , locSizeHeight = this . _gridSize . height , locPos = cc . p ( 0 , 0 ) ;
937958 var amp = 0.1 * this . _amplitude * this . _amplitudeRate ;
938959 var locTwirls = this . _twirls ;
960+ var v , a , dX , dY , avg = cc . p ( 0 , 0 ) ;
939961 for ( var i = 0 ; i < ( locSizeWidth + 1 ) ; ++ i ) {
940962 for ( var j = 0 ; j < ( locSizeHeight + 1 ) ; ++ j ) {
941963 locPos . x = i ;
942964 locPos . y = j ;
943- var v = this . originalVertex ( locPos ) ;
965+ v = this . originalVertex ( locPos ) ;
966+
967+ avg . x = i - ( locSizeWidth / 2.0 ) ;
968+ avg . y = j - ( locSizeHeight / 2.0 ) ;
944969
945- var avg = cc . p ( i - ( locSizeWidth / 2.0 ) , j - ( locSizeHeight / 2.0 ) ) ;
970+ a = cc . pLength ( avg ) * Math . cos ( Math . PI / 2.0 + time * Math . PI * locTwirls * 2 ) * amp ;
946971
947- var a = cc . pLength ( avg ) * Math . cos ( Math . PI / 2.0 + time * Math . PI * locTwirls * 2 ) * amp ;
948- var d = cc . p ( Math . sin ( a ) * ( v . y - c . y ) + Math . cos ( a ) * ( v . x - c . x ) , Math . cos ( a ) * ( v . y - c . y ) - Math . sin ( a ) * ( v . x - c . x ) ) ;
972+ dX = Math . sin ( a ) * ( v . y - c . y ) + Math . cos ( a ) * ( v . x - c . x ) ;
973+ dY = Math . cos ( a ) * ( v . y - c . y ) - Math . sin ( a ) * ( v . x - c . x ) ;
949974
950- v . x = c . x + d . x ;
951- v . y = c . y + d . y ;
975+ v . x = c . x + dX ;
976+ v . y = c . y + dY ;
952977
953978 this . setVertex ( locPos , v ) ;
954979 }
0 commit comments