PageRenderTime 25ms CodeModel.GetById 15ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/xbmc/visualizations/Goom/goom2k4-0/src/surf3d.c

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