1 /**************************************************************************** 2 Copyright (c) 2010-2012 cocos2d-x.org 3 Copyright (c) 2008-2010 Ricardo Quesada 4 Copyright (c) 2011 Zynga 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 @brief This action simulates a page turn from the bottom right hand corner of the screen. 29 It's not much use by itself but is used by the PageTurnTransition. 30 31 Based on an original paper by L Hong et al. 32 http://www.parc.com/publication/1638/turning-pages-of-3d-electronic-books.html 33 34 @since v0.8.2 35 */ 36 37 cc.PageTurn3D = cc.Grid3DAction.extend({ 38 /* 39 * Update each tick 40 * Time is the percentage of the way through the duration 41 */ 42 update:function (time) { 43 var tt = Math.max(0, time - 0.25); 44 var deltaAy = (tt * tt * 500); 45 var ay = -100 - deltaAy; 46 47 var deltaTheta = -Math.PI / 2 * Math.sqrt(time); 48 var theta = /*0.01f */ +Math.PI / 2 + deltaTheta; 49 50 var sinTheta = Math.sin(theta); 51 var cosTheta = Math.cos(theta); 52 53 for (var i = 0; i <= this._gridSize.x; ++i) { 54 for (var j = 0; j <= this._gridSize.y; ++j) { 55 // Get original vertex 56 var p = this.originalVertex(cc.g(i, j)); 57 58 var R = Math.sqrt((p.x * p.x) + ((p.y - ay) * (p.y - ay))); 59 var r = R * sinTheta; 60 var alpha = Math.asin(p.x / R); 61 var beta = alpha / sinTheta; 62 var cosBeta = Math.cos(beta); 63 64 // If beta > PI then we've wrapped around the cone 65 // Reduce the radius to stop these points interfering with others 66 if (beta <= Math.PI) { 67 p.x = ( r * Math.sin(beta)); 68 } 69 else { 70 // Force X = 0 to stop wrapped 71 // points 72 p.x = 0; 73 } 74 75 p.y = ( R + ay - ( r * (1 - cosBeta) * sinTheta)); 76 77 // We scale z here to avoid the animation being 78 // too much bigger than the screen due to perspectve transform 79 p.z = (r * ( 1 - cosBeta ) * cosTheta) / 7;// "100" didn't work for 80 81 // Stop z coord from dropping beneath underlying page in a transition 82 // issue #751 83 if (p.z < 0.5) { 84 p.z = 0.5; 85 } 86 87 // Set new coords 88 this.setVertex(cc.g(i, j), p); 89 90 } 91 } 92 } 93 }); 94 95 /** create the action */ 96 cc.PageTurn3D.create = function (gridSize, time) { 97 var action = new cc.PageTurn3D(); 98 return action; 99 }; 100