- Actor currentCube = mBoxes[actorIndex];
- ImageActor sideTile = mTiles[mContainerIndex][actorIndex];
- ImageActor frontTile = mTiles[mContainerIndex^1][actorIndex];
- if ( mFirstTransition && (!mIsToNextImage) ) // for the first transition, it is going to previous image
- {
- sideTile.SetRotation( Radian( angle), Vector3::YAXIS );
- }
- else if( !mChangeTurningDirection ) // reset rotation, translation and color
- {
- sideTile.MoveBy( resetTranslation );
- sideTile.SetRotation( Radian( angle), Vector3::YAXIS );
- }
- mAnimation.RotateTo( currentCube, Radian( -angle ), Vector3::YAXIS, AlphaFunctions::Linear );
- Vector3 position(currentCube.GetCurrentPosition());
- mAnimation.MoveTo(currentCube, Vector3( position.x*mDisplacementRatio, position.y, position.z ), AlphaFunctions::Bounce);
- mAnimation.ColorTo( frontTile, HALF_BRIGHTNESS, AlphaFunctions::EaseOut );
- mAnimation.ColorTo( sideTile, FULL_BRIGHTNESS, AlphaFunctions::EaseIn );
+ //rotate and translate the cube such that the edges remain in constant contact
+ //calculate the maximum distance the cube has to move when it the box has rotated 45 degrees
+ //ie distance from of centre of square to a vertex is given by:
+ // distance = width / sqrt(2)
+ //therefore the delta distance the cube should move is given by:
+ // delta_distance = ( width / 2 ) - distance
+ //re-arranging we get:
+ // delta_distance = ( width / 2 ) * ( sqrt(2) - 1 )
+ //accumulating over the length of the row we get:
+ // delta_distance_at_x = x * delta_distance;
+
+ float delta = (float)x * mTileSize.x * ( 1.4142f - 1.0f );
+
+ Vector3 position( mBoxes[ actorIndex ].GetCurrentPosition() );
+ mAnimation.AnimateTo( Property( mBoxes[ actorIndex ], Actor::Property::ORIENTATION ), Quaternion( Radian( angle ), Vector3::YAXIS ), AlphaFunction::LINEAR );
+ mAnimation.AnimateTo( Property( mBoxes[ actorIndex ], Actor::Property::POSITION_X ), position.x + delta, AlphaFunction::BOUNCE );
+
+ mAnimation.AnimateTo( Property( mCurrentTiles[ actorIndex ], Actor::Property::COLOR ), HALF_BRIGHTNESS, AlphaFunction::EASE_OUT );
+ mAnimation.AnimateTo( Property( mTargetTiles[ actorIndex ], Actor::Property::COLOR ), FULL_BRIGHTNESS, AlphaFunction::EASE_IN );