MythTV master
surf3d.cpp
Go to the documentation of this file.
1#include <cstddef>
2#include <cstdio>
3#include <cstdlib>
4#include <cstring>
5
6#include "surf3d.h"
7
8void grid3d_free(grid3d **grid)
9{
10 free ((*grid)->surf.vertex);
11 free ((*grid)->surf.svertex);
12 free (*grid);
13 *grid = nullptr;
14}
15
16grid3d *grid3d_new (int sizex, int defx, int sizez, int defz, v3d center) {
17 int x = defx;
18 int y = defz;
19 auto *g = (grid3d*)malloc (sizeof(grid3d));
20 surf3d *s = &(g->surf);
21 s->nbvertex = x*y;
22 s->vertex = (v3d*)malloc (sizeof(v3d)*x*y);
23 s->svertex = (v3d*)malloc(sizeof(v3d)*x*y);
24 s->center = center;
25
26 g->defx=defx;
27 g->sizex=sizex;
28 g->defz=defz;
29 g->sizez=sizez;
30 g->mode=0;
31
32 while (y) {
33 --y;
34 x = defx;
35 while (x) {
36 --x;
37 s->vertex[x+(defx*y)].x = (x-defx/2.0F)*sizex/defx;
38 s->vertex[x+(defx*y)].y = 0;
39 s->vertex[x+(defx*y)].z = (y-defz/2.0F)*sizez/defz;
40 }
41 }
42 return g;
43}
44
45//#undef HAVE_MMX
46#include "drawmethods.h"
47
48void surf3d_draw (surf3d *s, int color, int dist, int *buf, int *back, int W,int H) {
49 v2d v2 {};
50
51 for (int i=0;i<s->nbvertex;i++) {
52 V3D_TO_V2D(s->svertex[i],v2,W,H,dist);
53 int *p1 = buf + v2.x + (v2.y*static_cast<ptrdiff_t>(W));
54 [[maybe_unused]] int *p2 = back + v2.x + (v2.y*static_cast<ptrdiff_t>(W));
55 if ((v2.x>=0) && (v2.y>=0) && (v2.x<W) && (v2.y<H)) {
56 *p1 = color;
57 }
58 }
59}
60
61void grid3d_draw (grid3d *g, int color, int colorlow,
62 int dist, int *buf, int *back, int W,int H) {
63 v2d v2 {};
64 v2d v2x {};
65
66 for (int x=0;x<g->defx;x++) {
67 V3D_TO_V2D(g->surf.svertex[x],v2x,W,H,dist);
68
69 for (int z=1;z<g->defz;z++) {
70 V3D_TO_V2D(g->surf.svertex[(z*g->defx) + x],v2,W,H,dist);
71 if (((v2.x != -666) || (v2.y!=-666))
72 && ((v2x.x != -666) || (v2x.y!=-666))) {
73 draw_line(buf,v2x.x,v2x.y,v2.x,v2.y, colorlow, W, H);
74 draw_line(back,v2x.x,v2x.y,v2.x,v2.y, color, W, H);
76 }
77 v2x = v2;
78 }
79 }
80}
81
82void surf3d_rotate (surf3d *s, float angle) {
83 float cosa = NAN;
84 float sina = NAN;
85 SINCOS(angle,sina,cosa);
86 for (int i=0;i<s->nbvertex;i++) {
87 Y_ROTATE_V3D(s->vertex[i],s->svertex[i],cosa,sina);
88 }
89}
90
92 for (int i=0;i<s->nbvertex;i++) {
94 }
95}
96
97void grid3d_update (grid3d *g, float angle, const float *vals, float dist) {
98 float cosa = NAN;
99 float sina = NAN;
100 surf3d *s = &(g->surf);
101 v3d cam = s->center;
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 (int i=0;i<g->defx;i++)
111 s->vertex[i].y = (s->vertex[i].y*0.2F) + (vals[i]*0.8F);
112
113 for (int 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 (int 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}
static void draw_line(int *data, int x1, int y1, int x2, int y2, int col, int screenx, int screeny)
Definition: drawmethods.h:46
#define DRAWMETHOD_DONE()
Definition: drawmethods.h:38
static guint32 * back
Definition: goom_core.cpp:25
static guint32 * p2
Definition: goom_core.cpp:26
static guint32 * p1
Definition: goom_core.cpp:26
#define SINCOS(f, s, c)
Definition: mathtools.h:28
Definition: surf3d.h:14
int mode
Definition: surf3d.h:21
surf3d surf
Definition: surf3d.h:15
int defz
Definition: surf3d.h:19
int defx
Definition: surf3d.h:17
Definition: surf3d.h:6
v3d * svertex
Definition: surf3d.h:8
v3d center
Definition: surf3d.h:11
int nbvertex
Definition: surf3d.h:9
v3d * vertex
Definition: surf3d.h:7
Definition: v3d.h:14
Definition: v3d.h:10
float z
Definition: v3d.h:11
float y
Definition: v3d.h:11
void grid3d_free(grid3d **grid)
Definition: surf3d.cpp:8
void grid3d_draw(grid3d *g, int color, int colorlow, int dist, int *buf, int *back, int W, int H)
Definition: surf3d.cpp:61
grid3d * grid3d_new(int sizex, int defx, int sizez, int defz, v3d center)
Definition: surf3d.cpp:16
void grid3d_update(grid3d *g, float angle, const float *vals, float dist)
Definition: surf3d.cpp:97
void surf3d_translate(surf3d *s)
Definition: surf3d.cpp:91
void surf3d_draw(surf3d *s, int color, int dist, int *buf, int *back, int W, int H)
Definition: surf3d.cpp:48
void surf3d_rotate(surf3d *s, float angle)
Definition: surf3d.cpp:82
static float * vals
Definition: tentacle3d.cpp:19
#define V3D_TO_V2D(v3, v2, width, height, distance)
Definition: v3d.h:24
#define Y_ROTATE_V3D(vi, vf, sina, cosa)
Definition: v3d.h:41
#define TRANSLATE_V3D(vsrc, vdest)
Definition: v3d.h:51