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@13: #define COLOR(r, g, b) \ nuclear@13: do { \ nuclear@13: *cptr++ = r; \ nuclear@13: *cptr++ = g; \ nuclear@13: *cptr++ = b; \ nuclear@13: } while(0) nuclear@13: nuclear@12: int gen_box(struct mesh *m) nuclear@12: { nuclear@13: int i; nuclear@14: int num_faces = 12; nuclear@14: int num_verts = num_faces * 3; 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@13: int32_t *vptr, *cptr; nuclear@12: nuclear@12: nuclear@14: m->prim = X3D_TRIANGLES; nuclear@12: m->nverts = num_verts; nuclear@13: if(!(m->verts = malloc(num_verts * 3 * sizeof *m->verts))) { nuclear@12: return -1; nuclear@12: } nuclear@12: vptr = m->verts; nuclear@12: nuclear@13: if(!(m->colors = malloc(num_verts * 3 * sizeof *m->colors))) { nuclear@13: return -1; nuclear@13: } nuclear@13: cptr = m->colors; nuclear@13: 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@14: for(i=0; i<3; i++) COLOR(32768, 0, 32768); nuclear@14: nuclear@14: VERTEX(v[0][0], v[0][1], v[0][2]); nuclear@14: VERTEX(v[2][0], v[2][1], v[2][2]); nuclear@12: VERTEX(v[3][0], v[3][1], v[3][2]); nuclear@14: for(i=0; i<3; i++) COLOR(65536, 0, 65536); nuclear@13: nuclear@12: /* +Y */ nuclear@14: VERTEX(v[7][0], v[7][1], v[7][2]); nuclear@14: VERTEX(v[6][0], v[6][1], v[6][2]); nuclear@14: VERTEX(v[5][0], v[5][1], v[5][2]); nuclear@14: for(i=0; i<3; i++) COLOR(0, 32768, 0); nuclear@14: nuclear@14: VERTEX(v[7][0], v[7][1], v[7][2]); nuclear@14: VERTEX(v[5][0], v[5][1], v[5][2]); nuclear@12: VERTEX(v[4][0], v[4][1], v[4][2]); nuclear@14: for(i=0; i<3; i++) COLOR(0, 65536, 0); nuclear@13: 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@14: for(i=0; i<3; i++) COLOR(32768, 32768, 0); nuclear@14: nuclear@14: VERTEX(v[0][0], v[0][1], v[0][2]); nuclear@14: VERTEX(v[5][0], v[5][1], v[5][2]); nuclear@12: VERTEX(v[1][0], v[1][1], v[1][2]); nuclear@14: for(i=0; i<3; i++) COLOR(65536, 65536, 0); nuclear@13: 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@14: for(i=0; i<3; i++) COLOR(0, 0, 32768); nuclear@14: nuclear@14: VERTEX(v[2][0], v[2][1], v[2][2]); nuclear@14: VERTEX(v[7][0], v[7][1], v[7][2]); nuclear@12: VERTEX(v[3][0], v[3][1], v[3][2]); nuclear@14: for(i=0; i<3; i++) COLOR(0, 0, 65536); nuclear@13: 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@14: for(i=0; i<3; i++) COLOR(32768, 0, 0); nuclear@14: nuclear@14: VERTEX(v[1][0], v[1][1], v[1][2]); nuclear@14: VERTEX(v[6][0], v[6][1], v[6][2]); nuclear@12: VERTEX(v[2][0], v[2][1], v[2][2]); nuclear@14: for(i=0; i<3; i++) COLOR(65536, 0, 0); nuclear@13: 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@14: for(i=0; i<3; i++) COLOR(0, 32768, 32768); nuclear@14: nuclear@14: VERTEX(v[3][0], v[3][1], v[3][2]); nuclear@14: VERTEX(v[4][0], v[4][1], v[4][2]); nuclear@12: VERTEX(v[0][0], v[0][1], v[0][2]); nuclear@14: for(i=0; i<3; i++) COLOR(0, 65536, 65536); nuclear@12: nuclear@12: return 0; nuclear@12: }