diff options
Diffstat (limited to 'src/lib/evas/common3d/primitives/surfaces')
-rw-r--r-- | src/lib/evas/common3d/primitives/surfaces/meson.build | 4 | ||||
-rw-r--r-- | src/lib/evas/common3d/primitives/surfaces/surface.c | 91 | ||||
-rw-r--r-- | src/lib/evas/common3d/primitives/surfaces/terrain.c | 86 |
3 files changed, 0 insertions, 181 deletions
diff --git a/src/lib/evas/common3d/primitives/surfaces/meson.build b/src/lib/evas/common3d/primitives/surfaces/meson.build deleted file mode 100644 index 398996f148..0000000000 --- a/src/lib/evas/common3d/primitives/surfaces/meson.build +++ /dev/null @@ -1,4 +0,0 @@ -evas_src += files([ - 'surface.c', - 'terrain.c' -])
\ No newline at end of file diff --git a/src/lib/evas/common3d/primitives/surfaces/surface.c b/src/lib/evas/common3d/primitives/surfaces/surface.c deleted file mode 100644 index 7698ba5fb6..0000000000 --- a/src/lib/evas/common3d/primitives/surfaces/surface.c +++ /dev/null @@ -1,91 +0,0 @@ -#include "../primitive_common.h" - -Eina_Vector3 _get_func_normal(Evas_Canvas3D_Surface_Func *func, Evas_Real x, Evas_Real y) -{ - Eina_Vector3 v00, v01, v10, d1, d2, normal; - - func(&v00.x, &v00.y, &v00.z, x, y); - func(&v01.x, &v01.y, &v01.z, x, y + 0.01); - func(&v10.x, &v10.y, &v10.z, x + 0.01, y); - _primitives_vec3_subtract(&d1, &v00, &v01); - _primitives_vec3_subtract(&d2, &v01, &v10); - - _primitives_vec3_cross_product(&normal, &d1, &d2); - - _primitives_vec3_normalize(&normal); - - return normal; -} - -void -_normalize(Eina_Vector3 *vertices, Eina_Vector3 *normals, int vcount) -{ - int i; - Eina_Vector3 min, max; - min = max = vertices[0]; - -#define CHECK_MIN_AND_MAX(coord) \ - if (min.coord > vertices[i].coord) \ - min.coord = vertices[i].coord; \ - else if (max.coord < vertices[i].coord) \ - max.coord = vertices[i].coord; - for (i = 1; i < vcount; i++) - { - CHECK_MIN_AND_MAX(x) - CHECK_MIN_AND_MAX(y) - CHECK_MIN_AND_MAX(z) - } -#undef CHECK_MIN_AND_MAX - - for (i = 0; i < vcount; i++) - { - vertices[i].x = (vertices[i].x - min.x) / (max.x - min.x) - 0.5; - vertices[i].y = (vertices[i].y - min.y) / (max.y - min.y) - 0.5; - vertices[i].z = (vertices[i].z - min.z) / (max.z - min.z) - 0.5; - - normals[i].x = normals[i].x / (max.x - min.x); - normals[i].y = normals[i].y / (max.y - min.y); - normals[i].z = normals[i].z / (max.z - min.z); - } -} - -void -evas_model_set_from_surface_primitive(Evas_Canvas3D_Mesh *mesh, - int frame, - Evas_Canvas3D_Surface_Func func, - int p, - Eina_Vector2 tex_scale) -{ - int vcount, icount, vccount, i, j, num; - icount = p * p * 6; - vccount = p + 1; - vcount = vccount * vccount; - - ALLOCATE_VERTEX_DATA - - Evas_Real v, u, d = 1.0 / p; - - for (j = 0; j < vccount; j++) - { - u = j * d - 0.5; - for (i = 0; i < vccount; i++) - { - v = i * d - 0.5; - num = i + j * vccount; - func(&vertices[num].x, - &vertices[num].y, - &vertices[num].z, - v, u); - normals[num] = _get_func_normal(func, v, u); - - tangents[num].x = tangents[num].y = tangents[num].z = 0; - - tex_coord[num].x = i / ((vccount - 1) * tex_scale.x); - tex_coord[num].y = tex_scale.y - j / ((vccount - 1) * tex_scale.y); - } - } - - _normalize(vertices, normals, vcount); - _generate_indices(indices, p, p); - SET_VERTEX_DATA(frame) -} diff --git a/src/lib/evas/common3d/primitives/surfaces/terrain.c b/src/lib/evas/common3d/primitives/surfaces/terrain.c deleted file mode 100644 index 1f83c089ef..0000000000 --- a/src/lib/evas/common3d/primitives/surfaces/terrain.c +++ /dev/null @@ -1,86 +0,0 @@ -#include "../primitive_common.h" - -static Evas_Real -_random(int x, int y) -{ - int k = x + y * 57; - k = (k << 13) ^ k; - return (1.0f - ((k * (k * k * 15731 + 789221) + 1376312589) & 0x7fffffff) / - 1073741824.0f); -} - -static Evas_Real -_smooth(Evas_Real x, Evas_Real y) -{ - Evas_Real res; - res = (_random(x - 1, y - 1) + _random(x + 1, y - 1) + - _random(x - 1, y + 1) + _random(x + 1, y + 1)) / 16; - res += (_random(x - 1, y) + _random(x + 1, y) + - _random(x, y - 1) + _random(x, y + 1)) / 8; - res += _random(x, y) / 4; - return res; -} - -static Evas_Real -_interpolate(Evas_Real a, Evas_Real b, Evas_Real x) -{ - Evas_Real ft = x * M_PI; - Evas_Real f = (1 - cosf(ft)) * 0.5; - return a * (1 - f) + b * f; -} - -static Evas_Real _noise(Evas_Real x, Evas_Real y) -{ - Evas_Real ix = (int)(x); - Evas_Real fx = x - ix; - Evas_Real iy = (int)(y); - Evas_Real fy = y - iy; - - Evas_Real v1 = _smooth(ix, iy); - Evas_Real v2 = _smooth(ix + 1, iy); - Evas_Real v3 = _smooth(ix, iy + 1); - Evas_Real v4 = _smooth(ix + 1, iy + 1); - - Evas_Real i1 = _interpolate(v1, v2, fx); - Evas_Real i2 = _interpolate(v3, v4, fx); - - return _interpolate(i1, i2, fy); -} - -static void -_perlin_terrain(Evas_Real *out_x, - Evas_Real *out_y, - Evas_Real *out_z, - Evas_Real x, - Evas_Real y) -{ - Evas_Real persistence = 0.5f; - Evas_Real frequency = 5; - Evas_Real amplitude = 1; - int i = 0; - int octaves = 5; - - *out_x = x; - x += 0.5; - *out_y = y; - y += 0.5; - *out_z = 0; - - for(i = 0; i < octaves; i++) - { - *out_z += _noise(x * frequency, y * frequency) * amplitude; - - amplitude *= persistence; - frequency *= 2; - } -} - -void -evas_model_set_from_terrain_primitive(Evas_Canvas3D_Mesh *mesh, - int frame, - int p, - Eina_Vector2 tex_scale) -{ - evas_model_set_from_surface_primitive(mesh, frame, _perlin_terrain, p, tex_scale); -} - |