2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
17 #include <dali-toolkit/public-api/shader-effects/carousel-effect.h>
28 const std::string RADIUS_PROPERTY_NAME( "uRadius" );
29 const std::string ANGLE_PER_UNIT_PROPERTY_NAME( "uAnglePerUnit" );
30 const std::string CENTER_PROPERTY_NAME( "uCenter" );
34 CarouselEffect::CarouselEffect()
38 //Call the Parent copy constructor to add reference to the implementation for this object
39 CarouselEffect::CarouselEffect(ShaderEffect handle)
44 CarouselEffect::~CarouselEffect()
49 CarouselEffect CarouselEffect::New()
51 // append the default version
52 std::string vertexShader(
53 "uniform float uRadius;\n"
54 "uniform mediump vec2 uCenter;\n"
55 "uniform mediump vec2 uAnglePerUnit;\n"
59 " vec4 world = uModelView * vec4(aPosition,1.0);\n"
60 " vec2 d = (world.xy - uCenter) * uAnglePerUnit;\n"
61 " float a = length(d);\n"
62 " float cs = cos(radians(a));\n"
63 " world.z += cs * uRadius;\n"
64 " gl_Position = uProjection * world;\n"
66 " vTexCoord = aTexCoord;\n"
69 ShaderEffect shaderEffectCustom = ShaderEffect::New(vertexShader,
71 GeometryType( GEOMETRY_TYPE_IMAGE | GEOMETRY_TYPE_TEXT ),
72 ShaderEffect::GeometryHints( ShaderEffect::HINT_GRID | ShaderEffect::HINT_DEPTH_BUFFER ));
74 // Pass ownership to CarouselEffect through overloaded constructor, So that it now has access to the
75 // Dali::ShaderEffect implementation
76 CarouselEffect handle( shaderEffectCustom );
78 handle.SetUniform( RADIUS_PROPERTY_NAME, 0.0f );
79 handle.SetUniform( CENTER_PROPERTY_NAME, Vector2( 0.0f, 0.0f ) );
80 handle.SetUniform( ANGLE_PER_UNIT_PROPERTY_NAME, Vector2( 0.0f, 0.0f ) );
85 void CarouselEffect::SetRadius( float radius)
87 SetUniform( RADIUS_PROPERTY_NAME, radius );
90 void CarouselEffect::SetCenter( const Vector2& center )
92 SetUniform( CENTER_PROPERTY_NAME, center );
95 void CarouselEffect::SetAnglePerUnit( const Vector2& angle )
97 SetUniform( ANGLE_PER_UNIT_PROPERTY_NAME, angle );
100 const std::string& CarouselEffect::GetRadiusPropertyName() const
102 return RADIUS_PROPERTY_NAME;
105 const std::string& CarouselEffect::GetCenterPropertyName() const
107 return CENTER_PROPERTY_NAME;
110 const std::string& CarouselEffect::GetAnglePerUnitPropertyName() const
112 return ANGLE_PER_UNIT_PROPERTY_NAME;
115 } // namespace Toolkit