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