rayzor

annotate src/m3drast.c @ 17:79609d482762

the renderer renders, also fixed an unnoticed matrix conversion problem between scenegraph and min3d
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 14 Apr 2014 07:34:45 +0300
parents 70e332156d02
children 5380ff64e83f
rev   line source
nuclear@3 1 #include "m3dimpl.h"
nuclear@9 2 #include "lines.h"
nuclear@3 3
nuclear@3 4
nuclear@9 5 void m3d_draw_point(struct min3d_vertex *v)
nuclear@3 6 {
nuclear@5 7 int x = v->pos[0] + 0.5;
nuclear@5 8 int y = v->pos[1] + 0.5;
nuclear@5 9 int xsz = m3dctx->cbuf->xsz;
nuclear@9 10 m3dctx->cbuf->pixels[y * xsz + x] = v->color;
nuclear@3 11 }
nuclear@3 12
nuclear@9 13 void m3d_draw_line(struct min3d_vertex *v)
nuclear@3 14 {
nuclear@9 15 int x0, y0, x1, y1;
nuclear@9 16
nuclear@9 17 x0 = v[0].pos[0];
nuclear@9 18 y0 = v[0].pos[1];
nuclear@9 19 x1 = v[1].pos[0];
nuclear@9 20 y1 = v[1].pos[1];
nuclear@9 21
nuclear@9 22 if(clip_line2d(&x0, &y0, &x1, &y1, m3dctx->vport)) {
nuclear@9 23 draw_line(m3dctx->cbuf->pixels, m3dctx->cbuf->xsz, v->color, x0, y0, x1, y1);
nuclear@9 24 }
nuclear@3 25 }
nuclear@3 26
nuclear@9 27 void m3d_draw_poly(struct min3d_vertex *v, int numv)
nuclear@3 28 {
nuclear@9 29 int i;
nuclear@9 30 struct min3d_vertex last[2];
nuclear@9 31
nuclear@9 32 if(ENABLED(M3D_CULL_FACE)) {
nuclear@9 33 float a[2], b[2], crossz = 0;
nuclear@9 34
nuclear@9 35 for(i=1; i<numv - 1; i++) {
nuclear@9 36 int n = i + 1;
nuclear@9 37 a[0] = v[i].pos[0] - v[0].pos[0];
nuclear@9 38 a[1] = v[i].pos[1] - v[0].pos[1];
nuclear@9 39
nuclear@9 40 b[0] = v[n].pos[0] - v[0].pos[0];
nuclear@9 41 b[1] = v[n].pos[1] - v[0].pos[1];
nuclear@9 42
nuclear@9 43 crossz += a[0] * b[1] - a[1] * b[0];
nuclear@9 44 }
nuclear@9 45
nuclear@12 46 if(crossz > 0) return;
nuclear@9 47 }
nuclear@9 48
nuclear@9 49 last[0] = v[numv - 1];
nuclear@9 50 last[1] = v[0];
nuclear@9 51
nuclear@9 52 for(i=0; i<numv - 1; i++) {
nuclear@9 53 m3d_draw_line(v++);
nuclear@9 54 }
nuclear@9 55 m3d_draw_line(last);
nuclear@3 56 }