void cursor_scroll_right(file_t * file) { /* Scroll right */ file->rend->x_off+=DELTA_RIGHT_SCROLL; HMOVEN(LEFT, DELTA_RIGHT_SCROLL); HMOVE(RIGHT); /* damn cursor won't go to its place */ }
static void rt_arbn_faces_area(struct poly_face* faces, struct rt_arbn_internal* aip) { size_t i; size_t *npts = (size_t *)bu_calloc(aip->neqn, sizeof(size_t), "rt_arbn_faces_area: npts"); point_t **tmp_pts = (point_t **)bu_calloc(aip->neqn, sizeof(point_t *), "rt_arbn_faces_area: tmp_pts"); plane_t *eqs = (plane_t *)bu_calloc(aip->neqn, sizeof(plane_t), "rt_arbn_faces_area: eqs"); for (i = 0; i < aip->neqn; i++) { HMOVE(faces[i].plane_eqn, aip->eqn[i]); VUNITIZE(faces[i].plane_eqn); tmp_pts[i] = faces[i].pts; HMOVE(eqs[i], faces[i].plane_eqn); } bn_polygon_mk_pts_planes(npts, tmp_pts, aip->neqn, (const plane_t *)eqs); for (i = 0; i < aip->neqn; i++) { faces[i].npts = npts[i]; bn_polygon_sort_ccw(faces[i].npts, faces[i].pts, faces[i].plane_eqn); bn_polygon_area(&faces[i].area, faces[i].npts, (const point_t *)faces[i].pts); } bu_free((char *)tmp_pts, "rt_arbn_faces_area: tmp_pts"); bu_free((char *)npts, "rt_arbn_faces_area: npts"); bu_free((char *)eqs, "rt_arbn_faces_area: eqs"); }
static struct face_g_plane * nmg_construct_face_g_plane(const struct face_g_plane *original, void **structArray) { struct face_g_plane *ret; NMG_GETSTRUCT(ret, face_g_plane); ret->magic = NMG_FACE_G_PLANE_MAGIC; BU_LIST_INIT(&ret->f_hd); HMOVE(ret->N, original->N); ret->index = original->index; structArray[ret->index] = ret; return ret; }
int ged_quat(struct ged *gedp, int argc, const char *argv[]) { quat_t quat; double scan[4]; static const char *usage = "a b c d"; GED_CHECK_DATABASE_OPEN(gedp, GED_ERROR); GED_CHECK_VIEW(gedp, GED_ERROR); GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR); /* initialize result */ bu_vls_trunc(gedp->ged_result_str, 0); /* return Viewrot as a quaternion */ if (argc == 1) { quat_mat2quat(quat, gedp->ged_gvp->gv_rotation); bu_vls_printf(gedp->ged_result_str, "%.12g %.12g %.12g %.12g", V4ARGS(quat)); return GED_OK; } if (argc != 5) { bu_vls_printf(gedp->ged_result_str, "Usage: view %s %s", argv[0], usage); return GED_ERROR; } /* Set the view orientation given a quaternion */ if (sscanf(argv[1], "%lf", &scan[0]) != 1 || sscanf(argv[2], "%lf", &scan[1]) != 1 || sscanf(argv[3], "%lf", &scan[2]) != 1 || sscanf(argv[4], "%lf", &scan[3]) != 1) { bu_vls_printf(gedp->ged_result_str, "view %s: bad value detected - %s %s %s %s", argv[0], argv[1], argv[2], argv[3], argv[4]); return GED_ERROR; } HMOVE(quat, scan); quat_quat2mat(gedp->ged_gvp->gv_rotation, quat); ged_view_update(gedp->ged_gvp); return GED_OK; }
int soup_add_face_precomputed(struct soup_s *s, point_t a, point_t b , point_t c, plane_t d, uint32_t foo) { struct face_s *f; vect_t e1, e2, x; VSUB2(e1, b, a); VSUB2(e2, c, a); VCROSS(x, e1, e2); /* grow face array if needed */ if (s->nfaces >= s->maxfaces) s->faces = (struct face_s *)bu_realloc(s->faces, (s->maxfaces += faces_per_page) * sizeof(struct face_s), "bot soup faces"); f = s->faces + s->nfaces; VMOVE(f->vert[0], a); if (VDOT(x, d) <= 0) { VMOVE(f->vert[1], b); VMOVE(f->vert[2], c); } else { VMOVE(f->vert[1], c); VMOVE(f->vert[2], b); } HMOVE(f->plane, d); /* solve the bounding box (should this be VMINMAX?) */ VMOVE(f->min, f->vert[0]); VMOVE(f->max, f->vert[0]); VMIN(f->min, f->vert[1]); VMAX(f->max, f->vert[1]); VMIN(f->min, f->vert[2]); VMAX(f->max, f->vert[2]); /* fluff the bounding box for fp fuzz */ f->min[X]-=.1; f->min[Y]-=.1; f->min[Z]-=.1; f->max[X]+=.1; f->max[Y]+=.1; f->max[Z]+=.1; f->foo = foo; s->nfaces++; return 0; }
int rt_nurb_s_flat(struct face_g_snurb *srf, fastf_t epsilon) /* Epsilon value for flatness testing */ { register fastf_t max_row_dist; register fastf_t max_col_dist; register fastf_t max_dist; int dir; fastf_t * mesh_ptr = srf->ctl_points; int coords = RT_NURB_EXTRACT_COORDS(srf->pt_type); int j, i, k; int mesh_elt; vect_t p1, p2, p3, p4, v1, v2, v3; vect_t nrm; fastf_t nrmln; fastf_t dist; fastf_t * crv; int otherdir; dir = srf->dir; otherdir = (dir == RT_NURB_SPLIT_ROW) ? RT_NURB_SPLIT_COL : RT_NURB_SPLIT_ROW; max_row_dist = max_col_dist = -INFINITY; crv = (fastf_t *) bu_malloc(sizeof(fastf_t) * RT_NURB_EXTRACT_COORDS(srf->pt_type) * srf->s_size[1], "rt_nurb_s_flat: crv"); /* Test Row and RT_NURB_SPLIT_COL curves for flatness, If a curve * is not flat than get distance to line */ /* Test Row Curves */ for (i = 0; i < (srf->s_size[0]); i++) { fastf_t rdist; for (j = 0; j < (srf->s_size[1] * RT_NURB_EXTRACT_COORDS(srf->pt_type)); j++) crv[j] = *mesh_ptr++; rdist = rt_nurb_crv_flat(crv, srf->s_size[1], srf->pt_type); max_row_dist = FMAX(max_row_dist, rdist); } bu_free((char *)crv, "rt_nurb_s_flat: crv"); crv = (fastf_t *) bu_malloc(sizeof(fastf_t) * RT_NURB_EXTRACT_COORDS(srf->pt_type) * srf->s_size[0], "rt_nurb_s_flat: crv"); for (i = 0; i < (coords * srf->s_size[1]); i += coords) { fastf_t rdist; for (j = 0; j < (srf->s_size[0]); j++) { mesh_elt = (j * (srf->s_size[1] * coords)) + i; for (k = 0; k < coords; k++) crv[j * coords + k] = srf->ctl_points[mesh_elt + k]; } rdist = rt_nurb_crv_flat(crv, srf->s_size[0], srf->pt_type); max_col_dist = FMAX(max_col_dist, rdist); } bu_free((char *)crv, "rt_nurb_s_flat: crv"); max_dist = FMAX(max_row_dist, max_col_dist); if (max_dist > epsilon) { if (max_row_dist > max_col_dist) return RT_NURB_SPLIT_ROW; else return RT_NURB_SPLIT_COL; } /* Test the corners to see if they lie in a plane. */ /* * Extract the four corners and put a plane through three of them * and see how far the fourth is to the plane. */ mesh_ptr = srf->ctl_points; if (!RT_NURB_IS_PT_RATIONAL(srf->pt_type)) { VMOVE(p1, mesh_ptr); VMOVE(p2, (mesh_ptr + (srf->s_size[1] - 1) * coords)); VMOVE(p3, (mesh_ptr + ((srf->s_size[1] * (srf->s_size[0] - 1)) + (srf->s_size[1] - 1)) * coords)); VMOVE(p4, (mesh_ptr + (srf->s_size[1] * (srf->s_size[0] - 1)) * coords)); } else { hvect_t h1, h2, h3, h4; int offset; HMOVE(h1, mesh_ptr); HDIVIDE(p1, h1); offset = (srf->s_size[1] - 1) * coords; HMOVE(h2, mesh_ptr + offset); HDIVIDE(p2, h2); offset = ((srf->s_size[1] * (srf->s_size[0] - 1)) + (srf->s_size[1] - 1)) * coords; HMOVE(h3, mesh_ptr + offset); HDIVIDE(p3, h3); offset = (srf->s_size[1] * (srf->s_size[0] - 1)) * coords; HMOVE(h4, mesh_ptr + offset); HDIVIDE(p4, h4); } VSUB2(v1, p2, p1); VSUB2(v2, p3, p1); VCROSS(nrm, v1, v2); nrmln = MAGNITUDE(nrm); if (nrmln < 0.0001) /* XXX Why this constant? */ return RT_NURB_SPLIT_FLAT; VSUB2(v3, p4, p1); dist = fabs(VDOT(v3, nrm)) / nrmln; if (dist > epsilon) return otherdir; return RT_NURB_SPLIT_FLAT; /* Must be flat */ }
fastf_t rt_nurb_crv_flat(fastf_t *crv, int size, int pt_type) { point_t p1, p2; vect_t ln; int i; fastf_t dist; fastf_t max_dist; fastf_t length; fastf_t * c_ptr; vect_t testv, xp; hvect_t h1, h2; int coords; int rational; coords = RT_NURB_EXTRACT_COORDS(pt_type); rational = RT_NURB_IS_PT_RATIONAL(pt_type); max_dist = -INFINITY; if (!rational) { VMOVE(p1, crv); } else { HMOVE(h1, crv); HDIVIDE(p1, h1); } length = 0.0; /* * loop through all of the points until a line is found which may * not be the end pts of the curve if the endpoints are the same. */ for (i = size - 1; (i > 0) && length < SQRT_SMALL_FASTF; i--) { if (!rational) { VMOVE(p2, (crv + (i * coords))); } else { HMOVE(h2, (crv + (i * coords))); HDIVIDE(p2, h2); } VSUB2(ln, p1, p2); length = MAGNITUDE(ln); } if (length >= SQRT_SMALL_FASTF) { VSCALE(ln, ln, 1.0 / length); c_ptr = crv + coords; for (i = 1; i < size; i++) { if (!rational) { VSUB2(testv, p1, c_ptr); } else { HDIVIDE(h2, c_ptr); VSUB2(testv, p1, h2); } VCROSS(xp, testv, ln); dist = MAGNITUDE(xp); max_dist = FMAX(max_dist, dist); c_ptr += coords; } } return max_dist; }
int main(int argc, char *argv[]) { int count, status, num_read, enn, i, pp; fastf_t *points, *cur; fastf_t yaw, pch, rll, stepsize; /* intentionally double for scan */ double first[4]; double second[4]; double scan[4]; if (argc == 1 && isatty(fileno(stdin)) && isatty(fileno(stdout))) { usage(); return 0; } if (!get_args(argc, argv)) { usage(); return 0; } yaw = pch = rll = 0.0; /* read first two lines of table to determine the time step used */ /* (a constant time step is assumed throughout the rest of the file)*/ count = scanf("%lf %lf %lf %lf", first, first+1, first+2, first+3); count += scanf("%lf %lf %lf %lf", second, second+1, second+2, second+3); stepsize = second[0]-first[0]; if (count != 8) { bu_exit(1, "%s: ERROR: expecting at least eight values (in the first two lines of the table) to determine the time step used\n", argv[0]); } /* determine n, the number of points to store ahead and behind the * current point. 2n points are stored, minimum enn=2 */ enn = (int) (desired_step/stepsize); CLAMP(enn, 1, MAXN); /* allocate storage */ points = (fastf_t *) bu_calloc((3*enn+1)*4, sizeof(fastf_t), "points"); /* read the first 3n points into the storage array*/ VMOVEN(points+4, first, 4); VMOVEN(points+8, second, 4); num_read=4; /* in order to pass test if n=1 */ for (cur=points+12; cur<points+(4*(3*enn+1)); cur+=4) { num_read=scanf("%lf %lf %lf %lf", &scan[0], &scan[1], &scan[2], &scan[3]); /* convert double to fastf_t */ HMOVE(cur, scan); } if (num_read<4) { fprintf(stderr, "Anim_fly: Not enough lines in input table.\n"); fprintf(stderr, "Increase number of lines or reduce the minimum stepsize with -s.\n"); fprintf(stderr, "Currently the minimum step size is %g seconds.\n", desired_step); return 0; } max_cross = 0; count = 0; pp = 0; status = START; while (status != STOP) { switch (status) { case START: /* first n points */ pp += 4; get_orientation(points+pp, points+pp+4*enn, points+pp+4*2*enn, f_prm_0, &yaw, &pch, &rll); if (!(count%print_int)&&!estimate_f) { printf("%.10g\t%.10g\t%.10g\t%.10g\t%.10g\t%.10g\t%.10g\n", points[pp+0], points[pp+1], points[pp+2], points[pp+3], yaw, pch, rll); } if (pp >= 4*enn) status=MIDDLE; break; case MIDDLE: /* middle points (at least one)*/ for (i=0; i<3*enn*4; i++) { VMOVEN(points+(4*i), points+(4*(i+1)), 4); } num_read=scanf("%lf %lf %lf %lf", &scan[0], &scan[1], &scan[2], &scan[3]); /* convert double to fastf_t */ HMOVE(points+(4*(3*enn)), scan); if (num_read < 4) { pp = 0; status = WANE; } get_orientation(points, points+(4*enn), points+4*(2*enn), f_prm_1, &yaw, &pch, &rll); if (!(count%print_int)&&!estimate_f) { printf("%.10g\t%.10g\t%.10g\t%.10g\t%.10g\t%.10g\t%.10g\n", points[4*(enn)+0], points[4*(enn)+1], points[4*(enn)+2], points[4*(enn)+3], yaw, pch, rll); } break; case WANE: /* last n - 1 middle points */ pp += 4; if (pp >= 4*enn) { status = END; count--; pp = 0; break; } get_orientation(points+pp, points+pp+4*enn, points+pp+4*2*enn, f_prm_1, &yaw, &pch, &rll); if (!(count%print_int)&&!estimate_f) { printf("%.10g\t%.10g\t%.10g\t%.10g\t%.10g\t%.10g\t%.10g\n", points[4*(enn)+0+pp], points[4*(enn)+1+pp], points[4*(enn)+2+pp], points[4*(enn)+3+pp], yaw, pch, rll); } break; case END: /* last n points */ get_orientation(points+pp, points+pp+4*enn, points+pp+4*2*enn, f_prm_2, &yaw, &pch, &rll); if (!(count%print_int)&&!estimate_f) { printf("%.10g\t%.10g\t%.10g\t%.10g\t%.10g\t%.10g\t%.10g\n", points[8*enn+pp+0], points[8*enn+pp+1], points[8*enn+pp+2], points[8*enn+pp+3], yaw, pch, rll); } pp += 4; if (pp >= 4*enn) status = STOP; break; } count++; } /* Return the factor needed to achieve the requested max_bank */ if (estimate_f) { if (max_cross < VDIVIDE_TOL) { printf("%.10g\n", 0.0); } else { printf("%.10g\n", 1000.0 * max_bank/max_cross); } } bu_free(points, "points"); return 0; }
void render_cut_work(render_t *render, struct tie_s *tiep, struct tie_ray_s *ray, vect_t *pixel) { render_cut_t *rd; render_cut_hit_t hit; vect_t color; struct tie_id_s id; tfloat t, dot; rd = (render_cut_t *)render->data; /* Draw Arrow - Blue */ if (tie_work(&rd->tie, ray, &id, render_arrow_hit, NULL)) { VSET(*pixel, 0.0, 0.0, 1.0); return; } /* * I don't think this needs to be done for every pixel? * Flip plane normal to face us. */ t = ray->pos[0]*rd->plane[0] + ray->pos[1]*rd->plane[1] + ray->pos[2]*rd->plane[2] + rd->plane[3]; hit.mod = t < 0 ? 1 : -1; /* * Optimization: * First intersect this ray with the plane and fire the ray from there * Plane: Ax + By + Cz + D = 0 * Ray = O + td * t = -(Pn · R0 + D) / (Pn · Rd) */ t = (rd->plane[0]*ray->pos[0] + rd->plane[1]*ray->pos[1] + rd->plane[2]*ray->pos[2] + rd->plane[3]) / (rd->plane[0]*ray->dir[0] + rd->plane[1]*ray->dir[1] + rd->plane[2]*ray->dir[2]); /* Ray never intersects plane */ if (t > 0) return; ray->pos[0] += -t * ray->dir[0]; ray->pos[1] += -t * ray->dir[1]; ray->pos[2] += -t * ray->dir[2]; HMOVE(hit.plane, rd->plane); /* Render Geometry */ if (!tie_work(tiep, ray, &id, render_cut_hit, &hit)) return; /* * If the point after the splitting plane is an outhit, fill it in as if it were solid. * If the point after the splitting plane is an inhit, then just shade as usual. */ /* flipped normal */ dot = fabs(VDOT( ray->dir, hit.id.norm)); if (hit.mesh->flags & (ADRT_MESH_SELECT|ADRT_MESH_HIT)) { VSET(color, hit.mesh->flags & ADRT_MESH_HIT ? (tfloat)0.9 : (tfloat)0.2, (tfloat)0.2, hit.mesh->flags & ADRT_MESH_SELECT ? (tfloat)0.9 : (tfloat)0.2); } else { /* Mix actual color with white 4:1, shade 50% darker */ #if 0 VSET(color, 1.0, 1.0, 1.0); VSCALE(color, color, 3.0); VADD2(color, color, hit.mesh->attributes->color); VSCALE(color, color, 0.125); #else VSET(color, (tfloat)0.8, (tfloat)0.8, (tfloat)0.7); #endif } #if 0 if (dot < 0) { #endif /* Shade using inhit */ VSCALE((*pixel), color, (dot*0.90)); #if 0 } else { TIE_3 vec; fastf_t angle; /* shade solid */ VSUB2(vec, ray->pos, hit.id.pos); VUNITIZE(vec); angle = vec[0]*hit.mod*-hit.plane[0] + vec[1]*-hit.mod*hit.plane[1] + vec[2]*-hit.mod*hit.plane[2]; VSCALE((*pixel), color, (angle*0.90)); } #endif *pixel[0] += (tfloat)0.1; *pixel[1] += (tfloat)0.1; *pixel[2] += (tfloat)0.1; }
/** * Convert from "network" doubles to machine specific. * Transform */ int rt_arbn_import5(struct rt_db_internal *ip, const struct bu_external *ep, const fastf_t *mat, const struct db_i *dbip) { struct rt_arbn_internal *aip; size_t i; unsigned long neqn; int double_count; size_t byte_count; /* must be double for import and export */ double *eqn; RT_CK_DB_INTERNAL(ip); BU_CK_EXTERNAL(ep); if (dbip) RT_CK_DBI(dbip); neqn = ntohl(*(uint32_t *)ep->ext_buf); double_count = neqn * ELEMENTS_PER_PLANE; byte_count = double_count * SIZEOF_NETWORK_DOUBLE; BU_ASSERT_LONG(ep->ext_nbytes, ==, 4+ byte_count); ip->idb_major_type = DB5_MAJORTYPE_BRLCAD; ip->idb_type = ID_ARBN; ip->idb_meth = &OBJ[ID_ARBN]; BU_ALLOC(ip->idb_ptr, struct rt_arbn_internal); aip = (struct rt_arbn_internal *)ip->idb_ptr; aip->magic = RT_ARBN_INTERNAL_MAGIC; aip->neqn = neqn; if (aip->neqn <= 0) return -1; eqn = (double *)bu_malloc(byte_count, "arbn plane eqn[] temp buf"); bu_cv_ntohd((unsigned char *)eqn, (unsigned char *)ep->ext_buf + ELEMENTS_PER_PLANE, double_count); aip->eqn = (plane_t *)bu_malloc(double_count * sizeof(fastf_t), "arbn plane eqn[]"); for (i = 0; i < aip->neqn; i++) { HMOVE(aip->eqn[i], &eqn[i*ELEMENTS_PER_PLANE]); } bu_free(eqn, "arbn plane eqn[] temp buf"); /* Transform by the matrix, if we have one that is not the identity */ if (mat && !bn_mat_is_identity(mat)) { for (i = 0; i < aip->neqn; i++) { point_t orig_pt; point_t pt; vect_t norm; fastf_t factor; /* unitize the plane equation first */ factor = 1.0 / MAGNITUDE(aip->eqn[i]); VSCALE(aip->eqn[i], aip->eqn[i], factor); aip->eqn[i][W] = aip->eqn[i][W] * factor; /* Pick a point on the original halfspace */ VSCALE(orig_pt, aip->eqn[i], aip->eqn[i][W]); /* Transform the point, and the normal */ MAT4X3VEC(norm, mat, aip->eqn[i]); MAT4X3PNT(pt, mat, orig_pt); /* Measure new distance from origin to new point */ VUNITIZE(norm); VMOVE(aip->eqn[i], norm); aip->eqn[i][W] = VDOT(pt, norm); } } return 0; }