nuclear@12: #include nuclear@12: #include "ggen.h" nuclear@12: #include "mesh.h" nuclear@12: nuclear@12: #define X1 65536 nuclear@12: #define VERTEX(x, y, z) \ nuclear@12: do { \ nuclear@12: *vptr++ = x; \ nuclear@12: *vptr++ = y; \ nuclear@12: *vptr++ = z; \ nuclear@12: } while(0) nuclear@12: nuclear@12: int gen_box(struct mesh *m) nuclear@12: { nuclear@12: int num_faces = 8; nuclear@12: int num_verts = num_faces * 4; nuclear@12: int32_t v[8][3] = { nuclear@12: {-X1, -X1, -X1}, {X1, -X1, -X1}, {X1, -X1, X1}, {-X1, -X1, X1}, nuclear@12: {-X1, X1, -X1}, {X1, X1, -X1}, {X1, X1, X1}, {-X1, X1, X1} nuclear@12: }; nuclear@12: int32_t *vptr; nuclear@12: nuclear@12: nuclear@12: m->prim = X3D_QUADS; nuclear@12: m->nverts = num_verts; nuclear@12: if(!(m->verts = malloc(num_verts * sizeof *m->verts))) { nuclear@12: return -1; nuclear@12: } nuclear@12: vptr = m->verts; nuclear@12: nuclear@12: /* -Y */ nuclear@12: VERTEX(v[0][0], v[0][1], v[0][2]); nuclear@12: VERTEX(v[1][0], v[1][1], v[1][2]); nuclear@12: VERTEX(v[2][0], v[2][1], v[2][2]); nuclear@12: VERTEX(v[3][0], v[3][1], v[3][2]); nuclear@12: /* +Y */ nuclear@12: VERTEX(v[4][0], v[4][1], v[4][2]); nuclear@12: VERTEX(v[5][0], v[5][1], v[5][2]); nuclear@12: VERTEX(v[6][0], v[6][1], v[6][2]); nuclear@12: VERTEX(v[7][0], v[7][1], v[7][2]); nuclear@12: /* -Z */ nuclear@12: VERTEX(v[0][0], v[0][1], v[0][2]); nuclear@12: VERTEX(v[4][0], v[4][1], v[4][2]); nuclear@12: VERTEX(v[5][0], v[5][1], v[5][2]); nuclear@12: VERTEX(v[1][0], v[1][1], v[1][2]); nuclear@12: /* +Z */ nuclear@12: VERTEX(v[2][0], v[2][1], v[2][2]); nuclear@12: VERTEX(v[6][0], v[6][1], v[6][2]); nuclear@12: VERTEX(v[7][0], v[7][1], v[7][2]); nuclear@12: VERTEX(v[3][0], v[3][1], v[3][2]); nuclear@12: /* +X */ nuclear@12: VERTEX(v[1][0], v[1][1], v[1][2]); nuclear@12: VERTEX(v[5][0], v[5][1], v[5][2]); nuclear@12: VERTEX(v[6][0], v[6][1], v[6][2]); nuclear@12: VERTEX(v[2][0], v[2][1], v[2][2]); nuclear@12: /* -X */ nuclear@12: VERTEX(v[3][0], v[3][1], v[3][2]); nuclear@12: VERTEX(v[7][0], v[7][1], v[7][2]); nuclear@12: VERTEX(v[4][0], v[4][1], v[4][2]); nuclear@12: VERTEX(v[0][0], v[0][1], v[0][2]); nuclear@12: nuclear@12: return 0; nuclear@12: }