rayzor
annotate src/m3drast.c @ 22:5380ff64e83f
minor changes from dos, and line endings cleanup
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Fri, 02 May 2014 14:32:58 +0300 |
parents | d94a69933a71 |
children |
rev | line source |
---|---|
nuclear@22 | 1 #include "m3dimpl.h" |
nuclear@22 | 2 #include "lines.h" |
nuclear@22 | 3 |
nuclear@22 | 4 |
nuclear@22 | 5 void m3d_draw_point(struct min3d_vertex *v) |
nuclear@22 | 6 { |
nuclear@22 | 7 int x = v->pos[0] + 0.5; |
nuclear@22 | 8 int y = v->pos[1] + 0.5; |
nuclear@22 | 9 int xsz = m3dctx->cbuf->xsz; |
nuclear@22 | 10 m3dctx->cbuf->pixels[y * xsz + x] = v->color; |
nuclear@22 | 11 } |
nuclear@22 | 12 |
nuclear@22 | 13 void m3d_draw_line(struct min3d_vertex *v) |
nuclear@22 | 14 { |
nuclear@22 | 15 int x0, y0, x1, y1; |
nuclear@22 | 16 |
nuclear@22 | 17 x0 = v[0].pos[0]; |
nuclear@22 | 18 y0 = v[0].pos[1]; |
nuclear@22 | 19 x1 = v[1].pos[0]; |
nuclear@22 | 20 y1 = v[1].pos[1]; |
nuclear@22 | 21 |
nuclear@22 | 22 if(clip_line2d(&x0, &y0, &x1, &y1, m3dctx->vport)) { |
nuclear@22 | 23 draw_line(m3dctx->cbuf->pixels, m3dctx->cbuf->xsz, v->color, x0, y0, x1, y1); |
nuclear@22 | 24 } |
nuclear@22 | 25 } |
nuclear@22 | 26 |
nuclear@22 | 27 void m3d_draw_poly(struct min3d_vertex *v, int numv) |
nuclear@22 | 28 { |
nuclear@22 | 29 int i; |
nuclear@22 | 30 struct min3d_vertex last[2]; |
nuclear@22 | 31 |
nuclear@22 | 32 if(ENABLED(M3D_CULL_FACE)) { |
nuclear@22 | 33 float a[2], b[2], crossz = 0; |
nuclear@22 | 34 |
nuclear@22 | 35 for(i=1; i<numv - 1; i++) { |
nuclear@22 | 36 int n = i + 1; |
nuclear@22 | 37 a[0] = v[i].pos[0] - v[0].pos[0]; |
nuclear@22 | 38 a[1] = v[i].pos[1] - v[0].pos[1]; |
nuclear@22 | 39 |
nuclear@22 | 40 b[0] = v[n].pos[0] - v[0].pos[0]; |
nuclear@22 | 41 b[1] = v[n].pos[1] - v[0].pos[1]; |
nuclear@22 | 42 |
nuclear@22 | 43 crossz += a[0] * b[1] - a[1] * b[0]; |
nuclear@22 | 44 } |
nuclear@22 | 45 |
nuclear@22 | 46 if(crossz > 0) return; |
nuclear@22 | 47 } |
nuclear@22 | 48 |
nuclear@22 | 49 last[0] = v[numv - 1]; |
nuclear@22 | 50 last[1] = v[0]; |
nuclear@22 | 51 |
nuclear@22 | 52 for(i=0; i<numv - 1; i++) { |
nuclear@22 | 53 m3d_draw_line(v++); |
nuclear@22 | 54 } |
nuclear@22 | 55 m3d_draw_line(last); |
nuclear@22 | 56 } |