void bn_mat_xform_about_pt(mat_t mat, const mat_t xform, const point_t pt) { mat_t xlate; mat_t tmp; MAT_IDN(xlate); MAT_DELTAS_VEC_NEG(xlate, pt); bn_mat_mul(tmp, xform, xlate); MAT_DELTAS_VEC(xlate, pt); bn_mat_mul(mat, xlate, tmp); }
void do_light(char *name, fastf_t *pos, fastf_t *dir_at, int da_flag, double r, unsigned char *rgb, struct wmember *headp) /* direction or aim point */ /* 0 = direction, !0 = aim point */ /* radius of light */ { char nbuf[64]; vect_t center; mat_t rot; mat_t xlate; mat_t both; vect_t from; vect_t dir; if ( da_flag ) { VSUB2( dir, dir_at, pos ); VUNITIZE( dir ); } else { VMOVE( dir, dir_at ); } snprintf( nbuf, 64, "%s.s", name ); VSETALL( center, 0 ); mk_sph( outfp, nbuf, center, r ); /* * Need to rotate from 0, 0, -1 to vect "dir", * then xlate to final position. */ VSET( from, 0, 0, -1 ); bn_mat_fromto( rot, from, dir ); MAT_IDN( xlate ); MAT_DELTAS_VEC( xlate, pos); bn_mat_mul( both, xlate, rot ); mk_region1( outfp, name, nbuf, "light", "shadows=1", rgb ); (void)mk_addmember( name, &(headp->l), NULL, WMOP_UNION ); }
int bn_mat_scale_about_pt(mat_t mat, const point_t pt, const double scale) { mat_t xlate; mat_t s; mat_t tmp; MAT_IDN(xlate); MAT_DELTAS_VEC_NEG(xlate, pt); MAT_IDN(s); if (ZERO(scale)) { MAT_ZERO(mat); return -1; /* ERROR */ } s[15] = 1 / scale; bn_mat_mul(tmp, s, xlate); MAT_DELTAS_VEC(xlate, pt); bn_mat_mul(mat, xlate, tmp); return 0; /* OK */ }
bool STEPWrapper::convert(BRLCADWrapper *dot_g) { MAP_OF_PRODUCT_NAME_TO_ENTITY_ID name2id_map; MAP_OF_ENTITY_ID_TO_PRODUCT_NAME id2name_map; MAP_OF_ENTITY_ID_TO_PRODUCT_ID id2productid_map; MAP_OF_PRODUCT_NAME_TO_ENTITY_ID::iterator niter = name2id_map.end(); if (!dot_g) { return false; } this->dotg = dot_g; int num_ents = instance_list->InstanceCount(); for (int i = 0; i < num_ents; i++) { SDAI_Application_instance *sse = instance_list->GetSTEPentity(i); if (sse == NULL) { continue; } std::string name = sse->EntityName(); std::transform(name.begin(), name.end(), name.begin(), (int(*)(int))std::tolower); if ((sse->STEPfile_id > 0) && (sse->IsA(SCHEMA_NAMESPACE::e_shape_definition_representation))) { ShapeDefinitionRepresentation *sdr = dynamic_cast<ShapeDefinitionRepresentation *>(Factory::CreateObject(this, (SDAI_Application_instance *)sse)); if (!sdr) { bu_exit(1, "ERROR: unable to allocate a 'ShapeDefinitionRepresentation' entity\n"); } else { int sdr_id = sdr->GetId(); std::string pname = sdr->GetProductName(); int product_id = sdr->GetProductId(); id2productid_map[sdr_id] = product_id; if (pname.empty()) { std::string str = "ShapeDefinitionRepresentation@"; str = dotg->GetBRLCADName(str); id2name_map[sdr_id] = pname; } else { std::string temp = pname; int index = 2; while ((niter=name2id_map.find(temp)) != name2id_map.end()) { temp = pname + "_" + static_cast<ostringstream*>( &(ostringstream() << (index++)) )->str(); } pname = temp; if ((niter=name2id_map.find(pname)) == name2id_map.end()) { id2name_map[sdr_id] = pname; name2id_map[pname] = product_id; id2name_map[product_id] = pname; } } AdvancedBrepShapeRepresentation *aBrep = sdr->GetAdvancedBrepShapeRepresentation(); if (aBrep) { if (pname.empty()) { std::string str = "product@"; pname = dotg->GetBRLCADName(str); id2name_map[aBrep->GetId()] = pname; id2name_map[product_id] = pname; } else { id2name_map[aBrep->GetId()] = pname; id2name_map[product_id] = pname; } id2productid_map[aBrep->GetId()] = product_id; if (Verbose()) { if (!pname.empty()) { std::cerr << std::endl << " Generating Product -" << pname ; } else { std::cerr << std::endl << " Generating Product"; } } LocalUnits::length = aBrep->GetLengthConversionFactor(); LocalUnits::planeangle = aBrep->GetPlaneAngleConversionFactor(); LocalUnits::solidangle = aBrep->GetSolidAngleConversionFactor(); ON_Brep *onBrep = aBrep->GetONBrep(); if (!onBrep) { delete sdr; bu_exit(1, "ERROR: failure creating advanced boundary representation from %s\n", stepfile.c_str()); } else { ON_TextLog tl; if (!onBrep->IsValid(&tl)) { bu_log("WARNING: %s is not valid\n", name.c_str()); } //onBrep->SpSplitClosedFaces(); //ON_Brep *tbrep = TightenBrep(onBrep); mat_t mat; MAT_IDN(mat); Axis2Placement3D *axis = aBrep->GetAxis2Placement3d(); if (axis != NULL) { //assign matrix values double translate_to[3]; const double *toXaxis = axis->GetXAxis(); const double *toYaxis = axis->GetYAxis(); const double *toZaxis = axis->GetZAxis(); mat_t rot_mat; VMOVE(translate_to,axis->GetOrigin()); VSCALE(translate_to,translate_to,LocalUnits::length); MAT_IDN(rot_mat); VMOVE(&rot_mat[0], toXaxis); VMOVE(&rot_mat[4], toYaxis); VMOVE(&rot_mat[8], toZaxis); bn_mat_inv(mat, rot_mat); MAT_DELTAS_VEC(mat, translate_to); } dotg->WriteBrep(pname, onBrep,mat); delete onBrep; } } else { // must be an assembly if (pname.empty()) { std::string str = "assembly@"; pname = dotg->GetBRLCADName(str); } ShapeRepresentation *aSR = sdr->GetShapeRepresentation(); if (aSR) { int sr_id = aSR->GetId(); id2name_map[sr_id] = pname; id2name_map[product_id] = pname; id2productid_map[sr_id] = product_id; } } Factory::DeleteObjects(); } } } /* * Pickup BREP related to SHAPE_REPRESENTATION through SHAPE_REPRESENTATION_RELATIONSHIP * * like the following found in OpenBook Part 'C': * #21281=SHAPE_DEFINITION_REPRESENTATION(#21280,#21270); * #21280=PRODUCT_DEFINITION_SHAPE('','SHAPE FOR C.',#21279); * #21279=PRODUCT_DEFINITION('design','',#21278,#21275); * #21278=PRODUCT_DEFINITION_FORMATION_WITH_SPECIFIED_SOURCE('1','LAST_VERSION',#21277,.MADE.); * #21277=PRODUCT('C','C','NOT SPECIFIED',(#21276)); * #21270=SHAPE_REPRESENTATION('',(#21259),#21267); * #21259=AXIS2_PLACEMENT_3D('DANTE_BX_CPU_TOP_1',#21256,#21257,#21258); * #21267=(GEOMETRIC_REPRESENTATION_CONTEXT(3)GLOBAL_UNCERTAINTY_ASSIGNED_CONTEXT((#21266)) * GLOBAL_UNIT_ASSIGNED_CONTEXT((#21260,#21264,#21265))REPRESENTATION_CONTEXT('ID1','3')); * * #21271=SHAPE_REPRESENTATION_RELATIONSHIP('','',#21270,#21268); * #21268=ADVANCED_BREP_SHAPE_REPRESENTATION('',(#21254),#21267); * #21272=SHAPE_REPRESENTATION_RELATIONSHIP('','',#21270,#21269); * #21269=MANIFOLD_SURFACE_SHAPE_REPRESENTATION('',(#21255),#21267); * */ for (int i = 0; i < num_ents; i++) { SDAI_Application_instance *sse = instance_list->GetSTEPentity(i); if (sse == NULL) { continue; } std::string name = sse->EntityName(); std::transform(name.begin(), name.end(), name.begin(), (int(*)(int))std::tolower); if ((sse->STEPfile_id > 0) && (sse->IsA(SCHEMA_NAMESPACE::e_shape_representation_relationship))) { ShapeRepresentationRelationship *srr = dynamic_cast<ShapeRepresentationRelationship *>(Factory::CreateObject(this, (SDAI_Application_instance *)sse)); if (srr) { ShapeRepresentation *aSR = dynamic_cast<ShapeRepresentation *>(srr->GetRepresentationRelationshipRep_1()); AdvancedBrepShapeRepresentation *aBrep = dynamic_cast<AdvancedBrepShapeRepresentation *>(srr->GetRepresentationRelationshipRep_2()); if (!aBrep) { //try rep_1 aBrep = dynamic_cast<AdvancedBrepShapeRepresentation *>(srr->GetRepresentationRelationshipRep_1()); aSR = dynamic_cast<ShapeRepresentation *>(srr->GetRepresentationRelationshipRep_2()); } if ((aSR) && (aBrep)) { int sr_id = aSR->GetId(); MAP_OF_ENTITY_ID_TO_PRODUCT_ID::iterator it = id2productid_map.find(sr_id); if (it != id2productid_map.end()) { // product found int product_id = (*it).second; int brep_id = aBrep->GetId(); it = id2productid_map.find(brep_id); if (it == id2productid_map.end()) { // brep not loaded yet so lets do that here. string pname = id2name_map[product_id]; id2productid_map[brep_id] = product_id; if (Verbose()) { if (!pname.empty()) { std::cerr << std::endl << " Generating Product -" << pname ; } else { std::cerr << std::endl << " Generating Product"; } } LocalUnits::length = aBrep->GetLengthConversionFactor(); LocalUnits::planeangle = aBrep->GetPlaneAngleConversionFactor(); LocalUnits::solidangle = aBrep->GetSolidAngleConversionFactor(); ON_Brep *onBrep = aBrep->GetONBrep(); if (!onBrep) { bu_exit(1, "ERROR: failure creating advanced boundary representation from %s\n", stepfile.c_str()); } else { ON_TextLog tl; if (!onBrep->IsValid(&tl)) { bu_log("WARNING: %s is not valid\n", name.c_str()); } //onBrep->SpSplitClosedFaces(); //ON_Brep *tbrep = TightenBrep(onBrep); mat_t mat; MAT_IDN(mat); Axis2Placement3D *axis = aBrep->GetAxis2Placement3d(); if (axis != NULL) { //assign matrix values double translate_to[3]; const double *toXaxis = axis->GetXAxis(); const double *toYaxis = axis->GetYAxis(); const double *toZaxis = axis->GetZAxis(); mat_t rot_mat; VMOVE(translate_to,axis->GetOrigin()); VSCALE(translate_to,translate_to,LocalUnits::length); MAT_IDN(rot_mat); VMOVE(&rot_mat[0], toXaxis); VMOVE(&rot_mat[4], toYaxis); VMOVE(&rot_mat[8], toZaxis); bn_mat_inv(mat, rot_mat); MAT_DELTAS_VEC(mat, translate_to); } dotg->WriteBrep(pname, onBrep,mat); delete onBrep; } } } } Factory::DeleteObjects(); } } } if (Verbose()) { std::cerr << std::endl << " Generating BRL-CAD hierarchy." << std::endl; } for (int i = 0; i < num_ents; i++) { SDAI_Application_instance *sse = instance_list->GetSTEPentity(i); if (sse == NULL) { continue; } std::string name = sse->EntityName(); std::transform(name.begin(), name.end(), name.begin(), (int(*)(int))std::tolower); if ((sse->STEPfile_id > 0) && (sse->IsA(SCHEMA_NAMESPACE::e_context_dependent_shape_representation))) { ContextDependentShapeRepresentation *aCDSR = dynamic_cast<ContextDependentShapeRepresentation *>(Factory::CreateObject(this, (SDAI_Application_instance *)sse)); if (aCDSR) { int rep_1_id = aCDSR->GetRepresentationRelationshipRep_1()->GetId(); int rep_2_id = aCDSR->GetRepresentationRelationshipRep_2()->GetId(); int pid_1 = id2productid_map[rep_1_id]; int pid_2 = id2productid_map[rep_2_id]; Axis2Placement3D *axis1 = NULL; Axis2Placement3D *axis2 = NULL; if ((id2name_map.find(rep_1_id) != id2name_map.end()) && (id2name_map.find(rep_2_id) != id2name_map.end())) { string comb = id2name_map[rep_1_id]; string member = id2name_map[rep_2_id]; mat_t mat; MAT_IDN(mat); ProductDefinition *relatingProduct = aCDSR->GetRelatingProductDefinition(); ProductDefinition *relatedProduct = aCDSR->GetRelatedProductDefinition(); if (relatingProduct && relatedProduct) { string relatingName = relatingProduct->GetProductName(); int relatingID = relatingProduct->GetProductId(); string relatedName = relatedProduct->GetProductName(); int relatedID = relatedProduct->GetProductId(); if ((relatingID == pid_1) && (relatedID == pid_2)) { axis1 = aCDSR->GetTransformItem_1(); axis2 = aCDSR->GetTransformItem_2(); comb = id2name_map[rep_1_id]; member = id2name_map[rep_2_id]; } else if ((relatingID == pid_2) && (relatedID == pid_1)) { axis1 = aCDSR->GetTransformItem_2(); axis2 = aCDSR->GetTransformItem_1(); comb = id2name_map[rep_2_id]; member = id2name_map[rep_1_id]; } else { std::cerr << "Error: Found Representation Relationship Rep_1(name=" << comb << ",Id=" << rep_1_id << ")" << std::endl; std::cerr << "Error: Found Representation Relationship Rep_2(name=" << member << ",Id=" << rep_2_id << ")" << std::endl; std::cerr << "Error: but Relating ProductDefinition (name=" << relatingName << ",Id=" << relatingID << ")" << std::endl; std::cerr << "Error: Related ProductDefinition (name=" << relatedName << ",Id=" << relatedID << ")" << std::endl; } } if ((axis1 != NULL) && (axis2 != NULL)) { mat_t to_mat; mat_t from_mat; mat_t toinv_mat; //assign matrix values double translate_to[3]; double translate_from[3]; const double *toXaxis = axis1->GetXAxis(); const double *toYaxis = axis1->GetYAxis(); const double *toZaxis = axis1->GetZAxis(); const double *fromXaxis = axis2->GetXAxis(); const double *fromYaxis = axis2->GetYAxis(); const double *fromZaxis = axis2->GetZAxis(); VMOVE(translate_to,axis1->GetOrigin()); VSCALE(translate_to,translate_to,LocalUnits::length); VMOVE(translate_from,axis2->GetOrigin()); VSCALE(translate_from,translate_from,-LocalUnits::length); // undo from trans/rot MAT_IDN(from_mat); VMOVE(&from_mat[0], fromXaxis); VMOVE(&from_mat[4], fromYaxis); VMOVE(&from_mat[8], fromZaxis); MAT_DELTAS_VEC(from_mat, translate_from); // do to trans/rot MAT_IDN(to_mat); VMOVE(&to_mat[0], toXaxis); VMOVE(&to_mat[4], toYaxis); VMOVE(&to_mat[8], toZaxis); bn_mat_inv(toinv_mat, to_mat); MAT_DELTAS_VEC(toinv_mat, translate_to); bn_mat_mul(mat, toinv_mat, from_mat); } dotg->AddMember(comb,member,mat); } Factory::DeleteObjects(); } } } if (!dotg->WriteCombs()) { std::cerr << "Error writing BRL-CAD hierarchy." << std::endl; } return true; }
int ged_otranslate(struct ged *gedp, int argc, const char *argv[]) { struct directory *dp; struct _ged_trace_data gtd; struct rt_db_internal intern; vect_t delta; double scan[3]; mat_t dmat; mat_t emat; mat_t tmpMat; mat_t invXform; point_t rpp_min; point_t rpp_max; static const char *usage = "obj dx dy dz"; GED_CHECK_DATABASE_OPEN(gedp, GED_ERROR); GED_CHECK_READ_ONLY(gedp, GED_ERROR); GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR); /* initialize result */ bu_vls_trunc(gedp->ged_result_str, 0); /* must be wanting help */ if (argc == 1) { bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage); return GED_HELP; } if (argc != 5) { bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage); return GED_ERROR; } if (_ged_get_obj_bounds2(gedp, 1, argv+1, >d, rpp_min, rpp_max) == GED_ERROR) return GED_ERROR; dp = gtd.gtd_obj[gtd.gtd_objpos-1]; if (!(dp->d_flags & RT_DIR_SOLID)) { if (_ged_get_obj_bounds(gedp, 1, argv+1, 1, rpp_min, rpp_max) == GED_ERROR) return GED_ERROR; } if (sscanf(argv[2], "%lf", &scan[X]) != 1) { bu_vls_printf(gedp->ged_result_str, "%s: bad x value - %s", argv[0], argv[2]); return GED_ERROR; } if (sscanf(argv[3], "%lf", &scan[Y]) != 1) { bu_vls_printf(gedp->ged_result_str, "%s: bad y value - %s", argv[0], argv[3]); return GED_ERROR; } if (sscanf(argv[4], "%lf", &scan[Z]) != 1) { bu_vls_printf(gedp->ged_result_str, "%s: bad z value - %s", argv[0], argv[4]); return GED_ERROR; } MAT_IDN(dmat); VSCALE(delta, scan, gedp->ged_wdbp->dbip->dbi_local2base); MAT_DELTAS_VEC(dmat, delta); bn_mat_inv(invXform, gtd.gtd_xform); bn_mat_mul(tmpMat, invXform, dmat); bn_mat_mul(emat, tmpMat, gtd.gtd_xform); GED_DB_GET_INTERNAL(gedp, &intern, dp, emat, &rt_uniresource, GED_ERROR); RT_CK_DB_INTERNAL(&intern); GED_DB_PUT_INTERNAL(gedp, dp, &intern, &rt_uniresource, GED_ERROR); return GED_OK; }
/* * T P _ 3 S Y M B O L */ void tp_3symbol(FILE *fp, char *string, fastf_t *origin, fastf_t *rot, double scale) /* string of chars to be plotted */ /* lower left corner of 1st char */ /* Transform matrix (WARNING: may xlate) */ /* scale factor to change 1x1 char sz */ { register unsigned char *cp; double offset; /* offset of char from given x, y */ int ysign; /* sign of y motion, either +1 or -1 */ vect_t temp; vect_t loc; mat_t xlate_to_origin; mat_t mat; if ( string == NULL || *string == '\0' ) return; /* done before begun! */ /* * The point "origin" will be the center of the axis rotation. * The text is located in a local coordinate system with the * lower left corner of the first character at (0, 0, 0), with * the text proceeding onward towards +X. * We need to rotate the text around its local (0, 0, 0), * and then translate to the user's designated "origin". * If the user provided translation or * scaling in his matrix, it will *also* be applied. */ MAT_IDN( xlate_to_origin ); MAT_DELTAS_VEC( xlate_to_origin, origin ); bn_mat_mul( mat, xlate_to_origin, rot ); /* Check to see if initialization is needed */ if ( tp_cindex[040] == 0 ) tp_setup(); /* Draw each character in the input string */ offset = 0; for ( cp = (unsigned char *)string; *cp; cp++, offset += scale ) { register int *p; /* pointer to stroke table */ register int stroke; VSET( temp, offset, 0, 0 ); MAT4X3PNT( loc, mat, temp ); pdv_3move( fp, loc ); for ( p = tp_cindex[*cp]; (stroke= *p) != LAST; p++ ) { int draw; if ( stroke==NEGY ) { ysign = (-1); stroke = *++p; } else ysign = 1; /* Detect & process pen control */ if ( stroke < 0 ) { stroke = -stroke; draw = 0; } else draw = 1; /* stroke co-ordinates in string coord system */ VSET( temp, (stroke/11) * 0.1 * scale + offset, (ysign * (stroke%11)) * 0.1 * scale, 0 ); MAT4X3PNT( loc, mat, temp ); if ( draw ) pdv_3cont( fp, loc ); else pdv_3move( fp, loc ); } } }
/* F I R E _ S E T U P * * This routine is called (at prep time) * once for each region which uses this shader. * Any shader-specific initialization should be done here. */ HIDDEN int fire_setup(register struct region *rp, struct bu_vls *matparm, char **dpp, struct mfuncs *mfp, struct rt_i *rtip) /* pointer to reg_udata in *rp */ /* New since 4.4 release */ { register struct fire_specific *fire_sp; /* check the arguments */ RT_CHECK_RTI(rtip); BU_CK_VLS( matparm ); RT_CK_REGION(rp); if (rdebug&RDEBUG_SHADE) bu_log("fire_setup(%s)\n", rp->reg_name); /* Get memory for the shader parameters and shader-specific data */ BU_GETSTRUCT( fire_sp, fire_specific ); *dpp = (char *)fire_sp; /* initialize the default values for the shader */ memcpy(fire_sp, &fire_defaults, sizeof(struct fire_specific)); /* parse the user's arguments for this use of the shader. */ if (bu_struct_parse( matparm, fire_parse_tab, (char *)fire_sp ) < 0 ) return(-1); if (fire_sp->noise_size != -1.0) { VSETALL(fire_sp->noise_vscale, fire_sp->noise_size); } /* * The shader needs to operate in a coordinate system which stays * fixed on the region when the region is moved (as in animation). * We need to get a matrix to perform the appropriate transform(s). */ db_shader_mat(fire_sp->fire_m_to_sh, rtip, rp, fire_sp->fire_min, fire_sp->fire_max, &rt_uniresource); /* Build matrix to map shader space to noise space. * XXX If only we could get the frametime at this point * we could factor the flicker of flames into this matrix * rather than having to recompute it on a pixel-by-pixel basis. */ MAT_IDN(fire_sp->fire_sh_to_noise); MAT_DELTAS_VEC(fire_sp->fire_sh_to_noise, fire_sp->noise_delta); MAT_SCALE_VEC(fire_sp->fire_sh_to_noise, fire_sp->noise_vscale); /* get matrix for performing spline of fire colors */ rt_dspline_matrix(fire_sp->fire_colorspline_mat, "Catmull", 0.5, 0.0); if (rdebug&RDEBUG_SHADE || fire_sp->fire_debug ) { bu_struct_print( " FIRE Parameters:", fire_print_tab, (char *)fire_sp ); bn_mat_print( "m_to_sh", fire_sp->fire_m_to_sh ); bn_mat_print( "sh_to_noise", fire_sp->fire_sh_to_noise ); bn_mat_print( "colorspline", fire_sp->fire_colorspline_mat ); } return(1); }
static void tree_solids(union tree *tp, struct tree_bark *tb, int op, struct resource *resp) { RT_CK_TREE(tp); switch (tp->tr_op) { case OP_NOP: return; case OP_SOLID: { struct reg_db_internals *dbint; matp_t mp; long sol_id = 0; struct rt_ell_internal *ell_p; vect_t v; int ret; BU_ALLOC(dbint, struct reg_db_internals); BU_LIST_INIT_MAGIC(&(dbint->l), DBINT_MAGIC); if (tp->tr_a.tu_stp->st_matp) mp = tp->tr_a.tu_stp->st_matp; else mp = (matp_t)bn_mat_identity; /* Get the internal form of this solid & add it to the list */ ret = rt_db_get_internal(&dbint->ip, tp->tr_a.tu_stp->st_dp, tb->dbip, mp, resp); if (ret < 0) { bu_log("Failure reading %s object from database.\n", OBJ[sol_id].ft_name); return; } RT_CK_DB_INTERNAL(&dbint->ip); dbint->st_p = tp->tr_a.tu_stp; sol_id = dbint->ip.idb_type; if (sol_id < 0) { bu_log("Primitive ID %ld out of bounds\n", sol_id); bu_bomb(""); } if (sol_id != ID_ELL) { if (op == OP_UNION) bu_log("Non-ellipse \"union\" primitive of \"%s\" being ignored\n", tb->name); if (rdebug&RDEBUG_SHADE) bu_log(" got a primitive type %ld \"%s\". This primitive ain't no ellipse bucko!\n", sol_id, OBJ[sol_id].ft_name); break; } ell_p = (struct rt_ell_internal *)dbint->ip.idb_ptr; if (rdebug&RDEBUG_SHADE) bu_log(" got a primitive type %ld \"%s\"\n", sol_id, OBJ[sol_id].ft_name); RT_ELL_CK_MAGIC(ell_p); if (rdebug&RDEBUG_SHADE) { VPRINT("point", ell_p->v); VPRINT("a", ell_p->a); VPRINT("b", ell_p->b); VPRINT("c", ell_p->c); } /* create the matrix that maps the coordinate system defined * by the ellipse into model space, and get inverse for use * in the _render() proc */ MAT_IDN(mp); VMOVE(v, ell_p->a); VUNITIZE(v); mp[0] = v[0]; mp[4] = v[1]; mp[8] = v[2]; VMOVE(v, ell_p->b); VUNITIZE(v); mp[1] = v[0]; mp[5] = v[1]; mp[9] = v[2]; VMOVE(v, ell_p->c); VUNITIZE(v); mp[2] = v[0]; mp[6] = v[1]; mp[10] = v[2]; MAT_DELTAS_VEC(mp, ell_p->v); MAT_COPY(dbint->ell2model, mp); bn_mat_inv(dbint->model2ell, mp); /* find scaling of gaussian puff in ellipsoid space */ VSET(dbint->one_sigma, MAGNITUDE(ell_p->a) / tb->gs->gauss_sigma, MAGNITUDE(ell_p->b) / tb->gs->gauss_sigma, MAGNITUDE(ell_p->c) / tb->gs->gauss_sigma); if (rdebug&RDEBUG_SHADE) { VPRINT("sigma", dbint->one_sigma); } BU_LIST_APPEND(tb->l, &(dbint->l)); break; } case OP_UNION: tree_solids(tp->tr_b.tb_left, tb, tp->tr_op, resp); tree_solids(tp->tr_b.tb_right, tb, tp->tr_op, resp); break; case OP_NOT: bu_log("Warning: 'Not' region operator in %s\n", tb->name); tree_solids(tp->tr_b.tb_left, tb, tp->tr_op, resp); break; case OP_GUARD:bu_log("Warning: 'Guard' region operator in %s\n", tb->name); tree_solids(tp->tr_b.tb_left, tb, tp->tr_op, resp); break; case OP_XNOP:bu_log("Warning: 'XNOP' region operator in %s\n", tb->name); tree_solids(tp->tr_b.tb_left, tb, tp->tr_op, resp); break; case OP_INTERSECT: case OP_SUBTRACT: case OP_XOR: /* XXX this can get us in trouble if 1 solid is subtracted * from less than all the "union" solids of the region. */ tree_solids(tp->tr_b.tb_left, tb, tp->tr_op, resp); tree_solids(tp->tr_b.tb_right, tb, tp->tr_op, resp); return; default: bu_bomb("rt_tree_region_assign: bad op\n"); } }
int main(int argc, char **argv) { int frame; char name[128]; char gname[128]; vect_t normal; struct wmember head, ghead; matp_t matp; mat_t xlate; mat_t rot1, rot2, rot3; vect_t from, to; vect_t offset; if (argc > 0) { bu_log("Usage: %s\n", argv[0]); bu_log(" (Program expects ./pos.dat file to be present)\n"); bu_log(" (Will generate file tube.g)\n"); if (argc == 2) { if ( BU_STR_EQUAL(argv[1],"-h") || BU_STR_EQUAL(argv[1],"-?")) bu_exit(1,NULL); } else if (argc == 1) bu_log(" Program continues running:\n"); } BU_LIST_INIT(&head.l); BU_LIST_INIT(&ghead.l); outfp = wdb_fopen("tube.g"); if ((pos_fp = fopen("pos.dat", "r")) == NULL) perror("pos.dat"); /* Just warn */ mk_id(outfp, "Procedural Gun Tube with Projectile"); VSET(normal, 0, -1, 0); mk_half(outfp, "cut", normal, 0.0); VSET(normal, 0, 1, 0); mk_half(outfp, "bg.s", normal, -1000.0); (void)mk_addmember("bg.s", &head.l, NULL, WMOP_UNION); /* temp use of "head" */ mk_lcomb(outfp, "bg.r", &head, 1, "texture", "file=movie128bw.pix w=128", (unsigned char *)0, 0); #ifdef never /* Numbers for a 105-mm M68 gun */ oradius = 5 * inches2mm / 2; /* 5" outer diameter */ iradius = 4.134 * inches2mm / 2; /* 5" inner (land) diameter */ #else /* Numbers invented to match 125-mm KE (Erline) round */ iradius = 125.0/2; oradius = iradius + (5-4.134) * inches2mm / 2; /* 5" outer diameter */ #endif fprintf(stderr, "inner radius=%gmm, outer radius=%gmm\n", iradius, oradius); length = 187.0 * inches2mm; #ifdef never spacing = 100.; /* mm per sample */ nsamples = ceil(length/spacing); fprintf(stderr, "length=%gmm, spacing=%gmm\n", length, spacing); fprintf(stderr, "nframes=%d\n", nframes); #endif for (frame=0;; frame++) { cur_time = frame * delta_t; #ifdef never /* Generate some dummy sample data */ if (frame < 16) break; for (i=0; i<nsamples; i++) { sample[i][X] = i * spacing; sample[i][Y] = 0; sample[i][Z] = 4 * oradius * sin( ((double)i*i)/nsamples * M_2PI + frame * M_PI_4); } projectile_pos = ((double)frame)/nframes * (sample[nsamples-1][X] - sample[0][X]); /* length */ #else if (read_frame(stdin) < 0) break; if (pos_fp != NULL) read_pos(pos_fp); #endif #define build_spline build_cyl sprintf(name, "tube%do", frame); build_spline(name, nsamples, oradius); (void)mk_addmember(name, &head.l, NULL, WMOP_UNION); sprintf(name, "tube%di", frame); build_spline(name, nsamples, iradius); mk_addmember(name, &head.l, NULL, WMOP_SUBTRACT); mk_addmember("cut", &head.l, NULL, WMOP_SUBTRACT); sprintf(name, "tube%d", frame); mk_lcomb(outfp, name, &head, 1, "plastic", "", (unsigned char *)0, 0); /* Place the tube region and the ammo together. * The origin of the ammo is expected to be the center * of the rearmost plate. */ mk_addmember(name, &ghead.l, NULL, WMOP_UNION); matp = mk_addmember("ke", &ghead.l, NULL, WMOP_UNION)->wm_mat; VSET(from, 0, -1, 0); VSET(to, 1, 0, 0); /* to X axis */ bn_mat_fromto(rot1, from, to, &outfp->wdb_tol); VSET(from, 1, 0, 0); /* Projectile is 480mm long -- use center pt, not end */ xfinddir(to, projectile_pos + 480.0/2, offset); bn_mat_fromto(rot2, from, to, &outfp->wdb_tol); MAT_IDN(xlate); MAT_DELTAS_VEC(xlate, offset); bn_mat_mul(rot3, rot2, rot1); bn_mat_mul(matp, xlate, rot3); (void)mk_addmember("light.r", &ghead.l, NULL, WMOP_UNION); (void)mk_addmember("bg.r", &ghead.l, NULL, WMOP_UNION); sprintf(gname, "g%d", frame); mk_lcomb(outfp, gname, &ghead, 0, (char *)0, "", (unsigned char *)0, 0); fprintf(stderr, "frame %d\n", frame); fflush(stderr); } wdb_close(outfp); fflush(stderr); return 0; }