std::string CreatureManager::ProcessContactBone(const glm::vec2& pt_in, float radius, meshBone * bone_in) const { std::string ret_name; glm::vec2 cur_vec = glm::vec2(bone_in->getWorldEndPt() - bone_in->getWorldStartPt()); float cur_length = glm::length(cur_vec); glm::vec2 unit_vec = glm::normalize(cur_vec); glm::vec2 norm_vec(unit_vec.y, unit_vec.x); glm::vec2 rel_vec = pt_in - glm::vec2(bone_in->getWorldStartPt()); float proj = glm::dot(rel_vec, unit_vec); if( (proj >= 0) && (proj <= cur_length)) { float norm_proj = glm::dot(rel_vec, norm_vec); if(norm_proj <= radius) { return bone_in->getKey(); } } auto& cur_children = bone_in->getChildren(); for(auto& cur_child : cur_children) { ret_name = ProcessContactBone(pt_in, radius, cur_child); if(!ret_name.empty()) { break; } } return ret_name; }
int RPosRngBmAzmElv(int bm,int rn,int year, struct RadarSite *hdw,double frang, double rsep,double rx,double height, double *azm,double *elv) { double flat,flon,frho; double fx,fy,fz; double gx,gy,gz; double glat,glon; double gdlat,gdlon,gdrho; double gbx,gby,gbz; double ghx,ghy,ghz; double bx,by,bz,b; double dummy; int s; gdlat=hdw->geolat; gdlon=hdw->geolon; if (rx==0) rx=hdw->recrise; RPosGeo(1,bm,rn,hdw,frang,rsep,rx, height,&frho,&flat,&flon); sphtocar(frho,flat,flon,&fx,&fy,&fz); geodtgc(1,&gdlat,&gdlon,&gdrho,&glat,&glon,&dummy); sphtocar(gdrho,glat,glon,&gbx,&gby,&gbz); gx=fx-gbx; gy=fy-gby; gz=fz-gbz; norm_vec(&gx,&gy,&gz); glbthor(1,flat,flon,&gx,&gy,&gz,&ghx,&ghy,&ghz); norm_vec(&ghx,&ghy,&ghz); s=IGRFMagCmp(year,frho,flat,flon,&bx,&by,&bz,&b); if (s==-1) return -1; norm_vec(&bx,&by,&bz); ghz=-(bx*ghx+by*ghy)/bz; norm_vec(&ghx,&ghy,&ghz); *elv=atan2d(ghz,sqrt(ghx*ghx+ghy*ghy)); *azm=atan2d(ghy,-ghx); return 0; }
int update_wizard(t_wizard *wizard) { if (((wizard->cx <= wizard->vdest.x - wizard->speed || wizard->cx >= wizard->vdest.x + wizard->speed) || (wizard->cy <= wizard->vdest.y - wizard->speed || wizard->cy >= wizard->vdest.y + wizard->speed))) { if (wizard->move) { wizard->anim++; if (!(wizard->anim % 2)) wizard_hands_move(wizard); if (!(wizard->anim %= 5)) { /* wizard hat animation */ /* until I find a more elegant way */ if (wizard->tx_id == TX_W_WIZ_1) wizard->tx_id = TX_W_WIZ_2; else if (wizard->tx_id == TX_W_WIZ_2) wizard->tx_id = TX_W_WIZ_1; else if (wizard->tx_id == TX_R_WIZ_1) wizard->tx_id = TX_R_WIZ_2; else if (wizard->tx_id == TX_R_WIZ_2) wizard->tx_id = TX_R_WIZ_1; else if (wizard->tx_id == TX_G_WIZ_1) wizard->tx_id = TX_G_WIZ_2; else if (wizard->tx_id == TX_G_WIZ_2) wizard->tx_id = TX_G_WIZ_1; } update_wizard_angle(wizard); wizard->vmove.x = wizard->vdest.x - wizard->cx; wizard->vmove.y = wizard->vdest.y - wizard->cy; wizard->vmove = norm_vec(&wizard->vmove); wizard->cx += wizard->vmove.x * wizard->speed; wizard->cy += wizard->vmove.y * wizard->speed; } else { wizard->move = 1; if (!set_new_wizard_angle(wizard, wizard->vdest.x, wizard->vdest.y)) return (0); } } else { wizard->move = 0; wizard->anim++; if (!(wizard->anim %= 2)) wizard_hands_init(wizard); } return (1); }
int RPosInvMag(int bm,int rn,int year,struct RadarSite *hdw,double frang, double rsep,double rx,double height, double *mlat,double *mlon,double *azm) { double flat,flon,frho; double fx,fy,fz; double gx,gy,gz; double glat,glon; double gdlat,gdlon,gdrho; double gbx,gby,gbz; double ghx,ghy,ghz; double bx,by,bz,b; double dummy,elv,azc; double tmp_ht; double xlat,xlon,nlat,nlon; int s; gdlat=hdw->geolat; gdlon=hdw->geolon; if (rx==0) rx=hdw->recrise; RPosGeo(1,bm,rn,hdw,frang,rsep,rx, height,&frho,&flat,&flon); sphtocar(frho,flat,flon,&fx,&fy,&fz); geodtgc(1,&gdlat,&gdlon,&gdrho,&glat,&glon,&dummy); sphtocar(gdrho,glat,glon,&gbx,&gby,&gbz); gx=fx-gbx; gy=fy-gby; gz=fz-gbz; norm_vec(&gx,&gy,&gz); glbthor(1,flat,flon,&gx,&gy,&gz,&ghx,&ghy,&ghz); norm_vec(&ghx,&ghy,&ghz); s=IGRFMagCmp(year,frho,flat,flon,&bx,&by,&bz,&b); if (s==-1) return -1; norm_vec(&bx,&by,&bz); ghz=-(bx*ghx+by*ghy)/bz; norm_vec(&ghx,&ghy,&ghz); elv=atan2d(ghz,sqrt(ghx*ghx+ghy*ghy)); azc=atan2d(ghy,-ghx); geodtgc(-1,&gdlat,&gdlon,&gdrho,&flat,&flon,&dummy); tmp_ht=frho-gdrho; AACGMConvert(flat,flon,tmp_ht,mlat,mlon,&dummy,0); fldpnt_sph(frho,flat,flon,azc,rsep,&xlat,&xlon); s=AACGMConvert(xlat,xlon,tmp_ht,&nlat,&nlon,&dummy,0); if (s==-1) return -1; if ((nlon-*mlon) > 180) nlon=nlon-360; if ((nlon-*mlon) < -180) nlon=nlon+360; fldpnt_azm(*mlat,*mlon,nlat,nlon,azm); return 0; }