void writeRectangularBox ( rt_wdb* wdbp, Form& form, bool translate ) { char name[NAMELEN + 1]; point_t min, max; if (translate) { VADD2(min, form.data.pt[0], form.tr_vec); VADD2(max, form.data.pt[1], form.tr_vec); } else { VMOVE(min, form.data.pt[0]); VMOVE(max, form.data.pt[1]); } VSCALE(min, min, IntavalUnitInMm); VSCALE(max, max, IntavalUnitInMm); sprintf(name, "s%lu.rpp", (long unsigned int)++rpp_counter); mk_rpp(wdbp, name, min, max); addToRegion(form.compnr, name); if (form.s_compnr >= 1000) excludeFromRegion(form.s_compnr, name); }
static int move_walk(ClientData UNUSED(clientData), Tcl_Interp *interp, int UNUSED(objc), Tcl_Obj *const *objv) { struct isst_s *isst; Togl *togl; vect_t vec; int flag; if (Togl_GetToglFromObj(interp, objv[1], &togl) != TCL_OK) return TCL_ERROR; isst = (struct isst_s *) Togl_GetClientData(togl); if (Tcl_GetIntFromObj(interp, objv[2], &flag) != TCL_OK) return TCL_ERROR; if (flag >= 0) { VSUB2(vec, isst->camera.focus, isst->camera.pos); VSCALE(vec, vec, 0.1 * isst->tie->radius); VADD2(isst->camera.pos, isst->camera.pos, vec); VADD2(isst->camera.focus, isst->camera.focus, vec); } else { VSUB2(vec, isst->camera.pos, isst->camera.focus); VSCALE(vec, vec, 0.1 * isst->tie->radius); VADD2(isst->camera.pos, isst->camera.pos, vec); VADD2(isst->camera.focus, isst->camera.focus, vec); } isst->dirty = 1; return TCL_OK; }
/* void gridRotate(fastf_t azim, fastf_t elev, fastf_t roll, fastf_t *des_H, fastf_t *des_V) Creates the unit vectors H and V which are the horizontal and vertical components of the grid in target coordinates. The vectors are found from the azimuth and elevation of the viewing angle according to a simplification of the rotation matrix from grid coordinates to target coordinates. To see that the vectors are, indeed, unit vectors, recall the trigonometric relation: sin(A)^2 + cos(A)^2 = 1 . */ void gridRotate(fastf_t azim, fastf_t elev, fastf_t roll, fastf_t *des_H, fastf_t *des_V) { fastf_t sn_azm = sin(azim); fastf_t cs_azm = cos(azim); fastf_t sn_elv = sin(elev); des_H[0] = -sn_azm; des_H[1] = cs_azm; des_H[2] = 0.0; des_V[0] = -sn_elv*cs_azm; des_V[1] = -sn_elv*sn_azm; des_V[2] = cos(elev); if (!ZERO(roll)) { fastf_t tmp_V[3], tmp_H[3], prime_V[3]; fastf_t sn_roll = sin(roll); fastf_t cs_roll = cos(roll); VSCALE(tmp_V, des_V, cs_roll); VSCALE(tmp_H, des_H, sn_roll); VADD2(prime_V, tmp_V, tmp_H); VSCALE(tmp_V, des_V, -sn_roll); VSCALE(tmp_H, des_H, cs_roll); VADD2(des_H, tmp_V, tmp_H); VMOVE(des_V, prime_V); } return; }
int ged_model2view_lu(struct ged *gedp, int argc, const char *argv[]) { fastf_t f; point_t view_pt; double model_pt[3]; /* intentionally double for scan */ static const char *usage = "x y z"; 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); if (argc != 4) goto bad; if (sscanf(argv[1], "%lf", &model_pt[X]) != 1 || sscanf(argv[2], "%lf", &model_pt[Y]) != 1 || sscanf(argv[3], "%lf", &model_pt[Z]) != 1) goto bad; VSCALE(model_pt, model_pt, gedp->ged_wdbp->dbip->dbi_local2base); MAT4X3PNT(view_pt, gedp->ged_gvp->gv_model2view, model_pt); f = gedp->ged_gvp->gv_scale * gedp->ged_wdbp->dbip->dbi_base2local; VSCALE(view_pt, view_pt, f); bn_encode_vect(gedp->ged_result_str, view_pt); return GED_OK; bad: bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage); return GED_ERROR; }
int rt_superell_export4(struct bu_external *ep, const struct rt_db_internal *ip, double local2mm, const struct db_i *dbip) { struct rt_superell_internal *tip; union record *rec; if (dbip) RT_CK_DBI(dbip); RT_CK_DB_INTERNAL(ip); if (ip->idb_type != ID_SUPERELL) return -1; tip = (struct rt_superell_internal *)ip->idb_ptr; RT_SUPERELL_CK_MAGIC(tip); BU_CK_EXTERNAL(ep); ep->ext_nbytes = sizeof(union record); ep->ext_buf = (uint8_t *)bu_calloc(1, ep->ext_nbytes, "superell external"); rec = (union record *)ep->ext_buf; rec->s.s_id = ID_SOLID; rec->s.s_type = SUPERELL; /* NOTE: This also converts to dbfloat_t */ VSCALE(&rec->s.s_values[0], tip->v, local2mm); VSCALE(&rec->s.s_values[3], tip->a, local2mm); VSCALE(&rec->s.s_values[6], tip->b, local2mm); VSCALE(&rec->s.s_values[9], tip->c, local2mm); printf("SUPERELL: %g %g\n", tip->n, tip->e); rec->s.s_values[12] = tip->n; rec->s.s_values[13] = tip->e; return 0; }
/** * The external format is: * V point * A vector * B vector * C vector */ int rt_superell_export5(struct bu_external *ep, const struct rt_db_internal *ip, double local2mm, const struct db_i *dbip) { struct rt_superell_internal *eip; /* must be double for import and export */ double vec[ELEMENTS_PER_VECT*4 + 2]; if (dbip) RT_CK_DBI(dbip); RT_CK_DB_INTERNAL(ip); if (ip->idb_type != ID_SUPERELL) return -1; eip = (struct rt_superell_internal *)ip->idb_ptr; RT_SUPERELL_CK_MAGIC(eip); BU_CK_EXTERNAL(ep); ep->ext_nbytes = SIZEOF_NETWORK_DOUBLE * (ELEMENTS_PER_VECT*4 + 2); ep->ext_buf = (uint8_t *)bu_malloc(ep->ext_nbytes, "superell external"); /* scale 'em into local buffer */ VSCALE(&vec[0*ELEMENTS_PER_VECT], eip->v, local2mm); VSCALE(&vec[1*ELEMENTS_PER_VECT], eip->a, local2mm); VSCALE(&vec[2*ELEMENTS_PER_VECT], eip->b, local2mm); VSCALE(&vec[3*ELEMENTS_PER_VECT], eip->c, local2mm); vec[4*ELEMENTS_PER_VECT] = eip->n; vec[4*ELEMENTS_PER_VECT + 1] = eip->e; /* Convert from internal (host) to database (network) format */ bu_cv_htond(ep->ext_buf, (unsigned char *)vec, ELEMENTS_PER_VECT*4 + 2); return 0; }
int _ged_do_tra(struct ged *gedp, char coord, vect_t tvec, int (*func)()) { point_t delta; point_t work; point_t vc, nvc; if (func != (int (*)())0) return (*func)(gedp, coord, tvec); switch (coord) { case 'm': VSCALE(delta, tvec, -gedp->ged_wdbp->dbip->dbi_base2local); MAT_DELTAS_GET_NEG(vc, gedp->ged_gvp->gv_center); break; case 'v': default: VSCALE(tvec, tvec, -2.0*gedp->ged_wdbp->dbip->dbi_base2local*gedp->ged_gvp->gv_isize); MAT4X3PNT(work, gedp->ged_gvp->gv_view2model, tvec); MAT_DELTAS_GET_NEG(vc, gedp->ged_gvp->gv_center); VSUB2(delta, work, vc); break; } VSUB2(nvc, vc, delta); MAT_DELTAS_VEC_NEG(gedp->ged_gvp->gv_center, nvc); ged_view_update(gedp->ged_gvp); return GED_OK; }
int _ged_scale_rpc(struct ged *gedp, struct rt_rpc_internal *rpc, const char *attribute, fastf_t sf, int rflag) { RT_RPC_CK_MAGIC(rpc); switch (attribute[0]) { case 'b': case 'B': if (!rflag) sf /= MAGNITUDE(rpc->rpc_B); VSCALE(rpc->rpc_B, rpc->rpc_B, sf); break; case 'h': case 'H': if (!rflag) sf /= MAGNITUDE(rpc->rpc_H); VSCALE(rpc->rpc_H, rpc->rpc_H, sf); break; case 'r': case 'R': if (rflag) rpc->rpc_r *= sf; else rpc->rpc_r = sf; break; default: bu_vls_printf(gedp->ged_result_str, "bad rpc attribute - %s", attribute); return GED_ERROR; } return GED_OK; }
void top(fastf_t *vec1, fastf_t *vec2, fastf_t *t) { fastf_t tooch, mag; vect_t del, tvec; int i, j; tooch = t[2] * .25; del[0] = vec2[0] - vec1[0]; del[1] = 0.0; del[2] = vec2[2] - vec1[2]; mag = MAGNITUDE( del ); VSCALE(tvec, del, tooch/mag); VSUB2(&sol.s_values[0], vec1, tvec); VADD2(del, del, tvec); VADD2(&sol.s_values[3], del, tvec); tvec[0] = tvec[2] = 0.0; tvec[1] = t[1] - t[0]; VCROSS(del, tvec, &sol.s_values[3]); mag = MAGNITUDE( del ); if (del[2] < 0) mag *= -1.0; VSCALE(&sol.s_values[9], del, t[2]/mag); VADD2(&sol.s_values[6], &sol.s_values[3], &sol.s_values[9]); VMOVE(&sol.s_values[12], tvec); for (i=3; i<=9; i+=3) { j = i + 12; VADD2(&sol.s_values[j], &sol.s_values[i], tvec); } }
void writeCylinder ( rt_wdb* wdbp, Form& form, bool translate ) { char name[NAMELEN + 1]; vect_t base, height; if (translate) { VADD2(base, form.data.pt[0], form.tr_vec); } else { VMOVE(base, form.data.pt[0]); } VSUB2(height, form.data.pt[1], form.data.pt[0]); VSCALE(base, base, IntavalUnitInMm); VSCALE(height, height, IntavalUnitInMm); fastf_t radius = form.radius1 * IntavalUnitInMm; sprintf(name, "s%lu.rcc", (long unsigned)++rcc_counter); mk_rcc(wdbp, name, base, height, radius); addToRegion(form.compnr, name); if (form.s_compnr >= 1000) excludeFromRegion(form.s_compnr, name); }
int main(int argc, char **argv) { int c; fastf_t time, viewsize; fastf_t eyept[3], viewrot[16], angle[3], quat[4]; int anim_mat2ypr(fastf_t *, fastf_t *), anim_mat2zyx(const fastf_t *, fastf_t *), anim_mat2quat(fastf_t *, const fastf_t *); if (!get_args(argc, argv)) fprintf(stderr, "anim_keyread: get_args error"); while (!feof(stdin)) { /* read one keyframe */ scanf("%lf", &time); scanf("%lf", &viewsize); scanf("%lf %lf %lf", eyept, eyept+1, eyept+2); /* read in transposed matrix */ scanf("%lf %lf %lf %lf", viewrot+0, viewrot+4, viewrot+8, viewrot+12); scanf("%lf %lf %lf %lf", viewrot+1, viewrot+5, viewrot+9, viewrot+13); scanf("%lf %lf %lf %lf", viewrot+2, viewrot+6, viewrot+10, viewrot+14); scanf("%lf %lf %lf %lf", viewrot+3, viewrot+7, viewrot+11, viewrot+15); if (feof(stdin)) break; printf("%.10g\t%.10g\t%.10g\t%.10g\t%.10g\t", time, viewsize, eyept[0], eyept[1], eyept[2]); if (mode==YPR) { anim_v_unpermute(viewrot); c = anim_mat2ypr(angle, viewrot); if (c==ERROR1) fprintf(stderr, "Warning: yaw and roll arbitrarily defined at time = %f.\n", time); else if (c==ERROR2) fprintf(stderr, "Keyread: can't interpret matrix at time = %f.\n", time); if (units == DEGREES) VSCALE(angle, angle, RTOD); printf("%.10g\t%.10g\t%.10g\n", angle[0], angle[1], angle[2]); } else if (mode==XYZ) { c = anim_mat2zyx(angle, viewrot); if (c==ERROR1) fprintf(stderr, "Warning: x and z rotations arbitrarily defined at time = %f.\n", time); else if (c==ERROR2) fprintf(stderr, "Keyread: can't interpret matrix at time = %f\n.", time); if (units == DEGREES) VSCALE(angle, angle, RTOD); printf("%.10g\t%.10g\t%.10g\n", angle[X], angle[Y], angle[Z]); } else if (mode==QUATERNION) { anim_mat2quat(quat, viewrot); printf("%.10g\t%.10g\t%.10g\t%.10g\n", quat[X], quat[Y], quat[Z], quat[W]); } } return( 0 ); }
void rt_arbn_centroid(point_t *cent, const struct rt_db_internal *ip) { struct poly_face *faces; struct rt_arbn_internal *aip = (struct rt_arbn_internal *)ip->idb_ptr; size_t i; point_t arbit_point = VINIT_ZERO; fastf_t volume = 0.0; *cent[0] = 0.0; *cent[1] = 0.0; *cent[2] = 0.0; if (cent == NULL) return; /* allocate array of face structs */ faces = (struct poly_face *)bu_calloc(aip->neqn, sizeof(struct poly_face), "rt_arbn_centroid: faces"); for (i = 0; i < aip->neqn; i++) { /* allocate array of pt structs, max number of verts per faces = (# of faces) - 1 */ faces[i].pts = (point_t *)bu_calloc(aip->neqn - 1, sizeof(point_t), "rt_arbn_centroid: pts"); } rt_arbn_faces_area(faces, aip); for (i = 0; i < aip->neqn; i++) { bn_polygon_centroid(&faces[i].cent, faces[i].npts, (const point_t *) faces[i].pts); VADD2(arbit_point, arbit_point, faces[i].cent); } VSCALE(arbit_point, arbit_point, (1/aip->neqn)); for (i = 0; i < aip->neqn; i++) { vect_t tmp = VINIT_ZERO; /* calculate volume */ VSCALE(tmp, faces[i].plane_eqn, faces[i].area); faces[i].vol_pyramid = (VDOT(faces[i].pts[0], tmp)/3); volume += faces[i].vol_pyramid; /*Vector from arbit_point to centroid of face, results in h of pyramid */ VSUB2(faces[i].cent_pyramid, faces[i].cent, arbit_point); /*centroid of pyramid is 1/4 up from the bottom */ VSCALE(faces[i].cent_pyramid, faces[i].cent_pyramid, 0.75f); /* now cent_pyramid is back in the polyhedron */ VADD2(faces[i].cent_pyramid, faces[i].cent_pyramid, arbit_point); /* weight centroid of pyramid by pyramid's volume */ VSCALE(faces[i].cent_pyramid, faces[i].cent_pyramid, faces[i].vol_pyramid); /* add cent_pyramid to the centroid of the polyhedron */ VADD2(*cent, *cent, faces[i].cent_pyramid); } /* reverse the weighting */ VSCALE(*cent, *cent, (1/volume)); for (i = 0; i < aip->neqn; i++) { bu_free((char *)faces[i].pts, "rt_arbn_centroid: pts"); } bu_free((char *)faces, "rt_arbn_centroid: faces"); }
HIDDEN void get_cbar(void) { int eid, pid; int g1, g2; point_t pt1, pt2; fastf_t radius; vect_t height; struct pbar *pb; char cbar_name[NAMESIZE+1]; eid = atoi( curr_rec[1] ); pid = atoi( curr_rec[2] ); if ( !pid ) { if ( bar_def_pid ) pid = bar_def_pid; else pid = eid; } g1 = atoi( curr_rec[3] ); g2 = atoi( curr_rec[4] ); get_grid( g1, pt1 ); get_grid( g2, pt2 ); for ( BU_LIST_FOR( pb, pbar, &pbar_head.l ) ) { if ( pb->pid == pid ) break; } if ( BU_LIST_IS_HEAD( &pb->l, &pbar_head.l ) ) { log_line( "Non-existent PID referenced in CBAR" ); return; } VSCALE( pt1, pt1, conv[units] ); VSCALE( pt2, pt2, conv[units] ); radius = sqrt( pb->area/bn_pi ); radius = radius * conv[units]; VSUB2( height, pt2, pt1 ); sprintf( cbar_name, "cbar.%d", eid ); mk_rcc( fpout, cbar_name, pt1, height, radius ); mk_addmember( cbar_name, &pb->head.l, NULL, WMOP_UNION ); }
/* * R E F R A C T * * Compute the refracted ray 'v_2' from the incident ray 'v_1' with * the refractive indices 'ri_2' and 'ri_1' respectively. * Using Schnell's Law: * * theta_1 = angle of v_1 with surface normal * theta_2 = angle of v_2 with reversed surface normal * ri_1 * sin(theta_1) = ri_2 * sin(theta_2) * * sin(theta_2) = ri_1/ri_2 * sin(theta_1) * * The above condition is undefined for ri_1/ri_2 * sin(theta_1) * being greater than 1, and this represents the condition for total * reflection, the 'critical angle' is the angle theta_1 for which * ri_1/ri_2 * sin(theta_1) equals 1. * * Returns TRUE if refracted, FALSE if reflected. * * Note: output (v_2) can be same storage as an input. */ HIDDEN int rr_refract(vect_t v_1, vect_t norml, double ri_1, double ri_2, vect_t v_2) { vect_t w, u; fastf_t beta; if (NEAR_ZERO(ri_1, 0.0001) || NEAR_ZERO(ri_2, 0.0001)) { bu_log("rr_refract:ri1=%g, ri2=%g\n", ri_1, ri_2); beta = 1; } else { beta = ri_1/ri_2; /* temp */ if (beta > 10000) { bu_log("rr_refract: beta=%g\n", beta); beta = 1000; } } VSCALE(w, v_1, beta); VCROSS(u, w, norml); /* * |w X norml| = |w||norml| * sin(theta_1) * |u| = ri_1/ri_2 * sin(theta_1) = sin(theta_2) */ if ((beta = VDOT(u, u)) > 1.0) { /* Past critical angle, total reflection. * Calculate reflected (bounced) incident ray. */ if (R_DEBUG&RDEBUG_REFRACT) bu_log("rr_refract: reflected. ri1=%g ri2=%g beta=%g\n", ri_1, ri_2, beta); VREVERSE(u, v_1); beta = 2 * VDOT(u, norml); VSCALE(w, norml, beta); VSUB2(v_2, w, u); return 0; /* reflected */ } else { /* * 1 - beta = 1 - sin(theta_2)^^2 * = cos(theta_2)^^2. * beta = -1.0 * cos(theta_2) - Dot(w, norml). */ if (R_DEBUG&RDEBUG_REFRACT) bu_log("rr_refract: refracted. ri1=%g ri2=%g beta=%g\n", ri_1, ri_2, beta); beta = -sqrt(1.0 - beta) - VDOT(w, norml); VSCALE(u, norml, beta); VADD2(v_2, w, u); return 1; /* refracted */ } /* NOTREACHED */ }
void render_flos_work(render_t *render, struct tie_s *tie, struct tie_ray_s *ray, vect_t *pixel) { struct tie_id_s id, tid; vect_t vec; fastf_t angle; struct render_flos_s *rd; rd = (struct render_flos_s *)render->data; if (tie_work(tie, ray, &id, render_hit, NULL) != NULL) { VSET(*pixel, 0.0, 0.5, 0.0); } else return; VSUB2(vec, ray->pos, id.pos); VUNITIZE(vec); angle = VDOT(vec, id.norm); /* Determine if direct line of sight to fragment */ VMOVE(ray->pos, rd->frag_pos); VSUB2(ray->dir, id.pos, rd->frag_pos); VUNITIZE(ray->dir); if (tie_work(tie, ray, &tid, render_hit, NULL)) { if (fabs (id.pos[0] - tid.pos[0]) < TIE_PREC && fabs (id.pos[1] - tid.pos[1]) < TIE_PREC && fabs (id.pos[2] - tid.pos[2]) < TIE_PREC) { VSET(*pixel, 1.0, 0.0, 0.0); } } VSCALE(*pixel, *pixel, (0.5+angle*0.5)); }
/** * Export an XXX from internal form to external format. Note that * this means converting all integers to Big-Endian format and * floating point data to IEEE double. * * Apply the transformation to mm units as well. */ int rt_xxx_export5(struct bu_external *ep, const struct rt_db_internal *ip, double local2mm, const struct db_i *dbip) { struct rt_xxx_internal *xxx_ip; /* must be double for import and export */ double vec[ELEMENTS_PER_VECT]; RT_CK_DB_INTERNAL(ip); if (ip->idb_type != ID_XXX) return -1; xxx_ip = (struct rt_xxx_internal *)ip->idb_ptr; RT_XXX_CK_MAGIC(xxx_ip); if (dbip) RT_CK_DBI(dbip); BU_CK_EXTERNAL(ep); ep->ext_nbytes = SIZEOF_NETWORK_DOUBLE * ELEMENTS_PER_VECT; ep->ext_buf = (void *)bu_calloc(1, ep->ext_nbytes, "xxx external"); /* Since libwdb users may want to operate in units other than mm, * we offer the opportunity to scale the solid (to get it into mm) * on the way out. */ VSCALE(vec, xxx_ip->v, local2mm); /* Convert from internal (host) to database (network) format */ bu_cv_htond(ep->ext_buf, (unsigned char *)vec, ELEMENTS_PER_VECT); return 0; }
void tancir(register fastf_t *cir1, register fastf_t *cir2) { static fastf_t mag; vect_t work; fastf_t f; static fastf_t temp, tempp, ang, angc; work[0] = cir2[0] - cir1[0]; work[2] = cir2[1] - cir1[1]; work[1] = 0.0; mag = MAGNITUDE( work ); if ( mag > 1.0e-20 || mag < -1.0e-20 ) { f = 1.0/mag; } else { Tcl_AppendResult(interp, "tancir(): 0-length vector!\n", (char *)NULL); return; } VSCALE(work, work, f); temp = acos( work[0] ); if ( work[2] < 0.0 ) temp = 6.28318512717958646 - temp; tempp = acos( (cir1[2] - cir2[2]) * f ); ang = temp + tempp; angc = temp - tempp; if ( (cir1[1] + cir1[2] * sin(ang)) > (cir1[1] + cir1[2] * sin(angc)) ) ang = angc; plano[0] = cir1[0] + cir1[2] * cos(ang); plano[1] = cir1[1] + cir1[2] * sin(ang); plant[0] = cir2[0] + cir2[2] * cos(ang); plant[1] = cir2[1] + cir2[2] * sin(ang); return; }
int get_link(fastf_t *pos, fastf_t *angle_p, fastf_t dist) { int i; vect_t temp; while (dist >= tracklen) /*periodicize*/ dist -= tracklen; while (dist < 0.0) dist += tracklen; for (i=0;i<NW;i++) { if ( (dist -= x[i].t.len) < 0 ) { VSCALE(temp, (x[i].t.dir), dist); VADD2(pos, x[i].t.pos1, temp); *angle_p = atan2(x[i].t.dir[2], x[i].t.dir[0]); return(2*i); } if ((dist -= x[i].w.rad*x[i].w.arc) < 0) { *angle_p = dist/x[i].w.rad; *angle_p = x[i].w.ang1 - *angle_p; /*from x-axis to link*/ pos[0] = x[i].w.pos[0] + x[i].w.rad*cos(*angle_p); pos[1] = x[i].w.pos[1]; pos[2] = x[i].w.pos[2] + x[i].w.rad*sin(*angle_p); *angle_p -= M_PI_2; /*angle of clockwise tangent to circle*/ return(2*i+1); } } return -1; }
void rt_arbn_volume(fastf_t *volume, const struct rt_db_internal *ip) { struct poly_face *faces; struct rt_arbn_internal *aip = (struct rt_arbn_internal *)ip->idb_ptr; size_t i; *volume = 0.0; /* allocate array of face structs */ faces = (struct poly_face *)bu_calloc(aip->neqn, sizeof(struct poly_face), "rt_arbn_volume: faces"); for (i = 0; i < aip->neqn; i++) { /* allocate array of pt structs, max number of verts per faces = (# of faces) - 1 */ faces[i].pts = (point_t *)bu_calloc(aip->neqn - 1, sizeof(point_t), "rt_arbn_volume: pts"); } rt_arbn_faces_area(faces, aip); for (i = 0; i < aip->neqn; i++) { vect_t tmp; /* calculate volume of pyramid */ VSCALE(tmp, faces[i].plane_eqn, faces[i].area); *volume += VDOT(faces[i].pts[0], tmp)/3; } for (i = 0; i < aip->neqn; i++) { bu_free((char *)faces[i].pts, "rt_arbn_volume: pts"); } bu_free((char *)faces, "rt_arbn_volume: faces"); }
int _ged_scale_part(struct ged *gedp, struct rt_part_internal *part, const char *attribute, fastf_t sf, int rflag) { RT_PART_CK_MAGIC(part); switch (attribute[0]) { case 'H': if (!rflag) sf /= MAGNITUDE(part->part_H); VSCALE(part->part_H, part->part_H, sf); break; case 'v': if (rflag) part->part_vrad *= sf; else part->part_vrad = sf; break; case 'h': if (rflag) part->part_hrad *= sf; else part->part_hrad = sf; break; default: bu_vls_printf(gedp->ged_result_str, "bad part attribute - %s", attribute); return GED_ERROR; } return GED_OK; }
struct hyp_specific * hyp_internal_to_specific(struct rt_hyp_internal *hyp_in) { struct hyp_specific *hyp; BU_GET(hyp, struct hyp_specific); hyp->hyp_r1 = hyp_in->hyp_bnr * MAGNITUDE(hyp_in->hyp_A); hyp->hyp_r2 = hyp_in->hyp_bnr * hyp_in->hyp_b; hyp->hyp_c = sqrt(4 * MAGSQ(hyp_in->hyp_A) / MAGSQ(hyp_in->hyp_Hi) * (1 - hyp_in->hyp_bnr * hyp_in->hyp_bnr)); VSCALE(hyp->hyp_H, hyp_in->hyp_Hi, 0.5); VADD2(hyp->hyp_V, hyp_in->hyp_Vi, hyp->hyp_H); VMOVE(hyp->hyp_Au, hyp_in->hyp_A); VUNITIZE(hyp->hyp_Au); hyp->hyp_rx = 1.0 / (hyp->hyp_r1 * hyp->hyp_r1); hyp->hyp_ry = 1.0 / (hyp->hyp_r2 * hyp->hyp_r2); hyp->hyp_rz = (hyp->hyp_c * hyp->hyp_c) / (hyp->hyp_r1 * hyp->hyp_r1); /* calculate height to use for top/bottom intersection planes */ hyp->hyp_Hmag = MAGNITUDE(hyp->hyp_H); hyp->hyp_bounds = hyp->hyp_rz*hyp->hyp_Hmag*hyp->hyp_Hmag + 1.0; /* setup unit vectors for hyp_specific */ VMOVE(hyp->hyp_Hunit, hyp->hyp_H); VMOVE(hyp->hyp_Aunit, hyp->hyp_Au); VCROSS(hyp->hyp_Bunit, hyp->hyp_Hunit, hyp->hyp_Aunit); VUNITIZE(hyp->hyp_Aunit); VUNITIZE(hyp->hyp_Bunit); VUNITIZE(hyp->hyp_Hunit); return hyp; }
/** * For a hit on the surface of an METABALL, return the (u, v) * coordinates of the hit point, 0 <= u, v <= 1. * * u = azimuth * v = elevation */ void rt_metaball_uv(struct application *ap, struct soltab *stp, struct hit *hitp, struct uvcoord *uvp) { struct rt_metaball_internal *metaball = (struct rt_metaball_internal *)stp->st_specific; vect_t work, pprime; fastf_t r; if (ap) RT_CK_APPLICATION(ap); if (stp) RT_CK_SOLTAB(stp); if (hitp) RT_CK_HIT(hitp); if (!uvp) return; if (!metaball) return; /* stuff stolen from sph */ VSUB2(work, hitp->hit_point, stp->st_center); VSCALE(pprime, work, 1.0/MAGNITUDE(work)); /* Assert that pprime has unit length */ /* U is azimuth, atan() range: -pi to +pi */ uvp->uv_u = bn_atan2(pprime[Y], pprime[X]) * M_1_2PI; if (uvp->uv_u < 0) uvp->uv_u += 1.0; /* * V is elevation, atan() range: -pi/2 to +pi/2, because sqrt() * ensures that X parameter is always >0 */ uvp->uv_v = bn_atan2(pprime[Z], sqrt(pprime[X] * pprime[X] + pprime[Y] * pprime[Y])) * M_1_2PI; /* approximation: r / (circumference, 2 * pi * aradius) */ r = ap->a_rbeam + ap->a_diverge * hitp->hit_dist; uvp->uv_du = uvp->uv_dv = M_1_2PI * r / stp->st_aradius; return; }
static int find_closest_color(float color[3]) { int icolor[3]; int i; int dist_sq; int color_num; VSCALE(icolor, color, 255); color_num = 0; dist_sq = MAGSQ(icolor); for (i = 1; i < 256; i++) { int tmp_dist; int diff[3]; VSUB2(diff, icolor, &rgb[i*3]); tmp_dist = MAGSQ(diff); if (tmp_dist < dist_sq) { dist_sq = tmp_dist; color_num = i; } } return color_num; }
void draw_m_axes() { point_t m_ap; /* axes position in model coordinates, mm */ point_t v_ap; /* axes position in view coordinates */ VSCALE(m_ap, axes_state->ax_model_pos, local2base); MAT4X3PNT(v_ap, view_state->vs_vop->vo_model2view, m_ap); dmo_drawAxes_cmd(dmp, view_state->vs_vop->vo_size, view_state->vs_vop->vo_rotation, v_ap, axes_state->ax_model_size * INV_GED, color_scheme->cs_model_axes, color_scheme->cs_model_axes_label, axes_state->ax_model_linewidth, 0, /* positive direction only */ 0, /* three colors (i.e. X-red, Y-green, Z-blue) */ 0, /* no ticks */ 0, /* tick len */ 0, /* major tick len */ 0, /* tick interval */ 0, /* ticks per major */ NULL, /* tick color */ NULL, /* major tick color */ 0 /* tick threshold */); }
/* * F B M _ R E N D E R */ int fbm_render(struct application *ap, struct partition *pp, struct shadework *swp, char *dp) { register struct fbm_specific *fbm_sp = (struct fbm_specific *)dp; vect_t v_noise; point_t pt; if (rdebug&RDEBUG_SHADE) bu_struct_print( "foo", fbm_parse, (char *)fbm_sp ); pt[0] = swp->sw_hit.hit_point[0] * fbm_sp->scale[0]; pt[1] = swp->sw_hit.hit_point[1] * fbm_sp->scale[1]; pt[2] = swp->sw_hit.hit_point[2] * fbm_sp->scale[2]; bn_noise_vec(pt, v_noise); VSCALE(v_noise, v_noise, fbm_sp->distortion); if (rdebug&RDEBUG_SHADE) bu_log("fbm_render: point (%g %g %g) becomes (%g %g %g)\n\tv_noise (%g %g %g)\n", V3ARGS(swp->sw_hit.hit_point), V3ARGS(pt), V3ARGS(v_noise)); VADD2(swp->sw_hit.hit_normal, swp->sw_hit.hit_normal, v_noise); VUNITIZE(swp->sw_hit.hit_normal); return(1); }
void calc_isect2(point_t VTX0, point_t VTX1, point_t VTX2, fastf_t VV0, fastf_t VV1, fastf_t VV2, fastf_t D0, fastf_t D1, fastf_t D2, fastf_t *isect0, fastf_t *isect1, point_t isectpoint0, point_t isectpoint1) { fastf_t tmp=D0/(D0-D1); point_t diff; *isect0=VV0+(VV1-VV0)*tmp; VSUB2(diff, VTX1, VTX0); VSCALE(diff, diff, tmp); VADD2(isectpoint0, diff, VTX0); tmp=D0/(D0-D2); *isect1=VV0+(VV2-VV0)*tmp; VSUB2(diff, VTX2, VTX0); VSCALE(diff, diff, tmp); VADD2(isectpoint1, VTX0, diff); }
int _ged_scale_extrude(struct ged *gedp, struct rt_extrude_internal *extrude, const char *attribute, fastf_t sf, int rflag) { vect_t hvec; RT_EXTRUDE_CK_MAGIC(extrude); switch (attribute[0]) { case 'h': case 'H': if (!rflag) sf /= MAGNITUDE(extrude->h); VSCALE(hvec, extrude->h, sf); /* Make sure hvec is not zero length */ if (MAGNITUDE(hvec) > SQRT_SMALL_FASTF) { VMOVE(extrude->h, hvec); } break; default: bu_vls_printf(gedp->ged_result_str, "bad extrude attribute - %s", attribute); return GED_ERROR; } return GED_OK; }
void Line::EndPoint(double *p) { double d[3]; double mag = dir->Magnitude(); VMOVE(d,dir->Orientation()); VSCALE(d,d,mag); VADD2(p,pnt->Coordinates(),d); return; }
int rt_gen_circular_grid(struct xrays *rays, const struct xray *center_ray, fastf_t radius, const fastf_t *up_vector, fastf_t gridsize) { vect_t dir; vect_t avec; vect_t bvec; vect_t uvec; VMOVE(dir, center_ray->r_dir); VMOVE(uvec, up_vector); VUNITIZE(uvec); VSCALE(bvec, uvec, radius); VCROSS(avec, dir, up_vector); VUNITIZE(avec); VSCALE(avec, avec, radius); return rt_gen_elliptical_grid(rays, center_ray, avec, bvec, gridsize); }
int rt_gen_conic(struct xrays *rays, const struct xray *center_ray, fastf_t theta, vect_t up_vector, int rays_per_radius) { int count = 0; point_t start; vect_t orig_dir; fastf_t x, y; /* Setting radius to tan(theta) works because, as shown in the * following diagram, the ray that starts at the given point and * passes through orig_dir + (radius in any orthogonal direction) * has an angle of theta with the original ray; when the * resulting vector is normalized, the angle is preserved. */ fastf_t radius = tan(theta); fastf_t rsq = radius * radius; /* radius-squared, for use in the loop */ fastf_t gridsize = 2 * radius / (rays_per_radius - 1); vect_t a_dir, b_dir; register struct xrays *xrayp; VMOVE(start, center_ray->r_pt); VMOVE(orig_dir, center_ray->r_dir); /* Create vectors a_dir, b_dir that are orthogonal to orig_dir. */ VMOVE(b_dir, up_vector); VUNITIZE(b_dir); VCROSS(a_dir, orig_dir, up_vector); VUNITIZE(a_dir); for (y = -radius; y <= radius; y += gridsize) { vect_t tmp; printf("y:%f\n", y); VSCALE(tmp, b_dir, y); printf("y_partofit: %f,%f,%f\n", V3ARGS(tmp)); for (x = -radius; x <= radius; x += gridsize) { if (((x*x)/rsq + (y*y)/rsq) <= 1) { BU_ALLOC(xrayp, struct xrays); VMOVE(xrayp->ray.r_pt, start); VJOIN2(xrayp->ray.r_dir, orig_dir, x, a_dir, y, b_dir); VUNITIZE(xrayp->ray.r_dir); xrayp->ray.index = count++; xrayp->ray.magic = RT_RAY_MAGIC; BU_LIST_APPEND(&rays->l, &xrayp->l); } } } return count; }