2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <dali-toolkit/public-api/shader-effects/carousel-effect.h>
29 const std::string RADIUS_PROPERTY_NAME( "uRadius" );
30 const std::string ANGLE_PER_UNIT_PROPERTY_NAME( "uAnglePerUnit" );
31 const std::string CENTER_PROPERTY_NAME( "uCenter" );
35 CarouselEffect::CarouselEffect()
39 //Call the Parent copy constructor to add reference to the implementation for this object
40 CarouselEffect::CarouselEffect(ShaderEffect handle)
45 CarouselEffect::~CarouselEffect()
50 CarouselEffect CarouselEffect::New()
52 // append the default version
53 std::string vertexShader(
54 "uniform float uRadius;\n"
55 "uniform mediump vec2 uCenter;\n"
56 "uniform mediump vec2 uAnglePerUnit;\n"
60 " mediump vec4 world = uModelView * vec4(aPosition,1.0);\n"
61 " mediump vec2 d = (world.xy - uCenter) * uAnglePerUnit;\n"
62 " mediump float a = length(d);\n"
63 " mediump float cs = cos(radians(a));\n"
64 " world.z -= cs * uRadius;\n"
65 " gl_Position = uProjection * world;\n"
67 " vTexCoord = aTexCoord;\n"
70 ShaderEffect shaderEffectCustom = ShaderEffect::New(vertexShader,
72 GeometryType( GEOMETRY_TYPE_IMAGE ),
73 ShaderEffect::GeometryHints( ShaderEffect::HINT_GRID | ShaderEffect::HINT_DEPTH_BUFFER ));
75 // Pass ownership to CarouselEffect through overloaded constructor, So that it now has access to the
76 // Dali::ShaderEffect implementation
77 CarouselEffect handle( shaderEffectCustom );
79 handle.SetUniform( RADIUS_PROPERTY_NAME, 0.0f );
80 handle.SetUniform( CENTER_PROPERTY_NAME, Vector2( 0.0f, 0.0f ) );
81 handle.SetUniform( ANGLE_PER_UNIT_PROPERTY_NAME, Vector2( 0.0f, 0.0f ) );
86 void CarouselEffect::SetRadius( float radius)
88 SetUniform( RADIUS_PROPERTY_NAME, radius );
91 void CarouselEffect::SetCenter( const Vector2& center )
93 SetUniform( CENTER_PROPERTY_NAME, center );
96 void CarouselEffect::SetAnglePerUnit( const Vector2& angle )
98 SetUniform( ANGLE_PER_UNIT_PROPERTY_NAME, angle );
101 const std::string& CarouselEffect::GetRadiusPropertyName() const
103 return RADIUS_PROPERTY_NAME;
106 const std::string& CarouselEffect::GetCenterPropertyName() const
108 return CENTER_PROPERTY_NAME;
111 const std::string& CarouselEffect::GetAnglePerUnitPropertyName() const
113 return ANGLE_PER_UNIT_PROPERTY_NAME;
116 } // namespace Toolkit