rayzor

view src/m3drast.c @ 9:70e332156d02

moving along
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 10 Apr 2014 02:31:31 +0300
parents 5fcf72837b69
children d94a69933a71
line source
1 #include "m3dimpl.h"
2 #include "lines.h"
5 void m3d_draw_point(struct min3d_vertex *v)
6 {
7 int x = v->pos[0] + 0.5;
8 int y = v->pos[1] + 0.5;
9 int xsz = m3dctx->cbuf->xsz;
10 m3dctx->cbuf->pixels[y * xsz + x] = v->color;
11 }
13 void m3d_draw_line(struct min3d_vertex *v)
14 {
15 int x0, y0, x1, y1;
17 x0 = v[0].pos[0];
18 y0 = v[0].pos[1];
19 x1 = v[1].pos[0];
20 y1 = v[1].pos[1];
22 if(clip_line2d(&x0, &y0, &x1, &y1, m3dctx->vport)) {
23 draw_line(m3dctx->cbuf->pixels, m3dctx->cbuf->xsz, v->color, x0, y0, x1, y1);
24 }
25 }
27 void m3d_draw_poly(struct min3d_vertex *v, int numv)
28 {
29 int i;
30 struct min3d_vertex last[2];
32 if(ENABLED(M3D_CULL_FACE)) {
33 float a[2], b[2], crossz = 0;
35 for(i=1; i<numv - 1; i++) {
36 int n = i + 1;
37 a[0] = v[i].pos[0] - v[0].pos[0];
38 a[1] = v[i].pos[1] - v[0].pos[1];
40 b[0] = v[n].pos[0] - v[0].pos[0];
41 b[1] = v[n].pos[1] - v[0].pos[1];
43 crossz += a[0] * b[1] - a[1] * b[0];
44 }
46 if(crossz < 0) return;
47 }
49 last[0] = v[numv - 1];
50 last[1] = v[0];
52 for(i=0; i<numv - 1; i++) {
53 m3d_draw_line(v++);
54 }
55 m3d_draw_line(last);
56 }