configure.ac: Add checks for Flex/Yacc/Bison and other furry animals, for the new...
[platform/upstream/gst-plugins-good.git] / gst / goom / surf3d.c
1 #include "surf3d.h"
2 #include "goom_plugin_info.h"
3 #include <stdlib.h>
4 #include <stdio.h>
5 #include <string.h>
6
7 grid3d *
8 grid3d_new (int sizex, int defx, int sizez, int defz, v3d center)
9 {
10   int x = defx;
11   int y = defz;
12   grid3d *g = malloc (sizeof (grid3d));
13   surf3d *s = &(g->surf);
14
15   s->nbvertex = x * y;
16   s->vertex = malloc (x * y * sizeof (v3d));
17   s->svertex = malloc (x * y * sizeof (v3d));
18   s->center = center;
19
20   g->defx = defx;
21   g->sizex = sizex;
22   g->defz = defz;
23   g->sizez = sizez;
24   g->mode = 0;
25
26   while (y) {
27     --y;
28     x = defx;
29     while (x) {
30       --x;
31       s->vertex[x + defx * y].x = (float) (x - defx / 2) * sizex / defx;
32       s->vertex[x + defx * y].y = 0;
33       s->vertex[x + defx * y].z = (float) (y - defz / 2) * sizez / defz;
34     }
35   }
36   return g;
37 }
38
39 void
40 grid3d_draw (PluginInfo * plug, grid3d * g, int color, int colorlow,
41     int dist, Pixel * buf, Pixel * back, int W, int H)
42 {
43
44   int x;
45   v2d v2, v2x;
46
47   v2d *v2_array = malloc (g->surf.nbvertex * sizeof (v2d));
48
49   v3d_to_v2d (g->surf.svertex, g->surf.nbvertex, W, H, dist, v2_array);
50
51   for (x = 0; x < g->defx; x++) {
52     int z;
53
54     v2x = v2_array[x];
55
56     for (z = 1; z < g->defz; z++) {
57       v2 = v2_array[z * g->defx + x];
58       if (((v2.x != -666) || (v2.y != -666))
59           && ((v2x.x != -666) || (v2x.y != -666))) {
60         plug->methods.draw_line (buf, v2x.x, v2x.y, v2.x, v2.y, colorlow, W, H);
61         plug->methods.draw_line (back, v2x.x, v2x.y, v2.x, v2.y, color, W, H);
62       }
63       v2x = v2;
64     }
65   }
66
67   free (v2_array);
68 }
69
70 void
71 surf3d_rotate (surf3d * s, float angle)
72 {
73   int i;
74   float cosa;
75   float sina;
76
77   SINCOS (angle, sina, cosa);
78   for (i = 0; i < s->nbvertex; i++) {
79     Y_ROTATE_V3D (s->vertex[i], s->svertex[i], cosa, sina);
80   }
81 }
82
83 void
84 surf3d_translate (surf3d * s)
85 {
86   int i;
87
88   for (i = 0; i < s->nbvertex; i++) {
89     TRANSLATE_V3D (s->center, s->svertex[i]);
90   }
91 }
92
93 void
94 grid3d_update (grid3d * g, float angle, float *vals, float dist)
95 {
96   int i;
97   float cosa;
98   float sina;
99   surf3d *s = &(g->surf);
100   v3d cam = s->center;
101
102   cam.z += dist;
103
104   SINCOS ((angle / 4.3f), sina, cosa);
105   cam.y += sina * 2.0f;
106   SINCOS (angle, sina, cosa);
107
108   if (g->mode == 0) {
109     if (vals)
110       for (i = 0; i < g->defx; i++)
111         s->vertex[i].y = s->vertex[i].y * 0.2 + vals[i] * 0.8;
112
113     for (i = g->defx; i < s->nbvertex; i++) {
114       s->vertex[i].y *= 0.255f;
115       s->vertex[i].y += (s->vertex[i - g->defx].y * 0.777f);
116     }
117   }
118
119   for (i = 0; i < s->nbvertex; i++) {
120     Y_ROTATE_V3D (s->vertex[i], s->svertex[i], cosa, sina);
121     TRANSLATE_V3D (cam, s->svertex[i]);
122   }
123 }