Fix issues related with cameras.
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / public-api / shader-effects / carousel-effect.cpp
1 //
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://floralicense.org/license/
9 //
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.
15 //
16
17 #include <dali-toolkit/public-api/shader-effects/carousel-effect.h>
18
19 namespace Dali
20 {
21
22 namespace Toolkit
23 {
24
25 namespace
26 {
27
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" );
31
32 } // namespace
33
34 CarouselEffect::CarouselEffect()
35 {
36 }
37
38 //Call the Parent copy constructor to add reference to the implementation for this object
39 CarouselEffect::CarouselEffect(ShaderEffect handle)
40 :ShaderEffect(handle)
41 {
42 }
43
44 CarouselEffect::~CarouselEffect()
45 {
46 }
47
48
49 CarouselEffect CarouselEffect::New()
50 {
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"
56               "\n"
57               "void main()\n"
58               "{\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"
65               "    \n"
66               "    vTexCoord = aTexCoord;\n"
67               "}\n");
68
69   ShaderEffect shaderEffectCustom = ShaderEffect::New(vertexShader,
70           "",
71           GeometryType( GEOMETRY_TYPE_IMAGE | GEOMETRY_TYPE_TEXT ),
72           ShaderEffect::GeometryHints( ShaderEffect::HINT_GRID | ShaderEffect::HINT_DEPTH_BUFFER ));
73
74   // Pass ownership to CarouselEffect through overloaded constructor, So that it now has access to the
75   // Dali::ShaderEffect implementation
76   CarouselEffect handle( shaderEffectCustom );
77
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 ) );
81
82   return handle;
83 }
84
85 void CarouselEffect::SetRadius( float radius)
86 {
87   SetUniform( RADIUS_PROPERTY_NAME, radius );
88 }
89
90 void CarouselEffect::SetCenter( const Vector2& center )
91 {
92   SetUniform( CENTER_PROPERTY_NAME, center );
93 }
94
95 void CarouselEffect::SetAnglePerUnit( const Vector2& angle )
96 {
97   SetUniform( ANGLE_PER_UNIT_PROPERTY_NAME, angle );
98 }
99
100 const std::string& CarouselEffect::GetRadiusPropertyName() const
101 {
102   return RADIUS_PROPERTY_NAME;
103 }
104
105 const std::string& CarouselEffect::GetCenterPropertyName() const
106 {
107   return CENTER_PROPERTY_NAME;
108 }
109
110 const std::string& CarouselEffect::GetAnglePerUnitPropertyName() const
111 {
112   return ANGLE_PER_UNIT_PROPERTY_NAME;
113 }
114
115 } // namespace Toolkit
116
117 } // namespace Dali