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 * <p> 29 * This action simulates a page turn from the bottom right hand corner of the screen. <br/> 30 * It's not much use by itself but is used by the PageTurnTransition. <br/> 31 * <br/> 32 * Based on an original paper by L Hong et al. <br/> 33 * http://www.parc.com/publication/1638/turning-pages-of-3d-electronic-books.html 34 * </p> 35 * @class 36 * @extends cc.Grid3DAction 37 */ 38 cc.PageTurn3D = cc.Grid3DAction.extend(/** @lends cc.PageTurn3D# */{ 39 getGrid: function(){ 40 var result = new cc.Grid3D(this._gridSize); 41 result.setNeedDepthTestForBlit(true); 42 return result; 43 }, 44 45 clone: function(){ 46 var ret = new cc.PageTurn3D(); 47 ret.initWithDuration(this._duration, this._gridSize); 48 return ret; 49 }, 50 51 /** 52 * Update each tick <br/> 53 * Time is the percentage of the way through the duration 54 */ 55 update:function (time) { 56 var tt = Math.max(0, time - 0.25); 57 var deltaAy = (tt * tt * 500); 58 var ay = -100 - deltaAy; 59 60 var deltaTheta = -Math.PI / 2 * Math.sqrt(time); 61 var theta = /*0.01f */ +Math.PI / 2 + deltaTheta; 62 63 var sinTheta = Math.sin(theta); 64 var cosTheta = Math.cos(theta); 65 66 var locGridSize = this._gridSize; 67 var locVer = cc.p(0, 0); 68 for (var i = 0; i <= locGridSize.width; ++i) { 69 for (var j = 0; j <= locGridSize.height; ++j) { 70 locVer.x = i; 71 locVer.y = j; 72 // Get original vertex 73 var p = this.getOriginalVertex(locVer); 74 75 var R = Math.sqrt((p.x * p.x) + ((p.y - ay) * (p.y - ay))); 76 var r = R * sinTheta; 77 var alpha = Math.asin(p.x / R); 78 var beta = alpha / sinTheta; 79 var cosBeta = Math.cos(beta); 80 81 // If beta > PI then we've wrapped around the cone 82 // Reduce the radius to stop these points interfering with others 83 if (beta <= Math.PI) 84 p.x = ( r * Math.sin(beta)); 85 else 86 p.x = 0; //Force X = 0 to stop wrapped points 87 88 p.y = ( R + ay - ( r * (1 - cosBeta) * sinTheta)); 89 90 // We scale z here to avoid the animation being 91 // too much bigger than the screen due to perspectve transform 92 p.z = (r * ( 1 - cosBeta ) * cosTheta) / 7;// "100" didn't work for 93 94 // Stop z coord from dropping beneath underlying page in a transition 95 // issue #751 96 if (p.z < 0.5) 97 p.z = 0.5; 98 99 // Set new coords 100 this.setVertex(locVer, p); 101 } 102 } 103 } 104 }); 105 106 /** 107 * create PageTurn3D action 108 * @function 109 * @param {Number} duration 110 * @param {cc.Size} gridSize 111 * @return {cc.PageTurn3D} 112 */ 113 cc.pageTurn3D = function (duration, gridSize) { 114 return new cc.PageTurn3D(duration, gridSize); 115 }; 116 /** 117 * Please use cc.pageTurn3D instead 118 * create PageTurn3D action 119 * @param {Number} duration 120 * @param {cc.Size} gridSize 121 * @return {cc.PageTurn3D} 122 * @static 123 * @deprecated since v3.0 please use cc.pageTurn3D instead. 124 */ 125 cc.PageTurn3D.create = cc.pageTurn3D;