2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include "cube-transition-fold-effect-impl.h"
29 CubeTransitionFoldEffect::CubeTransitionFoldEffect( unsigned int numRows, unsigned int numColumns )
30 : CubeTransitionEffect( numRows, numColumns )
34 Toolkit::CubeTransitionFoldEffect CubeTransitionFoldEffect::New(unsigned int numRows, unsigned int numColumns )
36 // Create the implementation
37 IntrusivePtr< CubeTransitionFoldEffect > internalCubeTransEffect = new CubeTransitionFoldEffect( numRows, numColumns );
39 // Pass ownership to CustomActor handle
40 Toolkit::CubeTransitionFoldEffect cubeTransEffect( *internalCubeTransEffect );
43 internalCubeTransEffect->Initialize();
45 return cubeTransEffect;
48 void CubeTransitionFoldEffect::OnInitialize()
51 for( unsigned int y = 0; y < mRows; y++ )
54 for( unsigned int x = y%2; x < mColumns; x=x+2)
56 SetTargetLeft( idx + x );
58 for( unsigned int x = (y+1)%2; x < mColumns; x=x+2)
60 SetTargetRight( idx + x );
65 void CubeTransitionFoldEffect::OnStartTransition( Vector2 panPosition, Vector2 panDisplacement )
67 float angle = Math::PI_2;
70 if( panDisplacement.x < 0 )
72 for( unsigned int y = 0; y < mRows; y++ )
75 for( unsigned int x = y%2; x < mColumns; x=x+2)
77 SetTargetLeft( idx + x );
79 for( unsigned int x = (y+1)%2; x < mColumns; x=x+2)
81 SetTargetRight( idx + x );
89 for( unsigned int y = 0; y < mRows; y++ )
92 for( unsigned int x = y%2; x < mColumns; x=x+2)
94 SetTargetRight( idx + x );
96 for( unsigned int x = (y+1)%2; x < mColumns; x=x+2)
98 SetTargetLeft( idx + x );
103 for( unsigned int y = 0; y < mRows; y++ )
106 for( unsigned int x = y%2; x < mColumns; x=x+2)
108 SetupAnimation( idx + x, x, angle );
110 for( unsigned int x = (y+1)%2; x < mColumns; x=x+2)
112 SetupAnimation( idx + x, x, -angle );
120 void CubeTransitionFoldEffect::SetupAnimation( unsigned int actorIndex, unsigned int x, float angle )
122 //rotate and translate the cube such that the edges remain in constant contact
123 //calculate the maximum distance the cube has to move when it the box has rotated 45 degrees
124 //ie distance from of centre of square to a vertex is given by:
125 // distance = width / sqrt(2)
126 //therefore the delta distance the cube should move is given by:
127 // delta_distance = ( width / 2 ) - distance
128 //re-arranging we get:
129 // delta_distance = ( width / 2 ) * ( sqrt(2) - 1 )
130 //accumulating over the length of the row we get:
131 // delta_distance_at_x = x * delta_distance;
133 float delta = (float)x * mTileSize.x * ( 1.4142f - 1.0f );
135 Vector3 position( mBoxes[ actorIndex ].GetCurrentPosition() );
136 mAnimation.AnimateTo( Property( mBoxes[ actorIndex ], Actor::Property::ORIENTATION ), Quaternion( Radian( angle ), Vector3::YAXIS ), AlphaFunction::LINEAR );
137 mAnimation.AnimateTo( Property( mBoxes[ actorIndex ], Actor::Property::POSITION_X ), position.x + delta, AlphaFunction::BOUNCE );
139 mAnimation.AnimateTo( Property( mCurrentTiles[ actorIndex ], Actor::Property::COLOR ), HALF_BRIGHTNESS, AlphaFunction::EASE_OUT );
140 mAnimation.AnimateTo( Property( mTargetTiles[ actorIndex ], Actor::Property::COLOR ), FULL_BRIGHTNESS, AlphaFunction::EASE_IN );
143 } // namespace Internal
145 } // namespace Toolkit