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-cross-effect-impl.h"
27 CubeTransitionCrossEffect::CubeTransitionCrossEffect(unsigned int numRows, unsigned int numColumns)
28 : CubeTransitionEffect(numRows, numColumns),
29 mDisplacementSpreadFactor(0.008f)
33 Toolkit::CubeTransitionCrossEffect CubeTransitionCrossEffect::New(unsigned int numRows, unsigned int numColumns)
35 // Create the implementation
36 IntrusivePtr<CubeTransitionCrossEffect> internalCubeTransEffect = new CubeTransitionCrossEffect(numRows, numColumns);
38 // Pass ownership to CustomActor handle
39 Toolkit::CubeTransitionCrossEffect cubeTransEffect(*internalCubeTransEffect);
42 internalCubeTransEffect->Initialize();
44 return cubeTransEffect;
47 void CubeTransitionCrossEffect::OnInitialize()
50 for(unsigned int y = 0; y < mRows; y++)
52 for(unsigned int x = y % 2; x < mColumns; x += 2)
54 idx = y * mColumns + x;
57 for(unsigned int x = (y + 1) % 2; x < mColumns; x += 2)
59 idx = y * mColumns + x;
65 void CubeTransitionCrossEffect::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++)
74 for(unsigned int x = y % 2; x < mColumns; x += 2)
76 idx = y * mColumns + x;
79 for(unsigned int x = (y + 1) % 2; x < mColumns; x += 2)
81 idx = y * mColumns + x;
90 for(unsigned int y = 0; y < mRows; y++)
92 for(unsigned int x = y % 2; x < mColumns; x += 2)
94 idx = y * mColumns + x;
97 for(unsigned int x = (y + 1) % 2; x < mColumns; x += 2)
99 idx = y * mColumns + x;
105 const Vector2 halfSize = Self().GetCurrentProperty<Vector3>(Actor::Property::SIZE).GetVectorXY() * 0.5f;
106 //the centre to "explode" the tiles outwards from
107 Vector3 centre(halfSize.x, halfSize.y, -1.0f / mDisplacementSpreadFactor);
109 for(unsigned int y = 0; y < mRows; y++)
111 for(unsigned int x = y % 2; x < mColumns; x = x + 2) // rotate vertically
113 idx = y * mColumns + x;
114 SetupAnimation(idx, x, y, -angle, Vector3::XAXIS, centre);
116 for(unsigned int x = (y + 1) % 2; x < mColumns; x = x + 2) // rotate horizontally
118 idx = y * mColumns + x;
119 SetupAnimation(idx, x, y, angle, Vector3::YAXIS, centre);
127 void CubeTransitionCrossEffect::SetupAnimation(unsigned int actorIndex, unsigned int x, unsigned int y, float angle, const Vector3 axis, const Vector3& displacementCentre)
129 const Vector2 size = Self().GetCurrentProperty<Vector3>(Actor::Property::SIZE).GetVectorXY();
130 Vector2 halfSize = size * 0.5f;
132 //the position of the centre of the front face tile
133 Vector3 position(halfSize.x * (2.0f * x + 1.0f) / mColumns, halfSize.y * (2.0f * y + 1.0f) / mRows, 0.0f);
135 Vector3 direction = position - displacementCentre;
136 float length = direction.Length();
137 direction.Normalize();
139 float deltaLength = mCubeDisplacement / direction.z; //the length along the direction vector such that the projected direction onto the z axis is equal to mCubeDisplacement
141 Vector3 newPosition = (direction * (length + deltaLength)) + displacementCentre;
142 Vector3 newLocalPosition = newPosition - position;
144 mAnimation.AnimateTo(Property(mBoxes[actorIndex], Actor::Property::ORIENTATION), Quaternion(Radian(-angle), axis), AlphaFunction::EASE_IN_OUT_SINE);
145 mAnimation.AnimateTo(Property(mBoxes[actorIndex], Actor::Property::POSITION), newLocalPosition, AlphaFunction::BOUNCE);
147 mAnimation.AnimateTo(Property(mCurrentTiles[actorIndex], Actor::Property::COLOR), HALF_BRIGHTNESS, AlphaFunction::EASE_OUT);
148 mAnimation.AnimateTo(Property(mTargetTiles[actorIndex], Actor::Property::COLOR), FULL_BRIGHTNESS, AlphaFunction::EASE_IN);
151 } // namespace Internal
153 } // namespace Toolkit