QString TrackNode::toHtml() { QString D; int i; if ((i = findKey("_waypoint_")) != -1) D += "<p><b>"+QApplication::translate("MapFeature", "Waypoint")+"</b><br/>"; D += "<i>"+QApplication::translate("MapFeature", "coord")+": </i>" + COORD2STRING(position().y()) + " (" + Coord2Sexa(position().y()) + ") / " + COORD2STRING(position().x()) + " (" + Coord2Sexa(position().x()) + ")"; if (elevation()) D += "<br/><i>"+QApplication::translate("MapFeature", "elevation")+": </i>" + QString::number(elevation(), 'f', 4); if (speed()) D += "<br/><i>"+QApplication::translate("MapFeature", "speed")+": </i>" + QString::number(speed(), 'f', 4); if ((i = findKey("_description_")) != -1) D += "<br/><i>"+QApplication::translate("MapFeature", "description")+": </i>" + tagValue(i); if ((i = findKey("_comment_")) != -1) D += "<br/><i>"+QApplication::translate("MapFeature", "comment")+": </i>" + tagValue(i); return Feature::toMainHtml(QApplication::translate("MapFeature", "Node"), "node").arg(D); }
//------------------------------------------------------------------------------ // Printing functions //------------------------------------------------------------------------------ void Airport::printRecord(std::ostream& sout) const { char key1[AP_KEY_LEN+1]; key(key1); char id[AP_IDENT_LEN+1]; ident(id); char ccode[AP_CCODE_LEN+1]; countryCode(ccode); sout << key1; sout << ": "; sout << id; sout << "-"; sout << ccode; sout << " "; sout << char(airportType()); sout << " "; std::streamoff old = sout.precision(); sout.precision(12); sout << latitude(); sout << ", "; sout << longitude(); sout.precision(old); sout << ", "; sout << elevation(); sout << ", mv="; sout << magVariance(); }
void hoa_map_3D_tilde_perform_in1_in2_in3(t_hoa_map_3D_tilde *x, t_object *dsp64, float **ins, long numins, float **outs, long numouts, long sampleframes, long flags, void *userparam) { for(int i = 0; i < sampleframes; i++) { if(x->f_mode == 0) { x->f_map->setRadius(0, ins[1][i]); x->f_map->setAzimuth(0, ins[2][i]); x->f_map->setElevation(0, ins[3][i]); } else if(x->f_mode == 1) { x->f_map->setAzimuth(0, azimuth(ins[1][i], ins[2][i], ins[3][i])); x->f_map->setRadius(0, radius(ins[1][i], ins[2][i], ins[3][i])); x->f_map->setElevation(0,elevation(ins[1][i], ins[2][i], ins[3][i])); } x->f_map->process(&ins[0][i], x->f_sig_outs + numouts * i); } for(int i = 0; i < numouts; i++) { cblas_scopy(sampleframes, x->f_sig_outs+i, numouts, outs[i], 1); } }
/* * Initialize the topography color table. * Input: ct - the color table * size - number of entries in the table * minhgt, maxhgt - the range of height values */ void init_topo_color_table( unsigned int ct[], int size, float minhgt, float maxhgt ) { #define OCEAN #ifdef OCEAN /* Change submitted by Mike McCann to give better under-water */ /* topography colors. */ static float red[7] = { 5.0, 45.0, 20.0, 20.0, 70.0, 165.0, 200.0}; static float green[7] = {10.0, 50.0, 170.0,170.0, 200.0, 42.0, 200.0}; static float blue[7] = {30.0,150.0, 42.0, 42.0, 0.0, 42.0, 200.0}; static float range[7] = {-5.0, -0.020,-0.015, 0.0, 0.1, 1.0, 2.8}; #else static float red[4] = { 20.0, 70.0, 165.0, 200.0}; static float green[4] = {170.0, 200.0, 42.0, 200.0}; static float blue[4] = { 42.0, 0.0, 42.0, 200.0}; static float range[4] = { 0.0, 0.1, 1.0, 2.8}; #endif int i, j; float x0, x1; float r, g, b, dr, dg, db; /* initialize to all white to start */ for (i=0;i<size-1;i++) { ct[i] = 0xffffffff; } ct[size-1] = PACK_COLOR( 25, 25, 255, 255 ); /* r=25, g=25, b=255 */ #ifdef OCEAN for (i=0;i<6;i++) { #else for (i=0;i<3;i++) { #endif if (minhgt==maxhgt) { r = g = b = 0; dr = dg = db = 0; x0 = x1 = 0; } else { x0 = (range[i] - minhgt) / (maxhgt - minhgt) * (float)(size-1); x1 = (range[i+1] - minhgt) / (maxhgt - minhgt) * (float)(size-1); dr = (red[i+1]-red[i]) / (x1-x0); dg = (green[i+1]-green[i]) / (x1-x0); db = (blue[i+1]-blue[i]) / (x1-x0); r = red[i]; g = green[i]; b = blue[i]; } for (j=(int) x0; j<(int) x1; j++) { if (j>=0 && j<size-1) { ct[j] = PACK_COLOR( (int) r, (int) g, (int) b, 0xff ); } r += dr; g += dg; b += db; } } } /* * Generate the topography quadmesh. This must be called after the * grid data set has been loaded. * Input: toponame - name of topography file * textureflag - 1 = use texture mapping, 0 = don't texture map * hi_res - 1=high resolution topography, 0=normal resolution * Return: 1 = ok, 0 = error */ int init_topo( Display_Context dtx, char *toponame, int textureflag, int hi_res ) { double dx, dy; float lat, lon; float topo_dlat, topo_dlon; float *topoheight; int i, j; int topoflag = -1; int qr, qc; uint_1 *indexes; struct Topo *topo; /* MJK 12.02.98 begin */ if (dtx->UserTopoFlag) { topoflag = read_user_topo( dtx, toponame ); if (topoflag == 0) return 0; } if (topoflag == -1) { topoflag = read_topo( dtx->topo, toponame ); } topo = dtx->topo; /* MJK 12.02.98 end */ if (!topoflag && !textureflag) { return 0; } /* qrows, qcols - size of topography quadmesh in rows and columns */ if (topo->Topo_cols==dtx->Nc && topo->Topo_rows==dtx->Nr) { /* use same topography resolution as grid resolution */ qc = topo->Topo_cols; qr = topo->Topo_rows; } else { int maxverts = hi_res ? HI_RES_VERTS : LO_RES_VERTS; float r; if(((dtx->Xmax - dtx->Xmin)*(dtx->Ymax - dtx->Ymin))==0){ fprintf(stderr,"Error in init_topo %f %f %f %f\n",dtx->Xmax,dtx->Xmin,dtx->Ymax,dtx->Ymin); return -1; } r = sqrt( (float) maxverts / ((dtx->Xmax - dtx->Xmin)*(dtx->Ymax - dtx->Ymin)) ); qc = (int) (r * (dtx->Xmax - dtx->Xmin) + 0.5); qr = (int) (r * (dtx->Ymax - dtx->Ymin) + 0.5); } /* allocate space for topography vertex and color arrays */ if (topo->TopoVertex){ free(topo->TopoVertex); free(topo->TopoNormal); free(topo->TopoTexcoord); free(topo->TopoFlatVertex); /* MJK 12.02.98 begin */ for (i = 0; i <= MAXTIMES; i++) { if (topo->TopoIndexes[i] != NULL) free (topo->TopoIndexes[i]), topo->TopoIndexes[i] = NULL; } /* MJK 12.02.98 end */ /* free(topo->TopoIndexes[MAXTIMES]); */ } topo->TopoVertex = (float *) malloc( qr*qc*3*sizeof(float) ); topo->TopoNormal = (float *) malloc( qr*qc*3*sizeof(float) ); topo->TopoTexcoord = (float *) malloc( qr*qc*2*sizeof(float) ); topo->TopoFlatVertex = (float *) malloc( qr*qc*3*sizeof(float) ); topoheight = (float *) malloc( qr*qc*sizeof(float) ); /* topoheight = (float *) allocate( dtx, qr*qc*sizeof(float) ); */ indexes = malloc( qr*qc*1*sizeof(uint_1) ); topo->TopoIndexes[MAXTIMES] = indexes; /* * Compute topography vertices. */ if (dtx->CurvedBox==0) { /* Rectangular box: generate vertices in graphics coords */ int k; float x, y, z; /* MJK 12.15.98 */ double xx, yy, texture_s, texture_t, delta_s, delta_t; dx = (dtx->Xmax-dtx->Xmin) / (float) (qc-1); dy = (dtx->Ymax-dtx->Ymin) / (float) (qr-1); delta_s = 1.0 / (float) (qc-1); delta_t = 1.0 / (float) (qr-1); /* calculate sampling size */ if (topo->Topo_cols==dtx->Nc && topo->Topo_rows==dtx->Nr) { topo->LatSample = topo->LonSample = 1; } else { topo_dlat = (topo->Topo_northlat-topo->Topo_southlat) / topo->Topo_rows; topo->LatSample = CLAMP( (int) (2.0*dy/topo_dlat), 2, 20 ); topo_dlon = (topo->Topo_westlon-topo->Topo_eastlon) / topo->Topo_cols; topo->LonSample = CLAMP( (int) (2.0*dx/topo_dlon), 2, 20 ); } k = 0; yy = dtx->Ymax; texture_t = 0.0; for (i=0; i<qr; i++) { xx = dtx->Xmin; texture_s = 0.0; y = yy; for (j=0; j<qc; j++) { int water; float hgt; x = xx; xyzPRIME_to_geo( dtx, -1, -1, x, y, 0.0, &lat, &lon, &hgt ); hgt = elevation( dtx, dtx->topo, lat, lon, &water ) / 1000.0; /* hgt in km */ /* MJK 2.17.99 z = height_to_zPRIME( dtx, hgt ); */ z = height_to_zTOPO( dtx, hgt ); /* WLH 3 Nov 98 - kludge topo for inverted VERT_GENERIC */ if (dtx->VerticalSystem == VERT_GENERIC && dtx->TopBound < dtx->BottomBound) { z = dtx->Zmin + hgt / (dtx->BottomBound-dtx->TopBound) * (dtx->Zmax-dtx->Zmin); } z = ABS(dtx->Zmin - z) < 0.01 ? dtx->Zmin+0.01 : z; topo->TopoVertex[k*3+0] = x; topo->TopoVertex[k*3+1] = y; topo->TopoVertex[k*3+2] = z; topoheight[k] = hgt; /* save topo height at this vertex */ /* if water flag is set, index will be 255 */ indexes[k] = (water) ? 255 : 0; topo->TopoFlatVertex[k*3+0] = x; topo->TopoFlatVertex[k*3+1] = y; topo->TopoFlatVertex[k*3+2] = dtx->Zmin; topo->TopoTexcoord[k*2+0] = texture_s; topo->TopoTexcoord[k*2+1] = texture_t; k++; xx += dx; texture_s += delta_s; } yy -= dy; texture_t += delta_t; } } else { /* Curved box: generate vertices in geographic coordinates */ float lat, lon; double latlat, lonlon; double dlat, dlon; int k; float texture_s, texture_t, delta_s, delta_t; dlat = (dtx->NorthBound - dtx->SouthBound) / (float) (qr-1); dlon = (dtx->WestBound - dtx->EastBound) / (float) (qc-1); delta_s = 1.0 / (float) (qc-1); delta_t = 1.0 / (float) (qr-1); k = 0; latlat = dtx->NorthBound; texture_t = 0.0; for (i=0; i<qr; i++) { lonlon = dtx->WestBound; lat = latlat; texture_s = 0.0; for (j=0; j<qc; j++) { int water; float hgt, x, y, z; lon = lonlon; hgt = elevation( dtx, dtx->topo, lat, lon, &water ) / 1000.0; /* hgt in km */ /* MJK 2.17.99 geo_to_xyzPRIME( dtx, -1, -1, 1, &lat, &lon, &hgt, &x, &y, &z ); */ geo_to_xyzTOPO( dtx, -1, -1, 1, &lat, &lon, &hgt, &x, &y, &z ); topo->TopoVertex[k*3+0] = x; topo->TopoVertex[k*3+1] = y; topo->TopoVertex[k*3+2] = z; topoheight[k] = hgt; /* if water flag is set, index will be 255 */ indexes[k] = (water) ? 255 : 0; hgt = dtx->BottomBound; /* MJK 2.17.99 geo_to_xyzPRIME( dtx, -1, -1, 1, &lat, &lon, &hgt, &x, &y, &z ); */ geo_to_xyzTOPO( dtx, -1, -1, 1, &lat, &lon, &hgt, &x, &y, &z ); topo->TopoFlatVertex[k*3+0] = x; topo->TopoFlatVertex[k*3+1] = y; topo->TopoFlatVertex[k*3+2] = z; topo->TopoTexcoord[k*2+0] = texture_s; topo->TopoTexcoord[k*2+1] = texture_t; k++; lonlon -= dlon; texture_s += delta_s; } latlat -= dlat; texture_t += delta_t; } } /* Find MinTopoHgt and MaxTopoHgt */ topo->MinTopoHgt = 10000.0; topo->MaxTopoHgt = -10000.0; for (i=0;i<qr*qc;i++) { if (topoheight[i]<topo->MinTopoHgt) { topo->MinTopoHgt = topoheight[i]; } if (topoheight[i]>topo->MaxTopoHgt) { topo->MaxTopoHgt = topoheight[i]; } } /* Compute topography color table indexes. */ for (i=0;i<qr*qc;i++) { float hgt = topoheight[i]; if (indexes[i]!=255) { /* if not water */ if (topo->MinTopoHgt==topo->MaxTopoHgt) { indexes[i] = 0; } else { int index; index = (int) ( (hgt-topo->MinTopoHgt) / (topo->MaxTopoHgt-topo->MinTopoHgt) * 254.0 ); indexes[i] = CLAMP( index, 0, 254 ); } } } /* done with topoheight array */ free( topoheight ); /* compute quadmesh normal vectors */ { float *qnorm; qnorm = (float *) malloc( qc * qr * 3 * sizeof(float) ); /* qnorm = (float *) allocate( dtx, qc * qr * 3 * sizeof(float) ); */ /* step 1: compute surface normal for each quadrilateral. */ for (i=0;i<qr-1;i++) { for (j=0;j<qc-1;j++) { float a[3], b[3]; int index; index = (i*qc+j)*3; /* a is the down vector, b is the right vector */ a[0] = topo->TopoVertex[index+qc*3+0] - topo->TopoVertex[index+0]; a[1] = topo->TopoVertex[index+qc*3+1] - topo->TopoVertex[index+1]; a[2] = topo->TopoVertex[index+qc*3+2] - topo->TopoVertex[index+2]; b[0] = topo->TopoVertex[index+3+0] - topo->TopoVertex[index+0]; b[1] = topo->TopoVertex[index+3+1] - topo->TopoVertex[index+1]; b[2] = topo->TopoVertex[index+3+2] - topo->TopoVertex[index+2]; /* a cross b is the quad's facet normal */ qnorm[index+0] = a[1]*b[2]-a[2]*b[1]; qnorm[index+1] = -a[0]*b[2]+a[2]*b[0]; qnorm[index+2] = a[0]*b[1]-a[1]*b[0]; } } /* step 2: compute vertex normals by averaging adjacent */ /* quadrilateral normals. */ for (i=0;i<qr;i++) { for (j=0;j<qc;j++) { float n[3], mag; int index; index = (i*qc+j)*3; n[0] = n[1] = n[2] = 0.0; /* upper-left quad */ if (i>0 && j>0) { n[0] += qnorm[ index-qc*3-3+0 ]; n[1] += qnorm[ index-qc*3-3+1 ]; n[2] += qnorm[ index-qc*3-3+2 ]; } /* upper-right quad */ if (i>0 && j<qc-1) { n[0] += qnorm[ index-qc*3+0 ]; n[1] += qnorm[ index-qc*3+1 ]; n[2] += qnorm[ index-qc*3+2 ]; } /* lower-left quad */ if (i<qr-1 && j>0) { n[0] += qnorm[ index-3+0 ]; n[1] += qnorm[ index-3+1 ]; n[2] += qnorm[ index-3+2 ]; } /* lower-right quad */ if (i<qr-1 && j<qc-1) { n[0] += qnorm[ index+0 ]; n[1] += qnorm[ index+1 ]; n[2] += qnorm[ index+2 ]; } mag = sqrt( n[0]*n[0] + n[1]*n[1] + n[2]*n[2] ); if (mag>0.0) { mag = 1.0 / mag; topo->TopoNormal[index+0] = n[0] * mag; topo->TopoNormal[index+1] = n[1] * mag; topo->TopoNormal[index+2] = n[2] * mag; } } } free (qnorm); /* deallocate( dtx, qnorm, qc * qr * 3 * sizeof(float) ); */ } topo->qcols = qc; topo->qrows = qr; /* Define the initial quadmesh vertex colors */ if(dtx->ColorTable[VIS5D_TOPO_CT]==NULL){ dtx->ColorTable[VIS5D_TOPO_CT] = (struct ColorTable *) calloc(1,sizeof(struct ColorTable)); } init_topo_color_table( dtx->ColorTable[VIS5D_TOPO_CT]->Colors[MAXVARS*VIS5D_MAX_CONTEXTS], 256, topo->MinTopoHgt, topo->MaxTopoHgt ); topo->TopoColorVar = -1; /* MJK 12.02.98 */ make_topo_strips (dtx); return 1; }
void cssPropertyElevation() { elevation(); }
LightSource* SVGFEDistantLightElement::lightSource() const { return new DistantLightSource(azimuth(), elevation()); }
PassRefPtr<LightSource> SVGFEDistantLightElement::lightSource() const { return DistantLightSource::create(azimuth(), elevation()); }
/** * R E A D _ M A T */ void read_mat (struct rt_i *rtip) { double scan[16] = MAT_INIT_ZERO; char *buf; int status = 0x0; mat_t m; mat_t q; while ((buf = rt_read_cmd(stdin)) != (char *) 0) { if (bu_strncmp(buf, "eye_pt", 6) == 0) { if (sscanf(buf + 6, "%lf%lf%lf", &scan[X], &scan[Y], &scan[Z]) != 3) { bu_exit(1, "nirt: read_mat(): Failed to read eye_pt\n"); } target(X) = scan[X]; target(Y) = scan[Y]; target(Z) = scan[Z]; status |= RMAT_SAW_EYE; } else if (bu_strncmp(buf, "orientation", 11) == 0) { if (sscanf(buf + 11, "%lf%lf%lf%lf", &scan[X], &scan[Y], &scan[Z], &scan[W]) != 4) { bu_exit(1, "nirt: read_mat(): Failed to read orientation\n"); } MAT_COPY(q, scan); quat_quat2mat(m, q); if (nirt_debug & DEBUG_MAT) bn_mat_print("view matrix", m); azimuth() = atan2(-m[0], m[1]) / DEG2RAD; elevation() = atan2(m[10], m[6]) / DEG2RAD; status |= RMAT_SAW_ORI; } else if (bu_strncmp(buf, "viewrot", 7) == 0) { if (sscanf(buf + 7, "%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf", &scan[0], &scan[1], &scan[2], &scan[3], &scan[4], &scan[5], &scan[6], &scan[7], &scan[8], &scan[9], &scan[10], &scan[11], &scan[12], &scan[13], &scan[14], &scan[15]) != 16) { bu_exit(1, "nirt: read_mat(): Failed to read viewrot\n"); } MAT_COPY(m, scan); if (nirt_debug & DEBUG_MAT) bn_mat_print("view matrix", m); azimuth() = atan2(-m[0], m[1]) / DEG2RAD; elevation() = atan2(m[10], m[6]) / DEG2RAD; status |= RMAT_SAW_VR; } } if ((status & RMAT_SAW_EYE) == 0) { bu_exit(1, "nirt: read_mat(): Was given no eye_pt\n"); } if ((status & (RMAT_SAW_ORI | RMAT_SAW_VR)) == 0) { bu_exit(1, "nirt: read_mat(): Was given no orientation or viewrot\n"); } direct(X) = -m[8]; direct(Y) = -m[9]; direct(Z) = -m[10]; dir2ae(); targ2grid(); shoot("", 0, rtip); }
//------------------------------------------------------------------------------ // Printing functions //------------------------------------------------------------------------------ void Navaid::printRecord(std::ostream& sout) const { char icas[32]; icaoCode(icas); char ikey[32]; key(ikey); char id[12]; ident(id); char ccode[4]; countryCode(ccode); char rc[8]; radioClass(rc); sout << icas << ", "; sout << "\""; sout << ikey; sout << "\", "; sout << id; sout << "-"; sout << static_cast<char>(navaidType()); sout << "-"; sout << ccode; sout << "-"; sout << keyCode(); sout << ":"; std::streamoff old = sout.precision(); sout.precision(12); sout << " "; sout << latitude(); sout << ", "; sout << longitude(); sout.precision(old); sout << ", "; sout << elevation(); sout << " "; sout << frequency(); sout << "-"; sout << channel(); sout << " ( "; sout << magVariance(); sout << ", "; sout << slaveVariance(); sout << " )"; sout << " ("; sout << power(); sout << "-"; sout << rc; sout << "-"; sout << range(); sout << ")"; }
int main (int argc, char* argv[]) { ApplicationsLib::LogogSetup logog_setup; std::vector<std::string> keywords; keywords.push_back("-ALL"); keywords.push_back("-MESH"); keywords.push_back("-LOWPASS"); if (argc < 3) { INFO( "Moves mesh nodes and connected elements either by a given value " "or based on a list.\n"); INFO("Usage: %s <msh-file.msh> <keyword> [<value1>] [<value2>]", argv[0]); INFO("Available keywords:"); INFO( "\t-ALL <value1> <value2> : changes the elevation of all mesh " "nodes by <value2> in direction <value1> [x,y,z]."); INFO( "\t-MESH <value1> <value2> : changes the elevation of mesh nodes " "based on a second mesh <value1> with a search range of <value2>."); INFO( "\t-LOWPASS : applies a lowpass filter over node elevation using " "directly connected nodes."); return EXIT_FAILURE; } const std::string msh_name(argv[1]); const std::string current_key(argv[2]); std::string const ext (BaseLib::getFileExtension(msh_name)); if (!(ext == "msh" || ext == "vtu")) { ERR("Error: Parameter 1 must be a mesh-file (*.msh / *.vtu)."); INFO("Usage: %s <msh-file.gml> <keyword> <value>", argv[0]); return EXIT_FAILURE; } bool is_keyword(false); for (auto & keyword : keywords) if (current_key.compare(keyword)==0) { is_keyword = true; break; } if (!is_keyword) { ERR("Keyword not recognised. Available keywords:"); for (auto const& keyword : keywords) INFO("\t%s", keyword.c_str()); return EXIT_FAILURE; } std::unique_ptr<MeshLib::Mesh> mesh (MeshLib::IO::readMeshFromFile(msh_name)); if (mesh == nullptr) { ERR ("Error reading mesh file."); return 1; } // Start keyword-specific selection of nodes // moves the elevation of all nodes by value if (current_key.compare("-ALL")==0) { if (argc < 5) { ERR("Missing parameter..."); return EXIT_FAILURE; } const std::string dir(argv[3]); unsigned idx = (dir.compare("x") == 0) ? 0 : (dir.compare("y") == 0) ? 1 : 2; const double value(strtod(argv[4],0)); INFO("Moving all mesh nodes by %g in direction %d (%s)...", value, idx, dir.c_str()); //double value(-10); const std::size_t nNodes(mesh->getNumberOfNodes()); std::vector<MeshLib::Node*> nodes (mesh->getNodes()); for (std::size_t i=0; i<nNodes; i++) { (*nodes[i])[idx] += value; } } // maps the elevation of mesh nodes according to a ground truth mesh whenever nodes exist within max_dist if (current_key.compare("-MESH")==0) { if (argc < 5) { ERR("Missing parameter..."); return EXIT_FAILURE; } const std::string value (argv[3]); double max_dist(pow(strtod(argv[4],0), 2)); double offset (0.0); // additional offset for elevation (should be 0) std::unique_ptr<MeshLib::Mesh> ground_truth (MeshLib::IO::readMeshFromFile(value)); if (ground_truth == nullptr) { ERR ("Error reading mesh file."); return EXIT_FAILURE; } const std::vector<MeshLib::Node*>& ground_truth_nodes (ground_truth->getNodes()); GeoLib::AABB bounding_box(ground_truth_nodes.begin(), ground_truth_nodes.end()); MathLib::Point3d const& min(bounding_box.getMinPoint()); MathLib::Point3d const& max(bounding_box.getMaxPoint()); const std::size_t nNodes(mesh->getNumberOfNodes()); std::vector<MeshLib::Node*> nodes (mesh->getNodes()); for (std::size_t i=0; i<nNodes; i++) { bool is_inside (containsPoint(*nodes[i], min, max)); if (is_inside) { int idx = find_closest_point(nodes[i], ground_truth_nodes, max_dist); if (idx>=0) (*nodes[i])[2] = (*(ground_truth_nodes[idx]))[2]-offset; } } } // a simple lowpass filter for the elevation of mesh nodes using the elevation of each node // weighted by 2 and the elevation of each connected node weighted by 1 if (current_key.compare("-LOWPASS")==0) { const std::size_t nNodes(mesh->getNumberOfNodes()); std::vector<MeshLib::Node*> nodes (mesh->getNodes()); std::vector<double> elevation(nNodes); for (std::size_t i=0; i<nNodes; i++) elevation[i] = (*nodes[i])[2]; for (std::size_t i=0; i<nNodes; i++) { const std::vector<MeshLib::Node*> conn_nodes (nodes[i]->getConnectedNodes()); const unsigned nConnNodes (conn_nodes.size()); elevation[i] = (2*(*nodes[i])[2]); for (std::size_t j=0; j<nConnNodes; ++j) elevation[i] += (*conn_nodes[j])[2]; elevation[i] /= (nConnNodes+2); } for (std::size_t i=0; i<nNodes; i++) (*nodes[i])[2] = elevation[i]; } /**** add other keywords here ****/ std::string const new_mesh_name (msh_name.substr(0, msh_name.length() - 4) + "_new.vtu"); if (MeshLib::IO::writeMeshToFile(*mesh, new_mesh_name) != 0) return EXIT_FAILURE; INFO ("Result successfully written.") return EXIT_SUCCESS; }
int do_fit(struct FitBlock *iptr,int lag_lim,int goose, struct FitRange *ptr,struct FitRange *xptr, struct FitElv *elv, struct FitNoise *nptr) { struct FitACFBadSample badsmp; int badlag[MAX_RANGE][LAG_SIZE]; int i=0,k; double pwrd[MAX_RANGE],pwrt[MAX_RANGE]; double mnpwr, skylog, freq_to_vel, range; double xomega=0.0; double noise_pwr=0.0; int ni; nptr->skynoise=0.0; nptr->lag0=0.0; nptr->vel=0.0; if (iptr->prm.nave <= 1) return 0; freq_to_vel = C/(4*PI)/(iptr->prm.tfreq * 1000.0); if (iptr->prm.channel==0) FitACFBadlags(&iptr->prm,&badsmp); else FitACFBadlagsStereo(&iptr->prm,&badsmp); /* Determine the lag_0 noise level (0 dB reference) and the noise level at which fit_acf is to quit (average power in the fluctuations of the acfs which are pure noise) */ for (i=0; i < iptr->prm.nrang; i++) { pwrd[i] = (double) iptr->prm.pwr0[i]; /* transfer powers into local array */ pwrt[i] = pwrd[i]; } qsort(pwrt, iptr->prm.nrang, sizeof(double), dbl_cmp); /* determine the average lag0 power of the 10 lowest power acfs */ ni = 0; i = 0; mnpwr = 0.0; /* look for the lowest 10 values of lag0 power and average to get the noise level. Ignore values that are exactly 0. If you can't find 10 useable values within the first 1/3 of the sorted power list, then just use whatever you got in that first 1/3. If you didn't get any useable values, then use the NOISE parameter */ while ((ni < 10) && (i < iptr->prm.nrang/3)) { if (pwrt[i]) ++ni; mnpwr += pwrt[i++]; } ni = (ni > 0) ? ni : 1; mnpwr = mnpwr/ni; if (mnpwr < 1.0) mnpwr = iptr->prm.noise; nptr->skynoise = mnpwr; /* Now determine the level which will be used as the cut-off power for fit_acf. This is the average power at all non-zero lags of all acfs which have lag0 power < 1.6*mnpwr + 1 stnd. deviation from that average power level */ noise_pwr = noise_stat(mnpwr,&iptr->prm,&badsmp, iptr->acfd); /* convert the lag0 powers to dB */ if (nptr->skynoise > 0.0) skylog = 10.0 * log10(nptr->skynoise); else skylog = 0.0; for (i=0; i<iptr->prm.nrang; i++) { pwrd[i] = pwrd[i] - nptr->skynoise; if (pwrd[i] <= 0.0) ptr[i].p_0 = -50.0; else ptr[i].p_0 = 10.0*log10(pwrd[i]) - skylog; } /* reset the output arrays */ for (i=0; i<MAX_RANGE; i++) { ptr[i].p_l = -50.0; ptr[i].p_s = -50.0; ptr[i].p_l_err= 0.0; ptr[i].p_s_err= 0.0; ptr[i].w_l = 0.0; ptr[i].w_s = 0.0; ptr[i].w_l_err = 0.0; ptr[i].w_s_err = 0.0; ptr[i].v = 0.0; ptr[i].v_err = 0.0; ptr[i].phi0 = 0.0; ptr[i].phi0_err=0.0; ptr[i].sdev_l = 0.0; ptr[i].sdev_s = 0.0; ptr[i].sdev_phi = 0.0; ptr[i].gsct = 0.0; ptr[i].qflg = 0; ptr[i].nump=0; xptr[i].p_l = -50.0; xptr[i].p_s = -50.0; xptr[i].p_l_err= 0.0; xptr[i].p_s_err= 0.0; xptr[i].w_l = 0.0; xptr[i].w_s = 0.0; xptr[i].w_l_err = 0.0; xptr[i].w_s_err = 0.0; xptr[i].v = 0.0; xptr[i].v_err = 0.0; xptr[i].phi0 = 0.0; xptr[i].phi0_err=0.0; xptr[i].sdev_l = 0.0; xptr[i].sdev_s = 0.0; xptr[i].sdev_phi = 0.0; xptr[i].gsct = 0.0; xptr[i].qflg = 0; xptr[i].nump=0; elv[i].normal= 0.0; elv[i].low = 0.0; elv[i].high = 0.0; } /* ----------------------------------------------------------------------*/ /* Now do the fits for each acf */ for (k=0, i=0; k<iptr->prm.nrang;k++) { ptr[k].qflg = fit_acf(iptr->acfd[k], k+1,badlag[k],&badsmp, lag_lim,&iptr->prm,noise_pwr,0,0.0,&ptr[k]); xomega=ptr[k].v; if (ptr[k].qflg == 1) { /* several changes have been made here to fix an apparent problem in handling HUGE_VAL. If there are too few points in an ACF to allow the error on a parameter to be calculated then the subroutine fit_acf sets the value to HUGE_VAL. However, in this routine the error values are converted to natural units (e.g. velocity instead of frequency). It appears that multiplying HUGE_VAL by something causes a floating point exception that then sets the result of the calculation to 0. Thus the error values that were being stored in the file would be zero instead of HUGE_VAL. The code now checks to see if the value is set to HUGE_VAL before doing the conversion. If it is then instead of a converted version the error value is reset to HUGE_VAL. */ /* convert power from natural log to dB */ ptr[k].p_l = ptr[k].p_l*LN_TO_LOG - skylog; ptr[k].p_s = ptr[k].p_s*LN_TO_LOG - skylog; ptr[k].p_l_err = (ptr[k].p_l_err == HUGE_VAL) ? HUGE_VAL : ptr[k].p_l_err*LN_TO_LOG; ptr[k].p_s_err = (ptr[k].p_s_err == HUGE_VAL) ? HUGE_VAL : ptr[k].p_s_err*LN_TO_LOG; /* convert Doppler frequency to velocity */ ptr[k].v = iptr->prm.vdir*freq_to_vel*ptr[k].v; /* flag absurdly high velocities with qflg of 8 */ if (ptr[k].v > (freq_to_vel* (PI* 1000.0* 1000.0)/ iptr->prm.mpinc)) ptr[k].qflg= 8; ptr[k].v_err = (ptr[k].v_err == HUGE_VAL) ? HUGE_VAL : freq_to_vel*ptr[k].v_err; /* convert decay parameters to spectral widths */ ptr[k].w_l = freq_to_vel*2*ptr[k].w_l; ptr[k].w_l_err = (ptr[k].w_l_err == HUGE_VAL) ? HUGE_VAL : freq_to_vel*2*ptr[k].w_l_err; /* sigma is returned as sigma**2 so check the sign for validity if sigma**2 is negative take sqrt of the abs and transfer the sign */ ptr[k].w_s = (ptr[k].w_s >= 0) ? sqrt(ptr[k].w_s) : -sqrt(-ptr[k].w_s); if ((ptr[k].w_s !=0.0) && (ptr[k].w_s_err != HUGE_VAL)) ptr[k].w_s_err = 0.5*ptr[k].w_s_err/fabs(ptr[k].w_s); else ptr[k].w_s_err=HUGE_VAL; ptr[k].w_s = 3.33*freq_to_vel*ptr[k].w_s; ptr[k].w_s_err = (ptr[k].w_s_err == HUGE_VAL) ? HUGE_VAL : 3.33*freq_to_vel*ptr[k].w_s_err; /* Now check the values of power, velocity and width to see if this should be flagged as ground-scatter */ if (ptr[k].gsct == 0) ptr[k].gsct=ground_scatter(&ptr[k]); } if ((iptr->prm.xcf != 0) && (ptr[k].qflg == 1)) { xptr[k].qflg = fit_acf(iptr->xcfd[k], k+1,badlag[k],&badsmp, lag_lim,&iptr->prm,noise_pwr,1,xomega, &xptr[k]); } if (xptr[k].qflg == 1) { xptr[k].p_l = xptr[k].p_l*LN_TO_LOG - skylog; xptr[k].p_s = xptr[k].p_s*LN_TO_LOG - skylog; xptr[k].p_l_err = (xptr[k].p_l_err == HUGE_VAL) ? HUGE_VAL : xptr[k].p_l_err*LN_TO_LOG; xptr[k].p_s_err = (xptr[k].p_s_err == HUGE_VAL) ? HUGE_VAL : xptr[k].p_s_err*LN_TO_LOG; /* convert Doppler frequency to velocity */ xptr[k].v = iptr->prm.vdir*freq_to_vel*xptr[k].v; xptr[k].v_err = (xptr[k].v_err == HUGE_VAL) ? HUGE_VAL : freq_to_vel*xptr[k].v_err; /* convert decay parameters to spectral widths */ xptr[k].w_l = freq_to_vel*2*xptr[k].w_l; xptr[k].w_l_err = (xptr[k].w_l_err == HUGE_VAL) ? HUGE_VAL : freq_to_vel*2*xptr[k].w_l_err; /* sigma is returned as sigma**2 so check the sign for validity if sigma**2 is negative take sqrt of the abs and transfer the sign */ xptr[k].w_s = (xptr[k].w_s >= 0) ? sqrt(xptr[k].w_s) : -sqrt(-xptr[k].w_s); if ((xptr[k].w_s !=0.0) && (xptr[k].w_s_err != HUGE_VAL)) xptr[k].w_s_err = 0.5*xptr[k].w_s_err/fabs(xptr[k].w_s); else xptr[k].w_s_err=HUGE_VAL; xptr[k].w_s = 3.33*freq_to_vel*xptr[k].w_s; xptr[k].w_s_err = (xptr[k].w_s_err == HUGE_VAL) ? HUGE_VAL : 3.33*freq_to_vel*xptr[k].w_s_err; /* calculate the elevation angle */ if (xptr[k].phi0 > PI) xptr[k].phi0 = xptr[k].phi0 - 2*PI; if (xptr[k].phi0 < -PI) xptr[k].phi0 = xptr[k].phi0 + 2*PI; if (iptr->prm.phidiff != 0) xptr[k].phi0 = xptr[k].phi0*iptr->prm.phidiff; /* changes which array is first */ range = 0.15*(iptr->prm.lagfr + iptr->prm.smsep*(k-1)); if (goose==0) { elv[k].normal = elevation(&iptr->prm,range, xptr[k].phi0); elv[k].low = elevation(&iptr->prm,range, xptr[k].phi0+xptr[k].phi0_err); elv[k].high = elevation(&iptr->prm,range,xptr[k].phi0-xptr[k].phi0_err); } else { elv[k].normal = elev_goose(&iptr->prm,range, xptr[k].phi0); elv[k].low = elev_goose(&iptr->prm,range, xptr[k].phi0+xptr[k].phi0_err); elv[k].high = elev_goose(&iptr->prm,range, xptr[k].phi0-xptr[k].phi0_err); } } if( (ptr[k].qflg == 1)) i++; } return i; }
int main(int argc, char* argv[]){ //Debug place holder for input data creating CreateMatrix(50, 10, "v.data"); //debug add input data form here CreateMatrix(50, 10, "x.data"); CreateMatrix(50, 10, "y.data"); CreateMatrix(50, 10, "h.data"); myArray MatX; MatX.name = "Matrix X coordinate of target"; MatX.ar = readFile("x.data", &(MatX.row), &(MatX.col)); myArray MatY; MatY.name = "Matrix Y coordinate of target"; MatY.ar = readFile("y.data", &(MatY.row), &(MatY.col)); myArray MatH; MatH.name = "Matrix with relative height coordinate of target"; MatH.ar = readFile("h.data", &(MatH.row), &(MatH.col)); myArray MatV; MatV.name = "Matrix with relative height coordinate of target"; MatV.ar = readFile("v.data", &(MatV.row), &(MatV.col)); myArray MatDefec; MatDefec.name = "defection to target"; MatDefec.row = MatY.row; MatDefec.col = MatY.col; MatDefec.ar = malloc(sizeof(double)*(MatY.row * MatY.col)); myArray MatElev; MatElev.name = "Elevation to target"; MatElev.row = MatY.row; MatElev.col = MatY.col; MatElev.ar = malloc(sizeof(double)*(MatY.row * MatY.col)); printf("-----------------------------------------------\n"); printf("Oringinal X and Y\n-----------------------------------------------\n"); printf("XXXX printing original matrixX "); printArray(MatX.row, MatX.col, MatX.ar); printf("YYYYYprinting original matrixY "); printArray(MatY.row, MatY.col, MatY.ar); printf("\n-----------------------------------------------\n"); printf("-----------------------------------------------\n"); printf("printing original matrix Defelction to target\n"); printArray(MatDefec.row, MatDefec.col, MatDefec.ar); printf("performing the operation\n"); Defection(&MatX, &MatY, &MatDefec); // Defection2(MatX.ar, MatY.ar, MatDefec.ar, MatX.row * MatY.col); printf("-----------------------------------------------\n"); printf("printing original matrix Defelction to target\n"); printArray(MatDefec.row, MatDefec.col, MatDefec.ar); printf("-----------------------------------------------\n"); printf("-----------------------------------------------\n"); printf("printing elevation to target\n"); elevation(&MatX, &MatY, &MatH, &MatV, &MatElev); printArray(MatElev.row, MatElev.col, MatElev.ar); //Thou shalt free all that thy malloc free(MatDefec.ar); free(MatY.ar); free(MatX.ar); free(MatH.ar); free(MatElev.ar); free(MatV.ar); return 0; }
double bearing_elevation::e( double e ) { return elevation( e ); }
int main(int argc, char *argv[]) { struct rt_i *rtip = NULL; char db_title[TITLE_LEN+1];/* title from MGED file */ const char *tmp_str; extern char local_u_name[65]; extern double base2local; extern double local2base; FILE *fPtr; int Ch; /* Option name */ int mat_flag = 0; /* Read matrix from stdin? */ int use_of_air = 0; int print_ident_flag = 1; char ocastring[1024] = {0}; struct bu_list script_list; /* For -e and -f options */ struct script_rec *srp; extern outval ValTab[]; /* from if.c, callback functions for overlap, hit, and miss shots */ int if_overlap(struct application *, struct partition *, struct region *, struct region *, struct partition *); int if_hit(struct application *, struct partition *, struct seg *); int if_miss(struct application *); BU_LIST_INIT(&script_list); bu_setprogname(argv[0]); ocname[OVLP_RESOLVE] = "resolve"; ocname[OVLP_REBUILD_FASTGEN] = "rebuild_fastgen"; ocname[OVLP_REBUILD_ALL] = "rebuild_all"; ocname[OVLP_RETAIN] = "retain"; *ocastring = '\0'; bu_optind = 1; /* restart */ /* Handle command-line options */ while ((Ch = bu_getopt(argc, argv, OPT_STRING)) != -1) { if (bu_optopt == '?') Ch='h'; switch (Ch) { case 'A': attrib_add(bu_optarg, &need_prep); break; case 'B': rt_bot_minpieces = atoi(bu_optarg); break; case 'T': setenv("LIBRT_BOT_MINTIE", bu_optarg, 1); break; case 'b': do_backout = 1; break; case 'E': if (nirt_debug & DEBUG_SCRIPTS) show_scripts(&script_list, "before erasure"); while (BU_LIST_WHILE(srp, script_rec, &script_list)) { BU_LIST_DEQUEUE(&(srp->l)); free_script(srp); } if (nirt_debug & DEBUG_SCRIPTS) show_scripts(&script_list, "after erasure"); break; case 'e': enqueue_script(&script_list, READING_STRING, bu_optarg); if (nirt_debug & DEBUG_SCRIPTS) show_scripts(&script_list, "after enqueueing a literal"); break; case 'f': enqueue_script(&script_list, READING_FILE, bu_optarg); if (nirt_debug & DEBUG_SCRIPTS) show_scripts(&script_list, "after enqueueing a file name"); break; case 'L': listformats(); bu_exit(EXIT_SUCCESS, NULL); case 'M': mat_flag = 1; break; case 'O': sscanf(bu_optarg, "%1024s", ocastring); break; case 's': silent_flag = SILENT_YES; /* Positively yes */ break; case 'v': silent_flag = SILENT_NO; /* Positively no */ break; case 'x': sscanf(bu_optarg, "%x", (unsigned int *)&RTG.debug); break; case 'X': sscanf(bu_optarg, "%x", (unsigned int *)&nirt_debug); break; case 'u': if (sscanf(bu_optarg, "%d", &use_of_air) != 1) { (void) fprintf(stderr, "Illegal use-air specification: '%s'\n", bu_optarg); return 1; } break; case 'H': if (sscanf(bu_optarg, "%d", &print_ident_flag) != 1) { (void) fprintf(stderr, "Illegal header output option specified: '%s'\n", bu_optarg); return 1; } break; default: printusage(); bu_exit (Ch != 'h', NULL); } } /* end while getopt */ if (argc - bu_optind < 2) { printusage(); return 1; } if (isatty(0)) { if (silent_flag != SILENT_YES) silent_flag = SILENT_NO; } else { /* stdin is not a TTY */ if (silent_flag != SILENT_NO) silent_flag = SILENT_YES; } if (silent_flag != SILENT_YES && print_ident_flag) (void) fputs(brlcad_ident("Natalie's Interactive Ray Tracer"), stdout); if (use_of_air && (use_of_air != 1)) { fprintf(stderr, "Warning: useair=%d specified, will set to 1\n", use_of_air); use_of_air = 1; } switch (*ocastring) { case '\0': overlap_claims = OVLP_RESOLVE; break; case '0': case '1': case '2': case '3': if (ocastring[1] == '\0') { sscanf(ocastring, "%d", &overlap_claims); } else { fprintf(stderr, "Illegal overlap_claims specification: '%s'\n", ocastring); return 1; } break; case 'r': if (BU_STR_EQUAL(ocastring, "resolve")) overlap_claims = OVLP_RESOLVE; else if (BU_STR_EQUAL(ocastring, "rebuild_fastgen")) overlap_claims = OVLP_REBUILD_FASTGEN; else if (BU_STR_EQUAL(ocastring, "rebuild_all")) overlap_claims = OVLP_REBUILD_ALL; else if (BU_STR_EQUAL(ocastring, "retain")) overlap_claims = OVLP_RETAIN; else { fprintf(stderr, "Illegal overlap_claims specification: '%s'\n", ocastring); return 1; } break; default: fprintf(stderr, "Illegal overlap_claims specification: '%s'\n", ocastring); return 1; } db_name = argv[bu_optind]; /* build directory for target object */ if (silent_flag != SILENT_YES) { printf("Database file: '%s'\n", db_name); printf("Building the directory..."); } if ((rtip = rt_dirbuild(db_name, db_title, TITLE_LEN)) == RTI_NULL) { fflush(stdout); fprintf(stderr, "Could not load file %s\n", db_name); return 1; } rti_tab[use_of_air] = rtip; rti_tab[1 - use_of_air] = RTI_NULL; rtip->useair = use_of_air; rtip->rti_save_overlaps = (overlap_claims > 0); ++bu_optind; do_rt_gettrees(rtip, argv + bu_optind, argc - bu_optind, &need_prep); /* Initialize the table of resource structures */ rt_init_resource(&res_tab, 0, rtip); /* initialization of the application structure */ RT_APPLICATION_INIT(&ap); ap.a_hit = if_hit; /* branch to if_hit routine */ ap.a_miss = if_miss; /* branch to if_miss routine */ ap.a_overlap = if_overlap;/* branch to if_overlap routine */ ap.a_logoverlap = rt_silent_logoverlap; ap.a_onehit = 0; /* continue through shotline after hit */ ap.a_resource = &res_tab; ap.a_purpose = "NIRT ray"; ap.a_rt_i = rtip; /* rt_i pointer */ ap.a_zero1 = 0; /* sanity check, sayth raytrace.h */ ap.a_zero2 = 0; /* sanity check, sayth raytrace.h */ ap.a_uptr = (void *)a_tab.attrib; /* initialize variables */ azimuth() = 0.0; elevation() = 0.0; direct(X) = -1.0; direct(Y) = 0.0; direct(Z) = 0.0; grid(HORZ) = 0.0; grid(VERT) = 0.0; grid(DIST) = 0.0; grid2targ(); set_diameter(rtip); /* initialize the output specification */ default_ospec(); /* initialize NIRT's local units */ base2local = rtip->rti_dbip->dbi_base2local; local2base = rtip->rti_dbip->dbi_local2base; tmp_str = bu_units_string(local2base); if (tmp_str) { bu_strlcpy(local_u_name, tmp_str, sizeof(local_u_name)); } else { bu_strlcpy(local_u_name, "Unknown units", sizeof(local_u_name)); } if (silent_flag != SILENT_YES) { printf("Database title: '%s'\n", db_title); printf("Database units: '%s'\n", local_u_name); printf("model_min = (%g, %g, %g) model_max = (%g, %g, %g)\n", rtip->mdl_min[X] * base2local, rtip->mdl_min[Y] * base2local, rtip->mdl_min[Z] * base2local, rtip->mdl_max[X] * base2local, rtip->mdl_max[Y] * base2local, rtip->mdl_max[Z] * base2local); } /* Run the run-time configuration file, if it exists */ if ((fPtr = fopenrc()) != NULL) { interact(READING_FILE, fPtr, rtip); fclose(fPtr); } /* Run all scripts specified on the command line */ run_scripts(&script_list, rtip); /* Perform the user interface */ if (mat_flag) { read_mat(rtip); return 0; } else { interact(READING_FILE, stdin, rtip); } return 0; }
double bearing_elevation::e() const { return elevation(); }
bearing_elevation::bearing_elevation( double b, double e ) : bearing_( bearing( b ) ), elevation_( elevation( e ) ) {}
void Turret::trackAndFire (Player *closePlayer, float interval) { if (data->isSustained == false) { Vector3F rot = getAngulerPosition(); int aimed = 0; float old_rot = turretRotation; float increment = data->speed * interval; float des_z; Point3F playerPos; float dist = m_distf (getBoxCenter(), closePlayer->getLeadCenter()); leadPosition (closePlayer->getLeadCenter(), closePlayer->getLeadVelocity(), dist, &playerPos); TMat3F invMat; getNodeOffset (&invMat, "dummy muzzle", gunNode); invMat.inverse(); m_mul (Point3F (playerPos.x, playerPos.y, playerPos.z), invMat, &playerPos); des_z = rotation (-playerPos.x, -playerPos.y); while (des_z < 0) des_z += (float)M_2PI; while (des_z > M_2PI) des_z -= (float)M_2PI; float diff = des_z - turretRotation; if (diff > M_PI || diff < -M_PI) increment = -increment; if (diff < increment && diff > -increment) { turretRotation = des_z; aimed += 1; } else if (diff < 0) turretRotation -= increment; else turretRotation += increment; wrapRotation (); if (turretRotation != old_rot) setMaskBits (TRotationMask); float old_elevation = turretElevation; float des_y; increment = data->speed * interval; des_y = elevation (playerPos.x, playerPos.y, playerPos.z); diff = des_y - turretElevation; if (diff > M_PI || diff < -M_PI) increment = -increment; if (diff < increment && diff > -increment) { turretElevation = des_y; aimed += 1; } else if (diff < 0) turretElevation -= increment; else turretElevation += increment; wrapElevation (); if (old_elevation != turretElevation) setMaskBits (ElevationMask); if (closePlayer && aimed >= 2 && waitTime <= manager->getCurrentTime()) shoot (false, closePlayer); } else { Vector3F rot = getAngulerPosition(); int aimed = 0; float old_rot = turretRotation; float increment = data->speed * interval; float des_z; Point3F playerPos; float dist = m_distf (getBoxCenter(), closePlayer->getLeadCenter()); leadPosition (closePlayer->getLeadCenter(), closePlayer->getLeadVelocity(), dist, &playerPos); TMat3F invMat; getNodeOffset (&invMat, "dummy muzzle", gunNode); invMat.inverse(); m_mul (Point3F (playerPos.x, playerPos.y, playerPos.z), invMat, &playerPos); des_z = rotation (-playerPos.x, -playerPos.y); while (des_z < 0) des_z += (float)M_2PI; while (des_z > M_2PI) des_z -= (float)M_2PI; float diff = des_z - turretRotation; if (diff > M_PI || diff < -M_PI) increment = -increment; if (diff < increment && diff > -increment) { turretRotation = des_z; aimed += 1; } else if (diff < 0) turretRotation -= increment; else turretRotation += increment; wrapRotation (); if (turretRotation != old_rot) setMaskBits (TRotationMask); float old_elevation = turretElevation; float des_y; increment = data->speed * interval; des_y = elevation (playerPos.x, playerPos.y, playerPos.z); diff = des_y - turretElevation; if (diff > M_PI || diff < -M_PI) increment = -increment; if (diff < increment && diff > -increment) { turretElevation = des_y; aimed += 1; } else if (diff < 0) turretElevation -= increment; else turretElevation += increment; wrapElevation (); if (old_elevation != turretElevation) setMaskBits (ElevationMask); if (closePlayer && aimed >= 2 && waitTime <= manager->getCurrentTime()) { shoot (false, closePlayer); } } }
void Turret::serverProcessFiring(DWORD in_currTime) { if (!getControlClient() && getState () == StaticBase::Enabled && isActive()) { AssertFatal(m_pProjectile != NULL, "Must have projectile"); if (m_pTarget == NULL) { // Lost our target, or player mount just ended... unshoot(); return; } if (in_currTime >= m_beganState + data->firingTime) { // If the firing time runs out, we switch to reloading... unshoot(); return; } float useRange = data->gunRange == -1 ? data->iRange : data->gunRange; float minDist = useRange; if (isTargetable(m_pTarget, &minDist, useRange) == false) { unshoot(); return; } // Guess we're still good, track the player... float interval = 0.032; Vector3F rot = getAngulerPosition(); int aimed = 0; float old_rot = turretRotation; float increment = data->speed * interval; float des_z; Point3F playerPos; float dist = m_distf (getBoxCenter(), m_pTarget->getLeadCenter()); leadPosition (m_pTarget->getLeadCenter(), m_pTarget->getLeadVelocity(), dist, &playerPos); TMat3F invMat; getNodeOffset (&invMat, "dummy muzzle", gunNode); invMat.inverse(); m_mul (Point3F (playerPos.x, playerPos.y, playerPos.z), invMat, &playerPos); des_z = rotation (-playerPos.x, -playerPos.y); while (des_z < 0) des_z += (float)M_2PI; while (des_z > M_2PI) des_z -= (float)M_2PI; float diff = des_z - turretRotation; if (diff > M_PI || diff < -M_PI) increment = -increment; if (diff < increment && diff > -increment) { turretRotation = des_z; aimed += 1; } else if (diff < 0) turretRotation -= increment; else turretRotation += increment; wrapRotation (); if (turretRotation != old_rot) setMaskBits (TRotationMask); float old_elevation = turretElevation; float des_y; increment = data->speed * interval; des_y = elevation (playerPos.x, playerPos.y, playerPos.z); diff = des_y - turretElevation; if (diff > M_PI || diff < -M_PI) increment = -increment; if (diff < increment && diff > -increment) { turretElevation = des_y; aimed += 1; } else if (diff < 0) turretElevation -= increment; else turretElevation += increment; wrapElevation (); if (old_elevation != turretElevation) setMaskBits (ElevationMask); } if (m_pProjectile) m_pProjectile->updateImageTransform(getEyeTransform()); }
//------------------------------------------------------------------------------ // serialize true bearing and range to system //------------------------------------------------------------------------------ void Record::printTrueBearingRange(std::ostream& sout, const double aclat, const double aclon, const double acelev)const { double bearing, range, grdrange; Basic::Nav::glla2bd(aclat, aclon, acelev, latitude(), longitude(), elevation(), &bearing, &range, &grdrange); sout << " range " << range << " grdrange " << grdrange << " true_bearing " << bearing; }