X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;ds=sidebyside;f=dali-toolkit%2Finternal%2Fshader-effects%2Fpage-turn-effect-impl.cpp;h=732bbf9f3273d5003b48b45d7db2feef79cc005e;hb=2b4be89fbaad622c93c957ad425a485ba0cc8bd4;hp=275356fbb96b11086ffe4debfe83415a9955ca90;hpb=e2eda444afbe82e9591fe198eef339227f90a616;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-toolkit/internal/shader-effects/page-turn-effect-impl.cpp b/dali-toolkit/internal/shader-effects/page-turn-effect-impl.cpp index 275356f..732bbf9 100644 --- a/dali-toolkit/internal/shader-effects/page-turn-effect-impl.cpp +++ b/dali-toolkit/internal/shader-effects/page-turn-effect-impl.cpp @@ -1,25 +1,27 @@ -// -// Copyright (c) 2014 Samsung Electronics Co., Ltd. -// -// Licensed under the Flora License, Version 1.0 (the License); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://floralicense.org/license/ -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an AS IS BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// +/* + * Copyright (c) 2014 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ // CLASS HEADER #include "page-turn-effect-impl.h" // EXTERNAL HEADERS #include - +#include +#include namespace Dali { @@ -51,83 +53,76 @@ const Vector2 DEFAULT_SPINE_SHADOW_PARAMETER(50.0f, 20.0f); // when the vanishing point is very far away(pageHeight*THRESHOLD), make it infinitely, in this case, the page bent horizontally const float THRESHOLD(20.0); -struct CommonParametersConstraint +void CommonParametersConstraint( Matrix& current, const PropertyInputContainer& inputs ) { - Matrix operator()( const Matrix& current, - const PropertyInput& originalCenterProperty, - const PropertyInput& currentCenterProperty, - const PropertyInput& pageSizeProperty) + const Vector2& originalCenter = inputs[0]->GetVector2(); + Vector2 currentCenter = inputs[1]->GetVector2(); + const Vector2& pageSize = inputs[2]->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 ); + curveDirection.Normalize(); + if( fabs(curveDirection.y) < 0.01f) // eliminate the possibility of division by zero in the next step { - const Vector2& originalCenter = originalCenterProperty.GetVector2(); - Vector2 currentCenter = currentCenterProperty.GetVector2(); - const Vector2& pageSize = pageSizeProperty.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 ); - curveDirection.Normalize(); - 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; - // when the vanishing point is very far away, make it infinitely, in this case, the page bent horizontally - if( fabs(vanishingPointY-pageSize.y*0.5f) >= pageSize.y*THRESHOLD ) - { - curveDirection = Vector2(-1.f,0.f); - currentCenter.y = originalCenter.y; - - 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 ); - v1.Normalize(); - Vector2 v2( originalCenter.x, originalCenter.y - vanishingPointY ); - v2.Normalize(); - cosTheta = v1.x*v2.x + v1.y*v2.y; - sinTheta = ( vanishingPointY > pageSize.y*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 ); - } + curveDirection.y = 0.01f; + } + float vanishingPointY = originalCenter.y + curveDirection.x * originalCenter.x / curveDirection.y; - float originalLength = fabs(originalCenter.x/curveDirection.x); - float currentLength = fabs(currentCenter.x/curveDirection.x); - float curveHeight = 0.45f*sqrt(originalLength*originalLength - currentLength*currentLength); - - Matrix commonParameters( false ); - float* parameterArray = commonParameters.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; - - return commonParameters; + float curveEndY, cosTheta ,sinTheta ,translateX, translateY; + // when the vanishing point is very far away, make it infinitely, in this case, the page bent horizontally + if( fabs(vanishingPointY-pageSize.y*0.5f) >= pageSize.y*THRESHOLD ) + { + curveDirection = Vector2(-1.f,0.f); + currentCenter.y = originalCenter.y; + + 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 ); + v1.Normalize(); + Vector2 v2( originalCenter.x, originalCenter.y - vanishingPointY ); + v2.Normalize(); + cosTheta = v1.x*v2.x + v1.y*v2.y; + sinTheta = ( vanishingPointY > pageSize.y*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* 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; +} }//namespace PageTurnEffect::PageTurnEffect() +: mOriginalCenterPropertyIndex(Property::INVALID_INDEX), + mCurrentCenterPropertyIndex(Property::INVALID_INDEX) { } @@ -155,6 +150,7 @@ Toolkit::PageTurnEffect PageTurnEffect::CreateShaderEffect( bool enableBlending * ([3][2]) float curveHeight: The height of the interpolated hermite curve. * ([3][3]) float currentLength: The length from the current center to the curveEnd. */ + precision mediump float;\n uniform mat4 uCommonParameters;\n \n uniform vec2 uPageSize;\n @@ -318,6 +314,7 @@ Toolkit::PageTurnEffect PageTurnEffect::CreateShaderEffect( bool enableBlending std::string vertexShaderEnd("}"); std::string fragmentShaderPartOne = MAKE_STRING( + precision mediump float;\n uniform vec2 uPageSize;\n uniform vec2 uSpineShadowParameter;\n varying vec3 vNormal;\n @@ -394,12 +391,8 @@ Toolkit::PageTurnEffect PageTurnEffect::CreateShaderEffect( bool enableBlending shaderImpl->mOriginalCenterPropertyIndex = handle.RegisterProperty( ORIGINAL_CENTER_PROPERTY_NAME, Vector2( defaultPageSize[0], defaultPageSize[1]*0.5f ) ); shaderImpl->mCurrentCenterPropertyIndex = handle.RegisterProperty( CURRENT_CENTER_PROPERTY_NAME, Vector2( defaultPageSize[0], defaultPageSize[1]*0.5f ) ); - shaderImpl->mInternalConstraint = Constraint::New( handle.GetPropertyIndex( "uCommonParameters" ), - LocalSource( shaderImpl->mOriginalCenterPropertyIndex ), - LocalSource( shaderImpl->mCurrentCenterPropertyIndex ), - LocalSource( handle.GetPropertyIndex( PAGE_SIZE_PROPERTY_NAME ) ), - CommonParametersConstraint() ); - handle.ApplyConstraint( shaderImpl->mInternalConstraint ); + + shaderImpl->ApplyInternalConstraint(); // setting isTurningBack to -1.0f here means turning page forward handle.SetUniform( IS_TURNING_BACK_PROPERTY_NAME, -1.0f ); @@ -440,7 +433,11 @@ void PageTurnEffect::SetSpineShadowParameter(const Vector2& spineShadowParameter void PageTurnEffect::ApplyInternalConstraint() { - mShaderEffect.ApplyConstraint( mInternalConstraint ); + Constraint constraint = Constraint::New( mShaderEffect, mShaderEffect.GetPropertyIndex( "uCommonParameters" ), CommonParametersConstraint ); + constraint.AddSource( LocalSource( mOriginalCenterPropertyIndex ) ); + constraint.AddSource( LocalSource( mCurrentCenterPropertyIndex ) ); + constraint.AddSource( LocalSource( mShaderEffect.GetPropertyIndex( PAGE_SIZE_PROPERTY_NAME ) ) ); + constraint.Apply(); } const std::string& PageTurnEffect::GetPageSizePropertyName() const