gba-trycatch

annotate src/ggen.c @ 13:2070a81127f2

foo
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 23 Jun 2014 08:28:28 +0300
parents ecc022a21279
children c398d834d64a
rev   line source
nuclear@12 1 #include <stdlib.h>
nuclear@12 2 #include "ggen.h"
nuclear@12 3 #include "mesh.h"
nuclear@12 4
nuclear@12 5 #define X1 65536
nuclear@12 6 #define VERTEX(x, y, z) \
nuclear@12 7 do { \
nuclear@12 8 *vptr++ = x; \
nuclear@12 9 *vptr++ = y; \
nuclear@12 10 *vptr++ = z; \
nuclear@12 11 } while(0)
nuclear@12 12
nuclear@13 13 #define COLOR(r, g, b) \
nuclear@13 14 do { \
nuclear@13 15 *cptr++ = r; \
nuclear@13 16 *cptr++ = g; \
nuclear@13 17 *cptr++ = b; \
nuclear@13 18 } while(0)
nuclear@13 19
nuclear@12 20 int gen_box(struct mesh *m)
nuclear@12 21 {
nuclear@13 22 int i;
nuclear@12 23 int num_faces = 8;
nuclear@12 24 int num_verts = num_faces * 4;
nuclear@12 25 int32_t v[8][3] = {
nuclear@12 26 {-X1, -X1, -X1}, {X1, -X1, -X1}, {X1, -X1, X1}, {-X1, -X1, X1},
nuclear@12 27 {-X1, X1, -X1}, {X1, X1, -X1}, {X1, X1, X1}, {-X1, X1, X1}
nuclear@12 28 };
nuclear@13 29 int32_t *vptr, *cptr;
nuclear@12 30
nuclear@12 31
nuclear@12 32 m->prim = X3D_QUADS;
nuclear@12 33 m->nverts = num_verts;
nuclear@13 34 if(!(m->verts = malloc(num_verts * 3 * sizeof *m->verts))) {
nuclear@12 35 return -1;
nuclear@12 36 }
nuclear@12 37 vptr = m->verts;
nuclear@12 38
nuclear@13 39 if(!(m->colors = malloc(num_verts * 3 * sizeof *m->colors))) {
nuclear@13 40 return -1;
nuclear@13 41 }
nuclear@13 42 cptr = m->colors;
nuclear@13 43
nuclear@12 44 /* -Y */
nuclear@12 45 VERTEX(v[0][0], v[0][1], v[0][2]);
nuclear@12 46 VERTEX(v[1][0], v[1][1], v[1][2]);
nuclear@12 47 VERTEX(v[2][0], v[2][1], v[2][2]);
nuclear@12 48 VERTEX(v[3][0], v[3][1], v[3][2]);
nuclear@13 49 for(i=0; i<4; i++) COLOR(65536, 0, 65536);
nuclear@13 50
nuclear@12 51 /* +Y */
nuclear@12 52 VERTEX(v[4][0], v[4][1], v[4][2]);
nuclear@12 53 VERTEX(v[5][0], v[5][1], v[5][2]);
nuclear@12 54 VERTEX(v[6][0], v[6][1], v[6][2]);
nuclear@12 55 VERTEX(v[7][0], v[7][1], v[7][2]);
nuclear@13 56 for(i=0; i<4; i++) COLOR(0, 65536, 0);
nuclear@13 57
nuclear@12 58 /* -Z */
nuclear@12 59 VERTEX(v[0][0], v[0][1], v[0][2]);
nuclear@12 60 VERTEX(v[4][0], v[4][1], v[4][2]);
nuclear@12 61 VERTEX(v[5][0], v[5][1], v[5][2]);
nuclear@12 62 VERTEX(v[1][0], v[1][1], v[1][2]);
nuclear@13 63 for(i=0; i<4; i++) COLOR(65536, 65536, 0);
nuclear@13 64
nuclear@12 65 /* +Z */
nuclear@12 66 VERTEX(v[2][0], v[2][1], v[2][2]);
nuclear@12 67 VERTEX(v[6][0], v[6][1], v[6][2]);
nuclear@12 68 VERTEX(v[7][0], v[7][1], v[7][2]);
nuclear@12 69 VERTEX(v[3][0], v[3][1], v[3][2]);
nuclear@13 70 for(i=0; i<4; i++) COLOR(0, 0, 65536);
nuclear@13 71
nuclear@12 72 /* +X */
nuclear@12 73 VERTEX(v[1][0], v[1][1], v[1][2]);
nuclear@12 74 VERTEX(v[5][0], v[5][1], v[5][2]);
nuclear@12 75 VERTEX(v[6][0], v[6][1], v[6][2]);
nuclear@12 76 VERTEX(v[2][0], v[2][1], v[2][2]);
nuclear@13 77 for(i=0; i<4; i++) COLOR(65536, 0, 0);
nuclear@13 78
nuclear@12 79 /* -X */
nuclear@12 80 VERTEX(v[3][0], v[3][1], v[3][2]);
nuclear@12 81 VERTEX(v[7][0], v[7][1], v[7][2]);
nuclear@12 82 VERTEX(v[4][0], v[4][1], v[4][2]);
nuclear@12 83 VERTEX(v[0][0], v[0][1], v[0][2]);
nuclear@13 84 for(i=0; i<4; i++) COLOR(0, 65536, 65536);
nuclear@12 85
nuclear@12 86 return 0;
nuclear@12 87 }