gba-x3dtest
view 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 source
1 #include <stdlib.h>
2 #include "ggen.h"
3 #include "mesh.h"
5 #define X1 65536
6 #define VERTEX(x, y, z) \
7 do { \
8 *vptr++ = x; \
9 *vptr++ = y; \
10 *vptr++ = z; \
11 } while(0)
13 int gen_box(struct mesh *m)
14 {
15 int num_faces = 8;
16 int num_verts = num_faces * 4;
17 int32_t v[8][3] = {
18 {-X1, -X1, -X1}, {X1, -X1, -X1}, {X1, -X1, X1}, {-X1, -X1, X1},
19 {-X1, X1, -X1}, {X1, X1, -X1}, {X1, X1, X1}, {-X1, X1, X1}
20 };
21 int32_t *vptr;
24 m->prim = X3D_QUADS;
25 m->nverts = num_verts;
26 if(!(m->verts = malloc(num_verts * sizeof *m->verts))) {
27 return -1;
28 }
29 vptr = m->verts;
31 /* -Y */
32 VERTEX(v[0][0], v[0][1], v[0][2]);
33 VERTEX(v[1][0], v[1][1], v[1][2]);
34 VERTEX(v[2][0], v[2][1], v[2][2]);
35 VERTEX(v[3][0], v[3][1], v[3][2]);
36 /* +Y */
37 VERTEX(v[4][0], v[4][1], v[4][2]);
38 VERTEX(v[5][0], v[5][1], v[5][2]);
39 VERTEX(v[6][0], v[6][1], v[6][2]);
40 VERTEX(v[7][0], v[7][1], v[7][2]);
41 /* -Z */
42 VERTEX(v[0][0], v[0][1], v[0][2]);
43 VERTEX(v[4][0], v[4][1], v[4][2]);
44 VERTEX(v[5][0], v[5][1], v[5][2]);
45 VERTEX(v[1][0], v[1][1], v[1][2]);
46 /* +Z */
47 VERTEX(v[2][0], v[2][1], v[2][2]);
48 VERTEX(v[6][0], v[6][1], v[6][2]);
49 VERTEX(v[7][0], v[7][1], v[7][2]);
50 VERTEX(v[3][0], v[3][1], v[3][2]);
51 /* +X */
52 VERTEX(v[1][0], v[1][1], v[1][2]);
53 VERTEX(v[5][0], v[5][1], v[5][2]);
54 VERTEX(v[6][0], v[6][1], v[6][2]);
55 VERTEX(v[2][0], v[2][1], v[2][2]);
56 /* -X */
57 VERTEX(v[3][0], v[3][1], v[3][2]);
58 VERTEX(v[7][0], v[7][1], v[7][2]);
59 VERTEX(v[4][0], v[4][1], v[4][2]);
60 VERTEX(v[0][0], v[0][1], v[0][2]);
62 return 0;
63 }