- 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.SetOrientation( Radian( angle), Vector3::YAXIS );
- }
- else if( !mChangeTurningDirection ) // reset rotation, translation and color
- {
- sideTile.TranslateBy( resetTranslation );
- sideTile.SetOrientation( Radian( angle), Vector3::YAXIS );
- }
- mAnimation.AnimateTo( Property( currentCube, Actor::Property::ORIENTATION ), Quaternion( Radian( -angle ), Vector3::YAXIS ), AlphaFunction::LINEAR );
- Vector3 position(currentCube.GetCurrentPosition());
- mAnimation.AnimateTo( Property( currentCube, Actor::Property::POSITION ), Vector3( position.x*mDisplacementRatio, position.y, position.z ), AlphaFunction::BOUNCE );
- mAnimation.AnimateTo( Property( frontTile, Actor::Property::COLOR ), HALF_BRIGHTNESS, AlphaFunction::EASE_OUT );
- mAnimation.AnimateTo( Property( sideTile, Actor::Property::COLOR ), FULL_BRIGHTNESS, AlphaFunction::EASE_IN );
+ //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].GetCurrentProperty<Vector3>(Actor::Property::POSITION));
+ 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);