summaryrefslogtreecommitdiff
path: root/src/examples/evas/evas-3d-cube2.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/examples/evas/evas-3d-cube2.c')
-rw-r--r--src/examples/evas/evas-3d-cube2.c150
1 files changed, 61 insertions, 89 deletions
diff --git a/src/examples/evas/evas-3d-cube2.c b/src/examples/evas/evas-3d-cube2.c
index a2dd1fe..e46c2f7 100644
--- a/src/examples/evas/evas-3d-cube2.c
+++ b/src/examples/evas/evas-3d-cube2.c
@@ -79,8 +79,8 @@ _on_canvas_resize(Ecore_Evas *ee)
79 int w, h; 79 int w, h;
80 80
81 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h); 81 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
82 eo_do(background, efl_gfx_size_set(w, h)); 82 efl_gfx_size_set(background, w, h);
83 eo_do(image, efl_gfx_size_set(w, h)); 83 efl_gfx_size_set(image, w, h);
84} 84}
85 85
86static Eina_Bool 86static Eina_Bool
@@ -93,8 +93,7 @@ _animate_scene(void *data)
93 93
94 angle += 0.2; 94 angle += 0.2;
95 95
96 eo_do(scene->mesh_node, 96 evas_canvas3d_node_orientation_angle_axis_set(scene->mesh_node, angle, 1.0, 1.0, 1.0);
97 evas_canvas3d_node_orientation_angle_axis_set(angle, 1.0, 1.0, 1.0));
98 97
99 /* Rotate */ 98 /* Rotate */
100 if (angle > 360.0) angle -= 360.0f; 99 if (angle > 360.0) angle -= 360.0f;
@@ -104,7 +103,7 @@ _animate_scene(void *data)
104 if (frame >= 20) inc = -1; 103 if (frame >= 20) inc = -1;
105 else if (frame <= 0) inc = 1; 104 else if (frame <= 0) inc = 1;
106 105
107 eo_do(scene->mesh_node, evas_canvas3d_node_mesh_frame_set(scene->mesh, frame)); 106 evas_canvas3d_node_mesh_frame_set(scene->mesh_node, scene->mesh, frame);
108 107
109 return EINA_TRUE; 108 return EINA_TRUE;
110} 109}
@@ -113,39 +112,30 @@ static void
113_camera_setup(Scene_Data *data) 112_camera_setup(Scene_Data *data)
114{ 113{
115 data->camera = eo_add(EVAS_CANVAS3D_CAMERA_CLASS, evas); 114 data->camera = eo_add(EVAS_CANVAS3D_CAMERA_CLASS, evas);
116 eo_do(data->camera, 115 evas_canvas3d_camera_projection_perspective_set(data->camera, 60.0, 1.0, 2.0, 50.0);
117 evas_canvas3d_camera_projection_perspective_set(60.0, 1.0, 2.0, 50.0));
118 116
119 data->camera_node = 117 data->camera_node =
120 eo_add(EVAS_CANVAS3D_NODE_CLASS, evas, 118 eo_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_constructor(eoid, EVAS_CANVAS3D_NODE_TYPE_CAMERA));
121 evas_canvas3d_node_constructor(EVAS_CANVAS3D_NODE_TYPE_CAMERA)); 119 evas_canvas3d_node_camera_set(data->camera_node, data->camera);
122 eo_do(data->camera_node, 120 evas_canvas3d_node_position_set(data->camera_node, 0.0, 0.0, 3.0);
123 evas_canvas3d_node_camera_set(data->camera), 121 evas_canvas3d_node_look_at_set(data->camera_node, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 0.0, 0.0, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 1.0, 0.0);
124 evas_canvas3d_node_position_set(0.0, 0.0, 3.0), 122 evas_canvas3d_node_member_add(data->root_node, data->camera_node);
125 evas_canvas3d_node_look_at_set(EVAS_CANVAS3D_SPACE_PARENT, 0.0, 0.0, 0.0,
126 EVAS_CANVAS3D_SPACE_PARENT, 0.0, 1.0, 0.0));
127 eo_do(data->root_node,
128 evas_canvas3d_node_member_add(data->camera_node));
129} 123}
130 124
131static void 125static void
132_light_setup(Scene_Data *data) 126_light_setup(Scene_Data *data)
133{ 127{
134 data->light = eo_add(EVAS_CANVAS3D_LIGHT_CLASS, evas); 128 data->light = eo_add(EVAS_CANVAS3D_LIGHT_CLASS, evas);
135 eo_do(data->light, 129 evas_canvas3d_light_ambient_set(data->light, 0.2, 0.2, 0.2, 1.0);
136 evas_canvas3d_light_ambient_set(0.2, 0.2, 0.2, 1.0), 130 evas_canvas3d_light_diffuse_set(data->light, 1.0, 1.0, 1.0, 1.0);
137 evas_canvas3d_light_diffuse_set(1.0, 1.0, 1.0, 1.0), 131 evas_canvas3d_light_specular_set(data->light, 1.0, 1.0, 1.0, 1.0);
138 evas_canvas3d_light_specular_set(1.0, 1.0, 1.0, 1.0));
139 132
140 data->light_node = 133 data->light_node =
141 eo_add(EVAS_CANVAS3D_NODE_CLASS, evas, 134 eo_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_constructor(eoid, EVAS_CANVAS3D_NODE_TYPE_LIGHT));
142 evas_canvas3d_node_constructor(EVAS_CANVAS3D_NODE_TYPE_LIGHT)); 135 evas_canvas3d_node_light_set(data->light_node, data->light);
143 eo_do(data->light_node, 136 evas_canvas3d_node_position_set(data->light_node, 0.0, 0.0, 10.0);
144 evas_canvas3d_node_light_set(data->light), 137 evas_canvas3d_node_look_at_set(data->light_node, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 0.0, 0.0, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 1.0, 0.0);
145 evas_canvas3d_node_position_set(0.0, 0.0, 10.0), 138 evas_canvas3d_node_member_add(data->root_node, data->light_node);
146 evas_canvas3d_node_look_at_set(EVAS_CANVAS3D_SPACE_PARENT, 0.0, 0.0, 0.0,
147 EVAS_CANVAS3D_SPACE_PARENT, 0.0, 1.0, 0.0));
148 eo_do(data->root_node, evas_canvas3d_node_member_add(data->light_node));
149} 139}
150 140
151static void 141static void
@@ -155,86 +145,70 @@ _mesh_setup(Scene_Data *data)
155 data->material0 = eo_add(EVAS_CANVAS3D_MATERIAL_CLASS, evas); 145 data->material0 = eo_add(EVAS_CANVAS3D_MATERIAL_CLASS, evas);
156 data->material1 = eo_add(EVAS_CANVAS3D_MATERIAL_CLASS, evas); 146 data->material1 = eo_add(EVAS_CANVAS3D_MATERIAL_CLASS, evas);
157 147
158 eo_do(data->material0, 148 evas_canvas3d_material_enable_set(data->material0, EVAS_CANVAS3D_MATERIAL_ATTRIB_AMBIENT, EINA_TRUE);
159 evas_canvas3d_material_enable_set(EVAS_CANVAS3D_MATERIAL_ATTRIB_AMBIENT, EINA_TRUE), 149 evas_canvas3d_material_enable_set(data->material0, EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, EINA_TRUE);
160 evas_canvas3d_material_enable_set(EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, EINA_TRUE), 150 evas_canvas3d_material_enable_set(data->material0, EVAS_CANVAS3D_MATERIAL_ATTRIB_SPECULAR, EINA_TRUE);
161 evas_canvas3d_material_enable_set(EVAS_CANVAS3D_MATERIAL_ATTRIB_SPECULAR, EINA_TRUE), 151 evas_canvas3d_material_enable_set(data->material0, EVAS_CANVAS3D_MATERIAL_ATTRIB_NORMAL, EINA_TRUE);
162 evas_canvas3d_material_enable_set(EVAS_CANVAS3D_MATERIAL_ATTRIB_NORMAL, EINA_TRUE), 152 evas_canvas3d_material_color_set(data->material0, EVAS_CANVAS3D_MATERIAL_ATTRIB_AMBIENT, 0.2, 0.2, 0.2, 1.0);
163 153 evas_canvas3d_material_color_set(data->material0, EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, 0.8, 0.8, 0.8, 1.0);
164 evas_canvas3d_material_color_set(EVAS_CANVAS3D_MATERIAL_ATTRIB_AMBIENT, 0.2, 0.2, 0.2, 1.0), 154 evas_canvas3d_material_color_set(data->material0, EVAS_CANVAS3D_MATERIAL_ATTRIB_SPECULAR, 1.0, 1.0, 1.0, 1.0);
165 evas_canvas3d_material_color_set(EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, 0.8, 0.8, 0.8, 1.0), 155 evas_canvas3d_material_shininess_set(data->material0, 100.0);
166 evas_canvas3d_material_color_set(EVAS_CANVAS3D_MATERIAL_ATTRIB_SPECULAR, 1.0, 1.0, 1.0, 1.0), 156
167 evas_canvas3d_material_shininess_set(100.0)); 157 evas_canvas3d_material_enable_set(data->material1, EVAS_CANVAS3D_MATERIAL_ATTRIB_AMBIENT, EINA_TRUE);
168 158 evas_canvas3d_material_enable_set(data->material1, EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, EINA_TRUE);
169 eo_do(data->material1, 159 evas_canvas3d_material_enable_set(data->material1, EVAS_CANVAS3D_MATERIAL_ATTRIB_SPECULAR, EINA_TRUE);
170 evas_canvas3d_material_enable_set(EVAS_CANVAS3D_MATERIAL_ATTRIB_AMBIENT, EINA_TRUE), 160 evas_canvas3d_material_enable_set(data->material1, EVAS_CANVAS3D_MATERIAL_ATTRIB_NORMAL, EINA_TRUE);
171 evas_canvas3d_material_enable_set(EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, EINA_TRUE), 161 evas_canvas3d_material_color_set(data->material1, EVAS_CANVAS3D_MATERIAL_ATTRIB_AMBIENT, 0.2, 0.2, 0.2, 1.0);
172 evas_canvas3d_material_enable_set(EVAS_CANVAS3D_MATERIAL_ATTRIB_SPECULAR, EINA_TRUE), 162 evas_canvas3d_material_color_set(data->material1, EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, 0.8, 0.8, 0.8, 1.0);
173 evas_canvas3d_material_enable_set(EVAS_CANVAS3D_MATERIAL_ATTRIB_NORMAL, EINA_TRUE), 163 evas_canvas3d_material_color_set(data->material1, EVAS_CANVAS3D_MATERIAL_ATTRIB_SPECULAR, 1.0, 1.0, 1.0, 1.0);
174 164 evas_canvas3d_material_shininess_set(data->material1, 100.0);
175 evas_canvas3d_material_color_set(EVAS_CANVAS3D_MATERIAL_ATTRIB_AMBIENT, 0.2, 0.2, 0.2, 1.0),
176 evas_canvas3d_material_color_set(EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, 0.8, 0.8, 0.8, 1.0),
177 evas_canvas3d_material_color_set(EVAS_CANVAS3D_MATERIAL_ATTRIB_SPECULAR, 1.0, 1.0, 1.0, 1.0),
178 evas_canvas3d_material_shininess_set(100.0));
179 165
180 data->texture0 = eo_add(EVAS_CANVAS3D_TEXTURE_CLASS, evas); 166 data->texture0 = eo_add(EVAS_CANVAS3D_TEXTURE_CLASS, evas);
181 data->texture1 = eo_add(EVAS_CANVAS3D_TEXTURE_CLASS, evas); 167 data->texture1 = eo_add(EVAS_CANVAS3D_TEXTURE_CLASS, evas);
182 data->texture_normal = eo_add(EVAS_CANVAS3D_TEXTURE_CLASS, evas); 168 data->texture_normal = eo_add(EVAS_CANVAS3D_TEXTURE_CLASS, evas);
183 169
184 eo_do(data->texture0, 170 evas_canvas3d_texture_data_set(data->texture0, EVAS_COLORSPACE_ARGB8888, 4, 4, &pixels0[0]);
185 evas_canvas3d_texture_data_set(EVAS_COLORSPACE_ARGB8888, 4, 4, &pixels0[0])); 171 evas_canvas3d_texture_data_set(data->texture1, EVAS_COLORSPACE_ARGB8888, 4, 4, &pixels1[0]);
186 eo_do(data->texture1, 172 evas_canvas3d_texture_file_set(data->texture_normal, normal_map_path, NULL);
187 evas_canvas3d_texture_data_set(EVAS_COLORSPACE_ARGB8888, 4, 4, &pixels1[0]));
188 eo_do(data->texture_normal,
189 evas_canvas3d_texture_file_set(normal_map_path, NULL));
190 173
191 eo_do(data->material0, 174 evas_canvas3d_material_texture_set(data->material0, EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, data->texture0);
192 evas_canvas3d_material_texture_set(EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, data->texture0)); 175 evas_canvas3d_material_texture_set(data->material1, EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, data->texture1);
193 eo_do(data->material1, 176 evas_canvas3d_material_texture_set(data->material1, EVAS_CANVAS3D_MATERIAL_ATTRIB_NORMAL, data->texture_normal);
194 evas_canvas3d_material_texture_set(EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, data->texture1));
195 eo_do(data->material1,
196 evas_canvas3d_material_texture_set(EVAS_CANVAS3D_MATERIAL_ATTRIB_NORMAL, data->texture_normal));
197 177
198 /* Set data of primitive */ 178 /* Set data of primitive */
199 data->cube = eo_add(EVAS_CANVAS3D_PRIMITIVE_CLASS, evas); 179 data->cube = eo_add(EVAS_CANVAS3D_PRIMITIVE_CLASS, evas);
200 eo_do(data->cube, 180 evas_canvas3d_primitive_form_set(data->cube, EVAS_CANVAS3D_MESH_PRIMITIVE_CUBE);
201 evas_canvas3d_primitive_form_set(EVAS_CANVAS3D_MESH_PRIMITIVE_CUBE));
202 181
203 /* Setup mesh. */ 182 /* Setup mesh. */
204 data->mesh = eo_add(EVAS_CANVAS3D_MESH_CLASS, evas); 183 data->mesh = eo_add(EVAS_CANVAS3D_MESH_CLASS, evas);
205 eo_do(data->mesh, 184 evas_canvas3d_mesh_from_primitive_set(data->mesh, 0, data->cube);
206 evas_canvas3d_mesh_from_primitive_set(0, data->cube), 185 evas_canvas3d_mesh_frame_material_set(data->mesh, 0, data->material0);
207 evas_canvas3d_mesh_frame_material_set(0, data->material0), 186 evas_canvas3d_mesh_frame_add(data->mesh, 20);
208 evas_canvas3d_mesh_frame_add(20), 187 evas_canvas3d_mesh_frame_material_set(data->mesh, 20, data->material1);
209 evas_canvas3d_mesh_frame_material_set(20, data->material1), 188 evas_canvas3d_mesh_shade_mode_set(data->mesh, EVAS_CANVAS3D_SHADE_MODE_NORMAL_MAP);
210 evas_canvas3d_mesh_shade_mode_set(EVAS_CANVAS3D_SHADE_MODE_NORMAL_MAP));
211 189
212 data->mesh_node = 190 data->mesh_node =
213 eo_add(EVAS_CANVAS3D_NODE_CLASS, evas, 191 eo_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_constructor(eoid, EVAS_CANVAS3D_NODE_TYPE_MESH));
214 evas_canvas3d_node_constructor(EVAS_CANVAS3D_NODE_TYPE_MESH)); 192 evas_canvas3d_node_member_add(data->root_node, data->mesh_node);
215 eo_do(data->root_node, evas_canvas3d_node_member_add(data->mesh_node)); 193 evas_canvas3d_node_mesh_add(data->mesh_node, data->mesh);
216 eo_do(data->mesh_node, evas_canvas3d_node_mesh_add(data->mesh));
217} 194}
218 195
219static void 196static void
220_scene_setup(Scene_Data *data) 197_scene_setup(Scene_Data *data)
221{ 198{
222 data->scene = eo_add(EVAS_CANVAS3D_SCENE_CLASS, evas); 199 data->scene = eo_add(EVAS_CANVAS3D_SCENE_CLASS, evas);
223 eo_do(data->scene, 200 evas_canvas3d_scene_size_set(data->scene, WIDTH, HEIGHT);
224 evas_canvas3d_scene_size_set(WIDTH, HEIGHT), 201 evas_canvas3d_scene_background_color_set(data->scene, 0.0, 0.0, 0.0, 0.0);
225 evas_canvas3d_scene_background_color_set(0.0, 0.0, 0.0, 0.0));
226 202
227 data->root_node = 203 data->root_node =
228 eo_add(EVAS_CANVAS3D_NODE_CLASS, evas, 204 eo_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_constructor(eoid, EVAS_CANVAS3D_NODE_TYPE_NODE));
229 evas_canvas3d_node_constructor(EVAS_CANVAS3D_NODE_TYPE_NODE));
230 205
231 _camera_setup(data); 206 _camera_setup(data);
232 _light_setup(data); 207 _light_setup(data);
233 _mesh_setup(data); 208 _mesh_setup(data);
234 209
235 eo_do(data->scene, 210 evas_canvas3d_scene_root_node_set(data->scene, data->root_node);
236 evas_canvas3d_scene_root_node_set(data->root_node), 211 evas_canvas3d_scene_camera_node_set(data->scene, data->camera_node);
237 evas_canvas3d_scene_camera_node_set(data->camera_node));
238} 212}
239 213
240int 214int
@@ -261,19 +235,17 @@ main(void)
261 235
262 /* Add a background rectangle objects. */ 236 /* Add a background rectangle objects. */
263 background = eo_add(EVAS_RECTANGLE_CLASS, evas); 237 background = eo_add(EVAS_RECTANGLE_CLASS, evas);
264 eo_do(background, 238 efl_gfx_color_set(background, 0, 0, 0, 255);
265 efl_gfx_color_set(0, 0, 0, 255), 239 efl_gfx_size_set(background, WIDTH, HEIGHT);
266 efl_gfx_size_set(WIDTH, HEIGHT), 240 efl_gfx_visible_set(background, EINA_TRUE);
267 efl_gfx_visible_set(EINA_TRUE));
268 241
269 /* Add an image object for 3D scene rendering. */ 242 /* Add an image object for 3D scene rendering. */
270 image = evas_object_image_filled_add(evas); 243 image = evas_object_image_filled_add(evas);
271 eo_do(image, 244 efl_gfx_size_set(image, WIDTH, HEIGHT);
272 efl_gfx_size_set(WIDTH, HEIGHT), 245 efl_gfx_visible_set(image, EINA_TRUE);
273 efl_gfx_visible_set(EINA_TRUE));
274 246
275 /* Set the image object as render target for 3D scene. */ 247 /* Set the image object as render target for 3D scene. */
276 eo_do(image, evas_obj_image_scene_set(data.scene)); 248 evas_obj_image_scene_set(image, data.scene);
277 249
278 /* Add animation timer callback. */ 250 /* Add animation timer callback. */
279 ecore_timer_add(0.01, _animate_scene, &data); 251 ecore_timer_add(0.01, _animate_scene, &data);