MythTV  master
surf3d.c
Go to the documentation of this file.
1 #include "surf3d.h"
2 #include <stdlib.h>
3 #include <stdio.h>
4 #include <string.h>
5 
6 void grid3d_free(grid3d **grid)
7 {
8  free ((*grid)->surf.vertex);
9  free ((*grid)->surf.svertex);
10  free (*grid);
11  *grid = NULL;
12 }
13 
14 grid3d *grid3d_new (int sizex, int defx, int sizez, int defz, v3d center) {
15  int x = defx;
16  int y = defz;
17  grid3d *g = (grid3d*)malloc (sizeof(grid3d));
18  surf3d *s = &(g->surf);
19  s->nbvertex = x*y;
20  s->vertex = (v3d*)malloc (x*y*sizeof(v3d));
21  s->svertex = (v3d*)malloc(x*y*sizeof(v3d));
22  s->center = center;
23 
24  g->defx=defx;
25  g->sizex=sizex;
26  g->defz=defz;
27  g->sizez=sizez;
28  g->mode=0;
29 
30  while (y) {
31  --y;
32  x = defx;
33  while (x) {
34  --x;
35  s->vertex[x+defx*y].x = (float)(x-defx/2)*sizex/defx;
36  s->vertex[x+defx*y].y = 0;
37  s->vertex[x+defx*y].z = (float)(y-defz/2)*sizez/defz;
38  }
39  }
40  return g;
41 }
42 
43 //#undef HAVE_MMX
44 #include "drawmethods.h"
45 
46 void surf3d_draw (surf3d *s, int color, int dist, int *buf, int *back, int W,int H) {
47  int i;
48  v2d v2;
49 
50  for (i=0;i<s->nbvertex;i++) {
51  V3D_TO_V2D(s->svertex[i],v2,W,H,dist);
52  int *p1 = buf + v2.x + (v2.y*W);
53  int *p2 = back + v2.x + (v2.y*W);
54  if ((v2.x>=0) && (v2.y>=0) && (v2.x<W) && (v2.y<H)) {
55  *p1 = color;
56  }
57 
58  /* Squelch a gcc warning */
59  (void)p2;
60  }
61 }
62 
63 void grid3d_draw (grid3d *g, int color, int colorlow,
64  int dist, int *buf, int *back, int W,int H) {
65  int x;
66 // int *p1;
67 // int *p2;
68  v2d v2,v2x;
69 
70  for (x=0;x<g->defx;x++) {
71  int z;
72  V3D_TO_V2D(g->surf.svertex[x],v2x,W,H,dist);
73 
74  for (z=1;z<g->defz;z++) {
75  V3D_TO_V2D(g->surf.svertex[z*g->defx + x],v2,W,H,dist);
76  if (((v2.x != -666) || (v2.y!=-666))
77  && ((v2x.x != -666) || (v2x.y!=-666))) {
78  draw_line(buf,v2x.x,v2x.y,v2.x,v2.y, colorlow, W, H);
79  draw_line(back,v2x.x,v2x.y,v2.x,v2.y, color, W, H);
81  }
82  v2x = v2;
83  }
84  }
85 }
86 
87 void surf3d_rotate (surf3d *s, float angle) {
88  int i;
89  float cosa;
90  float sina;
91  SINCOS(angle,sina,cosa);
92  for (i=0;i<s->nbvertex;i++) {
93  Y_ROTATE_V3D(s->vertex[i],s->svertex[i],cosa,sina);
94  }
95 }
96 
98  int i;
99  for (i=0;i<s->nbvertex;i++) {
100  TRANSLATE_V3D(s->center,s->svertex[i]);
101  }
102 }
103 
104 void grid3d_update (grid3d *g, float angle, const float *vals, float dist) {
105  int i;
106  float cosa;
107  float sina;
108  surf3d *s = &(g->surf);
109  v3d cam = s->center;
110  cam.z += dist;
111 
112  SINCOS((angle/4.3F),sina,cosa);
113  cam.y += sina*2.0F;
114  SINCOS(angle,sina,cosa);
115 
116  if (g->mode==0) {
117  if (vals)
118  for (i=0;i<g->defx;i++)
119  s->vertex[i].y = s->vertex[i].y*0.2F + vals[i]*0.8F;
120 
121  for (i=g->defx;i<s->nbvertex;i++) {
122  s->vertex[i].y *= 0.255F;
123  s->vertex[i].y += (s->vertex[i-g->defx].y * 0.777F);
124  }
125  }
126 
127  for (i=0;i<s->nbvertex;i++) {
128  Y_ROTATE_V3D(s->vertex[i],s->svertex[i],cosa,sina);
129  TRANSLATE_V3D(cam,s->svertex[i]);
130  }
131 }
int y
Definition: v3d.h:15
#define NULL
Definition: H264Parser.h:62
float z
Definition: v3d.h:11
v3d center
Definition: surf3d.h:11
int x
Definition: v3d.h:15
static float * vals
Definition: tentacle3d.c:16
v3d * vertex
Definition: surf3d.h:7
Definition: v3d.h:14
Definition: surf3d.h:14
#define DRAWMETHOD_DONE()
Definition: drawmethods.h:38
void surf3d_rotate(surf3d *s, float angle)
Definition: surf3d.c:87
void surf3d_translate(surf3d *s)
Definition: surf3d.c:97
void grid3d_free(grid3d **grid)
Definition: surf3d.c:6
int nbvertex
Definition: surf3d.h:9
static void draw_line(int *data, int x1, int y1, int x2, int y2, int col, int screenx, int screeny)
Definition: drawmethods.h:46
void grid3d_draw(grid3d *g, int color, int colorlow, int dist, int *buf, int *back, int W, int H)
Definition: surf3d.c:63
void grid3d_update(grid3d *g, float angle, const float *vals, float dist)
Definition: surf3d.c:104
grid3d * grid3d_new(int sizex, int defx, int sizez, int defz, v3d center)
Definition: surf3d.c:14
Definition: surf3d.h:6
float y
Definition: v3d.h:11
#define V3D_TO_V2D(v3, v2, width, height, distance)
Definition: v3d.h:24
#define TRANSLATE_V3D(vsrc, vdest)
Definition: v3d.h:50
static guint32 * p2
Definition: goom_core.c:35
Definition: v3d.h:10
v3d * svertex
Definition: surf3d.h:8
static guint32 * back
Definition: goom_core.c:34
float x
Definition: v3d.h:11
#define SINCOS(f, s, c)
Definition: mathtools.h:25
void surf3d_draw(surf3d *s, int color, int dist, int *buf, int *back, int W, int H)
Definition: surf3d.c:46
static guint32 * p1
Definition: goom_core.c:35
unsigned char g
Definition: ParseText.cpp:329
#define Y_ROTATE_V3D(vi, vf, sina, cosa)
Definition: v3d.h:40