gba-trycatch

diff src/ggen.c @ 12:ecc022a21279

more tuff
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 23 Jun 2014 06:44:04 +0300
parents
children 2070a81127f2
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/ggen.c	Mon Jun 23 06:44:04 2014 +0300
     1.3 @@ -0,0 +1,63 @@
     1.4 +#include <stdlib.h>
     1.5 +#include "ggen.h"
     1.6 +#include "mesh.h"
     1.7 +
     1.8 +#define X1	65536
     1.9 +#define VERTEX(x, y, z)	\
    1.10 +	do { \
    1.11 +		*vptr++ = x; \
    1.12 +		*vptr++ = y; \
    1.13 +		*vptr++ = z; \
    1.14 +	} while(0)
    1.15 +
    1.16 +int gen_box(struct mesh *m)
    1.17 +{
    1.18 +	int num_faces = 8;
    1.19 +	int num_verts = num_faces * 4;
    1.20 +	int32_t v[8][3] = {
    1.21 +		{-X1, -X1, -X1}, {X1, -X1, -X1}, {X1, -X1, X1}, {-X1, -X1, X1},
    1.22 +		{-X1, X1, -X1}, {X1, X1, -X1}, {X1, X1, X1}, {-X1, X1, X1}
    1.23 +	};
    1.24 +	int32_t *vptr;
    1.25 +
    1.26 +
    1.27 +	m->prim = X3D_QUADS;
    1.28 +	m->nverts = num_verts;
    1.29 +	if(!(m->verts = malloc(num_verts * sizeof *m->verts))) {
    1.30 +		return -1;
    1.31 +	}
    1.32 +	vptr = m->verts;
    1.33 +
    1.34 +	/* -Y */
    1.35 +	VERTEX(v[0][0], v[0][1], v[0][2]);
    1.36 +	VERTEX(v[1][0], v[1][1], v[1][2]);
    1.37 +	VERTEX(v[2][0], v[2][1], v[2][2]);
    1.38 +	VERTEX(v[3][0], v[3][1], v[3][2]);
    1.39 +	/* +Y */
    1.40 +	VERTEX(v[4][0], v[4][1], v[4][2]);
    1.41 +	VERTEX(v[5][0], v[5][1], v[5][2]);
    1.42 +	VERTEX(v[6][0], v[6][1], v[6][2]);
    1.43 +	VERTEX(v[7][0], v[7][1], v[7][2]);
    1.44 +	/* -Z */
    1.45 +	VERTEX(v[0][0], v[0][1], v[0][2]);
    1.46 +	VERTEX(v[4][0], v[4][1], v[4][2]);
    1.47 +	VERTEX(v[5][0], v[5][1], v[5][2]);
    1.48 +	VERTEX(v[1][0], v[1][1], v[1][2]);
    1.49 +	/* +Z */
    1.50 +	VERTEX(v[2][0], v[2][1], v[2][2]);
    1.51 +	VERTEX(v[6][0], v[6][1], v[6][2]);
    1.52 +	VERTEX(v[7][0], v[7][1], v[7][2]);
    1.53 +	VERTEX(v[3][0], v[3][1], v[3][2]);
    1.54 +	/* +X */
    1.55 +	VERTEX(v[1][0], v[1][1], v[1][2]);
    1.56 +	VERTEX(v[5][0], v[5][1], v[5][2]);
    1.57 +	VERTEX(v[6][0], v[6][1], v[6][2]);
    1.58 +	VERTEX(v[2][0], v[2][1], v[2][2]);
    1.59 +	/* -X */
    1.60 +	VERTEX(v[3][0], v[3][1], v[3][2]);
    1.61 +	VERTEX(v[7][0], v[7][1], v[7][2]);
    1.62 +	VERTEX(v[4][0], v[4][1], v[4][2]);
    1.63 +	VERTEX(v[0][0], v[0][1], v[0][2]);
    1.64 +
    1.65 +	return 0;
    1.66 +}