2 * Copyright (c) 2021 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.
19 #include <dali-toolkit/internal/controls/scrollable/bouncing-effect-actor.h>
22 #include <dali/public-api/math/vector3.h>
23 #include <dali/public-api/object/property-map.h>
24 #include <dali/public-api/rendering/geometry.h>
25 #include <dali/public-api/rendering/renderer.h>
26 #include <dali/public-api/rendering/shader.h>
27 #include <dali/public-api/rendering/texture-set.h>
30 #include <dali-toolkit/internal/graphics/builtin-shader-extern-gen.h>
40 // Bouncing effect is presented by stacked three layers with same color and opacity
41 const float LAYER_HEIGHTS[5] =
51 Actor CreateBouncingEffectActor(Property::Index& bouncePropertyIndex)
53 // Create the bouncing mesh geometry
59 // 4 vertices 2 triangles per layer. The depth interval between each layer is 0.01
60 VertexPosition vertexData[20] = {
62 {Vector3(-0.5f, -0.5f, 0.f), Vector3(-0.5f, -0.5f, 0.f)},
63 {Vector3(0.5f, -0.5f, 0.f), Vector3(0.5f, -0.5f, 0.f)},
64 {Vector3(-0.5f, -0.5f, 0.f), Vector3(-0.5f, -0.5f + LAYER_HEIGHTS[0], 0.f)},
65 {Vector3(0.5f, -0.5f, 0.f), Vector3(0.5f, -0.5f + LAYER_HEIGHTS[0], 0.f)},
67 {Vector3(-0.5f, -0.5f, 0.01f), Vector3(-0.5f, -0.5f, 0.01f)},
68 {Vector3(0.5f, -0.5f, 0.01f), Vector3(0.5f, -0.5f, 0.01f)},
69 {Vector3(-0.5f, -0.5f, 0.01f), Vector3(-0.5f, -0.5f + LAYER_HEIGHTS[1], 0.01f)},
70 {Vector3(0.5f, -0.5f, 0.01f), Vector3(0.5f, -0.5f + LAYER_HEIGHTS[1], 0.01f)},
72 {Vector3(-0.5f, -0.5f, 0.02f), Vector3(-0.5f, -0.5f, 0.02f)},
73 {Vector3(0.5f, -0.5f, 0.02f), Vector3(0.5f, -0.5f, 0.02f)},
74 {Vector3(-0.5f, -0.5f, 0.02f), Vector3(-0.5f, -0.5f + LAYER_HEIGHTS[2], 0.02f)},
75 {Vector3(0.5f, -0.5f, 0.02f), Vector3(0.5f, -0.5f + LAYER_HEIGHTS[2], 0.02f)},
77 {Vector3(-0.5f, -0.5f, 0.03f), Vector3(-0.5f, -0.5f, 0.03f)},
78 {Vector3(0.5f, -0.5f, 0.03f), Vector3(0.5f, -0.5f, 0.03f)},
79 {Vector3(-0.5f, -0.5f, 0.03f), Vector3(-0.5f, -0.5f + LAYER_HEIGHTS[3], 0.03f)},
80 {Vector3(0.5f, -0.5f, 0.03f), Vector3(0.5f, -0.5f + LAYER_HEIGHTS[3], 0.03f)},
82 {Vector3(-0.5f, -0.5f, 0.04f), Vector3(-0.5f, -0.5f, 0.04f)},
83 {Vector3(0.5f, -0.5f, 0.04f), Vector3(0.5f, -0.5f, 0.04f)},
84 {Vector3(-0.5f, -0.5f, 0.04f), Vector3(-0.5f, -0.5f + LAYER_HEIGHTS[4], 0.04f)},
85 {Vector3(0.5f, -0.5f, 0.04f), Vector3(0.5f, -0.5f + LAYER_HEIGHTS[4], 0.04f)}};
86 Property::Map vertexFormat;
87 vertexFormat["aPosition1"] = Property::VECTOR3;
88 vertexFormat["aPosition2"] = Property::VECTOR3;
89 VertexBuffer vertices = VertexBuffer::New(vertexFormat);
90 vertices.SetData(vertexData, 20u);
92 unsigned short indexData[30] = {0, 3, 1, 0, 2, 3, 4, 7, 5, 4, 6, 7, 8, 11, 9, 8, 10, 11, 12, 15, 13, 12, 14, 15, 16, 19, 17, 16, 18, 19};
94 Geometry meshGeometry = Geometry::New();
95 meshGeometry.AddVertexBuffer(vertices);
96 meshGeometry.SetIndexBuffer(indexData, sizeof(indexData) / sizeof(indexData[0]));
99 Shader shader = Shader::New(SHADER_BOUNCING_EFFECT_MESH_SHADER_VERT, SHADER_BOUNCING_EFFECT_MESH_SHADER_FRAG);
102 Renderer renderer = Renderer::New(meshGeometry, shader);
105 Actor meshActor = Actor::New();
106 meshActor.AddRenderer(renderer);
109 bouncePropertyIndex = meshActor.RegisterProperty("uBounceCoefficient", 0.f);
114 } // namespace Internal
116 } // namespace Toolkit