diff options
| author | Starla Insigna <starla4444@gmail.com> | 2011-07-30 11:19:14 -0400 |
|---|---|---|
| committer | Starla Insigna <starla4444@gmail.com> | 2011-07-30 11:19:14 -0400 |
| commit | 9cd57b731ab1c666d4a1cb725538fdc137763d12 (patch) | |
| tree | 5bac45ae5157a1cb10c6e45500cbf72789917980 /libs/cocos2d/CCActionPageTurn3D.m | |
| download | cartcollect-9cd57b731ab1c666d4a1cb725538fdc137763d12.tar.gz cartcollect-9cd57b731ab1c666d4a1cb725538fdc137763d12.tar.bz2 cartcollect-9cd57b731ab1c666d4a1cb725538fdc137763d12.zip | |
Initial commit (version 0.2.1)
Diffstat (limited to 'libs/cocos2d/CCActionPageTurn3D.m')
| -rwxr-xr-x | libs/cocos2d/CCActionPageTurn3D.m | 86 |
1 files changed, 86 insertions, 0 deletions
| diff --git a/libs/cocos2d/CCActionPageTurn3D.m b/libs/cocos2d/CCActionPageTurn3D.m new file mode 100755 index 0000000..ee59500 --- /dev/null +++ b/libs/cocos2d/CCActionPageTurn3D.m | |||
| @@ -0,0 +1,86 @@ | |||
| 1 | /* | ||
| 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org | ||
| 3 | * | ||
| 4 | * Copyright (c) 2009 Sindesso Pty Ltd http://www.sindesso.com/ | ||
| 5 | * | ||
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| 7 | * of this software and associated documentation files (the "Software"), to deal | ||
| 8 | * in the Software without restriction, including without limitation the rights | ||
| 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| 10 | * copies of the Software, and to permit persons to whom the Software is | ||
| 11 | * furnished to do so, subject to the following conditions: | ||
| 12 | * | ||
| 13 | * The above copyright notice and this permission notice shall be included in | ||
| 14 | * all copies or substantial portions of the Software. | ||
| 15 | * | ||
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| 22 | * THE SOFTWARE. | ||
| 23 | * | ||
| 24 | */ | ||
| 25 | |||
| 26 | #import "CCActionPageTurn3D.h" | ||
| 27 | |||
| 28 | @implementation CCPageTurn3D | ||
| 29 | |||
| 30 | /* | ||
| 31 | * Update each tick | ||
| 32 | * Time is the percentage of the way through the duration | ||
| 33 | */ | ||
| 34 | -(void)update:(ccTime)time | ||
| 35 | { | ||
| 36 | float tt = MAX( 0, time - 0.25f ); | ||
| 37 | float deltaAy = ( tt * tt * 500); | ||
| 38 | float ay = -100 - deltaAy; | ||
| 39 | |||
| 40 | float deltaTheta = - (float) M_PI_2 * sqrtf( time) ; | ||
| 41 | float theta = /*0.01f*/ + (float) M_PI_2 +deltaTheta; | ||
| 42 | |||
| 43 | float sinTheta = sinf(theta); | ||
| 44 | float cosTheta = cosf(theta); | ||
| 45 | |||
| 46 | for( int i = 0; i <=gridSize_.x; i++ ) | ||
| 47 | { | ||
| 48 | for( int j = 0; j <= gridSize_.y; j++ ) | ||
| 49 | { | ||
| 50 | // Get original vertex | ||
| 51 | ccVertex3F p = [self originalVertex:ccg(i,j)]; | ||
| 52 | |||
| 53 | float R = sqrtf(p.x*p.x + (p.y - ay) * (p.y - ay)); | ||
| 54 | float r = R * sinTheta; | ||
| 55 | float alpha = asinf( p.x / R ); | ||
| 56 | float beta = alpha / sinTheta; | ||
| 57 | float cosBeta = cosf( beta ); | ||
| 58 | |||
| 59 | // If beta > PI then we've wrapped around the cone | ||
| 60 | // Reduce the radius to stop these points interfering with others | ||
| 61 | if( beta <= M_PI) | ||
| 62 | p.x = ( r * sinf(beta)); | ||
| 63 | else | ||
| 64 | { | ||
| 65 | // Force X = 0 to stop wrapped | ||
| 66 | // points | ||
| 67 | p.x = 0; | ||
| 68 | } | ||
| 69 | |||
| 70 | p.y = ( R + ay - ( r*(1 - cosBeta)*sinTheta)); | ||
| 71 | |||
| 72 | // We scale z here to avoid the animation being | ||
| 73 | // too much bigger than the screen due to perspectve transform | ||
| 74 | p.z = (r * ( 1 - cosBeta ) * cosTheta) / 7; // "100" didn't work for | ||
| 75 | |||
| 76 | // Stop z coord from dropping beneath underlying page in a transition | ||
| 77 | // issue #751 | ||
| 78 | if( p.z<0.5f ) | ||
| 79 | p.z = 0.5f; | ||
| 80 | |||
| 81 | // Set new coords | ||
| 82 | [self setVertex:ccg(i,j) vertex:p]; | ||
| 83 | } | ||
| 84 | } | ||
| 85 | } | ||
| 86 | @end | ||
