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"
27 CubeTransitionFoldEffect::CubeTransitionFoldEffect(unsigned int numRows, unsigned int numColumns)
28 : CubeTransitionEffect(numRows, numColumns)
32 Toolkit::CubeTransitionFoldEffect CubeTransitionFoldEffect::New(unsigned int numRows, unsigned int numColumns)
34 // Create the implementation
35 IntrusivePtr<CubeTransitionFoldEffect> internalCubeTransEffect = new CubeTransitionFoldEffect(numRows, numColumns);
37 // Pass ownership to CustomActor handle
38 Toolkit::CubeTransitionFoldEffect cubeTransEffect(*internalCubeTransEffect);
41 internalCubeTransEffect->Initialize();
43 return cubeTransEffect;
46 void CubeTransitionFoldEffect::OnInitialize()
49 for(unsigned int y = 0; y < mRows; y++)
52 for(unsigned int x = y % 2; x < mColumns; x = x + 2)
54 SetTargetLeft(idx + x);
56 for(unsigned int x = (y + 1) % 2; x < mColumns; x = x + 2)
58 SetTargetRight(idx + x);
63 void CubeTransitionFoldEffect::OnStartTransition(Vector2 panPosition, Vector2 panDisplacement)
65 float angle = Math::PI_2;
68 if(panDisplacement.x < 0)
70 for(unsigned int y = 0; y < mRows; y++)
73 for(unsigned int x = y % 2; x < mColumns; x = x + 2)
75 SetTargetLeft(idx + x);
77 for(unsigned int x = (y + 1) % 2; x < mColumns; x = x + 2)
79 SetTargetRight(idx + x);
87 for(unsigned int y = 0; y < mRows; y++)
90 for(unsigned int x = y % 2; x < mColumns; x = x + 2)
92 SetTargetRight(idx + x);
94 for(unsigned int x = (y + 1) % 2; x < mColumns; x = x + 2)
96 SetTargetLeft(idx + x);
101 for(unsigned int y = 0; y < mRows; y++)
104 for(unsigned int x = y % 2; x < mColumns; x = x + 2)
106 SetupAnimation(idx + x, x, angle);
108 for(unsigned int x = (y + 1) % 2; x < mColumns; x = x + 2)
110 SetupAnimation(idx + x, x, -angle);
118 void CubeTransitionFoldEffect::SetupAnimation(unsigned int actorIndex, unsigned int x, float angle)
120 //rotate and translate the cube such that the edges remain in constant contact
121 //calculate the maximum distance the cube has to move when it the box has rotated 45 degrees
122 //ie distance from of centre of square to a vertex is given by:
123 // distance = width / sqrt(2)
124 //therefore the delta distance the cube should move is given by:
125 // delta_distance = ( width / 2 ) - distance
126 //re-arranging we get:
127 // delta_distance = ( width / 2 ) * ( sqrt(2) - 1 )
128 //accumulating over the length of the row we get:
129 // delta_distance_at_x = x * delta_distance;
131 float delta = (float)x * mTileSize.x * (1.4142f - 1.0f);
133 Vector3 position(mBoxes[actorIndex].GetCurrentProperty<Vector3>(Actor::Property::POSITION));
134 mAnimation.AnimateTo(Property(mBoxes[actorIndex], Actor::Property::ORIENTATION), Quaternion(Radian(angle), Vector3::YAXIS), AlphaFunction::LINEAR);
135 mAnimation.AnimateTo(Property(mBoxes[actorIndex], Actor::Property::POSITION_X), position.x + delta, AlphaFunction::BOUNCE);
137 mAnimation.AnimateTo(Property(mCurrentTiles[actorIndex], Actor::Property::COLOR), HALF_BRIGHTNESS, AlphaFunction::EASE_OUT);
138 mAnimation.AnimateTo(Property(mTargetTiles[actorIndex], Actor::Property::COLOR), FULL_BRIGHTNESS, AlphaFunction::EASE_IN);
141 } // namespace Internal
143 } // namespace Toolkit