int main(int argc, char **argv) { point_t a, b, c, d; struct rt_wdb *fp; si.magic = RT_NURB_INTERNAL_MAGIC; si.nsrf = 0; si.srfs = (struct face_g_snurb **)bu_malloc( sizeof(struct face_g_snurb *)*100, "snurb ptrs"); if ((fp = wdb_fopen(argv[1])) == NULL) { bu_log("unable to open new database [%s]\n", argv[1]); perror("unable to open database file"); return 1; } mk_id( fp, "Mike's Spline Test" ); VSET( a, 0, 0, 0 ); VSET( b, 10, 0, 0 ); VSET( c, 10, 10, 0 ); VSET( d, 0, 10, 0 ); make_face( a, b, c, d, 2 ); mk_export_fwrite( fp, "spl", (genptr_t)&si, ID_BSPLINE ); return 0; }
int main(int argc, char *argv[]) { point_t a, b, c, d; struct rt_wdb *fp; struct rt_nurb_internal *si; char *filename = "spltest.g"; int helpflag; if (argc < 1 || argc > 2) { printusage(argv); bu_exit(1,NULL); } helpflag = (argc == 2 && ( BU_STR_EQUAL(argv[1],"-h") || BU_STR_EQUAL(argv[1],"-?"))); if (argc == 1 || helpflag) { printusage(argv); if (helpflag) bu_exit(1,NULL); bu_log(" Program continues running:\n"); } if (argc == 2) filename = argv[1]; if ((fp = wdb_fopen(filename)) == NULL) { perror("unable to open geometry database for writing"); bu_exit(1, "unable to open new database [%s]\n", filename); } mk_id(fp, "Mike's Spline Test"); VSET(a, 0, 0, 0); VSET(b, 10, 0, -5); VSET(c, 10, 10, 10); VSET(d, 0, 10, 0); BU_ALLOC(si, struct rt_nurb_internal); si->magic = RT_NURB_INTERNAL_MAGIC; si->nsrf = 0; si->srfs = (struct face_g_snurb **)bu_malloc(sizeof(struct face_g_snurb *)*100, "allocate snurb ptrs"); make_face(si, a, b, c, d, 2); /* wdb_export */ mk_export_fwrite(fp, "spltest", (void *)si, ID_BSPLINE); bu_log("Saving file %s\n",filename); return 0; }
void read_obj(const char* strName) { int i,j,k; FILE *fp; int nwords; char *comment_ptr; char *first_word; float x,y,z,w; /* read from standard input */ fp = fopen(strName,"r"); while (1) { comment_ptr = fetch_line (fp); if (comment_ptr == (char *) -1) /* end-of-file */ break; /* did we get a comment? */ if (comment_ptr) { make_comment (comment_ptr); continue; } /* if we get here, the line was not a comment */ nwords = fetch_words(); /* skip empty lines */ if (nwords == 0) continue; first_word = words[0]; if (equal_strings (first_word, "v")) { if (nwords < 4) { fprintf (stderr, "Too few coordinates: '%s'", str_orig); exit (-1); } #ifdef NEW_LOAD float3 pos; pos.x = atof (words[1]); pos.y = atof (words[2]); pos.z = atof (words[3]); vPosition.push_back(pos); #else x = atof (words[1]); y = atof (words[2]); z = atof (words[3]); if (nwords == 5) { w = atof (words[3]); has_w = 1; } else w = 1.0; make_vertex (x, y, z, w); #endif } else if (equal_strings (first_word, "vn")) { #ifdef NEW_LOAD float3 n; n.x = atof (words[1]); n.y = atof (words[2]); n.z = atof (words[3]); vNormal.push_back(n); has_normals = true; #endif } else if (equal_strings (first_word, "vt")) { #ifdef NEW_LOAD float2 t; t.x = atof (words[1]); t.y = atof (words[2]); vUV.push_back(t); texture_coords = true; #endif } else if (equal_strings (first_word, "f")) { #ifdef NEW_LOAD LoadFace(&words[1],nwords-1); #else make_face (&words[1], nwords-1); #endif } else { fprintf (stderr, "Do not recognize: '%s'\n", str_orig); } } nverts = vVertex.size(); nfaces = vIndex.size()/3; fclose(fp); }
void read_obj ( void ) /******************************************************************************/ /* Purpose: READ_OBJ reads in a Wavefront OBJ file. Author: Greg Turk */ { char *comment_ptr; char *first_word; FILE *fp; int i; int j; int k; int nwords; float w; float x; float y; float z; /* Read from standard input. */ fp = stdin; while (1) { comment_ptr = fetch_line ( fp ); /* End of file? */ if ( comment_ptr == ( char * ) -1 ) { break; } /* Did we actually get a comment? */ if ( comment_ptr ) { make_comment ( comment_ptr ); continue; } /* If we get here, the line was not a comment. */ nwords = fetch_words ( ); /* Skip empty lines. */ if ( nwords == 0 ) { continue; } first_word = words[0]; if (equal_strings (first_word, "v")) { if (nwords < 4) { fprintf (stderr, "Too few coordinates: '%s'", str_orig); exit (-1); } x = atof (words[1]); y = atof (words[2]); z = atof (words[3]); if (nwords == 5) { w = atof (words[3]); has_w = 1; } else { w = 1.0; } make_vertex ( x, y, z, w ); } else if (equal_strings (first_word, "vn")) { } else if (equal_strings (first_word, "vt")) { } else if (equal_strings (first_word, "f")) { make_face (&words[1], nwords-1); } else { fprintf (stderr, "Do not recognize: '%s'\n", str_orig); } } return; }
int main(int argc, char **argv) { meta_mpi_init(&argc, &argv); #ifdef __DEBUG__ int breakMe = 0; while (breakMe); #endif /*{ int i = 0; char hostname[256]; gethostname(hostname, sizeof(hostname)); printf("PID %d on %s ready for attach\n", getpid(), hostname); fflush(stdout); while (0 == i) sleep(5); }*/ int comm_sz; int rank; MPI_Comm_size(MPI_COMM_WORLD, &comm_sz); MPI_Comm_rank(MPI_COMM_WORLD, &rank); printf("Hello from rank %d!\n", rank); int i = argc; int ni, nj, nk, tx, ty, tz, face_id, l_type; a_bool async, autoconfig; meta_face * face_spec; a_dim3 dimgrid_red, dimblock_red, dimgrid_tr_red, dimarray_3d, arr_start, arr_end, dim_array2d, start_2d, end_2d, trans_dim, rtrans_dim; if (i < 11) { printf( "<ni> <nj> <nk> <tblockx> <tblocky> <tblockz> <face> <data_type> <async> <autoconfig>\n"); return (1); } ni = atoi(argv[1]); nj = atoi(argv[2]); nk = atoi(argv[3]); tx = atoi(argv[4]); ty = atoi(argv[5]); tz = atoi(argv[6]); face_id = atoi(argv[7]); l_type = atoi(argv[8]); set_type((meta_type_id) l_type); async = (a_bool) atoi(argv[9]); autoconfig = (a_bool) atoi(argv[10]); dimblock_red[0] = tx, dimblock_red[1] = ty, dimblock_red[2] = tz; dimgrid_red[0] = ni / tx + ((ni % tx) ? 1 : 0); dimgrid_red[1] = nj / ty + ((nj % ty) ? 1 : 0); dimgrid_red[2] = nk / tz + ((nk % tz) ? 1 : 0); dimarray_3d[0] = ni, dimarray_3d[1] = nj, dimarray_3d[2] = nk; //These are for the library reduction, which we use for sums void * sum_gpu, *zero; sum_gpu = malloc(g_typesize); zero = malloc(g_typesize); switch (g_type) { case a_db: *(double*) zero = 0; break; case a_fl: *(float*) zero = 0; break; case a_ul: *(unsigned long*) zero = 0; break; case a_in: *(int *) zero = 0; break; case a_ui: *(unsigned int *) zero = 0; break; } #ifdef WITH_TIMERS metaTimersInit(); #endif gpu_initialize(rank); data_allocate(ni, nj, nk); data_initialize(ni, nj, nk); MPI_Request request; MPI_Status status; for (i = 0; i < 1; i++) { if (rank == 0) { //Only process 0 actually needs to initialize data // proc1 is just a relay that tests things on the receiving // end and mirror's the data back //copy the unmodified prism to device meta_copy_h2d(dev_data3, data3, ni * nj * nk * g_typesize, async); //check_buffer(data3, dev_data3, ni*nj*nk); //Validate grid and block sizes (if too big, shrink the z-dim and add iterations) for (; meta_validate_worksize(&dimgrid_red, &dimblock_red) != 0 && dimblock_red[2] > 1; dimgrid_red[2] <<= 1, dimblock_red[2] >>= 1) ; //zero out the reduction sum meta_copy_h2d(reduction, zero, g_typesize, async); //reduce the face to check that the transfer was correct //accurately sets start and end indices to sum each face arr_start[0] = ((face_id == 3) ? ni - 1 : 0); arr_end[0] = ((face_id == 2) ? 0 : ni - 1); arr_start[1] = ((face_id == 5) ? nj - 1 : 0); arr_end[1] = ((face_id == 4) ? 0 : nj - 1); arr_start[2] = ((face_id == 1) ? nk - 1 : 0); arr_end[2] = ((face_id == 0) ? 0 : nk - 1); //check_dims(dimarray_3d, arr_start, arr_end); // printf("Integrity check dim(%d, %d, %d) start(%d, %d, %d) end(%d, %d, %d)\n", dimarray_3d[0], dimarray_3d[1], dimarray_3d[2], arr_start[0], arr_start[1], arr_start[2], arr_end[0], arr_end[1], arr_end[2]); a_err ret = meta_reduce(autoconfig ? NULL : &dimgrid_red, autoconfig ? NULL : &dimblock_red, dev_data3, &dimarray_3d, &arr_start, &arr_end, reduction, g_type, async); //a_dim3 testgrid, testblock; //testgrid[0] = testgrid[1] = testgrid[2] = 1; //testblock[0] = 16; //testblock[1] = 8; //testblock[2] = 1; //a_err ret = meta_reduce(&testgrid, &testblock, dev_data3, &dimarray_3d, &arr_start, &arr_end, reduction, g_type, async); printf("Reduce Error: %d\n", ret); //pull the sum back meta_copy_d2h(sum_gpu, reduction, g_typesize, async); //The 4 ternaries ensure the right args are passed to match the face // so this one call will work for any face printf("Initial Face Integrity Check: %s\n", check_face_sum(sum_gpu, (face_id < 4 ? nj : nk), (face_id < 2 || face_id > 3 ? ni : nk), (face_id & 1 ? (face_id < 2 ? nk - 1 : (face_id < 4 ? ni - 1 : nj - 1)) : 0)) ? "FAILED" : "PASSED"); //pack the face //TODO set a_dim3 structs once the internal implementation respects them face_spec = make_face(face_id, ni, nj, nk); ret = meta_pack_face(NULL, NULL, dev_face[face_id], dev_data3, face_spec, g_type, async); printf("Pack Return Val: %d\n", ret); //check_buffer(face[face_id], dev_face[face_id], face_spec->size[0]*face_spec->size[1]*face_spec->size[2]); //reduce the packed face to check that packing was correct meta_copy_h2d(reduction, zero, g_typesize, async); dim_array2d[0] = face_spec->size[2], dim_array2d[1] = face_spec->size[1], dim_array2d[2] = face_spec->size[0]; start_2d[0] = start_2d[1] = start_2d[2] = 0; end_2d[0] = (dim_array2d[0] == 1 ? 0 : ni - 1); end_2d[1] = (dim_array2d[1] == 1 ? 0 : nj - 1); end_2d[2] = (dim_array2d[2] == 1 ? 0 : nk - 1); //check_dims(dim_array2d, start_2d, end_2d); ret = meta_reduce(autoconfig ? NULL : &dimgrid_red, autoconfig ? NULL : &dimblock_red, dev_face[face_id], &dim_array2d, &start_2d, &end_2d, reduction, g_type, async); meta_copy_d2h(sum_gpu, reduction, g_typesize, async); //The 4 ternaries ensure the right args are passed to match the face // so this one call will work for any face printf("Packed Face Integrity Check: %s\n", check_face_sum(sum_gpu, (face_id < 4 ? nj : nk), (face_id < 2 || face_id > 3 ? ni : nk), (face_id & 1 ? (face_id < 2 ? nk - 1 : (face_id < 4 ? ni - 1 : nj - 1)) : 0)) ? "FAILED" : "PASSED"); //transpose the packed face (into the companion face's unoccupied buffer) trans_dim[0] = ( face_spec->size[2] == 1 ? face_spec->size[1] : face_spec->size[2]); trans_dim[1] = ( face_spec->size[0] == 1 ? face_spec->size[1] : face_spec->size[0]); trans_dim[2] = 1; rtrans_dim[0] = trans_dim[1]; rtrans_dim[1] = trans_dim[0]; rtrans_dim[2] = 1; void * stuff = calloc( face_spec->size[0] * face_spec->size[1] * face_spec->size[2], g_typesize); meta_copy_h2d(dev_face[(face_id & 1) ? face_id - 1 : face_id + 1], stuff, g_typesize * face_spec->size[0] * face_spec->size[1] * face_spec->size[2], async); //printf("**BEFORE**\n"); //check_buffer(face[face_id], dev_face[(face_id & 1) ? face_id-1 : face_id+1], face_spec->size[0]*face_spec->size[1]*face_spec->size[2]); //printf("**********\n"); //check_dims(dimgrid_red, dimblock_red, trans_dim); //TODO Figure out what's wrong with transpose and re-enable ret = meta_transpose_face(NULL, NULL, dev_face[face_id], dev_face[(face_id & 1) ? face_id - 1 : face_id + 1], &trans_dim, &trans_dim, g_type, async); printf("Transpose error: %d\n", ret); //printf("**AFTER***\n"); //check_buffer(face[face_id], dev_face[(face_id & 1) ? face_id-1 : face_id+1], face_spec->size[0]*face_spec->size[1]*face_spec->size[2]); //printf("**********\n"); //reduce the specific sums needed to check that transpose was correct meta_copy_h2d(reduction, zero, g_typesize, async); //shuffle the (local) X/Y dimension rtrans_dim[0] = trans_dim[1]; rtrans_dim[1] = trans_dim[0]; rtrans_dim[2] = 1; start_2d[0] = start_2d[1] = start_2d[2] = 0; end_2d[0] = trans_dim[0] - 1, end_2d[1] = trans_dim[1] - 1, end_2d[2] = 0; //check_dims(rtrans_dim, start_2d, end_2d); ret = meta_reduce(autoconfig ? NULL : &dimgrid_red, autoconfig ? NULL : &dimblock_red, dev_face[(face_id & 1) ? face_id - 1 : face_id + 1], &trans_dim, &start_2d, &end_2d, reduction, g_type, async); //ret = meta_reduce(NULL, NULL, dev_face[(face_id & 1)? face_id-1 : face_id+1], &trans_dim, &start_2d, &end_2d, reduction, g_type, async); meta_copy_d2h(sum_gpu, reduction, g_typesize, async); //The 4 ternaries ensure the right args are passed to match the face // so this one call will work for any face printf("Transposed Face Integrity Check: %s\n", check_face_sum(sum_gpu, (face_id < 4 ? nj : nk), (face_id < 2 || face_id > 3 ? ni : nk), (face_id & 1 ? (face_id < 2 ? nk - 1 : (face_id < 4 ? ni - 1 : nj - 1)) : 0)) ? "FAILED" : "PASSED"); //transpose the face back //TODO figure out what's wrong with transpose and re-enable ret = meta_transpose_face(autoconfig ? NULL : &dimgrid_red, autoconfig ? NULL : &dimblock_red, dev_face[(face_id & 1) ? face_id - 1 : face_id + 1], dev_face[face_id], &rtrans_dim, &rtrans_dim, g_type, async); //check_buffer(face[face_id], dev_face[face_id], face_spec->size[0]*face_spec->size[1]*face_spec->size[2]); //reduce the specified sums to ensure the reverse transpose worked too meta_copy_h2d(reduction, zero, g_typesize, async); start_2d[0] = start_2d[1] = start_2d[2] = 0; end_2d[0] = rtrans_dim[0] - 1, end_2d[1] = rtrans_dim[1] - 1, end_2d[2] = 0; dimgrid_tr_red[0] = dimgrid_red[1]; dimgrid_tr_red[1] = dimgrid_red[0]; dimgrid_tr_red[2] = dimgrid_red[2]; ret = meta_reduce(autoconfig ? NULL : &dimgrid_tr_red, autoconfig ? NULL : &dimblock_red, dev_face[(face_id & 1) ? face_id - 1 : face_id + 1], &rtrans_dim, &start_2d, &end_2d, reduction, g_type, async); meta_copy_d2h(sum_gpu, reduction, g_typesize, async); //The 4 ternaries ensure the right args are passed to match the face // so this one call will work for any face printf("Retransposed Face Integrity Check: %s\n", check_face_sum(sum_gpu, (face_id < 4 ? nj : nk), (face_id < 2 || face_id > 3 ? ni : nk), (face_id & 1 ? (face_id < 2 ? nk - 1 : (face_id < 4 ? ni - 1 : nj - 1)) : 0)) ? "FAILED" : "PASSED"); ; //send the packed face to proc1 ret = meta_mpi_packed_face_send(1, dev_face[face_id], trans_dim[0] * trans_dim[1], i, &request, g_type, async); //Force the recv and unpack to finish meta_flush(); //At this point the send should be forced to complete // which means there's either a failure in the SP helper or the RP helper //receive and unpack the face //TODO set a_dim3 structs - i believe these are fine //TODO set the face_spec - believe these are fine ret = meta_mpi_recv_and_unpack_face( autoconfig ? NULL : &dimgrid_red, autoconfig ? NULL : &dimblock_red, 1, face_spec, dev_data3, dev_face[face_id], i, &request, g_type, async); //Force the recv and unpack to finish meta_flush(); meta_copy_h2d(reduction, zero, g_typesize, async); arr_start[0] = ((face_id == 3) ? ni - 1 : 0); arr_end[0] = ((face_id == 2) ? 0 : ni - 1); arr_start[1] = ((face_id == 5) ? nj - 1 : 0); arr_end[1] = ((face_id == 4) ? 0 : nj - 1); arr_start[2] = ((face_id == 1) ? nk - 1 : 0); arr_end[2] = ((face_id == 0) ? 0 : nk - 1); //check_dims(dimarray_3d, arr_start, arr_end); ret = meta_reduce(autoconfig ? NULL : &dimgrid_red, autoconfig ? NULL : &dimblock_red, dev_data3, &dimarray_3d, &arr_start, &arr_end, reduction, g_type, async); meta_copy_d2h(sum_gpu, reduction, g_typesize, async); //The 4 ternaries ensure the right args are passed to match the face // so this one call will work for any face printf("RecvAndUnpacked ZeroFace Integrity Check: %s\n", (check_fp(0.0, *((double*) sum_gpu), 0.000001)) ? "PASSED" : "FAILED"); if (!check_fp(0.0, *((double*) sum_gpu), 0.000001)) printf("\tExpected [0.0], returned [%f]!\n", sum_gpu); ret = meta_mpi_recv_and_unpack_face( autoconfig ? NULL : &dimgrid_red, autoconfig ? NULL : &dimblock_red, 1, face_spec, dev_data3, dev_face[face_id], i, &request, g_type, async); //Force the recv and unpack to finish meta_flush(); meta_copy_h2d(reduction, zero, g_typesize, async); arr_start[0] = ((face_id == 3) ? ni - 1 : 0); arr_end[0] = ((face_id == 2) ? 0 : ni - 1); arr_start[1] = ((face_id == 5) ? nj - 1 : 0); arr_end[1] = ((face_id == 4) ? 0 : nj - 1); arr_start[2] = ((face_id == 1) ? nk - 1 : 0); arr_end[2] = ((face_id == 0) ? 0 : nk - 1); //check_dims(dimarray_3d, arr_start, arr_end); ret = meta_reduce(autoconfig ? NULL : &dimgrid_red, autoconfig ? NULL : &dimblock_red, dev_data3, &dimarray_3d, &arr_start, &arr_end, reduction, g_type, async); meta_copy_d2h(sum_gpu, reduction, g_typesize, async); //The 4 ternaries ensure the right args are passed to match the face // so this one call will work for any face printf("RecvAndUnpacked Face Integrity Check: %s\n", check_face_sum(sum_gpu, (face_id < 4 ? nj : nk), (face_id < 2 || face_id > 3 ? ni : nk), (face_id & 1 ? (face_id < 2 ? nk - 1 : (face_id < 4 ? ni - 1 : nj - 1)) : 0)) ? "FAILED" : "PASSED"); //TODO reduce the specified sub-sums on the face to further check accuracy of placement } else {
meta_copy_d2h(sum_gpu, reduction, g_typesize, async); //The 4 ternaries ensure the right args are passed to match the face // so this one call will work for any face printf("RecvAndUnpacked Face Integrity Check: %s\n", check_face_sum(sum_gpu, (face_id < 4 ? nj : nk), (face_id < 2 || face_id > 3 ? ni : nk), (face_id & 1 ? (face_id < 2 ? nk - 1 : (face_id < 4 ? ni - 1 : nj - 1)) : 0)) ? "FAILED" : "PASSED"); //TODO reduce the specified sub-sums on the face to further check accuracy of placement } else { //receive the packed buf //TODO fill in <buf_leng> face_spec = make_face(face_id, ni, nj, nk); meta_face * opp_face = make_face( (face_id & 1 ? face_id - 1 : face_id + 1), ni, nj, nk); //one of the faces should always be size = 1, since we're only taking a 1-deep subsection // thus, the size of the recv buffer can be the product of all 3 elements a_err ret = meta_mpi_packed_face_recv(0, dev_face[face_id], face_spec->size[0] * face_spec->size[1] * face_spec->size[2], i, &request, g_type, async); //Force the recv and unpack to finish //FIXME this flush appears to invalidate something needed by the ensuing reduce at L:570 meta_flush(); //check_buffer(face[face_id], dev_face[face_id], face_spec->size[0]*face_spec->size[1]*face_spec->size[2]);i //check_buffer(face[face_id], dev_face[face_id], face_spec->size[0]*face_spec->size[1]*face_spec->size[2]); //TODO reduce the packed buf to check the sum - this should be fine
Cube :: Cube(float my_size) { // adjust size to form around the origin h = my_size/2.0; // define number of vertices verts_size = 8; verts = new GLfloat*[verts_size]; // define the number of faces faces_size = 12; faces = new int*[faces_size]; // define arrays for normals v_norms = new GLfloat*[verts_size]; f_norms = new GLfloat*[faces_size]; // VERTICES ///////////////////////////////////////////// // front-top-right corner make_vert(0, -h, h, h); // front-bottom-right corner make_vert(1, -h, -h, h); // front-bottom-left corner make_vert(2, h, -h, h); // front-top-left corner make_vert(3, h, h, h); // back-top-right corner make_vert(4, -h, h, -h); // back-bottom-right corner make_vert(5, -h, -h, -h); // back-bottom-left corner make_vert(6, h, -h, -h); // back-top-left corner make_vert(7, h, h, -h); // FACES + NORMALS ///////////////////////////////////////////// // front face 1 make_face(0, 3, 2, 1); // front face 2 make_face(1, 3, 1, 0); // left face 1 make_face(2, 7, 6, 2); // left face 2 make_face(3, 7, 2, 3); // back face 1 make_face(4, 4, 5, 6); // back face 2 make_face(5, 4, 6, 7); // right face 1 make_face(6, 0, 1, 5); // right face 2 make_face(7, 0, 5, 4); // top face 1 make_face(8, 7, 3, 0); // top face 2 make_face(9, 7, 0, 4); // bottom face 1 make_face(10, 2, 6, 5); // bottom face 2 make_face(11, 2, 5, 1); // VERTEX NORMALS ///////////////////////////////////////////// // NOTE: The cube vertices have a varying // number of faces (some of which have the same normal). // This makes calculating the normals difficult. // Because there are only 8 vertices, // it is simple enough to just hard code them in. v_norms[0][0] = -1.0/3.0; v_norms[0][1] = 1.0/3.0; v_norms[0][2] = 1.0/3.0; v_norms[0][3] = 1.0; v_norms[1][0] = -1.0/3.0; v_norms[1][1] = -1.0/3.0; v_norms[1][2] = 1.0/3.0; v_norms[1][3] = 1.0; v_norms[2][0] = 1.0/3.0; v_norms[2][1] = -1.0/3.0; v_norms[2][2] = 1.0/3.0; v_norms[2][3] = 1.0; v_norms[3][0] = 1.0/3.0; v_norms[3][1] = 1.0/3.0; v_norms[3][2] = 1.0/3.0; v_norms[3][3] = 1.0; v_norms[4][0] = -1.0/3.0; v_norms[4][1] = 1.0/3.0; v_norms[4][2] = -1.0/3.0; v_norms[4][3] = 1.0; v_norms[5][0] = -1.0/3.0; v_norms[5][1] = -1.0/3.0; v_norms[5][2] = -1.0/3.0; v_norms[5][3] = 1.0; v_norms[6][0] = 1.0/3.0; v_norms[6][1] = -1.0/3.0; v_norms[6][2] = -1.0/3.0; v_norms[6][3] = 1.0; v_norms[7][0] = 1.0/3.0; v_norms[7][1] = 1.0/3.0; v_norms[7][2] = -1.0/3.0; v_norms[7][3] = 1.0; }
/** * triangulate the cube directly, without decomposition */ static void docube(PROCESS *process, CUBE *cube) { INTLISTS *polys; CORNER *c1, *c2; int i, index = 0, count, indexar[8]; /* Determine which case cube falls into. */ for (i = 0; i < 8; i++) { if (cube->corners[i]->value > 0.0f) { index += (1 << i); } } /* Using faces[] table, adds neighbouring cube if surface intersects face in this direction. */ if (MB_BIT(faces[index], 0)) add_cube(process, cube->i - 1, cube->j, cube->k); if (MB_BIT(faces[index], 1)) add_cube(process, cube->i + 1, cube->j, cube->k); if (MB_BIT(faces[index], 2)) add_cube(process, cube->i, cube->j - 1, cube->k); if (MB_BIT(faces[index], 3)) add_cube(process, cube->i, cube->j + 1, cube->k); if (MB_BIT(faces[index], 4)) add_cube(process, cube->i, cube->j, cube->k - 1); if (MB_BIT(faces[index], 5)) add_cube(process, cube->i, cube->j, cube->k + 1); /* Using cubetable[], determines polygons for output. */ for (polys = cubetable[index]; polys; polys = polys->next) { INTLIST *edges; count = 0; /* Sets needed vertex id's lying on the edges. */ for (edges = polys->list; edges; edges = edges->next) { c1 = cube->corners[corner1[edges->i]]; c2 = cube->corners[corner2[edges->i]]; indexar[count] = vertid(process, c1, c2); count++; } /* Adds faces to output. */ if (count > 2) { switch (count) { case 3: make_face(process, indexar[2], indexar[1], indexar[0], 0); break; case 4: if (indexar[0] == 0) make_face(process, indexar[0], indexar[3], indexar[2], indexar[1]); else make_face(process, indexar[3], indexar[2], indexar[1], indexar[0]); break; case 5: if (indexar[0] == 0) make_face(process, indexar[0], indexar[3], indexar[2], indexar[1]); else make_face(process, indexar[3], indexar[2], indexar[1], indexar[0]); make_face(process, indexar[4], indexar[3], indexar[0], 0); break; case 6: if (indexar[0] == 0) { make_face(process, indexar[0], indexar[3], indexar[2], indexar[1]); make_face(process, indexar[0], indexar[5], indexar[4], indexar[3]); } else { make_face(process, indexar[3], indexar[2], indexar[1], indexar[0]); make_face(process, indexar[5], indexar[4], indexar[3], indexar[0]); } break; case 7: if (indexar[0] == 0) { make_face(process, indexar[0], indexar[3], indexar[2], indexar[1]); make_face(process, indexar[0], indexar[5], indexar[4], indexar[3]); } else { make_face(process, indexar[3], indexar[2], indexar[1], indexar[0]); make_face(process, indexar[5], indexar[4], indexar[3], indexar[0]); } make_face(process, indexar[6], indexar[5], indexar[0], 0); break; } } } }