summaryrefslogtreecommitdiff
path: root/src/examples
diff options
context:
space:
mode:
authorBogdan Devichev <b.devichev@samsung.com>2015-04-15 17:02:25 +0200
committerCedric BAIL <cedric@osg.samsung.com>2015-05-07 09:53:08 +0200
commitfe674b160f6113600137db0bee4c9e0e422591f2 (patch)
treea51149b1b02f0a61ecc97a8088563bb864fdd87d /src/examples
parentb803714e406f5b447388640cefb2eeb4ca8decf7 (diff)
evas: surface primitive is normalized in Evas_3D examples.
Reviewers: cedric, Hermet, raster Subscribers: cedric Differential Revision: https://phab.enlightenment.org/D2341 Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
Diffstat (limited to 'src/examples')
-rw-r--r--src/examples/evas/evas-3d-primitives.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/examples/evas/evas-3d-primitives.c b/src/examples/evas/evas-3d-primitives.c
index d2297fa..41b3fde 100644
--- a/src/examples/evas/evas-3d-primitives.c
+++ b/src/examples/evas/evas-3d-primitives.c
@@ -383,6 +383,38 @@ evas_3d_add_sphere_frame(Eo *mesh, int frame, int p, vec2 tex_scale)
383} 383}
384 384
385void 385void
386_normalize(vec3 *vertices, vec3 *normals, int vcount)
387{
388 int i;
389 vec3 min, max;
390 min = max = vertices[0];
391
392#define CHECK_MIN_AND_MAX(coord) \
393 if (min.coord > vertices[i].coord) \
394 min.coord = vertices[i].coord; \
395 else if (max.coord < vertices[i].coord) \
396 max.coord = vertices[i].coord;
397 for (i = 1; i < vcount; i++)
398 {
399 CHECK_MIN_AND_MAX(x)
400 CHECK_MIN_AND_MAX(y)
401 CHECK_MIN_AND_MAX(z)
402 }
403#undef CHECK_MIN_AND_MAX
404
405 for (i = 0; i < vcount; i++)
406 {
407 vertices[i].x = (vertices[i].x - min.x) / (max.x - min.x) - 0.5;
408 vertices[i].y = (vertices[i].y - min.y) / (max.y - min.y) - 0.5;
409 vertices[i].z = (vertices[i].z - min.z) / (max.z - min.z) - 0.5;
410
411 normals[i].x = normals[i].x / (max.x - min.x);
412 normals[i].y = normals[i].y / (max.y - min.y);
413 normals[i].z = normals[i].z / (max.z - min.z);
414 }
415}
416
417void
386evas_3d_add_func_surface_frame(Eo *mesh, int frame, Surface func, int p, vec2 tex_scale) 418evas_3d_add_func_surface_frame(Eo *mesh, int frame, Surface func, int p, vec2 tex_scale)
387{ 419{
388 int vcount, icount, vccount, i, j; 420 int vcount, icount, vccount, i, j;
@@ -413,6 +445,7 @@ evas_3d_add_func_surface_frame(Eo *mesh, int frame, Surface func, int p, vec2 te
413 } 445 }
414 } 446 }
415 447
448 _normalize(vertices, normals, vcount);
416 _generate_grid_indices(indices, p); 449 _generate_grid_indices(indices, p);
417 SET_VERTEX_DATA(frame) 450 SET_VERTEX_DATA(frame)
418} 451}