X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Fpage-turn-view%2Fpage-turn-effect.cpp;h=1de017d3117831f714ad9c69fcd6a71f8039705b;hp=175d6d27f0997b06ee899c6f36337a77b893e24c;hb=f2039d47f9bed8104575da80a2ecf0bb6e37ff8d;hpb=f3e45e41c5f16ccc2538b283897ed6efb07e4ea9 diff --git a/dali-toolkit/internal/controls/page-turn-view/page-turn-effect.cpp b/dali-toolkit/internal/controls/page-turn-view/page-turn-effect.cpp index 175d6d2..1de017d 100644 --- a/dali-toolkit/internal/controls/page-turn-view/page-turn-effect.cpp +++ b/dali-toolkit/internal/controls/page-turn-view/page-turn-effect.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2021 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,25 +16,25 @@ */ // EXTERNAL INCLUDES -#include -#include #include +#include #include +#include // INTERNAL INCLUDES -#include #include #include +#include using namespace Dali; using namespace Dali::Toolkit; namespace { -const char * const PROPERTY_COMMON_PARAMETERS( "uCommonParameters" ); -const char * const PROPERTY_ORIGINAL_CENTER( "originalCenter" ); -const char * const PROPERTY_CURRENT_CENTER( "currentCenter" ); -} +const char* const PROPERTY_COMMON_PARAMETERS("uCommonParameters"); +const char* const PROPERTY_ORIGINAL_CENTER("originalCenter"); +const char* const PROPERTY_CURRENT_CENTER("currentCenter"); +} // namespace /** * This constraint updates the common parameter values used by every vertex. @@ -42,83 +42,84 @@ const char * const PROPERTY_CURRENT_CENTER( "currentCenter" ); */ struct CommonParametersConstraint { - CommonParametersConstraint( float pageHeight ) - : mPageHeight( pageHeight ) - {} + CommonParametersConstraint(float pageHeight) + : mPageHeight(pageHeight) + { + } - void operator()( Dali::Matrix& current, const PropertyInputContainer& inputs ) + void operator()(Dali::Matrix& current, const PropertyInputContainer& inputs) { const Vector2& originalCenter = inputs[0]->GetVector2(); - Vector2 currentCenter = inputs[1]->GetVector2(); + Vector2 currentCenter = inputs[1]->GetVector2(); // calculate the curve direction and the vanishing point // here, the vanishing point is the intersection of spine with the line passing through original center and vertical to curve direction - Vector2 curveDirection( currentCenter - originalCenter ); + Vector2 curveDirection(currentCenter - originalCenter); curveDirection.Normalize(); - if( fabs(curveDirection.y) < 0.01f) // eliminate the possibility of division by zero in the next step + if(fabs(curveDirection.y) < 0.01f) // eliminate the possibility of division by zero in the next step { curveDirection.y = 0.01f; } float vanishingPointY = originalCenter.y + curveDirection.x * originalCenter.x / curveDirection.y; - float curveEndY, cosTheta ,sinTheta ,translateX, translateY; + float curveEndY, cosTheta, sinTheta, translateX, translateY; // when the vanishing point is very far away, make it infinitely, in this case, the page bent horizontally const float THRESHOLD(20.0); - if( fabs(vanishingPointY-mPageHeight*0.5f) >= mPageHeight*THRESHOLD ) + if(fabs(vanishingPointY - mPageHeight * 0.5f) >= mPageHeight * THRESHOLD) { - curveDirection = Vector2(-1.f,0.f); + curveDirection = Vector2(-1.f, 0.f); currentCenter.y = originalCenter.y; - curveEndY = originalCenter.y; - cosTheta = 1.f; - sinTheta = 0.f; + curveEndY = originalCenter.y; + cosTheta = 1.f; + sinTheta = 0.f; translateX = currentCenter.x - originalCenter.x; translateY = vanishingPointY; } else { - curveEndY = currentCenter.y - curveDirection.y * (currentCenter.x/curveDirection.x) ; - Vector2 v1( currentCenter.x, currentCenter.y - vanishingPointY ); + curveEndY = currentCenter.y - curveDirection.y * (currentCenter.x / curveDirection.x); + Vector2 v1(currentCenter.x, currentCenter.y - vanishingPointY); v1.Normalize(); - Vector2 v2( originalCenter.x, originalCenter.y - vanishingPointY ); + Vector2 v2(originalCenter.x, originalCenter.y - vanishingPointY); v2.Normalize(); - cosTheta = v1.x*v2.x + v1.y*v2.y; - sinTheta = ( vanishingPointY > mPageHeight*0.5f ) ? sqrt(1.0-cosTheta*cosTheta) : -sqrt(1.0-cosTheta*cosTheta); - translateX = currentCenter.x - cosTheta*originalCenter.x - sinTheta*( originalCenter.y-vanishingPointY ); - translateY = currentCenter.y + sinTheta*originalCenter.x - cosTheta*( originalCenter.y-vanishingPointY ); + cosTheta = v1.x * v2.x + v1.y * v2.y; + sinTheta = (vanishingPointY > mPageHeight * 0.5f) ? sqrt(1.0 - cosTheta * cosTheta) : -sqrt(1.0 - cosTheta * cosTheta); + translateX = currentCenter.x - cosTheta * originalCenter.x - sinTheta * (originalCenter.y - vanishingPointY); + translateY = currentCenter.y + sinTheta * originalCenter.x - cosTheta * (originalCenter.y - vanishingPointY); } - float originalLength = fabs(originalCenter.x/curveDirection.x); - float currentLength = fabs(currentCenter.x/curveDirection.x); - float curveHeight = 0.45f*sqrt(originalLength*originalLength - currentLength*currentLength); + float originalLength = fabs(originalCenter.x / curveDirection.x); + float currentLength = fabs(currentCenter.x / curveDirection.x); + float curveHeight = 0.45f * sqrt(originalLength * originalLength - currentLength * currentLength); float* parameterArray = current.AsFloat(); - parameterArray[0] = cosTheta; - parameterArray[1] = -sinTheta; - parameterArray[2] = originalCenter.x; - parameterArray[3] = originalCenter.y; - parameterArray[4] = sinTheta; - parameterArray[5] = cosTheta; - parameterArray[6] = currentCenter.x; - parameterArray[7] = currentCenter.y; - parameterArray[8] = translateX; - parameterArray[9] = translateY; - parameterArray[10] = vanishingPointY; - parameterArray[11] = curveEndY; - parameterArray[12] = curveDirection.x; - parameterArray[13] = curveDirection.y; - parameterArray[14] = curveHeight; - parameterArray[15] = currentLength; + parameterArray[0] = cosTheta; + parameterArray[1] = -sinTheta; + parameterArray[2] = originalCenter.x; + parameterArray[3] = originalCenter.y; + parameterArray[4] = sinTheta; + parameterArray[5] = cosTheta; + parameterArray[6] = currentCenter.x; + parameterArray[7] = currentCenter.y; + parameterArray[8] = translateX; + parameterArray[9] = translateY; + parameterArray[10] = vanishingPointY; + parameterArray[11] = curveEndY; + parameterArray[12] = curveDirection.x; + parameterArray[13] = curveDirection.y; + parameterArray[14] = curveHeight; + parameterArray[15] = currentLength; } float mPageHeight; }; -void Dali::Toolkit::Internal::PageTurnApplyInternalConstraint( Actor& actor, float pageHeight ) +void Dali::Toolkit::Internal::PageTurnApplyInternalConstraint(Actor& actor, float pageHeight) { - Constraint constraint = Constraint::New( actor, actor.GetPropertyIndex( PROPERTY_COMMON_PARAMETERS ) , CommonParametersConstraint( pageHeight ) ); - constraint.AddSource( LocalSource( actor.GetPropertyIndex( PROPERTY_ORIGINAL_CENTER ) ) ); - constraint.AddSource( LocalSource( actor.GetPropertyIndex( PROPERTY_CURRENT_CENTER ) ) ); + Constraint constraint = Constraint::New(actor, actor.GetPropertyIndex(PROPERTY_COMMON_PARAMETERS), CommonParametersConstraint(pageHeight)); + constraint.AddSource(LocalSource(actor.GetPropertyIndex(PROPERTY_ORIGINAL_CENTER))); + constraint.AddSource(LocalSource(actor.GetPropertyIndex(PROPERTY_CURRENT_CENTER))); constraint.Apply(); } @@ -128,12 +129,11 @@ Property::Map Dali::Toolkit::Internal::CreatePageTurnEffect() Property::Map customShader; - customShader[ Toolkit::Visual::Shader::Property::VERTEX_SHADER ] = SHADER_PAGE_TURN_EFFECT_VERT.data(); - customShader[ Toolkit::Visual::Shader::Property::FRAGMENT_SHADER ] = SHADER_PAGE_TURN_EFFECT_FRAG.data(); - customShader[ Toolkit::Visual::Shader::Property::SUBDIVIDE_GRID_X ] = 20; - customShader[ Toolkit::Visual::Shader::Property::SUBDIVIDE_GRID_Y ] = 20; + customShader[Toolkit::Visual::Shader::Property::VERTEX_SHADER] = SHADER_PAGE_TURN_EFFECT_VERT.data(); + customShader[Toolkit::Visual::Shader::Property::FRAGMENT_SHADER] = SHADER_PAGE_TURN_EFFECT_FRAG.data(); + customShader[Toolkit::Visual::Shader::Property::SUBDIVIDE_GRID_X] = 20; + customShader[Toolkit::Visual::Shader::Property::SUBDIVIDE_GRID_Y] = 20; - map[ Toolkit::Visual::Property::SHADER ] = customShader; + map[Toolkit::Visual::Property::SHADER] = customShader; return map; - }