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"
30 CubeTransitionCrossEffect::CubeTransitionCrossEffect( unsigned int numRows, unsigned int numColumns )
31 : CubeTransitionEffect( numRows, numColumns ),
32 mDisplacementSpreadFactor( 0.008f )
36 Toolkit::CubeTransitionCrossEffect CubeTransitionCrossEffect::New(unsigned int numRows, unsigned int numColumns )
38 // Create the implementation
39 IntrusivePtr< CubeTransitionCrossEffect > internalCubeTransEffect = new CubeTransitionCrossEffect( numRows, numColumns );
41 // Pass ownership to CustomActor handle
42 Toolkit::CubeTransitionCrossEffect cubeTransEffect( *internalCubeTransEffect );
45 internalCubeTransEffect->Initialize();
47 return cubeTransEffect;
50 void CubeTransitionCrossEffect::OnInitialize()
53 for( unsigned int y = 0; y < mRows; y++ )
55 for( unsigned int x = y % 2; x < mColumns; x += 2 )
57 idx = y * mColumns + x;
60 for( unsigned int x = ( y + 1 ) % 2; x < mColumns; x += 2 )
62 idx = y * mColumns + x;
63 SetTargetRight( idx );
68 void CubeTransitionCrossEffect::OnStartTransition( Vector2 panPosition, Vector2 panDisplacement )
70 float angle = Math::PI_2;
73 if( panDisplacement.x < 0 )
75 for( unsigned int y = 0; y < mRows; y++ )
77 for( unsigned int x = y % 2; x < mColumns; x += 2 )
79 idx = y * mColumns + x;
82 for( unsigned int x = ( y + 1 ) % 2; x < mColumns; x += 2 )
84 idx = y * mColumns + x;
85 SetTargetRight( idx );
93 for( unsigned int y = 0; y < mRows; y++ )
95 for( unsigned int x = y % 2; x < mColumns; x += 2 )
97 idx = y * mColumns + x;
98 SetTargetBottom( idx );
100 for( unsigned int x = ( y + 1 ) % 2; x < mColumns; x += 2 )
102 idx = y * mColumns + x;
103 SetTargetLeft( idx );
108 const Vector2& size = Self().GetCurrentSize().GetVectorXY();
109 Vector2 halfSize = size * 0.5f;
110 //the centre to "explode" the tiles outwards from
111 Vector3 centre( halfSize.x, halfSize.y, -1.0f / mDisplacementSpreadFactor );
113 for( unsigned int y = 0; y < mRows; y++ )
115 for( unsigned int x = y%2; x < mColumns; x=x+2) // rotate vertically
117 idx = y*mColumns + x;
118 SetupAnimation( idx, x, y, -angle, Vector3::XAXIS, centre );
120 for( unsigned int x = (y+1)%2; x < mColumns; x=x+2) // rotate horizontally
122 idx = y*mColumns + x;
123 SetupAnimation( idx, x, y, angle, Vector3::YAXIS, centre );
131 void CubeTransitionCrossEffect::SetupAnimation( unsigned int actorIndex, unsigned int x, unsigned int y, float angle, const Vector3 axis, const Vector3& displacementCentre )
133 const Vector2& size = Self().GetCurrentSize().GetVectorXY();
134 Vector2 halfSize = size * 0.5f;
136 //the position of the centre of the front face tile
137 Vector3 position( halfSize.x * (2.0f * x + 1.0f) / mColumns, halfSize.y * (2.0f * y + 1.0f ) / mRows, 0.0f );
139 Vector3 direction = position - displacementCentre;
140 float length = direction.Length();
141 direction.Normalize();
143 float deltaLength = mCubeDisplacement / direction.z; //the length along the direction vector such that the projected direction onto the z axis is equal to mCubeDisplacement
145 Vector3 newPosition = ( direction * (length + deltaLength ) ) + displacementCentre;
146 Vector3 newLocalPosition = newPosition - position;
148 mAnimation.AnimateTo( Property( mBoxes[ actorIndex ], Actor::Property::ORIENTATION ), Quaternion( Radian( -angle ), axis ), AlphaFunction::EASE_IN_OUT_SINE );
149 mAnimation.AnimateTo( Property( mBoxes[ actorIndex ], Actor::Property::POSITION ), newLocalPosition, AlphaFunction::BOUNCE );
151 mAnimation.AnimateTo( Property( mCurrentTiles[ actorIndex ], Actor::Property::COLOR ), HALF_BRIGHTNESS, AlphaFunction::EASE_OUT );
152 mAnimation.AnimateTo( Property( mTargetTiles[ actorIndex ], Actor::Property::COLOR ), FULL_BRIGHTNESS, AlphaFunction::EASE_IN );
155 } // namespace Internal
157 } // namespace Toolkit