gba-x3dtest

annotate 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
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@12 13 int gen_box(struct mesh *m)
nuclear@12 14 {
nuclear@12 15 int num_faces = 8;
nuclear@12 16 int num_verts = num_faces * 4;
nuclear@12 17 int32_t v[8][3] = {
nuclear@12 18 {-X1, -X1, -X1}, {X1, -X1, -X1}, {X1, -X1, X1}, {-X1, -X1, X1},
nuclear@12 19 {-X1, X1, -X1}, {X1, X1, -X1}, {X1, X1, X1}, {-X1, X1, X1}
nuclear@12 20 };
nuclear@12 21 int32_t *vptr;
nuclear@12 22
nuclear@12 23
nuclear@12 24 m->prim = X3D_QUADS;
nuclear@12 25 m->nverts = num_verts;
nuclear@12 26 if(!(m->verts = malloc(num_verts * sizeof *m->verts))) {
nuclear@12 27 return -1;
nuclear@12 28 }
nuclear@12 29 vptr = m->verts;
nuclear@12 30
nuclear@12 31 /* -Y */
nuclear@12 32 VERTEX(v[0][0], v[0][1], v[0][2]);
nuclear@12 33 VERTEX(v[1][0], v[1][1], v[1][2]);
nuclear@12 34 VERTEX(v[2][0], v[2][1], v[2][2]);
nuclear@12 35 VERTEX(v[3][0], v[3][1], v[3][2]);
nuclear@12 36 /* +Y */
nuclear@12 37 VERTEX(v[4][0], v[4][1], v[4][2]);
nuclear@12 38 VERTEX(v[5][0], v[5][1], v[5][2]);
nuclear@12 39 VERTEX(v[6][0], v[6][1], v[6][2]);
nuclear@12 40 VERTEX(v[7][0], v[7][1], v[7][2]);
nuclear@12 41 /* -Z */
nuclear@12 42 VERTEX(v[0][0], v[0][1], v[0][2]);
nuclear@12 43 VERTEX(v[4][0], v[4][1], v[4][2]);
nuclear@12 44 VERTEX(v[5][0], v[5][1], v[5][2]);
nuclear@12 45 VERTEX(v[1][0], v[1][1], v[1][2]);
nuclear@12 46 /* +Z */
nuclear@12 47 VERTEX(v[2][0], v[2][1], v[2][2]);
nuclear@12 48 VERTEX(v[6][0], v[6][1], v[6][2]);
nuclear@12 49 VERTEX(v[7][0], v[7][1], v[7][2]);
nuclear@12 50 VERTEX(v[3][0], v[3][1], v[3][2]);
nuclear@12 51 /* +X */
nuclear@12 52 VERTEX(v[1][0], v[1][1], v[1][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[2][0], v[2][1], v[2][2]);
nuclear@12 56 /* -X */
nuclear@12 57 VERTEX(v[3][0], v[3][1], v[3][2]);
nuclear@12 58 VERTEX(v[7][0], v[7][1], v[7][2]);
nuclear@12 59 VERTEX(v[4][0], v[4][1], v[4][2]);
nuclear@12 60 VERTEX(v[0][0], v[0][1], v[0][2]);
nuclear@12 61
nuclear@12 62 return 0;
nuclear@12 63 }