1 /****************************************************************************
  2  Copyright (c) 2008-2010 Ricardo Quesada
  3  Copyright (c) 2011-2012 cocos2d-x.org
  4  Copyright (c) 2013-2014 Chukong Technologies Inc.
  5 
  6  http://www.cocos2d-x.org
  7 
  8  Permission is hereby granted, free of charge, to any person obtaining a copy
  9  of this software and associated documentation files (the "Software"), to deal
 10  in the Software without restriction, including without limitation the rights
 11  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 12  copies of the Software, and to permit persons to whom the Software is
 13  furnished to do so, subject to the following conditions:
 14 
 15  The above copyright notice and this permission notice shall be included in
 16  all copies or substantial portions of the Software.
 17 
 18  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 19  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 20  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 21  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 22  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 23  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 24  THE SOFTWARE.
 25  ****************************************************************************/
 26 
 27 /**
 28  * cc.Waves3D action. <br />
 29  * Reference the test cases (Effects Advanced Test)
 30  * @class
 31  * @extends cc.Grid3DAction
 32  * @param {Number} duration
 33  * @param {cc.Size} gridSize
 34  * @param {Number} waves
 35  * @param {Number} amplitude
 36  */
 37 cc.Waves3D = cc.Grid3DAction.extend(/** @lends cc.Waves3D# */{
 38     _waves: 0,
 39     _amplitude: 0,
 40     _amplitudeRate: 0,
 41 
 42 	/**
 43      * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. <br />
 44 	 * Create a wave 3d action with duration, grid size, waves and amplitude.
 45 	 * @param {Number} duration
 46 	 * @param {cc.Size} gridSize
 47 	 * @param {Number} waves
 48 	 * @param {Number} amplitude
 49 	 */
 50     ctor:function (duration, gridSize, waves, amplitude) {
 51         cc.GridAction.prototype.ctor.call(this);
 52 		amplitude !== undefined && this.initWithDuration(duration, gridSize, waves, amplitude);
 53     },
 54 
 55     /**
 56      * get Amplitude
 57      * @return {Number}
 58      */
 59     getAmplitude:function () {
 60         return this._amplitude;
 61     },
 62 
 63     /**
 64      * set Amplitude
 65      * @param {Number} amplitude
 66      */
 67     setAmplitude:function (amplitude) {
 68         this._amplitude = amplitude;
 69     },
 70 
 71     /**
 72      * get Amplitude Rate
 73      * @return {Number}
 74      */
 75     getAmplitudeRate:function () {
 76         return this._amplitudeRate;
 77     },
 78 
 79     /**
 80      * set Amplitude Rate
 81      * @param {Number} amplitudeRate
 82      */
 83     setAmplitudeRate:function (amplitudeRate) {
 84         this._amplitudeRate = amplitudeRate;
 85     },
 86 
 87     /**
 88      * initializes an action with duration, grid size, waves and amplitude
 89      * @param {Number} duration
 90      * @param {cc.Size} gridSize
 91      * @param {Number} waves
 92      * @param {Number} amplitude
 93      * @return {Boolean}
 94      */
 95     initWithDuration:function (duration, gridSize, waves, amplitude) {
 96         if (cc.Grid3DAction.prototype.initWithDuration.call(this, duration, gridSize)) {
 97             this._waves = waves;
 98             this._amplitude = amplitude;
 99             this._amplitudeRate = 1.0;
100             return true;
101         }
102         return false;
103     },
104 
105     /**
106      * Called once per frame. Time is the number of seconds of a frame interval.
107      *
108      * @param {Number}  dt
109      */
110     update:function (dt) {
111         var locGridSize = this._gridSize;
112         var locAmplitude = this._amplitude, locPos = cc.p(0, 0);
113         var locAmplitudeRate = this._amplitudeRate, locWaves = this._waves;
114         for (var i = 0; i < locGridSize.width + 1; ++i) {
115             for (var j = 0; j < locGridSize.height + 1; ++j) {
116                 locPos.x = i;
117                 locPos.y = j;
118                 var v = this.originalVertex(locPos);
119                 v.z += (Math.sin(Math.PI * dt * locWaves * 2 + (v.y + v.x) * 0.01) * locAmplitude * locAmplitudeRate);
120                 //cc.log("v.z offset is" + (Math.sin(Math.PI * dt * this._waves * 2 + (v.y + v.x) * 0.01) * this._amplitude * this._amplitudeRate));
121                 this.setVertex(locPos, v);
122             }
123         }
124     }
125 });
126 
127 /**
128  * Create a wave 3d action with duration, grid size, waves and amplitude.
129  * @function
130  * @param {Number} duration
131  * @param {cc.Size} gridSize
132  * @param {Number} waves
133  * @param {Number} amplitude
134  */
135 cc.waves3D = function (duration, gridSize, waves, amplitude) {
136     return new cc.Waves3D(duration, gridSize, waves, amplitude);
137 };
138 /**
139  * Please use cc.waves3D instead. <br />
140  * Create a wave 3d action with duration, grid size, waves and amplitude.
141  * @param {Number} duration
142  * @param {cc.Size} gridSize
143  * @param {Number} waves
144  * @param {Number} amplitude
145  * @static
146  * @deprecated since v3.0 <br /> Please use cc.waves3D instead.
147  */
148 cc.Waves3D.create = cc.waves3D;
149 
150 /**
151  * cc.FlipX3D action. <br />
152  * Flip around. <br />
153  * Reference the test cases (Effects Test)
154  * @class
155  * @extends cc.Grid3DAction
156  * @param {Number} duration
157  */
158 cc.FlipX3D = cc.Grid3DAction.extend(/** @lends cc.FlipX3D# */{
159 
160 	/**
161      * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. <br />
162 	 * Create a Flip X 3D action with duration.
163 	 * @param {Number} duration
164 	 */
165 	ctor: function(duration) {
166 		if (duration !== undefined)
167 			cc.GridAction.prototype.ctor.call(this, duration, cc.size(1, 1));
168 		else cc.GridAction.prototype.ctor.call(this);
169 	},
170 
171     /**
172      * initializes the action with duration
173      * @param {Number} duration
174      * @return {Boolean}
175      */
176     initWithDuration:function (duration) {
177         return cc.Grid3DAction.prototype.initWithDuration.call(this, duration, cc.size(1, 1));
178     },
179 
180     /**
181      * initializes the action with gridSize and duration
182      * @param {cc.Size} gridSize
183      * @param {Number} duration
184      * @return {Boolean}
185      */
186     initWithSize:function (gridSize, duration) {
187         if (gridSize.width != 1 || gridSize.height != 1) {
188             // Grid size must be (1,1)
189             cc.log("Grid size must be (1,1)");
190             return false;
191         }
192         return  cc.Grid3DAction.prototype.initWithDuration.call(this, duration, gridSize);
193     },
194 
195     /**
196      * Called once per frame. Time is the number of seconds of a frame interval.
197      *
198      * @param {Number}  dt
199      */
200     update:function (dt) {
201         var angle = Math.PI * dt; // 180 degrees
202         var mz = Math.sin(angle);
203         angle = angle / 2.0; // x calculates degrees from 0 to 90
204         var mx = Math.cos(angle);
205 
206         var diff = new cc.Vertex3F();
207         var tempVer = cc.p(0, 0);
208         tempVer.x = tempVer.y = 1;
209         var v0 = this.originalVertex(tempVer);
210         tempVer.x = tempVer.y = 0;
211         var v1 = this.originalVertex(tempVer);
212 
213         var x0 = v0.x;
214         var x1 = v1.x;
215         var x;
216         var a, b, c, d;
217 
218         if (x0 > x1) {
219             // Normal Grid
220             a = cc.p(0, 0);
221             b = cc.p(0, 1);
222             c = cc.p(1, 0);
223             d = cc.p(1, 1);
224             x = x0;
225         } else {
226             // Reversed Grid
227             c = cc.p(0, 0);
228             d = cc.p(0, 1);
229             a = cc.p(1, 0);
230             b = cc.p(1, 1);
231             x = x1;
232         }
233 
234         diff.x = ( x - x * mx );
235         diff.z = Math.abs(parseFloat((x * mz) / 4.0));
236 
237         // bottom-left
238         var v = this.originalVertex(a);
239         v.x = diff.x;
240         v.z += diff.z;
241         this.setVertex(a, v);
242 
243         // upper-left
244         v = this.originalVertex(b);
245         v.x = diff.x;
246         v.z += diff.z;
247         this.setVertex(b, v);
248 
249         // bottom-right
250         v = this.originalVertex(c);
251         v.x -= diff.x;
252         v.z -= diff.z;
253         this.setVertex(c, v);
254 
255         // upper-right
256         v = this.originalVertex(d);
257         v.x -= diff.x;
258         v.z -= diff.z;
259         this.setVertex(d, v);
260     }
261 });
262 
263 /**
264  * Create a Flip X 3D action with duration. <br />
265  * Flip around.
266  * @function
267  * @param {Number} duration
268  * @return {cc.FlipX3D}
269  */
270 cc.flipX3D = function (duration) {
271     return new cc.FlipX3D(duration);
272 };
273 
274 /**
275  * Please use cc.flipX3D instead. <br />
276  * Create a Flip X 3D action with duration. <br />
277  * Flip around.
278  * @param {Number} duration
279  * @return {cc.FlipX3D}
280  * @static
281  * @deprecated since v3.0 <br /> Please use cc.flipX3D instead.
282  */
283 cc.FlipX3D.create = cc.flipX3D;
284 
285 /**
286  * cc.FlipY3D action. <br />
287  * Upside down. <br />
288  * Reference the test cases (Effects Test)
289  * @class
290  * @extends cc.FlipX3D
291  * @param {Number} duration
292  */
293 cc.FlipY3D = cc.FlipX3D.extend(/** @lends cc.FlipY3D# */{
294 
295 	/**
296      * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. <br />
297 	 * Create a flip Y 3d action with duration.
298 	 * @param {Number} duration
299 	 */
300 	ctor: function(duration) {
301 		if (duration !== undefined)
302 			cc.GridAction.prototype.ctor.call(this, duration, cc.size(1, 1));
303 		else cc.GridAction.prototype.ctor.call(this);
304 	},
305 
306     /**
307      * Called once per frame. Time is the number of seconds of a frame interval.
308      *
309      * @param {Number}  dt
310      */
311     update:function (dt) {
312         var angle = Math.PI * dt; // 180 degrees
313         var mz = Math.sin(angle);
314         angle = angle / 2.0;     // x calculates degrees from 0 to 90
315         var my = Math.cos(angle);
316 
317         var diff = new cc.Vertex3F();
318 
319         var tempP = cc.p(0, 0);
320         tempP.x = tempP.y = 1;
321         var v0 = this.originalVertex(tempP);
322         tempP.x = tempP.y = 0;
323         var v1 = this.originalVertex(tempP);
324 
325         var y0 = v0.y;
326         var y1 = v1.y;
327         var y;
328         var a, b, c, d;
329 
330         if (y0 > y1) {
331             // Normal Grid
332             a = cc.p(0, 0);
333             b = cc.p(0, 1);
334             c = cc.p(1, 0);
335             d = cc.p(1, 1);
336             y = y0;
337         } else {
338             // Reversed Grid
339             b = cc.p(0, 0);
340             a = cc.p(0, 1);
341             d = cc.p(1, 0);
342             c = cc.p(1, 1);
343             y = y1;
344         }
345 
346         diff.y = y - y * my;
347         diff.z = Math.abs(parseFloat(y * mz) / 4.0);
348 
349         // bottom-left
350         var v = this.originalVertex(a);
351         v.y = diff.y;
352         v.z += diff.z;
353         this.setVertex(a, v);
354 
355         // upper-left
356         v = this.originalVertex(b);
357         v.y -= diff.y;
358         v.z -= diff.z;
359         this.setVertex(b, v);
360 
361         // bottom-right
362         v = this.originalVertex(c);
363         v.y = diff.y;
364         v.z += diff.z;
365         this.setVertex(c, v);
366 
367         // upper-right
368         v = this.originalVertex(d);
369         v.y -= diff.y;
370         v.z -= diff.z;
371         this.setVertex(d, v);
372     }
373 });
374 
375 /**
376  * Create a flip Y 3d action with duration. <br />
377  * Upside down.
378  * @function
379  * @param {Number} duration
380  * @return {cc.FlipY3D}
381  */
382 cc.flipY3D = function (duration) {
383     return new cc.FlipY3D(duration);
384 };
385 
386 /**
387  * Please use cc.flipY3D instead. <br />
388  * Create a flip Y 3d action with duration.
389  * @param {Number} duration
390  * @return {cc.FlipY3D}
391  * @static
392  * @deprecated since v3.0 <br /> Please use cc.flipY3D instead.
393  */
394 cc.FlipY3D.create = cc.flipY3D;
395 
396 /**
397  * cc.Lens3D action. <br />
398  * Upside down. <br />
399  * Reference the test cases (Effects Test)
400  * @class
401  * @extends cc.FlipX3D
402  * @param {Number} duration
403  * @param {cc.Size} gridSize
404  * @param {cc.Point} position
405  * @param {Number} radius
406  */
407 cc.Lens3D = cc.Grid3DAction.extend(/** @lends cc.Lens3D# */{
408     //lens center position
409     _position:null,
410     _radius:0,
411     //lens effect. Defaults to 0.7 - 0 means no effect, 1 is very strong effect
412     _lensEffect:0,
413     //lens is concave. (true = concave, false = convex) default is convex i.e. false
414     _concave:false,
415     _dirty:false,
416 
417 	/**
418      * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. <br />
419 	 * creates a lens 3d action with center position, radius.
420 	 * @param {Number} duration
421 	 * @param {cc.Size} gridSize
422 	 * @param {cc.Point} position
423 	 * @param {Number} radius
424 	 */
425     ctor:function (duration, gridSize, position, radius) {
426         cc.GridAction.prototype.ctor.call(this);
427 
428         this._position = cc.p(0, 0);
429 		radius !== undefined && this.initWithDuration(duration, gridSize, position, radius);
430     },
431 
432     /**
433      * Get lens center position
434      * @return {Number}
435      */
436     getLensEffect:function () {
437         return this._lensEffect;
438     },
439 
440     /**
441      * Set lens center position
442      * @param {Number} lensEffect
443      */
444     setLensEffect:function (lensEffect) {
445         this._lensEffect = lensEffect;
446     },
447 
448     /**
449      * Set whether lens is concave
450      * @param {Boolean} concave
451      */
452     setConcave:function (concave) {
453         this._concave = concave;
454     },
455 
456     /**
457      * get Position
458      * @return {cc.Point}
459      */
460     getPosition:function () {
461         return this._position;
462     },
463 
464     /**
465      * set Position
466      * @param {cc.Point} position
467      */
468     setPosition:function (position) {
469         if (!cc.pointEqualToPoint(position, this._position)) {
470             this._position.x = position.x;
471             this._position.y = position.y;
472             this._dirty = true;
473         }
474     },
475 
476     /**
477      * initializes the action with center position, radius, a grid size and duration
478      * @param {Number} duration
479      * @param {cc.Size} gridSize
480      * @param {cc.Point} position
481      * @param {Number} radius
482      * @return {Boolean}
483      */
484     initWithDuration:function (duration, gridSize, position, radius) {
485         if (cc.Grid3DAction.prototype.initWithDuration.call(this, duration, gridSize)) {
486             this.setPosition(position);
487             this._radius = radius;
488             this._lensEffect = 0.7;
489             this._dirty = true;
490             return true;
491         }
492         return false;
493     },
494 
495     /**
496      * Called once per frame. Time is the number of seconds of a frame interval.
497      *
498      * @param {Number}  dt
499      */
500     update:function (dt) {
501         if (this._dirty) {
502             var locGridSizeWidth = this._gridSize.width, locGridSizeHeight = this._gridSize.height;
503             var locRadius = this._radius, locLensEffect = this._lensEffect;
504             var locPos = cc.p(0, 0);
505             var vect = cc.p(0, 0);
506             var v, r, l, new_r, pre_log;
507             for (var i = 0; i < locGridSizeWidth + 1; ++i) {
508                 for (var j = 0; j < locGridSizeHeight + 1; ++j) {
509                     locPos.x = i;
510                     locPos.y = j;
511                     v = this.originalVertex(locPos);
512                     vect.x = this._position.x - v.x;
513                     vect.y = this._position.y - v.y;
514                     r = cc.pLength(vect);
515 
516                     if (r < locRadius) {
517                         r = locRadius - r;
518                         pre_log = r / locRadius;
519                         if (pre_log == 0)
520                             pre_log = 0.001;
521 
522                         l = Math.log(pre_log) * locLensEffect;
523                         new_r = Math.exp(l) * locRadius;
524 
525                         r = cc.pLength(vect);
526                         if (r > 0) {
527                             vect.x = vect.x / r;
528                             vect.y = vect.y / r;
529 
530                             vect.x = vect.x * new_r;
531                             vect.y = vect.y * new_r;
532                             v.z += cc.pLength(vect) * locLensEffect;
533                         }
534                     }
535                     this.setVertex(locPos, v);
536                 }
537             }
538             this._dirty = false;
539         }
540     }
541 });
542 
543 /**
544  * creates a lens 3d action with center position, radius
545  * @function
546  * @param {Number} duration
547  * @param {cc.Size} gridSize
548  * @param {cc.Point} position
549  * @param {Number} radius
550  * @return {cc.Lens3D}
551  */
552 cc.lens3D = function (duration, gridSize, position, radius) {
553     return new cc.Lens3D(duration, gridSize, position, radius);
554 };
555 
556 /**
557  * Please use cc.lens3D instead
558  * creates a lens 3d action with center position, radius
559  * @param {Number} duration
560  * @param {cc.Size} gridSize
561  * @param {cc.Point} position
562  * @param {Number} radius
563  * @return {cc.Lens3D}
564  * @static
565  * @deprecated since v3.0 <br /> Please use cc.lens3D instead.
566  */
567 cc.Lens3D.create = cc.lens3D;
568 
569 /**
570  * cc.Ripple3D action. <br />
571  * Reference the test cases (Effects Test)
572  * @class
573  * @extends cc.Grid3DAction
574  * @param {Number} duration
575  * @param {cc.Size} gridSize
576  * @param {cc.Point} position
577  * @param {Number} radius
578  * @param {Number} waves
579  * @param {Number} amplitude
580  */
581 cc.Ripple3D = cc.Grid3DAction.extend(/** @lends cc.Ripple3D# */{
582     /* center position */
583     _position: null,
584     _radius: 0,
585     _waves: 0,
586     _amplitude: 0,
587     _amplitudeRate: 0,
588 
589 	/**
590      * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. <br />
591 	 * creates a ripple 3d action with radius, number of waves, amplitude.
592 	 * @param {Number} duration
593 	 * @param {cc.Size} gridSize
594 	 * @param {cc.Point} position
595 	 * @param {Number} radius
596 	 * @param {Number} waves
597 	 * @param {Number} amplitude
598 	 */
599     ctor:function (duration, gridSize, position, radius, waves, amplitude) {
600         cc.GridAction.prototype.ctor.call(this);
601 
602         this._position = cc.p(0, 0);
603 		amplitude !== undefined && this.initWithDuration(duration, gridSize, position, radius, waves, amplitude);
604     },
605 
606     /**
607      * get center position
608      * @return {cc.Point}
609      */
610     getPosition:function () {
611         return this._position;
612     },
613 
614     /**
615      * set center position
616      * @param {cc.Point} position
617      */
618     setPosition:function (position) {
619         this._position.x = position.x;
620         this._position.y = position.y;
621     },
622 
623     /**
624      * get Amplitude
625      * @return {Number}
626      */
627     getAmplitude:function () {
628         return this._amplitude;
629     },
630 
631     /**
632      * set Amplitude
633      * @param {Number} amplitude
634      */
635     setAmplitude:function (amplitude) {
636         this._amplitude = amplitude;
637     },
638 
639     /**
640      * get Amplitude rate
641      * @return {*}
642      */
643     getAmplitudeRate:function () {
644         return this._amplitudeRate;
645     },
646 
647     /**
648      * get amplitude rate
649      * @param {Number} amplitudeRate
650      */
651     setAmplitudeRate:function (amplitudeRate) {
652         this._amplitudeRate = amplitudeRate;
653     },
654 
655     /**
656      * initializes the action with radius, number of waves, amplitude, a grid size and duration
657      * @param {Number} duration
658      * @param {cc.Size} gridSize
659      * @param {cc.Point} position
660      * @param {Number} radius
661      * @param {Number} waves
662      * @param {Number} amplitude
663      * @return {Boolean}
664      */
665     initWithDuration:function (duration, gridSize, position, radius, waves, amplitude) {
666         if (cc.Grid3DAction.prototype.initWithDuration.call(this, duration, gridSize)) {
667             this.setPosition(position);
668             this._radius = radius;
669             this._waves = waves;
670             this._amplitude = amplitude;
671             this._amplitudeRate = 1.0;
672             return true;
673         }
674         return false;
675     },
676 
677     /**
678      * Called once per frame. Time is the number of seconds of a frame interval.
679      *
680      * @param {Number}  dt
681      */
682     update:function (dt) {
683         var locGridSizeWidth = this._gridSize.width, locGridSizeHeight = this._gridSize.height;
684         var locPos = cc.p(0, 0), locRadius = this._radius;
685         var locWaves = this._waves, locAmplitude = this._amplitude, locAmplitudeRate = this._amplitudeRate;
686         var v, r, tempPos = cc.p(0, 0);
687         for (var i = 0; i < (locGridSizeWidth + 1); ++i) {
688             for (var j = 0; j < (locGridSizeHeight + 1); ++j) {
689                 locPos.x = i;
690                 locPos.y = j;
691                 v = this.originalVertex(locPos);
692 
693                 tempPos.x = this._position.x - v.x;
694                 tempPos.y = this._position.y - v.y;
695                 r = cc.pLength(tempPos);
696 
697                 if (r < locRadius) {
698                     r = locRadius - r;
699                     var rate = Math.pow(r / locRadius, 2);
700                     v.z += (Math.sin(dt * Math.PI * locWaves * 2 + r * 0.1) * locAmplitude * locAmplitudeRate * rate);
701                 }
702                 this.setVertex(locPos, v);
703             }
704         }
705     }
706 });
707 
708 /**
709  * creates a ripple 3d action with radius, number of waves, amplitude
710  * @function
711  * @param {Number} duration
712  * @param {cc.Size} gridSize
713  * @param {cc.Point} position
714  * @param {Number} radius
715  * @param {Number} waves
716  * @param {Number} amplitude
717  * @return {cc.Ripple3D}
718  */
719 cc.ripple3D = function (duration, gridSize, position, radius, waves, amplitude) {
720     return new cc.Ripple3D(duration, gridSize, position, radius, waves, amplitude);
721 };
722 
723 /**
724  * Please use cc.ripple3D instead
725  * creates a ripple 3d action with radius, number of waves, amplitude
726  * @param {Number} duration
727  * @param {cc.Size} gridSize
728  * @param {cc.Point} position
729  * @param {Number} radius
730  * @param {Number} waves
731  * @param {Number} amplitude
732  * @return {cc.Ripple3D}
733  * @static
734  * @deprecated since v3.0 <br /> Please use cc.ripple3D instead.
735  */
736 cc.Ripple3D.create = cc.ripple3D;
737 
738 /**
739  * cc.Shaky3D action. <br />
740  * Reference the test cases (Effects Test)
741  * @class
742  * @extends cc.Grid3DAction
743  * @param {Number} duration
744  * @param {cc.Size} gridSize
745  * @param {Number} range
746  * @param {Boolean} shakeZ
747  */
748 cc.Shaky3D = cc.Grid3DAction.extend(/** @lends cc.Shaky3D# */{
749     _randRange: 0,
750     _shakeZ: false,
751 
752 	/**
753      * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. <br />
754 	 * Create a shaky3d action with a range, shake Z vertices.
755 	 * @param {Number} duration
756 	 * @param {cc.Size} gridSize
757 	 * @param {Number} range
758 	 * @param {Boolean} shakeZ
759 	 */
760     ctor:function (duration, gridSize, range, shakeZ) {
761         cc.GridAction.prototype.ctor.call(this);
762 		shakeZ !== undefined && this.initWithDuration(duration, gridSize, range, shakeZ);
763     },
764 
765     /**
766      * initializes the action with a range, shake Z vertices, a grid and duration
767      * @param {Number} duration
768      * @param {cc.Size} gridSize
769      * @param {Number} range
770      * @param {Boolean} shakeZ
771      * @return {Boolean}
772      */
773     initWithDuration:function (duration, gridSize, range, shakeZ) {
774         if (cc.Grid3DAction.prototype.initWithDuration.call(this, duration, gridSize)) {
775             this._randRange = range;
776             this._shakeZ = shakeZ;
777             return true;
778         }
779         return false;
780     },
781 
782     /**
783      * Called once per frame. Time is the number of seconds of a frame interval.
784      *
785      * @param {Number}  dt
786      */
787     update:function (dt) {
788         var locGridSizeWidth = this._gridSize.width, locGridSizeHeight = this._gridSize.height;
789         var locRandRange = this._randRange, locShakeZ = this._shakeZ, locP = cc.p(0, 0);
790         var v;
791         for (var i = 0; i < (locGridSizeWidth + 1); ++i) {
792             for (var j = 0; j < (locGridSizeHeight + 1); ++j) {
793                 locP.x = i;
794                 locP.y = j;
795                 v = this.originalVertex(locP);
796                 v.x += (cc.rand() % (locRandRange * 2)) - locRandRange;
797                 v.y += (cc.rand() % (locRandRange * 2)) - locRandRange;
798                 if (locShakeZ)
799                     v.z += (cc.rand() % (locRandRange * 2)) - locRandRange;
800                 this.setVertex(locP, v);
801             }
802         }
803     }
804 });
805 
806 /**
807  * creates the action with a range, shake Z vertices, a grid and duration
808  * @function
809  * @param {Number} duration
810  * @param {cc.Size} gridSize
811  * @param {Number} range
812  * @param {Boolean} shakeZ
813  * @return {cc.Shaky3D}
814  */
815 cc.shaky3D = function (duration, gridSize, range, shakeZ) {
816     return new cc.Shaky3D(duration, gridSize, range, shakeZ);
817 };
818 
819 /**
820  * Please use cc.shaky3D instead
821  * creates the action with a range, shake Z vertices, a grid and duration
822  * @param {Number} duration
823  * @param {cc.Size} gridSize
824  * @param {Number} range
825  * @param {Boolean} shakeZ
826  * @return {cc.Shaky3D}
827  * @static
828  * @deprecated since v3.0 <br /> Please use cc.shaky3D instead.
829  */
830 cc.Shaky3D.create = cc.shaky3D;
831 
832 /**
833  * cc.Liquid action. <br />
834  * Reference the test cases (Effects Test)
835  * @class
836  * @extends cc.Grid3DAction
837  * @param {Number} duration
838  * @param {cc.Size} gridSize
839  * @param {Number} waves
840  * @param {Number} amplitude
841  */
842 cc.Liquid = cc.Grid3DAction.extend(/** @lends cc.Liquid# */{
843     _waves: 0,
844     _amplitude: 0,
845     _amplitudeRate: 0,
846 
847 	/**
848      * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. <br />
849 	 * Create a liquid action with amplitude, a grid and duration.
850 	 * @param {Number} duration
851 	 * @param {cc.Size} gridSize
852 	 * @param {Number} waves
853 	 * @param {Number} amplitude
854 	 */
855     ctor: function (duration, gridSize, waves, amplitude) {
856         cc.GridAction.prototype.ctor.call(this);
857 		amplitude !== undefined && this.initWithDuration(duration, gridSize, waves, amplitude);
858     },
859 
860     /**
861      * get amplitude
862      * @return {Number}
863      */
864     getAmplitude:function () {
865         return this._amplitude;
866     },
867 
868     /**
869      * set amplitude
870      * @param {Number} amplitude
871      */
872     setAmplitude:function (amplitude) {
873         this._amplitude = amplitude;
874     },
875 
876     /**
877      * get amplitude rate
878      * @return {Number}
879      */
880     getAmplitudeRate:function () {
881         return this._amplitudeRate;
882     },
883 
884     /**
885      * set amplitude rate
886      * @param {Number} amplitudeRate
887      */
888     setAmplitudeRate:function (amplitudeRate) {
889         this._amplitudeRate = amplitudeRate;
890     },
891 
892     /**
893      * initializes the action with amplitude, a grid and duration
894      * @param {Number} duration
895      * @param {cc.Size} gridSize
896      * @param {Number} waves
897      * @param {Number} amplitude
898      * @return {Boolean}
899      */
900     initWithDuration:function (duration, gridSize, waves, amplitude) {
901         if (cc.Grid3DAction.prototype.initWithDuration.call(this, duration, gridSize)) {
902             this._waves = waves;
903             this._amplitude = amplitude;
904             this._amplitudeRate = 1.0;
905             return true;
906         }
907         return false;
908     },
909 
910     /**
911      * Called once per frame. Time is the number of seconds of a frame interval.
912      *
913      * @param {Number}  dt
914      */
915     update:function (dt) {
916         var locSizeWidth = this._gridSize.width, locSizeHeight = this._gridSize.height, locPos = cc.p(0, 0);
917         var locWaves = this._waves, locAmplitude = this._amplitude, locAmplitudeRate = this._amplitudeRate;
918         var v;
919         for (var i = 1; i < locSizeWidth; ++i) {
920             for (var j = 1; j < locSizeHeight; ++j) {
921                 locPos.x = i;
922                 locPos.y = j;
923                 v = this.originalVertex(locPos);
924                 v.x = (v.x + (Math.sin(dt * Math.PI * locWaves * 2 + v.x * .01) * locAmplitude * locAmplitudeRate));
925                 v.y = (v.y + (Math.sin(dt * Math.PI * locWaves * 2 + v.y * .01) * locAmplitude * locAmplitudeRate));
926                 this.setVertex(locPos, v);
927             }
928         }
929     }
930 });
931 
932 /**
933  * creates the action with amplitude, a grid and duration
934  * @function
935  * @param {Number} duration
936  * @param {cc.Size} gridSize
937  * @param {Number} waves
938  * @param {Number} amplitude
939  * @return {cc.Liquid}
940  */
941 cc.liquid = function (duration, gridSize, waves, amplitude) {
942     return new cc.Liquid(duration, gridSize, waves, amplitude);
943 };
944 
945 /**
946  * Please use cc.liquid instead
947  * creates the action with amplitude, a grid and duration
948  * @param {Number} duration
949  * @param {cc.Size} gridSize
950  * @param {Number} waves
951  * @param {Number} amplitude
952  * @return {cc.Liquid}
953  * @static
954  * @deprecated since v3.0 <br /> Please use cc.liquid instead.
955  */
956 cc.Liquid.create = cc.liquid;
957 
958 /**
959  * cc.Waves action. <br />
960  * Reference the test cases (Effects Test)
961  * @class
962  * @extends cc.Grid3DAction
963  * @param {Number} duration
964  * @param {cc.Size} gridSize
965  * @param {Number} waves
966  * @param {Number} amplitude
967  * @param {Boolean} horizontal
968  * @param {Boolean} vertical
969  */
970 cc.Waves = cc.Grid3DAction.extend(/** @lends cc.Waves# */{
971     _waves: 0,
972     _amplitude: 0,
973     _amplitudeRate: 0,
974     _vertical: false,
975     _horizontal: false,
976 
977 	/**
978      * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. <br />
979 	 * Create a wave action with amplitude, horizontal sin, vertical sin, a grid and duration.
980 	 * @param {Number} duration
981 	 * @param {cc.Size} gridSize
982 	 * @param {Number} waves
983 	 * @param {Number} amplitude
984 	 * @param {Boolean} horizontal
985 	 * @param {Boolean} vertical
986 	 */
987     ctor: function (duration, gridSize, waves, amplitude, horizontal, vertical) {
988         cc.GridAction.prototype.ctor.call(this);
989 		vertical !== undefined && this.initWithDuration(duration, gridSize, waves, amplitude, horizontal, vertical);
990     },
991 
992     /**
993      * get amplitude
994      * @return {Number}
995      */
996     getAmplitude:function () {
997         return this._amplitude;
998     },
999 
1000     /**
1001      * set amplitude
1002      * @param {Number} amplitude
1003      */
1004     setAmplitude:function (amplitude) {
1005         this._amplitude = amplitude;
1006     },
1007 
1008     /**
1009      * get amplitude rate
1010      * @return {Number}
1011      */
1012     getAmplitudeRate:function () {
1013         return this._amplitudeRate;
1014     },
1015 
1016     /**
1017      * set amplitude rate
1018      * @param {Number} amplitudeRate
1019      */
1020     setAmplitudeRate:function (amplitudeRate) {
1021         this._amplitudeRate = amplitudeRate;
1022     },
1023 
1024     /**
1025      * initializes the action with amplitude, horizontal sin, vertical sin, a grid and duration
1026      * @param {Number} duration
1027      * @param {cc.Size} gridSize
1028      * @param {Number} waves
1029      * @param {Number} amplitude
1030      * @param {Boolean} horizontal
1031      * @param {Boolean} vertical
1032      * @return {Boolean}
1033      */
1034     initWithDuration:function (duration, gridSize, waves, amplitude, horizontal, vertical) {
1035         if (cc.Grid3DAction.prototype.initWithDuration.call(this, duration, gridSize)) {
1036             this._waves = waves;
1037             this._amplitude = amplitude;
1038             this._amplitudeRate = 1.0;
1039             this._horizontal = horizontal;
1040             this._vertical = vertical;
1041             return true;
1042         }
1043         return false;
1044     },
1045 
1046     /**
1047      * Called once per frame. Time is the number of seconds of a frame interval.
1048      *
1049      * @param {Number}  dt
1050      */
1051     update:function (dt) {
1052         var locSizeWidth = this._gridSize.width, locSizeHeight = this._gridSize.height, locPos = cc.p(0, 0);
1053         var locVertical = this._vertical, locHorizontal = this._horizontal;
1054         var locWaves = this._waves, locAmplitude = this._amplitude, locAmplitudeRate = this._amplitudeRate;
1055         var v;
1056         for (var i = 0; i < locSizeWidth + 1; ++i) {
1057             for (var j = 0; j < locSizeHeight + 1; ++j) {
1058                 locPos.x = i;
1059                 locPos.y = j;
1060                 v = this.originalVertex(locPos);
1061                 if (locVertical)
1062                     v.x = (v.x + (Math.sin(dt * Math.PI * locWaves * 2 + v.y * .01) * locAmplitude * locAmplitudeRate));
1063                 if (locHorizontal)
1064                     v.y = (v.y + (Math.sin(dt * Math.PI * locWaves * 2 + v.x * .01) * locAmplitude * locAmplitudeRate));
1065                 this.setVertex(locPos, v);
1066             }
1067         }
1068     }
1069 });
1070 
1071 /**
1072  * initializes the action with amplitude, horizontal sin, vertical sin, a grid and duration
1073  * @function
1074  * @param {Number} duration
1075  * @param {cc.Size} gridSize
1076  * @param {Number} waves
1077  * @param {Number} amplitude
1078  * @param {Boolean} horizontal
1079  * @param {Boolean} vertical
1080  * @return {cc.Waves}
1081  */
1082 cc.waves = function (duration, gridSize, waves, amplitude, horizontal, vertical) {
1083     return new cc.Waves(duration, gridSize, waves, amplitude, horizontal, vertical);
1084 };
1085 
1086 /**
1087  * Please use cc.waves instead
1088  * initializes the action with amplitude, horizontal sin, vertical sin, a grid and duration
1089  * @param {Number} duration
1090  * @param {cc.Size} gridSize
1091  * @param {Number} waves
1092  * @param {Number} amplitude
1093  * @param {Boolean} horizontal
1094  * @param {Boolean} vertical
1095  * @return {cc.Waves}
1096  * @static
1097  * @deprecated since v3.0 <br /> Please use cc.waves instead.
1098  */
1099 cc.Waves.create = cc.waves;
1100 
1101 /** @brief  */
1102 /**
1103  * cc.Twirl action. <br />
1104  * Reference the test cases (Effects Test)
1105  * @class
1106  * @extends cc.Grid3DAction
1107  * @param {Number} duration
1108  * @param {cc.Size} gridSize
1109  * @param {cc.Point} position
1110  * @param {Number} twirls
1111  * @param {Number} amplitude
1112  */
1113 cc.Twirl = cc.Grid3DAction.extend(/** @lends cc.Twirl# */{
1114     /* twirl center */
1115     _position: null,
1116     _twirls: 0,
1117     _amplitude: 0,
1118     _amplitudeRate: 0,
1119 
1120 	/**
1121      * Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function. <br />
1122 	 * Create a grid 3d action with center position, number of twirls, amplitude, a grid size and duration.
1123 	 * @param {Number} duration
1124 	 * @param {cc.Size} gridSize
1125 	 * @param {cc.Point} position
1126 	 * @param {Number} twirls
1127 	 * @param {Number} amplitude
1128 	 */
1129     ctor:function (duration, gridSize, position, twirls, amplitude) {
1130         cc.GridAction.prototype.ctor.call(this);
1131 
1132         this._position = cc.p(0, 0);
1133 		amplitude !== undefined && this.initWithDuration(duration, gridSize, position, twirls, amplitude);
1134     },
1135 
1136     /**
1137      * get twirl center
1138      * @return {cc.Point}
1139      */
1140     getPosition:function () {
1141         return this._position;
1142     },
1143 
1144     /**
1145      * set twirl center
1146      * @param {cc.Point} position
1147      */
1148     setPosition:function (position) {
1149         this._position.x = position.x;
1150         this._position.y = position.y;
1151     },
1152 
1153     /**
1154      * get amplitude
1155      * @return {Number}
1156      */
1157     getAmplitude:function () {
1158         return this._amplitude;
1159     },
1160 
1161     /**
1162      * set amplitude
1163      * @param {Number} amplitude
1164      */
1165     setAmplitude:function (amplitude) {
1166         this._amplitude = amplitude;
1167     },
1168 
1169     /**
1170      * get amplitude rate
1171      * @return {Number}
1172      */
1173     getAmplitudeRate:function () {
1174         return this._amplitudeRate;
1175     },
1176 
1177     /**
1178      * set amplitude rate
1179      * @param {Number} amplitudeRate
1180      */
1181     setAmplitudeRate:function (amplitudeRate) {
1182         this._amplitudeRate = amplitudeRate;
1183     },
1184 
1185     /** initializes the action with center position, number of twirls, amplitude, a grid size and duration */
1186     initWithDuration:function (duration, gridSize, position, twirls, amplitude) {
1187         if (cc.Grid3DAction.prototype.initWithDuration.call(this, duration, gridSize)) {
1188             this.setPosition(position);
1189             this._twirls = twirls;
1190             this._amplitude = amplitude;
1191             this._amplitudeRate = 1.0;
1192             return true;
1193         }
1194         return false;
1195     },
1196 
1197     /**
1198      * Called once per frame. Time is the number of seconds of a frame interval.
1199      *
1200      * @param {Number}  dt
1201      */
1202     update:function (dt) {
1203         var c = this._position;
1204         var locSizeWidth = this._gridSize.width, locSizeHeight = this._gridSize.height, locPos = cc.p(0, 0);
1205         var amp = 0.1 * this._amplitude * this._amplitudeRate;
1206         var locTwirls = this._twirls;
1207         var v, a, dX, dY, avg = cc.p(0, 0);
1208         for (var i = 0; i < (locSizeWidth + 1); ++i) {
1209             for (var j = 0; j < (locSizeHeight + 1); ++j) {
1210                 locPos.x = i;
1211                 locPos.y = j;
1212                 v = this.originalVertex(locPos);
1213 
1214                 avg.x = i - (locSizeWidth / 2.0);
1215                 avg.y = j - (locSizeHeight / 2.0);
1216 
1217                 a = cc.pLength(avg) * Math.cos(Math.PI / 2.0 + dt * Math.PI * locTwirls * 2) * amp;
1218 
1219                 dX = Math.sin(a) * (v.y - c.y) + Math.cos(a) * (v.x - c.x);
1220                 dY = Math.cos(a) * (v.y - c.y) - Math.sin(a) * (v.x - c.x);
1221 
1222                 v.x = c.x + dX;
1223                 v.y = c.y + dY;
1224 
1225                 this.setVertex(locPos, v);
1226             }
1227         }
1228     }
1229 });
1230 
1231 /**
1232  * creates the action with center position, number of twirls, amplitude, a grid size and duration
1233  * @function
1234  * @param {Number} duration
1235  * @param {cc.Size} gridSize
1236  * @param {cc.Point} position
1237  * @param {Number} twirls
1238  * @param {Number} amplitude
1239  * @return {cc.Twirl}
1240  */
1241 cc.twirl = function (duration, gridSize, position, twirls, amplitude) {
1242     return new cc.Twirl(duration, gridSize, position, twirls, amplitude);
1243 };
1244 
1245 /**
1246  * Please use cc.twirl instead
1247  * creates the action with center position, number of twirls, amplitude, a grid size and duration
1248  * @param {Number} duration
1249  * @param {cc.Size} gridSize
1250  * @param {cc.Point} position
1251  * @param {Number} twirls
1252  * @param {Number} amplitude
1253  * @return {cc.Twirl}
1254  * @static
1255  * @deprecated since v3.0 <br /> Please use cc.twirl instead.
1256  */
1257 cc.Twirl.create = cc.twirl;