diff --git a/OVP/D3D7Client/CSphereMgr.cpp b/OVP/D3D7Client/CSphereMgr.cpp index ec66e6887..2a5b06a65 100644 --- a/OVP/D3D7Client/CSphereMgr.cpp +++ b/OVP/D3D7Client/CSphereMgr.cpp @@ -309,7 +309,7 @@ void CSphereManager::Render (LPDIRECT3DDEVICE7 dev, int level, double bglvl) MATRIX3 rcam = *scn->GetCamera()->GetGRot(); rcam = mul (ecl2gal, rcam); - RenderParam.camdir = _V(rcam.m13, rcam.m23, rcam.m33); + RenderParam.camdir = {rcam.m13, rcam.m23, rcam.m33}; dev->SetRenderState (D3DRENDERSTATE_DESTBLEND, D3DBLEND_ONE); dev->SetRenderState (D3DRENDERSTATE_ALPHABLENDENABLE, TRUE); @@ -406,7 +406,7 @@ void CSphereManager::ProcessTile (int lvl, int hemisp, int ilat, int nlat, int i static const double rad0 = sqrt(2.0)*PI05; VECTOR3 cnt = TileCentre (hemisp, ilat, nlat, ilng, nlng); double rad = rad0/(double)nlat; - double alpha = acos (dotp (RenderParam.camdir, cnt)); + double alpha = std::acos(dot(RenderParam.camdir, cnt)); double adist = alpha - rad; if (adist > RenderParam.viewap) return; @@ -477,8 +477,8 @@ VECTOR3 CSphereManager::TileCentre (int hemisp, int ilat, int nlat, int ilng, in { double cntlat = PI05 * ((double)ilat+0.5)/(double)nlat, slat = sin(cntlat), clat = cos(cntlat); double cntlng = PI2 * ((double)ilng+0.5)/(double)nlng + PI, slng = sin(cntlng), clng = cos(cntlng); - if (hemisp) return _V(clat*clng, -slat, -clat*slng); - else return _V(clat*clng, slat, clat*slng); + if (hemisp) return {clat*clng, -slat, -clat*slng}; + else return {clat*clng, slat, clat*slng}; } // ======================================================================= diff --git a/OVP/D3D7Client/CloudMgr.cpp b/OVP/D3D7Client/CloudMgr.cpp index f26e2ff7a..047353413 100644 --- a/OVP/D3D7Client/CloudMgr.cpp +++ b/OVP/D3D7Client/CloudMgr.cpp @@ -36,7 +36,7 @@ CloudManager::CloudManager (const D3D7Client *gclient, const vPlanet *vplanet) maxlvl = min (*(int*)gc->GetConfigParam (CFGPRM_SURFACEMAXLEVEL), // global setting *(int*)oapiGetObjectParam (obj, OBJPRM_PLANET_SURFACEMAXLEVEL)); // planet-specific setting maxbaselvl = min (8, maxlvl); - pcdir = _V(1,0,0); + pcdir = {1,0,0}; lightfac = *(double*)gc->GetConfigParam (CFGPRM_SURFACELIGHTBRT); nmask = 0; nhitex = nhispec = 0; diff --git a/OVP/D3D7Client/HazeMgr.cpp b/OVP/D3D7Client/HazeMgr.cpp index b4397292e..fa2b5e542 100644 --- a/OVP/D3D7Client/HazeMgr.cpp +++ b/OVP/D3D7Client/HazeMgr.cpp @@ -36,7 +36,7 @@ HazeManager::HazeManager (const D3D7Client *gclient, const vPlanet *vplanet) dens0 = (float)(min (1.0, atmc->horizonalt/64e3 * *(double*)oapiGetObjectParam (obj, OBJPRM_PLANET_HAZEDENSITY))); } else { - basecol = _V(1,1,1); + basecol = {1,1,1}; hralt = 0.01f; dens0 = 1.0f; } @@ -113,7 +113,7 @@ void HazeManager::Render (LPDIRECT3DDEVICE7 dev, D3DMATRIX &wmat, bool dual) float dens = (float)max (1.0, 1.4 - 0.3/hralt*(cdist-1.0)); // saturate haze colour at low altitudes if (dual) dens *= (float)(0.5 + 0.5/cdist); // scale down intensity at large distances - normalise (rpos); + rpos = unit(rpos); cost = (float)rpos.y, sint = (float)sqrt (1.0-cost*cost); phi = atan2 (rpos.z, rpos.x), cosp = (float)cos(phi), sinp = (float)sin(phi); D3DMATRIX rmat = {cost*cosp, -sint, cost*sinp, 0, @@ -131,8 +131,8 @@ void HazeManager::Render (LPDIRECT3DDEVICE7 dev, D3DMATRIX &wmat, bool dual) oapiGetGlobalPos (obj, &gpos); psun = tmul (grot, -gpos); // sun in planet coords psun = mul (rrmat, psun); // sun in camera-relative horizon coords - VECTOR3 cs = psun-cpos; normalise(cs); // camera->sun - normalise (psun); + VECTOR3 cs = unit(psun - cpos); // camera->sun + psun = unit(psun); float psunx = (float)psun.x, psuny = (float)psun.y, psunz = (float)psun.z; colofs = (dual ? 0.4 : 0.3); @@ -146,10 +146,10 @@ void HazeManager::Render (LPDIRECT3DDEVICE7 dev, D3DMATRIX &wmat, bool dual) dev->SetTextureStageState (0, D3DTSS_ADDRESS, D3DTADDRESS_CLAMP); for (i = j = 0; i < HORIZON_NSEG; i++) { - VECTOR3 hp = {Vtx[j].x = r1*CosP[i], Vtx[j].y = h1, Vtx[j].z = r1*SinP[i]}; - csun = dotp (hp, psun); - VECTOR3 cp = hp-cpos; normalise(cp); - double colsh = 0.5*(dotp (cp,cs) + 1.0); + VECTOR3 hp{Vtx[j].x = r1*CosP[i], Vtx[j].y = h1, Vtx[j].z = r1*SinP[i]}; + csun = dot(hp, psun); + VECTOR3 cp = unit(hp - cpos); + double colsh = 0.5 * (dot(cp, cs) + 1.0); // compose a colourful sunset double maxred = colofs-0.18*colsh, minred = maxred-0.4; diff --git a/OVP/D3D7Client/Light.cpp b/OVP/D3D7Client/Light.cpp index 185fad74d..e41d6700e 100644 --- a/OVP/D3D7Client/Light.cpp +++ b/OVP/D3D7Client/Light.cpp @@ -22,7 +22,7 @@ D3D7Light::D3D7Light (OBJHANDLE _hObj, LTYPE _ltype, const Scene *scene, DWORD _idx) { hObj = _hObj; - rpos = _V(0,0,0); + rpos = {0,0,0}; ltype = _ltype; scn = scene; idx = _idx; @@ -64,7 +64,7 @@ void D3D7Light::UpdateDirectional () VECTOR3 rpos; oapiGetGlobalPos (hObj, &rpos); rpos -= *scn->GetCamera()->GetGPos(); // object position rel. to camera - rpos /= -length(rpos); // normalise + rpos /= -len(rpos); // normalise D3DVEC(rpos, light.dvDirection); } diff --git a/OVP/D3D7Client/Particle.cpp b/OVP/D3D7Client/Particle.cpp index dd03333f0..1e078cafc 100644 --- a/OVP/D3D7Client/Particle.cpp +++ b/OVP/D3D7Client/Particle.cpp @@ -58,7 +58,7 @@ D3D7ParticleStream::D3D7ParticleStream (GraphicsClient *_gc, PARTICLESTREAMSPEC d3d7c = (D3D7Client*)_gc; cam_ref = d3d7c->GetScene()->GetCamera()->GetGPos(); src_ref = 0; - src_ofs = _V(0,0,0); + src_ofs = {0,0,0}; interval = 0.1; SetSpecs (pss ? pss : &DefaultParticleStreamSpec); t0 = oapiGetSimTime(); @@ -590,8 +590,8 @@ void ExhaustStream::Update () ((double)rand()/(double)RAND_MAX-0.5)*dv_scale}; dv += vv; - normalise(s); - VECTOR3 vv2 = dv - s*dotp(s,dv); + s = unit(s); + VECTOR3 vv2 = dv - s * dot(s, dv); if (length(vv2)) vv2 *= 0.5*length(vv)/length(vv2); vv2 += s*(((double)rand()/(double)RAND_MAX)*dv_scale); p->vel = vv2*1.0/*2.0*/+av; @@ -675,9 +675,9 @@ void ExhaustStream::RenderGroundShadow (LPDIRECT3DDEVICE7 dev, LPDIRECTDRAWSURFA rad += oapiSurfaceElevation (hPlanet, lng, lat); // calculate the intersection of the vessel's shadow with the planet surface - double fac1 = dotp (sd, pv0); + double fac1 = dot(sd, pv0); if (fac1 > 0.0) return; // shadow doesn't intersect planet surface - double arg = fac1*fac1 - (dotp (pv0, pv0) - rad*rad); + double arg = fac1 * fac1 - (dot(pv0, pv0) - rad * rad); if (arg <= 0.0) return; // shadow doesn't intersect with planet surface double a = -fac1 - sqrt(arg); VECTOR3 shp = sd*a; // projection point in global frame @@ -696,9 +696,9 @@ void ExhaustStream::RenderGroundShadow (LPDIRECT3DDEVICE7 dev, LPDIRECTDRAWSURFA VECTOR3 pvr = p->pos - pp; // rel. particle position // calculate the intersection of the vessel's shadow with the planet surface - double fac1 = dotp (sd, pvr); + double fac1 = dot(sd, pvr); if (fac1 > 0.0) break; // shadow doesn't intersect planet surface - double arg = fac1*fac1 - (dotp (pvr, pvr) - rad*rad); + double arg = fac1 * fac1 - (dot(pvr, pvr) - rad * rad); if (arg <= 0.0) break; // shadow doesn't intersect with planet surface double a = -fac1 - sqrt(arg); @@ -734,7 +734,7 @@ ReentryStream::ReentryStream (oapi::GraphicsClient *_gc, OBJHANDLE hV, PARTICLES : D3D7ParticleStream (_gc, pss) { llevel = 1.0; - Attach (hV, _V(0,0,0), _V(0,0,0), &llevel); + Attach (hV, {0,0,0}, {0,0,0}, &llevel); hPlanet = 0; } diff --git a/OVP/D3D7Client/Scene.cpp b/OVP/D3D7Client/Scene.cpp index bf84755a2..46c19965e 100644 --- a/OVP/D3D7Client/Scene.cpp +++ b/OVP/D3D7Client/Scene.cpp @@ -292,13 +292,13 @@ VECTOR3 Scene::SkyColour () if (cdist < atmp->radlimit) { ATMPARAM prm; oapiGetPlanetAtmParams (hProxy, cdist, &prm); - normalise (rp); - double coss = dotp (pc, rp) / -cdist; + rp = unit(rp); + double coss = dot(pc, rp) / -cdist; double intens = min (1.0,(1.0839*coss+0.4581)) * sqrt (prm.rho/atmp->rho0); // => intensity=0 at sun zenith distance 115° // intensity=1 at sun zenith distance 60° if (intens > 0.0) - col += _V(atmp->color0.x*intens, atmp->color0.y*intens, atmp->color0.z*intens); + col += {atmp->color0.x*intens, atmp->color0.y*intens, atmp->color0.z*intens}; } for (int i = 0; i < 3; i++) if (col.data[i] > 1.0) col.data[i] = 1.0; @@ -450,7 +450,7 @@ void Scene::Render () const std::vector& ls = list[n].marker; VECTOR3 sp; for (j = 0; j < ls.size(); j++) { - if (dotp(ls[j].pos, cpos - ls[j].pos) >= 0.0) { // surface point visible? + if (dot(ls[j].pos, cpos - ls[j].pos) >= 0.0) { // surface point visible? sp = mul(prot, ls[j].pos) + ppos; RenderObjectMarker(pSkp, sp, ls[j].label[0], ls[j].label[1], list[n].shape, size); } @@ -642,8 +642,7 @@ void Scene::RenderVesselShadows (OBJHANDLE hPlanet, float depth) const void Scene::RenderObjectMarker (oapi::Sketchpad* pSkp, const VECTOR3 &gpos, const std::string& label1, const std::string& label2, int mode, int scale) { - VECTOR3 dp (gpos - *cam->GetGPos()); - normalise (dp); + VECTOR3 dp = unit(gpos - *cam->GetGPos()); m_celSphere->RenderMarker(pSkp, dp, label1, label2, mode, scale); } diff --git a/OVP/D3D7Client/SurfMgr.cpp b/OVP/D3D7Client/SurfMgr.cpp index 08e2a796a..bd12560fc 100644 --- a/OVP/D3D7Client/SurfMgr.cpp +++ b/OVP/D3D7Client/SurfMgr.cpp @@ -32,7 +32,7 @@ SurfaceManager::SurfaceManager (const D3D7Client *gclient, const vPlanet *vplane maxlvl = min (*(int*)gc->GetConfigParam (CFGPRM_SURFACEMAXLEVEL), // global setting *(int*)oapiGetObjectParam (obj, OBJPRM_PLANET_SURFACEMAXLEVEL)); // planet-specific setting maxbaselvl = min (8, maxlvl); - pcdir = _V(1,0,0); + pcdir = {1,0,0}; lightfac = *(double*)gc->GetConfigParam (CFGPRM_SURFACELIGHTBRT); spec_base = 0.95f; atmc = oapiGetPlanetAtmConstants (obj); diff --git a/OVP/D3D7Client/TileMgr.cpp b/OVP/D3D7Client/TileMgr.cpp index 24449d4a2..ef503c5c7 100644 --- a/OVP/D3D7Client/TileMgr.cpp +++ b/OVP/D3D7Client/TileMgr.cpp @@ -431,9 +431,8 @@ void TileManager::Render (LPDIRECT3DDEVICE7 dev, D3DMATRIX &wmat, double scale, D3DMAT_Copy (&RenderParam.wmat, &wmat); D3DMAT_Copy (&RenderParam.wmat_tmp, &wmat); D3DMAT_MatrixInvert (&imat, &wmat); - RenderParam.cdir = _V(imat._41, imat._42, imat._43); // camera position in local coordinates (units of planet radii) - RenderParam.cpos = vp->PosFromCamera() * scale; - normalise (RenderParam.cdir); // camera direction + RenderParam.cdir = unit(VECTOR3{imat._41, imat._42, imat._43}); // camera direction + RenderParam.cpos = vp->PosFromCamera() * scale; // camera position in local coordinates (units of planet radii) RenderParam.bfog = bfog; oapiGetRotationMatrix (obj, &RenderParam.grot); @@ -443,11 +442,10 @@ void TileManager::Render (LPDIRECT3DDEVICE7 dev, D3DMATRIX &wmat, double scale, RenderParam.objsize = oapiGetSize (obj); RenderParam.cdist = vp->CamDist() / vp->rad; // camera distance in units of planet radius RenderParam.viewap = (viewap ? viewap : acos (1.0/max (1.0, RenderParam.cdist))); - RenderParam.sdir = tmul (RenderParam.grot, -gpos); - normalise (RenderParam.sdir); // sun direction in planet frame + RenderParam.sdir = unit(tmul(RenderParam.grot, -gpos)); // sun direction in planet frame // limit resolution for fast camera movements - double limitstep, cstep = acos (dotp (RenderParam.cdir, pcdir)); + double limitstep, cstep = std::acos(dot(RenderParam.cdir, pcdir)); int maxlevel = SURF_MAX_PATCHLEVEL; static double limitstep0 = 5.12 * pow(2.0, -(double)SURF_MAX_PATCHLEVEL); for (limitstep = limitstep0; cstep > limitstep && maxlevel > 5; limitstep *= 2.0) @@ -512,7 +510,7 @@ void TileManager::ProcessTile (int lvl, int hemisp, int ilat, int nlat, int ilng static const double rad0 = sqrt(2.0)*PI05*0.5; VECTOR3 cnt = TileCentre (hemisp, ilat, nlat, ilng, nlng); double rad = rad0/(double)nlat; - double adist = acos (dotp (RenderParam.cdir, cnt)) - rad; + double adist = std::acos(dot(RenderParam.cdir, cnt)) - rad; if (adist >= RenderParam.viewap) { tilebuf->DeleteSubTiles (tile); // remove tile descriptions below return; @@ -594,7 +592,7 @@ void TileManager::ProcessTile (int lvl, int hemisp, int ilat, int nlat, int ilng } } else { // actually render the tile at this level - double sdist = acos (dotp (RenderParam.sdir, cnt)); + double sdist = std::acos(dot(RenderParam.sdir, cnt)); if (bCoarseTex) { if (sdist > PI05+rad && bkp_flag & 2) bkp_flag &= 0xFD, bkp_flag |= 1; // supress specular reflection on dark side RenderTile (lvl, hemisp, ilat, nlat, ilng, nlng, sdist, tile, bkp_range, bkp_tex, bkp_ltex, bkp_flag); @@ -665,8 +663,8 @@ VECTOR3 TileManager::TileCentre (int hemisp, int ilat, int nlat, int ilng, int n { double cntlat = PI*0.5 * ((double)ilat+0.5)/(double)nlat, slat = sin(cntlat), clat = cos(cntlat); double cntlng = PI*2.0 * ((double)ilng+0.5)/(double)nlng + PI, slng = sin(cntlng), clng = cos(cntlng); - if (hemisp) return _V(clat*clng, -slat, -clat*slng); - else return _V(clat*clng, slat, clat*slng); + if (hemisp) return {clat*clng, -slat, -clat*slng}; + else return {clat*clng, slat, clat*slng}; } // ======================================================================= @@ -751,7 +749,7 @@ bool TileManager::SpecularColour (D3DCOLORVALUE *col) return false; } else { double fac = 0.7; // needs thought ... - double cosa = dotp (RenderParam.cdir, RenderParam.sdir); + double cosa = dot(RenderParam.cdir, RenderParam.sdir); double alpha = 0.5*acos(cosa); // sun reflection angle double scale = sin(alpha)*fac; col->r = (float)max(0.0, spec_base - scale*atmc->color0.x); diff --git a/OVP/D3D7Client/VBase.cpp b/OVP/D3D7Client/VBase.cpp index 089fc51ab..b953799bb 100644 --- a/OVP/D3D7Client/VBase.cpp +++ b/OVP/D3D7Client/VBase.cpp @@ -203,7 +203,7 @@ bool vBase::Update () if (simt > Tchk) { VECTOR3 pos, sdir; MATRIX3 rot; - oapiGetGlobalPos (hObj, &pos); normalise(pos); + oapiGetGlobalPos (hObj, &pos); pos = unit(pos); oapiGetRotationMatrix (hObj, &rot); sdir = tmul (rot, -pos); double csun = sdir.y; @@ -298,10 +298,10 @@ void vBase::RenderGroundShadow (LPDIRECT3DDEVICE7 dev) oapiGetGlobalPos (hPlanet, &pp); // planet global pos oapiGetGlobalPos (hObj, &sd); // base global pos pvr = sd-pp; // planet-relative base position - d = length (pvr); // planet radius at base location - normalise (sd); // shadow projection direction + d = len(pvr); // planet radius at base location + sd = unit(sd); // shadow projection direction - double fac1 = dotp (sd, pvr); + double fac1 = dot(sd, pvr); if (fac1 > 0.0) // base is on planet night-side return; csun = -fac1/d; // sun elevation above horizon @@ -311,11 +311,11 @@ void vBase::RenderGroundShadow (LPDIRECT3DDEVICE7 dev) MATRIX3 vR; oapiGetRotationMatrix (hObj, &vR); VECTOR3 sdv = tmul (vR, sd); // projection direction in base frame - VECTOR3 hnp = pvr; normalise(hnp); + VECTOR3 hnp = unit(pvr); VECTOR3 hn = tmul (vR, hnp); // horizon normal in vessel frame // perform projections - double nd = dotp (hn, sdv); + double nd = dot(hn, sdv); VECTOR3 sdvs = sdv / nd; if (!sdvs.y) return; // required for plane offset correction @@ -382,7 +382,7 @@ bool vBase::ModLighting (LPD3DLIGHT7 light, double &nextcheck) oapiGetGlobalPos (hS, &GS); // sun position oapiGetGlobalPos (hP, &GP); // planet position S = GS-GB; // sun's position from base - s = length(S); // sun's distance + s = len(S); // sun's distance rs = oapiGetSize (hS); as = asin (rs/s); // apparent radius of sun's disc [rad] double amb = 0; @@ -390,8 +390,8 @@ bool vBase::ModLighting (LPD3DLIGHT7 light, double &nextcheck) // Calculate shadowing by planet P = GP-GB; - p = length(P); - phi = acos (dotp(S,P)/(s*p)); // angular distance between sun and planet + p = len(P); + phi = std::acos(dot(S, P) / (s * p)); // angular distance between sun and planet static const double ap = PI05; // apparent size of planet disc [rad] const ATMCONST *atm = (oapiGetObjectType(hP)==OBJTP_PLANET ? oapiGetPlanetAtmConstants (hP) : NULL); diff --git a/OVP/D3D7Client/VObject.cpp b/OVP/D3D7Client/VObject.cpp index 71301b6de..dc5e48d73 100644 --- a/OVP/D3D7Client/VObject.cpp +++ b/OVP/D3D7Client/VObject.cpp @@ -138,13 +138,13 @@ void vObject::UpdateRenderVectors() double scale = size * *(float*)gc->GetConfigParam(CFGPRM_FRAMEAXISSCALE); double rad = size * 0.01; float alpha = *(float*)gc->GetConfigParam(CFGPRM_FRAMEAXISOPACITY); - AddVector(_V(scale, 0, 0), _V(0, 0, 0), rad, std::string("+x"), _V(1, 1, 1), alpha, D3DRGB(1, 1, 1)); - AddVector(_V(0, scale, 0), _V(0, 0, 0), rad, std::string("+y"), _V(1, 1, 1), alpha, D3DRGB(1, 1, 1)); - AddVector(_V(0, 0, scale), _V(0, 0, 0), rad, std::string("+z"), _V(1, 1, 1), alpha, D3DRGB(1, 1, 1)); + AddVector({scale, 0, 0}, {0, 0, 0}, rad, std::string("+x"), {1, 1, 1}, alpha, D3DRGB(1, 1, 1)); + AddVector({0, scale, 0}, {0, 0, 0}, rad, std::string("+y"), {1, 1, 1}, alpha, D3DRGB(1, 1, 1)); + AddVector({0, 0, scale}, {0, 0, 0}, rad, std::string("+z"), {1, 1, 1}, alpha, D3DRGB(1, 1, 1)); if (flag & FAV_NEGATIVE) { - AddVector(_V(-scale, 0, 0), _V(0, 0, 0), rad, std::string("-x"), _V(1, 1, 1), alpha, D3DRGB(1, 1, 1)); - AddVector(_V(0, -scale, 0), _V(0, 0, 0), rad, std::string("-y"), _V(1, 1, 1), alpha, D3DRGB(1, 1, 1)); - AddVector(_V(0, 0, -scale), _V(0, 0, 0), rad, std::string("-z"), _V(1, 1, 1), alpha, D3DRGB(1, 1, 1)); + AddVector({-scale, 0, 0}, {0, 0, 0}, rad, std::string("-x"), {1, 1, 1}, alpha, D3DRGB(1, 1, 1)); + AddVector({0, -scale, 0}, {0, 0, 0}, rad, std::string("-y"), {1, 1, 1}, alpha, D3DRGB(1, 1, 1)); + AddVector({0, 0, -scale}, {0, 0, 0}, rad, std::string("-z"), {1, 1, 1}, alpha, D3DRGB(1, 1, 1)); } } } @@ -167,7 +167,7 @@ void vObject::RenderSpot (LPDIRECT3DDEVICE7 dev, const VECTOR3 *ofs, float size, float sphi = (float)sin(phi), cphi = (float)cos(phi); const double ambient = 0.2; - double cosa = dotp (unit(gpos), unit(gpos - camp)); + double cosa = dot(unit(gpos), unit(gpos - camp)); double intens = (lighting ? 0.5 * ((1.0-ambient)*cosa + 1.0+ambient) : 1.0); W._11 = (float)bdir.x; @@ -330,7 +330,7 @@ bool vObject::DrawVector(LPDIRECT3DDEVICE7 dev, const VECTOR3& end, const VECTOR VECTOR3 gpos; oapiGetRotationMatrix(hObj, &grot); VECTOR3 cp = tmul(grot, -cpos); - if (dotp(d, unit(end - cp)) > 0) + if (dot(d, unit(end - cp)) > 0) Idx = Idx1, nIdx = nIdx1; else Idx = Idx0, nIdx = nIdx0; diff --git a/OVP/D3D7Client/VPlanet.cpp b/OVP/D3D7Client/VPlanet.cpp index 13df847e9..3321fa017 100644 --- a/OVP/D3D7Client/VPlanet.cpp +++ b/OVP/D3D7Client/VPlanet.cpp @@ -321,7 +321,7 @@ void vPlanet::CheckResolution () void vPlanet::RenderZRange (double *nplane, double *fplane) { - double d = dotp (*scn->GetCamera()->GetGDir(), cpos); + double d = dot(*scn->GetCamera()->GetGDir(), cpos); *fplane = max (1e3, d+rad*1.2); *nplane = max (1e0, d-rad*1.2); *fplane = min (*fplane, *nplane*1e5); @@ -411,7 +411,7 @@ bool vPlanet::Render (LPDIRECT3DDEVICE7 dev) // day/nighttime fog lighting VECTOR3 ppos; oapiGetGlobalPos (hObj, &ppos); - double cosa = dotp (unit(ppos), unit(cpos)); + double cosa = dot(unit(ppos), unit(cpos)); double bright = 1.0 * max (0.0, min (1.0, cosa + 0.3)); float rfog = (float)(bright*(min(1.0,fogcol.x)+0.0)); // "whiten" the fog colour float gfog = (float)(bright*(min(1.0,fogcol.y)+0.0)); @@ -738,7 +738,7 @@ bool vPlanet::ModLighting (DWORD &ambient) if (!prm.bAtm) return false; if (cdist >= size+prm.atm_href) return false; - double alpha = acos (dotp (unit(*scn->GetCamera()->GetGPos()), -unit(cpos))); + double alpha = std::acos(dot(unit(*scn->GetCamera()->GetGPos()), -unit(cpos))); // angular distance between sun and planet as seen from camera double sunelev = alpha - PI05; // elevation of sun above horizon (assuming camera on ground) diff --git a/OVP/D3D7Client/VVessel.cpp b/OVP/D3D7Client/VVessel.cpp index a39428973..988c6a32b 100644 --- a/OVP/D3D7Client/VVessel.cpp +++ b/OVP/D3D7Client/VVessel.cpp @@ -147,32 +147,32 @@ void vVessel::UpdateRenderVectors() if ((flag & BFV_WEIGHT) && vessel->GetWeightVector(F)) { sprintf(cbuf, "G = %fN", len = length(F)); if (logscale) len = log(len + shift) - lshift; else len *= scale; - AddVector(unit(F) * (len * pscale), _V(0, 0, 0), scale2, std::string(cbuf), _V(1, 1, 0), alpha, D3DRGB(1, 1, 0)); + AddVector(unit(F) * (len * pscale), {0, 0, 0}, scale2, std::string(cbuf), {1, 1, 0}, alpha, D3DRGB(1, 1, 0)); } if ((flag & BFV_THRUST) && vessel->GetThrustVector(F)) { sprintf(cbuf, "T = %fN", len = length(F)); if (logscale) len = log(len + shift) - lshift; else len *= scale; - AddVector(unit(F) * (len * pscale), _V(0, 0, 0), scale2, std::string(cbuf), _V(0, 0, 1), alpha, D3DRGB(0.5, 0.5, 1)); + AddVector(unit(F) * (len * pscale), {0, 0, 0}, scale2, std::string(cbuf), {0, 0, 1}, alpha, D3DRGB(0.5, 0.5, 1)); } if ((flag & BFV_LIFT) && vessel->GetLiftVector(F)) { sprintf(cbuf, "L = %fN", len = length(F)); if (logscale) len = log(len + shift) - lshift; else len *= scale; - AddVector(unit(F) * (len * pscale), _V(0, 0, 0), scale2, std::string(cbuf), _V(0, 1, 0), alpha, D3DRGB(0.5, 1, 0.5)); + AddVector(unit(F) * (len * pscale), {0, 0, 0}, scale2, std::string(cbuf), {0, 1, 0}, alpha, D3DRGB(0.5, 1, 0.5)); } if ((flag & BFV_DRAG) && vessel->GetDragVector(F)) { sprintf(cbuf, "D = %fN", len = length(F)); if (logscale) len = log(len + shift) - lshift; else len *= scale; - AddVector(unit(F) * (len * pscale), _V(0, 0, 0), scale2, std::string(cbuf), _V(1, 0, 0), alpha, D3DRGB(1, 0.5, 0.5)); + AddVector(unit(F) * (len * pscale), {0, 0, 0}, scale2, std::string(cbuf), {1, 0, 0}, alpha, D3DRGB(1, 0.5, 0.5)); } if ((flag & BFV_TOTAL) && vessel->GetForceVector(F)) { sprintf(cbuf, "F = %fN", len = length(F)); if (logscale) len = log(len + shift) - lshift; else len *= scale; - AddVector(unit(F) * (len * pscale), _V(0, 0, 0), scale2, std::string(cbuf), _V(1, 1, 1), alpha, D3DRGB(1, 1, 1)); + AddVector(unit(F) * (len * pscale), {0, 0, 0}, scale2, std::string(cbuf), {1, 1, 1}, alpha, D3DRGB(1, 1, 1)); } if ((flag & BFV_TORQUE) && vessel->GetTorqueVector(F)) { sprintf(cbuf, "M = %fNm", len = length(F)); if (logscale) len = log(len + 1e-5) - log(1e-5); else len *= scale * 1e5; - AddVector(unit(F) * (len * pscale), _V(0, 0, 0), scale2 * 0.5, std::string(cbuf), _V(1, 0, 1), alpha, D3DRGB(1, 0, 1)); + AddVector(unit(F) * (len * pscale), {0, 0, 0}, scale2 * 0.5, std::string(cbuf), {1, 0, 1}, alpha, D3DRGB(1, 0, 1)); } } } @@ -535,16 +535,16 @@ void vVessel::RenderGroundShadow (LPDIRECT3DDEVICE7 dev, OBJHANDLE hPlanet) alt = d-R; // altitude above surface if (alt*eps > vessel->GetSize()) // too high to cast a shadow return; - normalise (sd); // shadow projection direction + sd = unit(sd); // shadow projection direction // calculate the intersection of the vessel's shadow with the planet surface - double fac1 = dotp (sd, pvr); + double fac1 = dot(sd, pvr); if (fac1 > 0.0) // shadow doesn't intersect planet surface return; double csun = -fac1/d; // sun elevation above horizon if (csun < shadow_elev_limit) // sun too low to cast shadow return; - double arg = fac1*fac1 - (dotp (pvr, pvr) - R*R); + double arg = fac1 * fac1 - (dot(pvr, pvr) - R * R); if (arg <= 0.0) // shadow doesn't intersect with planet surface return; double a = -fac1 - sqrt(arg); @@ -557,8 +557,8 @@ void vVessel::RenderGroundShadow (LPDIRECT3DDEVICE7 dev, OBJHANDLE hPlanet) vessel->HorizonInvRot (hnp, hn); // perform projections - double nr0 = dotp (hn, shp); - double nd = dotp (hn, sdv); + double nr0 = dot(hn, shp); + double nd = dot(hn, sdv); VECTOR3 sdvs = sdv / nd; DWORD j; @@ -629,8 +629,8 @@ void vVessel::SetExhaustVertices (const VECTOR3 &edir, const VECTOR3 &cdir, cons { // need to rotate the billboard so it faces the observer const float flarescale = 7.0; - VECTOR3 sdir = crossp (cdir, edir); normalise (sdir); - VECTOR3 tdir = crossp (cdir, sdir); normalise (tdir); + VECTOR3 sdir = unit(cross(cdir, edir)); + VECTOR3 tdir = unit(cross(cdir, sdir)); D3DVALUE rx = (D3DVALUE)ref.x, ry = (D3DVALUE)ref.y, rz = (D3DVALUE)ref.z; D3DVALUE sx = (D3DVALUE)(sdir.x*wscale); D3DVALUE sy = (D3DVALUE)(sdir.y*wscale); @@ -684,7 +684,7 @@ bool vVessel::ModLighting (LPD3DLIGHT7 light) double p = length(P); if (p < s) { // shadow only if planet closer than sun double psize = oapiGetSize(hP); - double phi = acos (dotp(S,P)/(s*p)); // angular distance between sun and planet + double phi = std::acos(dot(S, P) / (s * p)); // angular distance between sun and planet double ap = (psize < p ? asin(psize / p) : PI05); // apparent size of planet disc [rad] const ATMCONST *atm = (oapiGetObjectType(hP)==OBJTP_PLANET ? oapiGetPlanetAtmConstants (hP) : NULL); diff --git a/OVP/D3D7Client/spherepatch.cpp b/OVP/D3D7Client/spherepatch.cpp index 405225779..ed77fad25 100644 --- a/OVP/D3D7Client/spherepatch.cpp +++ b/OVP/D3D7Client/spherepatch.cpp @@ -206,9 +206,9 @@ void CreateSpherePatch (const oapi::D3D7Client *gclient, VBMESH &mesh, int nlng, double clng0 = cos(minlng), slng0 = sin(minlng); double clat1 = cos(maxlat), slat1 = sin(maxlat); double clng1 = cos(maxlng), slng1 = sin(maxlng); - VECTOR3 ex = {clat0*clng1 - clat0*clng0, 0, clat0*slng1 - clat0*slng0}; normalise(ex); - VECTOR3 ey = {0.5*(clng0+clng1)*(clat1-clat0), slat1-slat0, 0.5*(slng0+slng1)*(clat1-clat0)}; normalise(ey); - VECTOR3 ez = crossp (ey, ex); + auto ex = unit(VECTOR3{clat0*clng1 - clat0*clng0, 0, clat0*slng1 - clat0*slng0}); + auto ey = unit(VECTOR3{0.5*(clng0+clng1)*(clat1-clat0), slat1-slat0, 0.5*(slng0+slng1)*(clat1-clat0)}); + auto ez = cross(ey, ex); MATRIX3 R = {ex.x, ex.y, ex.z, ey.x, ey.y, ey.z, ez.x, ez.y, ez.z}; VECTOR3 pref = {0.5*(clat0*clng1 + clat0*clng0), slat0, 0.5*(clat0*slng1 + clat0*slng0)}; // origin VECTOR3 tpmin, tpmax; @@ -226,7 +226,7 @@ void CreateSpherePatch (const oapi::D3D7Client *gclient, VBMESH &mesh, int nlng, for (j = 0; j <= nseg; j++) { lng = (nseg ? minlng + (maxlng-minlng) * (double)j/(double)nseg : 0.0); slng = sin(lng), clng = cos(lng); - pos = _V(clat*clng, slat, clat*slng); + pos = {clat*clng, slat, clat*slng}; tpos = mul (R, pos-pref); if (!n) { tpmin = tpos; @@ -312,21 +312,21 @@ void CreateSpherePatch (const oapi::D3D7Client *gclient, VBMESH &mesh, int nlng, } // transform bounding box back to patch coordinates - pos = tmul (R, _V(tpmin.x, tpmin.y, tpmin.z)) + pref; + pos = tmul (R, {tpmin.x, tpmin.y, tpmin.z}) + pref; V[0].x = D3DVAL(pos.x); V[0].y = D3DVAL(pos.y); V[0].z = D3DVAL(pos.z); - pos = tmul (R, _V(tpmax.x, tpmin.y, tpmin.z)) + pref; + pos = tmul (R, {tpmax.x, tpmin.y, tpmin.z}) + pref; V[1].x = D3DVAL(pos.x); V[1].y = D3DVAL(pos.y); V[1].z = D3DVAL(pos.z); - pos = tmul (R, _V(tpmin.x, tpmax.y, tpmin.z)) + pref; + pos = tmul (R, {tpmin.x, tpmax.y, tpmin.z}) + pref; V[2].x = D3DVAL(pos.x); V[2].y = D3DVAL(pos.y); V[2].z = D3DVAL(pos.z); - pos = tmul (R, _V(tpmax.x, tpmax.y, tpmin.z)) + pref; + pos = tmul (R, {tpmax.x, tpmax.y, tpmin.z}) + pref; V[3].x = D3DVAL(pos.x); V[3].y = D3DVAL(pos.y); V[3].z = D3DVAL(pos.z); - pos = tmul (R, _V(tpmin.x, tpmin.y, tpmax.z)) + pref; + pos = tmul (R, {tpmin.x, tpmin.y, tpmax.z}) + pref; V[4].x = D3DVAL(pos.x); V[4].y = D3DVAL(pos.y); V[4].z = D3DVAL(pos.z); - pos = tmul (R, _V(tpmax.x, tpmin.y, tpmax.z)) + pref; + pos = tmul (R, {tpmax.x, tpmin.y, tpmax.z}) + pref; V[5].x = D3DVAL(pos.x); V[5].y = D3DVAL(pos.y); V[5].z = D3DVAL(pos.z); - pos = tmul (R, _V(tpmin.x, tpmax.y, tpmax.z)) + pref; + pos = tmul (R, {tpmin.x, tpmax.y, tpmax.z}) + pref; V[6].x = D3DVAL(pos.x); V[6].y = D3DVAL(pos.y); V[6].z = D3DVAL(pos.z); - pos = tmul (R, _V(tpmax.x, tpmax.y, tpmax.z)) + pref; + pos = tmul (R, {tpmax.x, tpmax.y, tpmax.z}) + pref; V[7].x = D3DVAL(pos.x); V[7].y = D3DVAL(pos.y); V[7].z = D3DVAL(pos.z); mesh.bb->Unlock (); } diff --git a/OVP/D3D7Client/surfmgr2.cpp b/OVP/D3D7Client/surfmgr2.cpp index 4a29b7956..4f62311b1 100644 --- a/OVP/D3D7Client/surfmgr2.cpp +++ b/OVP/D3D7Client/surfmgr2.cpp @@ -476,7 +476,7 @@ void SurfTile::Render () bool has_shadows = false; bool has_lights = false; if (ltex || render_shadows) { - sdist = acos (dotp (mgr->prm.sdir, cnt)); + sdist = std::acos(dot(mgr->prm.sdir, cnt)); rad = rad0/(double)(2<pos; - if (dotp (renderlabel[i]->pos, camlabelpos) >= 0.0) { - double fontscale = 1e4/length(camlabelpos)*(13-min(tile->lvl,12)*1); + if (dot(renderlabel[i]->pos, camlabelpos) >= 0.0) { + double fontscale = 1e4 / len(camlabelpos) * (13 - min(tile->lvl, 12) * 1); int idx = max(0, min(3, (int)fontscale)); if (idx != *fontidx) { skp->SetFont(labelfont[idx]); diff --git a/OVP/D3D7Client/tilemgr2.cpp b/OVP/D3D7Client/tilemgr2.cpp index 20e2764f6..0451b6461 100644 --- a/OVP/D3D7Client/tilemgr2.cpp +++ b/OVP/D3D7Client/tilemgr2.cpp @@ -138,7 +138,7 @@ VECTOR3 Tile::Centre () const int nlng = 2 << lvl; double cntlat = PI05 - PI * ((double)ilat+0.5)/(double)nlat, slat = sin(cntlat), clat = cos(cntlat); double cntlng = PI2 * ((double)ilng+0.5)/(double)nlng + PI, slng = sin(cntlng), clng = cos(cntlng); - return _V(clat*clng, slat, clat*slng); + return {clat*clng, slat, clat*slng}; } @@ -190,9 +190,9 @@ VBMESH *Tile::CreateMesh_quadpatch (int grdlat, int grdlng, INT16 *elev, double double clng0 = cos(minlng), slng0 = sin(minlng); double clat1 = cos(maxlat), slat1 = sin(maxlat); double clng1 = cos(maxlng), slng1 = sin(maxlng); - VECTOR3 ex = {clat0*clng1 - clat0*clng0, 0, clat0*slng1 - clat0*slng0}; normalise (ex); - VECTOR3 ey = {0.5*(clng0+clng1)*(clat1-clat0), slat1-slat0, 0.5*(slng0+slng1)*(clat1-clat0)}; normalise (ey); - VECTOR3 ez = crossp (ey, ex); + auto ex = unit(VECTOR3{clat0*clng1 - clat0*clng0, 0, clat0*slng1 - clat0*slng0}); + auto ey = unit(VECTOR3{0.5*(clng0+clng1)*(clat1-clat0), slat1-slat0, 0.5*(slng0+slng1)*(clat1-clat0)}); + auto ez = cross(ey, ex); MATRIX3 R = {ex.x, ex.y, ex.z, ey.x, ey.y, ey.z, ez.x, ez.y, ez.z}; VECTOR3 pref = {radius*clat0*0.5*(clng1+clng0), radius*slat0, radius*clat0*0.5*(slng1+slng0)}; // origin VECTOR3 tpmin, tpmax; @@ -220,7 +220,7 @@ VBMESH *Tile::CreateMesh_quadpatch (int grdlat, int grdlng, INT16 *elev, double eradius = radius + globelev; // radius including node elevation if (elev) eradius += (double)elev[(i+1)*TILE_ELEVSTRIDE + j+1]*elev_scale; - nml = _V(clat*clng, slat, clat*slng); + nml = {clat*clng, slat, clat*slng}; pos = nml*eradius; tpos = mul (R, pos-pref); if (!n) { @@ -322,8 +322,7 @@ VBMESH *Tile::CreateMesh_quadpatch (int grdlat, int grdlng, INT16 *elev, double // This version avoids the normalisation of the 4 intermediate face normals // It's faster and doesn't seem to make much difference - VECTOR3 nml = {2.0*dydz, dz*elev_scale*(elev[en-TILE_ELEVSTRIDE]-elev[en+TILE_ELEVSTRIDE]), dy*elev_scale*(elev[en-1]-elev[en+1])}; - normalise (nml); + auto nml = unit(VECTOR3{2.0*dydz, dz*elev_scale*(elev[en-TILE_ELEVSTRIDE]-elev[en+TILE_ELEVSTRIDE]), dy*elev_scale*(elev[en-1]-elev[en+1])}); // rotate into place nx1 = nml.x*clat - nml.y*slat; ny1 = nml.x*slat + nml.y*clat; @@ -365,14 +364,14 @@ VBMESH *Tile::CreateMesh_quadpatch (int grdlat, int grdlng, INT16 *elev, double pref.x -= dx; pref.y -= dy; mesh->bbvtx = new VECTOR4[8]; - mesh->bbvtx[0] = _V(tmul (R, _V(tpmin.x, tpmin.y, tpmin.z)) + pref); - mesh->bbvtx[1] = _V(tmul (R, _V(tpmax.x, tpmin.y, tpmin.z)) + pref); - mesh->bbvtx[2] = _V(tmul (R, _V(tpmin.x, tpmax.y, tpmin.z)) + pref); - mesh->bbvtx[3] = _V(tmul (R, _V(tpmax.x, tpmax.y, tpmin.z)) + pref); - mesh->bbvtx[4] = _V(tmul (R, _V(tpmin.x, tpmin.y, tpmax.z)) + pref); - mesh->bbvtx[5] = _V(tmul (R, _V(tpmax.x, tpmin.y, tpmax.z)) + pref); - mesh->bbvtx[6] = _V(tmul (R, _V(tpmin.x, tpmax.y, tpmax.z)) + pref); - mesh->bbvtx[7] = _V(tmul (R, _V(tpmax.x, tpmax.y, tpmax.z)) + pref); + mesh->bbvtx[0] = _V(tmul (R, {tpmin.x, tpmin.y, tpmin.z}) + pref); + mesh->bbvtx[1] = _V(tmul (R, {tpmax.x, tpmin.y, tpmin.z}) + pref); + mesh->bbvtx[2] = _V(tmul (R, {tpmin.x, tpmax.y, tpmin.z}) + pref); + mesh->bbvtx[3] = _V(tmul (R, {tpmax.x, tpmax.y, tpmin.z}) + pref); + mesh->bbvtx[4] = _V(tmul (R, {tpmin.x, tpmin.y, tpmax.z}) + pref); + mesh->bbvtx[5] = _V(tmul (R, {tpmax.x, tpmin.y, tpmax.z}) + pref); + mesh->bbvtx[6] = _V(tmul (R, {tpmin.x, tpmax.y, tpmax.z}) + pref); + mesh->bbvtx[7] = _V(tmul (R, {tpmax.x, tpmax.y, tpmax.z}) + pref); mesh->MapVertices (TileManager2Base::d3d, TileManager2Base::dev, TileManager2Base::vbMemCaps); // TODO return mesh; @@ -417,7 +416,7 @@ VBMESH *Tile::CreateMesh_hemisphere (int grd, INT16 *elev, double globelev) slng = sin(lng), clng = cos(lng); eradius = radius + globelev; // radius including node elevation if (elev) eradius += (double)elev[(grd+1-y)*TILE_ELEVSTRIDE + x+1]; - nml = _V(slat*clng, clat, slat*slng); + nml = {slat*clng, clat, slat*slng}; pos = nml*eradius; vtx->x = D3DVAL(pos.x); vtx->nx = D3DVAL(nml.x); vtx->y = D3DVAL(pos.y); vtx->ny = D3DVAL(nml.y); @@ -450,7 +449,7 @@ VBMESH *Tile::CreateMesh_hemisphere (int grd, INT16 *elev, double globelev) for (x = 0; x < x2; x++) mn += (double)elev[TILE_ELEVSTRIDE*(grd+1) + x+1]; eradius += mn/x2; } - nml = _V(0,1,0); + nml = {0,1,0}; pos = nml*eradius; vtx->x = D3DVAL(pos.x); vtx->nx = D3DVAL(nml.x); vtx->y = D3DVAL(pos.y); vtx->ny = D3DVAL(nml.y); @@ -468,7 +467,7 @@ VBMESH *Tile::CreateMesh_hemisphere (int grd, INT16 *elev, double globelev) for (x = 0; x < x2; x++) mn += (double)elev[TILE_ELEVSTRIDE + x+1]; eradius += mn/x2; } - nml = _V(0,-1,0); + nml = {0,-1,0}; pos = nml*eradius; vtx->x = D3DVAL(pos.x); vtx->nx = D3DVAL(nml.x); vtx->y = D3DVAL(pos.y); vtx->ny = D3DVAL(nml.y); @@ -516,8 +515,7 @@ VBMESH *Tile::CreateMesh_hemisphere (int grd, INT16 *elev, double globelev) if (!ilng) lng -= PI; slng = sin(lng), clng = cos(lng); en = (grd+1-y)*TILE_ELEVSTRIDE + x+1; - VECTOR3 nml = {2.0*dydz, dz*(elev[en-TILE_ELEVSTRIDE]-elev[en+TILE_ELEVSTRIDE]), dy*(elev[en-1]-elev[en+1])}; - normalise(nml); + auto nml = unit(VECTOR3{2.0*dydz, dz*(elev[en-TILE_ELEVSTRIDE]-elev[en+TILE_ELEVSTRIDE]), dy*(elev[en-1]-elev[en+1])}); // rotate into place nx1 = nml.x*clat - nml.y*slat; ny1 = nml.x*slat + nml.y*clat; @@ -794,11 +792,10 @@ void TileManager2Base::SetRenderPrm (MATRIX4 &dwmat, double prerot, bool use_zbu prm.dwmat_tmp = prm.dwmat; prm.cpos = obj_pos-cam_pos; prm.cdir = tmul (prm.grot, -prm.cpos); // camera's direction in planet frame - double cdist = length(prm.cdir); + double cdist = len(prm.cdir); prm.cdist = cdist / obj_size; // camera's distance in units of planet radius - normalise (prm.cdir); - prm.sdir = tmul (prm.grot, -obj_pos); // sun's direction in planet frame - normalise (prm.sdir); + prm.cdir = unit(prm.cdir); + prm.sdir = unit(tmul (prm.grot, -obj_pos)); // sun's direction in planet frame prm.viewap = acos (1.0/(max (prm.cdist, 1.0+minalt))); prm.scale = 1.0; prm.fog = rprm.bFog; diff --git a/OVP/D3D7Client/tilemgr2_imp.hpp b/OVP/D3D7Client/tilemgr2_imp.hpp index 7f20d1213..aed1be6d3 100644 --- a/OVP/D3D7Client/tilemgr2_imp.hpp +++ b/OVP/D3D7Client/tilemgr2_imp.hpp @@ -94,7 +94,7 @@ void TileManager2Base::ProcessNode (QuadTreeNode *node) VECTOR3 &cnt = tile->cnt; // tile centre in unit planet frame static const double rad0 = sqrt(2.0)*PI05; double rad = rad0/(double)nlat; - double alpha = acos (dotp (prm.cdir, cnt)); // angle between tile centre and camera from planet centre + double alpha = std::acos(dot(prm.cdir, cnt)); // angle between tile centre and camera from planet centre double adist = alpha - rad; // angle between closest tile corner and camera if (adist >= prm.viewap) { if (lvl == 0) diff --git a/OVP/D3D9Client/AABBUtil.cpp b/OVP/D3D9Client/AABBUtil.cpp index e7531ad71..0dd2598ec 100644 --- a/OVP/D3D9Client/AABBUtil.cpp +++ b/OVP/D3D9Client/AABBUtil.cpp @@ -17,9 +17,8 @@ // ================================================================================================================================= #include "AABBUtil.h" -#include "OrbiterAPI.h" -#include "VectorHelpers.h" #include "Log.h" +#include "OrbiterAPI.h" #pragma warning(push) #pragma warning(disable : 4838) diff --git a/OVP/D3D9Client/AtmoControls.h b/OVP/D3D9Client/AtmoControls.h index 451d05403..35baa229f 100644 --- a/OVP/D3D9Client/AtmoControls.h +++ b/OVP/D3D9Client/AtmoControls.h @@ -10,6 +10,9 @@ #define ATM_SLIDER_COUNT 20 +#include "DrawAPI.h" + +using oapi::FVECTOR3; typedef struct ScatterParams { ScatterParams(); ///< Defaut c'tor diff --git a/OVP/D3D9Client/CMakeLists.txt b/OVP/D3D9Client/CMakeLists.txt index 8e89c0e60..447113722 100644 --- a/OVP/D3D9Client/CMakeLists.txt +++ b/OVP/D3D9Client/CMakeLists.txt @@ -108,7 +108,6 @@ set(IncludeFiles TileMgr.h Tilemgr2.h VBase.h - VectorHelpers.h VideoTab.h VObject.h VPlanet.h diff --git a/OVP/D3D9Client/CSphereMgr.cpp b/OVP/D3D9Client/CSphereMgr.cpp index 6f8769e8a..18e78cf38 100644 --- a/OVP/D3D9Client/CSphereMgr.cpp +++ b/OVP/D3D9Client/CSphereMgr.cpp @@ -426,7 +426,7 @@ void CSphereManager::Render (LPDIRECT3DDEVICE9 dev, int level, double bglvl) rcam = mul(ecl2gal, rcam); - RenderParam.camdir = _V(rcam.m13, rcam.m23, rcam.m33); + RenderParam.camdir = {rcam.m13, rcam.m23, rcam.m33}; WaitForSingleObject (tilebuf->hQueueMutex, INFINITE); @@ -434,7 +434,7 @@ void CSphereManager::Render (LPDIRECT3DDEVICE9 dev, int level, double bglvl) CelFlow.bBeta = m_bStarImg; CelData.fAlpha = intens; CelData.fBeta = bgscale; - CelData.mViewProj = *scn->GetProjectionViewMatrix(); + CelData.mViewProj = to_FMATRIX4(*scn->GetProjectionViewMatrix()); pShader->Setup(pPatchVertexDecl, false, 0); pShader->ClearTextures(); @@ -468,7 +468,7 @@ void CSphereManager::ProcessTile (int lvl, int hemisp, int ilat, int nlat, int i static const double rad0 = sqrt(2.0)*PI05; VECTOR3 cnt = TileCentre (hemisp, ilat, nlat, ilng, nlng); double rad = rad0/(double)nlat; - double alpha = acos (dotp (RenderParam.camdir, cnt)); + double alpha = std::acos(dot(RenderParam.camdir, cnt)); double adist = alpha - rad; if (adist > RenderParam.viewap) return; @@ -502,8 +502,8 @@ void CSphereManager::RenderTile (int lvl, int hemisp, int ilat, int nlat, int il VBMESH &mesh = PATCH_TPL[lvl][ilat]; // patch template D3D9Stats.Old.Tiles[lvl]++; - - CelData.mWorld = mWorld; + + CelData.mWorld = to_FMATRIX4(mWorld); pShader->SetTexture(hTexA, tex, IPF_CLAMP | IPF_ANISOTROPIC); pShader->SetTexture(hTexB, ltex, IPF_CLAMP | IPF_ANISOTROPIC); @@ -524,8 +524,8 @@ VECTOR3 CSphereManager::TileCentre (int hemisp, int ilat, int nlat, int ilng, in { double cntlat = PI05 * ((double)ilat+0.5)/(double)nlat, slat = sin(cntlat), clat = cos(cntlat); double cntlng = PI2 * ((double)ilng+0.5)/(double)nlng + PI, slng = sin(cntlng), clng = cos(cntlng); - if (hemisp) return _V(clat*clng, -slat, -clat*slng); - else return _V(clat*clng, slat, clat*slng); + if (hemisp) return {clat*clng, -slat, -clat*slng}; + else return {clat*clng, slat, clat*slng}; } // ======================================================================= diff --git a/OVP/D3D9Client/CelSphere.cpp b/OVP/D3D9Client/CelSphere.cpp index 805feb1c0..21c9c006b 100644 --- a/OVP/D3D9Client/CelSphere.cpp +++ b/OVP/D3D9Client/CelSphere.cpp @@ -332,11 +332,11 @@ void D3D9CelestialSphere::Render(LPDIRECT3DDEVICE9 pDevice, const VECTOR3& skyCo // render ecliptic grid if (renderFlag & PLN_EGRID) { FVECTOR4 baseCol1(0.0f, 0.2f, 0.3f, 1.0f); - D3DXVECTOR4 vColor1 = ColorAdjusted(baseCol1); + auto vColor1 = to_D3DXVECTOR4(ColorAdjusted(baseCol1)); HR(s_FX->SetVector(s_eColor, &vColor1)); RenderGrid(s_FX, false); FVECTOR4 baseCol2(0.0f, 0.4f, 0.6f, 1.0f); - D3DXVECTOR4 vColor2 = ColorAdjusted(baseCol2); + auto vColor2 = to_D3DXVECTOR4(ColorAdjusted(baseCol2)); HR(s_FX->SetVector(s_eColor, &vColor2)); RenderGreatCircle(s_FX); MATRIX3 ident = _M(1, 0, 0, 0, 1, 0, 0, 0, 1); @@ -355,11 +355,11 @@ void D3D9CelestialSphere::Render(LPDIRECT3DDEVICE9 pDevice, const VECTOR3& skyCo D3DXMatrixMultiply(&rot, &T, m_scene->GetProjectionViewMatrix()); HR(s_FX->SetMatrix(s_eWVP, &rot)); FVECTOR4 baseCol1(0.3f, 0.0f, 0.0f, 1.0f); - D3DXVECTOR4 vColor1 = ColorAdjusted(baseCol1); + auto vColor1 = to_D3DXVECTOR4(ColorAdjusted(baseCol1)); HR(s_FX->SetVector(s_eColor, &vColor1)); RenderGrid(s_FX, false); FVECTOR4 baseCol2(0.7f, 0.0f, 0.0f, 1.0f); - D3DXVECTOR4 vColor2 = ColorAdjusted(baseCol2); + auto vColor2 = to_D3DXVECTOR4(ColorAdjusted(baseCol2)); HR(s_FX->SetVector(s_eColor, &vColor2)); RenderGreatCircle(s_FX); double dphi = ElevationScaleRotation(R); @@ -374,11 +374,11 @@ void D3D9CelestialSphere::Render(LPDIRECT3DDEVICE9 pDevice, const VECTOR3& skyCo D3DXMatrixMultiply(&rot, &m_transformCelestial, m_scene->GetProjectionViewMatrix()); HR(s_FX->SetMatrix(s_eWVP, &rot)); FVECTOR4 baseCol1(0.3f, 0.0f, 0.3f, 1.0f); - D3DXVECTOR4 vColor1 = ColorAdjusted(baseCol1); + auto vColor1 = to_D3DXVECTOR4(ColorAdjusted(baseCol1)); HR(s_FX->SetVector(s_eColor, &vColor1)); RenderGrid(s_FX, false); FVECTOR4 baseCol2(0.7f, 0.0f, 0.7f, 1.0f); - D3DXVECTOR4 vColor2 = ColorAdjusted(baseCol2); + auto vColor2 = to_D3DXVECTOR4(ColorAdjusted(baseCol2)); HR(s_FX->SetVector(s_eColor, &vColor2)); RenderGreatCircle(s_FX); double dphi = ElevationScaleRotation(m_rotCelestial); @@ -393,11 +393,11 @@ void D3D9CelestialSphere::Render(LPDIRECT3DDEVICE9 pDevice, const VECTOR3& skyCo D3DXMatrixMultiply(&rot, &T, m_scene->GetProjectionViewMatrix()); HR(s_FX->SetMatrix(s_eWVP, &rot)); oapi::FVECTOR4 baseCol1(0.2f, 0.2f, 0.0f, 1.0f); - D3DXVECTOR4 vColor1 = ColorAdjusted(baseCol1); + auto vColor1 = to_D3DXVECTOR4(ColorAdjusted(baseCol1)); HR(s_FX->SetVector(s_eColor, &vColor1)); RenderGrid(s_FX, false); oapi::FVECTOR4 baseCol2(0.5f, 0.5f, 0.0f, 1.0f); - D3DXVECTOR4 vColor2 = ColorAdjusted(baseCol2); + auto vColor2 = to_D3DXVECTOR4(ColorAdjusted(baseCol2)); HR(s_FX->SetVector(s_eColor, &vColor2)); RenderGreatCircle(s_FX); double dphi = ElevationScaleRotation(R); @@ -421,7 +421,7 @@ void D3D9CelestialSphere::Render(LPDIRECT3DDEVICE9 pDevice, const VECTOR3& skyCo D3DXMatrixMultiply(&rot, &iR, m_scene->GetProjectionViewMatrix()); HR(s_FX->SetMatrix(s_eWVP, &rot)); FVECTOR4 baseCol(0.0f, 0.6f, 0.0f, 1.0f); - D3DXVECTOR4 vColor = ColorAdjusted(baseCol); + auto vColor = to_D3DXVECTOR4(ColorAdjusted(baseCol)); HR(s_FX->SetVector(s_eColor, &vColor)); RenderGreatCircle(s_FX); } @@ -497,7 +497,7 @@ void D3D9CelestialSphere::RenderStars(ID3DXEffect *FX) void D3D9CelestialSphere::RenderConstellationLines(ID3DXEffect *FX) { const FVECTOR4 baseCol(0.5f, 0.3f, 0.2f, 1.0f); - D3DXVECTOR4 vColor = ColorAdjusted(baseCol); + auto vColor = to_D3DXVECTOR4(ColorAdjusted(baseCol)); HR(s_FX->SetVector(s_eColor, &vColor)); _TRACE; @@ -516,7 +516,7 @@ void D3D9CelestialSphere::RenderConstellationLines(ID3DXEffect *FX) void D3D9CelestialSphere::RenderConstellationBoundaries(ID3DXEffect* FX) { const FVECTOR4 baseCol(0.25f, 0.2f, 0.15f, 1.0f); - D3DXVECTOR4 vColor = ColorAdjusted(baseCol); + auto vColor = to_D3DXVECTOR4(ColorAdjusted(baseCol)); HR(s_FX->SetVector(s_eColor, &vColor)); _TRACE; diff --git a/OVP/D3D9Client/CloudMgr.cpp b/OVP/D3D9Client/CloudMgr.cpp index dbe9d6dd6..3b1f4e8e3 100644 --- a/OVP/D3D9Client/CloudMgr.cpp +++ b/OVP/D3D9Client/CloudMgr.cpp @@ -33,7 +33,7 @@ CloudManager::CloudManager(D3D9Client *gclient, const vPlanet *vplanet) maxlvl = min (*(int*)gc->GetConfigParam (CFGPRM_SURFACEMAXLEVEL), // global setting *(int*)oapiGetObjectParam (obj, OBJPRM_PLANET_SURFACEMAXLEVEL)); // planet-specific setting maxbaselvl = min (8, maxlvl); - pcdir = _V(1,0,0); + pcdir = {1,0,0}; lightfac = *(double*)gc->GetConfigParam (CFGPRM_SURFACELIGHTBRT); nmask = 0; nhitex = nhispec = 0; diff --git a/OVP/D3D9Client/Cloudmgr2.cpp b/OVP/D3D9Client/Cloudmgr2.cpp index 43f313dac..686ff150d 100644 --- a/OVP/D3D9Client/Cloudmgr2.cpp +++ b/OVP/D3D9Client/Cloudmgr2.cpp @@ -112,7 +112,7 @@ void CloudTile::Render() sp->vMicroOff = GetTexRangeDX(µrange); sp->fAlpha = 1.0f; sp->fBeta = 1.0f; - sp->mWorld = mWorld; + sp->mWorld = to_FMATRIX4(mWorld); // ------------------------------------------------------------------- // render surface mesh diff --git a/OVP/D3D9Client/D3D9Client.cpp b/OVP/D3D9Client/D3D9Client.cpp index ddb836442..014bfca0d 100644 --- a/OVP/D3D9Client/D3D9Client.cpp +++ b/OVP/D3D9Client/D3D9Client.cpp @@ -1683,7 +1683,7 @@ LRESULT D3D9Client::RenderWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM l xpos = GET_X_LPARAM(lParam); ypos = GET_Y_LPARAM(lParam); - GetScene()->vPickRay = GetScene()->GetPickingRay(xpos, ypos); + GetScene()->vPickRay = to_FVECTOR3( GetScene()->GetPickingRay(xpos, ypos) ); TRACKMOUSEEVENT te; te.cbSize = sizeof(TRACKMOUSEEVENT); te.dwFlags = TME_LEAVE; te.hwndTrack = hRenderWnd; TrackMouseEvent(&te); @@ -1790,7 +1790,7 @@ LRESULT D3D9Client::RenderWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM l if (d>1) d=1; double speed = *(double *)GetConfigParam(CFGPRM_GETCAMERASPEED); speed *= (DebugControls::GetVisualSize()/100.0); - if (scene->CameraPan(_V(0,0,double(d))*2.0, speed)) return 0; + if (scene->CameraPan(VECTOR3{0, 0, double(d)} * 2.0, speed)) return 0; } PickTerrain(uMsg, xpos, ypos); @@ -1810,7 +1810,7 @@ LRESULT D3D9Client::RenderWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM l if (bTrackMouse) { double speed = *(double *)GetConfigParam(CFGPRM_GETCAMERASPEED); speed *= (DebugControls::GetVisualSize() / 100.0); - if (scene->CameraPan(_V(-x, y, 0)*0.05, speed)) return 0; + if (scene->CameraPan(VECTOR3{-x, y, 0} * 0.05, speed)) return 0; } } diff --git a/OVP/D3D9Client/D3D9Effect.cpp b/OVP/D3D9Client/D3D9Effect.cpp index 8c40c0f18..ef434d073 100644 --- a/OVP/D3D9Client/D3D9Effect.cpp +++ b/OVP/D3D9Client/D3D9Effect.cpp @@ -5,13 +5,13 @@ // Copyright (C) 2011 - 2016 Jarmo Nikkanen // =========================================================================================== +#include "D3D9Config.h" #include "D3D9Effect.h" -#include "Log.h" -#include "Scene.h" #include "D3D9Surface.h" -#include "D3D9Config.h" +#include "D3D9Util.h" +#include "Log.h" #include "Mesh.h" -#include "VectorHelpers.h" +#include "Scene.h" D3D9Client * D3D9Effect::gc = 0; ID3DXEffect * D3D9Effect::FX = 0; @@ -570,9 +570,9 @@ void D3D9Effect::UpdateEffectCamera(OBJHANDLE hPlanet) oapiGetRotationMatrix(hGRef, &grot); - VECTOR3 polaraxis = mul(grot, _V(0, 1, 0)); - VECTOR3 east = unit(crossp(polaraxis, cam)); - VECTOR3 north = unit(crossp(cam, east)); + VECTOR3 polaraxis = mul(grot, VECTOR3{0, 1, 0}); + VECTOR3 east = unit(cross(polaraxis, cam)); + VECTOR3 north = unit(cross(cam, east)); if (hVessel==NULL) { LogErr("hVessel = NULL in UpdateEffectCamera()"); @@ -606,7 +606,7 @@ void D3D9Effect::UpdateEffectCamera(OBJHANDLE hPlanet) FX->SetFloat(ePointScale, 0.5f*float(height)/tan(ap)); FX->SetFloat(eProxySize, cos(proxy_size)); FX->SetFloat(eInvProxySize, 1.0f/(1.0f-cos(proxy_size))); - FX->SetFloat(eGlowConst, saturate(float(dotp(cam, sun)))); + FX->SetFloat(eGlowConst, saturate(float(dot(cam, sun)))); } @@ -784,8 +784,8 @@ void D3D9Effect::RenderExhaust(const LPD3DXMATRIX pW, VECTOR3 &cdir, EXHAUSTSPEC VECTOR3 ref = (*es->lpos) - (*es->ldir)*es->lofs; const float flarescale = 7.0; - VECTOR3 sdir = crossp(cdir, edir); normalise(sdir); - VECTOR3 tdir = crossp(cdir, sdir); normalise(tdir); + VECTOR3 sdir = unit(cross(cdir, edir)); + VECTOR3 tdir = unit(cross(cdir, sdir)); float rx = (float)ref.x; float ry = (float)ref.y; float rz = (float)ref.z; @@ -988,7 +988,7 @@ void D3D9Effect::RenderArrow(OBJHANDLE hObj, const VECTOR3 *ofs, const VECTOR3 * VECTOR3 z = mul (grot, unit(*dir)) * size; VECTOR3 y = mul (grot, unit(*rot)) * size; - VECTOR3 x = mul (grot, unit(crossp(*dir, *rot))) * size; + VECTOR3 x = mul (grot, unit(cross(*dir, *rot))) * size; D3DXMatrixIdentity(&W); diff --git a/OVP/D3D9Client/D3D9Util.cpp b/OVP/D3D9Client/D3D9Util.cpp index 17f6f140b..1fff033d9 100644 --- a/OVP/D3D9Client/D3D9Util.cpp +++ b/OVP/D3D9Client/D3D9Util.cpp @@ -9,15 +9,15 @@ #define STRICT -#include "D3D9util.h" #include "AABBUtil.h" #include "D3D9Client.h" -#include "VectorHelpers.h" #include "D3D9Config.h" -#include "VPlanet.h" +#include "D3D9Util.h" #include "Mesh.h" -#include +#include "VPlanet.h" + #include +#include #include extern D3D9Client* g_client; @@ -231,7 +231,7 @@ void SurfaceLighting(D3D9Sun *light, OBJHANDLE hP, OBJHANDLE hO, float ao) float s = float(length(S)); // sun's distance float rs = float(oapiGetSize(hS)) / s; - float h = float(dotp(S,P)) / s; // sun elevation + float h = float(dot(S, P)) / s; // sun elevation float d = 0.173f; // sun elevation for dispersion float ae = 0.242f; // sun elevation for ambient float aq = 0.342f; @@ -262,9 +262,9 @@ void SurfaceLighting(D3D9Sun *light, OBJHANDLE hP, OBJHANDLE hO, float ao) lcol *= 1.0f-amb*0.5f; // reduce direct light component to avoid overexposure } - light->Color = D3DXCOLOR(lcol.x, lcol.y, lcol.z, 1.0f); - light->Ambient = D3DXCOLOR(amb, amb, amb, 1.0f); - light->Dir = D3DXVEC(S) * (-1.0f/s); + light->Color = to_FVECTOR3(lcol); + light->Ambient = FVECTOR3{amb, amb, amb}; + light->Dir = to_FVECTOR3(D3DXVEC(S) / -s); } // =========================================== // Remove unecessary spaces and tablations @@ -1375,7 +1375,7 @@ void D3D9Light::UpdateLight(const LightEmitter *_le, const class vObject *vo) // ----------------------------------------------------------------------------- if (Type != 0) { D3DXVec3TransformNormal(&Direction, ptr(D3DXVEC(le->GetDirection())), vo->MWorld()); - float angle = acos(dot(unit(Position), Direction)); + float angle = acos(dot(unit(to_FVECTOR3(Position)), to_FVECTOR3(Direction))); cone = ilerp(U * 0.5f, P * 0.5f, angle); } } diff --git a/OVP/D3D9Client/D3D9Util.h b/OVP/D3D9Client/D3D9Util.h index 0498cae89..b2c98432a 100644 --- a/OVP/D3D9Client/D3D9Util.h +++ b/OVP/D3D9Client/D3D9Util.h @@ -8,19 +8,37 @@ #ifndef __D3DUTIL_H #define __D3DUTIL_H -#include "OrbiterAPI.h" -#include "Log.h" #include "DrawAPI.h" +#include "gcCore.h" +#include "Log.h" +#include "OrbiterAPI.h" + #include #include #include -#include "gcCore.h" #define float2 FVECTOR2 #define float3 FVECTOR3 #define float4 FVECTOR4 #define float4x4 FMATRIX4 +template +constexpr auto sign(const T& x) { return x < T{0} ? T{-1} : T{1}; } + +template +constexpr auto ilerp(const T& a, const T& b, const T& x) +{ + auto v = (x - a) / (b - a); + return v > T{1} ? T{1} : v < T{0} ? T{0} : v; +} + +template +constexpr auto hermite(const T& x) { return x * x * (T{3} - T{2} * x); } + +// enable vector operators for D3DXVECTOR3 and D3DXVECTOR4 +template<> struct is_vector3 : std::true_type { }; +template<> struct is_vector4 : std::true_type { }; + #ifdef _DEBUG #ifndef _TRACE #define _TRACE { LogTrace("[TRACE] %s Line:%d %s",__FILE__,__LINE__,__FUNCTION__); } @@ -449,9 +467,9 @@ inline RECT _RECT(DWORD l, DWORD t, DWORD r, DWORD b) return rect; } -inline VECTOR3 _V(D3DXVECTOR3 &i) +inline auto _V(D3DXVECTOR3 &i) { - return _V(double(i.x), double(i.y), double(i.z)); + return VECTOR3{double(i.x), double(i.y), double(i.z)}; } inline oapi::FVECTOR3 _FV(D3DXVECTOR3 &i) @@ -459,9 +477,9 @@ inline oapi::FVECTOR3 _FV(D3DXVECTOR3 &i) return oapi::FVECTOR3(i.x, i.y, i.z); } -inline VECTOR3 _V(D3DXVECTOR4 &i) +inline auto _V(D3DXVECTOR4 &i) { - return _V(double(i.x), double(i.y), double(i.z)); + return VECTOR3{double(i.x), double(i.y), double(i.z)}; } inline void D3DXCOLORSWAP(D3DXCOLOR *x) @@ -545,9 +563,9 @@ inline D3DXCOLOR _D3DXCOLOR(const VECTOR3 &v, float a = 1.0f) return D3DXCOLOR(float(v.x), float(v.y), float(v.z), a); } -inline VECTOR3 _VD3DX(const D3DXVECTOR3 &v) +inline auto _VD3DX(const D3DXVECTOR3 &v) { - return _V(double(v.x), double(v.y), double(v.z)); + return VECTOR3{double(v.x), double(v.y), double(v.z)}; } inline VECTOR4 _VD4DX(const D3DXVECTOR4 &v) @@ -560,6 +578,31 @@ inline float D3DVAL (double x) return (float)x; } +inline auto to_FVECTOR3(const D3DXVECTOR3 &v) { return FVECTOR3{v.x, v.y, v.z}; } +inline auto to_FVECTOR4(const D3DXVECTOR4 &v) { return FVECTOR4{v.x, v.y, v.z, v.w}; } + +inline auto to_D3DXVECTOR3(const FVECTOR3 &v) { return D3DXVECTOR3{v.x, v.y, v.z}; } +inline auto to_D3DXVECTOR4(const FVECTOR4 &v) { return D3DXVECTOR4{v.x, v.y, v.z, v.w}; } + +inline auto to_D3DXVECTOR3(const VECTOR3 &v) +{ + return D3DXVECTOR3{static_cast(v.x), static_cast(v.y), static_cast(v.z)}; +} + +inline auto to_FMATRIX4(const D3DXMATRIX &m) +{ + return FMATRIX4{ + m(0,0), m(0,1), m(0,2), m(0,3), + m(1,0), m(1,1), m(1,2), m(1,3), + m(2,0), m(2,1), m(2,2), m(2,3), + m(3,0), m(3,1), m(3,2), m(3,3), + }; +} + +inline auto to_D3DXCOLOR(const FVECTOR3 &v) { return D3DXCOLOR{v.x, v.y, v.z, 1}; } + +inline auto to_FVECTOR4(const D3DXCOLOR &c) { return FVECTOR4{c.r, c.g, c.b, c.a}; } + //char* _fgets(char* cbuf, int num, FILE* stream, bool keepOneSpace = false); int fgets2(char *buf, int cmax, FILE *file, DWORD param=0); diff --git a/OVP/D3D9Client/DebugControls.cpp b/OVP/D3D9Client/DebugControls.cpp index b487ddd38..b7c0a6569 100644 --- a/OVP/D3D9Client/DebugControls.cpp +++ b/OVP/D3D9Client/DebugControls.cpp @@ -6,17 +6,17 @@ #include "D3D9Client.h" -#include "resource.h" #include "D3D9Config.h" #include "D3D9Surface.h" #include "DebugControls.h" -#include "Commctrl.h" -#include "vObject.h" -#include "vVessel.h" -#include "vPlanet.h" -#include "Mesh.h" #include "MaterialMgr.h" -#include "VectorHelpers.h" +#include "Mesh.h" +#include "resource.h" +#include "VObject.h" +#include "VPlanet.h" +#include "VVessel.h" + +#include #include enum scale { LIN, SQRT, SQR }; diff --git a/OVP/D3D9Client/HazeMgr.cpp b/OVP/D3D9Client/HazeMgr.cpp index 2ea8594ac..63e78eaa2 100644 --- a/OVP/D3D9Client/HazeMgr.cpp +++ b/OVP/D3D9Client/HazeMgr.cpp @@ -13,13 +13,12 @@ // Implemented as transparent overlay on planetary disc // ============================================================================ -#include "HazeMgr.h" -#include "VPlanet.h" +#include "D3D9Config.h" +#include "D3D9Effect.h" #include "D3D9Surface.h" #include "D3D9Util.h" -#include "VectorHelpers.h" -#include "D3D9Effect.h" -#include "D3D9Config.h" +#include "HazeMgr.h" +#include "VPlanet.h" using namespace oapi; @@ -34,7 +33,7 @@ HazeManager::HazeManager (const D3D9Client *gclient, const vPlanet *vplanet) : D hralt = (float)(atmc->horizonalt / rad); dens0 = (float)(min (1.0, atmc->horizonalt/64e3 * *(double*)oapiGetObjectParam(obj, OBJPRM_PLANET_HAZEDENSITY))); } else { - basecol = _V(1,1,1); + basecol = {1,1,1}; hralt = 0.01f; dens0 = 1.0f; } @@ -119,7 +118,7 @@ void HazeManager::Render(LPDIRECT3DDEVICE9 pDev, D3DXMATRIX &wmat, bool dual) float dens = (float)max (1.0, 1.4 - 0.3/hralt*(cdist-1.0)); // saturate haze colour at low altitudes if (dual) dens *= (float)(0.5 + 0.5/cdist); // scale down intensity at large distances - normalise (rpos); + rpos = unit(rpos); cost = (float)rpos.y, sint = (float)sqrt (1.0-cost*cost); phi = atan2 (rpos.z, rpos.x), cosp = (float)cos(phi), sinp = (float)sin(phi); @@ -139,17 +138,17 @@ void HazeManager::Render(LPDIRECT3DDEVICE9 pDev, D3DXMATRIX &wmat, bool dual) oapiGetGlobalPos (obj, &gpos); psun = tmul (grot, -gpos); // sun in planet coords psun = mul (rrmat, psun); // sun in camera-relative horizon coords - VECTOR3 cs = psun-cpos; normalise(cs); // camera->sun - normalise (psun); + VECTOR3 cs = unit(psun - cpos); // camera->sun + psun = unit(psun); // float psunx = (float)psun.x, psuny = (float)psun.y, psunz = (float)psun.z; colofs = (dual ? 0.4 : 0.3); for (i = j = 0; i < HORIZON_NSEG; i++) { VECTOR3 hp = {Vtx[j].x = r1*CosP[i], Vtx[j].y = h1, Vtx[j].z = r1*SinP[i]}; - csun = dotp (hp, psun); - VECTOR3 cp = hp-cpos; normalise(cp); - double colsh = 0.5*(dotp (cp,cs) + 1.0); + csun = dot(hp, psun); + VECTOR3 cp = unit(hp - cpos); + double colsh = 0.5 * (dot(cp, cs) + 1.0); // compose a colourful sunset double maxred = colofs-0.18*colsh, minred = maxred-0.4; @@ -308,20 +307,20 @@ void HazeManager2::RenderSky(VECTOR3 cpos, VECTOR3 cdir, double rad, double apr) double al = asin(rad/cr); VECTOR3 ur = unit(cpos); - VECTOR3 ux = unit(crossp(cdir, ur)); - VECTOR3 uy = unit(crossp(ur, ux)); + VECTOR3 ux = unit(cross(cdir, ur)); + VECTOR3 uy = unit(cross(ur, ux)); D3DXMATRIX mWL, mL; D3DMAT_Identity(&mWL); - D3DMAT_FromAxisT(&mWL, ptr(_D3DXVECTOR3(ux)), ptr(_D3DXVECTOR3(ur)), ptr(_D3DXVECTOR3(uy))); + D3DMAT_FromAxisT(&mWL, ptr(to_D3DXVECTOR3(ux)), ptr(to_D3DXVECTOR3(ur)), ptr(to_D3DXVECTOR3(uy))); double a = 15.0*RAD; double b = (PI-asin(rad/cr))/6.0; - D3DXVECTOR3 vTileCenter = D3DXVECTOR3(float(sin(15.0*RAD)), 1.0f, float(1.0+cos(15.0*RAD))) * 0.5; - D3DXMatrixRotationAxis(&mL, ptr(_D3DXVECTOR3(ur)), float(-a*0.5)); + auto vTileCenter = D3DXVECTOR3(float(std::sin(15.0 * RAD)), 1, float(1 + std::cos(15.0 * RAD))) * 0.5f; + D3DXMatrixRotationAxis(&mL, ptr(to_D3DXVECTOR3(ur)), float(-a*0.5)); D3DXMatrixMultiply(&mWL, &mWL, &mL); - D3DXMatrixRotationAxis(&mL, ptr(_D3DXVECTOR3(ur)), float(-a)); + D3DXMatrixRotationAxis(&mL, ptr(to_D3DXVECTOR3(ur)), float(-a)); //vp->GetScatterConst()->mVP = vp->GetScene()->PushCameraFrustumLimits(hd * 0.1, hd * 5.0); @@ -401,12 +400,12 @@ void HazeManager2::RenderRing(VECTOR3 cpos, VECTOR3 cdir, double rad, double hra vp->GetScatterConst()->mVP = vp->GetScene()->PushCameraFrustumLimits(hd * 0.1, hd * 5.0); VECTOR3 ur = unit(cpos); - VECTOR3 ux = unit(crossp(cdir, ur)); - VECTOR3 uy = unit(crossp(ur, ux)); + VECTOR3 ux = unit(cross(cdir, ur)); + VECTOR3 uy = unit(cross(ur, ux)); D3DXMATRIX mW; D3DMAT_Identity(&mW); - D3DMAT_FromAxisT(&mW, ptr(_D3DXVECTOR3(ux)), ptr(_D3DXVECTOR3(ur)), ptr(_D3DXVECTOR3(uy))); + D3DMAT_FromAxisT(&mW, ptr(to_D3DXVECTOR3(ux)), ptr(to_D3DXVECTOR3(ur)), ptr(to_D3DXVECTOR3(uy))); ShaderParams sprm; memcpy_s(&sprm.mWorld, sizeof(sprm.mWorld), &mW, sizeof(mW)); diff --git a/OVP/D3D9Client/Mesh.cpp b/OVP/D3D9Client/Mesh.cpp index bf72285ea..86ebfbcf9 100644 --- a/OVP/D3D9Client/Mesh.cpp +++ b/OVP/D3D9Client/Mesh.cpp @@ -8,14 +8,14 @@ #define VISIBILITY_TOL 0.0015f -#include "Mesh.h" -#include "Log.h" -#include "Scene.h" -#include "D3D9Surface.h" #include "D3D9Catalog.h" #include "D3D9Config.h" +#include "D3D9Surface.h" +#include "D3D9Util.h" #include "DebugControls.h" -#include "VectorHelpers.h" +#include "Log.h" +#include "Mesh.h" +#include "Scene.h" #pragma warning(push) #pragma warning(disable : 4838) @@ -2716,11 +2716,11 @@ void D3D9Mesh::RenderShadowMap(const LPD3DXMATRIX pW, const LPD3DXMATRIX pVP, in D3DXMATRIX GroupMatrix, mWorldMesh; MeshShader* pShader = nullptr; - - MeshShader::vs_const.mVP = *pVP; - D3DXMatrixIdentity(MeshShader::vs_const.mW); - + MeshShader::vs_const.mVP = to_FMATRIX4(*pVP); + + D3DXMatrixIdentity((D3DXMATRIX*)&MeshShader::vs_const.mW); + if (bGlobalTF) D3DXMatrixMultiply(&mWorldMesh, &mTransform, pW); else mWorldMesh = *pW; @@ -2768,11 +2768,11 @@ void D3D9Mesh::RenderShadowMap(const LPD3DXMATRIX pW, const LPD3DXMATRIX pVP, in } if (Grp[g].bTransform) { - D3DXMatrixMultiply(MeshShader::vs_const.mW, &pGrpTF[g], pW); // Apply Animations to instance matrices + D3DXMatrixMultiply((D3DXMATRIX*)&MeshShader::vs_const.mW, &pGrpTF[g], pW); // Apply Animations to instance matrices bInit = true; } else { - if (bInit) MeshShader::vs_const.mW = mWorldMesh; + if (bInit) MeshShader::vs_const.mW = to_FMATRIX4(mWorldMesh); bInit = false; } diff --git a/OVP/D3D9Client/Particle.cpp b/OVP/D3D9Client/Particle.cpp index 6bc93d18a..29509b962 100644 --- a/OVP/D3D9Client/Particle.cpp +++ b/OVP/D3D9Client/Particle.cpp @@ -54,7 +54,7 @@ D3D9ParticleStream::D3D9ParticleStream(GraphicsClient *_gc, PARTICLESTREAMSPEC * //cam_ref = &gc->GetScene()->GetCameraGPos(); //src_ref = 0; - //src_ofs = _V(0,0,0); + //src_ofs = {0,0,0}; interval = 0.1; SetSpecs (pss ? pss : &DefaultParticleStreamSpec); @@ -622,8 +622,8 @@ void ExhaustStream::Update () ((double)rand()/(double)RAND_MAX-0.5)*dv_scale}; dv += vv; - normalise(s); - VECTOR3 vv2 = dv - s*dotp(s,dv); + s = unit(s); + VECTOR3 vv2 = dv - s * dot(s, dv); if (length(vv2)) vv2 *= 0.5*length(vv)/length(vv2); vv2 += s*(((double)rand()/(double)RAND_MAX)*dv_scale); p->vel = vv2*1.0/*2.0*/+av; @@ -704,9 +704,9 @@ void ExhaustStream::RenderGroundShadow (LPDIRECT3DDEVICE9 dev, LPDIRECT3DTEXTURE sd = unit(p->pos); // shadow projection direction VECTOR3 pv0 = p->pos - pp; // rel. particle position // calculate the intersection of the vessel's shadow with the planet surface - double fac1 = dotp (sd, pv0); + double fac1 = dot(sd, pv0); if (fac1 > 0.0) return; // shadow doesn't intersect planet surface - double arg = fac1*fac1 - (dotp (pv0, pv0) - R*R); + double arg = fac1 * fac1 - (dot(pv0, pv0) - R * R); if (arg <= 0.0) return; // shadow doesn't intersect with planet surface double a = -fac1 - sqrt(arg); VECTOR3 shp = sd*a; // projection point in global frame @@ -730,9 +730,9 @@ void ExhaustStream::RenderGroundShadow (LPDIRECT3DDEVICE9 dev, LPDIRECT3DTEXTURE VECTOR3 pvr = p->pos - pp; // rel. particle position // calculate the intersection of the vessel's shadow with the planet surface - double fac1 = dotp (sd, pvr); + double fac1 = dot(sd, pvr); if (fac1 > 0.0) break; // shadow doesn't intersect planet surface - double arg = fac1*fac1 - (dotp (pvr, pvr) - R*R); + double arg = fac1 * fac1 - (dot(pvr, pvr) - R * R); if (arg <= 0.0) break; // shadow doesn't intersect with planet surface double a = -fac1 - sqrt(arg); @@ -767,7 +767,7 @@ ReentryStream::ReentryStream (oapi::GraphicsClient *_gc, OBJHANDLE hV, PARTICLES : D3D9ParticleStream (_gc, pss) { llevel = 1.0; - Attach (hV, _V(0,0,0), _V(0,0,0), &llevel); + Attach (hV, {0,0,0}, {0,0,0}, &llevel); hPlanet = 0; } diff --git a/OVP/D3D9Client/RingMgr.cpp b/OVP/D3D9Client/RingMgr.cpp index 6aeec6cd6..19974c159 100644 --- a/OVP/D3D9Client/RingMgr.cpp +++ b/OVP/D3D9Client/RingMgr.cpp @@ -99,9 +99,9 @@ bool RingManager::Render(LPDIRECT3DDEVICE9 dev, D3DXMATRIX &mWorld, bool front) VECTOR3 gdir; oapiCameraGlobalDir(&gdir); - VECTOR3 yaxis = mul(grot, _V(0,1,0)); - VECTOR3 xaxis = unit(crossp(gdir, yaxis)); - VECTOR3 zaxis = unit(crossp(xaxis, yaxis)); + VECTOR3 yaxis = mul(grot, VECTOR3{0, 1, 0}); + VECTOR3 xaxis = unit(cross(gdir, yaxis)); + VECTOR3 zaxis = unit(cross(xaxis, yaxis)); if (!front) { xaxis = -xaxis; diff --git a/OVP/D3D9Client/RunwayLights.cpp b/OVP/D3D9Client/RunwayLights.cpp index 7689b2f1f..2f1aa8700 100644 --- a/OVP/D3D9Client/RunwayLights.cpp +++ b/OVP/D3D9Client/RunwayLights.cpp @@ -23,8 +23,8 @@ RunwayLights::RunwayLights(class vBase *_vB, const class Scene *scn) { vB = _vB; scene = scn; - end1 = _V(0, 0, 0); - end2 = _V(0, 0, 0); + end1 = {0, 0, 0}; + end2 = {0, 0, 0}; width = 50.0; td_disp = 0.0; td_disp2 = 0.0; @@ -39,13 +39,13 @@ RunwayLights::RunwayLights(class vBase *_vB, const class Scene *scn) bDisp2 = false; for (int i=0; i<12; ++i) { - PAPI_pos[i] = _V(0,0,0); + PAPI_pos[i] = {0,0,0}; PAPI_disp[i] = 0.0; PAPI_end[i] = 0; papi[i] = NULL; } for (int i=0; i<2; ++i) { - VASI[i] = _V(0,0,0); + VASI[i] = {0,0,0}; VASI_end[i] = 0; vasi[i] = NULL; } @@ -199,7 +199,7 @@ BeaconArray *RunwayLights::BuildLights(VECTOR3 _start, VECTOR3 _end, double disp VECTOR3 _space; // Vector between each light VECTOR3 _current; // Incremented in the for loop VECTOR3 _shift; - VECTOR3 _widthDir = unit(crossp(_dir, _V(0, 1, 0))); // used to calculate the edge lights + VECTOR3 _widthDir = unit(cross(_dir, VECTOR3{0, 1, 0})); // used to calculate the edge lights BeaconArrayEntry* beaconsEntry1 = new BeaconArrayEntry[numLights]; @@ -218,9 +218,9 @@ BeaconArray *RunwayLights::BuildLights(VECTOR3 _start, VECTOR3 _end, double disp centerLight.loff = 1.0f; centerLight.bright = 1.5f * brightness; centerLight.fall = 0.5; - centerLight.pos = _V(0,0,0); + centerLight.pos = {0,0,0}; centerLight.color = 0; - centerLight.dir = _dir*cos(upAngle*RAD) + _V(0, 1, 0)*sin(upAngle*RAD); + centerLight.dir = _dir * std::cos(upAngle * RAD) + VECTOR3{0, 1, 0} * std::sin(upAngle * RAD); endLight = centerLight; edgeLight = centerLight; @@ -510,7 +510,7 @@ BeaconArray *RunwayLights::BuildLights(VECTOR3 _start, VECTOR3 _end, double disp OBJHANDLE hPlanet = oapiGetBasePlanet(hObj); // double size = oapiGetSize(hPlanet); - for (int k=0;kRwyBrightness); papiLight.fall = 0.5; - papiLight.pos = _V(0,0,0); + papiLight.pos = {0,0,0}; papiLight.color = 0; - papiLight.dir = dir*cos(upAngle*RAD) + _V(0, 1, 0)*sin(upAngle*RAD); + papiLight.dir = dir * std::cos(upAngle * RAD) + VECTOR3{0, 1, 0} * std::sin(upAngle * RAD); BeaconArrayEntry entryPAPI[4]; for(int j=0; j<4; j++) { entryPAPI[j] = papiLight; - entryPAPI[j].dir = _V(-entryPAPI[j].dir.x, entryPAPI[j].dir.y, -entryPAPI[j].dir.z); + entryPAPI[j].dir = {-entryPAPI[j].dir.x, entryPAPI[j].dir.y, -entryPAPI[j].dir.z}; entryPAPI[j].pos = start + dir*PAPI_pos[i].z + widthDir*disp + widthDir*j*papi_separation - widthDir*papi_separation*1.5; } @@ -569,8 +569,7 @@ BeaconArray *RunwayLights::BuildVASI(VECTOR3 _start, VECTOR3 _end, DWORD idx) // Helping vectors VECTOR3 _direction = _end - _start; // Vector of the runway - VECTOR3 _dir = _direction; // Normalized direction - normalise(_dir); + VECTOR3 _dir = unit(_direction); // Normalized direction VECTOR3 _td_disp = _dir * td_disp; // Touch zone displacement vector _start += _td_disp; @@ -583,8 +582,7 @@ BeaconArray *RunwayLights::BuildVASI(VECTOR3 _start, VECTOR3 _end, DWORD idx) // Main lights vectors VECTOR3 _current; // Incremented in the for loop - VECTOR3 _widthDir = crossp(_direction, _V(0, 1, 0)); // used to calculate the edge lights - normalise(_widthDir); + VECTOR3 _widthDir = unit(cross(_direction, VECTOR3{0, 1, 0})); // used to calculate the edge lights BeaconArrayEntry* beaconsEntry1 = new BeaconArrayEntry[30]; @@ -601,9 +599,9 @@ BeaconArray *RunwayLights::BuildVASI(VECTOR3 _start, VECTOR3 _end, DWORD idx) vasiLight.loff = 1.0f; vasiLight.bright = 3.0f * float(Config->RwyBrightness); vasiLight.fall = 0.1f; - vasiLight.pos = _V(0,0,0); + vasiLight.pos = {0,0,0}; vasiLight.color = 0; - vasiLight.dir = _dir*cos(upAngle*RAD) + _V(0, 1, 0)*sin(upAngle*RAD); + vasiLight.dir = _dir * std::cos(upAngle * RAD) + VECTOR3{0, 1, 0} * std::sin(upAngle * RAD); _current = _start + _dir * VASI[e].z + _widthDir * (width/2.0 + 30.0); _current.y = 0; @@ -612,7 +610,7 @@ BeaconArray *RunwayLights::BuildVASI(VECTOR3 _start, VECTOR3 _end, DWORD idx) beaconsEntry1[i] = vasiLight; beaconsEntry1[i].color = red; beaconsEntry1[i].size = 1.0f * lightSize; - beaconsEntry1[i].pos = _current + _widthDir * 2.0 * float(k) + _V(0,1,0); + beaconsEntry1[i].pos = _current + _widthDir * 2.0 * float(k) + VECTOR3{0, 1, 0}; } _current -= _dir * VASI[e].y; @@ -620,7 +618,7 @@ BeaconArray *RunwayLights::BuildVASI(VECTOR3 _start, VECTOR3 _end, DWORD idx) for (k=0;k<5;k++, i++) { beaconsEntry1[i] = vasiLight; beaconsEntry1[i].color = white; - beaconsEntry1[i].pos = _current + _widthDir * 2.0 * float(k) + _V(0,1,0) + _V(0,1,0)*(sin(VASI[e].x*RAD)*VASI[e].y); + beaconsEntry1[i].pos = _current + _widthDir * 2.0 * float(k) + VECTOR3{0, 1, 0} + VECTOR3{0, 1, 0} * (std::sin(VASI[e].x * RAD) * VASI[e].y); } // Post process lights ------------------------------------------ @@ -629,7 +627,7 @@ BeaconArray *RunwayLights::BuildVASI(VECTOR3 _start, VECTOR3 _end, DWORD idx) double size = oapiGetSize(hPlanet); for (int k=0;k #include @@ -727,13 +727,13 @@ VECTOR3 Scene::SkyColour () if (cdist < atmp->radlimit) { ATMPARAM prm; oapiGetPlanetAtmParams (hProxy, cdist, &prm); - normalise (rp); - double coss = dotp (pc, rp) / -cdist; + rp = unit(rp); + double coss = dot(pc, rp) / -cdist; double intens = min (1.0,(1.0839*coss+0.4581)) * sqrt (prm.rho/atmp->rho0); // => intensity=0 at sun zenith distance 115? // intensity=1 at sun zenith distance 60? if (intens > 0.0) - col += _V(atmp->color0.x*intens, atmp->color0.y*intens, atmp->color0.z*intens); + col += {atmp->color0.x*intens, atmp->color0.y*intens, atmp->color0.z*intens}; } for (int i=0;i<3;i++) if (col.data[i] > 1.0) col.data[i] = 1.0; } @@ -878,10 +878,10 @@ void Scene::GetLVLH(vVessel *vV, D3DXVECTOR3 *up, D3DXVECTOR3 *nr, D3DXVECTOR3 * OBJHANDLE hRef = hV->GetGravityRef(); oapiGetRotationMatrix(hRef, &grot); hV->GetRelativePos(hRef, rpos); - VECTOR3 axis = mul(grot, _V(0, 1, 0)); - normalise(rpos); + VECTOR3 axis = mul(grot, VECTOR3{0, 1, 0}); + rpos = unit(rpos); *up = D3DXVEC(rpos); - *fw = D3DXVEC(unit(crossp(axis, rpos))); + *fw = D3DXVEC(unit(cross(axis, rpos))); D3DXVec3Cross(nr, up, fw); D3DXVec3Normalize(nr, nr); } @@ -905,7 +905,7 @@ float Scene::ComputeNearClipPlane() VECTOR3 pos; oapiGetGlobalPos(hObj,&pos); double g = atan(Camera.apsq); - double t = dotp(unit(Camera.pos-pos), unit(Camera.dir)); + double t = dot(unit(Camera.pos-pos), unit(Camera.dir)); if (t<-1.0) t=1.0; if (t>1.0) t=1.0f; double a = PI - acos(t); double R = oapiGetSize(hObj) + hVes->GetSurfaceElevation(); @@ -1169,7 +1169,7 @@ void Scene::ComputeLocalLightsVisibility() { if (Lights[i].cone > 0.0f) { LLCBuf[nGlares].index = float(nGlares); - LLCBuf[nGlares].pos = Lights[i].Position; + LLCBuf[nGlares].pos = to_FVECTOR3(Lights[i].Position); LLCBuf[nGlares].cone = Lights[i].cone; Lights[i].GPUId = nGlares; nGlares++; @@ -1191,7 +1191,7 @@ void Scene::ComputeLocalLightsVisibility() psgBuffer[GBUF_DEPTH]->GetDesc(&desc); ComputeData.vSrc = FVECTOR4((float)desc.Width, (float)desc.Height, 1.0f / (float)desc.Width, 1.0f / (float)desc.Height); - ComputeData.vDir = Camera.z; + ComputeData.vDir = to_FVECTOR3(Camera.z); ComputeData.mSVP = Camera.mProjView; // Must setup render target before calling Setup() @@ -1514,7 +1514,7 @@ void Scene::RenderMainScene() SmapRenderList.clear(); SmapRenderList.push_back(vFocus); - D3DXVECTOR3 ld = sunLight.Dir; + auto ld = to_D3DXVECTOR3(sunLight.Dir); D3DXVECTOR3 pos = vFocus->GetBoundingSpherePosDX(); float rad = vFocus->GetBoundingSphereRadius(); float frad = rad; @@ -1643,7 +1643,7 @@ void Scene::RenderMainScene() const std::vector& ls = list[n].marker; VECTOR3 sp; for (int j = 0; j < ls.size(); j++) { - if (dotp(ls[j].pos, cpos - ls[j].pos) >= 0.0) { // surface point visible? + if (dot(ls[j].pos, cpos - ls[j].pos) >= 0.0) { // surface point visible? sp = mul(prot, ls[j].pos) + ppos; RenderObjectMarker(pSketch, sp, ls[j].label[0], ls[j].label[1], list[n].shape, size); } @@ -1675,7 +1675,7 @@ void Scene::RenderMainScene() double apprad = 8000e3 / (length(cpos - bpos) * tan(GetCameraAperture())); - if (dotp(bpos, cpos - bpos) >= 0.0 && apprad > LABEL_DISTLIMIT) { // surface point visible? + if (dot(bpos, cpos - bpos) >= 0.0 && apprad > LABEL_DISTLIMIT) { // surface point visible? char name[64]; oapiGetObjectName(hBase, name, 63); VECTOR3 sp = mul(prot, bpos) + ppos; RenderObjectMarker(pSketch, sp, std::string(name), std::string(), 0, size); @@ -1779,7 +1779,7 @@ void Scene::RenderMainScene() // if (Config->ShadowMapMode >= 1) { - D3DXVECTOR3 ld = sunLight.Dir; + auto ld = to_D3DXVECTOR3(sunLight.Dir); D3DXVECTOR3 pos = vFocus->GetBoundingSpherePosDX(); float rad = vFocus->GetBoundingSphereRadius(); @@ -1825,7 +1825,7 @@ void Scene::RenderMainScene() while (!Intersect.empty()) { - D3DXVECTOR3 ld = sunLight.Dir; + auto ld = to_D3DXVECTOR3(sunLight.Dir); D3DXVECTOR3 pos = Intersect.front()->GetBoundingSpherePosDX(); float rad = Intersect.front()->GetBoundingSphereRadius(); @@ -2377,7 +2377,7 @@ D3DXCOLOR Scene::GetSunDiffColor() float pwr = 1.0f; - if (hP == hS) return GetSun()->Color; + if (hP == hS) return to_D3DXCOLOR(GetSun()->Color); double r = length(P); double pres = 1000.0; @@ -2394,7 +2394,7 @@ D3DXCOLOR Scene::GetSunDiffColor() float k = float(sqrt(r*r - size*size)); // Horizon distance float alt = float(r - size); float rs = float(oapiGetSize(hS) / s); - float ac = float(-dotp(S, P) / (r*s)); // sun elevation + float ac = float(-dot(S, P) / (r * s)); // sun elevation // Avoid some fault conditions if (alt<0) alt = 0, k = 1e3, size = r; @@ -3040,8 +3040,7 @@ bool Scene::WorldToScreenSpace2(const VECTOR3& wpos, oapi::FVECTOR2* pt, D3DXMAT // void Scene::RenderObjectMarker(oapi::Sketchpad *pSkp, const VECTOR3 &gpos, const std::string& label1, const std::string& label2, int mode, int scale) { - VECTOR3 dp (gpos - GetCameraGPos()); - normalise (dp); + VECTOR3 dp = unit(gpos - GetCameraGPos()); m_celSphere->RenderMarker(pSkp, dp, label1, label2, mode, scale); } @@ -3173,7 +3172,7 @@ FMATRIX4 Scene::PushCameraFrustumLimits(float nearlimit, float farlimit) FRUSTUM fr = { Camera.nearplane, Camera.farplane }; FrustumStack.push(fr); SetCameraFrustumLimits(nearlimit, farlimit); - return FMATRIX4(GetProjectionViewMatrix()); + return to_FMATRIX4(*GetProjectionViewMatrix()); } // =========================================================================================== @@ -3182,7 +3181,7 @@ FMATRIX4 Scene::PopCameraFrustumLimits() { SetCameraFrustumLimits(FrustumStack.top().znear, FrustumStack.top().zfar); FrustumStack.pop(); - return FMATRIX4(GetProjectionViewMatrix()); + return to_FMATRIX4(*GetProjectionViewMatrix()); } // =========================================================================================== @@ -3375,7 +3374,7 @@ void Scene::UpdateCameraFromOrbiter(DWORD dwPass) else { // Camera target doesn't exist. (Should not happen) oapiCameraGlobalPos(&Camera.pos); - Camera.relpos = _V(0,0,0); + Camera.relpos = {0,0,0}; } oapiCameraGlobalDir(&Camera.dir); @@ -3669,7 +3668,7 @@ void Scene::RenderGlares() Const.GPUId = (float(GPUId) + 0.5f) / desc.Width; Const.Pos = FVECTOR4(pt.x, pt.y, size, size); Const.Alpha = Lights[i].cone; - Const.Color = Lights[i].Diffuse; + Const.Color = to_FVECTOR4(Lights[i].Diffuse); Const.Blend = 1.0f; pRenderGlares->SetVSConstants("Const", &Const, sizeof(Const)); pRenderGlares->SetPSConstants("Const", &Const, sizeof(Const)); diff --git a/OVP/D3D9Client/Spherepatch.cpp b/OVP/D3D9Client/Spherepatch.cpp index 20186ba27..990b7b990 100644 --- a/OVP/D3D9Client/Spherepatch.cpp +++ b/OVP/D3D9Client/Spherepatch.cpp @@ -265,9 +265,9 @@ void CreateSpherePatch (LPDIRECT3DDEVICE9 pDev, VBMESH &mesh, int nlng, int nlat double clng0 = cos(minlng), slng0 = sin(minlng); double clat1 = cos(maxlat), slat1 = sin(maxlat); double clng1 = cos(maxlng), slng1 = sin(maxlng); - VECTOR3 ex = {clat0*clng1 - clat0*clng0, 0, clat0*slng1 - clat0*slng0}; normalise(ex); - VECTOR3 ey = {0.5*(clng0+clng1)*(clat1-clat0), slat1-slat0, 0.5*(slng0+slng1)*(clat1-clat0)}; normalise(ey); - VECTOR3 ez = crossp (ey, ex); + auto ex = unit(VECTOR3{clat0*clng1 - clat0*clng0, 0, clat0*slng1 - clat0*slng0}); + auto ey = unit(VECTOR3{0.5*(clng0+clng1)*(clat1-clat0), slat1-slat0, 0.5*(slng0+slng1)*(clat1-clat0)}); + auto ez = cross(ey, ex); MATRIX3 R = {ex.x, ex.y, ex.z, ey.x, ey.y, ey.z, ez.x, ez.y, ez.z}; VECTOR3 pref = {0.5*(clat0*clng1 + clat0*clng0), slat0, 0.5*(clat0*slng1 + clat0*slng0)}; // origin VECTOR3 tpmin, tpmax; @@ -285,7 +285,7 @@ void CreateSpherePatch (LPDIRECT3DDEVICE9 pDev, VBMESH &mesh, int nlng, int nlat for (j = 0; j <= nseg; j++) { lng = (nseg ? minlng + (maxlng-minlng) * (double)j/(double)nseg : 0.0); slng = sin(lng), clng = cos(lng); - pos = _V(clat*clng, slat, clat*slng); + pos = {clat*clng, slat, clat*slng}; tpos = mul (R, pos-pref); if (!n) { tpmin = tpos; @@ -360,14 +360,14 @@ void CreateSpherePatch (LPDIRECT3DDEVICE9 pDev, VBMESH &mesh, int nlng, int nlat } // transform bounding box back to patch coordinates - mesh.Box[0] = _V(tmul (R, _V(tpmin.x, tpmin.y, tpmin.z)) + pref); - mesh.Box[1] = _V(tmul (R, _V(tpmax.x, tpmin.y, tpmin.z)) + pref); - mesh.Box[2] = _V(tmul (R, _V(tpmin.x, tpmax.y, tpmin.z)) + pref); - mesh.Box[3] = _V(tmul (R, _V(tpmax.x, tpmax.y, tpmin.z)) + pref); - mesh.Box[4] = _V(tmul (R, _V(tpmin.x, tpmin.y, tpmax.z)) + pref); - mesh.Box[5] = _V(tmul (R, _V(tpmax.x, tpmin.y, tpmax.z)) + pref); - mesh.Box[6] = _V(tmul (R, _V(tpmin.x, tpmax.y, tpmax.z)) + pref); - mesh.Box[7] = _V(tmul (R, _V(tpmax.x, tpmax.y, tpmax.z)) + pref); + mesh.Box[0] = _V(tmul (R, {tpmin.x, tpmin.y, tpmin.z}) + pref); + mesh.Box[1] = _V(tmul (R, {tpmax.x, tpmin.y, tpmin.z}) + pref); + mesh.Box[2] = _V(tmul (R, {tpmin.x, tpmax.y, tpmin.z}) + pref); + mesh.Box[3] = _V(tmul (R, {tpmax.x, tpmax.y, tpmin.z}) + pref); + mesh.Box[4] = _V(tmul (R, {tpmin.x, tpmin.y, tpmax.z}) + pref); + mesh.Box[5] = _V(tmul (R, {tpmax.x, tpmin.y, tpmax.z}) + pref); + mesh.Box[6] = _V(tmul (R, {tpmin.x, tpmax.y, tpmax.z}) + pref); + mesh.Box[7] = _V(tmul (R, {tpmax.x, tpmax.y, tpmax.z}) + pref); } diff --git a/OVP/D3D9Client/SurfMgr.cpp b/OVP/D3D9Client/SurfMgr.cpp index 395031ba1..a39539971 100644 --- a/OVP/D3D9Client/SurfMgr.cpp +++ b/OVP/D3D9Client/SurfMgr.cpp @@ -36,7 +36,7 @@ SurfaceManager::SurfaceManager (D3D9Client *gclient, const vPlanet *vplanet) maxbaselvl = min(8, maxlvl); - pcdir = _V(1,0,0); + pcdir = {1,0,0}; lightfac = *(double*)gc->GetConfigParam (CFGPRM_SURFACELIGHTBRT); spec_base = 0.95f; atmc = oapiGetPlanetAtmConstants (obj); diff --git a/OVP/D3D9Client/Surfmgr2.cpp b/OVP/D3D9Client/Surfmgr2.cpp index 5056100ac..cf7d5a370 100644 --- a/OVP/D3D9Client/Surfmgr2.cpp +++ b/OVP/D3D9Client/Surfmgr2.cpp @@ -12,16 +12,16 @@ // LOD (level-of-detail) algorithm for surface patch resolution. // ============================================================== -#include "Surfmgr2.h" -#include "Tilemgr2.h" #include "Cloudmgr2.h" #include "D3D9Catalog.h" #include "D3D9Config.h" -#include "vVessel.h" -#include "VectorHelpers.h" +#include "D3D9Surface.h" +#include "D3D9Util.h" #include "DebugControls.h" #include "gcCore.h" -#include "D3D9Surface.h" +#include "Surfmgr2.h" +#include "Tilemgr2.h" +#include "VVessel.h" // ======================================================================= extern void FilterElevationGraphics(OBJHANDLE hPlanet, int lvl, int ilat, int ilng, float *elev); @@ -797,7 +797,7 @@ void SurfTile::Render () bool render_shadows = (mgr->GetPlanet()->CloudMgr2() != NULL) && mgr->GetClient()->GetConfigParam(CFGPRM_CLOUDSHADOWS) && pShader->bCloudShd; if (ltex) { - sdist = acos(dotp(mgr->prm.sdir, cnt)); + sdist = std::acos(dot(mgr->prm.sdir, cnt)); rad = rad0 / (double)(2 << lvl); // tile radius has_specular = (ltex != NULL) && sdist < (1.75 + rad); has_lights = (render_lights && ltex && sdist > 1.35); @@ -921,7 +921,7 @@ void SurfTile::Render () // ---------------------------------------------------------------------- FVECTOR4 texcoord; - const vPlanet::sOverlay *oLay = vPlanet->IntersectOverlay(bnd.vec, &texcoord); + const vPlanet::sOverlay *oLay = vPlanet->IntersectOverlay(to_VECTOR4(bnd), &texcoord); if (pShader->bDevtools) { @@ -973,7 +973,7 @@ void SurfTile::Render () sp->vTexOff = GetTexRangeDX(&texrange); sp->vMicroOff = GetTexRangeDX(µrange); - sp->mWorld = mWorld; + sp->mWorld = to_FMATRIX4(mWorld); sp->fTgtScale = tgtscale; if (has_lights) sp->fBeta = float(mgr->Cprm().lightfac); @@ -1003,7 +1003,7 @@ void SurfTile::Render () if (sqrt(D3DXVec3Dot(&bc, &bc) - x * x) < (shd->rad + mesh->bsRad)) { float s = float(shd->size); float sr = 2.0f * shd->rad / s; - sp->mLVP = shd->mViewProj; + sp->mLVP = to_FMATRIX4(shd->mViewProj); sp->vSHD = FVECTOR4(sr, 1.0f / s, 0.0f, 1.0f / shd->depth); fc->bShadows = true; } @@ -1066,11 +1066,11 @@ void SurfTile::Render () for (int i = 0; i < nMeshLights; i++) { auto pL = pLights[LightList[i].idx]; - Locals.attenuation[i] = pL.Attenuation; + Locals.attenuation[i] = to_FVECTOR3(pL.Attenuation); Locals.diffuse[i] = FVECTOR4(pL.Diffuse).rgb; - Locals.direction[i] = pL.Direction; - Locals.param[i] = pL.Param; - Locals.position[i] = pL.Position; + Locals.direction[i] = to_FVECTOR3(pL.Direction); + Locals.param[i] = to_FVECTOR4(pL.Param); + Locals.position[i] = to_FVECTOR3(pL.Position); Spots[i] = (pL.Type == 1); } diff --git a/OVP/D3D9Client/TileLabel.cpp b/OVP/D3D9Client/TileLabel.cpp index bd9f85976..1fc88220b 100644 --- a/OVP/D3D9Client/TileLabel.cpp +++ b/OVP/D3D9Client/TileLabel.cpp @@ -284,7 +284,7 @@ void TileLabel::Render (D3D9Pad *skp, oapi::Font **labelfont, int *fontidx) for (i = 0; i < nrenderlabel; ++i) { VECTOR3 camlabelpos = campos-renderlabel[i]->pos; - if (dotp (renderlabel[i]->pos, camlabelpos) >= 0.0) { + if (dot(renderlabel[i]->pos, camlabelpos) >= 0.0) { double fontscale = 1e4/length(camlabelpos)*(13-min(tile->lvl,12)*1); int idx = max(0, min(3, (int)fontscale)); if (idx != *fontidx) { diff --git a/OVP/D3D9Client/TileMgr.cpp b/OVP/D3D9Client/TileMgr.cpp index 32d09b5f5..b94123ebb 100644 --- a/OVP/D3D9Client/TileMgr.cpp +++ b/OVP/D3D9Client/TileMgr.cpp @@ -482,9 +482,8 @@ void TileManager::Render(LPDIRECT3DDEVICE9 dev, D3DXMATRIX &wmat, double scale, D3DMAT_Copy (&RenderParam.wmat, &wmat); D3DMAT_Copy (&RenderParam.wmat_tmp, &wmat); D3DMAT_MatrixInvert (&imat, &wmat); - RenderParam.cdir = _V(imat._41, imat._42, imat._43); // camera position in local coordinates (units of planet radii) - RenderParam.cpos = vp->PosFromCamera() * scale; - normalise (RenderParam.cdir); // camera direction + RenderParam.cdir = unit(VECTOR3{imat._41, imat._42, imat._43}); // camera direction + RenderParam.cpos = vp->PosFromCamera() * scale; // camera position in local coordinates (units of planet radii) RenderParam.bfog = bfog; oapiGetRotationMatrix (obj, &RenderParam.grot); @@ -495,12 +494,11 @@ void TileManager::Render(LPDIRECT3DDEVICE9 dev, D3DXMATRIX &wmat, double scale, RenderParam.objsize = oapiGetSize (obj); RenderParam.cdist = vp->CamDist() / vp->GetSize(); // camera distance in units of planet radius RenderParam.viewap = (viewap ? viewap : acos (1.0/max (1.0, RenderParam.cdist))); - RenderParam.sdir = tmul (RenderParam.grot, -gpos); + RenderParam.sdir = unit(tmul(RenderParam.grot, -gpos)); // sun direction in planet frame RenderParam.horzdist = sqrt(RenderParam.cdist*RenderParam.cdist-1.0) * RenderParam.objsize; - normalise (RenderParam.sdir); // sun direction in planet frame // limit resolution for fast camera movements - double limitstep, cstep = acos (dotp (RenderParam.cdir, pcdir)); + double limitstep, cstep = std::acos(dot(RenderParam.cdir, pcdir)); int maxlevel = SURF_MAX_PATCHLEVEL; static double limitstep0 = 5.12 * pow(2.0, -(double)SURF_MAX_PATCHLEVEL); for (limitstep = limitstep0; cstep > limitstep && maxlevel > 5; limitstep *= 2.0) @@ -567,7 +565,7 @@ void TileManager::ProcessTile (int lvl, int hemisp, int ilat, int nlat, int ilng static const double rad0 = sqrt(2.0)*PI05*0.5; VECTOR3 cnt = TileCentre (hemisp, ilat, nlat, ilng, nlng); double rad = rad0/(double)nlat; - double x = dotp (RenderParam.cdir, cnt); + double x = dot(RenderParam.cdir, cnt); double adist = acos(x) - rad; if (adist >= RenderParam.viewap) { @@ -670,7 +668,7 @@ void TileManager::ProcessTile (int lvl, int hemisp, int ilat, int nlat, int ilng // actually render the tile at this level --------------------------------------- // - double sdist = acos (dotp (RenderParam.sdir, cnt)); + double sdist = std::acos(dot(RenderParam.sdir, cnt)); if (bCoarseTex) { //if (sdist > PI05+rad && bkp_flag & 2) bkp_flag &= 0xFD; @@ -690,8 +688,8 @@ VECTOR3 TileManager::TileCentre (int hemisp, int ilat, int nlat, int ilng, int n { double cntlat = PI*0.5 * ((double)ilat+0.5)/(double)nlat, slat = sin(cntlat), clat = cos(cntlat); double cntlng = PI*2.0 * ((double)ilng+0.5)/(double)nlng + PI, slng = sin(cntlng), clng = cos(cntlng); - if (hemisp) return _V(clat*clng, -slat, -clat*slng); - else return _V(clat*clng, slat, clat*slng); + if (hemisp) return {clat*clng, -slat, -clat*slng}; + else return {clat*clng, slat, clat*slng}; } // ======================================================================= @@ -761,7 +759,7 @@ bool TileManager::SpecularColour (D3DCOLORVALUE *col) return false; } else { double fac = 0.7; // needs thought ... - double cosa = dotp (RenderParam.cdir, RenderParam.sdir); + double cosa = dot(RenderParam.cdir, RenderParam.sdir); double alpha = 0.5*acos(cosa); // sun reflection angle double scale = sin(alpha)*fac; col->r = (float)max(0.0, spec_base - scale*atmc->color0.x); diff --git a/OVP/D3D9Client/Tilemgr2.cpp b/OVP/D3D9Client/Tilemgr2.cpp index 6818d7ddd..4ec099e35 100644 --- a/OVP/D3D9Client/Tilemgr2.cpp +++ b/OVP/D3D9Client/Tilemgr2.cpp @@ -389,7 +389,7 @@ VECTOR3 Tile::Centre () const int nlng = 2 << lvl; double cntlat = PI05 - PI * ((double)ilat+0.5)/(double)nlat, slat = sin(cntlat), clat = cos(cntlat); double cntlng = PI2 * ((double)ilng+0.5)/(double)nlng + PI, slng = sin(cntlng), clng = cos(cntlng); - return _V(clat*clng, slat, clat*slng); + return {clat*clng, slat, clat*slng}; } @@ -451,9 +451,9 @@ VBMESH *Tile::CreateMesh_quadpatch (int grdlat, int grdlng, float *elev, double double clng0 = cos(minlng), slng0 = sin(minlng); double clat1 = cos(maxlat), slat1 = sin(maxlat); double clng1 = cos(maxlng), slng1 = sin(maxlng); - VECTOR3 ex = {clat0*clng1 - clat0*clng0, 0, clat0*slng1 - clat0*slng0}; normalise (ex); - VECTOR3 ey = {0.5*(clng0+clng1)*(clat1-clat0), slat1-slat0, 0.5*(slng0+slng1)*(clat1-clat0)}; normalise (ey); - VECTOR3 ez = crossp (ey, ex); + auto ex = unit(VECTOR3{clat0*clng1 - clat0*clng0, 0, clat0*slng1 - clat0*slng0}); + auto ey = unit(VECTOR3{0.5*(clng0+clng1)*(clat1-clat0), slat1-slat0, 0.5*(slng0+slng1)*(clat1-clat0)}); + auto ez = cross(ey, ex); MATRIX3 R = {ex.x, ex.y, ex.z, ey.x, ey.y, ey.z, ez.x, ez.y, ez.z}; VECTOR3 pref = {radius*clat0*0.5*(clng1+clng0), radius*slat0, radius*clat0*0.5*(slng1+slng0)}; // origin VECTOR3 tpmin, tpmax; @@ -485,7 +485,7 @@ VBMESH *Tile::CreateMesh_quadpatch (int grdlat, int grdlng, float *elev, double if (elev) e = elev[(i+1)*TILE_ELEVSTRIDE + j+1] * float(elev_scale); eradius += double(e); - nml = _V(clat*clng, slat, clat*slng); + nml = {clat*clng, slat, clat*slng}; pos = nml*eradius; tpos = mul (R, pos-pref); if (!n) { @@ -587,8 +587,7 @@ VBMESH *Tile::CreateMesh_quadpatch (int grdlat, int grdlng, float *elev, double // This version avoids the normalisation of the 4 intermediate face normals // It's faster and doesn't seem to make much difference - VECTOR3 nml = { 2.0*dydz, dz*elev_scale*(elev[en - TILE_ELEVSTRIDE] - elev[en + TILE_ELEVSTRIDE]), dy*elev_scale*(elev[en - 1] - elev[en + 1]) }; - normalise (nml); + auto nml = unit(VECTOR3{ 2.0*dydz, dz*elev_scale*(elev[en - TILE_ELEVSTRIDE] - elev[en + TILE_ELEVSTRIDE]), dy*elev_scale*(elev[en - 1] - elev[en + 1]) }); // rotate into place nx1 = nml.x*clat - nml.y*slat; ny1 = nml.x*slat + nml.y*clat; @@ -630,14 +629,14 @@ VBMESH *Tile::CreateMesh_quadpatch (int grdlat, int grdlng, float *elev, double pref.x -= dx; pref.y -= dy; - mesh->Box[0] = _V(tmul (R, _V(tpmin.x, tpmin.y, tpmin.z)) + pref); - mesh->Box[1] = _V(tmul (R, _V(tpmax.x, tpmin.y, tpmin.z)) + pref); - mesh->Box[2] = _V(tmul (R, _V(tpmin.x, tpmax.y, tpmin.z)) + pref); - mesh->Box[3] = _V(tmul (R, _V(tpmax.x, tpmax.y, tpmin.z)) + pref); - mesh->Box[4] = _V(tmul (R, _V(tpmin.x, tpmin.y, tpmax.z)) + pref); - mesh->Box[5] = _V(tmul (R, _V(tpmax.x, tpmin.y, tpmax.z)) + pref); - mesh->Box[6] = _V(tmul (R, _V(tpmin.x, tpmax.y, tpmax.z)) + pref); - mesh->Box[7] = _V(tmul (R, _V(tpmax.x, tpmax.y, tpmax.z)) + pref); + mesh->Box[0] = _V(tmul(R, {tpmin.x, tpmin.y, tpmin.z}) + pref); + mesh->Box[1] = _V(tmul(R, {tpmax.x, tpmin.y, tpmin.z}) + pref); + mesh->Box[2] = _V(tmul(R, {tpmin.x, tpmax.y, tpmin.z}) + pref); + mesh->Box[3] = _V(tmul(R, {tpmax.x, tpmax.y, tpmin.z}) + pref); + mesh->Box[4] = _V(tmul(R, {tpmin.x, tpmin.y, tpmax.z}) + pref); + mesh->Box[5] = _V(tmul(R, {tpmax.x, tpmin.y, tpmax.z}) + pref); + mesh->Box[6] = _V(tmul(R, {tpmin.x, tpmax.y, tpmax.z}) + pref); + mesh->Box[7] = _V(tmul(R, {tpmax.x, tpmax.y, tpmax.z}) + pref); mesh->ComputeSphere(); mesh->MapVertices(TileManager2Base::pDev); @@ -684,7 +683,7 @@ VBMESH *Tile::CreateMesh_hemisphere (int grd, float *elev, double globelev) slng = sin(lng), clng = cos(lng); eradius = radius + globelev; // radius including node elevation if (elev) eradius += (double)elev[(grd+1-y)*TILE_ELEVSTRIDE + x+1]; - nml = _V(slat*clng, clat, slat*slng); + nml = {slat*clng, clat, slat*slng}; pos = nml*eradius; vtx->x = D3DVAL(pos.x); vtx->nx = D3DVAL(nml.x); vtx->y = D3DVAL(pos.y); vtx->ny = D3DVAL(nml.y); @@ -717,7 +716,7 @@ VBMESH *Tile::CreateMesh_hemisphere (int grd, float *elev, double globelev) for (x = 0; x < x2; x++) mn += (double)elev[TILE_ELEVSTRIDE*(grd+1) + x+1]; eradius += mn/x2; } - nml = _V(0,1,0); + nml = {0,1,0}; pos = nml*eradius; vtx->x = D3DVAL(pos.x); vtx->nx = D3DVAL(nml.x); vtx->y = D3DVAL(pos.y); vtx->ny = D3DVAL(nml.y); @@ -735,7 +734,7 @@ VBMESH *Tile::CreateMesh_hemisphere (int grd, float *elev, double globelev) for (x = 0; x < x2; x++) mn += (double)elev[TILE_ELEVSTRIDE + x+1]; eradius += mn/x2; } - nml = _V(0,-1,0); + nml = {0,-1,0}; pos = nml*eradius; vtx->x = D3DVAL(pos.x); vtx->nx = D3DVAL(nml.x); vtx->y = D3DVAL(pos.y); vtx->ny = D3DVAL(nml.y); @@ -783,8 +782,7 @@ VBMESH *Tile::CreateMesh_hemisphere (int grd, float *elev, double globelev) if (!ilng) lng -= PI; slng = sin(lng), clng = cos(lng); en = (grd+1-y)*TILE_ELEVSTRIDE + x+1; - VECTOR3 nml = {2.0*dydz, dz*(elev[en-TILE_ELEVSTRIDE]-elev[en+TILE_ELEVSTRIDE]), dy*(elev[en-1]-elev[en+1])}; - normalise(nml); + auto nml = unit(VECTOR3{2.0*dydz, dz*(elev[en-TILE_ELEVSTRIDE]-elev[en+TILE_ELEVSTRIDE]), dy*(elev[en-1]-elev[en+1])}); // rotate into place nx1 = nml.x*clat - nml.y*slat; ny1 = nml.x*slat + nml.y*clat; @@ -1190,9 +1188,8 @@ void TileManager2Base::SetRenderPrm (MATRIX4 &dwmat, double prerot, bool use_zbu prm.cdir = tmul (prm.grot, -prm.cpos); // camera's direction in planet frame double cdist = length(prm.cdir); prm.cdist = cdist / obj_size; // camera's distance in units of planet radius - normalise (prm.cdir); - prm.sdir = tmul (prm.grot, -obj_pos); // sun's direction in planet frame - normalise (prm.sdir); + prm.cdir = unit(prm.cdir); + prm.sdir = unit(tmul(prm.grot, -obj_pos)); // sun's direction in planet frame // Add 5km threshold to allow slight camera movement with out causing surface tiles to unload prm.viewap = acos (1.0/(max ((cdist+5e3) / obj_size, 1.0+minalt))); prm.scale = 1.0; diff --git a/OVP/D3D9Client/Tilemgr2.h b/OVP/D3D9Client/Tilemgr2.h index 6811c6929..3c286d132 100644 --- a/OVP/D3D9Client/Tilemgr2.h +++ b/OVP/D3D9Client/Tilemgr2.h @@ -71,15 +71,14 @@ typedef struct { float tvmin, tvmax; } TEXCRDRANGE2; -typedef union { - VECTOR4 vec; - struct { - double minlng; ///< Left - - double maxlat; ///< Top + - double maxlng; ///< Right + - double minlat; ///< Bottom - - }; -} TILEBOUNDS; +struct TILEBOUNDS { + double minlng; ///< Left - + double maxlat; ///< Top + + double maxlng; ///< Right + + double minlat; ///< Bottom - +}; + +inline auto to_VECTOR4(const TILEBOUNDS& b) { return VECTOR4{b.minlng, b.maxlat, b.maxlng, b.minlat}; } bool FileExists(const char* path); diff --git a/OVP/D3D9Client/Tilemgr2_imp.hpp b/OVP/D3D9Client/Tilemgr2_imp.hpp index 4ed3e2b97..3bcf7388f 100644 --- a/OVP/D3D9Client/Tilemgr2_imp.hpp +++ b/OVP/D3D9Client/Tilemgr2_imp.hpp @@ -120,7 +120,7 @@ void TileManager2Base::ProcessNode (QuadTreeNode *node) VECTOR3 &cnt = tile->cnt; // tile centre in unit planet frame static const double rad0 = sqrt(2.0)*PI05; double rad = rad0/(double)nlat; - double alpha = acos (dotp (prm.cdir, cnt)); // angle between tile centre and camera from planet centre + double alpha = std::acos(dot(prm.cdir, cnt)); // angle between tile centre and camera from planet centre double adist = alpha - rad; // angle between closest tile corner and camera if (adist >= prm.viewap) { if (lvl == 0) diff --git a/OVP/D3D9Client/VBase.cpp b/OVP/D3D9Client/VBase.cpp index a748e7a12..7a97e6990 100644 --- a/OVP/D3D9Client/VBase.cpp +++ b/OVP/D3D9Client/VBase.cpp @@ -361,7 +361,7 @@ bool vBase::Update (bool bMainScene) if (fabs(simt-Tchk)>1.0) { VECTOR3 pos, sdir; MATRIX3 rot; - oapiGetGlobalPos (hObj, &pos); normalise(pos); + oapiGetGlobalPos (hObj, &pos); pos = unit(pos); oapiGetRotationMatrix (hObj, &rot); sdir = tmul (rot, -pos); double csun = sdir.y; @@ -424,8 +424,8 @@ bool vBase::RenderStructures(LPDIRECT3DDEVICE9 dev) // render generic objects above shadows for (DWORD i=0; iGetBoundingSpherePos(); - FVECTOR3 qw = TransformCoord(bs, mWorld); + auto bs = to_FVECTOR3(structure_as[i]->GetBoundingSpherePos()); + auto qw = TransformCoord(bs, to_FMATRIX4(mWorld)); D3D9Sun sp = vP->GetObjectAtmoParams(qw._V() + vP->CameraPos()); structure_as[i]->SetSunLight(&sp); structure_as[i]->Render(&mWorld, RENDER_BASE); @@ -478,7 +478,7 @@ void vBase::RenderGroundShadow(LPDIRECT3DDEVICE9 dev, float alpha) pCurrentVisual = this; VECTOR3 sd; - oapiGetGlobalPos(hObj, &sd); normalise(sd); + oapiGetGlobalPos(hObj, &sd); sd = unit(sd); MATRIX3 mRot; oapiGetRotationMatrix(hObj, &mRot); @@ -508,7 +508,7 @@ void vBase::RenderGroundShadow(LPDIRECT3DDEVICE9 dev, float alpha) float rad = structure_as[i]->BBox.bs.w; if (rad<250.0f) ToLocal(q, &a, &b); - else ToLocal(_V(0,0,0), &a, &b); + else ToLocal({0,0,0}, &a, &b); if (vP->GetElevation(a, b, &el0) <= 0) el0 = oapiSurfaceElevation(hPlanet, a, b); if (vP->GetElevation(a + d, b, &el1) <= 0) el1 = oapiSurfaceElevation(hPlanet, a + d, b); @@ -522,11 +522,11 @@ void vBase::RenderGroundShadow(LPDIRECT3DDEVICE9 dev, float alpha) vb = FromLocal(vb); vc = FromLocal(vc); - VECTOR3 n = -unit(crossp(vb - va, vc - va)); + VECTOR3 n = -unit(cross(vb - va, vc - va)); D3DXVECTOR3 hn = D3DXVEC(n); - float zo = float(-dotp(va, n)); + float zo = float(-dot(va, n)); float nd = D3DXVec3Dot(&hn, &lsun); hn /= nd; float ofs = zo / nd; diff --git a/OVP/D3D9Client/VObject.cpp b/OVP/D3D9Client/VObject.cpp index ebbf6c569..4f58aeb6f 100644 --- a/OVP/D3D9Client/VObject.cpp +++ b/OVP/D3D9Client/VObject.cpp @@ -61,7 +61,7 @@ vObject::vObject(OBJHANDLE _hObj, const Scene *scene) if (_hObj) size = oapiGetSize(_hObj); else size = 0; dmWorld = identity4(); - albedo = _V(1,1,1); + albedo = {1,1,1}; oapiGetObjectName(hObj, name, 64); sunLight = *scene->GetSun(); objtp = oapiGetObjectType(hObj); @@ -172,7 +172,7 @@ bool vObject::Update(bool bMainScene) oapiGetGlobalPos(hTgt, &tpos); - axis = mul(grot, _V(0, 1, 0)); + axis = mul(grot, VECTOR3{0, 1, 0}); cpos = gpos - scn->GetCameraGPos(); cdist = length(cpos); @@ -225,7 +225,7 @@ D3DXVECTOR3 vObject::GetBoundingSpherePosDX() VECTOR3 vObject::GetBoundingSpherePos() { D3DXVECTOR3 pos = GetBoundingSpherePosDX(); - return _V((double)pos.x, (double)pos.y, (double)pos.z); + return VECTOR3{(double)pos.x, (double)pos.y, (double)pos.z}; } @@ -285,7 +285,7 @@ void vObject::RenderSpot(LPDIRECT3DDEVICE9 dev, const VECTOR3 *ofs, float size, VECTOR3 camp = scn->GetCameraGPos(); const double ambient = 0.2; - double cosa = dotp (unit(gpos), unit(gpos - camp)); + double cosa = dot(unit(gpos), unit(gpos - camp)); double intens = (lighting ? 0.5 * ((1.0-ambient)*cosa + 1.0+ambient) : 1.0); D3DXMATRIX W; @@ -329,7 +329,7 @@ void vObject::RenderDot(LPDIRECT3DDEVICE9 dev) D3DXVec3Normalize(&vCam, &vPos); D3DMAT_CreateX_Billboard(&vCam, &vPos, scale, &W); - float ints = float(sqrt(1.0+dotp(unit(gpos-spos), unit(cpos)))) * 1.0f; + float ints = float(sqrt(1.0 + dot(unit(gpos - spos), unit(cpos)))) * 1.0f; if (ints>1.0f) ints=1.0f; @@ -360,24 +360,24 @@ void vObject::RenderVectors (LPDIRECT3DDEVICE9 dev, D3D9Pad* pSkp) //scale *= 0.99f; // 1% "slimmer" to avoid z-fighting with force vector(s) float ascale = float(size) * sclset * 0.5f; - RenderAxisVector(pSkp, ptr(D3DXCOLOR(1, 0, 0, alpha)), _V(1, 0, 0), ascale, scale); - RenderAxisLabel(pSkp, ptr(D3DXCOLOR(1, 0, 0, alpha)), _V(1, 0, 0), ascale, scale, "+X"); + RenderAxisVector(pSkp, ptr(D3DXCOLOR(1, 0, 0, alpha)), {1, 0, 0}, ascale, scale); + RenderAxisLabel(pSkp, ptr(D3DXCOLOR(1, 0, 0, alpha)), {1, 0, 0}, ascale, scale, "+X"); - RenderAxisVector(pSkp, ptr(D3DXCOLOR(0, 1, 0, alpha)), _V(0, 1, 0), ascale, scale); - RenderAxisLabel(pSkp, ptr(D3DXCOLOR(0, 1, 0, alpha)), _V(0, 1, 0), ascale, scale, "+Y"); + RenderAxisVector(pSkp, ptr(D3DXCOLOR(0, 1, 0, alpha)), {0, 1, 0}, ascale, scale); + RenderAxisLabel(pSkp, ptr(D3DXCOLOR(0, 1, 0, alpha)), {0, 1, 0}, ascale, scale, "+Y"); - RenderAxisVector(pSkp, ptr(D3DXCOLOR(0, 0, 1, alpha)), _V(0, 0, 1), ascale, scale); - RenderAxisLabel(pSkp, ptr(D3DXCOLOR(0, 0, 1, alpha)), _V(0, 0, 1), ascale, scale, "+Z"); + RenderAxisVector(pSkp, ptr(D3DXCOLOR(0, 0, 1, alpha)), {0, 0, 1}, ascale, scale); + RenderAxisLabel(pSkp, ptr(D3DXCOLOR(0, 0, 1, alpha)), {0, 0, 1}, ascale, scale, "+Z"); if (favmode & FAV_NEGATIVE) { - RenderAxisVector(pSkp, ptr(D3DXCOLOR(1, 0, 0, alpha * 0.5f)), _V(-1, 0, 0), ascale, scale); - RenderAxisLabel(pSkp, ptr(D3DXCOLOR(1, 0, 0, alpha)), _V(-1, 0, 0), ascale, scale, "-X"); + RenderAxisVector(pSkp, ptr(D3DXCOLOR(1, 0, 0, alpha * 0.5f)), {-1, 0, 0}, ascale, scale); + RenderAxisLabel(pSkp, ptr(D3DXCOLOR(1, 0, 0, alpha)), {-1, 0, 0}, ascale, scale, "-X"); - RenderAxisVector(pSkp, ptr(D3DXCOLOR(0, 1, 0, alpha * 0.5f)), _V(0, -1, 0), ascale, scale); - RenderAxisLabel(pSkp, ptr(D3DXCOLOR(0, 1, 0, alpha)), _V(0, -1, 0), ascale, scale, "-Y"); + RenderAxisVector(pSkp, ptr(D3DXCOLOR(0, 1, 0, alpha * 0.5f)), {0, -1, 0}, ascale, scale); + RenderAxisLabel(pSkp, ptr(D3DXCOLOR(0, 1, 0, alpha)), {0, -1, 0}, ascale, scale, "-Y"); - RenderAxisVector(pSkp, ptr(D3DXCOLOR(0, 0, 1, alpha * 0.5f)), _V(0, 0, -1), ascale, scale); - RenderAxisLabel(pSkp, ptr(D3DXCOLOR(0, 0, 1, alpha)), _V(0, 0, -1), ascale, scale, "-Z"); + RenderAxisVector(pSkp, ptr(D3DXCOLOR(0, 0, 1, alpha * 0.5f)), {0, 0, -1}, ascale, scale); + RenderAxisLabel(pSkp, ptr(D3DXCOLOR(0, 0, 1, alpha)), {0, 0, -1}, ascale, scale, "-Z"); } } } @@ -395,11 +395,11 @@ void vObject::RenderAxisVector(D3D9Pad *pSkp, const D3DXCOLOR *pColor, VECTOR3 v VECTOR3 camp = gc->GetScene()->GetCameraGPos(); VECTOR3 pos = gpos - camp; - VECTOR3 rot = crossp(pos, vector); + VECTOR3 rot = cross(pos, vector); VECTOR3 y = mul (grot, unit(vector)) * size; VECTOR3 x = mul (grot, unit(rot)) * size; - VECTOR3 z = mul (grot, unit(crossp(vector, rot))) * size; + VECTOR3 z = mul (grot, unit(cross(vector, rot))) * size; D3DXMatrixIdentity(&W); @@ -431,11 +431,11 @@ void vObject::RenderAxisLabel(D3D9Pad *pSkp, const D3DXCOLOR *clr, VECTOR3 vecto VECTOR3 camp = gc->GetScene()->GetCameraGPos(); VECTOR3 pos = gpos - camp; - VECTOR3 rot = crossp(pos, vector); + VECTOR3 rot = cross(pos, vector); VECTOR3 y = mul(grot, unit(vector)) * size; VECTOR3 x = mul(grot, unit(rot)) * size; - VECTOR3 z = mul(grot, unit(crossp(vector, rot))) * size; + VECTOR3 z = mul(grot, unit(cross(vector, rot))) * size; D3DXMatrixIdentity(&W); diff --git a/OVP/D3D9Client/VPlanet.cpp b/OVP/D3D9Client/VPlanet.cpp index 330ee7516..4346538d2 100644 --- a/OVP/D3D9Client/VPlanet.cpp +++ b/OVP/D3D9Client/VPlanet.cpp @@ -17,25 +17,25 @@ #define D3D_OVERLOADS -#include -#include -#include - +#include "AtmoControls.h" +#include "CloudMgr.h" +#include "cloudmgr2.h" #include "D3D9Client.h" #include "D3D9Config.h" -#include "VPlanet.h" -#include "VBase.h" -#include "SurfMgr.h" -#include "surfmgr2.h" -#include "cloudmgr2.h" -#include "CloudMgr.h" -#include "HazeMgr.h" -#include "RingMgr.h" +#include "D3D9Util.h" #include "DebugControls.h" -#include "AtmoControls.h" -#include "VectorHelpers.h" -#include "OapiExtension.h" +#include "HazeMgr.h" #include "IProcess.h" +#include "OapiExtension.h" +#include "RingMgr.h" +#include "SurfMgr.h" +#include "surfmgr2.h" +#include "VBase.h" +#include "VPlanet.h" + +#include +#include +#include using namespace oapi; @@ -361,7 +361,7 @@ vPlanet::vPlanet (OBJHANDLE _hObj, const Scene *scene) : pSunColor(), pRaySkyView(), pMieSkyView(), pLandViewRay(), pLandViewMie(), pAmbientSky(), pLandViewAtn(), ShaderName("Auto\0") { memset(&MicroCfg, 0, sizeof(MicroCfg)); - vRefPoint = _V(1,0,0); + vRefPoint = {1,0,0}; atm_mode = 0; iConfig = 0; dist_scale = 1.0f; @@ -619,7 +619,7 @@ VECTOR3 vPlanet::GetUnitSurfacePos(double lng, double lat) const { double slat = sin(lat), clat = cos(lat); double slng = sin(lng), clng = cos(lng); - return _V(clat*clng, slat, clat*slng); + return {clat*clng, slat, clat*slng}; } // ============================================================== @@ -878,7 +878,7 @@ void vPlanet::CheckResolution() void vPlanet::RenderZRange (double *nplane, double *fplane) { - double d = dotp (scn->GetCameraGDir(), cpos); + double d = dot(scn->GetCameraGDir(), cpos); *fplane = max (1e3, d+size*1.2); *nplane = max (1e0, d-size*1.2); *fplane = min (*fplane, *nplane*1e5); @@ -913,7 +913,7 @@ bool vPlanet::Render(LPDIRECT3DDEVICE9 dev) { // Must update the latest view projection matrix - cp.mVP = *scn->GetProjectionViewMatrix(); + cp.mVP = to_FMATRIX4(*scn->GetProjectionViewMatrix()); // Setup shadow maps for surface base objects and mesh based bodies --------------- // @@ -947,7 +947,7 @@ bool vPlanet::Render(LPDIRECT3DDEVICE9 dev) prm.AmbColor = D3DXCOLOR(0,0,0,0); prm.FogColor = D3DXCOLOR(0,0,0,0); prm.TintColor = D3DXCOLOR(0,0,0,0); - prm.SunDir = _D3DXVECTOR3(SunDirection()); + prm.SunDir = to_D3DXVECTOR3(SunDirection()); if (ringmgr) { ringmgr->Render(dev, mWorld, false); @@ -999,7 +999,7 @@ bool vPlanet::Render(LPDIRECT3DDEVICE9 dev) // day/nighttime fog lighting VECTOR3 ppos; oapiGetGlobalPos (hObj, &ppos); - double cosa = dotp (unit(ppos), unit(cpos)); + double cosa = dot(unit(ppos), unit(cpos)); double bright = 1.0 * max (0.0, min (1.0, cosa + 0.3)); float rfog = (float)(bright*(min(1.0,fogcol.x)+0.0)); // "whiten" the fog colour float gfog = (float)(bright*(min(1.0,fogcol.y)+0.0)); @@ -1232,7 +1232,7 @@ bool vPlanet::ModLighting (DWORD &ambient) if (!prm.bAtm) return false; if (cdist >= size+prm.atm_href) return false; - double alpha = acos (dotp (unit(scn->GetCameraGPos()), -unit(cpos))); + double alpha = std::acos(dot(unit(scn->GetCameraGPos()), -unit(cpos))); // angular distance between sun and planet as seen from camera double sunelev = alpha - PI05; // elevation of sun above horizon (assuming camera on ground) @@ -1260,7 +1260,7 @@ VECTOR3 vPlanet::ReferencePoint() MATRIX3 mRot; oapiGetRotationMatrix(hObj, &mRot); VECTOR3 vLPos = unit(tmul(mRot, PosFromCamera())); - if (dotp(vLPos, vRefPoint)<0.9993) vRefPoint = vLPos; + if (dot(vLPos, vRefPoint) < 0.9993) vRefPoint = vLPos; return vRefPoint; } diff --git a/OVP/D3D9Client/VPlanetAtmo.cpp b/OVP/D3D9Client/VPlanetAtmo.cpp index 711b0b084..3a90b8534 100644 --- a/OVP/D3D9Client/VPlanetAtmo.cpp +++ b/OVP/D3D9Client/VPlanetAtmo.cpp @@ -8,16 +8,16 @@ #define D3D_OVERLOADS -#include -#include -#include - +#include "AtmoControls.h" #include "D3D9Client.h" #include "D3D9Config.h" -#include "VPlanet.h" -#include "AtmoControls.h" -#include "VectorHelpers.h" +#include "D3D9Util.h" #include "IProcess.h" +#include "VPlanet.h" + +#include +#include +#include using namespace oapi; @@ -595,9 +595,9 @@ void vPlanet::UpdateScatter() oapiGetRotationMatrix(hObj, &mRot); VECTOR3 vNrm = mul(mRot, ReferencePoint()); - VECTOR3 vRot = unit(mul(mRot, _V(0, 1, 0))); - VECTOR3 vTan = unit(crossp(vRot, vNrm)); - VECTOR3 vBiT = unit(crossp(vTan, vNrm)); + VECTOR3 vRot = unit(mul(mRot, VECTOR3{0, 1, 0})); + VECTOR3 vTan = unit(cross(vRot, vNrm)); + VECTOR3 vBiT = unit(cross(vTan, vNrm)); memcpy(&cp.mVP, scn->GetProjectionViewMatrix(), sizeof(FMATRIX4)); diff --git a/OVP/D3D9Client/VVessel.cpp b/OVP/D3D9Client/VVessel.cpp index 86dd4c4d4..67db883d4 100644 --- a/OVP/D3D9Client/VVessel.cpp +++ b/OVP/D3D9Client/VVessel.cpp @@ -333,7 +333,7 @@ void vVessel::InsertMesh(UINT idx) { _TRACE; - VECTOR3 ofs=_V(0,0,0); + VECTOR3 ofs{0, 0, 0}; UINT i; LPD3DXMATRIX pT = NULL; @@ -399,7 +399,7 @@ void vVessel::InsertMesh(UINT idx) // void vVessel::ResetMesh(UINT idx) { - VECTOR3 ofs = _V(0, 0, 0); + VECTOR3 ofs{0, 0, 0}; if ((idx < nmesh) && meshlist[idx].mesh) { @@ -721,9 +721,9 @@ bool vVessel::Render(LPDIRECT3DDEVICE9 dev, bool internalpass) // Initialize MeshShader constants // - MeshShader::ps_const.Cam_X = *scn->GetCameraX(); - MeshShader::ps_const.Cam_Y = *scn->GetCameraY(); - MeshShader::ps_const.Cam_Z = *scn->GetCameraZ(); + MeshShader::ps_const.Cam_X = to_FVECTOR3(*scn->GetCameraX()); + MeshShader::ps_const.Cam_Y = to_FVECTOR3(*scn->GetCameraY()); + MeshShader::ps_const.Cam_Z = to_FVECTOR3(*scn->GetCameraZ()); @@ -1043,14 +1043,14 @@ void vVessel::RenderGroundShadow(LPDIRECT3DDEVICE9 dev, OBJHANDLE hPlanet, float alt = d - R; // altitude above surface if (alt*eps > vessel->GetSize()) return; // too high to cast a shadow - normalise(sd); // shadow projection direction + sd = unit(sd); // shadow projection direction // calculate the intersection of the vessel's shadow with the planet surface - double fac1 = dotp(sd, pvr); + double fac1 = dot(sd, pvr); if (fac1 > 0.0) return; // shadow doesn't intersect planet surface double csun = -fac1 / d; // sun elevation above horizon if (csun < shadow_elev_limit) return; // sun too low to cast shadow - double arg = fac1*fac1 - (dotp(pvr, pvr) - R*R); + double arg = fac1 * fac1 - (dot(pvr, pvr) - R * R); if (arg <= 0.0) return; // shadow doesn't intersect with planet surface double a = -fac1 - sqrt(arg); @@ -1064,7 +1064,7 @@ void vVessel::RenderGroundShadow(LPDIRECT3DDEVICE9 dev, OBJHANDLE hPlanet, float // perform projections //double nr0 = dotp(hn, shp); float nr0 = float(-alt); - double nd = dotp(hn, sdv); + double nd = dot(hn, sdv); VECTOR3 sdvs = sdv / nd; D3DXVECTOR4 nrml = D3DXVECTOR4(float(hn.x), float(hn.y), float(hn.z), float(alt)); @@ -1107,7 +1107,7 @@ void vVessel::RenderGroundShadow(LPDIRECT3DDEVICE9 dev, OBJHANDLE hPlanet, float if (meshlist[i].trans) { VECTOR3 of; vessel->GetMeshOffset(i, of); - nrml.w += float(dotp(of, hn)); // Sift a local groung level + nrml.w += float(dot(of, hn)); // Sift a local groung level D3DXMatrixMultiply(&mProjWorldShift, meshlist[i].trans, &mProjWorld); mesh->RenderStencilShadows(alpha, &mWorld, &mProjWorldShift, false, &nrml); } @@ -1217,7 +1217,7 @@ bool vVessel::RenderENVMap(LPDIRECT3DDEVICE9 pDev, DWORD cnt, DWORD flags) // ----------------------------------------------------------------------------------------------- // VECTOR3 gpos; - vessel->Local2Global(_V(eCam->lPos.x, eCam->lPos.y, eCam->lPos.z), gpos); + vessel->Local2Global({eCam->lPos.x, eCam->lPos.y, eCam->lPos.z}, gpos); // Prepare camera and scene for env map rendering scn->PushCamera(); @@ -1333,7 +1333,7 @@ bool vVessel::ProbeIrradiance(LPDIRECT3DDEVICE9 pDev, DWORD cnt, DWORD flags) // ----------------------------------------------------------------------------------------------- // VECTOR3 gpos; - vessel->Local2Global(_V(0,0,0), gpos); + vessel->Local2Global({0,0,0}, gpos); // Prepare camera and scene for env map rendering scn->PushCamera(); @@ -1419,8 +1419,8 @@ void vVessel::RenderLightCone(LPD3DXMATRIX pWT) D3DXVECTOR3 Circle[65]; WORD CIdx[130]; - VECTOR3 _X = crossp(_D, _V(0.4, 0.2, -0.6)); - VECTOR3 _Y = crossp(_D, _X); + VECTOR3 _X = cross(_D, {0.4, 0.2, -0.6}); + VECTOR3 _Y = cross(_D, _X); D3DXVECTOR3 _x = D3DXVEC(_X); D3DXVECTOR3 _y = D3DXVEC(_Y); @@ -1711,9 +1711,9 @@ void vVessel::RenderReentry(LPDIRECT3DDEVICE9 dev) VECTOR3 d; vessel->GetShipAirspeedVector(d); vessel->GlobalRot(d, d); - normalise(d); + d = unit(d); - float x = float(dotp(d, unit(cpos))); + float x = float(dot(d, unit(cpos))); if (x<0) x=-x; x=pow(x,0.3f); float alpha_B = (x*0.40f + 0.60f) * ints; diff --git a/OVP/D3D9Client/VectorHelpers.h b/OVP/D3D9Client/VectorHelpers.h deleted file mode 100644 index 843084014..000000000 --- a/OVP/D3D9Client/VectorHelpers.h +++ /dev/null @@ -1,343 +0,0 @@ -// ================================================================================================================================= -// The MIT Lisence: -// -// Copyright (C) 2013-2016 Jarmo Nikkanen -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation -// files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, -// modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software -// is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// ================================================================================================================================= - - -#include "OrbiterAPI.h" -#include - - -#ifndef __VECTORHELPERS_H -#define __VECTORHELPERS_H - -#if defined(_MSC_VER) && (_MSC_VER >= 1900 ) // Microsoft Visual Studio Version 2015 and higher - // exp2() and log2() are defined in -#define _constexpr_ constexpr - -#else // older MSVC++ versions - -inline double exp2(double d) -{ - return exp(d*0.69314718055994530941723212145818); -} - -inline float exp2(float d) -{ - return exp(d*0.693147180559945f); -} - -inline double log2(double d) -{ - return log(d*1.4426950408889634073599246810019); -} -inline float log2(float d) -{ - return log(d*1.442695040888963f); -} - -inline double log1p(double d) -{ - return log(d+1.0); -} -// inline float log1p(float d) -// { -// return log(d+1.0f); -// } -#define _constexpr_ -#endif - -template inline _constexpr_ T sign (T val) -{ - return val < T(0) ? T(-1) : T(1); -} - -template inline _constexpr_ T lerp (T a, T b, T x) -{ - return a + (b - a)*x; -} -// ...slightly faster than the above, but not available in Visual Studio 2012 (I think)? -//template inline _constexpr_ T lerp(T v0, T v1, T t) { -// return fma(t, v1, fma(-t, v0, v0)); -//} - -template inline _constexpr_ T saturate (T val) -{ - return (val > T(1)) ? T(1) - : (val < T(0)) ? T(0) - : val; -} - -template inline _constexpr_ T clamp(T x, T a, T b) -{ - return x > b ? b - : x < a ? a - : x; -} - -template inline _constexpr_ T ilerp(T a, T b, T x) -{ - return saturate((x - a) / (b - a)); -} - -template inline _constexpr_ T sqr(T a) -{ - return a * a; -} - -template inline _constexpr_ T hermite(T a) -{ - return a * a * (T(3) - T(2)*a); -} - - -// VECTOR3 Helpers ================================================================== -// -inline VECTOR3 &operator+= (VECTOR3 &v, double d) -{ - v.x+=d; v.y+=d; v.z+=d; - return v; -} - -inline VECTOR3 &operator-= (VECTOR3 &v, double d) -{ - v.x-=d; v.y-=d; v.z-=d; - return v; -} - -inline VECTOR3 operator+ (const VECTOR3 &v, double d) -{ - return _V(v.x+d, v.y+d, v.z+d); -} - -inline VECTOR3 operator- (const VECTOR3 &v, double d) -{ - return _V(v.x-d, v.y-d, v.z-d); -} - -inline VECTOR3 operator- (double d, const VECTOR3 &v) -{ - return _V(d-v.x, d-v.y, d-v.z); -} - -inline VECTOR3 exp2(const VECTOR3 &v) -{ - return _V(exp2(v.x), exp2(v.y), exp2(v.z)); -} - -inline VECTOR3 rcp(const VECTOR3 &v) -{ - return _V(1.0/v.x, 1.0/v.y, 1.0/v.z); -} - -inline VECTOR3 vmax(const VECTOR3 &v, const VECTOR3 &w) -{ - return _V(std::max(v.x, w.x), std::max(v.y, w.y), std::max(v.z, w.z)); -} - -inline VECTOR3 vmin(const VECTOR3 &v, const VECTOR3 &w) -{ - return _V(std::min(v.x, w.x), std::min(v.y, w.y), std::min(v.z, w.z)); -} - - -// VECTOR4 Helpers ================================================================== -// -// -inline VECTOR4 &operator+= (VECTOR4 &v, double d) -{ - v.x+=d; v.y+=d; v.z+=d; v.w+=d; - return v; -} - -inline VECTOR4 &operator-= (VECTOR4 &v, double d) -{ - v.x-=d; v.y-=d; v.z-=d; v.w-=d; - return v; -} - -inline VECTOR4 operator+ (const VECTOR4 &v, double d) -{ - return _V(v.x+d, v.y+d, v.z+d, v.w+d); -} - -inline VECTOR4 operator- (const VECTOR4 &v, double d) -{ - return _V(v.x-d, v.y-d, v.z-d, v.w-d); -} - -inline VECTOR4 operator- (double d, const VECTOR4 &v) -{ - return _V(d-v.x, d-v.y, d-v.z, d-v.w); -} - -inline VECTOR4 &operator*= (VECTOR4 &v, double d) -{ - v.x*=d; v.y*=d; v.z*=d; v.w*=d; - return v; -} - -inline VECTOR4 &operator/= (VECTOR4 &v, double d) -{ - d=1.0/d; v.x*=d; v.y*=d; v.z*=d; v.w*=d; - return v; -} - -inline VECTOR4 operator* (const VECTOR4 &v, double d) -{ - return _V(v.x*d, v.y*d, v.z*d, v.w*d); -} - -inline VECTOR4 operator/ (const VECTOR4 &v, double d) -{ - d=1.0/d; return _V(v.x*d, v.y*d, v.z*d, v.w*d); -} - -inline double dotp(const VECTOR4 &v, const VECTOR4 &w) -{ - return v.x*w.x + v.y*w.y + v.z*w.z + v.w*w.w; -} - -inline double length(const VECTOR4 &v) -{ - return sqrt(dotp(v,v)); -} - -inline VECTOR4 normalize(const VECTOR4 &v) -{ - return v*(1.0/sqrt(dotp(v,v))); -} - -inline VECTOR4 exp2(const VECTOR4 &v) -{ - return _V(exp2(v.x), exp2(v.y), exp2(v.z), exp2(v.w)); -} - -inline VECTOR4 rcp(const VECTOR4 &v) -{ - return _V(1.0/v.x, 1.0/v.y, 1.0/v.z, 1.0/v.w); -} - -inline VECTOR4 vmax(const VECTOR4 &v, const VECTOR4 &w) -{ - return _V(std::max(v.x, w.x), std::max(v.y, w.y), std::max(v.z, w.z), std::max(v.w, w.w)); -} - -inline VECTOR4 vmin(const VECTOR4 &v, const VECTOR4 &w) -{ - return _V(std::min(v.x, w.x), std::min(v.y, w.y), std::min(v.z, w.z), std::min(v.w, w.w)); -} - - -// D3DXVECTOR3 Helpers ================================================================== -// -// - -inline D3DXVECTOR3 exp2(const D3DXVECTOR3 &v) -{ - return D3DXVECTOR3(exp2(v.x), exp2(v.y), exp2(v.z)); -} - -inline D3DXVECTOR3 _D3DXVECTOR3(const VECTOR3 &v) -{ - return D3DXVECTOR3(float(v.x), float(v.y), float(v.z)); -} - -inline D3DXVECTOR3 _D3DXVECTOR3(double x, double y, double z) -{ - return D3DXVECTOR3(float(x), float(y), float(z)); -} - -inline D3DXVECTOR3 operator* (const D3DXVECTOR3 &a, const D3DXVECTOR3 &b) -{ - return D3DXVECTOR3(a.x*b.x, a.y*b.y, a.z*b.z); -} - -inline D3DXVECTOR3 operator+ (const D3DXVECTOR3 &a, float d) -{ - return D3DXVECTOR3(a.x+d, a.y+d, a.z+d); -} - -inline D3DXVECTOR3 &operator*= (D3DXVECTOR3 &a, const D3DXVECTOR3 &b) -{ - a.x *= b.x; a.y *= b.y; a.z *= b.z; - return a; -} - -inline D3DXVECTOR3 &operator+= (D3DXVECTOR3 &a, float d) -{ - a.x += d; a.y += d; a.z += d; - return a; -} - -inline D3DXVECTOR3 rcp(const D3DXVECTOR3 &v) -{ - return D3DXVECTOR3(1.0f/v.x, 1.0f/v.y, 1.0f/v.z); -} - -inline D3DXVECTOR3 vmax(const D3DXVECTOR3 &v, const D3DXVECTOR3 &w) -{ - return D3DXVECTOR3(std::max(v.x, w.x), std::max(v.y, w.y), std::max(v.z, w.z)); -} - -inline D3DXVECTOR3 vmin(const D3DXVECTOR3 &v, const D3DXVECTOR3 &w) -{ - return D3DXVECTOR3(std::min(v.x, w.x), std::min(v.y, w.y), std::min(v.z, w.z)); -} - -inline D3DXVECTOR3 lerp(const D3DXVECTOR3 &v, const D3DXVECTOR3 &w, float x) -{ - return D3DXVECTOR3(v.x+(w.x-v.x)*x, v.y+(w.y-v.y)*x, v.z+(w.z-v.z)*x); -} - - - -// D3DXVECTOR4 Helpers ================================================================== -// -// -inline D3DXVECTOR4 abs(D3DXVECTOR4 &a) -{ - return D3DXVECTOR4(abs(a.x), abs(a.y), abs(a.z), abs(a.w)); -} - -inline D3DXVECTOR4 sign(D3DXVECTOR4 &a) -{ - return D3DXVECTOR4(sign(a.x), sign(a.y), sign(a.z), sign(a.w)); -} - -inline D3DXVECTOR4 pow(float x, D3DXVECTOR4 &y) -{ - return D3DXVECTOR4(pow(x, y.x), pow(x, y.y), pow(x, y.z), pow(x, y.w)); -} - -inline D3DXVECTOR4 operator- (const D3DXVECTOR4 &v, float d) -{ - return D3DXVECTOR4(v.x-d, v.y-d, v.z-d, v.w-d); -} - -inline D3DXVECTOR4 operator+ (const D3DXVECTOR4 &v, float d) -{ - return D3DXVECTOR4(v.x+d, v.y+d, v.z+d, v.w+d); -} - -inline D3DXVECTOR4 &operator*= (D3DXVECTOR4 &v, const D3DXVECTOR4 &d) -{ - v.x*=d.x; v.y*=d.y; v.z*=d.z; v.w*=d.w; - return v; -} - -#endif - diff --git a/OVP/D3D9Client/gcConst.h b/OVP/D3D9Client/gcConst.h index 9c4461c83..b537acdfa 100644 --- a/OVP/D3D9Client/gcConst.h +++ b/OVP/D3D9Client/gcConst.h @@ -659,7 +659,7 @@ class gcConst */ inline void WorldMatrix(FMATRIX4 *mat, const VECTOR3 &pos, const VECTOR3 &x, const VECTOR3 &z, double scale = 1.0) { - VECTOR3 y = crossp(x, z); + VECTOR3 y = cross(x, z); mat->m11 = float(x.x * scale); mat->m12 = float(x.y * scale); mat->m13 = float(x.z * scale); mat->m14 = 0.0f; mat->m21 = float(y.x * scale); mat->m22 = float(y.y * scale); mat->m23 = float(y.z * scale); mat->m24 = 0.0f; mat->m31 = float(z.x * scale); mat->m32 = float(z.y * scale); mat->m33 = float(z.z * scale); mat->m34 = 0.0f; diff --git a/OVP/D3D9Client/gcCore.cpp b/OVP/D3D9Client/gcCore.cpp index 7c9330d6a..164d8af24 100644 --- a/OVP/D3D9Client/gcCore.cpp +++ b/OVP/D3D9Client/gcCore.cpp @@ -182,7 +182,7 @@ void gcCore::ReleaseSwap(HSWAP hSwap) // CAMERAHANDLE gcCore::SetupCustomCamera(CAMERAHANDLE hCam, OBJHANDLE hVessel, VECTOR3 &pos, VECTOR3 &dir, VECTOR3 &up, double fov, SURFHANDLE hSurf, DWORD flags) { - VECTOR3 x = crossp(up, dir); + VECTOR3 x = cross(up, dir); MATRIX3 mTake; mTake.m11 = x.x; mTake.m21 = x.y; mTake.m31 = x.z; mTake.m12 = up.x; mTake.m22 = up.y; mTake.m32 = up.z; diff --git a/OVP/D3D9Client/gcCore.h b/OVP/D3D9Client/gcCore.h index f8634acab..f8695bad4 100644 --- a/OVP/D3D9Client/gcCore.h +++ b/OVP/D3D9Client/gcCore.h @@ -784,7 +784,7 @@ INTERFACE_BUILDER class gcCore */ inline void WorldMatrix(FMATRIX4* mat, const VECTOR3& pos, const VECTOR3& x, const VECTOR3& z, double scale = 1.0) { - VECTOR3 y = crossp(x, z); + VECTOR3 y = cross(x, z); mat->m11 = float(x.x * scale); mat->m12 = float(x.y * scale); mat->m13 = float(x.z * scale); mat->m14 = 0.0f; mat->m21 = float(y.x * scale); mat->m22 = float(y.y * scale); mat->m23 = float(y.z * scale); mat->m24 = 0.0f; mat->m31 = float(z.x * scale); mat->m32 = float(z.y * scale); mat->m33 = float(z.z * scale); mat->m34 = 0.0f; diff --git a/OVP/D3D9Client/samples/DrawOrbits/Draw.cpp b/OVP/D3D9Client/samples/DrawOrbits/Draw.cpp index 1e981566d..4eb49dac7 100644 --- a/OVP/D3D9Client/samples/DrawOrbits/Draw.cpp +++ b/OVP/D3D9Client/samples/DrawOrbits/Draw.cpp @@ -239,7 +239,7 @@ void Orbits::clbkPreStep(double simt, double simdt, double mjd) // Compute/Update orbit line intensity --------------------------------------- // Fade away orbits viewed from a shallow angle - float f = float(pow(abs(dotp(rdir, pO->_W)), 0.2)); + float f = float(std::pow(std::abs(dot(rdir, pO->_W)), 0.2)); if (f < 0.6f) f = 0.6f; @@ -328,7 +328,7 @@ void Orbits::SetClipper(Sketchpad *pSkp2, OBJHANDLE hObj, DWORD idx) Clip[idx].Pos = (bpos - CamPos); // Object position Clip[idx].dRad = dRad; - double len2 = dotp(Clip[idx].Pos, Clip[idx].Pos); + double len2 = dot(Clip[idx].Pos, Clip[idx].Pos); double hdst = sqrt(len2 - dRad*dRad); double ilen = 1.0 / sqrt(len2); @@ -396,7 +396,7 @@ bool Orbits::IsVisible(VECTOR3 pos, oapi::IVECTOR2 *pt, const SIZE &s) double len = length(pos); VECTOR3 uPos = pos / len; - for (int i = 0; i < 2; i++) if ((Clip[i].vcov < dotp(Clip[i].uPos, uPos)) && (len > Clip[i].hdst)) return false; + for (int i = 0; i < 2; i++) if ((Clip[i].vcov < dot(Clip[i].uPos, uPos)) && (len > Clip[i].hdst)) return false; return WorldToScreenSpace(pos, pt, pVP, s); } diff --git a/OVP/D3D9Client/samples/DrawOrbits/Orbit.cpp b/OVP/D3D9Client/samples/DrawOrbits/Orbit.cpp index 4000c42df..a0d161fd9 100644 --- a/OVP/D3D9Client/samples/DrawOrbits/Orbit.cpp +++ b/OVP/D3D9Client/samples/DrawOrbits/Orbit.cpp @@ -262,7 +262,7 @@ double COrbit::RelTrAByMJD(double mjd) const // double COrbit::TrAOfProjection(const VECTOR3 _p) const { - return limit(atan2(dotp(_p, _Q), dotp(_p, _P))); + return limit(std::atan2(dot(_p, _Q), dot(_p, _P))); } // ================================================================================================= @@ -270,7 +270,7 @@ double COrbit::TrAOfProjection(const VECTOR3 _p) const double COrbit::TrAOfAscendingNode(const VECTOR3 _n) const { VECTOR3 _p = crossp_LH(_n, _W); - return limit(atan2(dotp(_p, _Q), dotp(_p, _P))); + return limit(std::atan2(dot(_p, _Q), dot(_p, _P))); } // ================================================================================================= @@ -299,7 +299,7 @@ double COrbit::Inc() const double COrbit::LAN() const { VECTOR3 _p = crossp_LH(_Pol, _W); - double x = atan2(dotp(_p, _Aux), dotp(_p, _Equ)); + double x = std::atan2(dot(_p, _Aux), dot(_p, _Equ)); if (x<0) return PI2 + x; return x; } @@ -308,7 +308,7 @@ double COrbit::LAN() const double COrbit::AgP() const { VECTOR3 _p = crossp_LH(_Pol, _W); - return PI2 - limit(atan2(dotp(_p, _Q), dotp(_p, _P))); + return PI2 - limit(std::atan2(dot(_p, _Q), dot(_p, _P))); } // ================================================================================================= @@ -418,7 +418,7 @@ void COrbit::CreateFromStateVectors(const VECTOR3 &_pos, const VECTOR3 &_vel, do double om = 1.0 / mu; // Eccentricity VECTOR3 - _P = ((_pos * (v2 - mu* Or )) - (_vel * dotp(_pos, _vel))) * om; + _P = ((_pos * (v2 - mu* Or )) - (_vel * dot(_pos, _vel))) * om; _H = crossp_LH(_pos, _vel); _Q = unit(crossp_LH(_H, _P)); _R = _pos* Or ; @@ -430,7 +430,7 @@ void COrbit::CreateFromStateVectors(const VECTOR3 &_pos, const VECTOR3 &_vel, do ecc = 0.0; VECTOR3 _i = unit(crossp_LH(_K_ECL, _H)); VECTOR3 _j = unit(crossp_LH(_H, _i)); - _P = -unit(_j*dotp(_i, _J_ECL) - _i*dotp(_i, _I_ECL)); + _P = -unit(_j * dot(_i, _J_ECL) - _i * dot(_i, _I_ECL)); _Q = unit(crossp_LH(_H, _P)); par = sqrlen(_H)*om; sma = par; @@ -443,12 +443,12 @@ void COrbit::CreateFromStateVectors(const VECTOR3 &_pos, const VECTOR3 &_vel, do // Calculate True anomaly // - double x = dotp(_P, _R); + double x = dot(_P, _R); if (x >= 1.0) tra = 0.0; else if (x <= -1.0) tra = PI; else { tra = acos(x); - x = dotp(_pos, _vel); + x = dot(_pos, _vel); if (fabs(x)<1e-9) x = 0.0; // Avoid some precision problems if (x <= 0.0) tra = PI2 - tra; } @@ -508,7 +508,7 @@ void COrbit::CreateFromElements(const ELEMENTS *Elem, double iMu, double iEpoch) void COrbit::EscapeOrbit(const VECTOR3 &_Pos, const VECTOR3 &_Esc, double Mu, double MJD, double Dir) { VECTOR3 _H = crossp_LH(_Pos, _Esc); - double Es2 = dotp(_Esc, _Esc); + double Es2 = dot(_Esc, _Esc); mu = Mu; sma = -mu / Es2; diff --git a/OVP/D3D9Client/samples/DrawOrbits/Reference.cpp b/OVP/D3D9Client/samples/DrawOrbits/Reference.cpp index f44f6b770..5bd0dcadc 100644 --- a/OVP/D3D9Client/samples/DrawOrbits/Reference.cpp +++ b/OVP/D3D9Client/samples/DrawOrbits/Reference.cpp @@ -99,12 +99,12 @@ OBJHANDLE ReferenceClass::FindGravityReference(OBJHANDLE body) // Compute Eccentricity double myy = mass * GC; - double v = length(vel); - double r = length(pos); - double e = length( ( (pos * ((v*v)-(myy/r))) - (vel * dotp(pos,vel)) ) * (1/myy) ); + double v = len(vel); + double r = len(pos); + double e = len(((pos * ((v * v) - (myy / r))) - (vel * dot(pos, vel))) * (1 / myy)); if (e<1) { - distance=length(pos); + distance = len(pos); force=(GC*mass)/(distance*distance); if (force>gf) gf=force, gr_ref=obj, gr_dist=distance; } @@ -151,7 +151,7 @@ void ReferenceClass::CreateDatabase() if (References[j].grf_handle==ref && References[j].handle!=ref) { // Anything orbiting this object oapiGetRelativePos(References[j].handle,ref,&pos); // Compute it's distance - distance = length(pos) * 1.5; + distance = len(pos) * 1.5; if (References[i].dist0 && References[i].handle!=StarHandle) { // does this ReferenceClass have an distance setting nref=References[i].handle; oapiGetRelativePos(x,nref,&distance); - if (length(distance)GetGroupThrusterCount(engine); @@ -187,7 +187,7 @@ VECTOR3 GetThrusterGroupDir_LH(VESSEL *ship, THGROUP_TYPE engine) // VECTOR3 GetThrusterGroupThrustVector_LH(VESSEL *ship, THGROUP_TYPE engine) { - VECTOR3 d, dir = _V(0, 0, 0); + VECTOR3 d, dir = {0, 0, 0}; int i, c = ship->GetGroupThrusterCount(engine); for (i = 0; i= 1.0) return 0.0; else if (x <= -1.0) return PI; return(acos(x)); } @@ -145,7 +145,7 @@ inline double angle(const VECTOR3 &v, const VECTOR3 &h) /*! \details Return angle between two unit vectors */ inline double anglen(const VECTOR3 &v, const VECTOR3 &h) { - double x = dotp(v, h); + double x = dot(v, h); if (x >= 1.0) return 0.0; else if (x <= -1.0) return PI; return(acos(x)); } @@ -179,7 +179,7 @@ If they are allreay normalized use GetAngle2() instead. */ inline double GetAngle(const VECTOR3 &_p, const VECTOR3 &_I, const VECTOR3 &_J) { - double x = atan2(dotp(_p, unit(_J)), dotp(_p, unit(_I))); + double x = std::atan2(dot(_p, unit(_J)), dot(_p, unit(_I))); if (x<0) return PI2 + x; return x; } @@ -189,7 +189,7 @@ inputs are not normalized internally, must be normalized externally. Vector _p d */ inline double GetAngleN(const VECTOR3 &_p, const VECTOR3 &_I, const VECTOR3 &_J) { - double x = atan2(dotp(_p, _J), dotp(_p, _I)); + double x = std::atan2(dot(_p, _J), dot(_p, _I)); if (x<0) return PI2 + x; return x; } diff --git a/OVP/D3D9Client/samples/GenericCamera/MFD.cpp b/OVP/D3D9Client/samples/GenericCamera/MFD.cpp index f90b46446..402a10363 100644 --- a/OVP/D3D9Client/samples/GenericCamera/MFD.cpp +++ b/OVP/D3D9Client/samples/GenericCamera/MFD.cpp @@ -191,9 +191,9 @@ void CameraMFD::SelectVessel(VESSEL *hVes, Type _type) VECTOR3 pos, dir, rot; - pos = _V(0, 0, 0); - dir = _V(1, 0, 0); - rot = _V(0, 1, 0); + pos = {0, 0, 0}; + dir = {1, 0, 0}; + rot = {0, 1, 0}; type = _type; diff --git a/OVP/D3D9Client/samples/TerrainToolBox/Basics.cpp b/OVP/D3D9Client/samples/TerrainToolBox/Basics.cpp index c404116d8..fa3dd1fee 100644 --- a/OVP/D3D9Client/samples/TerrainToolBox/Basics.cpp +++ b/OVP/D3D9Client/samples/TerrainToolBox/Basics.cpp @@ -51,7 +51,7 @@ FMATRIX4 ToolKit::CreateWorldMatrix(OBJHANDLE hPlanet, double lng, double lat, d double rad = oapiGetSize(hPlanet) + elev; MATRIX3 mRot; oapiGetRotationMatrix(hPlanet, &mRot); - VECTOR3 vRot = mul(mRot, _V(0, 1, 0)); + VECTOR3 vRot = mul(mRot, VECTOR3{0, 1, 0}); VECTOR3 lpos, cpos, gp; oapiEquToLocal(hPlanet, lng, lat, rad, &lpos); @@ -63,8 +63,8 @@ FMATRIX4 ToolKit::CreateWorldMatrix(OBJHANDLE hPlanet, double lng, double lat, d FMATRIX4 m; VECTOR3 y = unit(lpos); // up - VECTOR3 x = unit(crossp(y, vRot)); // west - VECTOR3 z = crossp(x, y); // north + VECTOR3 x = unit(cross(y, vRot)); // west + VECTOR3 z = cross(x, y); // north VECTOR3 p = ((gp + lpos) - cpos); x *= scale; @@ -428,5 +428,5 @@ VECTOR3 ToolKit::GetSurfacePosUnit(double lng, double lat) MATRIX3 mRot; double w = cos(lat); oapiGetRotationMatrix(hPlanet, &mRot); - return mul(mRot, _V(w*cos(lng), sin(lat), w*sin(lng))); + return mul(mRot, VECTOR3{w * cos(lng), sin(lat), w * sin(lng)}); } diff --git a/Orbitersdk/include/DrawAPI.h b/Orbitersdk/include/DrawAPI.h index 1f7a303dd..c2a6a053b 100644 --- a/Orbitersdk/include/DrawAPI.h +++ b/Orbitersdk/include/DrawAPI.h @@ -21,11 +21,6 @@ #include "OrbiterAPI.h" #include -#include - -#ifdef D3D9CLIENT_EXPORTS -#include "d3dx9.h" -#endif /// \brief Poly object handle typedef void* HPOLY; @@ -210,20 +205,6 @@ namespace oapi { z = float(v.z); } -#ifdef D3D9CLIENT_EXPORTS - FVECTOR3(const D3DXVECTOR3 &v) - { - x = float(v.x); - y = float(v.y); - z = float(v.z); - } - FVECTOR3(const D3DXCOLOR& v) - { - x = float(v.r); - y = float(v.g); - z = float(v.b); - } -#endif float MaxRGB() const { return (std::max)(r, (std::max)(g, b)); @@ -335,16 +316,6 @@ namespace oapi { return FVECTOR3(-x, -y, -z); } -#ifdef D3D9CLIENT_EXPORTS - inline operator D3DXVECTOR3() const - { - return D3DXVECTOR3(x, y, z); - } - inline operator D3DXCOLOR() const - { - return D3DXCOLOR(x, y, z, 1); - } -#endif struct { float x, y, z; }; struct { float r, g, b; }; FVECTOR2 xy; @@ -472,24 +443,6 @@ namespace oapi { w = float(_w); } -#ifdef D3D9CLIENT_EXPORTS - FVECTOR4(const D3DXVECTOR4& v) - { - x = float(v.x); - y = float(v.y); - z = float(v.z); - w = float(v.w); - } - FVECTOR4(const D3DXCOLOR& v) - { - x = float(v.r); - y = float(v.g); - z = float(v.b); - w = float(v.a); - } -#endif - - inline FVECTOR4 operator* (float f) const { return FVECTOR4(x * f, y * f, z * f, w * f); @@ -552,13 +505,6 @@ namespace oapi { return FVECTOR4(-x, -y, -z, -w); } -#ifdef D3D9CLIENT_EXPORTS - inline operator D3DXVECTOR4() const - { - return D3DXVECTOR4(x, y, z, w); - } -#endif - __m128 xm; float data[4]; struct { float x, y, z, w; }; struct { float r, g, b, a; }; @@ -625,21 +571,6 @@ namespace oapi { for (int i = 0; i < 16; i++) data[i] = pSrc[i]; } -#ifdef D3D9CLIENT_EXPORTS - FMATRIX4(const D3DXMATRIX& m) - { - memcpy_s(data, sizeof(FMATRIX4), &m, sizeof(m)); - } - FMATRIX4(const LPD3DXMATRIX m) - { - memcpy_s(data, sizeof(FMATRIX4), m, sizeof(FMATRIX4)); - } - inline operator LPD3DXMATRIX() - { - return (LPD3DXMATRIX)this; - } -#endif - void Zero() { for (int i = 0; i < 16; i++) data[i] = 0.0; @@ -763,23 +694,14 @@ namespace oapi { return FVECTOR3(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x); } - inline float saturate(float x) - { - //sadly std::clamp produces garbage assembly on both gcc and MSVC - //this version makes MSVC produce good code - x = (x < 0.0f) ? 0.0f : x; - x = (x > 1.0f) ? 1.0f : x; - return x; - } - inline FVECTOR3 saturate(const FVECTOR3& v) { - return FVECTOR3(saturate(v.x), saturate(v.y), saturate(v.z)); + return FVECTOR3(::saturate(v.x), ::saturate(v.y), ::saturate(v.z)); } inline FVECTOR4 saturate(const FVECTOR4& v) { - return FVECTOR4(saturate(v.x), saturate(v.y), saturate(v.z), saturate(v.w)); + return FVECTOR4(::saturate(v.x), ::saturate(v.y), ::saturate(v.z), ::saturate(v.w)); } inline FVECTOR2 lerp(const FVECTOR2& a, const FVECTOR2& b, float x) diff --git a/Orbitersdk/include/OrbiterAPI.h b/Orbitersdk/include/OrbiterAPI.h index 8f372c420..cd8dc1bad 100644 --- a/Orbitersdk/include/OrbiterAPI.h +++ b/Orbitersdk/include/OrbiterAPI.h @@ -11,24 +11,28 @@ * \file OrbiterAPI.h * \brief General API interface functions * \todo Check functions in VESSELSTATUS2::arot and oapiGetPlanetObliquityMatrix(), - * minus sign has changed a place in a matrix. Is this correct?? + * minus sign has changed a place in a matrix. Is this correct?? * \todo class CameraMode documentation */ -#ifndef __ORBITERAPI_H -#define __ORBITERAPI_H +#ifndef ORBITERAPI_H +#define ORBITERAPI_H -#if defined(_MSC_VER) && (_MSC_VER >= 1300 ) // Microsoft Visual Studio Version 2003 and higher -#if !defined(_CRT_SECURE_NO_DEPRECATE) -#define _CRT_SECURE_NO_DEPRECATE -#endif +#if defined(_MSC_VER) && (_MSC_VER >= 1300) // Microsoft Visual Studio Version 2003 and higher + #if !defined(_CRT_SECURE_NO_DEPRECATE) + #define _CRT_SECURE_NO_DEPRECATE + #endif #endif + +#include "math.hpp" +#include "vector.hpp" + +#include #include -#include -#include -#include #include +#include + extern "C" { #include "Lua/lua.h" } @@ -39,18 +43,18 @@ extern "C" { #define DLLCLBK extern "C" __declspec(dllexport) #ifdef OAPI_IMPLEMENTATION -#define OAPIFUNC DLLEXPORT + #define OAPIFUNC DLLEXPORT #else -#define OAPIFUNC DLLIMPORT + #define OAPIFUNC DLLIMPORT #endif #pragma warning(disable: 4201) // Message loop return type - maintain backward compatibility for 32-bit #ifdef _WIN64 -#define OAPI_MSGTYPE LRESULT + #define OAPI_MSGTYPE LRESULT #else -#define OAPI_MSGTYPE int + #define OAPI_MSGTYPE int #endif // ====================================================================== @@ -60,11 +64,11 @@ extern "C" { const double PI = 3.14159265358979323846; ///< pi const double PI05 = 1.57079632679489661923; ///< pi/2 const double PI2 = 6.28318530717958647693; ///< pi*2 -const double RAD = PI/180.0; ///< factor to map degrees to radians -const double DEG = 180.0/PI; ///< factor to map radians to degrees -const double C0 = 299792458.0; ///< speed of light in vacuum [m/s] +const double RAD = PI / 180; ///< factor to map degrees to radians +const double DEG = 180 / PI; ///< factor to map radians to degrees +const double C0 = 299792458; ///< speed of light in vacuum [m/s] const double TAUA = 499.004783806; ///< light time for 1 AU [s] -const double AU = C0*TAUA; ///< astronomical unit (mean geocentric distance of the sun) [m] +const double AU = C0 * TAUA; ///< astronomical unit (mean geocentric distance of the sun) [m] const double GGRAV = 6.67259e-11; ///< gravitational constant [m^3 kg^-1 s^-2] const double G = 9.81; ///< gravitational acceleration [m/s^2] at Earth mean radius const double ATMP = 101.4e3; ///< atmospheric pressure [Pa] at Earth sea level @@ -79,10 +83,10 @@ const double ATMD = 1.293; ///< atmospheric density [kg/m^3] at Earth s * \param angle input angle [rad] * \return normalised angle [rad] */ -inline double normangle (double angle) +inline double normangle(double angle) { - double a = fmod (angle, PI2); - return (a >= PI ? a-PI2 : a < -PI ? a+PI2 : a); + double a = std::fmod(angle, PI2); + return a >= PI ? (a - PI2) : a < -PI ? (a + PI2) : a; } /** @@ -90,10 +94,10 @@ inline double normangle (double angle) * \param angle input angle [rad] * \return normalised angle [rad] */ -inline double posangle (double angle) +inline double posangle(double angle) { - double a = fmod (angle, PI2); - return (a >= 0.0 ? a : a+PI2); + double a = std::fmod(angle, PI2); + return a >= 0 ? a : (a + PI2); } /** @@ -106,7 +110,7 @@ inline double posangle (double angle) * with 'k', 'M', 'G' postfixes as required * \note cbuf must be allocated to sufficient size to hold the string */ -OAPIFUNC void FormatValue (char *cbuf, int n, double f, int precision=4); +OAPIFUNC void FormatValue(char *cbuf, int n, double f, int precision = 4); // ====================================================================== // API data types @@ -138,81 +142,79 @@ namespace oapi { // ====================================================================== //@{ /// \brief Handle for objects (vessels, stations, planets) -typedef void *OBJHANDLE; +using OBJHANDLE = void *; /// \brief Handle for vessel superstructures -typedef void *SUPERVESSELHANDLE; +using SUPERVESSELHANDLE = void *; /// \brief Handle for visuals -typedef void *VISHANDLE; +using VISHANDLE = void *; /// \brief Handle for meshes -typedef void *MESHHANDLE; +using MESHHANDLE = void *; /// \brief Handle for graphics-client-specific meshes -typedef int *DEVMESHHANDLE; -//struct DEVMESHHANDLE { -// DEVMESHHANDLE() { hMesh = NULL; } -// DEVMESHHANDLE(MESHHANDLE h) { hMesh = h; } -// DWORD id; -// MESHHANDLE hMesh; -// operator int() { return (int)hMesh; } -//}; +using DEVMESHHANDLE = int *; /// \brief Handle for bitmap surfaces and textures (panels and panel items) -typedef void *SURFHANDLE; +using SURFHANDLE = void *; /// \brief Handle for 2D instrument panels -typedef void *PANELHANDLE; +using PANELHANDLE = void *; /// \brief Handle for file streams -typedef void *FILEHANDLE; +using FILEHANDLE = void *; /// \brief Handle for script interpreters -typedef void *INTERPRETERHANDLE; +using INTERPRETERHANDLE = void *; /// \brief Handle for thrusters -typedef void *THRUSTER_HANDLE; +using THRUSTER_HANDLE = void *; /// \brief Handle for logical thruster groups -typedef void *THGROUP_HANDLE; +using THGROUP_HANDLE = void *; /// \brief Propellant resource handle -typedef void *PROPELLANT_HANDLE; +using PROPELLANT_HANDLE = void *; /// \brief Handle for particle streams -typedef void *PSTREAM_HANDLE; +using PSTREAM_HANDLE = void *; /// \brief Handle for vessel docking ports -typedef void *DOCKHANDLE; +using DOCKHANDLE = void *; /// \brief Handle vor vessel passive attachment points -typedef void *ATTACHMENTHANDLE; +using ATTACHMENTHANDLE = void *; /// \brief Handle for vessel airfoils -typedef void *AIRFOILHANDLE; +using AIRFOILHANDLE = void *; /// \brief Handle for vessel aerodynamic control surfaces -typedef void *CTRLSURFHANDLE; +using CTRLSURFHANDLE = void *; /// \brief Handle for a navigation radio transmitter (VOR, ILS, IDS, XPDR) -typedef void *NAVHANDLE; +using NAVHANDLE = void *; /// \brief Handle for animation components -typedef void *ANIMATIONCOMPONENT_HANDLE; +using ANIMATIONCOMPONENT_HANDLE = void *; /// \brief Handle for custom items added to Launchpad "Extra" list -typedef void *LAUNCHPADITEM_HANDLE; +using LAUNCHPADITEM_HANDLE = void *; /// \brief Handle for onscreen annotation objects -typedef void *NOTEHANDLE; +using NOTEHANDLE = void *; /// \brief Handle for elevation query managers -typedef void *ELEVHANDLE; +using ELEVHANDLE = void *; //@} -typedef enum { FILE_IN, FILE_OUT, FILE_APP, FILE_IN_ZEROONFAIL } FileAccessMode; -typedef enum { ROOT, CONFIG, SCENARIOS, TEXTURES, TEXTURES2, MESHES, MODULES } PathRoot; +enum FileAccessMode { + FILE_IN, FILE_OUT, FILE_APP, FILE_IN_ZEROONFAIL +}; + +enum PathRoot { + ROOT, CONFIG, SCENARIOS, TEXTURES, TEXTURES2, MESHES, MODULES +}; /// \defgroup surfid Identifiers for special render surfaces /// @{ @@ -231,22 +233,6 @@ typedef enum { ROOT, CONFIG, SCENARIOS, TEXTURES, TEXTURES2, MESHES, MODULES } P */ // =========================================================================== //@{ -/** - * \brief 3-element vector - */ -typedef union { - double data[3]; ///< array data interface - struct { double x, y, z; }; ///< named data interface -} VECTOR3; - -/** - * \brief 4-element vector - */ -typedef union { - double data[4]; ///< array data interface - struct { double x, y, z, w; }; ///< named data interface -} VECTOR4; - /** * \brief 3x3-element matrix */ @@ -1354,8 +1340,8 @@ typedef struct { * (translation, rotation or scaling). * \sa VESSEL::MeshgroupTransform */ -typedef struct { - union { +struct MESHGROUP_TRANSFORM { + union data { struct { VECTOR3 ref; ///< rotation reference point VECTOR3 axis; ///< rotation axis direction @@ -1367,11 +1353,20 @@ typedef struct { struct { VECTOR3 scale; ///< scaling factor } scaleparam; + data() { } } P; int nmesh; ///< mesh index (>= 0) int ngrp; ///< group index (>= 0, or < 0 to indicate entire mesh) - enum { TRANSLATE, ROTATE, SCALE } transform; ///< transformation flag -} MESHGROUP_TRANSFORM; + enum trans_t { TRANSLATE, ROTATE, SCALE } transform; ///< transformation flag + + MESHGROUP_TRANSFORM() { } + MESHGROUP_TRANSFORM(double sx, double sy, double sz, int nmesh, int ngrp, trans_t trans) : + nmesh{nmesh}, ngrp{ngrp}, transform{trans} + { P.transparam = {{sx, sy, sz}}; } + MESHGROUP_TRANSFORM(double rx, double ry, double rz, double ax, double ay, double az, float angle, int nmesh, int ngrp, trans_t trans) : + nmesh{nmesh}, ngrp{ngrp}, transform{trans} + { P.rotparam = {{rx, ry, rz}, {ax, ay, az}, angle}; } +}; #pragma pack(pop) // Animation component (obsolete) @@ -6969,261 +6964,6 @@ OAPIFUNC void oapiTriggerRedrawArea (int panel_id, int vc_id, int area_id); // Some helper functions // ====================================================================== -/** - * \ingroup vec - * \brief Vector composition - * - * Returns a vector composed of the three provided arguments - * \param x x-component - * \param y y-component - * \param z z-component - * \return vector defined as (x,y,z) - */ -inline VECTOR3 _V(double x, double y, double z) -{ - VECTOR3 vec = {x,y,z}; return vec; -} - -/** - * \ingroup vec - * \brief Vector copy - * - * Copies the element values from the source to the target vector. - * \param[out] a target vector - * \param[in] b source vector - */ -inline void veccpy (VECTOR3 &a, const VECTOR3 &b) -{ - a.x = b.x; - a.y = b.y; - a.z = b.z; -} - -/** - * \ingroup vec - * \brief Vector addition - * \param a first vector operand - * \param b second vector operand - * \return Result of a+b. - */ -inline VECTOR3 operator+ (const VECTOR3 &a, const VECTOR3 &b) -{ - VECTOR3 c; - c.x = a.x+b.x; - c.y = a.y+b.y; - c.z = a.z+b.z; - return c; -} - -/** - * \ingroup vec - * \brief Vector subtraction - * \param a first vector operand - * \param b second vector operand - * \return Result of a-b. - */ -inline VECTOR3 operator- (const VECTOR3 &a, const VECTOR3 &b) -{ - VECTOR3 c; - c.x = a.x-b.x; - c.y = a.y-b.y; - c.z = a.z-b.z; - return c; -} - -/** - * \ingroup vec - * \brief Multiplication of vector with scalar - * \param a vector operand - * \param f scalar operand - * \return Result of element-wise a*f. - */ -inline VECTOR3 operator* (const VECTOR3 &a, const double f) -{ - VECTOR3 c; - c.x = a.x*f; - c.y = a.y*f; - c.z = a.z*f; - return c; -} - -/** - * \ingroup vec - * \brief Division of vector by a scalar - * \param a vector operand - * \param f scalar operand - * \return Result of element-wise a/f. - */ -inline VECTOR3 operator/ (const VECTOR3 &a, const double f) -{ - VECTOR3 c; - c.x = a.x/f; - c.y = a.y/f; - c.z = a.z/f; - return c; -} - -/** - * \ingroup vec - * \brief Vector addition-assignment a += b - * \param[in,out] a Left-hand vector operand - * \param[in] b Right-hand vector operand - * \return Replaces a with a+b and returns the result. - */ -inline VECTOR3 &operator+= (VECTOR3 &a, const VECTOR3 &b) -{ - a.x += b.x; - a.y += b.y; - a.z += b.z; - return a; -} - -/** - * \ingroup vec - * \brief Vector subtraction-assignment a -= b - * \param[in,out] a Left-hand vector operand - * \param[in] b Right-hand vector operand - * \return Replaces a with a-b and returns the result. - */ -inline VECTOR3 &operator-= (VECTOR3 &a, const VECTOR3 &b) -{ - a.x -= b.x; - a.y -= b.y; - a.z -= b.z; - return a; -} - -/** - * \ingroup vec - * \brief Vector-scalar multiplication-assignment a *= f - * \param[in,out] a Left-hand vector operand - * \param[in] f Right hand scalar operand - * \return Replaces a with element-wise a*f and returns the result. - */ -inline VECTOR3 &operator*= (VECTOR3 &a, const double f) -{ - a.x *= f; - a.y *= f; - a.z *= f; - return a; -} - -/** - * \ingroup vec - * \brief Vector-scalar division-assignment a /= f - * \param[in,out] a Left-hand vector operand - * \param[in] f Right-hand scalar operand - * \return Replaces a with element-wise a/f and returns the result. - */ -inline VECTOR3 &operator/= (VECTOR3 &a, const double f) -{ - a.x /= f; - a.y /= f; - a.z /= f; - return a; -} - -/** - * \ingroup vec - * \brief Vector unary minus -a - * \param[in] a Vector operand - * \return Negative vector (-a.x, -a.y, -a.z) - */ -inline VECTOR3 operator- (const VECTOR3 &a) -{ - VECTOR3 c; - c.x = -a.x; - c.y = -a.y; - c.z = -a.z; - return c; -} - -/** - * \ingroup vec - * \brief Scalar (inner, dot) product of two vectors - * \param[in] a First vector operand - * \param[in] b Second vector operand - * \return Scalar product ab - */ -inline double dotp (const VECTOR3 &a, const VECTOR3 &b) -{ - return a.x*b.x + a.y*b.y + a.z*b.z; -} - -/** - * \ingroup vec - * \brief Vector (cross) product of two vectors - * \param[in] a First vector operand - * \param[in] b Second vector operand - * \return Vector product axb - */ -inline VECTOR3 crossp (const VECTOR3 &a, const VECTOR3 &b) -{ - return _V(a.y*b.z - b.y*a.z, a.z*b.x - b.z*a.x, a.x*b.y - b.x*a.y); -} - -/** - * \ingroup vec - * \brief Length (L2-norm) of a vector - * \param a Vector operand - * \return Vector norm |a|2 - */ -inline double length (const VECTOR3 &a) -{ - return sqrt (a.x*a.x + a.y*a.y + a.z*a.z); -} - -/** - * \ingroup vec - * \brief Length squared of a vector - * \param a Vector operand - * \return Vector norm |a|22 - */ -inline double length2 (const VECTOR3 &a) -{ - return (a.x*a.x + a.y*a.y + a.z*a.z); -} - -/** - * \ingroup vec - * \brief Distance between two points - * \param[in] a First point - * \param[in] b Second point - * \return Distance between a and b - */ -inline double dist (const VECTOR3 &a, const VECTOR3 &b) -{ - return length (a-b); -} - -/** - * \ingroup vec - * \brief Normalise a vector - * - * Resizes the argument vector to length 1. - * \param[in,out] a Vector argument - * \note The length of a must be greater than 0. - */ -inline void normalise (VECTOR3 &a) -{ - a /= length(a); -} - -/** - * \ingroup vec - * \brief Returns normalised vector - * - * Returns a vector of length 1 with the same direction - * as the argument vector. - * \param[in] a Vector argument - * \return Normalised vector. - * \note The length of a must be greater than 0. - */ -inline VECTOR3 unit (const VECTOR3 &a) -{ - return a / length(a); -} - /** * \ingroup vec * \brief Matrix composition @@ -7377,12 +7117,13 @@ inline MATRIX3 &operator/= (MATRIX3 &A, double s) * \param[in] b vector operand * \return Result of Ab */ -inline VECTOR3 mul (const MATRIX3 &A, const VECTOR3 &b) +inline auto mul(const MATRIX3 &A, const VECTOR3 &b) { - return _V ( + return VECTOR3{ A.m11*b.x + A.m12*b.y + A.m13*b.z, A.m21*b.x + A.m22*b.y + A.m23*b.z, - A.m31*b.x + A.m32*b.y + A.m33*b.z); + A.m31*b.x + A.m32*b.y + A.m33*b.z + }; } /** @@ -7392,12 +7133,13 @@ inline VECTOR3 mul (const MATRIX3 &A, const VECTOR3 &b) * \param[in] b vector operand * \return Result of ATb */ -inline VECTOR3 tmul (const MATRIX3 &A, const VECTOR3 &b) +inline auto tmul(const MATRIX3 &A, const VECTOR3 &b) { - return _V ( + return VECTOR3{ A.m11*b.x + A.m21*b.y + A.m31*b.z, A.m12*b.x + A.m22*b.y + A.m32*b.z, - A.m13*b.x + A.m23*b.y + A.m33*b.z); + A.m13*b.x + A.m23*b.y + A.m33*b.z + }; } /** @@ -7519,9 +7261,12 @@ inline VECTOR3 POINTERTOREF (VECTOR3 *p) // ====================================================================== #ifdef ORBITER_MODULE + void dummy(); -void calldummy () { dummy(); } -DLLCLBK char *ModuleDate () { return (char*)__DATE__; } +void calldummy() { dummy(); } + +DLLCLBK char *ModuleDate() { return (char*)__DATE__; } + #endif -#endif // !__ORBITERAPI_H \ No newline at end of file +#endif // ORBITERAPI_H \ No newline at end of file diff --git a/Orbitersdk/include/afxres.h b/Orbitersdk/include/afxres.h deleted file mode 100644 index 0b59f96b4..000000000 --- a/Orbitersdk/include/afxres.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef __AFXRES_H__ -#define __AFXRES_H__ - -#include -#include -#define IDC_STATIC -1 - -#endif /*__AFXRES_H__*/ diff --git a/Orbitersdk/include/math.hpp b/Orbitersdk/include/math.hpp new file mode 100644 index 000000000..548277ca8 --- /dev/null +++ b/Orbitersdk/include/math.hpp @@ -0,0 +1,19 @@ +//////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2023 Dimitry Ishenko +// Contact: dimitry (dot) ishenko (at) (gee) mail (dot) com +// +// Distributed under the MIT license. + +//////////////////////////////////////////////////////////////////////////////// +#ifndef MATH_HPP +#define MATH_HPP + +//////////////////////////////////////////////////////////////////////////////// +/** + * @brief return x saturated to the range [0, 1] +*/ +template +constexpr auto saturate(T x) { return x < T{0} ? T{0} : (x > T{1} ? T{1} : x); } + +//////////////////////////////////////////////////////////////////////////////// +#endif diff --git a/Orbitersdk/include/vector.hpp b/Orbitersdk/include/vector.hpp new file mode 100644 index 000000000..c364ca791 --- /dev/null +++ b/Orbitersdk/include/vector.hpp @@ -0,0 +1,266 @@ +//////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2023 Dimitry Ishenko +// Contact: dimitry (dot) ishenko (at) (gee) mail (dot) com +// +// Distributed under the MIT license. + +//////////////////////////////////////////////////////////////////////////////// +#ifndef VECTOR_HPP +#define VECTOR_HPP + +#include +#include // std::size_t +#include // std::ostream +#include + +//////////////////////////////////////////////////////////////////////////////// +/** + * @brief type traits for 2-, 3- and 4-dimensional vectors + * + * Classes belonging to is_vector2 must have x and y member variables. + * Classes belonging to is_vector3 must have x, y and z member variables. + * Classes belonging to is_vector4 must have x, y, z and w member variables. + */ +template struct is_vector2 : std::false_type { }; +template struct is_vector3 : std::false_type { }; +template struct is_vector4 : std::false_type { }; + +//////////////////////////////////////////////////////////////////////////////// +/** + * @brief 3-dimensional vector of type double + */ +union VECTOR3 +{ + double data[3]; + struct { double x, y, z; }; + + constexpr VECTOR3() : x{0}, y{0}, z{0} { } + constexpr VECTOR3(double x, double y, double z) : x{x}, y{y}, z{z} { } + + constexpr VECTOR3(const VECTOR3&) = default; + constexpr VECTOR3& operator=(const VECTOR3&) = default; + + constexpr auto const& operator[](std::size_t i) const { return data[i]; } + constexpr auto& operator[](std::size_t i) { return data[i]; } +}; + +/** + * @brief 4-dimensional vector of type double + */ +union VECTOR4 +{ + struct { double x, y, z, w; }; + + constexpr VECTOR4() : x{0}, y{0}, z{0}, w{0} { } + constexpr VECTOR4(double x, double y, double z, double w) : x{x}, y{y}, z{z}, w{w} { } + + constexpr VECTOR4(const VECTOR4&) = default; + constexpr VECTOR4& operator=(const VECTOR4&) = default; + + constexpr auto const& operator[](std::size_t i) const { const double* d[] = {&x, &y, &z, &w}; return *d[i]; } + constexpr auto& operator[](std::size_t i) { double* d[] = {&x, &y, &z, &w}; return *d[i]; } +}; + +template<> struct is_vector3 : std::true_type { }; +template<> struct is_vector4 : std::true_type { }; + +//////////////////////////////////////////////////////////////////////////////// +/** + * @brief helper macros for vector type traits + */ +#define if_vector2(V) std::enable_if_t::value>* = nullptr +#define if_vector3(V) std::enable_if_t::value>* = nullptr +#define if_vector4(V) std::enable_if_t::value>* = nullptr +#define if_vector( V) std::enable_if_t::value || is_vector3::value || is_vector4::value>* = nullptr + +/** + * @brief vector operators + */ +template constexpr auto& operator+=(V& l, const V& r) { l.x += r.x; l.y += r.y; return l; } +template constexpr auto& operator+=(V& l, const V& r) { l.x += r.x; l.y += r.y; l.z += r.z; return l; } +template constexpr auto& operator+=(V& l, const V& r) { l.x += r.x; l.y += r.y; l.z += r.z; l.w += r.w; return l; } + +template constexpr auto& operator+=(V& v, auto q) { v.x += q; v.y += q; return v; } +template constexpr auto& operator+=(V& v, auto q) { v.x += q; v.y += q; v.z += q; return v; } +template constexpr auto& operator+=(V& v, auto q) { v.x += q; v.y += q; v.z += q; v.w += q; return v; } + +template constexpr auto& operator-=(V& l, const V& r) { l.x -= r.x; l.y -= r.y; return l; } +template constexpr auto& operator-=(V& l, const V& r) { l.x -= r.x; l.y -= r.y; l.z -= r.z; return l; } +template constexpr auto& operator-=(V& l, const V& r) { l.x -= r.x; l.y -= r.y; l.z -= r.z; l.w -= r.w; return l; } + +template constexpr auto& operator-=(V& v, auto q) { v.x -= q; v.y -= q; return v; } +template constexpr auto& operator-=(V& v, auto q) { v.x -= q; v.y -= q; v.z -= q; return v; } +template constexpr auto& operator-=(V& v, auto q) { v.x -= q; v.y -= q; v.z -= q; v.w -= q; return v; } + +template constexpr auto& operator*=(V& l, const V& r) { l.x *= r.x; l.y *= r.y; return l; } +template constexpr auto& operator*=(V& l, const V& r) { l.x *= r.x; l.y *= r.y; l.z *= r.z; return l; } +template constexpr auto& operator*=(V& l, const V& r) { l.x *= r.x; l.y *= r.y; l.z *= r.z; l.w *= r.w; return l; } + +template constexpr auto& operator*=(V& v, auto q) { v.x *= q; v.y *= q; return v; } +template constexpr auto& operator*=(V& v, auto q) { v.x *= q; v.y *= q; v.z *= q; return v; } +template constexpr auto& operator*=(V& v, auto q) { v.x *= q; v.y *= q; v.z *= q; v.w *= q; return v; } + +template constexpr auto& operator/=(V& l, const V& r) { l.x /= r.x; l.y /= r.y; return l; } +template constexpr auto& operator/=(V& l, const V& r) { l.x /= r.x; l.y /= r.y; l.z /= r.z; return l; } +template constexpr auto& operator/=(V& l, const V& r) { l.x /= r.x; l.y /= r.y; l.z /= r.z; l.w /= r.w; return l; } + +template constexpr auto& operator/=(V& v, auto q) { v.x /= q; v.y /= q; return v; } +template constexpr auto& operator/=(V& v, auto q) { v.x /= q; v.y /= q; v.z /= q; return v; } +template constexpr auto& operator/=(V& v, auto q) { v.x /= q; v.y /= q; v.z /= q; v.w /= q; return v; } + +template constexpr auto operator+ (const V& v) { return V{+v.x, +v.y}; } // unary + +template constexpr auto operator+ (const V& v) { return V{+v.x, +v.y, +v.z}; } // unary + +template constexpr auto operator+ (const V& v) { return V{+v.x, +v.y, +v.z, +v.w}; } // unary + + +template constexpr auto operator- (const V& v) { return V{-v.x, -v.y}; } // unary - +template constexpr auto operator- (const V& v) { return V{-v.x, -v.y, -v.z}; } // unary - +template constexpr auto operator- (const V& v) { return V{-v.x, -v.y, -v.z, -v.w}; } // unary - + +template constexpr auto operator+ (const V& l, const V& r) { return V{l.x + r.x, l.y + r.y}; } +template constexpr auto operator+ (const V& l, const V& r) { return V{l.x + r.x, l.y + r.y, l.z + r.z}; } +template constexpr auto operator+ (const V& l, const V& r) { return V{l.x + r.x, l.y + r.y, l.z + r.z, l.w + r.w}; } + +template constexpr auto operator+ (const V& v, auto q) { return V{v.x + q, v.y + q}; } +template constexpr auto operator+ (const V& v, auto q) { return V{v.x + q, v.y + q, v.z + q}; } +template constexpr auto operator+ (const V& v, auto q) { return V{v.x + q, v.y + q, v.z + q, v.w + q}; } + +template constexpr auto operator+ (auto q, const V& v) { return V{q + v.x, q + v.y}; } +template constexpr auto operator+ (auto q, const V& v) { return V{q + v.x, q + v.y, q + v.z}; } +template constexpr auto operator+ (auto q, const V& v) { return V{q + v.x, q + v.y, q + v.z, q + v.w}; } + +template constexpr auto operator- (const V& l, const V& r) { return V{l.x - r.x, l.y - r.y}; } +template constexpr auto operator- (const V& l, const V& r) { return V{l.x - r.x, l.y - r.y, l.z - r.z}; } +template constexpr auto operator- (const V& l, const V& r) { return V{l.x - r.x, l.y - r.y, l.z - r.z, l.w - r.w}; } + +template constexpr auto operator- (const V& v, auto q) { return V{v.x - q, v.y - q}; } +template constexpr auto operator- (const V& v, auto q) { return V{v.x - q, v.y - q, v.z - q}; } +template constexpr auto operator- (const V& v, auto q) { return V{v.x - q, v.y - q, v.z - q, v.w - q}; } + +template constexpr auto operator- (auto q, const V& v) { return V{q - v.x, q - v.y}; } +template constexpr auto operator- (auto q, const V& v) { return V{q - v.x, q - v.y, q - v.z}; } +template constexpr auto operator- (auto q, const V& v) { return V{q - v.x, q - v.y, q - v.z, q - v.w}; } + +template constexpr auto operator* (const V& l, const V& r) { return V{l.x * r.x, l.y * r.y}; } +template constexpr auto operator* (const V& l, const V& r) { return V{l.x * r.x, l.y * r.y, l.z * r.z}; } +template constexpr auto operator* (const V& l, const V& r) { return V{l.x * r.x, l.y * r.y, l.z * r.z, l.w * r.w}; } + +template constexpr auto operator* (const V& v, auto q) { return V{v.x * q, v.y * q}; } +template constexpr auto operator* (const V& v, auto q) { return V{v.x * q, v.y * q, v.z * q}; } +template constexpr auto operator* (const V& v, auto q) { return V{v.x * q, v.y * q, v.z * q, v.w * q}; } + +template constexpr auto operator* (auto q, const V& v) { return V{q * v.x, q * v.y}; } +template constexpr auto operator* (auto q, const V& v) { return V{q * v.x, q * v.y, q * v.z}; } +template constexpr auto operator* (auto q, const V& v) { return V{q * v.x, q * v.y, q * v.z, q * v.w}; } + +template constexpr auto operator/ (const V& l, const V& r) { return V{l.x / r.x, l.y / r.y}; } +template constexpr auto operator/ (const V& l, const V& r) { return V{l.x / r.x, l.y / r.y, l.z / r.z}; } +template constexpr auto operator/ (const V& l, const V& r) { return V{l.x / r.x, l.y / r.y, l.z / r.z, l.w / r.w}; } + +template constexpr auto operator/ (const V& v, auto q) { return V{v.x / q, v.y / q}; } +template constexpr auto operator/ (const V& v, auto q) { return V{v.x / q, v.y / q, v.z / q}; } +template constexpr auto operator/ (const V& v, auto q) { return V{v.x / q, v.y / q, v.z / q, v.w / q}; } + +template constexpr auto operator/ (auto q, const V& v) { return V{q / v.x, q / v.y}; } +template constexpr auto operator/ (auto q, const V& v) { return V{q / v.x, q / v.y, q / v.z}; } +template constexpr auto operator/ (auto q, const V& v) { return V{q / v.x, q / v.y, q / v.z, q / v.w}; } + +template constexpr auto operator==(const V& l, const V& r) { return l.x == r.x && l.y == r.y; } +template constexpr auto operator==(const V& l, const V& r) { return l.x == r.x && l.y == r.y && l.z == r.z; } +template constexpr auto operator==(const V& l, const V& r) { return l.x == r.x && l.y == r.y && l.z == r.z && l.w == r.w; } + +template constexpr auto operator!=(const V& l, const V& r) { return l.r != r.x || l.y != r.y; } +template constexpr auto operator!=(const V& l, const V& r) { return l.r != r.x || l.y != r.y || l.z != r.z; } +template constexpr auto operator!=(const V& l, const V& r) { return l.r != r.x || l.y != r.y || l.z != r.z || l.w != r.w; } + +/** + * @brief stream insertion operators + */ +template inline auto& operator<<(std::ostream& os, const V& v) { os << v.x << ',' << v.y; return os; } +template inline auto& operator<<(std::ostream& os, const V& v) { os << v.x << ',' << v.y << ',' << v.z; return os; } +template inline auto& operator<<(std::ostream& os, const V& v) { os << v.x << ',' << v.y << ',' << v.z << ',' << v.w; return os; } + +//////////////////////////////////////////////////////////////////////////////// +/** + * @brief absolute value + */ +template constexpr auto abs(const V& v) { return V{std::abs(v.x), std::abs(v.y)}; } +template constexpr auto abs(const V& v) { return V{std::abs(v.x), std::abs(v.y), std::abs(v.z)}; } +template constexpr auto abs(const V& v) { return V{std::abs(v.x), std::abs(v.y), std::abs(v.z), std::abs(v.w)}; } + +/** + * @brief angle between two vectors + */ +template constexpr auto angle(const V& l, const V& r) { return std::acos( dot(unit(l), unit(r)) ); } + +/** + * @brief cross product + */ +template +constexpr auto cross(const V& l, const V& r) +{ + return V{l.y * r.z - r.y * l.z, l.z * r.x - r.z * l.x, l.x * r.y - r.x * l.y}; +} + +/** + * @brief distance between two points (squared and not) + */ +template constexpr auto dist_2(const V& l, const V& r) { return len_2(l - r); } +template constexpr auto dist(const V& l, const V& r) { return std::sqrt(dist_2(l, r)); } + +/** + * @brief dot (scalar) product + */ +template constexpr auto dot(const V& l, const V& r) { return l.x * r.x + l.y * r.y; } +template constexpr auto dot(const V& l, const V& r) { return l.x * r.x + l.y * r.y + l.z * r.z; } +template constexpr auto dot(const V& l, const V& r) { return l.x * r.x + l.y * r.y + l.z * r.z + l.w * r.w; } + +/** + * @brief e raised to the power + */ +template constexpr auto exp(const V& v) { return V{std::exp(v.x), std::exp(v.y)}; } +template constexpr auto exp(const V& v) { return V{std::exp(v.x), std::exp(v.y), std::exp(v.z)}; } +template constexpr auto exp(const V& v) { return V{std::exp(v.x), std::exp(v.y), std::exp(v.z), std::exp(v.w)}; } + +/** + * @brief linear interpolation + */ +template constexpr auto lerp(const V& a, const V& b, auto t) { return a + t * (b - a); } + +/** + * @brief vector norm/length (squared and not) + */ +template constexpr auto norm_2(const V& v) { return dot(v, v); } +template constexpr auto len_2 (const V& v) { return norm_2(v); } + +template constexpr auto norm(const V& v) { return std::sqrt(norm_2(v)); } +template constexpr auto len (const V& v) { return norm(v); } + +/** + * @brief raise to the power + */ +template constexpr auto pow(const V& l, const V& r) { return V{std::pow(l.x, r.x), std::pow(l.y, r.y)}; } +template constexpr auto pow(const V& l, const V& r) { return V{std::pow(l.x, r.x), std::pow(l.y, r.y), std::pow(l.z, r.z)}; } +template constexpr auto pow(const V& l, const V& r) { return V{std::pow(l.x, r.x), std::pow(l.y, r.y), std::pow(l.z, r.z), std::pow(l.w, r.w)}; } + +template constexpr auto pow(const V& v, auto e) { return V{std::pow(v.x, e), std::pow(v.y, e)}; } +template constexpr auto pow(const V& v, auto e) { return V{std::pow(v.x, e), std::pow(v.y, e), std::pow(v.z, e)}; } +template constexpr auto pow(const V& v, auto e) { return V{std::pow(v.x, e), std::pow(v.y, e), std::pow(v.z, e), std::pow(v.w, e)}; } + +template constexpr auto pow(auto b, const V& v) { return V{std::pow(b, v.x), std::pow(b, v.y)}; } +template constexpr auto pow(auto b, const V& v) { return V{std::pow(b, v.x), std::pow(b, v.y), std::pow(b, v.z)}; } +template constexpr auto pow(auto b, const V& v) { return V{std::pow(b, v.x), std::pow(b, v.y), std::pow(b, v.z), std::pow(b, v.w)}; } + +/** + * @brief square root + */ +template constexpr auto sqrt(const V& v) { return V{std::sqrt(v.x), std::sqrt(v.y)}; } +template constexpr auto sqrt(const V& v) { return V{std::sqrt(v.x), std::sqrt(v.y), std::sqrt(v.z)}; } +template constexpr auto sqrt(const V& v) { return V{std::sqrt(v.x), std::sqrt(v.y), std::sqrt(v.z), std::sqrt(v.w)}; } + +/** + * @brief normalized unit vector + */ +template constexpr auto unit(const V& v) { return v / len(v); } + +//////////////////////////////////////////////////////////////////////////////// +#endif diff --git a/Sound/XRSound/src/SoundPreSteps.cpp b/Sound/XRSound/src/SoundPreSteps.cpp index 4d5973b99..13401901f 100644 --- a/Sound/XRSound/src/SoundPreSteps.cpp +++ b/Sound/XRSound/src/SoundPreSteps.cpp @@ -347,7 +347,7 @@ const float RCSDefaultSoundPreStep::s_minThrustLevelForSound = 0.20f; RCSDefaultSoundPreStep::RCSDefaultSoundPreStep(VesselXRSoundEngine *pEngine) : DefaultSoundPreStep(pEngine) { - m_thrustVectorsROT = m_thrustVectorsLIN = _V(0, 0, 0); // set by value + m_thrustVectorsROT = m_thrustVectorsLIN = {0, 0, 0}; // set by value // we have six total axes, but need to check for both rotation and translation: rotation and translation for a given axis share the same sound slot const XRSoundConfigFileParser &config = m_pEngine->GetConfig(); diff --git a/Sound/XRSound/src/VesselXRSoundEngine.cpp b/Sound/XRSound/src/VesselXRSoundEngine.cpp index cba955644..26f673dc1 100644 --- a/Sound/XRSound/src/VesselXRSoundEngine.cpp +++ b/Sound/XRSound/src/VesselXRSoundEngine.cpp @@ -439,9 +439,8 @@ double VesselXRSoundEngine::GetCameraDistance() if (pVessel == nullptr) // vessel deleted out from under us? return 10.0; // just assume the camera is close - const VECTOR3 &zero = _V(0, 0, 0); VECTOR3 vesselGlobalCoords; - pVessel->Local2Global(zero, vesselGlobalCoords); + pVessel->Local2Global(VECTOR3{0, 0, 0}, vesselGlobalCoords); return dist(vesselGlobalCoords, GetCameraCoordinates()); } diff --git a/Src/Module/LuaScript/LuaInterpreter/Interpreter.cpp b/Src/Module/LuaScript/LuaInterpreter/Interpreter.cpp index d8b7a1efb..eed32716f 100644 --- a/Src/Module/LuaScript/LuaInterpreter/Interpreter.cpp +++ b/Src/Module/LuaScript/LuaInterpreter/Interpreter.cpp @@ -1345,14 +1345,14 @@ int Interpreter::vec_add (lua_State *L) } else { ASSERT_SYNTAX (lua_isnumber(L,2), "Argument 2: expected vector or number"); fb = lua_tonumber (L,2); - lua_pushvector (L, _V(va.x+fb, va.y+fb, va.z+fb)); + lua_pushvector (L, {va.x+fb, va.y+fb, va.z+fb}); } } else { ASSERT_SYNTAX (lua_isnumber(L,1), "Argument 1: expected vector or number"); fa = lua_tonumber (L,1); if (lua_isvector (L,2)) { vb = lua_tovector (L,2); - lua_pushvector (L, _V(fa+vb.x, fa+vb.y, fa+vb.z)); + lua_pushvector (L, {fa+vb.x, fa+vb.y, fa+vb.z}); } else { ASSERT_SYNTAX (lua_isnumber(L,2), "Argument 2: expected vector or number"); fb = lua_tonumber (L,2); @@ -1374,14 +1374,14 @@ int Interpreter::vec_sub (lua_State *L) } else { ASSERT_SYNTAX (lua_isnumber(L,2), "Argument 2: expected vector or number"); fb = lua_tonumber (L,2); - lua_pushvector (L, _V(va.x-fb, va.y-fb, va.z-fb)); + lua_pushvector (L, {va.x-fb, va.y-fb, va.z-fb}); } } else { ASSERT_SYNTAX (lua_isnumber(L,1), "Argument 1: expected vector or number"); fa = lua_tonumber (L,1); if (lua_isvector (L,2)) { vb = lua_tovector (L,2); - lua_pushvector (L, _V(fa-vb.x, fa-vb.y, fa-vb.z)); + lua_pushvector (L, {fa-vb.x, fa-vb.y, fa-vb.z}); } else { ASSERT_SYNTAX (lua_isnumber(L,2), "Argument 2: expected vector or number"); fb = lua_tonumber (L,2); @@ -1462,7 +1462,7 @@ int Interpreter::vec_dotp (lua_State *L) v1 = lua_tovector(L,1); ASSERT_SYNTAX(lua_isvector(L,2), "Argument 2: expected vector"); v2 = lua_tovector(L,2); - lua_pushnumber (L, dotp(v1,v2)); + lua_pushnumber(L, dot(v1, v2)); return 1; } @@ -1473,7 +1473,7 @@ int Interpreter::vec_crossp (lua_State *L) v1 = lua_tovector(L,1); ASSERT_SYNTAX(lua_isvector(L,2), "Argument 2: expected vector"); v2 = lua_tovector(L,2); - lua_pushvector (L, crossp(v1,v2)); + lua_pushvector(L, cross(v1, v2)); return 1; } @@ -1482,7 +1482,7 @@ int Interpreter::vec_length (lua_State *L) VECTOR3 v; ASSERT_SYNTAX(lua_isvector(L,1), "Argument 1: expected vector"); v = lua_tovector(L,1); - lua_pushnumber (L, length(v)); + lua_pushnumber(L, len(v)); return 1; } @@ -1894,7 +1894,7 @@ int Interpreter::oapi_set_maininfovisibilitymode (lua_State *L) int Interpreter::oapiCreateAnnotation (lua_State *L) { NOTEHANDLE *pnote = (NOTEHANDLE*)lua_newuserdata (L, sizeof(NOTEHANDLE)); - *pnote = ::oapiCreateAnnotation (true, 1.0, _V(1,0.8,0.6)); + *pnote = ::oapiCreateAnnotation (true, 1.0, {1,0.8,0.6}); oapiAnnotationSetPos (*pnote, 0.03, 0.2, 0.4, 0.4); g_notehandles.push_back(pnote); diff --git a/Src/Module/LuaScript/LuaInterpreter/lua_vessel_mtd.cpp b/Src/Module/LuaScript/LuaInterpreter/lua_vessel_mtd.cpp index 1422e80bc..1a612fa55 100644 --- a/Src/Module/LuaScript/LuaInterpreter/lua_vessel_mtd.cpp +++ b/Src/Module/LuaScript/LuaInterpreter/lua_vessel_mtd.cpp @@ -1574,7 +1574,7 @@ int Interpreter::v_get_status (lua_State *L) if (version == 1) { - VESSELSTATUS status = {0}; + VESSELSTATUS status{ }; v->GetStatus(status); lua_push_vessel_status(L, status); return 1; @@ -1615,7 +1615,7 @@ int Interpreter::v_defset_status (lua_State *L) if (version == 1) { - VESSELSTATUS status = {0}; + VESSELSTATUS status{ }; v->GetStatus(status); // Extract known values from table @@ -2347,7 +2347,7 @@ int Interpreter::v_get_progradedir (lua_State *L) v->GetRelativeVel (hRef, vel); v->GetRotationMatrix (rot); vel = tmul (rot, vel); // rotate into vessel frame - normalise (vel); + vel = unit(vel); lua_pushvector (L, vel); return 1; } diff --git a/Src/Orbiter/Base.cpp b/Src/Orbiter/Base.cpp index c3b7928c5..09242efd4 100644 --- a/Src/Orbiter/Base.cpp +++ b/Src/Orbiter/Base.cpp @@ -49,7 +49,7 @@ Base::Base (char *fname, Planet *_planet, double _lng, double _lat) char cbuf[256]; int texid = 0, bias = 0; //visual = 0; - sundir.Set(0,-1,0); + sundir = {0, -1, 0}; sundir_updt = 0.0; InitDeviceObjects (); @@ -114,8 +114,7 @@ Base::Base (char *fname, Planet *_planet, double _lng, double _lat) LpadSpec *tmp = new LpadSpec[npad+1]; TRACENEW if (npad) memcpy (tmp, lspec, npad*sizeof(LpadSpec)), delete []lspec; lspec = tmp; - const Vector &pos = ((Lpad*)bo)->GetPos(); - lspec[npad].relpos.Set (pos.x, pos.y, pos.z); + lspec[npad].relpos = ((Lpad*)bo)->GetPos(); lspec[npad].status = 0; lspec[npad].vessel = 0; if (float freq = ((Lpad*)bo)->GetILSfreq()) { @@ -129,8 +128,8 @@ Base::Base (char *fname, Planet *_planet, double _lng, double _lat) RwySpec *tmp = new RwySpec[nrwy+1]; TRACENEW if (nrwy) memcpy (tmp, rwy, nrwy*sizeof(RwySpec)), delete []rwy; rwy = tmp; - Vector p1 (Vector (prwy->end1.x, prwy->end1.y, prwy->end1.z)); - Vector p2 (Vector (prwy->end2.x, prwy->end2.y, prwy->end2.z)); + VECTOR3 p1{prwy->end1.x, prwy->end1.y, prwy->end1.z}; + VECTOR3 p2{prwy->end2.x, prwy->end2.y, prwy->end2.z}; Rel_EquPos (p1, rwy[nrwy].lng1, rwy[nrwy].lat1); Rel_EquPos (p2, rwy[nrwy].lng2, rwy[nrwy].lat2); Orthodome (rwy[nrwy].lng1, rwy[nrwy].lat1, rwy[nrwy].lng2, rwy[nrwy].lat2, rwy[nrwy].length, rwy[nrwy].appr1); @@ -422,13 +421,13 @@ void Base::Attach (Planet *_parent) rad = cbody->Size(); // dist from planet centre elev = 0.0; cbody->EquatorialToLocal (slng, clng, slat, clat, rad, rpos); - s0->vel.Set (0,0,0); // base is fixed to ground + s0->vel = {0,0,0}; // base is fixed to ground rrot.Set ( clng*slat, clng*clat, -slng, // rotate from local -clat, slat, 0, // base to local slng*slat, slng*clat, clng); // planet coords double v = Pi2*rad*clat / cbody->RotT(); // surface velocity - rotvel.Set (-v*slng, 0.0, v*clng); // velocity vector in non-rotating planet coords + rotvel = {-v * slng, 0.0, v * clng}; // velocity vector in non-rotating planet coords } DWORD Base::GetTileList (const SurftileSpec **_tile) const @@ -585,8 +584,8 @@ void Base::Update (bool force) // WARNING: this should work the other way round: combine the // two quaternions and extract grot - s1->pos.Set (mul (cbody->s1->R, rpos) + cbody->s1->pos); - s1->vel.Set (mul (cbody->s1->R, rotvel) + cbody->s1->vel); + s1->pos = mul(cbody->s1->R, rpos) + cbody->s1->pos; + s1->vel = mul(cbody->s1->R, rotvel) + cbody->s1->vel; // periodically update some secondary parameters if (td.SimT1 > sundir_updt || force) { @@ -596,7 +595,7 @@ void Base::Update (bool force) } } -void Base::Rel_EquPos (const Vector &relpos, double &_lng, double &_lat) const +void Base::Rel_EquPos (const VECTOR3 &relpos, double &_lng, double &_lat) const { _lng = lng + relpos.z/(cbody->Size()*cos(lat)); _lat = lat - relpos.x/cbody->Size(); @@ -777,5 +776,5 @@ int Base::ReportTouchdown (VesselBase *vessel, double vlng, double vlat) double Base::CosSunAlt () const { - return (s0->R.m12*s0->pos.x + s0->R.m22*s0->pos.y + s0->R.m32*s0->pos.z) / (-s0->pos.length()); + return (s0->R.m12 * s0->pos.x + s0->R.m22 * s0->pos.y + s0->R.m32 * s0->pos.z) / -len(s0->pos); } diff --git a/Src/Orbiter/Base.h b/Src/Orbiter/Base.h index 0c45525ca..01106f552 100644 --- a/Src/Orbiter/Base.h +++ b/Src/Orbiter/Base.h @@ -19,7 +19,7 @@ class Base; struct SurftileSpec; typedef struct { - Vector relpos; + VECTOR3 relpos; int status; // 0=free, 1=occupied, 2=booked VesselBase *vessel; // vessel assigned to pad Nav_VTOL *nav; // pointer to NAV transmitter @@ -65,7 +65,7 @@ class Base: public Body { inline double Elevation() const { return elev; } // Return mean base elevation - void Rel_EquPos (const Vector &relpos, double &_lng, double &_lat) const; + void Rel_EquPos (const VECTOR3 &relpos, double &_lng, double &_lat) const; // converts a base-relative position into longitude/latitude void Pad_EquPos (DWORD padno, double &_lng, double &_lat) const; @@ -119,18 +119,18 @@ class Base: public Body { // Return cosine of angle between surface normal and direction to // the sun (which is assumed in the centre of the global coord system) - inline Vector SunDirection () const - { return (s1 ? tmul(s1->R, -s1->pos.unit()) : tmul (s0->R, -s0->pos.unit())); } + inline VECTOR3 SunDirection () const + { return (s1 ? tmul(s1->R, -unit(s1->pos)) : tmul(s0->R, -unit(s0->pos))); } // Return vector pointing towards sun (= world coordiate origin) in // base local coordinates - inline const Vector *SunDirectionBuffered () const + inline const VECTOR3 *SunDirectionBuffered () const { return &sundir; } // Return vector pointing towards sun (= world coordiate origin) in // base local coordinates. // This version returns a stored value that is updated in regular intervals - inline Vector4 ShadowColor () const { return Vector4(0.0, 0.0, 0.0, 0.7); } + inline VECTOR4 ShadowColor () const { return VECTOR4{0.0, 0.0, 0.0, 0.7}; } // colour and transparency of shadows. Make this planet-specific DWORD GetTileList (const SurftileSpec **_tile) const; @@ -171,11 +171,11 @@ class Base: public Body { //const Planet *planet; double rad, lng, lat; // equatorial coords of the base double elev; // mean elevation of the base - Vector rpos; // base position in local planet frame + VECTOR3 rpos; // base position in local planet frame Matrix rrot; // rotation matrix in local planet frame double objscale; // size of "typical" base object (for camera-distance dependent render cutoff) bool bObjmapsphere; // map base objects onto spherical planet surface? - Vector rotvel; // base velocity as result of planet rotation in local planet coords (rotvel.y=0) + VECTOR3 rotvel; // base velocity as result of planet rotation in local planet coords (rotvel.y=0) DWORD npad; // number of landing pads int padfree; // number of available (unoccupied) pads @@ -204,7 +204,7 @@ class Base: public Body { DWORD ntilebuf; // list length DWORD ntile; // number of surface tiles - Vector sundir; // sun direction in base coordinates + VECTOR3 sundir; // sun direction in base coordinates double sundir_updt; // time of next buffered sun direction update // common resources diff --git a/Src/Orbiter/Baseobj.cpp b/Src/Orbiter/Baseobj.cpp index d4313d4dc..e402af1d7 100644 --- a/Src/Orbiter/Baseobj.cpp +++ b/Src/Orbiter/Baseobj.cpp @@ -175,7 +175,7 @@ void BaseObject::MapToAltitude (NTVERTEX *vtx, int nvtx) double lng, lat; double elev0 = base->Elevation(); for (int i = 0; i < nvtx; i++) { - base->Rel_EquPos (Vector (vtx[i].x, vtx[i].y, vtx[i].z), lng, lat); + base->Rel_EquPos({vtx[i].x, vtx[i].y, vtx[i].z}, lng, lat); vtx[i].y += (float)base->RefPlanet()->Elevation (lng, lat) - elev; } } @@ -369,7 +369,7 @@ bool MeshObject::LoadMesh (char *fname) return true; } -void MeshObject::UpdateShadow (Vector &fromsun, double azim) +void MeshObject::UpdateShadow (VECTOR3 &fromsun, double azim) { ax = (float)fromsun.x; az = (float)fromsun.z; @@ -2174,7 +2174,7 @@ int RunwayLights::Read (istream &is) void RunwayLights::Setup () { - relpos = Vector((end1.x+end2.x)*0.5, (end1.y+end2.y)*0.5, (end1.z+end2.z)*0.5); + relpos = {(end1.x + end2.x) * 0.5, (end1.y + end2.y) * 0.5, (end1.z + end2.z) * 0.5}; BaseObject::Setup(); NTVERTEX vtx[2]; vtx[0].x = end1.x, vtx[0].y = end1.y, vtx[0].z = end1.z; @@ -2225,31 +2225,31 @@ void RunwayLights::Render (LPDIRECT3DDEVICE7 dev, bool day) #endif // INLINEGRAPHICS } -void RunwayLights::VertexArray (DWORD count, const Vector &cpos, const Vector &pos, const Vector &ofs, double size, POSTEXVERTEX *&Vtx) +void RunwayLights::VertexArray (DWORD count, const VECTOR3 &cpos, const VECTOR3 &pos, const VECTOR3 &ofs, double size, POSTEXVERTEX *&Vtx) { size *= 0.15; // for distance resizing (see below bsize) DWORD i; double bsize, ap = g_camera->Aperture(); - Vector p(pos), bdir, v1, v2; + VECTOR3 p = pos, bdir, v1, v2; for (i = 0; i < count; i++) { - bdir.Set (p-cpos); + bdir = p - cpos; // beacon position rel to camera - bsize = size * sqrt((bdir.length()+1.0)*ap); + bsize = size * sqrt((len(bdir) + 1.0) * ap); // this resizes the beacons so they appear larger at greater distance // may need more thought if (!bdir.y || !bdir.z) { - v1.Set (0,bsize,0); - v2.Set (0,0,bsize); + v1 = {0, bsize, 0}; + v2 = {0, 0, bsize}; } else { - v1.Set (bdir.z,0,-bdir.x); - v2.Set (-bdir.x*bdir.y, bdir.z*bdir.z+bdir.x*bdir.x, -bdir.y*bdir.z); - v1 *= bsize/v1.length(); - v2 *= bsize/v2.length(); + v1 = {bdir.z, 0, -bdir.x}; + v2 = {-bdir.x * bdir.y, bdir.z * bdir.z + bdir.x * bdir.x, -bdir.y * bdir.z}; + v1 *= bsize / len(v1); + v2 *= bsize / len(v2); } // v1 and v2 are two orthogonal vectors perpendicular to the vector from // camera to beacon. Required to set up the billboard vertices @@ -2279,14 +2279,14 @@ void RunwayLights::VertexArray (DWORD count, const Vector &cpos, const Vector &p void RunwayLights::Update () { - Vector pos, ofs; + VECTOR3 pos, ofs; POSTEXVERTEX *Vtx; // transform camera position and direction into local base coords - Vector cpos (tmul (base->GRot(), g_camera->GPos()-base->GPos())); - Vector cdir (tmul (base->GRot(), g_camera->Direction())); + VECTOR3 cpos = tmul(base->GRot(), g_camera->GPos() - base->GPos()); + VECTOR3 cdir = tmul(base->GRot(), g_camera->Direction()); - bool look12 = (dotp (cdir, dyndata->ref2-dyndata->ref1) >= 0); + bool look12 = (dot(cdir, dyndata->ref2-dyndata->ref1) >= 0); // camera looks in direction from ref1 to ref2 if (papi) { // light configuration for PAPI indicator @@ -2411,18 +2411,18 @@ void RunwayLights::Activate () nbp = (papi ? 8:0); // number of precision approach lights nbt = dyndata->nb_tot = nbwn + nbwd + nbr + nbp; // total number of lights - dyndata->ref1.Set (end1.x, end1.y, end1.z); - dyndata->ref2.Set (end2.x, end2.y, end2.z); - Vector dr(end2.x-end1.x, end2.y-end1.y, end2.z-end1.z); - dyndata->ofs1.Set (dr/(nbc-1)); - dr.unify(); - dyndata->dir.Set (dr); - dyndata->ofs3.Set (dr.z*width, 0, -dr.x*width); - dyndata->nml.Set (dyndata->ofs3.unit()); + dyndata->ref1 = {end1.x, end1.y, end2.z}; + dyndata->ref2 = {end2.x, end2.y, end2.z}; + VECTOR3 dr{end2.x - end1.x, end2.y - end1.y, end2.z - end1.z}; + dyndata->ofs1 = dr / (nbc - 1); + dr = unit(dr); + dyndata->dir = dr; + dyndata->ofs3 = {dr.z * width, 0, -dr.x * width}; + dyndata->nml = unit(dyndata->ofs3); if (vasi) { - dyndata->ofs5.Set (dr*vasi->ofs + dyndata->ofs3*2.0); + dyndata->ofs5 = dr * vasi->ofs + dyndata->ofs3 * 2.0; //dyndata->ofs5.y += 2.0; - dyndata->ofs4.Set (dyndata->ofs5 - dr*vasi->lightsep); + dyndata->ofs4 = dyndata->ofs5 - dr * vasi->lightsep; dyndata->vasi_ry = 2.0; dyndata->vasi_wy = dyndata->vasi_ry + vasi->lightsep * tan(vasi->apprangle); //dyndata->ofs4.y += vasi->lightsep * tan(vasi->apprangle); @@ -2543,41 +2543,40 @@ void BeaconArray::Update () const double resize_fac = 0.1; DWORD i; - Vector p, v1, v2; + VECTOR3 p, v1, v2; double bsize = size; // transform camera into local base coords - Vector cdir (tmul (base->GRot(), g_camera->GPos()-base->GPos())); + VECTOR3 cdir = tmul(base->GRot(), g_camera->GPos() - base->GPos()); for (i = 0; i < count; i++) { - Vector bdir (Pos[i]-cdir); // vector from camera to beacon i - bsize = size * sqrt(bdir.length()+1.0)*resize_fac; // distance scaling of beacon size + VECTOR3 bdir = Pos[i] - cdir; // vector from camera to beacon i + bsize = size * sqrt(len(bdir) + 1.0) * resize_fac; // distance scaling of beacon size if (bdir.y == 0.0 && bdir.z == 0.0) { - v1.Set (0,1,0); - v2.Set (0,0,1); + v1 = {0, 1, 0}; + v2 = {0, 0, 1}; } else { - v1.Set (bdir.z,0,-bdir.x); - v2.Set (-bdir.x*bdir.y, bdir.z*bdir.z+bdir.x*bdir.x, -bdir.y*bdir.z); - v1.unify(); v2.unify(); + v1 = unit(VECTOR3{bdir.z, 0, -bdir.x}); + v2 = unit(VECTOR3{-bdir.x * bdir.y, bdir.z * bdir.z + bdir.x * bdir.x, -bdir.y * bdir.z}); } - p.Set(Pos[i] - (v1+v2)*bsize); + p = Pos[i] - (v1 + v2) * bsize; Vtx[i*4].x = (float)p.x; Vtx[i*4].y = (float)p.y; Vtx[i*4].z = (float)p.z; - p.Set(Pos[i] + (v1-v2)*bsize); + p = Pos[i] + (v1 - v2) * bsize; Vtx[i*4+1].x = (float)p.x; Vtx[i*4+1].y = (float)p.y; Vtx[i*4+1].z = (float)p.z; - p.Set(Pos[i] + (v1+v2)*bsize); + p = Pos[i] + (v1 + v2) * bsize; Vtx[i*4+2].x = (float)p.x; Vtx[i*4+2].y = (float)p.y; Vtx[i*4+2].z = (float)p.z; - p.Set(Pos[i] - (v1-v2)*bsize); + p = Pos[i] - (v1 - v2) * bsize; Vtx[i*4+3].x = (float)p.x; Vtx[i*4+3].y = (float)p.y; Vtx[i*4+3].z = (float)p.z; @@ -2590,14 +2589,16 @@ void BeaconArray::Activate () Vtx = new POSTEXVERTEX[nVtx = count*4]; TRACENEW Idx = new WORD[nIdx = count*6]; TRACENEW - Pos = new Vector[count]; TRACENEW + Pos = new VECTOR3[count]; TRACENEW double ici, ic = 1.0/(count-1); for (i = 0; i < count; i++) { ici = ic*i; - Pos[i].Set ((end2.x-end1.x)*ici + end1.x, - (end2.y-end1.y)*ici + end1.y, - (end2.z-end1.z)*ici + end1.z); + Pos[i] = { + (end2.x - end1.x) * ici + end1.x, + (end2.y - end1.y) * ici + end1.y, + (end2.z - end1.z) * ici + end1.z + }; } for (i = 0; i < count; i++) { @@ -2665,9 +2666,9 @@ void Train::Init (const D3DVECTOR &_end1, const D3DVECTOR &_end2) void Train::Setup () { double lng, lat; - base->Rel_EquPos (Vector(end1.x, end1.y, end1.z), lng, lat); + base->Rel_EquPos({end1.x, end1.y, end1.z}, lng, lat); end1.y += base->RefPlanet()->Elevation (lng, lat)-base->Elevation(); - base->Rel_EquPos (Vector(end2.x, end2.y, end2.z), lng, lat); + base->Rel_EquPos({end2.x, end2.y, end2.z}, lng, lat); end2.y += base->RefPlanet()->Elevation (lng, lat)-base->Elevation(); } @@ -2951,7 +2952,7 @@ void Train1::Update () _shvtx[i].x += dx, _shvtx[i].z += dz; } -void Train1::UpdateShadow (Vector &fromsun, double az) +void Train1::UpdateShadow (VECTOR3 &fromsun, double az) { static DWORD i, j, nCH, ii[12] = {2,3,4,5,6,7,10,11,12,13,14,15}; static VECTOR2D proj[12]; @@ -3278,7 +3279,7 @@ void Train2::Update () } } -void Train2::UpdateShadow (Vector &fromsun, double az) +void Train2::UpdateShadow (VECTOR3 &fromsun, double az) { static DWORD i, j, nCH, ii[12] = {2,3,4,5,6,7,10,11,12,13,14,15}; static VECTOR2D proj[12]; @@ -3412,13 +3413,12 @@ void SolarPlant::Render (LPDIRECT3DDEVICE7 dev, bool) int i, j; // check for flashing panels - Vector pc, cdir (tmul (base->GRot(), g_camera->GPos()-base->GPos())); + VECTOR3 pc, cdir = tmul(base->GRot(), g_camera->GPos() - base->GPos()); bool anyflash = false; double alpha; for (i = 0; i < npanel; i++) { - pc.Set (cdir.x - ppos[i].x, cdir.y - ppos[i].y, cdir.z - ppos[i].z); - pc.unify(); - alpha = dotp (pc, nml); + pc = unit(cdir - VECTOR3{ppos[i].x, ppos[i].y, ppos[i].z}); + alpha = dot(pc, nml); if (alpha > 0.999) { anyflash = flash[i] = true; for (j = i*4; j < (i+1)*4; j++) Vtx[j].tu += 0.25; @@ -3533,7 +3533,7 @@ void SolarPlant::Activate () if (g_pOrbiter->Cfg()->CfgVisualPrm.bShadows) { ShVtx = new VERTEX_XYZ[nShVtx = npanel*4]; TRACENEW ShIdx = new WORD[nShIdx = npanel*6]; TRACENEW - Vector4 shadowCol = base->ShadowColor(); + auto shadowCol = base->ShadowColor(); D3DCOLOR shcol = D3DRGBA(shadowCol.x, shadowCol.y, shadowCol.z, shadowCol.w); for (n = 0; n < nShVtx; n++) { ShVtx[n].y = 0.0f; @@ -3580,7 +3580,7 @@ void SolarPlant::Update () nml = *base->SunDirectionBuffered(); if (nml.y < 0.0) { nml.y = 0.0; - nml.unify(); + nml = unit(nml); } int i, vtx_ofs = npanel*4; @@ -3617,7 +3617,7 @@ void SolarPlant::Update () updT = td.SimT1 + 60.0; } -void SolarPlant::UpdateShadow (Vector &fromsun, double az) +void SolarPlant::UpdateShadow (VECTOR3 &fromsun, double az) { if (!g_pOrbiter->Cfg()->CfgVisualPrm.bShadows) return; if (have_shadows = (nml.y > 0.2)) { diff --git a/Src/Orbiter/Baseobj.h b/Src/Orbiter/Baseobj.h index 27740974a..99cdc62af 100644 --- a/Src/Orbiter/Baseobj.h +++ b/Src/Orbiter/Baseobj.h @@ -82,7 +82,7 @@ class BaseObject { // allow object to update itself (but not its shadows). Only needs to be implemented // for objects which set OBJSPEC_UPDATEVERTEX - virtual void UpdateShadow (Vector &fromsun, double az) {} + virtual void UpdateShadow (VECTOR3 &fromsun, double az) {} // update shadow vertices according to shadow vector 'fromsun' (azimuth angle 'az') // Note that this function is for updates according to changes in sun position. // Fast changing shadows due to dynamic objects should be updated in 'Update' @@ -95,7 +95,7 @@ class BaseObject { // Object renders its own shadow or part of it. // Only objects which set OBJSPEC_RENDERSHADOW need to implement this - const Vector &EquPos () const { return equpos; } + const VECTOR3 &EquPos () const { return equpos; } // Returns the equatorial position of the reference point // The radius value includes ground elevation // x=lng [rad], y=lat [rad], z=radius [m] @@ -121,9 +121,9 @@ class BaseObject { const Base *base; // pointer to associated surface base int ngrp; // number of mesh groups used by the object - Vector relpos; // object position relative to basis frame - Vector equpos; // object position in equatorial frame: x=lng [rad], y=lat [rad], z=radius [m] - Vector scale; // object scaling factors + VECTOR3 relpos; // object position relative to basis frame + VECTOR3 equpos; // object position in equatorial frame: x=lng [rad], y=lat [rad], z=radius [m] + VECTOR3 scale; // object scaling factors double rot; // rotation around vertical axis double elev; // elevation of reference point above mean radius [m] double yofs; // vertical translation of reference point against base reference @@ -147,7 +147,7 @@ class MeshObject: public BaseObject { void ExportGroup (int grp, NTVERTEX *vtx, WORD *idx, DWORD &idx_ofs); Mesh *ExportMesh (); Mesh *ExportShadowMesh (double &elev); - void UpdateShadow (Vector &fromsun, double az); + void UpdateShadow (VECTOR3 &fromsun, double az); void Render (LPDIRECT3DDEVICE7 dev, bool day=true); void RenderShadow (LPDIRECT3DDEVICE7 dev); @@ -314,7 +314,7 @@ class Lpad: public BaseObject { Lpad (const Base *_base); void SetPadno (DWORD no) { padno = no; } DWORD GetPadno () const { return padno; } - const Vector &GetPos () const { return relpos; } + const VECTOR3 &GetPos () const { return relpos; } const float GetILSfreq () const { return ILSfreq; } protected: @@ -394,7 +394,7 @@ class BeaconArray: public BaseObject { D3DVECTOR end1, end2; DWORD count; double size; - Vector *Pos; + VECTOR3 *Pos; POSTEXVERTEX *Vtx; WORD *Idx; DWORD nVtx, nIdx; @@ -456,7 +456,7 @@ class RunwayLights: public BaseObject { void Deactivate (); private: - void VertexArray (DWORD count, const Vector &cpos, const Vector &pos, const Vector &ofs, double size, POSTEXVERTEX *&Vtx); + void VertexArray (DWORD count, const VECTOR3 &cpos, const VECTOR3 &pos, const VECTOR3 &ofs, double size, POSTEXVERTEX *&Vtx); // Calculates the billboard vertices for an array of 'count' beacons, starting at 'pos', each offset from the previous // by 'ofs'. cpos is camera position, 'size' is beacon size, 'Vtx' is the result // The Vtx pointer is moved past the end of the current list on return @@ -478,14 +478,14 @@ class RunwayLights: public BaseObject { DWORD nb_centre, nb_side, nb_approach, nb_end; // number of lights: runway centre, runway side, approach path, runway end DWORD nb_vasi_w, nb_vasi_r; // number of white and red VASI approach indicators (if any) DWORD nb_tot, nb_white_night, nb_white_day, nb_red; // number of lights: total, white, red - Vector ref1; // reference point 1 (=end1) - Vector ref2; // reference point 2 (=end2) - Vector dir; // unit vector from ref1 to ref2 - Vector nml; // horizontal unit vector perpendicular to dir - Vector ofs1; // offset vector between centerline lights - Vector ofs3; // offset from centerline to runway edge - Vector ofs4; // offset from centerline to VASI white lights - Vector ofs5; // offset from centerline to VASI red lights + VECTOR3 ref1; // reference point 1 (=end1) + VECTOR3 ref2; // reference point 2 (=end2) + VECTOR3 dir; // unit vector from ref1 to ref2 + VECTOR3 nml; // horizontal unit vector perpendicular to dir + VECTOR3 ofs1; // offset vector between centerline lights + VECTOR3 ofs3; // offset from centerline to runway edge + VECTOR3 ofs4; // offset from centerline to VASI white lights + VECTOR3 ofs5; // offset from centerline to VASI red lights double vasi_ry, vasi_wy; // VASI red/white light elevation int flashpos; // position of flashing approach light double flashtime; // time of next strobe light change @@ -548,7 +548,7 @@ class Train1: public Train { bool GetShadowSpec (DWORD &nvtx, DWORD &nidx); void ExportShadow (VERTEX_XYZ *vtx, WORD *idx); void Update (); - void UpdateShadow (Vector &fromsun, double az); + void UpdateShadow (VECTOR3 &fromsun, double az); void Activate (); void Deactivate (); @@ -581,7 +581,7 @@ class Train2: public Train { bool GetShadowSpec (DWORD &nvtx, DWORD &nidx); void ExportShadow (VERTEX_XYZ *vtx, WORD *idx); void Update (); - void UpdateShadow (Vector &fromsun, double az); + void UpdateShadow (VECTOR3 &fromsun, double az); void Activate (); void Deactivate (); void Render (LPDIRECT3DDEVICE7 dev, bool day); @@ -616,7 +616,7 @@ class SolarPlant: public BaseObject { void Render (LPDIRECT3DDEVICE7 dev, bool day=true); void RenderShadow (LPDIRECT3DDEVICE7 dev); void Update (); - void UpdateShadow (Vector &fromsun, double az); + void UpdateShadow (VECTOR3 &fromsun, double az); void Activate (); void Deactivate(); @@ -637,7 +637,7 @@ class SolarPlant: public BaseObject { DWORD nIdx, nShIdx; // number of indices bool *flash; // panel flashing in sunlight? LPDIRECTDRAWSURFACE7 tex; // texture to use - Vector nml; // pointing direction of panels (towards sun) + VECTOR3 nml; // pointing direction of panels (towards sun) //VBase *vbase; // associated base visual double updT; // time of next direction update diff --git a/Src/Orbiter/Body.cpp b/Src/Orbiter/Body.cpp index 3513d2895..ee0fec706 100644 --- a/Src/Orbiter/Body.cpp +++ b/Src/Orbiter/Body.cpp @@ -67,13 +67,13 @@ Body::Body(char* fname) if (!GetItemReal (ifs, "Mass", mass)) mass = 1.0; // desperate default if (!GetItemReal (ifs, "Size", size)) size = 1.0; // desperate default - if (!GetItemVector (ifs, "AlbedoRGB", albedo)) albedo.Set (1,1,1); + if (!GetItemVector (ifs, "AlbedoRGB", albedo)) albedo = {1, 1, 1}; GetItemVector (ifs, "InitPos", s0->pos); GetItemVector (ifs, "InitVel", s0->vel); - rpos_base.Set (s0->pos); rpos_add.Set (0,0,0); - rvel_base.Set (s0->vel); rvel_add.Set (0,0,0); + rpos_base = s0->pos; rpos_add = {0, 0, 0}; + rvel_base = s0->vel; rvel_add = {0, 0, 0}; } void Body::SetName (char *_name) @@ -89,23 +89,23 @@ void Body::SetSize (double newsize) g_pOrbiter->NotifyObjectSize (this); } -void Body::RPlace (const Vector &rpos, const Vector &rvel) +void Body::RPlace (const VECTOR3 &rpos, const VECTOR3 &rvel) { // should RPlace be allowed outside update phase? s1->pos = rpos_base = rpos; - rpos_add.Set (0,0,0); + rpos_add = {0, 0, 0}; s1->vel = rvel_base = rvel; - rvel_add.Set (0,0,0); + rvel_add = {0, 0, 0}; } -void Body::SetRPos (const Vector &p) +void Body::SetRPos (const VECTOR3 &p) { dCHECK(s1 != s0, "Update state not available") rpos_base = s1->pos = p; - rpos_add.Set (0,0,0); + rpos_add = {0, 0, 0}; } -void Body::AddRPos (const Vector &dp) { +void Body::AddRPos (const VECTOR3 &dp) { rpos_base += dp; s1->pos = rpos_base + rpos_add; } @@ -113,17 +113,17 @@ void Body::AddRPos (const Vector &dp) { void Body::FlushRPos () { rpos_base = s1->pos; - rpos_add.Set(0,0,0); + rpos_add = {0, 0, 0}; } -void Body::SetRVel (const Vector &v) +void Body::SetRVel (const VECTOR3 &v) { dCHECK(s1 != s0, "Update state not available") rvel_base = s1->vel = v; - rvel_add.Set (0,0,0); + rvel_add = {0, 0, 0}; } -void Body::AddRVel (const Vector &dv) +void Body::AddRVel (const VECTOR3 &dv) { dCHECK(s1 != s0, "Update state not available") rvel_base += dv; @@ -133,23 +133,23 @@ void Body::AddRVel (const Vector &dv) void Body::FlushRVel () { rvel_base = s1->vel; - rvel_add.Set(0,0,0); + rvel_add = {0, 0, 0}; } -void Body::LocalToEquatorial (const Vector &loc, double &lng, double &lat, double &rad) const +void Body::LocalToEquatorial (const VECTOR3 &loc, double &lng, double &lat, double &rad) const { - rad = loc.length(); + rad = len(loc); //loc *= 1.0/rad; lng = atan2 (loc.z, loc.x); lat = asin (loc.y / rad); //lat = atan (loc.y / hypot (loc.x, loc.z)); } -bool Body::SurfpointVisible (double lng, double lat, const Vector &gcam) const +bool Body::SurfpointVisible (double lng, double lat, const VECTOR3 &gcam) const { - Vector sp; + VECTOR3 sp; EquatorialToGlobal (lng, lat, size, sp); - return (dotp (sp-GPos(), gcam-sp) >= 0.0); + return (dot(sp - GPos(), gcam - sp) >= 0.0); } void Body::BroadcastVisMsg (DWORD msg, DWORD_PTR content) diff --git a/Src/Orbiter/Body.h b/Src/Orbiter/Body.h index be03b290c..3c3d45d6c 100644 --- a/Src/Orbiter/Body.h +++ b/Src/Orbiter/Body.h @@ -51,54 +51,54 @@ class Body { inline double Mass() const { return mass; } // Current object mass [kg] - inline const Vector &Albedo () const { return albedo; } + inline const VECTOR3 &Albedo () const { return albedo; } // object albedo (RGB, 0-1) - inline const Vector &GPos() const { return s0->pos; } - inline const Vector &GVel() const { return s0->vel; } + inline const VECTOR3 &GPos() const { return s0->pos; } + inline const VECTOR3 &GVel() const { return s0->vel; } inline const Matrix &GRot() const { return s0->R; } inline const Quaternion &GQ() const { return s0->Q; } // Object position, velocity and orientation in global coords. To transform // a point between local object coords p_loc and global coords p_glob: // p_glob = GRot * p_loc + GPos - void SetRPos (const Vector &p); - void AddRPos (const Vector &dp); + void SetRPos (const VECTOR3 &p); + void AddRPos (const VECTOR3 &dp); void FlushRPos (); - void SetRVel (const Vector &v); - void AddRVel (const Vector &dv); + void SetRVel (const VECTOR3 &v); + void AddRVel (const VECTOR3 &dv); void FlushRVel (); - inline Vector GlobalToLocal (const Vector &glob) const + inline VECTOR3 GlobalToLocal (const VECTOR3 &glob) const { return tmul (s0->R, glob - s0->pos); } // Convert global position glob into body's local coordinate system - inline void GlobalToLocal (const Vector &glob, Vector &loc) const - { loc.Set (tmul (s0->R, glob - s0->pos)); } + inline void GlobalToLocal (const VECTOR3 &glob, VECTOR3 &loc) const + { loc = tmul(s0->R, glob - s0->pos); } // same with different interface - inline void LocalToGlobal (const Vector &loc, Vector &glob) const - { glob.Set (mul (s0->R, loc) + s0->pos); } + inline void LocalToGlobal (const VECTOR3 &loc, VECTOR3 &glob) const + { glob = mul(s0->R, loc) + s0->pos; } - void LocalToEquatorial (const Vector &loc, double &lng, double &lat, double &rad) const; - inline void GlobalToEquatorial (const Vector &glob, double &lng, double &lat, double &rad) const + void LocalToEquatorial (const VECTOR3 &loc, double &lng, double &lat, double &rad) const; + inline void GlobalToEquatorial (const VECTOR3 &glob, double &lng, double &lat, double &rad) const { LocalToEquatorial (GlobalToLocal (glob), lng, lat, rad); } // Convert local/global position glob into equatorial coordinates of // the body (longitude, latitude and radial distance - inline void EquatorialToLocal (double slng, double clng, double slat, double clat, double rad, Vector &loc) const - { double xz = rad*clat; loc.Set (xz*clng, rad*slat, xz*slng); } - inline void EquatorialToLocal (double lng, double lat, double rad, Vector &loc) const + inline void EquatorialToLocal (double slng, double clng, double slat, double clat, double rad, VECTOR3 &loc) const + { double xz = rad * clat; loc = {xz * clng, rad * slat, xz * slng}; } + inline void EquatorialToLocal (double lng, double lat, double rad, VECTOR3 &loc) const { EquatorialToLocal (sin(lng), cos(lng), sin(lat), cos(lat), rad, loc); } - inline void EquatorialToGlobal (double lng, double lat, double rad, Vector &glob) const - { Vector loc; EquatorialToLocal (lng, lat, rad, loc); LocalToGlobal (loc, glob); } + inline void EquatorialToGlobal (double lng, double lat, double rad, VECTOR3 &glob) const + { VECTOR3 loc; EquatorialToLocal (lng, lat, rad, loc); LocalToGlobal (loc, glob); } - virtual bool SurfpointVisible (double lng, double lat, const Vector &gcam) const; + virtual bool SurfpointVisible (double lng, double lat, const VECTOR3 &gcam) const; // Returns true if a surface point given by longitude and latitude is visible from global point gcam // This base class method assumes a spherical object of radius Size() - virtual void RPlace (const Vector &rpos, const Vector &rvel); + virtual void RPlace (const VECTOR3 &rpos, const VECTOR3 &rvel); // Set object position and velocity in parent coords virtual void Update (bool force = false) {} @@ -149,27 +149,27 @@ class Body { // Operations on updated state vectors (only accessible during update phase // AFTER the object has been updated) - inline Vector GlobalToLocal_t1 (const Vector &glob) const + inline VECTOR3 GlobalToLocal_t1 (const VECTOR3 &glob) const { return tmul (s1->R, glob - s1->pos); } // Convert global position glob into body's local coordinate system - inline void GlobalToLocal_t1 (const Vector &glob, Vector &loc) const - { loc.Set (tmul (s1->R, glob - s1->pos)); } + inline void GlobalToLocal_t1(const VECTOR3 &glob, VECTOR3 &loc) const + { loc = tmul(s1->R, glob - s1->pos); } // same with different interface - inline void LocalToGlobal_t1 (const Vector &loc, Vector &glob) const - { glob.Set (mul (s1->R, loc) + s1->pos); } + inline void LocalToGlobal_t1 (const VECTOR3 &loc, VECTOR3 &glob) const + { glob = mul(s1->R, loc) + s1->pos; } - inline const Vector &Acceleration() const { return acc; }; + inline const VECTOR3 &Acceleration() const { return acc; }; protected: double mass { 0.0 }; // current body mass [kg] double size { 0.0 }; // (mean) body radius [m] - Vector albedo { 1, 1, 1 }; // object albedo (RGB, 0-1) + VECTOR3 albedo{1, 1, 1}; // object albedo (RGB, 0-1) double vislimit { 1e-3 }; // total visibility limit (in units of viewport vertical) double spotlimit { 1e-3 }; // spot visibility limit (in units of viewport vertical) - Vector acc; // current acceleration vector + VECTOR3 acc; // current acceleration vector VISHANDLE hVis { nullptr }; // visual identifier passed to messages (NULL=no visual) @@ -178,9 +178,9 @@ class Body { std::string name; // object name std::string filename; - Vector rpos_base { 0, 0, 0 }, rpos_add { 0, 0, 0 }; // base and incremental parts of rpos - Vector rvel_base { 0, 0, 0 }, rvel_add { 0, 0, 0 }; // base and incremental parts of rvel - int updcount { 0 }; // update counter + VECTOR3 rpos_base, rpos_add; // base and incremental parts of rpos + VECTOR3 rvel_base, rvel_add; // base and incremental parts of rvel + int updcount { 0 }; // update counter private: void SetName (char *_name = 0); diff --git a/Src/Orbiter/BodyIntegrator.cpp b/Src/Orbiter/BodyIntegrator.cpp index f611e859d..ebf910308 100644 --- a/Src/Orbiter/BodyIntegrator.cpp +++ b/Src/Orbiter/BodyIntegrator.cpp @@ -158,12 +158,12 @@ void RigidBody::RK2_LinAng (double h, int nsub, int isub) { double h05 = h*0.5; - Vector acc1, tau; + VECTOR3 acc1, tau; StateVectors s; - s.pos.Set (s1->pos+s1->vel*h05); - s.vel.Set (s1->vel+acc*h05); + s.pos = s1->pos + s1->vel * h05; + s.vel = s1->vel + acc * h05; s.SetRot (s1->Q.Rot(s1->omega*h05)); - s.omega.Set (s1->omega+arot*h05); + s.omega = s1->omega + arot * h05; GetIntermediateMoments (acc1, tau, s, (isub+0.5)/nsub, h); rpos_add += s.vel*h; @@ -182,28 +182,28 @@ void RigidBody::RK4_LinAng (double h, int nsub, int isub) double h05 = h*0.5; double hi6 = h/6.0; - Vector tau, acc1, aacc1, acc2, aacc2, acc3, aacc3; + VECTOR3 tau, acc1, aacc1, acc2, aacc2, acc3, aacc3; StateVectors sa, sb, sc; - sa.pos.Set (s1->pos+s1->vel*h05); - sa.vel.Set (s1->vel+acc*h05); + sa.pos = s1->pos + s1->vel * h05; + sa.vel = s1->vel + acc * h05; sa.SetRot (s1->Q.Rot(s1->omega*h05)); - sa.omega.Set (s1->omega+arot*h05); + sa.omega = s1->omega + arot * h05; GetIntermediateMoments (acc1, tau, sa, (isub+0.5)/nsub, h); - aacc1.Set (EulerInv_full (tau, sa.omega)); + aacc1 = EulerInv_full(tau, sa.omega); - sb.pos.Set (s1->pos+sa.vel*h05); - sb.vel.Set (s1->vel+acc1*h05); + sb.pos = s1->pos + sa.vel * h05; + sb.vel = s1->vel + acc1 * h05; sb.SetRot (s1->Q.Rot(sa.omega*h05)); - sb.omega.Set (s1->omega+aacc1*h05); + sb.omega = s1->omega + aacc1 * h05; GetIntermediateMoments (acc2, tau, sb, (isub+0.5)/nsub, h); - aacc2.Set (EulerInv_full (tau, sb.omega)); + aacc2 = EulerInv_full(tau, sb.omega); - sc.pos.Set (s1->pos+sb.vel*h); - sc.vel.Set (s1->vel+acc2*h); + sc.pos = s1->pos + sb.vel * h; + sc.vel = s1->vel + acc2 * h; sc.SetRot (s1->Q.Rot(sb.omega*h)); - sc.omega.Set (s1->omega+aacc2*h); + sc.omega = s1->omega + aacc2 * h; GetIntermediateMoments (acc3, tau, sc, (isub+1.0)/nsub, h); - aacc3.Set (EulerInv_full (tau, sc.omega)); + aacc3 = EulerInv_full(tau, sc.omega); rvel_add += (acc +(acc1+acc2)*2.0+acc3)*hi6; rpos_add += (s1->vel+(sa.vel+sb.vel)*2.0+sc.vel)*hi6; @@ -221,30 +221,31 @@ void RigidBody::RKdrv_LinAng (double h, int nsub, int isub, int n, const double int i, j; double bh; static int nbuf = 8; + // TODO: re-write without raw pointers static StateVectors *s = new StateVectors[nbuf]; TRACENEW - static Vector *a = new Vector[nbuf]; TRACENEW // linear acceleration - static Vector *d = new Vector[nbuf]; TRACENEW // angular acceleration - Vector tau; + static VECTOR3 *a = new VECTOR3[nbuf]; TRACENEW // linear acceleration + static VECTOR3 *d = new VECTOR3[nbuf]; TRACENEW // angular acceleration + VECTOR3 tau; if (n > nbuf) { // grow buffers delete []s; delete []a; delete []d; s = new StateVectors[n]; TRACENEW - a = new Vector[n]; TRACENEW - d = new Vector[n]; TRACENEW + a = new VECTOR3[n]; TRACENEW + d = new VECTOR3[n]; TRACENEW nbuf = n; } s[0].Set (s1->vel, s1->pos, s1->omega, s1->Q); - a[0].Set (acc); - d[0].Set (arot); + a[0] = acc; + d[0] = arot; for (i = 1; i < n; i++) { s[i].Set (s1->vel, s1->pos, s1->omega, s1->Q); for (j = 0; j < i; j++) s[i].Advance (beta[j]*h, a[j], s[j].vel, d[j], s[j].omega); GetIntermediateMoments (a[i],tau,s[i],(isub+alpha[i-1])/nsub, h); - d[i].Set (EulerInv_full (tau, s[i].omega)); + d[i] = EulerInv_full(tau, s[i].omega); beta += n-1; } for (i = 0; i < n; i++) { @@ -302,12 +303,12 @@ void RigidBody::SY2_LinAng (double h, int nsub, int isub) { double h05 = h*0.5; StateVectors s; - Vector tau; + VECTOR3 tau; rpos_add += (rvel_base+rvel_add)*h05; s1->Q.Rotate (s1->omega*h05); s.Set (s1->vel, rpos_base+rpos_add, s1->omega, s1->Q); GetIntermediateMoments (acc, tau, s, (isub+0.5)/nsub, h); - arot.Set (EulerInv_full (tau, s.omega)); + arot = EulerInv_full(tau, s.omega); rvel_add += acc*h; s1->omega += arot*h; rpos_add += (rvel_base+rvel_add)*h05; @@ -330,7 +331,7 @@ void RigidBody::SY4_LinAng (double h, int nsub, int isub) static const double d4[3] = {x1, x0, x1}; static const double c4[4] = {x1/2, (x0+x1)/2, (x0+x1)/2, x1/2}; StateVectors s; - Vector tau; + VECTOR3 tau; for (i = 0; i < 4; i++) { double step = h * c4[i]; @@ -340,7 +341,7 @@ void RigidBody::SY4_LinAng (double h, int nsub, int isub) if (i != 3) { s.Set (rvel_base+rvel_add, rpos_base+rpos_add, s1->omega, s1->Q); GetIntermediateMoments (acc, tau, s, (isub+sec)/nsub, h); - arot.Set (EulerInv_full (tau, s.omega)); + arot = EulerInv_full(tau, s.omega); rvel_add += acc * (h*d4[i]); s1->omega += arot * (h*d4[i]); } @@ -364,7 +365,7 @@ void RigidBody::SY6_LinAng (double h, int nsub, int isub) static const double c6[8] = { w3/2, (w3+w2)/2, (w2+w1)/2, (w1+w0)/2, (w1+w0)/2, (w2+w1)/2, (w3+w2)/2, w3/2 }; StateVectors s; - Vector tau; + VECTOR3 tau; for (i = 0; i < 8; i++) { double step = h * c6[i]; @@ -374,7 +375,7 @@ void RigidBody::SY6_LinAng (double h, int nsub, int isub) if (i != 7) { s.Set (rvel_base+rvel_add, rpos_base+rpos_add, s1->omega, s1->Q); GetIntermediateMoments (acc, tau, s, (isub+sec)/nsub, h); - arot.Set (EulerInv_full (tau, s.omega)); + arot = EulerInv_full(tau, s.omega); rvel_add += acc * (h*d6[i]); s1->omega += arot * (h*d6[i]); } @@ -407,7 +408,7 @@ void RigidBody::SY8_LinAng (double h, int nsub, int isub) (W1+W0)/2, (W2+W1)/2, (W3+W2)/2, (W4+W3)/2, (W5+W4)/2, (W6+W5)/2, (W7+W6)/2, W7/2 }; StateVectors s; - Vector tau; + VECTOR3 tau; for (i = 0; i < 16; i++) { double step = h * c8[i]; @@ -417,7 +418,7 @@ void RigidBody::SY8_LinAng (double h, int nsub, int isub) if (i != 15) { s.Set (rvel_base+rvel_add, rpos_base+rpos_add, s1->omega, s1->Q); GetIntermediateMoments (acc, tau, s, (isub+sec)/nsub, h); - arot.Set (EulerInv_full (tau, s.omega)); + arot = EulerInv_full(tau, s.omega); rvel_add += acc * (h*d8[i]); s1->omega += arot * (h*d8[i]); } @@ -565,7 +566,7 @@ void RigidBody::Encke () const int neq = 6; int i, j, k, kk; double f[6][13], x[6], xwrk[6], temp, t0, ti, tf, twrk, dt, tfrac; - Vector d[13], omega[13], tau; // angular state parameters + VECTOR3 d[13], omega[13], tau; // angular state parameters StateVectors s; ti = t0 = td.SimT0; @@ -600,8 +601,8 @@ void RigidBody::Encke () } // angular state - omega[0].Set (s1->omega); - d[0].Set (arot); + omega[0] = s1->omega; + d[0] = arot; for (k = 1; k < 13; k++) { kk = k-1; @@ -612,7 +613,7 @@ void RigidBody::Encke () } x[i] = xwrk[i] + dt*temp; } - omega[k].Set (s1->omega); + omega[k] = s1->omega; for (j = 0; j < kk; j++) { omega[k] += d[j]*(beta[k][j]*dt); } @@ -628,7 +629,7 @@ void RigidBody::Encke () f[i][k] = x[i+3]; f[i+3][k] = acc_pert.data[i]; } - d[k].Set (EulerInv_simple (tau, omega[k])); + d[k] = EulerInv_simple(tau, omega[k]); } for (i = 0; i < neq; i++) { diff --git a/Src/Orbiter/CSphereMgr.cpp b/Src/Orbiter/CSphereMgr.cpp index 499e168ae..9e5575bad 100644 --- a/Src/Orbiter/CSphereMgr.cpp +++ b/Src/Orbiter/CSphereMgr.cpp @@ -291,7 +291,7 @@ void CSphereManager::Render(LPDIRECT3DDEVICE7 dev, int level, double bglvl) Matrix rcam = g_camera->GRot(); rcam.premul(ecl2gal); - RenderParam.camdir.Set(rcam.m13, rcam.m23, rcam.m33); + RenderParam.camdir = {rcam.m13, rcam.m23, rcam.m33}; #ifdef _DEBUG // check expected render and texture stages on entry @@ -395,9 +395,9 @@ void CSphereManager::ProcessTile (int lvl, int hemisp, int ilat, int nlat, int i ntot++; static const double rad0 = sqrt(2.0)*Pi05; - Vector cnt = TileCentre (hemisp, ilat, nlat, ilng, nlng); + VECTOR3 cnt = TileCentre (hemisp, ilat, nlat, ilng, nlng); double rad = rad0/(double)nlat; - double alpha = acos (dotp (RenderParam.camdir, cnt)); + double alpha = std::acos(dot(RenderParam.camdir, cnt)); double adist = alpha - rad; if (adist > RenderParam.viewap) return; @@ -471,12 +471,12 @@ void CSphereManager::RenderTile (int lvl, int hemisp, int ilat, int nlat, int il // returns the direction of the tile centre from the planet centre in local // planet coordinates -Vector CSphereManager::TileCentre (int hemisp, int ilat, int nlat, int ilng, int nlng) +VECTOR3 CSphereManager::TileCentre (int hemisp, int ilat, int nlat, int ilng, int nlng) { double cntlat = Pi05 * ((double)ilat+0.5)/(double)nlat, slat = sin(cntlat), clat = cos(cntlat); double cntlng = Pi2 * ((double)ilng+0.5)/(double)nlng + Pi, slng = sin(cntlng), clng = cos(cntlng); - if (hemisp) return Vector (clat*clng, -slat, -clat*slng); - else return Vector (clat*clng, slat, clat*slng); + return hemisp ? VECTOR3{clat * clng, -slat, -clat * slng} + : VECTOR3{clat * clng, slat, clat * slng}; } // ======================================================================= diff --git a/Src/Orbiter/CSphereMgr.h b/Src/Orbiter/CSphereMgr.h index 612d29529..2ad2a24bd 100644 --- a/Src/Orbiter/CSphereMgr.h +++ b/Src/Orbiter/CSphereMgr.h @@ -42,7 +42,7 @@ class CSphereManager { MATRIX4 WorldMatrix (int ilng, int nlng, int ilat, int nlat); void SetWorldMatrix (const MATRIX4 &W); - Vector TileCentre (int hemisp, int ilat, int nlat, int ilng, int nlng); + VECTOR3 TileCentre (int hemisp, int ilat, int nlat, int ilng, int nlng); // returns the direction of the tile centre from the planet centre in local // planet coordinates @@ -76,7 +76,7 @@ class CSphereManager { MATRIX4 transform; // full transformation matrix (for frustum checks) MATRIX4 viewproj; // view+projection matrix MATRIX4 dwmat; // world matrix - Vector camdir; // camera direction in galactic frame + VECTOR3 camdir; // camera direction in galactic frame double viewap; // viewport aperture (semi-diagonal) } RenderParam; diff --git a/Src/Orbiter/Camera.cpp b/Src/Orbiter/Camera.cpp index 197a1b8f9..021f4ef8a 100644 --- a/Src/Orbiter/Camera.cpp +++ b/Src/Orbiter/Camera.cpp @@ -39,7 +39,7 @@ extern Pane *g_pane; extern Vessel *g_focusobj; extern char DBG_MSG[256]; -static Vector nullvec; +static VECTOR3 nullvec; static bool brot = false; const double dragT = 3.0; static const double vmax = 2.0; // max rotation velocity (rad/s) @@ -50,15 +50,15 @@ Camera::Camera (double _nearplane, double _farplane) extmode = CAMERA_TARGETRELATIVE; intmode = CAMERA_GENERICCOCKPIT; action = CAMERA_NORMAL; - gdir.Set (1,0,0); + gdir = {1, 0, 0}; rofs = &nullvec; target = 0; rdist = 4.0; dirref = 0; ephi = etheta = 0.0; dphi = dtht = 0.0; - eyeofs0. Set (0,0.1,0.08); - SetDefaultCockpitDir (Vector (0,0,1)); + eyeofs0 = {0, 0.1, 0.08}; + SetDefaultCockpitDir({0, 0, 1}); SetCockpitDir (0,0); SetCatchAngle (RAD*5.0); memset (&cockpitprm, 0, sizeof(cockpitprm)); @@ -200,7 +200,7 @@ void Camera::SetIntMode (IntCamMode mode) intmode = mode; if (!external_view) { if (intmode != CAMERA_VIRTUALCOCKPIT || !RecallVCParams()) { - rpos.Set (nullvec); + rpos = nullvec; SetCockpitDir (0,0); } } @@ -222,7 +222,7 @@ void Camera::StoreVCParams() bool Camera::RecallVCParams() { if (target != cockpitprm.target) return false; // don't restore across different vessels - rpos.Set (cockpitprm.rpos); + rpos = cockpitprm.rpos; SetCockpitDir (cockpitprm.cphi, cockpitprm.ctheta); return true; } @@ -383,12 +383,11 @@ void Camera::Attach (Body *_target, int mode) if (external_view) { SetViewExternal(); SetRelPos (rdist, ephi, etheta); - gspos.Set (mul (target->GRot(), rpos)); - gpos.Set (gspos + target->GPos()); - GPOS = MakeVECTOR3 (gpos); + gspos = mul(target->GRot(), rpos); + gpos = gspos + target->GPos(); grot.Set (target->GRot()); if (extmode == CAMERA_ABSDIRECTION) - gdir = mul (target->GRot(), mul (rrot, Vector (0,0,1))); + gdir = mul(target->GRot(), mul(rrot, VECTOR3{0, 0, 1})); if ((extmode == CAMERA_TARGETTOOBJECT || extmode == CAMERA_TARGETFROMOBJECT) && dirref == target) extmode = CAMERA_TARGETRELATIVE; // sanity check } else { @@ -397,22 +396,21 @@ void Camera::Attach (Body *_target, int mode) rofs = vessel->CamPos(); SetDefaultCockpitDir (*vessel->CamDir0(), vessel->CamTilt0()); if (intmode != CAMERA_VIRTUALCOCKPIT || !RecallVCParams()) { - rpos.Set (nullvec); + rpos = nullvec; SetCockpitDir (0,0); } SetCatchAngle (vessel->CamCatchRange()); - grot.Set (target->GRot() * rrot); - gspos.Set (mul (target->GRot(), *rofs)); - gpos.Set (gspos + target->GPos()); - GPOS = MakeVECTOR3 (gpos); + grot = target->GRot() * rrot; + gspos = mul(target->GRot(), *rofs); + gpos = gspos + target->GPos(); } - tref.Set(0,0,0); + tref = {0, 0, 0}; vphi = vtht = dphi = dtht = 0.0; has_tref = false; SendDlgMessage (3, 0); } -bool Camera::Direction2Viewport(const Vector &dir, int &x, int &y) +bool Camera::Direction2Viewport(const VECTOR3 &dir, int &x, int &y) { D3DVECTOR homog; D3DMath_VectorMatrixMultiply (homog, D3DMath_Vector(dir.x, dir.y, dir.z), *D3D_ProjViewMatrix()); @@ -432,7 +430,7 @@ double Camera::Distance () const { if (external_view && target) { if (extmode == CAMERA_GROUNDOBSERVER) - return gspos.length(); + return len(gspos); //return gpos.dist (target->GPos()); else return rdist*target->Size(); } else return 0.0; @@ -458,7 +456,7 @@ void Camera::AddPhi (double dphi) } else { SetRelPos (rdist, ephi+dphi*0.5, etheta); if (extmode == CAMERA_ABSDIRECTION) - gdir = mul (target->GRot(), mul (rrot, Vector (0,0,1))); + gdir = mul(target->GRot(), mul(rrot, VECTOR3{0, 0, 1})); } } } @@ -471,7 +469,7 @@ void Camera::AddTheta (double dtheta) } else { SetRelPos (rdist, ephi, etheta+dtheta*0.5); if (extmode == CAMERA_ABSDIRECTION) - gdir = mul (target->GRot(), mul (rrot, Vector (0,0,1))); + gdir = mul(target->GRot(), mul(rrot, VECTOR3{0, 0, 1})); } } } @@ -488,7 +486,7 @@ void Camera::Rotate (double _dphi, double _dtht, bool smooth) rot_smooth = smooth; } -void Camera::MoveTo (const Vector &p) +void Camera::MoveTo (const VECTOR3 &p) { if (ExtCtrlMode & CAMDATA_POS) return; // inhibit transition moves if camera is externally controlled if (external_view) { @@ -498,7 +496,7 @@ void Camera::MoveTo (const Vector &p) } } -void Camera::MoveToDirect (const Vector &p) +void Camera::MoveToDirect (const VECTOR3 &p) { if (external_view) { } else { @@ -547,13 +545,13 @@ void Camera::ChangeDist (double fact) } } -void Camera::Drag (const Vector &gshift) +void Camera::Drag (const VECTOR3 &gshift) { if (external_view) { - tref.Set (has_tref ? tref+gshift: gshift); + tref = has_tref ? tref + gshift : gshift; tref_t0 = td.SysT1; - tref_d0 = tref.length(); - tref_r0 = rpos.length(); + tref_d0 = len(tref); + tref_r0 = len(rpos); tref_r1 = (has_tref && rshift ? tref_r1/tref_r0*rdist : rdist)*target->Size(); rdist = tref_r0/target->Size(); has_tref = true; @@ -586,13 +584,13 @@ void Camera::SetFrustumLimits (double _nearplane, double _farplane) UpdateProjectionMatrix (); } -void Camera::ViewportToGlobalDir (double sx, double sy, Vector &gdir) const +void Camera::ViewportToGlobalDir (double sx, double sy, VECTOR3 &gdir) const { - Vector s((sx-w05+0.5)*tan_ap/h05, (h05-sy-0.5)*tan_ap/h05, 1.0); - gdir.Set (mul (grot, s.unit())); + VECTOR3 s{(sx - w05 + 0.5) * tan_ap / h05, (h05 - sy - 0.5) * tan_ap / h05, 1.0}; + gdir = mul(grot, unit(s)); } -void Camera::SetDefaultCockpitDir (const Vector &dir, double tilt) +void Camera::SetDefaultCockpitDir (const VECTOR3 &dir, double tilt) { isStdDir = (dir.x == 0 && dir.y == 0 && dir.z > 0 && tilt == 0.0); Matrix rrot0_old(rrot0); @@ -635,7 +633,7 @@ void Camera::SetCockpitDir (double ph, double th) 0.0, costh, sinth, sinph, -cosph*sinth, cosph*costh); } - eyeofs = mul (rrot, Vector (0,0.1,0.08)) - eyeofs0; + eyeofs = mul(rrot, VECTOR3{0, 0.1, 0.08}) - eyeofs0; if (!isStdDir) eyeofs = mul (rrot0, eyeofs); } @@ -673,7 +671,7 @@ void Camera::SetCatchAngle (double cangle) void Camera::ResetCockpitPos () { if (!external_view) { - rpos.Set (0,0,0); + rpos = {0, 0, 0}; } } @@ -698,7 +696,7 @@ void Camera::SetRelPos (double r, double ph, double th) 0.0, costh, sinth, sinph, -cosph*sinth, cosph*costh); double dist = -rdist*target->Size(); - rpos.Set (rrot.m13*dist, rrot.m23*dist, rrot.m33*dist); + rpos = {rrot.m13 * dist, rrot.m23 * dist, rrot.m33 * dist}; } void Camera::SetTrackMode (ExtCamMode mode, const Body *ref) @@ -707,19 +705,19 @@ void Camera::SetTrackMode (ExtCamMode mode, const Body *ref) Attach (target, 1); if (extmode == CAMERA_GLOBALFRAME) { - Vector rdir (-tmul (target->GRot(), rpos).unit()); + VECTOR3 rdir = -unit(tmul(target->GRot(), rpos)); SetRelPos (rdist, atan2 (-rdir.x, rdir.z), asin (rdir.y)); } switch (mode) { case CAMERA_ABSDIRECTION: - gdir.Set (-mul (target->GRot(), rpos).unit()); + gdir = -unit(mul(target->GRot(), rpos)); break; case CAMERA_TARGETRELATIVE: // nothing to do break; case CAMERA_GLOBALFRAME: - gdir.Set (-mul (target->GRot(), rpos).unit()); + gdir = -unit(mul(target->GRot(), rpos)); SetRelPos (rdist, atan2 (-gdir.x, gdir.z), asin (gdir.y)); break; case CAMERA_TARGETTOOBJECT: @@ -801,8 +799,8 @@ void Camera::SetGroundObserver_TargetLock (bool lock) go.tgtlock = lock; if (go.tgtlock && external_view && extmode == CAMERA_GROUNDOBSERVER) { - gdir.Set ((target->GPos()-gpos).unit()); - Vector hdir = tmul (go.R, tmul (dirref->GRot(), gdir)); + gdir = unit(target->GPos() - gpos); + VECTOR3 hdir = tmul(go.R, tmul(dirref->GRot(), gdir)); go.tht = asin (hdir.y); go.phi = atan2 (-hdir.x, hdir.z); OutputGroundObserverParams(); @@ -829,8 +827,8 @@ void Camera::GroundObserverShift (double dx, double dz, double dh) if (!external_view || extmode != CAMERA_GROUNDOBSERVER) return; double r; - Vector dsz (grot.m13, grot.m23, grot.m33); // dz: go forward/backward w.r.t. camera view direction - Vector dsx (grot.m11, grot.m21, grot.m31); // dx: go sideways w.r.t. camera view direction + VECTOR3 dsz{grot.m13, grot.m23, grot.m33}; // dz: go forward/backward w.r.t. camera view direction + VECTOR3 dsx{grot.m11, grot.m21, grot.m31}; // dx: go sideways w.r.t. camera view direction dirref->GlobalToEquatorial (gpos + dsz*dz + dsx*dx, go.lng, go.lat, r); double new_alt = max (1.0, go.alt+dh); go.alt0 += new_alt-go.alt; @@ -980,11 +978,11 @@ DWORD Camera::UpdateExternalControl (ExternalCameraControl *ecc) double x = min (posrange, max (-posrange, data.x)); double y = min (posrange, max (-posrange, data.y)); double z = min (posrange, max (-posrange, data.z)); - Vector p(x,y,z); - Vector pr(mul (isStdDir ? rrot : rrot0*rrot, p)); + VECTOR3 p{x, y, z}; + VECTOR3 pr = mul(isStdDir ? rrot : rrot0 * rrot, p); if (dragpos) { - Vector D0(pr-rpos); - double d0 = D0.length(); + VECTOR3 D0 = pr - rpos; + double d0 = len(D0); double d = td.SysDT*1.0; if (d > d0) dragpos = false; else pr = rpos + D0*(d/d0); @@ -1046,7 +1044,7 @@ void Camera::Update () double ralt_proxy = 1e100; for (i = 0; i < g_psys->nPlanet(); i++) { Planet *planet = g_psys->GetPlanet(i); - dist = gpos.dist (planet->GPos()); + dist = ::dist(gpos, planet->GPos()); double alt = dist - planet->Size(); double ralt = alt/planet->Size(); if (ralt < ralt_proxy) { @@ -1060,35 +1058,32 @@ void Camera::Update () bool allow_invert = true; switch (extmode) { case CAMERA_TARGETRELATIVE: - gspos.Set (mul (target->GRot(), rpos)); - gpos.Set (gspos + target->GPos()); - GPOS = MakeVECTOR3 (gpos); - grot.Set (target->GRot() * rrot); + gspos = mul(target->GRot(), rpos); + gpos = gspos + target->GPos(); + grot = target->GRot() * rrot; break; case CAMERA_TARGETTOOBJECT: case CAMERA_TARGETFROMOBJECT: - gdir.Set ((dirref->GPos()-target->GPos()).unit()); + gdir = unit(dirref->GPos() - target->GPos()); if (extmode == CAMERA_TARGETFROMOBJECT) gdir = -gdir; allow_invert = false; // fall through case CAMERA_ABSDIRECTION: { - Vector rdir (tmul (target->GRot(), gdir)); + VECTOR3 rdir = tmul(target->GRot(), gdir); double th = asin (rdir.y); double ph = atan2 (-rdir.x, rdir.z); double dph = fabs(ph-ephi); if (allow_invert && dph >= Pi05 && dph < 3.0*Pi05) ph += Pi, th = Pi-th; // camera is upside-down - a bit hacky! SetRelPos (rdist, ph, th); - gspos.Set (gdir * (-rdist*target->Size())); - gpos.Set (gspos + target->GPos()); - GPOS = MakeVECTOR3 (gpos); - grot.Set (target->GRot() * rrot); + gspos = gdir * (-rdist * target->Size()); + gpos = gspos + target->GPos(); + grot = target->GRot() * rrot; } break; case CAMERA_GLOBALFRAME: - gspos.Set (rpos); - gpos.Set (gspos + target->GPos()); - GPOS = MakeVECTOR3 (gpos); - grot.Set (rrot); + gspos = rpos; + gpos = gspos + target->GPos(); + grot = rrot; break; case CAMERA_GROUNDOBSERVER: { double rad, elev = 0.0; @@ -1101,11 +1096,10 @@ void Camera::Update () rad = dirref->Size() + elev + go.alt; } dirref->EquatorialToGlobal (go.lng, go.lat, rad, gpos); - GPOS = MakeVECTOR3 (gpos); - gspos.Set (gpos - target->GPos()); + gspos = gpos - target->GPos(); if (go.tgtlock) { - gdir.Set ((target->GPos()-gpos).unit()); - Vector hdir = tmul (go.R, tmul (dirref->GRot(), gdir)); + gdir = unit(target->GPos() - gpos); + VECTOR3 hdir = tmul(go.R, tmul(dirref->GRot(), gdir)); if (fabs (hdir.y) < 0.999999) { go.tht = asin (hdir.y); go.phi = atan2 (-hdir.x, hdir.z); @@ -1126,20 +1120,19 @@ void Camera::Update () if (has_tref) { double t = t1 - tref_t0; if (t >= dragT) { - tref.Set(0,0,0); + tref = {0, 0, 0}; has_tref = false; rshift = false; } else { double scale = (1.0 - t*t/(dragT*dragT)*(3.0-2.0*t/dragT)); - double tlen = tref.length(); + double tlen = len(tref); if (tlen) { - tref *= (tref_d0*scale)/tref.length(); + tref *= (tref_d0 * scale) / len(tref); gpos += tref; gspos += tref; - GPOS = MakeVECTOR3 (gpos); } if (rshift) { - rpos *= ((tref_r0-tref_r1)*scale+tref_r1)/rpos.length(); - rdist = rpos.length()/target->Size(); + rpos *= ((tref_r0 - tref_r1) * scale + tref_r1) / len(rpos); + rdist = len(rpos) / target->Size(); } } } @@ -1224,8 +1217,8 @@ void Camera::Update () if (movehead) { static double v = 0; const double a = 1.5, vmax = 2.0; - Vector dr = tgtp - rpos; - double d, dst = dr.length(); + VECTOR3 dr = tgtp - rpos; + double d, dst = len(dr); if (dst > 1e-4) { if (v < vmax) v = min (vmax, v + dt*a); v = min (v, sqrt (0.5*a*dst)); @@ -1238,10 +1231,9 @@ void Camera::Update () } } - grot.Set (target->GRot() * (isStdDir ? rrot : rrot0*rrot)); - gspos.Set (mul (target->GRot(), *rofs + rpos + eyeofs)); - gpos.Set (gspos + target->GPos()); - GPOS = MakeVECTOR3 (gpos); + grot = target->GRot() * (isStdDir ? rrot : rrot0 * rrot); + gspos = mul(target->GRot(), *rofs + rpos + eyeofs); + gpos = gspos + target->GPos(); } // dynamic nearplane calculation @@ -1250,10 +1242,10 @@ void Camera::Update () double np = dist_proxy; // near-plane no further than closest object if (planet_proxy && alt_proxy < 0.1*planet_proxy->Size()) { // make sure the near-plane doesn't cut into the planet surface - Vector gd(grot.m13,grot.m23,grot.m33); - Vector cp(planet_proxy->GPos()-gpos); - double alt = cp.length()-planet_proxy->Size(); - double az = acos (dotp (gd, cp.unit())); + VECTOR3 gd{grot.m13, grot.m23, grot.m33}; + VECTOR3 cp = planet_proxy->GPos() - gpos; + double alt = len(cp) - planet_proxy->Size(); + double az = std::acos(dot(gd, unit(cp))); double a = atan (tan_ap*std::hypot(w05,h05)/h05); double tht = az-a; if (tht < Pi05) diff --git a/Src/Orbiter/Camera.h b/Src/Orbiter/Camera.h index 603ae007f..81d3e34a9 100644 --- a/Src/Orbiter/Camera.h +++ b/Src/Orbiter/Camera.h @@ -79,23 +79,21 @@ class Camera { { return (!external_view && cphi == 0 && ctheta == 0); } // Return true if we are in cockpit mode and the camera points in the default direction - inline const Vector *GPosPtr () const { return &gpos; } - inline const VECTOR3 *GPOSPtr () const { return &GPOS; } + inline const VECTOR3 *GPosPtr () const { return &gpos; } // reference to global camera position - inline const Vector *GSPosPtr () const { return &gspos; } + inline const VECTOR3 *GSPosPtr () const { return &gspos; } // reference to target-relative camera position in global orientation - inline Vector CockpitPos () const { return *rofs + rpos + eyeofs; } + inline VECTOR3 CockpitPos () const { return *rofs + rpos + eyeofs; } // camera position inside cockpit, including eye-rotation offset // only for internal modes - inline Vector Direction() const - { return Vector (grot.m13, grot.m23, grot.m33); } + inline VECTOR3 Direction() const { return VECTOR3{grot.m13, grot.m23, grot.m33}; } // Return direction (in global coords) in which the camera is looking // (last column of GRot) - bool Direction2Viewport(const Vector &dir, int &x, int &y); + bool Direction2Viewport(const VECTOR3 &dir, int &x, int &y); double Distance() const; double Phi() const; @@ -134,11 +132,11 @@ class Camera { // change the view direction in free CAMERA_GROUNDOBSERVER mode, but // may be extended to perform actions in other modes - void MoveTo (const Vector &p); + void MoveTo (const VECTOR3 &p); // Slew camera position to p. Only used in cockpit view // (coordinates are in local vessel coordinates) - void MoveToDirect (const Vector &p); + void MoveToDirect (const VECTOR3 &p); // Set camera position to p (no transition). Only used in cockpit view // (coordinates are in local vessel coordinates) @@ -150,7 +148,7 @@ class Camera { // Change the distance to the object by factor "fact" // (External views only) - void SetDefaultCockpitDir (const Vector &dir, double tilt = 0.0); + void SetDefaultCockpitDir (const VECTOR3 &dir, double tilt = 0.0); // set the default camera direction for cockpit modes // 'dir' must be normalised to 1 @@ -168,7 +166,7 @@ class Camera { void SetCatchAngle (double cangle); // Set the angle [rad] over which the camera auto-centers to its default direction - void Drag (const Vector &gshift); + void Drag (const VECTOR3 &gshift); // Displace camera by 'gshift' (global coords) from its // 'natural' position. The camera will automatically // gradually move back (external camera mode only) @@ -181,7 +179,7 @@ class Camera { // Rotate camera direction in free CAMERA_GROUNDOBSERVER mode // dphi and dtht are incremental tilts in local horizon coordinates - inline const Vector &GPos() const { return gpos; } + inline const VECTOR3 &GPos() const { return gpos; } inline const Matrix &GRot() const { return grot; } double GroundAltitude() const { return go.alt; } @@ -274,7 +272,7 @@ class Camera { D3DMATRIX *D3D_ProjViewMatrix (); // Return product ProjectionMatrix * ViewMatrix - void ViewportToGlobalDir (double sx, double sy, Vector &gdir) const; + void ViewportToGlobalDir (double sx, double sy, VECTOR3 &gdir) const; // converts viewport coordinates (pixels) into a direction vector // in the global frame @@ -320,21 +318,20 @@ class Camera { POINT pm; // last cursor position double mmoveT; // time of last mouse move - Vector gpos; // current camera pos in global coords - VECTOR3 GPOS; // gpos in VECTOR3 format - Vector gspos; // current camera pos relative to target, in global orientation + VECTOR3 gpos; // current camera pos in global coords + VECTOR3 gspos; // current camera pos relative to target, in global orientation Matrix grot; // current camera rotation in global coords - Vector *rofs; // cockpit position offset - Vector rpos; // current camera pos in target system + VECTOR3 *rofs; // cockpit position offset + VECTOR3 rpos; // current camera pos in target system Matrix rrot0; // camera rotation of default cockpit direction Matrix rrot; // current camera rotation in target system (rel to default direction in cockpit modes) bool isStdDir; // true if default cockpit camera direction is +z - Vector eyeofs0, eyeofs;// offset between eyes and head rotation point (standard and rotated coords) - Vector tref; // camera target point offset from target origin (in target coords) + VECTOR3 eyeofs0, eyeofs;// offset between eyes and head rotation point (standard and rotated coords) + VECTOR3 tref; // camera target point offset from target origin (in target coords) double tref_t0, tref_d0, tref_r0, tref_r1; // auxiliary variables for camera dragging bool has_tref, rshift; // use tref? - Vector gdir; // camera direction in global coords (for 'absolute direction' modes) + VECTOR3 gdir; // camera direction in global coords (for 'absolute direction' modes) Body *target; // Reference body. Relative coordinates (RPos) refer to this. const Body *dirref; // body used as direction reference for CAMERA_TARGETTOOBJECT and // CAMERA_TARGETFROMOBJECT external modes @@ -358,7 +355,7 @@ class Camera { // cockpit camera parameters struct { Body *target; // target vessel - Vector rpos; // camera position offset + VECTOR3 rpos; // camera position offset double cphi,ctheta;// camera azimuth and polar angles } cockpitprm; double cphi, ctheta; // current azimuth and polar angles of cockpit camera direction @@ -368,7 +365,7 @@ class Camera { bool rot_smooth; // flag for smooth rotation (acceleration/deceleration) bool movehead; // move head in cockpit mode - Vector tgtp; // cockpit camera target position (to implement 'leaning') + VECTOR3 tgtp; // cockpit camera target position (to implement 'leaning') struct GroundObserver {// ground observer camera parameters double lng, lat; // position diff --git a/Src/Orbiter/CelSphereAPI.cpp b/Src/Orbiter/CelSphereAPI.cpp index c5b42c45e..102223d2a 100644 --- a/Src/Orbiter/CelSphereAPI.cpp +++ b/Src/Orbiter/CelSphereAPI.cpp @@ -28,7 +28,7 @@ oapi::CelestialSphere::CelestialSphere(oapi::GraphicsClient* gc) m_markerPen[i] = gc->clbkCreatePen(1, 0, MarkerColor(i)); m_textBlendAdditive = false; - m_skyCol = _V(0, 0, 0); + m_skyCol = {0, 0, 0}; m_skyBrt = 0.0; m_meshGridLabel = 0; diff --git a/Src/Orbiter/Celbody.cpp b/Src/Orbiter/Celbody.cpp index 2fe9d2d3a..f62ae181c 100644 --- a/Src/Orbiter/Celbody.cpp +++ b/Src/Orbiter/Celbody.cpp @@ -23,13 +23,13 @@ extern TimeData td; extern char DBG_MSG[256]; void Pol2Crt (double *pol, double *crt, bool dopos, bool dovel); -void InterpretEphemeris (double *data, int flg, Vector *pos, Vector *vel, Vector *bpos, Vector *bvel); +void InterpretEphemeris (double *data, int flg, VECTOR3 *pos, VECTOR3 *vel, VECTOR3 *bpos, VECTOR3 *bvel); // ======================================================================= // class CelestialBody -CelestialBody::CelestialBody (double _mass, double _size) -: RigidBody (_mass, _size, Vector (1,1,1)), pinesgrav(NULL) +CelestialBody::CelestialBody(double _mass, double _size) : + RigidBody{_mass, _size, {1, 1, 1}}, pinesgrav{NULL} { DefaultParam(); el = new Elements; TRACENEW @@ -232,8 +232,8 @@ void CelestialBody::Attach (CelestialBody *_parent) } else if (bInitFromElements) { el->PosVel (s0->pos, s0->vel, td.SimT0); if (elframe == ELFRAME_PARENTEQU) { // convert to ecliptic frame - s0->pos.Set (mul (cbody->R_ecl, s0->pos)); // rotate radius vector by planet's obliquity - s0->vel.Set (mul (cbody->R_ecl, s0->vel)); // rotate velocity vector by planet's obliquity + s0->pos = mul(cbody->R_ecl, s0->pos); // rotate radius vector by planet's obliquity + s0->vel = mul(cbody->R_ecl, s0->vel); // rotate velocity vector by planet's obliquity el->Calculate (s0->pos, s0->vel, td.SimT0); // update elements with modified state vectors } bpos = s0->pos; @@ -272,11 +272,11 @@ const Elements *CelestialBody::Els () const return el; } -Vector CelestialBody::Barycentre2Pos (const Vector &bary) const +VECTOR3 CelestialBody::Barycentre2Pos (const VECTOR3 &bary) const { if (!nsecondary) return bary; else { - Vector b2; + VECTOR3 b2; double m, mtot = mass; for (DWORD i = 0; i < nsecondary; i++) { mtot += (m = secondary[i]->Mass()); @@ -286,10 +286,10 @@ Vector CelestialBody::Barycentre2Pos (const Vector &bary) const } } -Vector CelestialBody::Pos2Barycentre (const Vector &pos) const +VECTOR3 CelestialBody::Pos2Barycentre (const VECTOR3 &pos) const { double m, mtot = mass; - Vector b(pos*mass); + VECTOR3 b = pos * mass; for (DWORD i = 0; i < nsecondary; i++) { mtot += (m = secondary[i]->Mass()); b += secondary[i]->GPos() * m; @@ -328,24 +328,24 @@ int CelestialBody::RelTrueAndBaryState() } if (flg & EPHEM_POLAR) Pol2Crt (s, s, true, havevel); - cpos = bpos = Vector (s[0], s[1], s[2]); + cpos = bpos = {s[0], s[1], s[2]}; havetrue = havebary = true; if (havevel) - cvel = bvel = Vector (s[3], s[4], s[5]); + cvel = bvel = {s[3], s[4], s[5]}; } else { if (flg & EPHEM_TRUEPOS) { havetrue = true; havevel = ((flg & EPHEM_TRUEVEL) != 0); if (flg & EPHEM_POLAR) Pol2Crt (state, state, true, havevel); - cpos = Vector (state[0], state[1], state[2]); - if (havevel) cvel = Vector (state[3], state[4], state[5]); + cpos = {state[0], state[1], state[2]}; + if (havevel) cvel = {state[3], state[4], state[5]}; } if (flg & EPHEM_BARYPOS) { havebary = true; havevel = ((flg & EPHEM_BARYVEL) != 0); if (flg & EPHEM_POLAR) Pol2Crt (state+6, state+6, true, havevel); - bpos = Vector (state[6], state[7], state[8]); - if (havevel) bvel = Vector (state[9], state[10], state[11]); + bpos = {state[6], state[7], state[8]}; + if (havevel) bvel = {state[9], state[10], state[11]}; } } el_valid = false; @@ -367,7 +367,7 @@ int CelestialBody::RelTrueAndBaryState() bvelofs = bvel - cvel; } else { // calculate the barycentre offset manually from child positions - bposofs.Set(0,0,0); bvelofs.Set(0,0,0); // system barycentre + bposofs = bvelofs = {0, 0, 0}; // system barycentre double bmass = mass; for (i = 0; i < nsecondary; i++) { bposofs += secondary[i]->bpos * secondary[i]->Mass(); @@ -485,7 +485,7 @@ void CelestialBody::Update (bool force) bvel = s1->vel; } - acc = cpos * (-cvel.length2()/cpos.length2()); + acc = cpos * (-len_2(cvel)) / len_2(cpos); //if (cbody) acc += cbody->acc; } @@ -504,7 +504,7 @@ void CelestialBody::UpdatePrecession () // R_ref component of R_ref*R_rel (tilt of precession reference) if (eps_ref) R_ref_rel.premul (R_ref); - R_axis = mul (R_ref_rel, Vector(0,1,0)); // direction of rotation axis + R_axis = mul(R_ref_rel, VECTOR3{0, 1, 0}); // direction of rotation axis eps_ecl = acos (R_axis.y); // axis obliquity lan_ecl = atan2 (-R_axis.x, R_axis.z); // axis LAN double sinL = sin(lan_ecl), cosL = cos(lan_ecl); @@ -596,13 +596,13 @@ int CelestialBody::ExternState (double *res) return flg; } -bool CelestialBody::PositionAtTime (double t, Vector *p) const +bool CelestialBody::PositionAtTime (double t, VECTOR3 *p) const { if (bDynamicPosVel) return false; // can't calc at arbitrary times if using dynamic updates double res[12]; - static Vector bp; + static VECTOR3 bp; int flg = ExternEphemeris (td.MJD_ref+Day(t), EPHEM_TRUEPOS, res); if (flg) { @@ -620,13 +620,13 @@ bool CelestialBody::PositionAtTime (double t, Vector *p) const return true; } -bool CelestialBody::PosVelAtTime (double t, Vector *p, Vector *v) const +bool CelestialBody::PosVelAtTime (double t, VECTOR3 *p, VECTOR3 *v) const { if (bDynamicPosVel) return false; // can't calc at arbitrary times if using dynamic updates double res[12]; - static Vector bp, bv; + static VECTOR3 bp, bv; int flg = ExternEphemeris (td.MJD_ref+Day(t), EPHEM_TRUEPOS | EPHEM_TRUEVEL, res); if (flg) { @@ -639,33 +639,33 @@ bool CelestialBody::PosVelAtTime (double t, Vector *p, Vector *v) const return true; } -Vector CelestialBody::InterpolatePosition (double n) const +VECTOR3 CelestialBody::InterpolatePosition (double n) const { // Interpolate global position of body by iterative bisection if (n == 0) return s0->pos; else if (n == 1.0) return s1->pos; - Vector refp0, refp1, refpm; + VECTOR3 refp0, refp1, refpm; const CelestialBody *ref = ElRef(); if (ref) { // otherwise assume that reference position is origin - refp0.Set (ref->s0->pos); - refp1.Set (ref->s1->pos); + refp0 = ref->s0->pos; + refp1 = ref->s1->pos; refpm = ref->InterpolatePosition (n); // recursively get reference position at fractional step n } const double eps = 1e-2; - Vector rp0 (s0->pos-refp0); // rel. position at current step - Vector rp1 (s1->pos-refp1); // rel. position at next step - double rd0 = rp0.length(); // radius at current step - double rd1 = rp1.length(); // radius at next step + VECTOR3 rp0 = s0->pos - refp0; // rel. position at current step + VECTOR3 rp1 = s1->pos - refp1; // rel. position at next step + double rd0 = len(rp0); // radius at current step + double rd1 = len(rp1); // radius at next step double n0 = 0.0; // lower bound of search bracket double n1 = 1.0; // upper bound of search bracket double nm = 0.5, d = 0.5; // current trial point double rdm = (rd0+rd1)*0.5; // trial radius - Vector rpm = (rp0+rp1).unit()*rdm; // trial position + VECTOR3 rpm = unit(rp0 + rp1) * rdm; // trial position while (fabs (nm-n) > eps && d > eps) { // interval too large - continue d *= 0.5; // new interval width if (nm < n) { // cut away lower half of interval @@ -680,12 +680,12 @@ Vector CelestialBody::InterpolatePosition (double n) const nm -= d; } rdm = (rd0+rd1)*0.5; // new trial radius - rpm = (rp0+rp1).unit()*rdm; // new trial position + rpm = unit(rp0 + rp1) * rdm; // new trial position } if (fabs (nm-n) > 1e-10) { // linear interpolation of remaining step double scale = (n-n0)/(n1-n0); rdm = rd0 + (rd1-rd0)*scale; - rpm = (rp0 + (rp1-rp0)*scale).unit() * rdm; + rpm = unit(rp0 + (rp1 - rp0) * scale) * rdm; } return rpm + refpm; } @@ -706,7 +706,7 @@ StateVectors CelestialBody::InterpolateState (double n) const sv.vel = s0->vel*(1.0-n) + s1->vel*n; // may need a better interpolation GetRotation (td.SimT0 + td.SimDT*n, sv.R); sv.Q.Set (sv.R); - sv.omega.Set (s0->omega*(1.0-n) + s1->omega*n); // is this ok? + sv.omega = s0->omega * (1.0 - n) + s1->omega * n; // is this ok? return sv; } @@ -792,7 +792,7 @@ void Pol2Crt (double *pol, double *crt, bool dopos, bool dovel) } } -void InterpretEphemeris (double *data, int flg, Vector *pos, Vector *vel, Vector *bpos, Vector *bvel) +void InterpretEphemeris (double *data, int flg, VECTOR3 *pos, VECTOR3 *vel, VECTOR3 *bpos, VECTOR3 *bvel) { static double crt[6], *p; diff --git a/Src/Orbiter/Celbody.h b/Src/Orbiter/Celbody.h index 98e3dfe7d..f39d79dd3 100644 --- a/Src/Orbiter/Celbody.h +++ b/Src/Orbiter/Celbody.h @@ -68,7 +68,7 @@ friend class CELBODY2; // on calculation of orbital elements in equatorial frame, and on // oapiGetPlanetObliquityMatrix - inline const Vector &RotAxis() const { return R_axis; } + inline const VECTOR3 &RotAxis() const { return R_axis; } // rotation axis (direction of north pole) in global coords const Elements *Els() const; @@ -86,12 +86,12 @@ friend class CELBODY2; // parent state and its own relative state. // Recursively updates all secondary body states. - bool PositionAtTime (double t, Vector *p) const; + bool PositionAtTime (double t, VECTOR3 *p) const; // Returns planet's position p at simulation time t [s] in ecliptic frame, // relative to planet's parent. This only works if planet updates // its position analytically, otherwise the function returns false. - bool PosVelAtTime (double t, Vector *p, Vector *v) const; + bool PosVelAtTime (double t, VECTOR3 *p, VECTOR3 *v) const; // Returns planet's position p and velocity v at simulation time t [s] in // ecliptic frame, relative to planet's parent. Only works if planet updates // position analytically, otherwise function returns false @@ -100,7 +100,7 @@ friend class CELBODY2; // Returns rotation matrix at time t. // Note: this function assumes current precession, i.e. t sufficiently close to td.SimT0 - Vector InterpolatePosition (double n) const; + VECTOR3 InterpolatePosition (double n) const; // interpolate a planet position to a time between last and current time step, // where n=0 refers to last step, and n=1 to current step. // linear interpolation of position, plus linear interpolation of radius, if @@ -112,7 +112,7 @@ friend class CELBODY2; // Note: This function can only be called during the state calculation phase, after // s1 has been evaluated, but before it is copied back to s0 - const Vector &Barycentre () const { return bpos; } + const VECTOR3 &Barycentre () const { return bpos; } // Returns position of barycentre (planet + secondaries) inline DWORD nJcoeff() const { return njcoeff; } @@ -123,7 +123,7 @@ friend class CELBODY2; // returns true if the body uses Pines Algorithm to calculate gravitational acceleration from spherical harmonics inline bool usePines() const { return usePinesGravity; } - inline Vector pinesAccel(const Vector rposmax, const int maxDegree, const int maxOrder){ + inline VECTOR3 pinesAccel(const VECTOR3 rposmax, const int maxDegree, const int maxOrder){ return pinesgrav.GetPinesGrav(rposmax, maxDegree, maxOrder); } inline unsigned int GetPinesCutoff() const { @@ -144,8 +144,8 @@ friend class CELBODY2; // Add an object as a secondary (e.g. moon) // Secondaries are used e.g. for barycentre calculations - Vector Barycentre2Pos (const Vector &bary) const; - virtual Vector Pos2Barycentre (const Vector &pos) const; + VECTOR3 Barycentre2Pos (const VECTOR3 &bary) const; + virtual VECTOR3 Pos2Barycentre (const VECTOR3 &pos) const; // Returns object's position from system barycentre or vice versa by scanning // all secondary bodies. @@ -216,7 +216,7 @@ friend class CELBODY2; double rot_T, rot_omega; // siderial rotation time and angular velocity double Dphi; // rotation offset at t=0 - Vector R_axis; // rotation axis direction (north pole) in global coords + VECTOR3 R_axis; // rotation axis direction (north pole) in global coords double *jcoeff; // coefficients Jn of the harmonic expansion of planet ellipsoid shape, starting with J2 (jcoeff[0]=J2, jcoeff[1]=J3, etc.) DWORD njcoeff; // number of coefficients in the jcoeff list @@ -224,8 +224,8 @@ friend class CELBODY2; PinesGravProp pinesgrav; // coefficients and methods for calculating non-spherical gravity vectors using Pines Algorithm bool usePinesGravity; // use Pines Algorithm if true, if false use the older jcoeff method - Vector bpos, bvel; // object's barycentre state (the barycentre of the set of bodies including *this and its children) with respect to the true position of the parent of *this - Vector bposofs, bvelofs; // body barycentre state - true state + VECTOR3 bpos, bvel; // object's barycentre state (the barycentre of the set of bodies including *this and its children) with respect to the true position of the parent of *this + VECTOR3 bposofs, bvelofs;// body barycentre state - true state bool ephem_parentbary; // true if body calculates its state with respect to the parent barycentre, false if with respect to parent's true position }; diff --git a/Src/Orbiter/Config.cpp b/Src/Orbiter/Config.cpp index a9218226d..5c0625332 100644 --- a/Src/Orbiter/Config.cpp +++ b/Src/Orbiter/Config.cpp @@ -392,21 +392,12 @@ bool GetItemBool (istream &is, const char *label, bool &val) return false; } -bool GetItemVector (istream &is, const char *label, Vector &val) +bool GetItemVector (istream &is, const char *label, VECTOR3 &val) { double x, y, z; if (!GetItemString (is, label, g_cbuf)) return false; if (sscanf (g_cbuf, "%lf%lf%lf", &x, &y, &z) != 3) return false; - val.Set (x,y,z); - return true; -} - -bool GetItemVECTOR (istream &is, const char *label, VECTOR3 &val) -{ - double x, y, z; - if (!GetItemString (is, label, g_cbuf)) return false; - if (sscanf (g_cbuf, "%lf%lf%lf", &x, &y, &z) != 3) return false; - val.x = x; val.y = y; val.z = z; + val = {x, y, z}; return true; } @@ -1495,12 +1486,12 @@ bool Config::GetBool (istream &is, const char *category, bool &val) return false; } -bool Config::GetVector (istream &is, const char *category, Vector &val) +bool Config::GetVector (istream &is, const char *category, VECTOR3 &val) { double x, y, z; if (!GetString (is, category, g_cbuf)) return false; if (sscanf (g_cbuf, "%lf%lf%lf", &x, &y, &z) < 3) return false; - val.Set (x, y, z); + val = {x, y, z}; return true; } @@ -1544,7 +1535,7 @@ bool Config::GetBool (const char *category, bool &val) return GetBool (ifs, category, val); } -bool Config::GetVector (const char *category, Vector &val) +bool Config::GetVector (const char *category, VECTOR3 &val) { if (!Root) return false; ifstream ifs (Root); diff --git a/Src/Orbiter/Config.h b/Src/Orbiter/Config.h index bc1a2f22c..73ca010cd 100644 --- a/Src/Orbiter/Config.h +++ b/Src/Orbiter/Config.h @@ -303,8 +303,7 @@ bool GetItemInt (std::istream &is, const char *label, int &val); bool GetItemSize (std::istream& is, const char* label, size_t& val); bool GetItemHex (std::istream &is, const char *label, int &val); bool GetItemBool (std::istream &is, const char *label, bool &val); -bool GetItemVector (std::istream &is, const char *label, Vector &val); -bool GetItemVECTOR (std::istream &is, const char *label, VECTOR3 &val); +bool GetItemVector (std::istream &is, const char *label, VECTOR3 &val); bool FindLine (std::istream &is, const char *line); // scans stream 'is' from beginning for a line beginning with 'line' @@ -436,7 +435,7 @@ class Config { bool GetInt (const char *category, int &val); bool GetSize (const char* category, size_t& val); bool GetBool (const char *category, bool &val); - bool GetVector (const char *category, Vector &val); + bool GetVector (const char *category, VECTOR3 &val); private: bool GetString (std::istream &is, const char *category, char *val); @@ -444,7 +443,7 @@ class Config { bool GetInt (std::istream &is, const char *category, int &val); bool GetSize (std::istream& is, const char* category, size_t& val); bool GetBool (std::istream &is, const char *category, bool &val); - bool GetVector (std::istream &is, const char *category, Vector &val); + bool GetVector (std::istream &is, const char *category, VECTOR3 &val); mutable char cfgpath[256]; // buffer for creating full path names char mshpath[256]; diff --git a/Src/Orbiter/D3dmath.h b/Src/Orbiter/D3dmath.h index df9462b35..5da3d71b1 100644 --- a/Src/Orbiter/D3dmath.h +++ b/Src/Orbiter/D3dmath.h @@ -73,7 +73,7 @@ inline void SetInvD3DRotation (D3DMATRIX &a, const Matrix &r) // SetD3DTranslation() // Assemble a logical translation vector into a D3D transformation matrix -inline void SetD3DTranslation (D3DMATRIX &a, const Vector &t) +inline void SetD3DTranslation (D3DMATRIX &a, const VECTOR3 &t) { a._41 = (FLOAT)t.x; a._42 = (FLOAT)t.y; diff --git a/Src/Orbiter/DlgFocus.cpp b/Src/Orbiter/DlgFocus.cpp index fc18e3c1c..b50cd2fdf 100644 --- a/Src/Orbiter/DlgFocus.cpp +++ b/Src/Orbiter/DlgFocus.cpp @@ -334,11 +334,10 @@ void DlgFocus::RescanTree_Nearby (HWND hDlg) char cbuf[256]; cbuf[255] = '\0'; HTREEITEM hti, hti_focus = NULL; SendDlgItemMessage (hDlg, IDC_TREE1, TVM_DELETEITEM, 0, 0); - const Vector &campos = g_camera->GPos(); for (DWORD i = 0; i < g_psys->nVessel(); i++) { Vessel *vessel = g_psys->GetVessel(i); if (vessel->GetEnableFocus()) { - double dst = campos.dist (vessel->GPos()); + double dst = dist(g_camera->GPos(), vessel->GPos()); if (dst <= range) { hti = AddVesselToTree (hDlg, NULL, vessel); if (hti) hti_focus = hti; diff --git a/Src/Orbiter/DlgInfo.cpp b/Src/Orbiter/DlgInfo.cpp index 87c574342..39316ae05 100644 --- a/Src/Orbiter/DlgInfo.cpp +++ b/Src/Orbiter/DlgInfo.cpp @@ -560,7 +560,7 @@ void DlgInfo::UpdateItems_vessel () vlist.srf->GetItem (2)->SetValue (cbuf+1); sprintf (cbuf, "%sm/s", FloatStr (sp->groundspd)+1); vlist.srf->GetItem (3)->SetValue (cbuf); - Vector V (mul (sp->L2H, tmul (vessel->ProxyBody()->GRot(), sp->groundvel_glob))); + VECTOR3 V = mul(sp->L2H, tmul(vessel->ProxyBody()->GRot(), sp->groundvel_glob)); sprintf (cbuf, "%sm/s", FloatStr (V.y)+1); vlist.srf->GetItem (4)->SetValue (cbuf); sprintf (cbuf, "%0.0f°", sp->dir*DEG); @@ -851,8 +851,8 @@ void DlgInfo::UpdateItems_celbody () if (cblist.loc) { Planet *earth = g_psys->GetPlanet ("Earth"); if (earth && earth != cbody) { - Vector p (cbody->GPos() - earth->GPos()); - double r = p.length(); + VECTOR3 p = cbody->GPos() - earth->GPos(); + double r = len(p); double lng = atan2 (p.z, p.x); double lat = p.y/r; double ra, dc, rah, ram, ras, dcd, dcm, dcs; @@ -875,8 +875,8 @@ void DlgInfo::UpdateItems_celbody () if (cblist.ecl) { if (el) { - Vector p (cbody->GPos() - cbody->ElRef()->GPos()); - double r = p.length(); + VECTOR3 p = cbody->GPos() - cbody->ElRef()->GPos(); + double r = len(p); double lng = atan2 (p.z, p.x); double lat = p.y/r; sprintf (cbuf, "%0.3f°", DEG*posangle(lng)); diff --git a/Src/Orbiter/Element.cpp b/Src/Orbiter/Element.cpp index 53ffd218f..c1e624426 100644 --- a/Src/Orbiter/Element.cpp +++ b/Src/Orbiter/Element.cpp @@ -140,7 +140,7 @@ void Elements::Setup (double m, double M, double mjd) // specific angular momentum double h = sqrt(priv_mu * priv_p); // magnitude of momentum - priv_H.Set(h*sini*sint, h*cosi, -h*sini*cost); + priv_H = {h * sini * sint, h * cosi, -h * sini * cost}; } void Elements::Reset (double _a, double _e, double _i, @@ -240,17 +240,17 @@ double Elements::EccAnomaly (double ma) const return E; } -bool Elements::AscendingNode (Vector &asc) const +bool Elements::AscendingNode (VECTOR3 &asc) const { double d = Rdist (priv_omega); - asc.Set (priv_N * d); + asc = priv_N * d; return (d >= 0.0); } -bool Elements::DescendingNode (Vector &desc) const +bool Elements::DescendingNode (VECTOR3 &desc) const { double d = Rdist (priv_omega+Pi); - desc.Set (priv_N * -d); + desc = priv_N * -d; return (d >= 0.0); } @@ -269,7 +269,7 @@ void Elements::RelPos (double &r, double &ta, double t) const r = priv_p / (1.0 + e * cos(ta)); } -void Elements::Pol2Crt (double r, double ta, Vector &pos) const +void Elements::Pol2Crt (double r, double ta, VECTOR3 &pos) const { double sinto = sin (ta + priv_omega); double costo = cos (ta + priv_omega); @@ -278,7 +278,7 @@ void Elements::Pol2Crt (double r, double ta, Vector &pos) const pos.y = r * sinto * sini; } -void Elements::PosVel (Vector &pos, Vector &vel, double t) const +void Elements::PosVel (VECTOR3 &pos, VECTOR3 &vel, double t) const { double r, ta; @@ -297,16 +297,16 @@ void Elements::PosVel (Vector &pos, Vector &vel, double t) const vel.y = rv * sinto * sini; } -Vector Elements::Pos (double t) const +VECTOR3 Elements::Pos (double t) const { double r, ta; - Vector pos; + VECTOR3 pos; RelPos (r, ta, t); Pol2Crt (r, ta, pos); return pos; } -void Elements::PosVel_TA (Vector &pos, Vector &vel, double ta) const +void Elements::PosVel_TA (VECTOR3 &pos, VECTOR3 &vel, double ta) const { double r = Rdist (ta); Pol2Crt (r, ta, pos); @@ -330,7 +330,7 @@ double Elements::Spd_TA(double ta) const return hypot(vx, vz); } -void Elements::Update (Vector &pos, Vector &vel) +void Elements::Update (VECTOR3 &pos, VECTOR3 &vel) { double sinto, costo, vx, vz, thetav; @@ -369,32 +369,32 @@ void Elements::Update (Vector &pos, Vector &vel) if ((priv_Tpe = -priv_ma/priv_n) < 0.0) priv_Tpe += priv_T; if ((priv_Tap = priv_Tpe-0.5*priv_T) < 0.0) priv_Tap += priv_T; - pos.Set (priv_R); - vel.Set (priv_V); + pos = priv_R; + vel = priv_V; } -void Elements::Calculate (const Vector &R, const Vector &V, double simt) +void Elements::Calculate (const VECTOR3 &R, const VECTOR3 &V, double simt) { bool closed_orbit; - priv_R.Set (R); // store radius vector - priv_V.Set (V); // store velocity vector + priv_R = R; // store radius vector + priv_V = V; // store velocity vector // auxiliary vectors and norms - double v2 = V.length2(); - priv_v = sqrt (v2); - priv_r = R.length(); - priv_H.Set (crossp (V, R)); // left-handed coordinates! - double h = priv_H.length(); - double rv = dotp (R, V); + double v2 = len(V); + priv_v = sqrt(v2); + priv_r = len(R); + priv_H = cross(V, R); // left-handed coordinates! + double h = len(priv_H); + double rv = dot(R, V); // semi-major axis a = priv_r * priv_mu / (2.0*priv_mu - priv_r*v2); //priv_E.Set ((R * (v2-priv_mu/priv_r) - V * rv)/priv_mu); - priv_E.Set (R * (1.0/priv_r - 1.0/a) - V * (rv/priv_mu)); + priv_E = R * (1.0 / priv_r - 1.0 / a) - V * (rv / priv_mu); - e = priv_E.length(); + e = len(priv_E); closed_orbit = (e < 1.0); // inclination @@ -425,11 +425,11 @@ void Elements::Calculate (const Vector &R, const Vector &V, double simt) // longitude of ascending node if (i > I_NOINC_LIMIT) { double tmp = 1.0/std::hypot(priv_H.z, priv_H.x); - priv_N.Set (-priv_H.z*tmp, 0.0, priv_H.x*tmp); // unit vector + priv_N = {-priv_H.z * tmp, 0.0, priv_H.x * tmp}; // unit vector theta = acos (priv_N.x); if (priv_N.z < 0.0) theta = Pi2-theta; } else { - priv_N.Set (1.0, 0.0, 0.0); + priv_N = {1.0, 0.0, 0.0}; theta = 0.0; // convention for equatorial orbits } sint = sin(theta), cost = cos(theta); @@ -437,7 +437,7 @@ void Elements::Calculate (const Vector &R, const Vector &V, double simt) // argument of periapsis if (e > E_CIRCLE_LIMIT) { if (i > I_NOINC_LIMIT) { - double arg = dotp (priv_N, priv_E)/e; + double arg = dot(priv_N, priv_E) / e; if (arg < -1.0) priv_omega = Pi; else if (arg > 1.0) priv_omega = 0.0; else priv_omega = acos (arg); @@ -456,12 +456,12 @@ void Elements::Calculate (const Vector &R, const Vector &V, double simt) // true anomaly if (e > E_CIRCLE_LIMIT) { - priv_tra = acos (dotp (priv_E, R)/(e*priv_r)); + priv_tra = std::acos(dot(priv_E, R) / (e * priv_r)); if (rv < 0.0) priv_tra = Pi2-priv_tra; } else { if (i > I_NOINC_LIMIT) { - priv_tra = acos (dotp (priv_N, R)/priv_r); - if (dotp (priv_N, V) > 0.0) priv_tra = Pi2-priv_tra; + priv_tra = std::acos(dot(priv_N, R) / priv_r); + if (dot(priv_N, V) > 0.0) priv_tra = Pi2 - priv_tra; } else { priv_tra = acos (R.x/priv_r); if (V.x > 0.0) priv_tra = Pi2-priv_tra; @@ -526,7 +526,7 @@ void Elements::Calculate (const Vector &R, const Vector &V, double simt) #endif } -void Elements::PlaneCoeffs (const Vector &R, const Vector &V, double &a, double &b, double &c) +void Elements::PlaneCoeffs (const VECTOR3 &R, const VECTOR3 &V, double &a, double &b, double &c) { // warning: may need unit vectors for R and V // for numerical stability diff --git a/Src/Orbiter/Element.h b/Src/Orbiter/Element.h index cb5257999..6bfed5bed 100644 --- a/Src/Orbiter/Element.h +++ b/Src/Orbiter/Element.h @@ -71,7 +71,7 @@ class Elements { // (the angle between the perihelion and the object) // Note -Pi <= theta < Pi - void Pol2Crt (double r, double ta, Vector &pos) const; + void Pol2Crt (double r, double ta, VECTOR3 &pos) const; // Convert orbital position from polar coordinates (radius r, true anomaly ta) // to cartesian coordinates (pos) @@ -83,31 +83,31 @@ class Elements { { return sqrt (priv_mu * (2.0/r - 1.0/a)); } // return magnitude of orbital velocity for given radius distance - void PosVel (Vector &pos, Vector &vel, double t) const; + void PosVel (VECTOR3 &pos, VECTOR3 &vel, double t) const; // calculate position and velocity relative to reference // body at time t - Vector Pos (double t) const; + VECTOR3 Pos (double t) const; - void PosVel_TA (Vector &pos, Vector &vel, double ta) const; + void PosVel_TA (VECTOR3 &pos, VECTOR3 &vel, double ta) const; // calculate position and velocity relative to reference // at true anomaly ta double Spd_TA(double ta) const; // magnitude of orbital velocity at true anomaly ta - void Update (Vector &pos, Vector &vel); + void Update (VECTOR3 &pos, VECTOR3 &vel); // as PosVel, but also updates internal time-varying data to current simulation time - void Calculate (const Vector &R, const Vector &V, double t); + void Calculate (const VECTOR3 &R, const VECTOR3 &V, double t); // Calculate elements from position and velocity at simulation time t - void PlaneCoeffs (const Vector &R, const Vector &V, double &a, double &b, double &c); + void PlaneCoeffs (const VECTOR3 &R, const VECTOR3 &V, double &a, double &b, double &c); // Given position and velocity vectors, return the coefficients of the // orbital plane E: ax + by + cz + d = 0 (d=0 since plane through origin) - bool AscendingNode (Vector &asc) const; - bool DescendingNode (Vector &desc) const; + bool AscendingNode (VECTOR3 &asc) const; + bool DescendingNode (VECTOR3 &desc) const; // return cartesian coordinates of ascending and descending nodes // in the reference system // return value: error flag (true=ok, false=node doesn't exist (only @@ -132,9 +132,9 @@ class Elements { double P() const { return priv_p; } // parameter of conic section (semi-latus rectum) // time-varying parameters (calculated at the time of the last call to Calculate2) - const Vector &RVec() const { return priv_R; } // radius vector - const Vector &VVec() const { return priv_V; } // velocity vector - const Vector &HVec() const { return priv_H; } // specific angular momentum H = R x V + const VECTOR3 &RVec() const { return priv_R; }// radius vector + const VECTOR3 &VVec() const { return priv_V; }// velocity vector + const VECTOR3 &HVec() const { return priv_H; }// specific angular momentum H = R x V double Radius() const { return priv_r; } // radius vector length double Vel() const { return priv_v; } // magnitude of velocity double MeanAnm() const { return priv_ma; } // mean anomaly @@ -167,14 +167,14 @@ class Elements { double priv_omega; // argument of periapsis [rad] double priv_p; // parameter of conic section: r = p / (1 + e cos nu) double priv_tmp; // for calculation of true anomaly (if e < 1) - Vector priv_H; // normal to orbital plane (no unit vector) - Vector priv_N; // points towards ascending node (unit vector) - Vector priv_E; // points towards periapsis (no unit vector) + VECTOR3 priv_H; // normal to orbital plane (no unit vector) + VECTOR3 priv_N; // points towards ascending node (unit vector) + VECTOR3 priv_E; // points towards periapsis (no unit vector) // the following parameters vary with time and are only valid at the // time when Calculate or Update is called - Vector priv_R; // radius vector - Vector priv_V; // velocity vector + VECTOR3 priv_R; // radius vector + VECTOR3 priv_V; // velocity vector double priv_r; // radius vector length double priv_v; // magnitude of velocity double priv_ea; // eccentric anomaly diff --git a/Src/Orbiter/FlightRecorder.cpp b/Src/Orbiter/FlightRecorder.cpp index 990b4fc9b..ab4eb27a8 100644 --- a/Src/Orbiter/FlightRecorder.cpp +++ b/Src/Orbiter/FlightRecorder.cpp @@ -128,16 +128,16 @@ void Vessel::FRecorder_Save (bool force) for (iter = 0; iter < niter; iter++) { if (ref) { - Vector pos = s0->pos-ref->GPos(); - Vector vel = s0->vel-ref->GVel(); + VECTOR3 pos = s0->pos - ref->GPos(); + VECTOR3 vel = s0->vel - ref->GVel(); if (frec_last.frm == 1) { // map to equatorial //vel = tmul (cbody->GRot(), vel); double lng, lat, rad, vref; ref->LocalToEquatorial (tmul (ref->GRot(), pos), lng, lat, rad); vref = Pi2/ref->RotT() * rad*cos(lat); - vel = tmul (ref->GRot(), vel) - Vector(-vref*sin(lng),0,vref*cos(lng)); + vel = tmul(ref->GRot(), vel) - VECTOR3{-vref * std::sin(lng), 0, vref * std::cos(lng)}; } - double cddir = dotp (vel.unit(), frec_last.rvel.unit()); + double cddir = dot(unit(vel), unit(frec_last.rvel)); bool nextstep = (fstatus == FLIGHTSTATUS_FREEFLIGHT && (g_pOrbiter->Cfg()->CfgRecPlayPrm.bSysInterval ? td.SysT1 - frec_last_syst : td.SimT1 - frec_last.simt) > max_step); @@ -161,7 +161,7 @@ void Vessel::FRecorder_Save (bool force) ofstream ofs (FRfname, ios::app); ofs << setprecision(10) << (frec_last.simt-Tofs) << ' '; if (frec_last.crd == 1) { // store in polar coords - double r = frec_last.rpos.length(); + double r = len(frec_last.rpos); double phi = atan2 (frec_last.rpos.z, frec_last.rpos.x); double tht = asin (frec_last.rpos.y/r); ofs << setprecision(12) << r << ' ' << phi << ' ' << tht << ' '; @@ -415,8 +415,8 @@ bool Vessel::FRecorder_Read (const char *scname) frec[nfrec].simt = simt; frec[nfrec].frm = frm; frec[nfrec].ref = ref; - frec[nfrec].rpos.Set (x, y, z); - frec[nfrec].rvel.Set (vx, vy, vz); + frec[nfrec].rpos = { x, y, z}; + frec[nfrec].rvel = {vx, vy, vz}; nfrec++; } } @@ -487,21 +487,21 @@ void Vessel::FRecorder_Play () double dT, dt, w0, w1; double r0, r1, v0, v1, a0, b, lng, lat, rad, vref; int i; - static Vector s; + static VECTOR3 s; while (cfrec+2 < nfrec && frec[cfrec+1].simt < td.SimT1) cfrec++; dT = frec[cfrec+1].simt - frec[cfrec].simt; dt = td.SimT1 - frec[cfrec].simt; - Vector P0 = frec[cfrec].rpos, P1 = frec[cfrec+1].rpos; - Vector V0 = frec[cfrec].rvel, V1 = frec[cfrec+1].rvel; + VECTOR3 P0 = frec[cfrec].rpos, P1 = frec[cfrec + 1].rpos; + VECTOR3 V0 = frec[cfrec].rvel, V1 = frec[cfrec + 1].rvel; if (frec[cfrec].frm == 1) { // map from equatorial frame // propagate from current rotation state to rotation state at last sample double dlng = Pi2*dt/frec[cfrec].ref->RotT(), sind = sin(dlng), cosd = cos(dlng); s.x = P0.x*cosd + P0.z*sind; s.z = -P0.x*sind + P0.z*cosd; s.y = P0.y; - P0.Set (mul (frec[cfrec].ref->s1->R, s)); + P0 = mul(frec[cfrec].ref->s1->R, s); // Needs to be fixed! frec[cfrec].ref->LocalToEquatorial (s, lng, lat, rad); @@ -509,20 +509,20 @@ void Vessel::FRecorder_Play () s.x = V0.x*cosd + V0.z*sind; s.z = -V0.x*sind + V0.z*cosd; s.y = V0.y; - V0.Set (mul (frec[cfrec].ref->s1->R, s + Vector (-vref*sin(lng),0,vref*cos(lng)))); + V0 = mul(frec[cfrec].ref->s1->R, s + VECTOR3{-vref * std::sin(lng), 0, vref * std::cos(lng)}); } if (frec[cfrec+1].frm == 1) { // map from equatorial frame double dlng = Pi2*(dt-dT)/frec[cfrec+1].ref->RotT(), sind = sin(dlng), cosd = cos(dlng); s.x = P1.x*cosd + P1.z*sind; s.z = -P1.x*sind + P1.z*cosd; s.y = P1.y; - P1.Set (mul (frec[cfrec+1].ref->s1->R, s)); + P1 = mul(frec[cfrec + 1].ref->s1->R, s); frec[cfrec+1].ref->LocalToEquatorial (s, lng, lat, rad); vref = Pi2/frec[cfrec+1].ref->RotT() * rad * cos(lat); s.x = V1.x*cosd + V1.z*sind; s.z = -V1.x*sind + V1.z*cosd; s.y = V1.y; - V1.Set (mul (frec[cfrec].ref->s1->R, s + Vector (-vref*sin(lng),0,vref*cos(lng)))); + V1 = mul(frec[cfrec].ref->s1->R, s + VECTOR3{-vref * std::sin(lng), 0, vref * std::cos(lng)}); } for (i = 0; i < 3; i++) { @@ -541,9 +541,9 @@ void Vessel::FRecorder_Play () if (td.SimT1 < frec_att[nfrec_att-1].simt) { // store old orientation for calculating angular velocities - Vector r1 (sv->R.m11, sv->R.m21, sv->R.m31); - Vector r2 (sv->R.m12, sv->R.m22, sv->R.m32); - Vector r3 (sv->R.m13, sv->R.m23, sv->R.m33); + VECTOR3 r1{sv->R.m11, sv->R.m21, sv->R.m31}; + VECTOR3 r2{sv->R.m12, sv->R.m22, sv->R.m32}; + VECTOR3 r3{sv->R.m13, sv->R.m23, sv->R.m33}; while (cfrec_att+2 < nfrec_att && frec_att[cfrec_att+1].simt < td.SimT1) cfrec_att++; dt = frec_att[cfrec_att+1].simt - frec_att[cfrec_att].simt; @@ -560,7 +560,7 @@ void Vessel::FRecorder_Play () Q.interp (frec_att[cfrec_att].q, frec_att[cfrec_att+1].q, w1); sv->R.Set (Q); double lng, lat, rad, slng, clng, slat, clat; - Vector loc = tmul (frec_att[cfrec_att].ref->s1->R, sv->pos - frec_att[cfrec_att].ref->s1->pos); + VECTOR3 loc = tmul(frec_att[cfrec_att].ref->s1->R, sv->pos - frec_att[cfrec_att].ref->s1->pos); frec_att[cfrec_att].ref->LocalToEquatorial (loc, lng, lat, rad); slng = sin(lng), clng = cos(lng), slat = sin(lat), clat = cos(lat); sv->R.postmul (Matrix (-slng, 0, clng, @@ -576,9 +576,9 @@ void Vessel::FRecorder_Play () // this may need more thought. The current algorithm may work // in a differential sense, but there should be something more // intelligent in the case of large changes in orientation - Vector dx = tmul (sv->R,r1); - Vector dy = tmul (sv->R,r2); - Vector dz = tmul (sv->R,r3); + VECTOR3 dx = tmul(sv->R,r1); + VECTOR3 dy = tmul(sv->R,r2); + VECTOR3 dz = tmul(sv->R,r3); sv->omega.x = atan2 (dy.z, dz.z) * td.iSimDT; sv->omega.y = -atan2 (dx.z, dx.x) * td.iSimDT; sv->omega.z = atan2 (dx.y, dx.x) * td.iSimDT; @@ -749,11 +749,11 @@ void Vessel::FRecorder_EndPlayback () { if (bFRplayback) { bFRplayback = false; - Amom_add.Set(0,0,0); - rvel_base.Set (s0->vel); - rvel_add.Set(0,0,0); - rpos_base.Set (s0->pos); - rpos_add.Set(0,0,0); + Amom_add = {0, 0, 0}; + rvel_base = s0->vel; + rvel_add = {0, 0, 0}; + rpos_base = s0->pos; + rpos_add = {0, 0, 0}; s0->Q.Set (s0->R); if (supervessel && supervessel->GetVessel(0) == this) supervessel->FRecorder_EndPlayback(); diff --git a/Src/Orbiter/GraphicsAPI.cpp b/Src/Orbiter/GraphicsAPI.cpp index 8fd818197..7f51bd951 100644 --- a/Src/Orbiter/GraphicsAPI.cpp +++ b/Src/Orbiter/GraphicsAPI.cpp @@ -727,8 +727,8 @@ ParticleStream::ParticleStream (GraphicsClient *_gc, PARTICLESTREAMSPEC *pss) gc = _gc; level = NULL; hRef = NULL; - lpos = _V(0,0,0); pos = &lpos; - ldir = _V(0,0,0); dir = &ldir; + lpos = {0,0,0}; pos = &lpos; + ldir = {0,0,0}; dir = &ldir; } ParticleStream::~ParticleStream () @@ -815,7 +815,7 @@ void ScreenAnnotation::Reset () { ClearText(); SetPosition (0.1, 0.1, 0.5, 0.6); - SetColour (_V(1.0,0.7,0.2)); + SetColour ({1.0,0.7,0.2}); SetSize (1.0); } diff --git a/Src/Orbiter/LightEmitter.cpp b/Src/Orbiter/LightEmitter.cpp index ef3faac89..0d2641c18 100644 --- a/Src/Orbiter/LightEmitter.cpp +++ b/Src/Orbiter/LightEmitter.cpp @@ -23,8 +23,8 @@ LightEmitter::LightEmitter () col_diff.r = col_diff.g = col_diff.b = col_diff.a = 1.0f; col_spec.r = col_spec.g = col_spec.b = col_spec.a = 1.0f; col_ambi.r = col_ambi.g = col_ambi.b = col_ambi.a = 1.0f; - lpos = _V(0,0,0); pos = &lpos; - ldir = _V(0,0,1); dir = &ldir; + lpos = {0,0,0}; pos = &lpos; + ldir = {0,0,1}; dir = &ldir; lintens = 1.0; intens = &lintens; } @@ -39,8 +39,8 @@ LightEmitter::LightEmitter (COLOUR4 diffuse, COLOUR4 specular, COLOUR4 ambient) col_diff = diffuse; col_spec = specular; col_ambi = ambient; - lpos = _V(0,0,0); pos = &lpos; - ldir = _V(0,0,1); dir = &ldir; + lpos = {0,0,0}; pos = &lpos; + ldir = {0,0,1}; dir = &ldir; lintens = 1.0; intens = &lintens; } diff --git a/Src/Orbiter/Mfd.cpp b/Src/Orbiter/Mfd.cpp index 536ffa241..f4295186d 100644 --- a/Src/Orbiter/Mfd.cpp +++ b/Src/Orbiter/Mfd.cpp @@ -1194,7 +1194,7 @@ void UpdateEllipse (int cntx, int cnty, double scale, { int i; int idx1 = ELN-1, idx2 = 2*ELNQ, idx3 = idx2-1; - Vector tmp, v[ELN]; + VECTOR3 tmp, v[ELN]; double phi, sphi, cphi, r, x, y; double fac = Pi05/(double)ELNQ; double e2 = el->e * el->e; @@ -1230,7 +1230,7 @@ void UpdateHyperbola (int cntx, int cnty, int IW, int IH, double scale, int i; int idx = ELNH-1; - Vector asc, desc, v[ELN-1]; + VECTOR3 asc, desc, v[ELN-1]; double phi, cphi, sphi, r, x, y, len = 1; double p = el->PeDist()*(1.0+el->e); // parameter of polar equation double radmax = 1.5*cntx/scale; @@ -1264,11 +1264,11 @@ void UpdateHyperbola (int cntx, int cnty, int IW, int IH, double scale, pt[ELN+1].y = pt[idx].y; pt[ELN+2].x = -1; // apoapsis - mark invalid if (ascok = el->AscendingNode (asc)) { // ascending node - if ((len = asc.length()) > radmax) asc *= (radmax/len); + if ((len = ::len(asc)) > radmax) asc *= (radmax / len); MapScreen (cntx, cnty, scale, mul (irot, asc), pt+(ELN+3)); } if (descok = el->DescendingNode (desc)) { // descending node - if ((len = desc.length()) > radmax) desc *= (radmax/len); + if ((len = ::len(desc)) > radmax) desc *= (radmax / len); MapScreen (cntx, cnty, scale, mul (irot, desc), pt+(ELN+4)); } if (!ascok) { diff --git a/Src/Orbiter/Mfd.h b/Src/Orbiter/Mfd.h index 8fdc646b0..e3751b23c 100644 --- a/Src/Orbiter/Mfd.h +++ b/Src/Orbiter/Mfd.h @@ -353,7 +353,7 @@ void UpdateOrbitGraph (int cntx, int cnty, int IW, int IH, double scale, // generate polygon for general conical section (ellipse or hyperbola) // given orbital elements and projection matrices -inline void MapScreen (int cntx, int cnty, double scale, const Vector &v, oapi::IVECTOR2 *p) +inline void MapScreen (int cntx, int cnty, double scale, const VECTOR3 &v, oapi::IVECTOR2 *p) { // map logical point into instrument coords p->x = cntx + (int)(v.x*scale); diff --git a/Src/Orbiter/MfdAlign.cpp b/Src/Orbiter/MfdAlign.cpp index d99a2a3d5..ae14ba96f 100644 --- a/Src/Orbiter/MfdAlign.cpp +++ b/Src/Orbiter/MfdAlign.cpp @@ -136,8 +136,8 @@ void Instrument_OPlaneAlign::UpdateDraw (oapi::Sketchpad *skp) // update my elements double refrad = elref->Size(); - Vector sp = vessel->GPos() - elref->GPos(); - Vector sv = vessel->GVel() - elref->GVel(); + VECTOR3 sp = vessel->GPos() - elref->GPos(); + VECTOR3 sv = vessel->GVel() - elref->GVel(); shpel->Calculate(sp, sv, td.SimT1); bool subsurf_node = (shpel->PeDist() < refrad); @@ -177,7 +177,7 @@ void Instrument_OPlaneAlign::UpdateDraw (oapi::Sketchpad *skp) } // update target elements - Vector tp, tv; + VECTOR3 tp, tv; if (tgt) { tp = tgt->GPos() - elref->GPos(); tv = tgt->GVel() - elref->GVel(); @@ -197,22 +197,21 @@ void Instrument_OPlaneAlign::UpdateDraw (oapi::Sketchpad *skp) } // ship in planet coords - double svmag = sv.length(); - sp.unify(), sv.unify(); + double svmag = len(sv); + sp = unit(sp); sv = unit(sv); // normals of the two orbital planes - Vector nm1 = shpel->HVec().unit(); - Vector nm2 = tgtel->HVec().unit(); + VECTOR3 nm1 = unit(shpel->HVec()); + VECTOR3 nm2 = unit(tgtel->HVec()); - double reli = xangle(nm1, nm2); // relative inclination + double reli = angle(nm1, nm2); // relative inclination double didt = (reli - preli) / dT; // inclination rate preli = reli; // remember for next step // angle between ship and ascending node - Vector nd = crossp(nm1, nm2); - nd.unify(); - double cosp = dotp(nd, sp); + VECTOR3 nd = unit(cross(nm1, nm2)); + double cosp = dot(nd, sp); double Aan = acos(cosp); - if (dotp(nm1, crossp(nd, sp)) < 0) Aan = Pi2 - Aan; // ascending node is behind us + if (dot(nm1, cross(nd, sp)) < 0) Aan = Pi2 - Aan; // ascending node is behind us double Adn = posangle(Aan + Pi); double Aan_signed = (Aan < Pi ? Aan : Pi2 - Aan); @@ -371,7 +370,7 @@ void Instrument_OPlaneAlign::UpdateDraw (oapi::Sketchpad *skp) CY = (55*IH) / 100; int xa, ya, xd, yd; Matrix irot(IRotMatrix(shpel->cost, shpel->sint, shpel->cosi, shpel->sini)); - Vector P = mul(irot, sp); + VECTOR3 P = mul(irot, sp); x = (int)(RD*P.x); y = (int)(RD*P.z); if (mode == ORBIT) { @@ -420,12 +419,12 @@ void Instrument_OPlaneAlign::UpdateDraw (oapi::Sketchpad *skp) bool Instrument_OPlaneAlign::GetTimingsFromSurface(double &Tan, double &Aan, double &Tdn, double &Adn, double &VSurf) { // target plane normal - Vector nm2 = tgtel->HVec().unit(); + VECTOR3 nm2 = unit(tgtel->HVec()); nm2 = tmul(elref->GRot(), nm2); // rotate into frame of reference planet double nx = nm2.x, ny = nm2.y, nz = nm2.z; // ship position in reference body frame - Vector p = elref->GlobalToLocal(vessel->GPos()); + VECTOR3 p = elref->GlobalToLocal(vessel->GPos()); double y0 = p.y; double r0 = hypot(p.x, p.z); double phi0 = atan2(p.x, p.z); diff --git a/Src/Orbiter/MfdDocking.cpp b/Src/Orbiter/MfdDocking.cpp index 9ee4e6ebf..13eef925d 100644 --- a/Src/Orbiter/MfdDocking.cpp +++ b/Src/Orbiter/MfdDocking.cpp @@ -311,31 +311,31 @@ void Instrument_Docking::UpdateDraw (oapi::Sketchpad *skp) if (!tgt) return; - Vector dpos; + VECTOR3 dpos; double dstold = dst; if (!ps) { // no dock information // target object in ship coords - dpos.Set (tmul (vessel->GRot(), tgt->GPos() - vessel->GPos())); - dst = dpos.length(); + dpos = tmul(vessel->GRot(), tgt->GPos() - vessel->GPos()); + dst = ::len(dpos); } else { // dock position in ship coords - dpos.Set (tmul (vessel->GRot(), mul (tgt->GRot(), ps->ref) + tgt->GPos() - vessel->GPos())); - dst = dpos.dist (vessel->dock[refdock]->ref); + dpos = tmul(vessel->GRot(), mul(tgt->GRot(), ps->ref) + tgt->GPos() - vessel->GPos()); + dst = dist(dpos, vessel->dock[refdock]->ref); // dock position in ship approach frame: - Vector adposold(adpos); // store for velocity calculation - adpos.Set (mul (dockframe, dpos)); + VECTOR3 adposold = adpos; // store for velocity calculation + adpos = mul(dockframe, dpos); // dock approach direction in ship coords: - Vector ddir(tmul(vessel->GRot(), mul(tgt->GRot(), -ps->dir))); + VECTOR3 ddir = tmul(vessel->GRot(), mul(tgt->GRot(), -ps->dir)); // dock "up" direction in ship coords: - Vector drot(tmul(vessel->GRot(), mul(tgt->GRot(), ps->rot))); + VECTOR3 drot = tmul(vessel->GRot(), mul(tgt->GRot(), ps->rot)); // dock approach direction in ship approach frame: - Vector addir (mul (dockframe, ddir)); + VECTOR3 addir = mul(dockframe, ddir); // dock "up" direction in ship approach frame: - Vector adrot(mul(dockframe, drot)); + VECTOR3 adrot = mul(dockframe, drot); // Euler angles (yaw, pitch, bank) of vessel with respect to correct docking attitude double yaw = -atan2(addir.x, addir.z); @@ -343,10 +343,10 @@ void Instrument_Docking::UpdateDraw (oapi::Sketchpad *skp) double bank = -atan2(adrot.x, adrot.y); // dock reference point in ship approach frame - Vector adockref (mul (dockframe, vessel->dock[refdock]->ref)); + VECTOR3 adockref = mul(dockframe, vessel->dock[refdock]->ref); // intersection of approach vector with ship's approach xy plane double s = (adockref.z - adpos.z) / addir.z; - Vector Z (adpos - adockref + addir*s); + VECTOR3 Z = adpos - adockref + addir * s; double z = std::hypot(Z.x, Z.y); double lz = (log10(z)+1.0+scale) * 0.25; diff --git a/Src/Orbiter/MfdDocking.h b/Src/Orbiter/MfdDocking.h index 13621ecb9..8120572ce 100644 --- a/Src/Orbiter/MfdDocking.h +++ b/Src/Orbiter/MfdDocking.h @@ -49,7 +49,7 @@ class Instrument_Docking: public Instrument { int Legacy_port; // target docking port (legacy method) char title[50]; int circx, circy, circr, bar0, barh, barw, bar0x, bar1x; - Vector adpos; // previous station location in ship approach frame + VECTOR3 adpos; // previous station location in ship approach frame double dst; // previous station distance Matrix dockframe; // rotation matrix ship local -> ship approach frame oapi::Brush *brush[4]; diff --git a/Src/Orbiter/MfdLanding.cpp b/Src/Orbiter/MfdLanding.cpp index e73a3478d..6ecf3c41c 100644 --- a/Src/Orbiter/MfdLanding.cpp +++ b/Src/Orbiter/MfdLanding.cpp @@ -168,8 +168,8 @@ void Instrument_Landing::UpdateDraw (oapi::Sketchpad *skp) cbuf[0] = '0'+i-1; skp->Text (circx+1, circy+rd-2, cbuf, 1); } - Vector hvel (tmul (sp->ref->GRot(), sp->groundvel_glob)); - hvel.Set (mul (sp->L2H, hvel)); + VECTOR3 hvel = tmul(sp->ref->GRot(), sp->groundvel_glob); + hvel = mul(sp->L2H, hvel); hspd = std::hypot (hvel.x, hvel.z); vdir = atan2 (hvel.x, hvel.z) - sp->dir; if (vdir <= -Pi) vdir += Pi2; diff --git a/Src/Orbiter/MfdMap.cpp b/Src/Orbiter/MfdMap.cpp index cacba0d80..2a97ef8a2 100644 --- a/Src/Orbiter/MfdMap.cpp +++ b/Src/Orbiter/MfdMap.cpp @@ -383,8 +383,8 @@ void Instrument_Map::UpdateDraw_Map (oapi::Sketchpad *skp) g_focusobj->Name(), fabs(lng)*DEG, lng>=0.0 ? 'E':'W', fabs(lat)*DEG, lat>=0.0 ? 'N':'S', DistStr(rad-refplanet->Size())); if (sp) { - Vector hvel (tmul (sp->ref->GRot(), sp->groundvel_glob)); - hvel.Set (mul (sp->L2H, hvel)); + VECTOR3 hvel = tmul(sp->ref->GRot(), sp->groundvel_glob); + hvel = mul(sp->L2H, hvel); double crs = atan2 (hvel.x, hvel.z); sprintf (cbuf+strlen(cbuf)-1, ", Crs %05.1fº]", Deg(posangle(crs))); } diff --git a/Src/Orbiter/MfdMap_old.cpp b/Src/Orbiter/MfdMap_old.cpp index 9a2df67d4..ce7c73e88 100644 --- a/Src/Orbiter/MfdMap_old.cpp +++ b/Src/Orbiter/MfdMap_old.cpp @@ -552,10 +552,10 @@ void Instrument_MapOld::CalcOrbitProj (const Elements *el, const Planet *planet, el->sint, 0, el->cost)); R.tpremul (planet->GRot()); - Vector rg, rl; + VECTOR3 rg, rl; for (i = 0; i < npt05; i++) { - rl.Set (mul (R, Vector(cosp[i],0,sinp[i]))); + rl = mul(R, VECTOR3{cosp[i], 0, sinp[i]}); x = rl.x, y = rl.y, z = rl.z; lng = atan2 (z,x) + Pi; // maps start at -Pi (180°W) lat = atan(y/std::hypot(x,z)); @@ -585,7 +585,7 @@ bool Instrument_MapOld::CalcIntersect (const Elements *el, const Planet *planet, double lng, lat, r, ta = acos(arg); double f1 = (double)mapw/Pi2; int yofs = maph/2; - Vector pos; + VECTOR3 pos; el->Pol2Crt (rad, ta, pos); planet->GlobalToEquatorial (pos+planet->GPos(), lng, lat, r); is1->x = (int)((lng+Pi)*f1); diff --git a/Src/Orbiter/MfdOrbit.cpp b/Src/Orbiter/MfdOrbit.cpp index b581536f4..cdcca5546 100644 --- a/Src/Orbiter/MfdOrbit.cpp +++ b/Src/Orbiter/MfdOrbit.cpp @@ -267,8 +267,8 @@ void Instrument_Orbit::UpdateDraw (oapi::Sketchpad *skp) bool bValidTgtEl = (elref && tgt); if (bValidShpEl) { - Vector pos = vessel->GPos()-elref->GPos(); - Vector vel = vessel->GVel()-elref->GVel(); + VECTOR3 pos = vessel->GPos() - elref->GPos(); + VECTOR3 vel = vessel->GVel() - elref->GVel(); if (frmmode == FRM_EQU) { // convert to equatorial frame pos = tmul (elref->RotObliq(), pos); vel = tmul (elref->RotObliq(), vel); @@ -281,8 +281,8 @@ void Instrument_Orbit::UpdateDraw (oapi::Sketchpad *skp) max (2.0*shpel->PeDist(), shpel->Radius())); } if (bValidTgtEl) { - Vector pos = tgt->GPos()-elref->GPos(); - Vector vel = tgt->GVel()-elref->GVel(); + VECTOR3 pos = tgt->GPos() - elref->GPos(); + VECTOR3 vel = tgt->GVel() - elref->GVel(); if (frmmode == FRM_EQU) { // convert to equatorial frame pos = tmul (elref->RotObliq(), pos); vel = tmul (elref->RotObliq(), vel); diff --git a/Src/Orbiter/MfdSurface.cpp b/Src/Orbiter/MfdSurface.cpp index 4f38db3d7..2cafec80b 100644 --- a/Src/Orbiter/MfdSurface.cpp +++ b/Src/Orbiter/MfdSurface.cpp @@ -729,7 +729,7 @@ void Instrument_Surface::UpdateDraw (oapi::Sketchpad *skp) spd_valid = IAS (vessel->ProxyBody(), spd); break; case 4: // orbital speed - spd = (vessel->GVel()-vessel->ProxyBody()->GVel()).length(); + spd = len(vessel->GVel()-vessel->ProxyBody()->GVel()); spd_valid = true; break; } diff --git a/Src/Orbiter/MfdSync.cpp b/Src/Orbiter/MfdSync.cpp index dd2e6bfa3..76a588877 100644 --- a/Src/Orbiter/MfdSync.cpp +++ b/Src/Orbiter/MfdSync.cpp @@ -161,7 +161,7 @@ void Instrument_OSync::UpdateDraw (oapi::Sketchpad *skp) rlng = man_rlng, sinr = man_sinr, cosr = man_cosr; break; } - Vector v(mul (rot1, Vector(cosr, 0.0, sinr))); + VECTOR3 v = mul(rot1, VECTOR3{cosr, 0, sinr}); skp->SetPen (draw[0][0].solidpen); skp->Line (ICNTX, ICNTY, ICNTX+(int)(v.x*pixrad), ICNTY-(int)(v.z*pixrad)); @@ -170,15 +170,13 @@ void Instrument_OSync::UpdateDraw (oapi::Sketchpad *skp) skp->Text (x, y, cbuf, strlen(cbuf)); y += (3*ch)/2; // ship in planet coords - Vector sp = vessel->GPos()-ref->GPos(); - Vector sv = vessel->GVel()-ref->GVel(); + VECTOR3 sp = vessel->GPos() - ref->GPos(); + VECTOR3 sv = vessel->GVel() - ref->GVel(); // normals of the two orbital planes - Vector nm1 = crossp (sv, sp); - Vector nm2 = crossp (tgt->GVel()-ref->GVel(), tgt->GPos()-ref->GPos()); - nm1.unify(); - nm2.unify(); + VECTOR3 nm1 = unit(cross(sv, sp)); + VECTOR3 nm2 = unit(cross(tgt->GVel() - ref->GVel(), tgt->GPos() - ref->GPos())); // relative inclination between ship's and target's orbital planes - double reli = xangle (nm1, nm2); + double reli = angle(nm1, nm2); // calculate ship time to reference point double myta = myel->TrueAnm(); @@ -207,12 +205,12 @@ void Instrument_OSync::UpdateDraw (oapi::Sketchpad *skp) sprintf (cbuf, "DLng%7.2fº", Deg(dlng)); skp->Text (x, y, cbuf, strlen(cbuf)); y += ch; // target distance - Vector rp = tgt->GPos()-vessel->GPos(); - sprintf (cbuf, "Dist%s", DistStr (rp.length())); + VECTOR3 rp = tgt->GPos() - vessel->GPos(); + sprintf(cbuf, "Dist%s", DistStr(len(rp))); skp->Text (x, y, cbuf, strlen(cbuf)); y += ch; // target velocity - Vector rv = tgt->GVel()-vessel->GVel(); - sprintf (cbuf, "RVel%s", DistStr (rv.length())); + VECTOR3 rv = tgt->GVel() - vessel->GVel(); + sprintf(cbuf, "RVel%s", DistStr (len(rv))); skp->Text (x, y, cbuf, strlen(cbuf)); y += ch; // find best match diff --git a/Src/Orbiter/MfdTransfer.cpp b/Src/Orbiter/MfdTransfer.cpp index 4ceee5783..69e83829f 100644 --- a/Src/Orbiter/MfdTransfer.cpp +++ b/Src/Orbiter/MfdTransfer.cpp @@ -55,7 +55,8 @@ Instrument_Transfer::Instrument_Transfer (Pane *_pane, INT_PTR _id, const Spec & hto_a = 0.0; nstep = 2000; // should be variable step_scale = 10.0; - path = new Vector[nstep]; TRACENEW + // TODO: re-write without using raw pointers + path = new VECTOR3[nstep]; TRACENEW pathp = new oapi::IVECTOR2[100]; TRACENEW process_num = false; @@ -109,7 +110,7 @@ void Instrument_Transfer::UpdateDraw (oapi::Sketchpad *skp) int y, x0 = cw/2, x1 = IW-12*cw, y0 = 1+(ch*3)/2; double scale; // scaling factor for orbit display const Elements *tgtel, *workel; - Vector sp, sv; + VECTOR3 sp, sv; Matrix rot2, *workr; oapi::IVECTOR2 pt[ELN+5], p0; double p1, p2, A, B, C, d, p, q, arg, sinr, cosr, rlng; @@ -122,8 +123,8 @@ void Instrument_Transfer::UpdateDraw (oapi::Sketchpad *skp) // sanity checks if (elref) { - sp.Set (src->GPos()-elref->GPos()); // ship in planet coords - sv.Set (src->GVel()-elref->GVel()); + sp = src->GPos() - elref->GPos(); // ship in planet coords + sv = src->GVel() - elref->GVel(); shpel->Calculate (sp, sv, td.SimT1); bValid = true; } else bValid = false; @@ -161,7 +162,7 @@ void Instrument_Transfer::UpdateDraw (oapi::Sketchpad *skp) // ship -> src location indicator if (src != vessel) { int x, y; - Vector dp (mul (irot, vessel->GPos() - src->GPos())); + VECTOR3 dp = mul(irot, vessel->GPos() - src->GPos()); double r = std::hypot (dp.x, dp.z); x = (int)(IW*0.1/r*dp.x); y = (int)(IW*0.1/r*dp.z); @@ -230,7 +231,7 @@ void Instrument_Transfer::UpdateDraw (oapi::Sketchpad *skp) cosr = cos(rlng); // resolve ambiguity in sine if (fabs (A*cosr + B*sinr + C) > fabs (-A*cosr + B*sinr + C)) rlng = Pi-rlng, cosr = -cosr; - Vector v(mul (*workr, Vector(cosr, 0.0, sinr))); + VECTOR3 v = mul(*workr, VECTOR3{cosr, 0, sinr}); skp->SetPen (draw[2][1].solidpen); skp->Line (ICNTX, ICNTY, ICNTX+(int)(v.x*pixrad), ICNTY-(int)(v.z*pixrad)); @@ -249,7 +250,7 @@ void Instrument_Transfer::UpdateDraw (oapi::Sketchpad *skp) // target postition at intersect time tanm = tgtel->TrueAnomaly (tgtel->MeanAnomaly (td.SimT1+dt0)); tlng = tanm + tgtel->omegab; - v.Set (mul (rot2, Vector (cos(tanm), 0.0, sin(tanm)))); + v = mul(rot2, VECTOR3{std::cos(tanm), 0.0, std::sin(tanm)}); skp->SetPen (draw[1][1].dashpen); skp->Line (ICNTX, ICNTY, ICNTX+(int)(v.x*pixrad), ICNTY-(int)(v.z*pixrad)); } else { @@ -325,12 +326,10 @@ void Instrument_Transfer::UpdateDraw (oapi::Sketchpad *skp) if (bTarget) { // normals of the two orbital planes - Vector nm1 = crossp (sv, sp); - Vector nm2 = crossp (tgt->GVel()-elref->GVel(), tgt->GPos()-elref->GPos()); - nm1.unify(); - nm2.unify(); + VECTOR3 nm1 = unit(cross(sv, sp)); + VECTOR3 nm2 = unit(cross(tgt->GVel() - elref->GVel(), tgt->GPos() - elref->GPos())); // relative inclination between ship's and target's orbital planes - double reli = xangle (nm1, nm2); + double reli = angle(nm1, nm2); // relative inclination ship orbit <-> target orbit skp->SetTextColor (draw[reli < RAD*1.0 ? 0:1][1].col); @@ -356,19 +355,19 @@ void Instrument_Transfer::DisplayOrbit (oapi::Sketchpad *skp, oapi::IVECTOR2 *p) double Instrument_Transfer::CalcElements (const Elements *el1, Elements *el2, double lng, double a) { // first calculate pos & vel of orbit el1 at ejection point - Vector P, V; + VECTOR3 P, V; double ta = l_eject - el1->omegab; // true anomaly at ejection point el1->PosVel_TA (P, V, ta); // add thrust double dv; if (a) { // rescale deltav so as to maintain a - double ip2 = 2.0/P.length(); + double ip2 = 2.0 / len(P); dv = sqrt (el1->Mu() * (ip2 - 1.0/a)) - sqrt (el1->Mu() * (ip2 - 1.0/el1->a)); - V *= 1.0 + dv/V.length(); + V *= 1.0 + dv / len(V); } else { // rescale a so as to maintain deltav dv = deltav; - V *= 1.0 + dv/V.length(); + V *= 1.0 + dv / len(V); } // calculate new elements @@ -378,11 +377,11 @@ double Instrument_Transfer::CalcElements (const Elements *el1, Elements *el2, do bool Instrument_Transfer::CalcStep () { - Vector refpos, a0, a1, a2, v1, v2; + VECTOR3 refpos, a0, a1, a2, v1, v2; double tstep, tstep_i2, tstep_i6, tb, tc; a0 = g_psys->GaccAt (step_t, step_gpos, src); - tstep = step_scale/a0.length(); + tstep = step_scale / len(a0); tstep_i2 = tstep*0.5; tstep_i6 = tstep/6.0; tb = step_t + tstep_i2; @@ -402,7 +401,7 @@ bool Instrument_Transfer::CalcStep () bool Instrument_Transfer::InitNumTrajectory (const Elements *el) { - Vector refpos, refvel, pos, vel; + VECTOR3 refpos, refvel, pos, vel; step_t = step_0 = td.SimT0; if (elref->Type() == OBJTP_PLANET) if (!((Planet*)elref)->PosVelAtTime (td.SimT0, &refpos, &refvel)) @@ -627,8 +626,9 @@ bool Instrument_Transfer::SetNstep (int np) { if (np < 2) return false; if (np == nstep) return true; // nothing to do - Vector *path_tmp = new Vector[np]; TRACENEW - memcpy (path_tmp, path, min (np, nstep)*sizeof(Vector)); + // TODO: re-write without using raw pointers + VECTOR3 *path_tmp = new VECTOR3[np]; TRACENEW + memcpy (path_tmp, path, min (np, nstep)*sizeof(VECTOR3)); delete []path; path = path_tmp; if (enable_num && np > nstep) diff --git a/Src/Orbiter/MfdTransfer.h b/Src/Orbiter/MfdTransfer.h index c2f4017d4..15b3d26e9 100644 --- a/Src/Orbiter/MfdTransfer.h +++ b/Src/Orbiter/MfdTransfer.h @@ -67,8 +67,8 @@ class Instrument_Transfer: public Instrument { int step_curr; double step_scale; double step_t, step_0; - Vector step_gpos, step_gvel; - Vector *path; // trajectory path + VECTOR3 step_gpos, step_gvel; + VECTOR3 *path; // trajectory path oapi::IVECTOR2 *pathp; // screen mapping of trajectory path static struct SavePrm { diff --git a/Src/Orbiter/Nav.cpp b/Src/Orbiter/Nav.cpp index f94e09330..f8edebd06 100644 --- a/Src/Orbiter/Nav.cpp +++ b/Src/Orbiter/Nav.cpp @@ -57,29 +57,29 @@ int Nav::IdString (char *str, int len) const return 0; } -double Nav::Dist (const Vector &gpos) const +double Nav::Dist (const VECTOR3 &gpos) const { - Vector gp; + VECTOR3 gp; GPos (gp); - return gp.dist (gpos); + return dist(gp, gpos); } -double Nav::FieldStrength (const Vector &gpos) const +double Nav::FieldStrength (const VECTOR3 &gpos) const { // field strength in arbitrary units - Vector gp; + VECTOR3 gp; GPos (gp); - double dist2 = max(gp.dist2(gpos), 1.0); + double dist2 = max(dist_2(gp, gpos), 1.0); return (range*range)/dist2; } -bool Nav::InRange (const Vector &gpos) const +bool Nav::InRange (const VECTOR3 &gpos) const { // Note "InRange" corresponds to FieldStrength > 1 - Vector gp; + VECTOR3 gp; GPos (gp); - return gp.dist2 (gpos) < range*range; + return dist_2(gp, gpos) < range * range; } void Nav::GetData (NAVDATA *data) const @@ -128,9 +128,9 @@ int Nav_VOR::IdString (char *str, int len) const return _snprintf (str, len, "VOR %s", GetId()); } -void Nav_VOR::GPos (Vector &gp) const +void Nav_VOR::GPos (VECTOR3 &gp) const { - gp.Set (mul (planet->GRot(), lpos) + planet->GPos()); + gp = mul(planet->GRot(), lpos) + planet->GPos(); //planet->EquatorialToGlobal (lng, lat, planet->Size(), gp); } @@ -210,9 +210,9 @@ int Nav_IDS::IdString (char *str, int len) const return _snprintf (str, len, "IDS %s", vessel->Name()); } -void Nav_IDS::GPos (Vector &gp) const +void Nav_IDS::GPos (VECTOR3 &gp) const { - gp.Set (vessel->GetDockGPos (ps)); + gp = vessel->GetDockGPos(ps); } void Nav_IDS::GetData (NAVDATA *data) const diff --git a/Src/Orbiter/Nav.h b/Src/Orbiter/Nav.h index a0523600d..7b82de0c8 100644 --- a/Src/Orbiter/Nav.h +++ b/Src/Orbiter/Nav.h @@ -37,10 +37,10 @@ class Nav { inline const char *GetId() const { return id; } virtual void GetData (NAVDATA *data) const; virtual int IdString (char *str, int len) const; - virtual void GPos (Vector &gp) const = 0; - double Dist (const Vector &gpos) const; - double FieldStrength (const Vector &gpos) const; - bool InRange (const Vector &gpos) const; + virtual void GPos (VECTOR3 &gp) const = 0; + double Dist (const VECTOR3 &gpos) const; + double FieldStrength (const VECTOR3 &gpos) const; + bool InRange (const VECTOR3 &gpos) const; protected: DWORD step; @@ -63,14 +63,14 @@ class Nav_VOR: public Nav { virtual int IdString (char *str, int len) const; inline const Planet *GetPlanet() const { return planet; } inline void GetEquPos (double &_lng, double &_lat) const { _lng = lng, _lat = lat; } - inline void LPos (Vector &lp) const { lp = lpos; } - void GPos (Vector &gp) const; + inline void LPos (VECTOR3 &lp) const { lp = lpos; } + void GPos (VECTOR3 &gp) const; void GetData (NAVDATA *data) const; protected: const Planet *planet; double lng, lat; - Vector lpos; + VECTOR3 lpos; }; // ======================================================================= @@ -118,7 +118,7 @@ class Nav_IDS: public Nav { Nav_IDS (const Vessel *_vessel, const PortSpec *_ps, float _freq, float _range = 2e4); inline DWORD Type () const { return TRANSMITTER_IDS; } int IdString (char *str, int len) const; - void GPos (Vector &gp) const; + void GPos (VECTOR3 &gp) const; inline const Vessel *GetVessel () const { return vessel; } inline const PortSpec *GetPortSpec () const { return ps; } void GetData (NAVDATA *data) const; @@ -137,7 +137,7 @@ class Nav_XPDR: public Nav { Nav_XPDR (const Vessel *_vessel, float _freq, float _range = 1e6); inline DWORD Type () const { return TRANSMITTER_XPDR; } int IdString (char *str, int len) const; - inline void GPos (Vector &gp) const { gp.Set (vessel->GPos()); } + inline void GPos(VECTOR3 &gp) const { gp = vessel->GPos(); } inline const Vessel *GetVessel () const { return vessel; } void GetData (NAVDATA *data) const; diff --git a/Src/Orbiter/Orbiter.cpp b/Src/Orbiter/Orbiter.cpp index 76766ed6b..6560aed6b 100644 --- a/Src/Orbiter/Orbiter.cpp +++ b/Src/Orbiter/Orbiter.cpp @@ -1325,7 +1325,7 @@ bool Orbiter::KillVessels () v = g_psys->GetVessel(j); if (v->KillPending()) continue; if (v != vessel && v->GetEnableFocus()) { - d = vessel->GPos().dist (v->GPos()); + d = dist(vessel->GPos(), v->GPos()); if (d < dmin) dmin = d, tgt = v; } } @@ -1370,7 +1370,7 @@ bool Orbiter::KillVessels () return true; } -void Orbiter::NotifyObjectJump (const Body *obj, const Vector &shift) +void Orbiter::NotifyObjectJump (const Body *obj, const VECTOR3 &shift) { if (obj == g_camera->Target()) g_camera->Drag (-shift); if (g_camera->Target()) g_camera->Update (); @@ -1389,7 +1389,7 @@ void Orbiter::NotifyObjectJump (const Body *obj, const Vector &shift) void Orbiter::NotifyObjectSize (const Body *obj) { - if (obj == g_camera->Target()) g_camera->Drag (Vector(0,0,0)); + if (obj == g_camera->Target()) g_camera->Drag({0, 0, 0}); } //----------------------------------------------------------------------------- diff --git a/Src/Orbiter/Orbiter.h b/Src/Orbiter/Orbiter.h index 44d01f923..472708772 100644 --- a/Src/Orbiter/Orbiter.h +++ b/Src/Orbiter/Orbiter.h @@ -141,7 +141,7 @@ class Orbiter { } } - void NotifyObjectJump (const Body *obj, const Vector &shift); + void NotifyObjectJump (const Body *obj, const VECTOR3 &shift); void NotifyObjectSize (const Body *obj); void SetWarpFactor (double warp, bool force = false, double delay = 0.0); diff --git a/Src/Orbiter/OrbiterAPI.cpp b/Src/Orbiter/OrbiterAPI.cpp index 80e7afe05..21b701724 100644 --- a/Src/Orbiter/OrbiterAPI.cpp +++ b/Src/Orbiter/OrbiterAPI.cpp @@ -382,70 +382,49 @@ DLLEXPORT void oapiSetEmptyMass (OBJHANDLE hVessel, double mass) DLLEXPORT void oapiGetGlobalPos (OBJHANDLE hObj, VECTOR3 *pos) { - if (((Body*)hObj)->s0) { - Vector gp(((Body*)hObj)->GPos()); - pos->x = gp.x, pos->y = gp.y, pos->z = gp.z; - } + if (((Body*)hObj)->s0) *pos = ((Body*)hObj)->GPos(); } DLLEXPORT void oapiGetGlobalVel (OBJHANDLE hObj, VECTOR3 *vel) { - if (((Body*)hObj)->s0) { - Vector gv(((Body*)hObj)->GVel()); - vel->x = gv.x, vel->y = gv.y, vel->z = gv.z; - } + if (((Body*)hObj)->s0) *vel = ((Body*)hObj)->GVel(); } DLLEXPORT void oapiGetFocusGlobalPos (VECTOR3 *pos) { - Vector gp(g_focusobj->GPos()); - pos->x = gp.x, pos->y = gp.y, pos->z = gp.z; + *pos = g_focusobj->GPos(); } DLLEXPORT void oapiGetFocusGlobalVel (VECTOR3 *vel) { - Vector gv(g_focusobj->GVel()); - vel->x = gv.x, vel->y = gv.y, vel->z = gv.z; + *vel = g_focusobj->GVel(); } DLLEXPORT void oapiGetRelativePos (OBJHANDLE hObj, OBJHANDLE hRef, VECTOR3 *pos) { if (((Body*)hObj)->s0 && ((Body*)hRef)->s0) { - Vector dp(((Body*)hObj)->GPos()-((Body*)hRef)->GPos()); - pos->x = dp.x, pos->y = dp.y, pos->z = dp.z; + *pos = ((Body*)hObj)->GPos() - ((Body*)hRef)->GPos(); } } DLLEXPORT void oapiGetRelativeVel (OBJHANDLE hObj, OBJHANDLE hRef, VECTOR3 *vel) { - if (((Body*)hObj)->s0 && ((Body*)hRef)->s0) { - Vector dv(((Body*)hObj)->GVel() - ((Body*)hRef)->GVel()); - vel->x = dv.x, vel->y = dv.y, vel->z = dv.z; - } + if (((Body*)hObj)->s0 && ((Body*)hRef)->s0) *vel = ((Body*)hObj)->GVel() - ((Body*)hRef)->GVel(); } DLLEXPORT void oapiGetFocusRelativePos (OBJHANDLE hRef, VECTOR3 *pos) { - if (((Body*)hRef)->s0) { - Vector dp(g_focusobj->GPos() - ((Body*)hRef)->GPos()); - pos->x = dp.x, pos->y = dp.y, pos->z = dp.z; - } + if (((Body*)hRef)->s0) *pos = g_focusobj->GPos() - ((Body*)hRef)->GPos(); } DLLEXPORT void oapiGetFocusRelativeVel (OBJHANDLE hRef, VECTOR3 *vel) { - if (((Body*)hRef)->s0) { - Vector dv(g_focusobj->GVel() - ((Body*)hRef)->GVel()); - vel->x = dv.x, vel->y = dv.y, vel->z = dv.z; - } + if (((Body*)hRef)->s0) *vel = g_focusobj->GVel() - ((Body*)hRef)->GVel(); } DLLEXPORT void oapiGetBarycentre (OBJHANDLE hObj, VECTOR3 *bary) { - if (((Body*)hObj)->s0) { - Vector b(((CelestialBody*)hObj)->Barycentre()); - bary->x = b.x, bary->y = b.y, bary->z = b.z; - } + if (((Body*)hObj)->s0) *bary = ((CelestialBody*)hObj)->Barycentre(); } DLLEXPORT void oapiGetRotationMatrix (OBJHANDLE hObj, MATRIX3 *mat) @@ -458,54 +437,32 @@ DLLEXPORT void oapiGetRotationMatrix (OBJHANDLE hObj, MATRIX3 *mat) DLLEXPORT void oapiGlobalToLocal (OBJHANDLE hObj, const VECTOR3 *glob, VECTOR3 *loc) { - if (((Body*)hObj)->s0) { - Vector vloc; - ((Body*)hObj)->GlobalToLocal(Vector(glob->x, glob->y, glob->z), vloc); - loc->x = vloc.x, loc->y = vloc.y, loc->z = vloc.z; - } + if (((Body*)hObj)->s0) ((Body*)hObj)->GlobalToLocal(*glob, *loc); } DLLEXPORT void oapiLocalToGlobal (OBJHANDLE hObj, const VECTOR3 *loc, VECTOR3 *glob) { - if (((Body*)hObj)->s0) { - Vector vglob; - ((Body*)hObj)->LocalToGlobal(Vector(loc->x, loc->y, loc->z), vglob); - glob->x = vglob.x, glob->y = vglob.y, glob->z = vglob.z; - } + if (((Body*)hObj)->s0) ((Body*)hObj)->LocalToGlobal(*loc, *glob); } DLLEXPORT void oapiEquToLocal (OBJHANDLE hObj, double lng, double lat, double rad, VECTOR3 *loc) { - if (((Body*)hObj)->s0) { - Vector vloc; - ((Body*)hObj)->EquatorialToLocal(lng, lat, rad, vloc); - loc->x = vloc.x, loc->y = vloc.y, loc->z = vloc.z; - } + if (((Body*)hObj)->s0) ((Body*)hObj)->EquatorialToLocal(lng, lat, rad, *loc); } DLLEXPORT void oapiLocalToEqu (OBJHANDLE hObj, const VECTOR3 &loc, double *lng, double *lat, double *rad) { - if (((Body*)hObj)->s0) { - Vector vloc(loc.x, loc.y, loc.z); - ((Body*)hObj)->LocalToEquatorial(vloc, *lng, *lat, *rad); - } + if (((Body*)hObj)->s0) ((Body*)hObj)->LocalToEquatorial(loc, *lng, *lat, *rad); } DLLEXPORT void oapiEquToGlobal (OBJHANDLE hObj, double lng, double lat, double rad, VECTOR3 *glob) { - if (((Body*)hObj)->s0) { - Vector vglob; - ((Body*)hObj)->EquatorialToGlobal(lng, lat, rad, vglob); - glob->x = vglob.x, glob->y = vglob.y, glob->z = vglob.z; - } + if (((Body*)hObj)->s0) ((Body*)hObj)->EquatorialToGlobal(lng, lat, rad, *glob); } DLLEXPORT void oapiGlobalToEqu (OBJHANDLE hObj, const VECTOR3 &glob, double *lng, double *lat, double *rad) { - if (((Body*)hObj)->s0) { - Vector vglob(glob.x, glob.y, glob.z); - ((Body*)hObj)->GlobalToEquatorial(vglob, *lng, *lat, *rad); - } + if (((Body*)hObj)->s0) ((Body*)hObj)->GlobalToEquatorial(glob, *lng, *lat, *rad); } DLLEXPORT double oapiOrthodome (double lng1, double lat1, double lng2, double lat2) @@ -684,28 +641,22 @@ DLLEXPORT bool oapiGetGroundspeedVector (OBJHANDLE hVessel, REFFRAME frame, VECT if (sp) { switch (frame) { case FRAME_GLOBAL: - vel->x = sp->groundvel_glob.x, vel->y = sp->groundvel_glob.y, vel->z = sp->groundvel_glob.z; + *vel = sp->groundvel_glob; return true; case FRAME_LOCAL: - vel->x = sp->groundvel_ship.x, vel->y = sp->groundvel_ship.y, vel->z = sp->groundvel_ship.z; + *vel = sp->groundvel_ship; + return true; + case FRAME_REFLOCAL: + *vel = tmul(sp->ref->GRot(), sp->groundvel_glob); + return true; + case FRAME_HORIZON: + *vel = mul(sp->L2H, tmul(sp->ref->GRot(), sp->groundvel_glob)); return true; - case FRAME_REFLOCAL: { - Vector hvel (tmul (sp->ref->GRot(), sp->groundvel_glob)); - vel->x = hvel.x, vel->y = hvel.y, vel->z = hvel.z; - } return true; - case FRAME_HORIZON: { - Vector hvel (tmul (sp->ref->GRot(), sp->groundvel_glob)); - hvel.Set (mul (sp->L2H, hvel)); - vel->x = hvel.x, vel->y = hvel.y, vel->z = hvel.z; - } return true; - default: - vel->x = vel->y = vel->z = 0.0; - return false; } - } else { - vel->x = vel->y = vel->z = 0.0; - return false; } + + *vel = {0, 0, 0}; + return false; } DLLEXPORT BOOL oapiGetAirspeed (OBJHANDLE hVessel, double *airspeed) @@ -727,28 +678,22 @@ DLLEXPORT bool oapiGetAirspeedVector (OBJHANDLE hVessel, REFFRAME frame, VECTOR3 if (sp) { switch (frame) { case FRAME_GLOBAL: - vel->x = sp->airvel_glob.x, vel->y = sp->airvel_glob.y, vel->z = sp->airvel_glob.z; + *vel = sp->airvel_glob; return true; case FRAME_LOCAL: - vel->x = sp->airvel_ship.x, vel->y = sp->airvel_ship.y, vel->z = sp->airvel_ship.z; + *vel = sp->airvel_ship; + return true; + case FRAME_REFLOCAL: + *vel = tmul(sp->ref->GRot(), sp->airvel_glob); + return true; + case FRAME_HORIZON: + *vel = mul(sp->L2H, tmul(sp->ref->GRot(), sp->airvel_glob)); return true; - case FRAME_REFLOCAL: { - Vector hvel (tmul (sp->ref->GRot(), sp->airvel_glob)); - vel->x = hvel.x, vel->y = hvel.y, vel->z = hvel.z; - } return true; - case FRAME_HORIZON: { - Vector hvel (tmul (sp->ref->GRot(), sp->airvel_glob)); - hvel.Set (mul (sp->L2H, hvel)); - vel->x = hvel.x, vel->y = hvel.y, vel->z = hvel.z; - } return true; - default: - vel->x = vel->y = vel->z = 0.0; - return false; } - } else { - vel->x = vel->y = vel->z = 0.0; - return false; - } + } + + *vel = {0, 0, 0}; + return false; } DLLEXPORT BOOL oapiGetAirspeedVector (OBJHANDLE hVessel, VECTOR3 *speedvec) @@ -756,9 +701,7 @@ DLLEXPORT BOOL oapiGetAirspeedVector (OBJHANDLE hVessel, VECTOR3 *speedvec) LOGOUT_OBSOLETE; const SurfParam *sp = ((Vessel*)hVessel)->GetSurfParam(); if (sp) { - Vector hvel (tmul (sp->ref->GRot(), sp->airvel_glob)); - hvel.Set (mul (sp->L2H, hvel)); - speedvec->x = hvel.x, speedvec->y = hvel.y, speedvec->z = hvel.z; + *speedvec = mul(sp->L2H, tmul(sp->ref->GRot(), sp->airvel_glob)); return TRUE; } else { return FALSE; @@ -794,9 +737,7 @@ DLLEXPORT BOOL oapiGetFocusAirspeedVector (VECTOR3 *speedvec) LOGOUT_OBSOLETE; const SurfParam *sp = g_focusobj->GetSurfParam(); if (sp) { - Vector hvel (tmul (sp->ref->GRot(), sp->airvel_glob)); - hvel.Set (mul (sp->L2H, hvel)); - speedvec->x = hvel.x, speedvec->y = hvel.y, speedvec->z = hvel.z; + *speedvec = mul(sp->L2H, tmul(sp->ref->GRot(), sp->airvel_glob)); return TRUE; } else { return FALSE; @@ -853,12 +794,12 @@ DLLEXPORT void oapiGetFocusAtmPressureDensity (double *pressure, double *density DLLEXPORT VECTOR3 oapiGetGroundVector (OBJHANDLE hPlanet, double lng, double lat, int frame) { - return MakeVECTOR3 (((Planet*)hPlanet)->GroundVelocity (lng, lat, 0, frame)); + return ((Planet*)hPlanet)->GroundVelocity(lng, lat, 0, frame); } DLLEXPORT VECTOR3 oapiGetWindVector (OBJHANDLE hPlanet, double lng, double lat, double alt, int frame, double *windspeed) { - return MakeVECTOR3 (((Planet*)hPlanet)->WindVelocity (lng, lat, alt, frame, 0, windspeed)); + return ((Planet*)hPlanet)->WindVelocity (lng, lat, alt, frame, 0, windspeed); } // =========================================================================== @@ -1049,18 +990,12 @@ DLLEXPORT OBJHANDLE oapiCameraProxyGbody () DLLEXPORT void oapiCameraGlobalPos (VECTOR3 *gpos) { - const Vector *gp = g_camera->GPosPtr(); - gpos->x = gp->x; - gpos->y = gp->y; - gpos->z = gp->z; + *gpos = g_camera->GPos(); } DLLEXPORT void oapiCameraGlobalDir (VECTOR3 *gdir) { - const Vector gd = g_camera->Direction(); - gdir->x = gd.x; - gdir->y = gd.y; - gdir->z = gd.z; + *gdir = g_camera->Direction(); } DLLEXPORT void oapiCameraRotationMatrix (MATRIX3 *rmat) @@ -1230,13 +1165,7 @@ DLLEXPORT double oapiSurfaceElevationEx(OBJHANDLE hPlanet, double lng, double la if (body->Type() != OBJTP_PLANET) return 0.0; Planet *planet = (Planet*)body; ElevationManager *emgr = planet->ElevMgr(); - Vector normal; - if (nml) - normal = MakeVector(*nml); - double elev = (emgr ? emgr->Elevation(lat, lng, tgtlvl, tilecache, nml ? &normal : 0, lvl) : 0.0); - if (nml) - *nml = MakeVECTOR3(normal); - return elev; + return emgr ? emgr->Elevation(lat, lng, tgtlvl, tilecache, nml, lvl) : 0; } DLLEXPORT std::vector *InitTileCache(int size) @@ -1291,11 +1220,7 @@ DLLEXPORT NAVHANDLE oapiGetBasePadNav (OBJHANDLE hBase, DWORD pad) DLLEXPORT void oapiGetNavPos (NAVHANDLE hNav, VECTOR3 *gpos) { - Vector p; - ((Nav*)hNav)->GPos (p); - gpos->x = p.x; - gpos->y = p.y; - gpos->z = p.z; + ((Nav*)hNav)->GPos(*gpos); } DLLEXPORT DWORD oapiGetNavChannel (NAVHANDLE hNav) @@ -1310,7 +1235,7 @@ DLLEXPORT float oapiGetNavFreq (NAVHANDLE hNav) DLLEXPORT double oapiGetNavSignal (NAVHANDLE hNav, const VECTOR3 &gpos) { - return ((Nav*)hNav)->FieldStrength (MakeVector(gpos)); + return ((Nav*)hNav)->FieldStrength(gpos); } DLLEXPORT float oapiGetNavRange (NAVHANDLE hNav) @@ -1337,8 +1262,7 @@ DLLEXPORT int oapiGetNavDescr (NAVHANDLE hNav, char *descr, int maxlen) DLLEXPORT bool oapiNavInRange (NAVHANDLE hNav, const VECTOR3 &gpos) { - Vector p(gpos.x, gpos.y, gpos.z); - return ((Nav*)hNav)->InRange (p); + return ((Nav*)hNav)->InRange(gpos); } DLLEXPORT INTERPRETERHANDLE oapiCreateInterpreter () @@ -1855,12 +1779,12 @@ DLLEXPORT void oapiVCRegisterArea (int id, int draw_event, int mouse_event) DLLEXPORT void oapiVCSetAreaClickmode_Spherical (int id, const VECTOR3 &cnt, double rad) { - g_pane->SetVCAreaClickmode_Spherical (id, Vector(cnt.x, cnt.y, cnt.z), rad); + g_pane->SetVCAreaClickmode_Spherical(id, cnt, rad); } DLLEXPORT void oapiVCSetAreaClickmode_Quadrilateral (int id, const VECTOR3 &p1, const VECTOR3 &p2, const VECTOR3 &p3, const VECTOR3 &p4) { - g_pane->SetVCAreaClickmode_Quadrilateral (id, Vector(p1.x, p1.y, p1.z), Vector(p2.x,p2.y,p2.z), Vector(p3.x,p3.y,p3.z), Vector(p4.x,p4.y,p4.z)); + g_pane->SetVCAreaClickmode_Quadrilateral(id, p1, p2, p3, p4); } DLLEXPORT oapi::Sketchpad *oapiGetSketchpad (SURFHANDLE surf) @@ -2419,12 +2343,7 @@ DLLEXPORT bool oapiReadItem_bool (FILEHANDLE f, char *item, bool &val) DLLEXPORT bool oapiReadItem_vec (FILEHANDLE f, char *item, VECTOR3 &val) { - Vector vec; - bool res = GetItemVector (*(ifstream*)f, item, vec); - val.x = vec.x; - val.y = vec.y; - val.z = vec.z; - return res; + return GetItemVector(*(ifstream*)f, item, val); } DLLEXPORT void oapiOpenInputBox (char *title, bool (*Clbk)(void*,char*,void*), char *buf, int vislen, void *usrdata) diff --git a/Src/Orbiter/Pane.cpp b/Src/Orbiter/Pane.cpp index af3ee19e1..c4b1fde5a 100644 --- a/Src/Orbiter/Pane.cpp +++ b/Src/Orbiter/Pane.cpp @@ -584,7 +584,7 @@ void Pane::Update (double simt, double syst) panel->RedrawAllAreas (PANEL_REDRAW_ALWAYS); } else if (vcockpit) { int idx, aid, mstate; - Vector vx; + VECTOR3 vx; vcockpit->GetMouseState (idx, mstate, vx); if (mstate) { aid = vcockpit->area[idx]->id; @@ -817,7 +817,7 @@ void Pane::SetSketchpadDefault (oapi::Sketchpad *skp) skp->SetFont (hudfont[0]); } -bool Pane::GlobalToScreen (const Vector &glob, int &x, int &y) const +bool Pane::GlobalToScreen (const VECTOR3 &glob, int &x, int &y) const { D3DVECTOR homog; bool vis = GlobalToHomog (glob, homog); @@ -828,7 +828,7 @@ bool Pane::GlobalToScreen (const Vector &glob, int &x, int &y) const return vis; } -bool Pane::GlobalToScreen (const Vector &glob, double &x, double &y) const +bool Pane::GlobalToScreen (const VECTOR3 &glob, double &x, double &y) const { D3DVECTOR homog; bool vis = GlobalToHomog (glob, homog); @@ -839,7 +839,7 @@ bool Pane::GlobalToScreen (const Vector &glob, double &x, double &y) const return vis; } -bool Pane::GlobalToHomog (const Vector &glob, D3DVECTOR &homog) const +bool Pane::GlobalToHomog (const VECTOR3 &glob, D3DVECTOR &homog) const { //D3DVECTOR gpos = {-(D3DVALUE)glob.x, -(D3DVALUE)glob.y, -(D3DVALUE)glob.z}; D3DVECTOR gpos = {(D3DVALUE)glob.x, (D3DVALUE)glob.y, (D3DVALUE)glob.z}; @@ -849,7 +849,7 @@ bool Pane::GlobalToHomog (const Vector &glob, D3DVECTOR &homog) const /* homog.z >= 0.0 && */ homog.z <= g_camera->HomogZlimit()); } -void Pane::ScreenToGlobal (int x, int y, Vector &glob) const +void Pane::ScreenToGlobal (int x, int y, VECTOR3 &glob) const { D3DVECTOR homog, gpos; homog.x = (float)(x*2.0/W-1.0); @@ -859,8 +859,7 @@ void Pane::ScreenToGlobal (int x, int y, Vector &glob) const D3DMath_MatrixInvert (IP, *g_camera->D3D_ProjViewMatrix()); D3DMath_VectorMatrixMultiply (gpos, homog, IP); //D3DMath_VectorTMatrixMultiply (gpos, homog, *g_camera->D3D_ProjViewMatrix()); - glob.Set (-gpos.x, -gpos.y, -gpos.z); - glob.unify(); + glob = unit(VECTOR3{-gpos.x, -gpos.y, -gpos.z}); } bool Pane::OpenMFD (INT_PTR id, int type, ifstream *ifs) @@ -1135,7 +1134,7 @@ void Pane::RegisterVCHUD (const VCHUDSPEC *spec) } } -void Pane::ShiftVC (const Vector &shift) +void Pane::ShiftVC (const VECTOR3 &shift) { if (vcockpit) { vcockpit->Shift (shift); @@ -1159,7 +1158,7 @@ void Pane::RegisterVCArea (int id, const RECT &tgtrect, int draw_mode, int mouse if (vcockpit) vcockpit->DefineArea (id, tgtrect, draw_mode, mouse_mode, bkmode, tgt); } -void Pane::SetVCAreaClickmode_Spherical (int aid, const Vector &cnt, double rad) +void Pane::SetVCAreaClickmode_Spherical (int aid, const VECTOR3 &cnt, double rad) { if (vcockpit) { int id = vcockpit->AreaIndex (aid); @@ -1167,7 +1166,7 @@ void Pane::SetVCAreaClickmode_Spherical (int aid, const Vector &cnt, double rad) } } -void Pane::SetVCAreaClickmode_Quadrilateral (int aid, const Vector &p1, const Vector &p2, const Vector &p3, const Vector &p4) +void Pane::SetVCAreaClickmode_Quadrilateral (int aid, const VECTOR3 &p1, const VECTOR3 &p2, const VECTOR3 &p3, const VECTOR3 &p4) { if (vcockpit) { int id = vcockpit->AreaIndex (aid); diff --git a/Src/Orbiter/Pane.h b/Src/Orbiter/Pane.h index 6bc1ded42..c3df591fb 100644 --- a/Src/Orbiter/Pane.h +++ b/Src/Orbiter/Pane.h @@ -228,28 +228,28 @@ class Pane { void RegisterVCMFD (int id, const VCMFDSPEC *spec); void RegisterVCHUD (const VCHUDSPEC *spec); - void ShiftVC (const Vector &shift); + void ShiftVC (const VECTOR3 &shift); void RegisterVCArea (int id, const RECT &tgtrect, int draw_mode, int mouse_mode, int bkmode, SURFHANDLE tgt); - void SetVCAreaClickmode_Spherical (int id, const Vector &cnt, double rad); - void SetVCAreaClickmode_Quadrilateral (int id, const Vector &p1, const Vector &p2, const Vector &p3, const Vector &p4); + void SetVCAreaClickmode_Spherical (int id, const VECTOR3 &cnt, double rad); + void SetVCAreaClickmode_Quadrilateral (int id, const VECTOR3 &p1, const VECTOR3 &p2, const VECTOR3 &p3, const VECTOR3 &p4); void TriggerVCRedrawArea (int vcid, int area_id); void TriggerRedrawArea (int pid, int vcid, int area_id); void SetPanel2DBlink (VECTOR3 v[4]); - bool GlobalToHomog (const Vector &glob, D3DVECTOR &homog) const; + bool GlobalToHomog (const VECTOR3 &glob, D3DVECTOR &homog) const; // transform global position glob into homogeneous viewport // coordinates (x=-1: left edge of viewing fustrum etc.) // return value indicates point within fustrum (does not check // front and back planes) - bool GlobalToScreen (const Vector &glob, int &x, int &y) const; - bool GlobalToScreen (const Vector &glob, double &x, double &y) const; + bool GlobalToScreen (const VECTOR3 &glob, int &x, int &y) const; + bool GlobalToScreen (const VECTOR3 &glob, double &x, double &y) const; // return screen coordinates for global position glob // return value indicates point visible on screen // x and y are undefined if not visible - void ScreenToGlobal (int x, int y, Vector &glob) const; + void ScreenToGlobal (int x, int y, VECTOR3 &glob) const; // return global direction corresponding to screen coordinate x,y void InitState (const char *scn); diff --git a/Src/Orbiter/Particle.cpp b/Src/Orbiter/Particle.cpp index a79aa34c8..65e04a0ca 100644 --- a/Src/Orbiter/Particle.cpp +++ b/Src/Orbiter/Particle.cpp @@ -53,9 +53,9 @@ static PARTICLESTREAMSPEC DefaultParticleStreamSpec = { D3D7ParticleStream::D3D7ParticleStream (oapi::GraphicsClient *_gc, PARTICLESTREAMSPEC *pss): ParticleStream (_gc, pss) { - cam_ref = g_camera->GPOSPtr(); + cam_ref = g_camera->GPosPtr(); src_ref = 0; - src_ofs = _V(0,0,0); + src_ofs = {0,0,0}; interval = 0.1; SetSpecs (pss ? pss : &DefaultParticleStreamSpec); t0 = td.SimT0; @@ -232,7 +232,7 @@ double D3D7ParticleStream::MinCameraDist() const int i; for (p = pfirst, i = 0; p; p = p->next, i++) { if (!(i % 5)) { // only check every 5th particle for performance - double cdist = length2(*cam_ref - p->pos); + double cdist = len(*cam_ref - p->pos); if (cdist < min_cam_dist) { min_cam_dist = cdist; size = p->size; @@ -557,7 +557,7 @@ void ExhaustStream::Update () rad = oapiGetSize (hPlanet); if (vessel) rad += vessel->GetSurfaceElevation(); VECTOR3 dv = pp-plast->pos; // gravitational dv - double d = length (dv); + double d = len(dv); dv *= Ggrav * oapiGetMass(hPlanet)/(d*d*d) * td.SimDT; ATMPARAM prm; @@ -585,19 +585,19 @@ void ExhaustStream::Update () p->size += (alpha+alpha1) * td.SimDT; VECTOR3 s (p->pos - pp); - if (length(s) < rad) { - VECTOR3 dp = s * (rad/length(s)-1.0); + if (len(s) < rad) { + VECTOR3 dp = s * (rad / len(s) - 1.0); p->pos += dp; - static double dv_scale = length(vv)*0.2; + static double dv_scale = len(vv) * 0.2; VECTOR3 dv = {((double)rand()/(double)RAND_MAX-0.5)*dv_scale, ((double)rand()/(double)RAND_MAX-0.5)*dv_scale, ((double)rand()/(double)RAND_MAX-0.5)*dv_scale}; dv += vv; - normalise(s); - VECTOR3 vv2 = dv - s*dotp(s,dv); - if (length(vv2)) vv2 *= 0.5*length(vv)/length(vv2); + s = unit(s); + VECTOR3 vv2 = dv - s * dot(s, dv); + if (len(vv2)) vv2 *= 0.5 * len(vv) / len(vv2); vv2 += s*(((double)rand()/(double)RAND_MAX)*dv_scale); p->vel = vv2*1.0/*2.0*/+av; double r = (double)rand()/(double)RAND_MAX; @@ -686,9 +686,9 @@ void ExhaustStream::RenderGroundShadow (LPDIRECT3DDEVICE7 dev, LPDIRECTDRAWSURFA } // calculate the intersection of the vessel's shadow with the planet surface - double fac1 = dotp (sd, pv0); + double fac1 = dot(sd, pv0); if (fac1 > 0.0) return; // shadow doesn't intersect planet surface - double arg = fac1*fac1 - (dotp (pv0, pv0) - rad*rad); + double arg = fac1 * fac1 - (dot(pv0, pv0) - rad * rad); if (arg <= 0.0) return; // shadow doesn't intersect with planet surface double a = -fac1 - sqrt(arg); VECTOR3 shp = sd*a; // projection point in global frame @@ -707,9 +707,9 @@ void ExhaustStream::RenderGroundShadow (LPDIRECT3DDEVICE7 dev, LPDIRECTDRAWSURFA VECTOR3 pvr = p->pos - pp; // rel. particle position // calculate the intersection of the vessel's shadow with the planet surface - double fac1 = dotp (sd, pvr); + double fac1 = dot(sd, pvr); if (fac1 > 0.0) break; // shadow doesn't intersect planet surface - double arg = fac1*fac1 - (dotp (pvr, pvr) - rad*rad); + double arg = fac1 * fac1 - (dot(pvr, pvr) - rad * rad); if (arg <= 0.0) break; // shadow doesn't intersect with planet surface double a = -fac1 - sqrt(arg); @@ -746,7 +746,7 @@ ReentryStream::ReentryStream (oapi::GraphicsClient *_gc, OBJHANDLE hV, PARTICLES : D3D7ParticleStream (_gc, pss) { llevel = 1.0; - Attach (hV, _V(0,0,0), _V(0,0,0), &llevel); + Attach (hV, {0,0,0}, {0,0,0}, &llevel); hPlanet = 0; } diff --git a/Src/Orbiter/PinesGrav.cpp b/Src/Orbiter/PinesGrav.cpp index 73519cd2e..2c98dc581 100644 --- a/Src/Orbiter/PinesGrav.cpp +++ b/Src/Orbiter/PinesGrav.cpp @@ -182,9 +182,9 @@ int PinesGravProp::readGravModel(char* filename, int cutoff, int &actualLoadedTe } } -Vector PinesGravProp::GetPinesGrav(const Vector rpos, const int maxDegree, const int maxOrder) +VECTOR3 PinesGravProp::GetPinesGrav(const VECTOR3 rpos, const int maxDegree, const int maxOrder) { - r = rpos.length(); + r = len(rpos); s = rpos.x / r; t = rpos.y / r; u = rpos.z / r; @@ -254,11 +254,5 @@ Vector PinesGravProp::GetPinesGrav(const Vector rpos, const int maxDegree, const } - Vector gperturbed; - - gperturbed.x = (g1 - g4 * s); - gperturbed.y = (g2 - g4 * t); - gperturbed.z = (g3 - g4 * u); - - return gperturbed; + return VECTOR3{g1 - g4 * s, g2 - g4 * t, g3 - g4 * u}; } \ No newline at end of file diff --git a/Src/Orbiter/PinesGrav.h b/Src/Orbiter/PinesGrav.h index fb286e849..bb32d8ef2 100644 --- a/Src/Orbiter/PinesGrav.h +++ b/Src/Orbiter/PinesGrav.h @@ -29,7 +29,7 @@ class PinesGravProp PinesGravProp(CelestialBody* celestialbody); ~PinesGravProp(); int readGravModel(char* filename, int cutoff, int& actualLoadedTerms, int& maxModelTerms); - Vector GetPinesGrav(const Vector rposmax, const int maxDegree, const int maxOrder); + VECTOR3 GetPinesGrav(const VECTOR3 rposmax, const int maxDegree, const int maxOrder); inline unsigned int GetCoeffCutoff() const { return CoeffCutoff; } private: CelestialBody* parentBody; diff --git a/Src/Orbiter/Planet.cpp b/Src/Orbiter/Planet.cpp index 335b787de..6c8897a18 100644 --- a/Src/Orbiter/Planet.cpp +++ b/Src/Orbiter/Planet.cpp @@ -45,7 +45,7 @@ extern char DBG_MSG[256]; int patchidx[9] = {0, 1, 2, 3, 5, 13, 37, 137, 501}; // index to the first texture of a given surface patch level -void InterpretEphemeris (double *data, int format, Vector *pos, Vector *vel); +void InterpretEphemeris (double *data, int format, VECTOR3 *pos, VECTOR3 *vel); const double OAPI_RAND_MAX = 65536.0; @@ -274,20 +274,14 @@ Planet::Planet (char *fname) hazerange = max (0.0, min (0.9, hazerange)); if (!GetItemReal (ifs, "AtmHazeShift", hazeshift)) hazeshift = 0.0; if (!GetItemReal (ifs, "AtmHazeDensity", hazedens)) hazedens = 1.0; - Vector col0; - if (GetItemVector (ifs, "AtmColor0", col0)) { - atm.color0.x = col0.x; atm.color0.y = col0.y; atm.color0.z = col0.z; - } - if (!GetItemVector (ifs, "AtmHazeColor", hazecol)) - hazecol.Set (atm.color0.x, atm.color0.y, atm.color0.z); + GetItemVector(ifs, "AtmColor0", atm.color0); + if (!GetItemVector(ifs, "AtmHazeColor", hazecol)) hazecol = atm.color0; if (GetItemString (ifs, "AtmFogParam", cbuf)) { i = sscanf (cbuf, "%lf%lf%lf", &fog.dens_0, &fog.dens_ref, &fog.alt_ref); - if (GetItemVector (ifs, "AtmFogColor", col0)) fog.col = MakeVECTOR3 (col0); - else fog.col = atm.color0; + if (!GetItemVector(ifs, "AtmFogColor", fog.col)) fog.col = atm.color0; } - if (!GetItemVector (ifs, "AtmTintColor", tintcol)) - tintcol.Set (fog.col.x*0.2, fog.col.y*0.2, fog.col.z*0.2); + if (!GetItemVector(ifs, "AtmTintColor", tintcol)) tintcol = fog.col * 0.2; } GetItemReal (ifs, "HorizonExcess", horizon_excess); @@ -638,7 +632,7 @@ void Planet::ScanLabelLists (ifstream &cfg) double lng, lat; int nl; char *pc; - Vector pos; + VECTOR3 pos; FindLine (ulf, "BEGIN_DATA"); for (nl = 0;; nl++) { if (!ulf.getline (cbuf, 256)) break; @@ -646,7 +640,7 @@ void Planet::ScanLabelLists (ifstream &cfg) if (!pc || sscanf (pc, "%lf%lf", &lng, &lat) != 2) continue; EquatorialToLocal (RAD*lng, RAD*lat, size, pos); oapi::GraphicsClient::LABELSPEC ls; - ls.pos = _V(pos.x, pos.y, pos.z); + ls.pos = {pos.x, pos.y, pos.z}; for (i = 0; i < 2; i++) { if (pc = strtok (NULL, ":")) ls.label[i] = trim_string(pc); @@ -883,7 +877,7 @@ void Planet::ElToEcliptic (const Elements *el_equ, Elements *el_ecl) const // this should be done by direct transform rather // than going via pos/vel - Vector pos, vel; + VECTOR3 pos, vel; el_equ->PosVel (pos, vel, 0.0); el_ecl->Calculate (mul (GRot(), pos), mul (GRot(), vel), 0.0); } @@ -1018,25 +1012,25 @@ double Planet::Elevation (double lng, double lat) const return (emgr ? emgr->Elevation(lat,lng) : 0.0); } -Vector Planet::GroundVelocity (double lng, double lat, double alt, int frame) +VECTOR3 Planet::GroundVelocity (double lng, double lat, double alt, int frame) { - if (frame < 2 || frame > 3) return Vector(0,0,0); // sanity check + if (frame < 2 || frame > 3) return VECTOR3{0, 0, 0}; // sanity check double vground = Pi2 * (size+alt) * cos(lat) / RotT(); - Vector v(-vground*sin(lng), 0.0, vground*cos(lng)); + VECTOR3 v{-vground * std::sin(lng), 0.0, vground * std::cos(lng)}; if (frame == 2) return v; else return mul (s0->R, v) + s0->vel; } -Vector Planet::WindVelocity (double lng, double lat, double alt, int frame, WindPrm *prm, double *windspeed) +VECTOR3 Planet::WindVelocity (double lng, double lat, double alt, int frame, WindPrm *prm, double *windspeed) { - Vector wv(0,0,0); + VECTOR3 wv{0, 0, 0}; if (bEnableWind && HasAtmosphere()) { int k, dim; DWORD r, rnd; - Vector wv0[4]; + VECTOR3 wv0[4]; // cubic interpolation double alt_km = alt*1e-3; @@ -1102,11 +1096,11 @@ Vector Planet::WindVelocity (double lng, double lat, double alt, int frame, Wind } - if (windspeed) *windspeed = wv.length(); + if (windspeed) *windspeed = len(wv); if (frame == 0) return wv; // surface-local frame double slng = sin(lng), clng = cos(lng), slat = sin(lat), clat = cos(lat); - Vector wv_loc (tmul (Matrix (-slng,0,clng, clat*clng,slat,clat*slng, -slat*clng,clat,-slat*slng), wv)); + VECTOR3 wv_loc = tmul(Matrix(-slng, 0, clng, clat * clng, slat, clat * slng, -slat * clng, clat, -slat * slng), wv); switch (frame) { case 1: // planet-local diff --git a/Src/Orbiter/Planet.h b/Src/Orbiter/Planet.h index 7172f0f75..60cd62bc7 100644 --- a/Src/Orbiter/Planet.h +++ b/Src/Orbiter/Planet.h @@ -143,7 +143,7 @@ class Planet: public CelestialBody { inline double AtmHazeRange () const { return hazerange; } inline double AtmHazeShift () const { return hazeshift; } inline double AtmHazeDensity () const { return hazedens; } - inline const Vector &AtmHazeColor () const { return hazecol; } + inline const VECTOR3 &AtmHazeColor () const { return hazecol; } inline double ShadowDepth () const { return shadowalpha; } inline double CloudRotationAngle () const { return cloudrot; } inline float CloudShadowDepth () const { return cloudshadowcol; } @@ -157,8 +157,8 @@ class Planet: public CelestialBody { void SetLabelActive(int i, bool active) { if (i >= 0 && i < nLabelLegend) labelLegend[i].active = active; } - Vector GroundVelocity (double lng, double lat, double alt=0.0, int frame=2); - Vector WindVelocity (double lng, double lat, double alt, int frame=0, WindPrm *prm=NULL, double *windspeed=NULL); + VECTOR3 GroundVelocity (double lng, double lat, double alt=0.0, int frame=2); + VECTOR3 WindVelocity (double lng, double lat, double alt, int frame=0, WindPrm *prm=NULL, double *windspeed=NULL); // returns a velocity vector in local planet coordinates for ground/air at a point given // in equatorial coordinates @@ -224,8 +224,8 @@ class Planet: public CelestialBody { double hazerange; // bleed-in factor of horizon haze into planet disc (0-0.9, 0=none) double hazeshift; // shift of horizon haze reference radius (units of planet radius, default=0) double hazedens; // horizon haze density factor - Vector hazecol; // horizon haze colour - Vector tintcol; // atmospheric tint colour + VECTOR3 hazecol; // horizon haze colour + VECTOR3 tintcol; // atmospheric tint colour double minelev; // minimum elevation as read from config file double maxelev; // maximum elevation as read from config file double crot_t, crot_offset; // cloud layer rotation time and offset diff --git a/Src/Orbiter/Psys.cpp b/Src/Orbiter/Psys.cpp index 78ac22e57..14fa6f502 100644 --- a/Src/Orbiter/Psys.cpp +++ b/Src/Orbiter/Psys.cpp @@ -496,7 +496,7 @@ void PlanetarySystem::UndockVessel (SuperVessel *sv, Vessel *_vessel, int port, } } -void PlanetarySystem::ScanGFieldSources (const Vector *gpos, const Body *exclude, GFieldData *gfd) const +void PlanetarySystem::ScanGFieldSources (const VECTOR3 *gpos, const Body *exclude, GFieldData *gfd) const { const double min_contrib = 1e-6; // min. rel. g-field contribution threshold DWORD i, j, idx; @@ -504,10 +504,10 @@ void PlanetarySystem::ScanGFieldSources (const Vector *gpos, const Body *exclude gfd->ngrav = 0; // reset gravitation source list for (i = 0; i < celestials.size(); i++) if (celestials[i] != exclude) - atot += celestials[i]->Mass() / gpos->dist2 (celestials[i]->GPos()); + atot += celestials[i]->Mass() / dist_2(*gpos, celestials[i]->GPos()); for (i = 0; i < celestials.size(); i++) { if (celestials[i] != exclude) { - a = celestials[i]->Mass() / gpos->dist2 (celestials[i]->GPos()); + a = celestials[i]->Mass() / dist_2(*gpos, celestials[i]->GPos()); if (a > min_contrib*atot) { if (gfd->ngrav < MAXGFIELDLIST) gfd->gravidx[gfd->ngrav++] = i; @@ -518,7 +518,7 @@ void PlanetarySystem::ScanGFieldSources (const Vector *gpos, const Body *exclude // called very often for (j = 0; j < MAXGFIELDLIST; j++) { idx = gfd->gravidx[j]; - a2 = celestials[idx]->Mass() / gpos->dist2 (celestials[idx]->GPos()); + a2 = celestials[idx]->Mass() / dist_2(*gpos, celestials[idx]->GPos()); if (a2 < amin) amin = a2, jmin = j; } if (amin < a) gfd->gravidx[jmin] = i; // replace @@ -529,22 +529,22 @@ void PlanetarySystem::ScanGFieldSources (const Vector *gpos, const Body *exclude gfd->testidx = 0; } -void PlanetarySystem::UpdateGFieldSources (const Vector *gpos, const Body *exclude, GFieldData *gfd) const +void PlanetarySystem::UpdateGFieldSources (const VECTOR3 *gpos, const Body *exclude, GFieldData *gfd) const { extern const DWORD MAXGFIELDLIST; const double min_contrib = 1e-6; // min. g-field contribution threshold DWORD i, idx, imin; double a, atot = 0.0, amin = 1e100; - Vector acc; + VECTOR3 acc; bool testnext = true; // First, check we can drop the weakest member of the current list for (i = 0; i < gfd->ngrav; i++) { idx = gfd->gravidx[i]; if (celestials[idx] != exclude) { - Vector acci = SingleGacc (celestials[idx]->GPos() - *gpos, celestials[idx]); + VECTOR3 acci = SingleGacc(celestials[idx]->GPos() - *gpos, celestials[idx]); acc += acci; - a = acci.length(); + a = len(acci); atot += a; if (a < amin) amin = a, imin = i; } @@ -558,8 +558,8 @@ void PlanetarySystem::UpdateGFieldSources (const Vector *gpos, const Body *exclu // Test next candidate for inclusion in the list if (testnext && exclude != celestials[idx = gfd->testidx]) { - Vector acci = SingleGacc (celestials[idx]->GPos() - *gpos, celestials[idx]); - a = acci.length(); + VECTOR3 acci = SingleGacc(celestials[idx]->GPos() - *gpos, celestials[idx]); + a = len(acci); if (a > min_contrib*atot) { if (gfd->ngrav < MAXGFIELDLIST) gfd->gravidx[gfd->ngrav++] = idx; else if (a > amin) gfd->gravidx[imin] = idx; @@ -568,9 +568,9 @@ void PlanetarySystem::UpdateGFieldSources (const Vector *gpos, const Body *exclu if (++gfd->testidx == celestials.size()) gfd->testidx = 0; } -Vector PlanetarySystem::GaccAt (double t, const Vector &gpos, const Body *exclude) const +VECTOR3 PlanetarySystem::GaccAt (double t, const VECTOR3 &gpos, const Body *exclude) const { - Vector r, acc, pos, closepos; + VECTOR3 r, acc, pos, closepos; CelestialBody *closep = 0; const CelestialBody *sec; DWORD i; @@ -583,11 +583,11 @@ Vector PlanetarySystem::GaccAt (double t, const Vector &gpos, const Body *exclud celestials[i]->Primary()->Type() == OBJTP_PLANET) continue; if (celestials[i]->Type() == OBJTP_PLANET) { if (!celestials[i]->PositionAtTime (t, &pos)) continue; - } else pos.Set(0,0,0); // sun assumed in origin - r.Set(pos - gpos); - d = r.length(); + } else pos = {0, 0, 0}; // sun assumed in origin + r = pos - gpos; + d = len(r); acc += r * (Ggrav * celestials[i]->Mass() / (d*d*d)); - if (d < dmin) dmin = d, closep = celestials[i], closepos.Set(pos); + if (d < dmin) dmin = d, closep = celestials[i], closepos = pos; } // pass 2: moons of closest planet if (closep && closep->Type() == OBJTP_PLANET) { @@ -595,27 +595,27 @@ Vector PlanetarySystem::GaccAt (double t, const Vector &gpos, const Body *exclud sec = closep->Secondary(i); if (!sec->PositionAtTime (t, &pos)) continue; pos += closepos; - r.Set(pos - gpos); - d = r.length(); + r = pos - gpos; + d = len(r); acc += r * (Ggrav * sec->Mass() / (d*d*d)); } } return acc; } -Vector SingleGacc_perturbation (const Vector &rpos, const CelestialBody *body) +VECTOR3 SingleGacc_perturbation (const VECTOR3 &rpos, const CelestialBody *body) { // Calculate perturbation of gravitational acceleration due to nonspherical // shape of the body. // rpos: relative position of 'bodies' wrt. r (global frame) - Vector dg; + VECTOR3 dg; if (body->UseComplexGravity() && body->usePines()) { //Rotate position vector into the planet's local frame Matrix rot = body->GRot(); - Vector lpos = -tmul(rot,rpos)/1000.0; + VECTOR3 lpos = -tmul(rot, rpos) / 1000; //Convert to right-handed double temp_y; @@ -647,7 +647,7 @@ Vector SingleGacc_perturbation (const Vector &rpos, const CelestialBody *body) else if (body->UseComplexGravity() && body->nJcoeff() > 0) { const double eps = 1e-10; // perturbation limit - double d = rpos.length(); + double d = len(rpos); double Rr = body->Size() / d; double Rrn = Rr*Rr; double gacc_r = 0.0, gacc_p = 0.0; @@ -655,8 +655,8 @@ Vector SingleGacc_perturbation (const Vector &rpos, const CelestialBody *body) // J2 perturbation term double Jn_Rrn = body->Jcoeff(0) * Rrn; // relative influence of J2 term if (fabs (Jn_Rrn) > eps) { - Vector er (rpos.unit()); // radial unit vector - Vector loc (tmul (body->GRot(), er)); + VECTOR3 er = unit(rpos); // radial unit vector + VECTOR3 loc = tmul(body->GRot(), er); double lat = asin(-loc.y), slat = sin(lat), clat = cos(lat); // latitude gacc_r += 1.5 * Jn_Rrn * (1.0 - 3.0*slat*slat); gacc_p += 3.0 * Jn_Rrn * clat*slat; @@ -683,28 +683,28 @@ Vector SingleGacc_perturbation (const Vector &rpos, const CelestialBody *body) double GM = Ggrav * body->Mass(); double T0 = GM / (d*d); - Vector ep, ea (crossp (er, body->RotAxis())); // azimuth vector - double lea = ea.length(); - if (lea > eps) ep.Set (crossp (er, ea/lea)); // polar unit vector - else ep.Set (0,0,0); + VECTOR3 ep, ea = cross(er, body->RotAxis()); // azimuth vector + double lea = len(ea); + if (lea > eps) ep = cross(er, ea / lea); // polar unit vector + else ep = {0, 0, 0}; dg = er * (T0*gacc_r) + ep * (T0*gacc_p); } } return dg; } -Vector SingleGacc (const Vector &rpos, const CelestialBody *body) +VECTOR3 SingleGacc (const VECTOR3 &rpos, const CelestialBody *body) { // Calculate gravitational acceleration at a position r from a single source // rpos: relative position of 'body' wrt. r (global coords) - double d = rpos.length(); + double d = len(rpos); return rpos * (Ggrav * body->Mass() / (d*d*d)) + SingleGacc_perturbation (rpos, body); } -Vector PlanetarySystem::Gacc (const Vector &gpos, const Body *exclude, const GFieldData *gfd) const +VECTOR3 PlanetarySystem::Gacc (const VECTOR3 &gpos, const Body *exclude, const GFieldData *gfd) const { - Vector acc; + VECTOR3 acc; DWORD i, j; if (gfd) { @@ -722,9 +722,9 @@ Vector PlanetarySystem::Gacc (const Vector &gpos, const Body *exclude, const GFi return acc; } -Vector PlanetarySystem::Gacc_intermediate (const Vector &gpos, double n, const Body *exclude, GFieldData *gfd) const +VECTOR3 PlanetarySystem::Gacc_intermediate (const VECTOR3 &gpos, double n, const Body *exclude, GFieldData *gfd) const { - Vector acc; + VECTOR3 acc; DWORD i, j; if (gfd) { // use body's source list @@ -742,11 +742,11 @@ Vector PlanetarySystem::Gacc_intermediate (const Vector &gpos, double n, const B return acc; } -Vector PlanetarySystem::Gacc_intermediate_pert (const CelestialBody *cbody, const Vector &relpos, double n, const Body *exclude, GFieldData *gfd) const +VECTOR3 PlanetarySystem::Gacc_intermediate_pert (const CelestialBody *cbody, const VECTOR3 &relpos, double n, const Body *exclude, GFieldData *gfd) const { - Vector acc; + VECTOR3 acc; DWORD i, j; - Vector gpos = relpos + cbody->InterpolatePosition (n); + VECTOR3 gpos = relpos + cbody->InterpolatePosition(n); if (gfd) { // use body's source list for (j = 0; j < gfd->ngrav; j++) { @@ -769,12 +769,12 @@ Vector PlanetarySystem::Gacc_intermediate_pert (const CelestialBody *cbody, cons return acc; } -Vector PlanetarySystem::GaccRel (const Vector &rpos, const CelestialBody *cbody, double n, const Body *exclude, GFieldData *gfd) const +VECTOR3 PlanetarySystem::GaccRel (const VECTOR3 &rpos, const CelestialBody *cbody, double n, const Body *exclude, GFieldData *gfd) const { - Vector acc; + VECTOR3 acc; DWORD i, j; - Vector gpos (rpos + cbody->InterpolatePosition (n)); + VECTOR3 gpos = rpos + cbody->InterpolatePosition(n); if (gfd) { // use bodies's source list for (j = 0; j < gfd->ngrav; j++) { @@ -791,12 +791,12 @@ Vector PlanetarySystem::GaccRel (const Vector &rpos, const CelestialBody *cbody, return acc; } -Vector PlanetarySystem::GaccPn_perturbation (const Vector &gpos, double n, const CelestialBody *cbody) const +VECTOR3 PlanetarySystem::GaccPn_perturbation (const VECTOR3 &gpos, double n, const CelestialBody *cbody) const { return SingleGacc_perturbation (cbody->InterpolatePosition (n) - gpos, cbody); } -CelestialBody *PlanetarySystem::GetDominantGravitySource (const Vector &gpos, double &gfrac) +CelestialBody *PlanetarySystem::GetDominantGravitySource (const VECTOR3 &gpos, double &gfrac) { // assumes spherical gravity sources DWORD i; @@ -804,8 +804,8 @@ CelestialBody *PlanetarySystem::GetDominantGravitySource (const Vector &gpos, do CelestialBody *body = 0; for (i = 0; i < celestials.size(); i++) { - Vector r(celestials[i]->GPos() - gpos); - gtot += (g = celestials[i]->Mass() / r.length2()); + VECTOR3 r = celestials[i]->GPos() - gpos; + gtot += (g = celestials[i]->Mass() / len_2(r)); if (g > gmax) { gmax = g; body = celestials[i]; @@ -815,15 +815,15 @@ CelestialBody *PlanetarySystem::GetDominantGravitySource (const Vector &gpos, do return body; } -double PlanetarySystem::GetGravityContribution (const Body *body, const Vector &gpos, bool *dominant) +double PlanetarySystem::GetGravityContribution (const Body *body, const VECTOR3 &gpos, bool *dominant) { // assumes spherical gravity sources DWORD i; double g, gtot = 0.0, gbody = 0.0, gmax = 0.0; for (i = 0; i < celestials.size(); i++) { - Vector r(celestials[i]->GPos() - gpos); - gtot += (g = celestials[i]->Mass() / r.length2()); + VECTOR3 r = celestials[i]->GPos() - gpos; + gtot += (g = celestials[i]->Mass() / len_2(r)); if (celestials[i] == body) gbody = g; if (g > gmax) gmax = g; } @@ -831,11 +831,11 @@ double PlanetarySystem::GetGravityContribution (const Body *body, const Vector & return (gtot ? gbody/gtot : 0.0); } -Vector PlanetarySystem::GetMomentumFlux (const Vector &gpos) const +VECTOR3 PlanetarySystem::GetMomentumFlux (const VECTOR3 &gpos) const { const double L = 3.846e26; // sun luminosity [W] - SHOULD BE CONFIGURABLE! const double F = L/(4.0*PI*C0); // radiation force at unit distance - double r2 = gpos.length2(); + double r2 = len_2(gpos); double p = F/r2; // radiation pressure at distance r return gpos * (p/sqrt(r2)); } diff --git a/Src/Orbiter/Psys.h b/Src/Orbiter/Psys.h index 503f51e8d..baea74698 100644 --- a/Src/Orbiter/Psys.h +++ b/Src/Orbiter/Psys.h @@ -14,8 +14,8 @@ class Vessel; class SuperVessel; struct TimeJumpData; -Vector SingleGacc (const Vector &rpos, const CelestialBody *body); -Vector SingleGacc_perturbation (const Vector &rpos, const CelestialBody *body); +VECTOR3 SingleGacc (const VECTOR3 &rpos, const CelestialBody *body); +VECTOR3 SingleGacc_perturbation (const VECTOR3 &rpos, const CelestialBody *body); class PlanetarySystem { friend class Body; @@ -127,17 +127,17 @@ class PlanetarySystem { void Timejump (const TimeJumpData& jump); // Discontinuous step - void ScanGFieldSources (const Vector *gpos, const Body *exclude, GFieldData *gfd) const; + void ScanGFieldSources (const VECTOR3 *gpos, const Body *exclude, GFieldData *gfd) const; // Build a list of significant gravity sources at point 'gpos', // excluding body 'exclude', and return results in 'gfd'. - void UpdateGFieldSources (const Vector *gpos, const Body *exclude, GFieldData *gfd) const; + void UpdateGFieldSources (const VECTOR3 *gpos, const Body *exclude, GFieldData *gfd) const; // Update the existing list - Vector GaccAt (double t, const Vector &gpos, const Body *exclude = 0) const; + VECTOR3 GaccAt (double t, const VECTOR3 &gpos, const Body *exclude = 0) const; // gravity field at gpos for time t - Vector Gacc (const Vector &gpos, const Body *exclude = 0, const GFieldData *gfd = 0) const; + VECTOR3 Gacc (const VECTOR3 &gpos, const Body *exclude = 0, const GFieldData *gfd = 0) const; // Acceleration vector due to gravitational forces at global position gpos for current time t0. // If exclude != 0 then this object is omitted (to avoid objects interrogating themselves) // If gfd != 0 then only g-sources from this list are computed @@ -149,32 +149,32 @@ class PlanetarySystem { // if gfd != 0 then only objects from this source list are computed (plus an additional // one tested for inclusion in the list) - Vector Gacc_intermediate (const Vector &gpos, double n, const Body *exclude = 0, GFieldData *gfd = 0) const; + VECTOR3 Gacc_intermediate (const VECTOR3 &gpos, double n, const Body *exclude = 0, GFieldData *gfd = 0) const; // Acceleration vector due to gravitational forces at global position gpos at intermediate // time t = t0+n*dt, where 0 <= n <= 1 is a fractional time step, n = (t-t0)/dt, and dt = t1-t0. // Uses linear interpolation of celestial body positions. // If gfd != 0 then only g-sources from this list are computed - Vector Gacc_intermediate_pert (const CelestialBody *cbody, const Vector &gpos, double n, const Body *exclude, GFieldData *gfd) const; + VECTOR3 Gacc_intermediate_pert (const CelestialBody *cbody, const VECTOR3 &gpos, double n, const Body *exclude, GFieldData *gfd) const; - Vector GaccPn_perturbation (const Vector &gpos, double n, const CelestialBody *cbody) const; + VECTOR3 GaccPn_perturbation (const VECTOR3 &gpos, double n, const CelestialBody *cbody) const; // returns the nonspherical perturbation of the gravity field from 'body' at global // position 'gpos' at fractional time n during current time step (0<=n<=1). - Vector GaccRel (const Vector &rpos, const CelestialBody *cbody, double n, const Body *exclude, GFieldData *gfd) const; + VECTOR3 GaccRel (const VECTOR3 &rpos, const CelestialBody *cbody, double n, const Body *exclude, GFieldData *gfd) const; // this version calculates the gravitational acceleration vector at fractional time n during // current time step for position 'rpos' relative to 'cbody' - CelestialBody *GetDominantGravitySource (const Vector &gpos, double &gfrac); + CelestialBody *GetDominantGravitySource (const VECTOR3 &gpos, double &gfrac); // return the dominant object contributing to the gravity field // at position pos. gfrac is the fractional contribution of the // dominant body to the total field - double GetGravityContribution (const Body *body, const Vector &gpos, bool *dominant = 0); + double GetGravityContribution (const Body *body, const VECTOR3 &gpos, bool *dominant = 0); // returns the fractional contribution of "body" to the gravity field at gpos. // if defined, dominant returns true if the body is the major contributor - Vector GetMomentumFlux (const Vector &gpos) const; + VECTOR3 GetMomentumFlux (const VECTOR3 &gpos) const; // returns the momentum flux [N/m^2] due to solar radiation at position gpos. // - assumes single radiation source at origin // - source luminosity is fixed to L=3.846e26 W (sun) diff --git a/Src/Orbiter/Rigidbody.cpp b/Src/Orbiter/Rigidbody.cpp index 440b2055f..8ab0c29bd 100644 --- a/Src/Orbiter/Rigidbody.cpp +++ b/Src/Orbiter/Rigidbody.cpp @@ -38,11 +38,11 @@ RigidBody::PROPMODE RigidBody::PropMode[MAX_PROP_LEVEL] = {&RigidBody::RK2_LinAn const double gfielddata_updt_interval = 60.0; -inline Vector Call_EulerInv_full (RigidBody *body, const Vector &tau, const Vector &omega) +inline auto Call_EulerInv_full (RigidBody *body, const VECTOR3 &tau, const VECTOR3 &omega) { return body->EulerInv_full (tau, omega); } -inline Vector Call_EulerInv_simple (RigidBody *body, const Vector &tau, const Vector &omega) +inline auto Call_EulerInv_simple (RigidBody *body, const VECTOR3 &tau, const VECTOR3 &omega) { return body->EulerInv_simple (tau, omega); } -inline Vector Call_EulerInv_zero (RigidBody *body, const Vector &tau, const Vector &omega) +inline auto Call_EulerInv_zero (RigidBody *body, const VECTOR3 &tau, const VECTOR3 &omega) { return body->EulerInv_zero (tau, omega); } // ======================================================================= @@ -53,10 +53,10 @@ RigidBody::RigidBody (): Body () SetDefaultCaps (); } -RigidBody::RigidBody (double _mass, double _size, const Vector &_pmi): Body (_mass, _size) +RigidBody::RigidBody (double _mass, double _size, const VECTOR3 &_pmi): Body (_mass, _size) { SetDefaultCaps (); - pmi.Set (_pmi); + pmi = _pmi; } RigidBody::RigidBody (char *fname): Body (fname) @@ -81,7 +81,7 @@ void RigidBody::SetDefaultCaps () el = 0; el_valid = false; - pmi.Set (-1,-1,-1); // "undef" + pmi = {-1, -1, -1}; // "undef" bDynamicPosVel = true; bCanUpdateStabilised = g_pOrbiter->Cfg()->CfgPhysicsPrm.bOrbitStabilise; bDistmass = g_pOrbiter->Cfg()->CfgPhysicsPrm.bDistributedMass; @@ -104,8 +104,8 @@ void RigidBody::ReadGenericCaps (ifstream &ifs) void RigidBody::SetDefaultState () { - arot.Set (0,0,0); - torque.Set (0,0,0); + arot = {0, 0, 0}; + torque = {0, 0, 0}; } void RigidBody::SetOrbitReference (CelestialBody *body) @@ -169,7 +169,7 @@ void RigidBody::SetPropagator (int &plevel, int &nstep) const if (td.SimDT < PropMode[plevel].tlim) break; // 2. Angle step limit - double astep = s0->omega.length()*td.SimDT; // angular step size + double astep = len(s0->omega) * td.SimDT; // angular step size for (; plevel < nPropLevel-1; plevel++) if (astep < PropMode[plevel].alim) break; @@ -192,9 +192,9 @@ void RigidBody::Update (bool force) // incremental part to minimise roundoff errors int i; - Vector tau; - pcpos.Set (cpos); - ostep = cvel.length()*td.SimDT / (Pi2 * cpos.length()); + VECTOR3 tau; + pcpos = cpos; + ostep = len(cvel) * td.SimDT / (Pi2 * len(cpos)); // approx. orbit step length (fraction of full orbit) bIgnoreGravTorque = (!bDistmass || ostep > 0.1 /*|| @@ -224,14 +224,14 @@ void RigidBody::Update (bool force) if (!bOrbitStabilised) { FlushRPos(); FlushRVel(); - s1->pos.Set (cpos); - s1->vel.Set (cvel); + s1->pos = cpos; + s1->vel = cvel; GetIntermediateMoments_pert (acc_pert, tau, *s0, 0, dt, cbody); el->Calculate (cpos, cvel, td.SimT0); // get elements from previous step } Encke(); - s1->pos.Set (cpos + cbody->s1->pos); - s1->vel.Set (cvel + cbody->s1->vel); + s1->pos = cpos + cbody->s1->pos; + s1->vel = cvel + cbody->s1->vel; FlushRPos(); FlushRVel(); s1->R.Set (s1->Q); @@ -240,8 +240,8 @@ void RigidBody::Update (bool force) } else { // do a dynamic state vector integration - Vector acc0(acc), arot0(arot); - Vector rpos_add0(rpos_add), rvel_add0(rvel_add); + VECTOR3 acc0 = acc, arot0 = arot; + VECTOR3 rpos_add0 = rpos_add, rvel_add0 = rvel_add; do { // Select propagator SetPropagator (PropLevel, nPropSubsteps); @@ -257,16 +257,16 @@ void RigidBody::Update (bool force) s1->vel = rvel_base + rvel_add; s1->R.Set (s1->Q); GetIntermediateMoments (acc, tau, *s1, (i+1.0)/nPropSubsteps, dt); - arot.Set (EulerInv_full (tau, s1->omega)); + arot = EulerInv_full(tau, s1->omega); } } while (!ValidateStateUpdate (s1)); //s1->R.Set (s1->Q); if (updcount++ == 1000) { // flush increments rpos_base += rpos_add; - rpos_add.Set (0,0,0); + rpos_add = {0, 0, 0}; rvel_base += rvel_add; - rvel_add.Set (0,0,0); + rvel_add = {0, 0, 0}; updcount = 0; } el_valid = bOrbitStabilised = false; @@ -279,10 +279,10 @@ void RigidBody::Update (bool force) const double vmag_max = 100.0*Pi; // limit angular velocities to 100Hz - make user-definable! extern int errno; errno = 0; - double vmag = s1->omega.length(); + double vmag = len(s1->omega); if (vmag > vmag_max || errno) { if (errno) { // fatal error - reset to arbitrary values - s1->omega.Set (0,0,vmag_max); + s1->omega = {0, 0, vmag_max}; vmag = vmag_max; s1->Q.Set (0,0,0,1); s1->R.Set (s0->Q); @@ -290,7 +290,7 @@ void RigidBody::Update (bool force) s1->omega *= vmag_max/vmag; vmag = vmag_max; } - arot.Set(0,0,0); + arot = {0, 0, 0}; } } Body::Update (force); @@ -317,13 +317,13 @@ void RigidBody::UpdateGFieldSources (const PlanetarySystem *psys) // ======================================================================= -Vector RigidBody::InterpolatePos (const Vector &p0, const Vector &p1, double t1, double dt, double tfrac) const +VECTOR3 RigidBody::InterpolatePos (const VECTOR3 &p0, const VECTOR3 &p1, double t1, double dt, double tfrac) const { if (ostep < 1e-3) { // use simple linear interpolation return p0 + (p1-p0)*tfrac; } else if (ostep < 1e-2) { // slightly more sophisticated interpolation - Vector dir (p0 + (p1-p0)*tfrac); - return dir.unit() * (p0.length()*(1.0-tfrac) + p1.length()*tfrac); + VECTOR3 dir = p0 + (p1 - p0) * tfrac; + return unit(dir) * (len(p0) * (1.0 - tfrac) + len(p1) * tfrac); } else { // use Kepler orbit interpolation if (!el_valid) { el->Calculate (cpos, cvel, td.SimT0); @@ -335,7 +335,7 @@ Vector RigidBody::InterpolatePos (const Vector &p0, const Vector &p1, double t1, // ======================================================================= -void RigidBody::GetIntermediateMoments (Vector &acc, Vector &tau, +void RigidBody::GetIntermediateMoments (VECTOR3 &acc, VECTOR3 &tau, const StateVectors &state, double tfrac, double dt) { // linear acceleration due to graviational field @@ -343,14 +343,14 @@ void RigidBody::GetIntermediateMoments (Vector &acc, Vector &tau, // angular acceleration due to gravity gradient torque if (!cbody || bIgnoreGravTorque) { - tau.Set (0,0,0); + tau = {0, 0, 0}; } else { // map cbody into vessel frame - Vector R0 (tmul (state.Q, cbody->InterpolatePosition (tfrac) - state.pos)); - double r0 = R0.length(); - Vector Re = R0/r0; + VECTOR3 R0 = tmul(state.Q, cbody->InterpolatePosition(tfrac) - state.pos); + double r0 = len(R0); + VECTOR3 Re = R0 / r0; double mag = 3.0 * Ggrav * cbody->Mass() / pow(r0,3.0); - tau.Set (crossp (pmi*Re, Re) * mag); + tau = cross(pmi * Re, Re) * mag; // damping of angular velocity if (tidaldamp) { @@ -365,7 +365,7 @@ void RigidBody::GetIntermediateMoments (Vector &acc, Vector &tau, // ======================================================================= -void RigidBody::GetIntermediateMoments_pert (Vector &acc, Vector &tau, +void RigidBody::GetIntermediateMoments_pert (VECTOR3 &acc, VECTOR3 &tau, const StateVectors &state_rel, double tfrac, double dt, const CelestialBody *cbody) { // Note: Encke's method in the current implementation doesn't seem @@ -373,8 +373,8 @@ void RigidBody::GetIntermediateMoments_pert (Vector &acc, Vector &tau, // altogether to revert to a simple 2-body solution #define NO_GRAV_PERT #ifdef NO_GRAV_PERT - acc.Set (0,0,0); - tau.Set (0,0,0); + acc = {0, 0, 0}; + tau = {0, 0, 0}; #else Vector gpos = state_rel.pos + cbody->InterpolatePosition (tfrac); // linear acceleration due to graviational field @@ -382,14 +382,14 @@ void RigidBody::GetIntermediateMoments_pert (Vector &acc, Vector &tau, // angular acceleration due to gravity gradient torque if (!cbody || bIgnoreGravTorque) { - tau.Set (0,0,0); + tau = {0, 0, 0}; } else { // map cbody into vessel frame Vector R0 (tmul (state_rel.Q, cbody->InterpolatePosition (tfrac) - gpos)); - double r0 = R0.length(); + double r0 = len(R0); Vector Re = R0/r0; double mag = 3.0 * Ggrav * cbody->Mass() / pow(r0,3.0); - tau.Set (crossp (pmi*Re, Re) * mag); + tau = cross(pmi * Re, Re) * mag; // damping of angular velocity if (tidaldamp) { @@ -405,13 +405,13 @@ void RigidBody::GetIntermediateMoments_pert (Vector &acc, Vector &tau, // ======================================================================= -Vector RigidBody::GetPertAcc (const PertIntData &data, const Vector &pos, double tfrac) +VECTOR3 RigidBody::GetPertAcc (const PertIntData &data, const VECTOR3 &pos, double tfrac) { // acceleration perturbation: difference of the perturbation fields // between vessel position and central body position (at last step) - static Vector zero(0,0,0); - Vector accp (g_psys->GaccRel (pos, cbody, tfrac, cbody, &gfielddata) - g_psys->GaccRel (zero, cbody, tfrac, cbody, &gfielddata)); + static VECTOR3 zero{0, 0, 0}; + VECTOR3 accp = g_psys->GaccRel(pos, cbody, tfrac, cbody, &gfielddata) - g_psys->GaccRel(zero, cbody, tfrac, cbody, &gfielddata); if (data.nonspherical) accp += SingleGacc_perturbation (-pos, cbody); @@ -421,18 +421,18 @@ Vector RigidBody::GetPertAcc (const PertIntData &data, const Vector &pos, double // ======================================================================= -Vector RigidBody::GetTorque () const +VECTOR3 RigidBody::GetTorque () const { - if (!cbody || bIgnoreGravTorque) return Vector(0,0,0); // sanity check + if (!cbody || bIgnoreGravTorque) return {0, 0, 0}; // sanity check - Vector R0; + VECTOR3 R0; // map cbody into vessel frame - R0.Set (tmul (s0->R, cbody->s0->pos - s0->pos)); - double r0 = R0.length(); - Vector Re = R0/r0; + R0 = tmul (s0->R, cbody->s0->pos - s0->pos); + double r0 = len(R0); + VECTOR3 Re = R0 / r0; double mag = 3.0 * Ggrav * cbody->Mass() / pow(r0,3.0); - Vector M (crossp (pmi*Re, Re) * mag); + VECTOR3 M = cross(pmi * Re, Re) * mag; // damping of angular velocity if (tidaldamp) { @@ -448,24 +448,25 @@ Vector RigidBody::GetTorque () const // ======================================================================= -void RigidBody::SetAngVel (const Vector &omega) +void RigidBody::SetAngVel (const VECTOR3 &omega) { - s0->omega.Set (omega); + s0->omega = omega; } // ======================================================================= -Vector RigidBody::Euler_full (const Vector &omegadot, const Vector &omega) const +VECTOR3 RigidBody::Euler_full (const VECTOR3 &omegadot, const VECTOR3 &omega) const { - return Vector ( - omegadot.x*pmi.x + (pmi.y-pmi.z)*omega.y*omega.z, - omegadot.y*pmi.y + (pmi.z-pmi.x)*omega.z*omega.x, - omegadot.z*pmi.z + (pmi.x-pmi.y)*omega.x*omega.y); + return VECTOR3{ + omegadot.x * pmi.x + (pmi.y - pmi.z) * omega.y * omega.z, + omegadot.y * pmi.y + (pmi.z - pmi.x) * omega.z * omega.x, + omegadot.z * pmi.z + (pmi.x - pmi.y) * omega.x * omega.y + }; } // ======================================================================= -Vector RigidBody::EulerInv_full (const Vector &tau, const Vector &omega) const +VECTOR3 RigidBody::EulerInv_full (const VECTOR3 &tau, const VECTOR3 &omega) const { // Solves Euler's equation (in left-handed system): // @@ -474,15 +475,16 @@ Vector RigidBody::EulerInv_full (const Vector &tau, const Vector &omega) const // for angular acceleration domega/dt, given torque tau, angular // velocity omega and inertia tensor I (assumed to be diagonal). - return Vector ( - (tau.x - (pmi.y-pmi.z)*omega.y*omega.z) / pmi.x, - (tau.y - (pmi.z-pmi.x)*omega.z*omega.x) / pmi.y, - (tau.z - (pmi.x-pmi.y)*omega.x*omega.y) / pmi.z); + return VECTOR3{ + (tau.x - (pmi.y - pmi.z) * omega.y * omega.z) / pmi.x, + (tau.y - (pmi.z - pmi.x) * omega.z * omega.x) / pmi.y, + (tau.z - (pmi.x - pmi.y) * omega.x * omega.y) / pmi.z + }; } // ======================================================================= -Vector RigidBody::EulerInv_simple (const Vector &tau, const Vector &omega) const +VECTOR3 RigidBody::EulerInv_simple (const VECTOR3 &tau, const VECTOR3 &omega) const { // Simplified version of Euler's equation: ignores coupling terms, // and only solves @@ -493,12 +495,12 @@ Vector RigidBody::EulerInv_simple (const Vector &tau, const Vector &omega) const // tensor I (assumed to be diagonal). // Used at high time acceleration to avoid instabilities. - return Vector (tau.x/pmi.x, tau.y/pmi.y, tau.z/pmi.z); + return tau / pmi; } // ======================================================================= -Vector RigidBody::EulerInv_zero (const Vector &tau, const Vector &omega) const +VECTOR3 RigidBody::EulerInv_zero (const VECTOR3 &tau, const VECTOR3 &omega) const { // Trivial version of Euler's equation: suppresses cross-axis // coupling terms and torque, i.e. solves @@ -507,7 +509,7 @@ Vector RigidBody::EulerInv_zero (const Vector &tau, const Vector &omega) const // // for angular acceleration domega/dt, and thus returns zero. - return Vector (0,0,0); + return {0, 0, 0}; } // ======================================================================= @@ -516,8 +518,8 @@ void RigidBody::SetDynamicUpdate (bool dynamic) { if (bDynamicPosVel == dynamic) return; // nothing to do if (bDynamicPosVel = dynamic) { - rpos_base.Set (s0->pos); - rpos_add.Set (0,0,0); + rpos_base = s0->pos; + rpos_add = {0, 0, 0}; } else { } } diff --git a/Src/Orbiter/Rigidbody.h b/Src/Orbiter/Rigidbody.h index a3a682ca2..df0280200 100644 --- a/Src/Orbiter/Rigidbody.h +++ b/Src/Orbiter/Rigidbody.h @@ -35,15 +35,15 @@ typedef struct { // used for dynamic grav updates typedef struct { // data for angular integrators int nsub; // subdivisions of current time step (1=full step) double t1, dt; // subdivision end time, time interval - Vector p0, p1; // orbital positions at start, end of subdivision step - Vector (*AngAcc)(RigidBody *body, const Vector &tau, const Vector &omega); + VECTOR3 p0, p1; // orbital positions at start, end of subdivision step + VECTOR3 (*AngAcc)(RigidBody *body, const VECTOR3 &tau, const VECTOR3 &omega); // full/simplified Euler's equations of angular motion } AngIntData; typedef struct { // data for linear perturbation integrators double t1, dt; // subdivision end time, time interval - Vector dv; // applied non-gravitational delta v - Vector p0; // orbital position at start of sobdivision step + VECTOR3 dv; // applied non-gravitational delta v + VECTOR3 p0; // orbital position at start of sobdivision step bool nonspherical; // include nonspherical perturbations } PertIntData; @@ -58,7 +58,7 @@ typedef void (RigidBody::*LinAngPropagator)(double, int, int); class RigidBody: public Body { public: RigidBody (); - RigidBody (double _mass, double _size, const Vector &_pmi); + RigidBody (double _mass, double _size, const VECTOR3 &_pmi); RigidBody (char *fname); virtual ~RigidBody(); @@ -66,7 +66,7 @@ class RigidBody: public Body { static void GlobalSetup (); // 1-time setup routines at beginning of simulation session - inline const Vector &PMI () const { return pmi; } + inline const VECTOR3 &PMI() const { return pmi; } // principal moments of inertia //virtual void BeginStateUpdate (); @@ -90,14 +90,14 @@ class RigidBody: public Body { // for current step. Note that nstep > PropSubMax is valid, but should only be // used for immediate collision treatment - virtual void GetIntermediateMoments (Vector &acc, Vector &tau, + virtual void GetIntermediateMoments(VECTOR3 &acc, VECTOR3 &tau, const StateVectors &state, double tfrac, double dt); // Returns acceleration acc and torque tau, at time SimT0+tfrac*SimDT // and step size dt, given intermediate state in global frame // Note: state.vel is not used by this method - virtual void GetIntermediateMoments_pert (Vector &acc, - Vector &tau, const StateVectors &state_rel, double tfrac, double dt, + virtual void GetIntermediateMoments_pert(VECTOR3 &acc, + VECTOR3 &tau, const StateVectors &state_rel, double tfrac, double dt, const CelestialBody *cbody); // As GetIntermediateMoments, but excludes the pointmass gravitational // acceleration of cbody. This is used by the Encke stabilised @@ -108,39 +108,39 @@ class RigidBody: public Body { virtual bool ValidateStateUpdate (StateVectors *s) { return true; } - virtual Vector GetPertAcc (const PertIntData &data, const Vector &pos, double tfrac); + virtual VECTOR3 GetPertAcc(const PertIntData &data, const VECTOR3 &pos, double tfrac); // returns the gravity perturbation (on top of the spherical gravity field // from cbody) at relative position pos, at fractional time tfrac within // the current time step - virtual Vector GetTorque () const; + virtual VECTOR3 GetTorque() const; // Returns mass-normalised torque vector for state s0. This only consists of // gravity gradient torque, and only if enabled. - inline const Vector &AngularVelocity () const { return s0->omega; } + inline const VECTOR3 &AngularVelocity() const { return s0->omega; } // angular velocity - should be moved to Body class! - virtual void SetAngVel (const Vector &omega); + virtual void SetAngVel(const VECTOR3 &omega); // set angular velocity to 'omega' - inline Vector AngularMomentum () const - { return Vector(pmi.x*s0->omega.x, pmi.y*s0->omega.y, pmi.z*s0->omega.z); } + inline VECTOR3 AngularMomentum() const + { return VECTOR3{pmi.x * s0->omega.x, pmi.y * s0->omega.y, pmi.z * s0->omega.z}; } // returns the vessel's current angular momentum (in local vessel coordinates) - Vector Euler_full (const Vector &omegadot, const Vector &omega) const; + VECTOR3 Euler_full(const VECTOR3 &omegadot, const VECTOR3 &omega) const; // returns torque tau, given angular acceleration omegadot and angular velocity // omega. - Vector EulerInv_full (const Vector &tau, const Vector &omega) const; + VECTOR3 EulerInv_full(const VECTOR3 &tau, const VECTOR3 &omega) const; // Solves Euler's equation: // returns angular acceleration, given torque tau and angular velocity // omega. - Vector EulerInv_simple (const Vector &tau, const Vector &omega) const; + VECTOR3 EulerInv_simple(const VECTOR3 &tau, const VECTOR3 &omega) const; // Simplified angular acceleration calculation ignoring cross-axis // coupling terms - Vector EulerInv_zero (const Vector &tau, const Vector &omega) const; + VECTOR3 EulerInv_zero(const VECTOR3 &tau, const VECTOR3 &omega) const; // Trivial angular acceleration calculation: ignores cross-axis // coupling terms and torque, and always returns zero @@ -186,7 +186,7 @@ class RigidBody: public Body { void UpdateGFieldSources (const PlanetarySystem *psys); // Update an existing list of gravity sources - Vector InterpolatePos (const Vector &p0, const Vector &p1, double t1, double dt, double tfrac) const; + VECTOR3 InterpolatePos(const VECTOR3 &p0, const VECTOR3 &p1, double t1, double dt, double tfrac) const; // interpolates orbital position between start point p1 and end point p2, given // end time t1 and interval dt, at fractional position tfrac [0..1] @@ -219,12 +219,12 @@ class RigidBody: public Body { mutable Elements *el; // osculating elements for orbiting bodies mutable bool el_valid; // flag for element update - Vector cpos, cvel; // state vectors w.r.t. reference body - Vector pcpos; // refbody-relative position at previous step - Vector pmi; // principal moments of inertia tensor - Vector arot; // current angular acceleration - Vector acc_pert; // current acceleration excluding gravity from primary point mass (for Encke state integration, only valid during stabilised updates) - Vector torque; // current torque of CG + VECTOR3 cpos, cvel;// state vectors w.r.t. reference body + VECTOR3 pcpos; // refbody-relative position at previous step + VECTOR3 pmi; // principal moments of inertia tensor + VECTOR3 arot; // current angular acceleration + VECTOR3 acc_pert; // current acceleration excluding gravity from primary point mass (for Encke state integration, only valid during stabilised updates) + VECTOR3 torque; // current torque of CG double tidaldamp; // damping factor for tidal torque double ostep; // time step in terms of fractional orbit (approx.) AngIntData aidata; // data for angular integration diff --git a/Src/Orbiter/Scene.cpp b/Src/Orbiter/Scene.cpp index ed950fd26..0221a1201 100644 --- a/Src/Orbiter/Scene.cpp +++ b/Src/Orbiter/Scene.cpp @@ -292,7 +292,7 @@ void Scene::UpdateVisual (Body *body, Camera **camlist, int ncam) for (i = 0; !vis && i < ncam; i++) { Camera *cam = camlist[i]; - double dist = body->GPos().dist (cam->GPos()); + double dist = ::dist(body->GPos(), cam->GPos()); double apps = body->Size()/(dist*cam->TanAperture()); vis = (apps > body->VisLimit()); #ifdef UNDEF @@ -501,7 +501,7 @@ void Scene::AddLocalLight (const LightEmitter *le, const VObject *vo, DWORD idx) } if (lght.dltType != D3DLIGHT_POINT) { const VECTOR3 dir = le->GetDirection(); - Vector d = mul (vo->GetBody()->GRot(), MakeVector(dir)); + VECTOR3 d = mul(vo->GetBody()->GRot(), dir); lght.dvDirection.dvX = (float)d.x; lght.dvDirection.dvY = (float)d.y; lght.dvDirection.dvZ = (float)d.z; @@ -570,7 +570,7 @@ void Scene::Timejump (PlanetarySystem *psys, Camera **camlist, DWORD ncam, bool static int lvlid[256]; -void Scene::Render3DLabel (const Vector &gp, const char *label, double scale, DWORD colour) +void Scene::Render3DLabel (const VECTOR3 &gp, const char *label, double scale, DWORD colour) { static VERTEX_TL1TEX Vtx[4] = { {0,0,0,0,(D3DCOLOR)D3DRGBA(1,1,1,1),0.001f,0.001f}, @@ -580,8 +580,8 @@ void Scene::Render3DLabel (const Vector &gp, const char *label, double scale, DW }; static WORD Idx[6] = {0,1,2,3,2,1}; - Vector lp = gp-g_camera->GPos(); - double dist = lp.length(); + VECTOR3 lp = gp - g_camera->GPos(); + double dist = len(lp); int ix, iy, w; RECT sr = {0,0,0,28}; if (g_pane->GlobalToScreen (lp/dist, ix, iy)) { @@ -654,40 +654,39 @@ double Scene::MinParticleCameraDist() const VECTOR3 Scene::SkyColour() { - Vector col; + VECTOR3 col; const Planet* pp = g_camera->ProxyPlanet(); if (pp && pp->HasAtmosphere()) { const ATMCONST* atmp = pp->AtmParams(); - Vector pc(g_camera->GPos() - pp->GPos()); - double cdist = pc.length(); + VECTOR3 pc = g_camera->GPos() - pp->GPos(); + double cdist = len(pc); if (cdist < atmp->radlimit) { ATMPARAM prm; pp->GetAtmParam(cdist - pp->Size(), 0, 0, &prm); - Vector ps(-pp->GPos()); - ps.unify(); - double coss = (pc & ps) / cdist; + VECTOR3 ps = unit(-pp->GPos()); + double coss = dot(pc, ps) / cdist; double intens = min(1.0, (1.0839 * coss + 0.4581)) * sqrt(prm.rho / atmp->rho0); // => intensity=0 at sun zenith distance 115° // intensity=1 at sun zenith distance 60° if (intens > 0.0) - col += Vector(atmp->color0.x * intens, atmp->color0.y * intens, atmp->color0.z * intens); + col += atmp->color0 * intens; } for (int i = 0; i < 3; i++) if (col.data[i] > 1.0) col.data[i] = 1.0; } - return MakeVECTOR3(col); + return col; } -void Scene::RenderObjectMarker (oapi::Sketchpad* pSkp, const Vector &gpos, const std::string& label1, const std::string& label2, int mode, int scale) +void Scene::RenderObjectMarker (oapi::Sketchpad* pSkp, const VECTOR3 &gpos, const std::string& label1, const std::string& label2, int mode, int scale) { - m_celSphere->RenderMarker(pSkp, MakeVECTOR3((gpos - g_camera->GPos()).unit()), label1, label2, mode, scale); + m_celSphere->RenderMarker(pSkp, unit(gpos - g_camera->GPos()), label1, label2, mode, scale); } void Scene::Render (D3DRECT* vp_rect) { int i, j, k; DWORD n; - Vector col; + VECTOR3 col; HRESULT res; g_vtxcount = g_tilecount = 0; @@ -708,8 +707,7 @@ void Scene::Render (D3DRECT* vp_rect) // set lighting for (i = 0; i < nstarlight; i++) { star_lght->dcvDiffuse = starlight[i].col; - Vector dir = g_camera->GPos() - *starlight[i].gpos; - dir.unify(); + VECTOR3 dir = unit(g_camera->GPos() - *starlight[i].gpos); star_lght->dvDirection.x = (D3DVALUE)dir.x; star_lght->dvDirection.y = (D3DVALUE)dir.y; star_lght->dvDirection.z = (D3DVALUE)dir.z; @@ -823,19 +821,19 @@ void Scene::Render (D3DRECT* vp_rect) font = nullptr; Planet* pl = (Planet*)vo->GetBody(); double lng, lat, apprad = vo->AppRad() / (0.5 * viewH); - Vector sp; + VECTOR3 sp; if ((flagMItem & MKR_BMARK) && apprad > SURFLABEL_LIMIT) { // mark surface bases for (n = 0; n < pl->nBase(); n++) { Base* base = pl->GetBase(n); base->EquPos(lng, lat); pl->EquatorialToGlobal(lng, lat, pl->Size(), sp); - if (dotp(sp - pl->GPos(), g_camera->GPos() - sp) >= 0.0) // surface point visible? + if (dot(sp - pl->GPos(), g_camera->GPos() - sp) >= 0.0) // surface point visible? RenderObjectMarker(pSkp, sp, std::string(base->Name()), std::string(), 0); } } if ((flagMItem & MKR_RMARK) && apprad > VORLABEL_LIMIT && pl->nNav()) { // mark VOR transmitters NavManager& navm = pl->NavMgr(); - Vector cloc(tmul(pl->GRot(), g_camera->GPos() - pl->GPos())); // camera in planet coords + VECTOR3 cloc = tmul(pl->GRot(), g_camera->GPos() - pl->GPos()); // camera in planet coords char cbuf[64]; bool found; for (n = 0; n < navm.nNav(); n++) { @@ -850,7 +848,7 @@ void Scene::Render (D3DRECT* vp_rect) break; } if (found) { - if (sp.dist2(cloc) < 2.5e11 && dotp(sp, cloc - sp) >= 0.0) { // surface point visible? + if (dist_2(sp, cloc) < 2.5e11 && dot(sp, cloc - sp) >= 0.0) { // surface point visible? sprintf(cbuf, "%0.2f", nav->GetFreq()); RenderObjectMarker(pSkp, mul(pl->GRot(), sp) + pl->GPos(), std::string(cbuf), std::string(), 0); } @@ -859,7 +857,7 @@ void Scene::Render (D3DRECT* vp_rect) } if (pl->LabelFormat() < 2 && (flagMItem & MKR_LMARK)) { // user-defined planetary surface labels int nlist; - Vector cp, mp; + VECTOR3 cp, mp; bool bNeedSetup = true; oapi::GraphicsClient::LABELLIST* list = pl->LabelList(&nlist); for (k = 0; k < nlist; k++) { @@ -876,8 +874,8 @@ void Scene::Render (D3DRECT* vp_rect) } const std::vector< oapi::GraphicsClient::LABELSPEC>& uls = list[k].marker; for (j = 0; j < uls.size(); j++) { - mp = MakeVector(uls[j].pos); - if (dotp(mp, cp - mp) >= 0.0) { // surface point visible? + mp = uls[j].pos; + if (dot(mp, cp - mp) >= 0.0) { // surface point visible? sp = mul(pl->GRot(), mp) + pl->GPos(); RenderObjectMarker(pSkp, sp, uls[j].label[0], uls[j].label[1], shape, size); } diff --git a/Src/Orbiter/Scene.h b/Src/Orbiter/Scene.h index 13dcdb760..b168dce41 100644 --- a/Src/Orbiter/Scene.h +++ b/Src/Orbiter/Scene.h @@ -34,7 +34,7 @@ class Scene { public: struct STARLIGHT { D3DCOLORVALUE col; - const Vector *gpos; + const VECTOR3 *gpos; }; Scene (OrbiterGraphics *og); @@ -88,10 +88,10 @@ class Scene { void Render (D3DRECT* vp_rect); // Render the scene in vp using device dev - void Render3DLabel (const Vector &p, const char *label, double scale = 1.0, DWORD colour = D3DRGBA(1,1,1,1)); + void Render3DLabel (const VECTOR3 &p, const char *label, double scale = 1.0, DWORD colour = D3DRGBA(1,1,1,1)); // Render text "label" at position p using current world matrix - void RenderObjectMarker (oapi::Sketchpad* pSkp, const Vector &gpos, const std::string& label1, const std::string& label2 = 0, int mode = 0, int scale = 0); + void RenderObjectMarker (oapi::Sketchpad* pSkp, const VECTOR3 &gpos, const std::string& label1, const std::string& label2 = 0, int mode = 0, int scale = 0); // Render a box with label to mark an object at global position gpos void RenderVesselShadows (); diff --git a/Src/Orbiter/Spherepatch.cpp b/Src/Orbiter/Spherepatch.cpp index fd62efa41..20329e6fe 100644 --- a/Src/Orbiter/Spherepatch.cpp +++ b/Src/Orbiter/Spherepatch.cpp @@ -33,7 +33,7 @@ extern char DBG_MSG[256]; // ======================================================================= // Local prototypes -static int Exist (Vector *node, int nnode, Vector p); +static int Exist (VECTOR3 *node, int nnode, VECTOR3 p); static void CreateRing (Mesh &mesh, float irad, float orad, int nsect); LPDIRECT3DVERTEXBUFFER7 bbtarget; // target buffer for bounding box transformation @@ -210,7 +210,7 @@ void VBMESH::MapVertices (LPDIRECT3D7 d3d, LPDIRECT3DDEVICE7 dev, DWORD MemFlag) PatchManager::PatchManager (const char *_name, char _res_id, int _npatch, int _nlat, int *_nlng, VBMESH *_patch, D3DMATRIX *_trans, - Vector *_patchcnt, double *_patchrad, + VECTOR3 *_patchcnt, double *_patchrad, LPDIRECTDRAWSURFACE7 *_tex, LPDIRECTDRAWSURFACE7 *_ntex) : res_id(_res_id), npatch(_npatch), nlat(_nlat), nlng(_nlng), vbpatch(_patch), trans(_trans), patchcnt(_patchcnt), patchrad(_patchrad), @@ -232,9 +232,9 @@ bool PatchManager::SetReflectionColour (D3DCOLORVALUE *col) const ATMCONST* ap = planet->AtmParams(); if (ap) { double fac = 0.7; // adjust! - Vector S = -planet->GPos(); - Vector C = g_camera->GPos() + S; - double cosa = dotp (S, C) / (S.length() * C.length()); + VECTOR3 S = -planet->GPos(); + VECTOR3 C = g_camera->GPos() + S; + double cosa = dot(S, C) / (len(S) * len(C)); double alpha = 0.5*acos(cosa); // sun reflection angle double scale = sin(alpha)*fac; @@ -254,8 +254,8 @@ void PatchManager::Render (LPDIRECT3DDEVICE7 dev, D3DMATRIX &wmat, double visrad D3DMATRIX wtrans, imat; D3DMath_MatrixInvert (imat, wmat); - Vector rpos(imat._41, imat._42, imat._43); // camera in local coords - double id = 1.0 / max (rpos.length(), 1.0); // inverse camera distance + VECTOR3 rpos{imat._41, imat._42, imat._43}; // camera in local coords + double id = 1.0 / max (len(rpos), 1.0); // inverse camera distance if (!visrad) visrad = acos (id); // aperture of visibility sector rpos *= id; // surface point below camera bool hasmicro = false; @@ -328,7 +328,7 @@ void PatchManager::Render (LPDIRECT3DDEVICE7 dev, D3DMATRIX &wmat, double visrad if (vis) vis[idx] = false; // 1. check whether patch is within horizon radius of visibility - double cntdist = acos (rpos & patchcnt[idx]); + double cntdist = std::acos(dot(rpos, patchcnt[idx])); if (cntdist-patchrad[idx] >= visrad) continue; nquery++; @@ -417,7 +417,7 @@ void PatchManager::RenderNightlights (LPDIRECT3DDEVICE7 dev, D3DMATRIX &wmat, do dVERIFY (dev->GetMaterial (&pmat), "LPDIRECT3DDEVICE7::GetMaterial failed"); dVERIFY (dev->SetRenderState (D3DRENDERSTATE_ALPHABLENDENABLE, TRUE), "LPDIRECT3DDEVICE7::SetRenderState failed"); int i, j, hemisphere, idx; - Vector sundir; + VECTOR3 sundir; double dcos; float scale; bool dorender, modmat = true; @@ -435,8 +435,7 @@ void PatchManager::RenderNightlights (LPDIRECT3DDEVICE7 dev, D3DMATRIX &wmat, do #endif if (ref) { - sundir.Set (tmul (ref->GRot(), -ref->GPos())); - sundir.unify(); + sundir = unit(tmul(ref->GRot(), -ref->GPos())); } for (hemisphere = idx = 0; hemisphere < 2; hemisphere++) { for (i = nlat-1; i >= 0; i--) { // move from poles towards equator @@ -448,7 +447,7 @@ void PatchManager::RenderNightlights (LPDIRECT3DDEVICE7 dev, D3DMATRIX &wmat, do else dorender = true; // (acos (rpos & patchcnt[idx]) - patchrad[idx] < visrad); // FIX: vis should always exist if (dorender) { // patch visible from camera - if (ref) dcos = sundir & patchcnt[idx]; + if (ref) dcos = dot(sundir, patchcnt[idx]); else dcos = -1; if (dcos < 0.0) { // nightside if (dcos > -0.2) { @@ -501,11 +500,11 @@ void PatchManager::RenderSimple (LPDIRECT3DDEVICE7 dev, D3DMATRIX &wmat, double dev->SetTextureStageState (1, D3DTSS_COLOROP, D3DTOP_DISABLE); } -void PatchManager::SetupPatchBand (int ilat, D3DMATRIX *trans, Vector *pcnt, double *prad) +void PatchManager::SetupPatchBand (int ilat, D3DMATRIX *trans, VECTOR3 *pcnt, double *prad) { double lng1, lng2, slng1, clng1, slng2, clng2; double lat1, lat2, slat1, clat1, slat2, clat2; - Vector crnr[4]; + VECTOR3 crnr[4]; int i, ncorner, c, nofs = 0, sofs, nl = nlng[ilat]; for (i = nlat-1; i > ilat; i--) nofs += nlng[i]; sofs = nofs + npatch/2; @@ -529,23 +528,23 @@ void PatchManager::SetupPatchBand (int ilat, D3DMATRIX *trans, Vector *pcnt, dou D3DMath_MatrixMultiply (trans[sofs+i], south, trans[nofs+i]); // set up visibility stuff - crnr[0].Set (clat1*clng1, slat1, clat1*slng1); - crnr[1].Set (clat1*clng2, slat1, clat1*slng2); - crnr[2].Set (clat2*clng1, slat2, clat2*slng1); - crnr[3].Set (clat2*clng2, slat2, clat2*slng2); + crnr[0] = {clat1 * clng1, slat1, clat1 * slng1}; + crnr[1] = {clat1 * clng2, slat1, clat1 * slng2}; + crnr[2] = {clat2 * clng1, slat2, clat2 * slng1}; + crnr[3] = {clat2 * clng2, slat2, clat2 * slng2}; ncorner = (ilat == nlat-1 ? 3 : 4); - pcnt[nofs+i].Set (0,0,0); + pcnt[nofs+i] = {0, 0, 0}; for (c = 0; c < ncorner; c++) pcnt[nofs+i] += crnr[c] / (double)ncorner; for (c = 0, prad[nofs+i] = 0.0; c < ncorner; c++) { - double cangle = acos (pcnt[nofs+i] & crnr[c]); + double cangle = std::acos(dot(pcnt[nofs + i], crnr[c])); if (cangle > prad[nofs+i]) prad[nofs+i] = cangle; } - pcnt[sofs+i].Set (pcnt[nofs+i].x, -pcnt[nofs+i].y, -pcnt[nofs+i].z); + pcnt[sofs+i] = {pcnt[nofs + i].x, -pcnt[nofs + i].y, -pcnt[nofs + i].z}; prad[sofs+i] = prad[nofs+i]; } } -void PatchManager::SetupPatchBands (D3DMATRIX *trans, Vector *pcnt, double *prad) +void PatchManager::SetupPatchBands (D3DMATRIX *trans, VECTOR3 *pcnt, double *prad) { for (int i = 0; i < nlat; i++) SetupPatchBand (i, trans, pcnt, prad); @@ -671,7 +670,7 @@ void PatchManager4::Render (LPDIRECT3DDEVICE7 dev, D3DMATRIX &wmat, double visra bool PatchManager5::needsetup = true; D3DMATRIX PatchManager5::TRANS[8]; -Vector PatchManager5::PATCHCNT[8]; +VECTOR3 PatchManager5::PATCHCNT[8]; double PatchManager5::PATCHRAD[8]; PatchManager5::PatchManager5 (char *_name, LPDIRECTDRAWSURFACE7 *_tex, LPDIRECTDRAWSURFACE7 *_ntex) @@ -688,7 +687,7 @@ PatchManager5::PatchManager5 (char *_name, LPDIRECTDRAWSURFACE7 *_tex, LPDIRECTD bool PatchManager6::needsetup = true; D3DMATRIX PatchManager6::TRANS[24]; -Vector PatchManager6::PATCHCNT[24]; +VECTOR3 PatchManager6::PATCHCNT[24]; double PatchManager6::PATCHRAD[24]; PatchManager6::PatchManager6 (char *_name, LPDIRECTDRAWSURFACE7 *_tex, LPDIRECTDRAWSURFACE7 *_ntex) @@ -705,7 +704,7 @@ PatchManager6::PatchManager6 (char *_name, LPDIRECTDRAWSURFACE7 *_tex, LPDIRECTD bool PatchManager7::needsetup = true; D3DMATRIX PatchManager7::TRANS[100]; -Vector PatchManager7::PATCHCNT[100]; +VECTOR3 PatchManager7::PATCHCNT[100]; double PatchManager7::PATCHRAD[100]; PatchManager7::PatchManager7 (char *_name, LPDIRECTDRAWSURFACE7 *_tex, LPDIRECTDRAWSURFACE7 *_ntex) @@ -722,7 +721,7 @@ PatchManager7::PatchManager7 (char *_name, LPDIRECTDRAWSURFACE7 *_tex, LPDIRECTD bool PatchManager8::needsetup = true; D3DMATRIX PatchManager8::TRANS[364]; -Vector PatchManager8::PATCHCNT[364]; +VECTOR3 PatchManager8::PATCHCNT[364]; double PatchManager8::PATCHRAD[364]; PatchManager8::PatchManager8 (char *_name, LPDIRECTDRAWSURFACE7 *_tex, LPDIRECTDRAWSURFACE7 *_ntex, @@ -856,7 +855,7 @@ void CreateSphere (LPDIRECT3D7 d3d, LPDIRECT3DDEVICE7 dev, VBMESH &mesh, DWORD n // ======================================================================= // check existence of a node -static int Exist (Vector *node, int nnode, Vector p) +static int Exist (VECTOR3 *node, int nnode, VECTOR3 p) { const double eps = 1e-6; for (int i = 0; i < nnode; i++) { @@ -876,7 +875,7 @@ void CreateSpherePatch (LPDIRECT3D7 d3d, LPDIRECT3DDEVICE7 dev, VBMESH &mesh, in double minlat, maxlat, lat, minlng, maxlng, lng; double slat, clat, slng, clng; WORD tmp; - Vector pos, tpos; + VECTOR3 pos, tpos; minlat = Pi05 * (double)ilat/(double)nlat; maxlat = Pi05 * (double)(ilat+1)/(double)nlat; @@ -898,12 +897,12 @@ void CreateSpherePatch (LPDIRECT3D7 d3d, LPDIRECT3DDEVICE7 dev, VBMESH &mesh, in double clng0 = cos(minlng), slng0 = sin(minlng); double clat1 = cos(maxlat), slat1 = sin(maxlat); double clng1 = cos(maxlng), slng1 = sin(maxlng); - Vector ex(clat0*clng1 - clat0*clng0, 0, clat0*slng1 - clat0*slng0); ex.unify(); - Vector ey(0.5*(clng0+clng1)*(clat1-clat0), slat1-slat0, 0.5*(slng0+slng1)*(clat1-clat0)); ey.unify(); - Vector ez(crossp (ey, ex)); + auto ex = unit(VECTOR3{clat0 * clng1 - clat0 * clng0, 0, clat0 * slng1 - clat0 * slng0}); + auto ey = unit(VECTOR3{0.5 * (clng0 + clng1) * (clat1 - clat0), slat1 - slat0, 0.5 * (slng0 + slng1) * (clat1 - clat0)}); + auto ez = cross(ey, ex); Matrix R(ex.x, ex.y, ex.z, ey.x, ey.y, ey.z, ez.x, ez.y, ez.z); - Vector pref (0.5*(clat0*clng1 + clat0*clng0), slat0, 0.5*(clat0*slng1 + clat0*slng0)); // origin - Vector tpmin, tpmax; + VECTOR3 pref{0.5 * (clat0 * clng1 + clat0 * clng0), slat0, 0.5 * (clat0 * slng1 + clat0 * slng0)}; // origin + VECTOR3 tpmin, tpmax; float dx, dy; if (shift_origin) { @@ -918,7 +917,7 @@ void CreateSpherePatch (LPDIRECT3D7 d3d, LPDIRECT3DDEVICE7 dev, VBMESH &mesh, in for (j = 0; j <= nseg; j++) { lng = (nseg ? minlng + (maxlng-minlng) * (double)j/(double)nseg : 0.0); slng = sin(lng), clng = cos(lng); - pos.Set (clat*clng, slat, clat*slng); + pos = {clat * clng, slat, clat * slng}; tpos = mul (R, pos-pref); if (!n) { tpmin = tpos; @@ -1007,21 +1006,21 @@ void CreateSpherePatch (LPDIRECT3D7 d3d, LPDIRECT3DDEVICE7 dev, VBMESH &mesh, in mesh.bb->Lock (DDLOCK_WAIT | DDLOCK_WRITEONLY | DDLOCK_DISCARDCONTENTS, (LPVOID*)&V, NULL); // transform bounding box back to patch coordinates - pos = tmul (R, Vector(tpmin.x, tpmin.y, tpmin.z)) + pref; + pos = tmul(R, VECTOR3{tpmin.x, tpmin.y, tpmin.z}) + pref; V[0].x = D3DVAL(pos.x); V[0].y = D3DVAL(pos.y); V[0].z = D3DVAL(pos.z); - pos = tmul (R, Vector(tpmax.x, tpmin.y, tpmin.z)) + pref; + pos = tmul(R, VECTOR3{tpmax.x, tpmin.y, tpmin.z}) + pref; V[1].x = D3DVAL(pos.x); V[1].y = D3DVAL(pos.y); V[1].z = D3DVAL(pos.z); - pos = tmul (R, Vector(tpmin.x, tpmax.y, tpmin.z)) + pref; + pos = tmul(R, VECTOR3{tpmin.x, tpmax.y, tpmin.z}) + pref; V[2].x = D3DVAL(pos.x); V[2].y = D3DVAL(pos.y); V[2].z = D3DVAL(pos.z); - pos = tmul (R, Vector(tpmax.x, tpmax.y, tpmin.z)) + pref; + pos = tmul(R, VECTOR3{tpmax.x, tpmax.y, tpmin.z}) + pref; V[3].x = D3DVAL(pos.x); V[3].y = D3DVAL(pos.y); V[3].z = D3DVAL(pos.z); - pos = tmul (R, Vector(tpmin.x, tpmin.y, tpmax.z)) + pref; + pos = tmul(R, VECTOR3{tpmin.x, tpmin.y, tpmax.z}) + pref; V[4].x = D3DVAL(pos.x); V[4].y = D3DVAL(pos.y); V[4].z = D3DVAL(pos.z); - pos = tmul (R, Vector(tpmax.x, tpmin.y, tpmax.z)) + pref; + pos = tmul(R, VECTOR3{tpmax.x, tpmin.y, tpmax.z}) + pref; V[5].x = D3DVAL(pos.x); V[5].y = D3DVAL(pos.y); V[5].z = D3DVAL(pos.z); - pos = tmul (R, Vector(tpmin.x, tpmax.y, tpmax.z)) + pref; + pos = tmul(R, VECTOR3{tpmin.x, tpmax.y, tpmax.z}) + pref; V[6].x = D3DVAL(pos.x); V[6].y = D3DVAL(pos.y); V[6].z = D3DVAL(pos.z); - pos = tmul (R, Vector(tpmax.x, tpmax.y, tpmax.z)) + pref; + pos = tmul(R, VECTOR3{tpmax.x, tpmax.y, tpmax.z}) + pref; V[7].x = D3DVAL(pos.x); V[7].y = D3DVAL(pos.y); V[7].z = D3DVAL(pos.z); mesh.bb->Unlock (); @@ -1030,14 +1029,14 @@ void CreateSpherePatch (LPDIRECT3D7 d3d, LPDIRECT3DDEVICE7 dev, VBMESH &mesh, in // set bounding box in main memory mesh.bbvtx = new VECTOR4[8]; - mesh.bbvtx[0] = MakeVECTOR4 (tmul (R, Vector(tpmin.x, tpmin.y, tpmin.z)) + pref); - mesh.bbvtx[1] = MakeVECTOR4 (tmul (R, Vector(tpmax.x, tpmin.y, tpmin.z)) + pref); - mesh.bbvtx[2] = MakeVECTOR4 (tmul (R, Vector(tpmin.x, tpmax.y, tpmin.z)) + pref); - mesh.bbvtx[3] = MakeVECTOR4 (tmul (R, Vector(tpmax.x, tpmax.y, tpmin.z)) + pref); - mesh.bbvtx[4] = MakeVECTOR4 (tmul (R, Vector(tpmin.x, tpmin.y, tpmax.z)) + pref); - mesh.bbvtx[5] = MakeVECTOR4 (tmul (R, Vector(tpmax.x, tpmin.y, tpmax.z)) + pref); - mesh.bbvtx[6] = MakeVECTOR4 (tmul (R, Vector(tpmin.x, tpmax.y, tpmax.z)) + pref); - mesh.bbvtx[7] = MakeVECTOR4 (tmul (R, Vector(tpmax.x, tpmax.y, tpmax.z)) + pref); + mesh.bbvtx[0] = MakeVECTOR4(tmul(R, VECTOR3{tpmin.x, tpmin.y, tpmin.z}) + pref); + mesh.bbvtx[1] = MakeVECTOR4(tmul(R, VECTOR3{tpmax.x, tpmin.y, tpmin.z}) + pref); + mesh.bbvtx[2] = MakeVECTOR4(tmul(R, VECTOR3{tpmin.x, tpmax.y, tpmin.z}) + pref); + mesh.bbvtx[3] = MakeVECTOR4(tmul(R, VECTOR3{tpmax.x, tpmax.y, tpmin.z}) + pref); + mesh.bbvtx[4] = MakeVECTOR4(tmul(R, VECTOR3{tpmin.x, tpmin.y, tpmax.z}) + pref); + mesh.bbvtx[5] = MakeVECTOR4(tmul(R, VECTOR3{tpmax.x, tpmin.y, tpmax.z}) + pref); + mesh.bbvtx[6] = MakeVECTOR4(tmul(R, VECTOR3{tpmin.x, tpmax.y, tpmax.z}) + pref); + mesh.bbvtx[7] = MakeVECTOR4(tmul(R, VECTOR3{tpmax.x, tpmax.y, tpmax.z}) + pref); } void DestroyVBMesh (VBMESH &mesh) @@ -1082,11 +1081,11 @@ HorizonManager::HorizonManager (const Planet *_planet, const VPlanet *_vplanet) const ATMCONST *atmp = planet->AtmParams(); if (atmp) { //basecol.Set (atmp->color0.x, atmp->color0.y, atmp->color0.z); - basecol.Set (planet->AtmHazeColor()); + basecol = planet->AtmHazeColor(); hralt = (float)(atmp->horizonalt / planet->Size()); dens0 = (float)(min (1.0, atmp->horizonalt/64e3*planet->AtmHazeDensity())); } else { - basecol.Set (1,1,1); + basecol = {1, 1, 1}; hralt = 0.01f; dens0 = 1.0f; } @@ -1113,21 +1112,21 @@ void HorizonManager::Render (LPDIRECT3DDEVICE7 dev, D3DMATRIX &wmat, bool dual) { D3DMATRIX imat, transm; - Vector psun; + VECTOR3 psun; int i, j; double phi, csun, alpha, colofs; float cosp, sinp, cost, sint, h1, h2, r1, r2, intr, intg, intb; D3DMath_MatrixInvert (imat, wmat); - Vector rpos (imat._41, imat._42, imat._43); // camera in local coords (planet radius = 1) - double cdist = rpos.length(); + VECTOR3 rpos{imat._41, imat._42, imat._43}; // camera in local coords (planet radius = 1) + double cdist = len(rpos); alpha = dens0 * min (1.0, (cdist-1.0)*200.0); if (!dual) alpha = 1.0-alpha; if (alpha <= 0.0) return; // nothing to do alpha = min(alpha,1.0); - Vector cpos (0,cdist,0); + VECTOR3 cpos{0, cdist, 0}; double hr = hralt; const double cdist_min = 1.002; if (cdist < cdist_min) { @@ -1158,7 +1157,7 @@ void HorizonManager::Render (LPDIRECT3DDEVICE7 dev, D3DMATRIX &wmat, bool dual) float dens = (float)max (1.0, 1.4 - 0.3/hralt*(cdist-1.0)); // saturate haze colour at low altitudes if (dual) dens *= (float)(0.5 + 0.5/cdist); // scale down intensity at large distances - rpos.unify(); cost = (float)rpos.y, sint = (float)sqrt (1.0-cost*cost); + rpos = unit(rpos); cost = (float)rpos.y; sint = (float)sqrt(1.0 - cost * cost); phi = atan2 (rpos.z, rpos.x), cosp = (float)cos(phi), sinp = (float)sin(phi); D3DMATRIX rmat (cost*cosp, -sint, cost*sinp, 0, sint*cosp, cost, sint*sinp, 0, @@ -1169,10 +1168,10 @@ void HorizonManager::Render (LPDIRECT3DDEVICE7 dev, D3DMATRIX &wmat, bool dual) Matrix rrmat (cost*cosp, -sint, cost*sinp, sint*cosp, cost, sint*sinp, -sinp, 0, cosp ); - psun.Set (tmul (planet->GRot(), -planet->GPos())); // sun in planet coords - psun.Set (mul (rrmat, psun)); // sun in camera-relative horizon coords - Vector cs (psun-cpos); cs.unify(); // camera->sun - psun.unify(); + psun = tmul(planet->GRot(), -planet->GPos()); // sun in planet coords + psun = mul(rrmat, psun); // sun in camera-relative horizon coords + VECTOR3 cs = unit(psun - cpos); // camera->sun + psun = unit(psun); float psunx = (float)psun.x, psuny = (float)psun.y, psunz = (float)psun.z; colofs = (dual ? 0.4 : 0.3); @@ -1186,10 +1185,10 @@ void HorizonManager::Render (LPDIRECT3DDEVICE7 dev, D3DMATRIX &wmat, bool dual) dev->SetTextureStageState (0, D3DTSS_ADDRESS, D3DTADDRESS_CLAMP); for (i = j = 0; i < HORIZON_NSEG; i++) { - Vector hp (Vtx[j].x = r1*CosP[i], Vtx[j].y = h1, Vtx[j].z = r1*SinP[i]); - csun = dotp (hp, psun); - Vector cp(hp-cpos); cp.unify(); - double colsh = 0.5*(dotp (cp,cs) + 1.0); + VECTOR3 hp{Vtx[j].x = r1*CosP[i], Vtx[j].y = h1, Vtx[j].z = r1*SinP[i]}; + csun = dot(hp, psun); + VECTOR3 cp = unit(hp - cpos); + double colsh = 0.5 * (dot(cp, cs) + 1.0); // compose a colourful sunset double maxred = colofs-0.18*colsh, minred = maxred-0.4; diff --git a/Src/Orbiter/Spherepatch.h b/Src/Orbiter/Spherepatch.h index d3909caa9..35a28fa1c 100644 --- a/Src/Orbiter/Spherepatch.h +++ b/Src/Orbiter/Spherepatch.h @@ -63,7 +63,7 @@ class PatchManager { public: PatchManager (const char *_name, char _res_id, int _npatch, int _nlat, int *_nlng, VBMESH *_patch, D3DMATRIX *_trans, - Vector *_patchcnt, double *_patchrad, + VECTOR3 *_patchcnt, double *_patchrad, LPDIRECTDRAWSURFACE7 *_tex, LPDIRECTDRAWSURFACE7 *_ntex = 0); virtual ~PatchManager(); @@ -90,10 +90,10 @@ class PatchManager { // device-dependent static initialisation protected: - void SetupPatchBands (D3DMATRIX *trans, Vector *pcnt, double *prad); + void SetupPatchBands (D3DMATRIX *trans, VECTOR3 *pcnt, double *prad); // initialise all latitude bands - void SetupPatchBand (int ilat, D3DMATRIX *trans, Vector *pcnt, double *prad); + void SetupPatchBand (int ilat, D3DMATRIX *trans, VECTOR3 *pcnt, double *prad); // generate transformation matrices for patches in latitude band // ilat (for northern hemisphere in ntrans, for southern in strans) @@ -112,7 +112,7 @@ class PatchManager { static LPDIRECTDRAWSURFACE7 lightstruct1; static LPDIRECTDRAWSURFACE7 cloudstruct; D3DMATRIX *trans; - Vector *patchcnt; + VECTOR3 *patchcnt; const CelestialBody *ref; // global position of reference object double *patchrad; bool *vis; @@ -168,7 +168,7 @@ class PatchManager5: public PatchManager { private: static bool needsetup; static D3DMATRIX TRANS[8]; // transformation matrices for the 8 patches - static Vector PATCHCNT[8]; + static VECTOR3 PATCHCNT[8]; static double PATCHRAD[8]; }; @@ -182,7 +182,7 @@ class PatchManager6: public PatchManager { private: static bool needsetup; static D3DMATRIX TRANS[24]; // transformation matrices for the 8 patches - static Vector PATCHCNT[24]; + static VECTOR3 PATCHCNT[24]; static double PATCHRAD[24]; }; @@ -196,7 +196,7 @@ class PatchManager7: public PatchManager { private: static bool needsetup; static D3DMATRIX TRANS[100]; // transformation matrices for the 8 patches - static Vector PATCHCNT[100]; + static VECTOR3 PATCHCNT[100]; static double PATCHRAD[100]; }; @@ -211,7 +211,7 @@ class PatchManager8: public PatchManager { private: static bool needsetup; static D3DMATRIX TRANS[364]; // transformation matrices for patches - static Vector PATCHCNT[364]; + static VECTOR3 PATCHCNT[364]; static double PATCHRAD[364]; }; @@ -233,7 +233,7 @@ class HorizonManager { private: const Planet *planet; const VPlanet *vplanet; - Vector basecol; + VECTOR3 basecol; float hralt; // relative horizon altitude float dens0; // atmosphere density factor float hshift; // horizon reference shift factor diff --git a/Src/Orbiter/Star.cpp b/Src/Orbiter/Star.cpp index 5ae0b9af1..3ba0831c6 100644 --- a/Src/Orbiter/Star.cpp +++ b/Src/Orbiter/Star.cpp @@ -66,16 +66,8 @@ void Star::Update (bool force) // of the global coordinate system } -Vector Star::Pos2Barycentre (Vector &pos) -{ - // by definition, the barycentre of stars (root objects) is the origin - return Vector(); -} - -Vector4 Star::GetLightColor () -{ - return {1,1,1,1}; -} +// by definition, the barycentre of stars (root objects) is the origin +VECTOR3 Star::Pos2Barycentre (VECTOR3 &pos) { return VECTOR3{ }; } #ifdef INLINEGRAPHICS void Star::InitDeviceObjects () diff --git a/Src/Orbiter/Star.h b/Src/Orbiter/Star.h index 6f2581ade..d3b833573 100644 --- a/Src/Orbiter/Star.h +++ b/Src/Orbiter/Star.h @@ -30,9 +30,9 @@ class Star: public CelestialBody { void Update (bool force = false); // Perform time step - Vector Pos2Barycentre (Vector &pos); + VECTOR3 Pos2Barycentre (VECTOR3 &pos); - Vector4 GetLightColor(); + auto GetLightColor() { return VECTOR4{1, 1, 1, 1}; } #ifdef INLINEGRAPHICS void InitDeviceObjects (); diff --git a/Src/Orbiter/SuperVessel.cpp b/Src/Orbiter/SuperVessel.cpp index 18a70ca5a..858fc77b0 100644 --- a/Src/Orbiter/SuperVessel.cpp +++ b/Src/Orbiter/SuperVessel.cpp @@ -35,23 +35,23 @@ SuperVessel::SuperVessel (Vessel *vessel) vlist = new SubVesselData[nv = 1]; TRACENEW vlist[0].vessel = vessel; vlist[0].rrot.Set (1,0,0, 0,1,0, 0,0,1); // identity - vlist[0].rpos.Set (0,0,0); - cg.Set (0,0,0); - s0->vel.Set (vessel->GVel()); - rvel_base.Set (s0->vel); - rvel_add.Set (0,0,0); + vlist[0].rpos = {0, 0, 0}; + cg = {0, 0, 0}; + s0->vel = vessel->GVel(); + rvel_base = s0->vel; + rvel_add = {0, 0, 0}; s0->R.Set (vessel->GRot()); s0->Q.Set (vessel->GQ()); bOrbitStabilised = false; cbody = 0; size = vessel->Size(); el = new Elements; TRACENEW - s0->omega.Set (vessel->AngularVelocity()); - s0->pos.Set (vessel->GPos()); - rpos_base.Set (s0->pos); - rpos_add.Set (0,0,0); - rvel_base.Set (s0->vel); - rvel_add.Set (0,0,0); + s0->omega = vessel->AngularVelocity(); + s0->pos = vessel->GPos(); + rpos_base = s0->pos; + rpos_add = {0, 0, 0}; + rvel_base = s0->vel; + rvel_add = {0, 0, 0}; gfielddata.ngrav = 0; updcount = irand (100); acc = g_psys->Gacc (s0->pos, 0, &gfielddata); @@ -84,15 +84,15 @@ SuperVessel::SuperVessel (Vessel *vessel1, Vessel *vessel2, int port1, int port2 vlist[1].vessel = vessel2; // by definition the SuperVessel has the first vessel's position and orientation - vlist[0].rpos.Set (0,0,0); + vlist[0].rpos = {0, 0, 0}; vlist[0].rrot.Set (1,0,0, 0,1,0, 0,0,1); // identity // calculate position and orientation of second vessel relative to first vessel1->RelDockingPos (vessel2, port1, port2, vlist[1].rpos, vlist[1].rrot); - vlist[1].rq.Set (vlist[1].rrot); + vlist[1].rq = vlist[1].rrot; // total mass, centre of gravity and velocity - cg.Set(0,0,0); + cg = {0, 0, 0}; mass = 0.0; for (i = 0; i < 2; i++) { mass += vlist[i].vessel->mass; @@ -109,12 +109,12 @@ SuperVessel::SuperVessel (Vessel *vessel1, Vessel *vessel2, int port1, int port2 // add up linear momentae if (mixmoments) { - s0->vel.Set(0,0,0); + s0->vel = {0, 0, 0}; for (i = 0; i < 2; i++) s0->vel += vlist[i].vessel->s0->vel * vlist[i].vessel->mass; s0->vel /= mass; - } else s0->vel.Set (vlist[0].vessel->s0->vel); - rvel_base.Set (s0->vel); - rvel_add.Set (0,0,0); + } else s0->vel = vlist[0].vessel->s0->vel; + rvel_base = s0->vel; + rvel_add = {0, 0, 0}; // total principal axes of inertia CalcPMI (); @@ -122,24 +122,24 @@ SuperVessel::SuperVessel (Vessel *vessel1, Vessel *vessel2, int port1, int port2 // add up angular momentae if (mixmoments) { // calculate linear and angular velocity from conservation of linear/angular momentum - Vector am; + VECTOR3 am; for (i = 0; i < 2; i++) { // individual spin of each vessel am += mul (vlist[i].rrot, vlist[i].vessel->AngularMomentum()) * vlist[i].vessel->mass; // contribution of vessel motion to angular momentum - am += crossp (tmul (s0->R, vlist[i].vessel->s0->vel - s0->vel), vlist[i].rpos-cg) * vlist[i].vessel->mass; + am += cross(tmul(s0->R, vlist[i].vessel->s0->vel - s0->vel), vlist[i].rpos-cg) * vlist[i].vessel->mass; } - s0->omega.Set (am.x/pmi.x, am.y/pmi.y, am.z/pmi.z); + s0->omega = {am.x / pmi.x, am.y / pmi.y, am.z / pmi.z}; s0->omega /= mass; } else { // set linear/angular velocity directly from reference vessel - s0->omega.Set (vlist[0].vessel->AngularVelocity()); + s0->omega = vlist[0].vessel->AngularVelocity(); } // supervessel position - s0->pos.Set (vessel1->s0->pos + mul (s0->R, cg)); - rpos_base.Set (s0->pos); - rpos_add.Set (0,0,0); + s0->pos = vessel1->s0->pos + mul(s0->R, cg); + rpos_base = s0->pos; + rpos_add = {0, 0, 0}; gfielddata.ngrav = 0; updcount = irand (100); // spread update times @@ -156,8 +156,8 @@ SuperVessel::SuperVessel (Vessel *vessel1, Vessel *vessel2, int port1, int port2 Vessel *v = vlist[i].vessel; v->SetSuperStruct (this); ComponentStateVectors (s0, v->s0, i); - v->rpos_base = v->s0->pos; v->rpos_add.Set (0,0,0); - v->rvel_base = v->s0->vel; v->rvel_add.Set (0,0,0); + v->rpos_base = v->s0->pos; v->rpos_add = {0, 0, 0}; + v->rvel_base = v->s0->vel; v->rvel_add = {0, 0, 0}; if (v->s1) v->s1->Set(*v->s0); v->UpdateSurfParams(); } @@ -226,18 +226,18 @@ void SuperVessel::Detach (Vessel *vessel, DWORD port, double vsep) // give it a separation push double vs = vsep * vessel->mass / mass; // structure velocity double vv = vsep - vs; // vessel velocity - Vector sepdir (mul (vessel->GRot(), vessel->dock[port]->dir)); - Vector rotvel; + VECTOR3 sepdir = mul(vessel->GRot(), vessel->dock[port]->dir); + VECTOR3 rotvel; if (atomic1) { // velocity component from rotation: v = omega x r - rotvel = mul (s0->R, crossp (vlist[idx1].rpos-cg, s0->omega)); + rotvel = mul(s0->R, cross(vlist[idx1].rpos-cg, s0->omega)); vessel->RPlace_individual (mul (s0->R, vlist[idx1].rpos-cg) + s0->pos, s0->vel - sepdir*vv + rotvel); //vessel->acc = g_psys->Gacc (vessel->rpos, vessel, &vessel->gfielddata); vessel->SetSuperStruct (NULL); if (atomic2) { // disband superstructure // velocity component from rotation: v = omega x r - rotvel = mul (s0->R, crossp (vlist[idx2].rpos-cg, s0->omega)); + rotvel = mul(s0->R, cross(vlist[idx2].rpos-cg, s0->omega)); vessel2->RPlace_individual (mul (s0->R, vlist[idx2].rpos-cg) + s0->pos, s0->vel + sepdir*vs + rotvel); //vessel2->acc = g_psys->Gacc (vessel2->rpos, vessel2, &vessel2->gfielddata); vessel2->SetSuperStruct (NULL); @@ -256,7 +256,7 @@ void SuperVessel::Detach (Vessel *vessel, DWORD port, double vsep) } else { if (atomic2) { // velocity componet from rotation: v = omega x r - rotvel = mul (s0->R, crossp (vlist[idx2].rpos-cg, s0->omega)); + rotvel = mul(s0->R, cross(vlist[idx2].rpos-cg, s0->omega)); vessel2->RPlace_individual (mul (s0->R, vlist[idx2].rpos-cg) + s0->pos, s0->vel + sepdir*vs + rotvel); vessel2->SetSuperStruct (NULL); SubVesselData *tmp = new SubVesselData[nv-1]; TRACENEW @@ -268,7 +268,7 @@ void SuperVessel::Detach (Vessel *vessel, DWORD port, double vsep) rvel_add -= sepdir*vv; } else { // split into 2 supervessels - rotvel = mul (s0->R, crossp (vlist[idx2].rpos-cg, s0->omega)); + rotvel = mul(s0->R, cross(vlist[idx2].rpos-cg, s0->omega)); vessel2->RPlace_individual (mul (s0->R, vlist[idx2].rpos-cg) + s0->pos, s0->vel + sepdir*vs + rotvel); SuperVessel *sv2 = new SuperVessel (vessel2); TRACENEW g_psys->AddSuperVessel (sv2); @@ -293,11 +293,11 @@ bool SuperVessel::Activate (bool force) vlist[i].vessel->fstatus = FLIGHTSTATUS_FREEFLIGHT; // none of the following should be necessary vlist[i].vessel->rpos_base = vlist[i].vessel->s0->pos; - vlist[i].vessel->rpos_add.Set (0,0,0); + vlist[i].vessel->rpos_add = {0, 0, 0}; vlist[i].vessel->s0->vel += vlist[i].vessel->rvel_add; vlist[i].vessel->rvel_base = vlist[i].vessel->s0->vel; - vlist[i].vessel->rvel_add.Set (0,0,0); - vlist[i].vessel->s0->omega.Set (0,0,0); + vlist[i].vessel->rvel_add = {0, 0, 0}; + vlist[i].vessel->s0->omega = {0, 0, 0}; } return true; } else @@ -306,10 +306,10 @@ bool SuperVessel::Activate (bool force) // ======================================================================= -void SuperVessel::RPlace (const Vector &_rpos, const Vector &_rvel, const Vessel *ref) +void SuperVessel::RPlace (const VECTOR3 &_rpos, const VECTOR3 &_rvel, const Vessel *ref) { DWORD i; - Vector dp = _rpos-s0->pos; + VECTOR3 dp = _rpos - s0->pos; if (ref) for (i = 0; i < nv; i++) if (vlist[i].vessel == ref) { @@ -317,9 +317,9 @@ void SuperVessel::RPlace (const Vector &_rpos, const Vector &_rvel, const Vessel break; } rpos_base = s0->pos += dp; - rpos_add.Set (0,0,0); + rpos_add = {0, 0, 0}; rvel_base = s0->vel = _rvel; - rvel_add.Set (0,0,0); + rvel_add = {0, 0, 0}; cpos = s0->pos - vlist[0].vessel->cbody->GPos(); cvel = s0->vel - vlist[0].vessel->cbody->GVel(); for (i = 0; i < nv; i++) // update component states @@ -332,7 +332,7 @@ void SuperVessel::RPlace (const Vector &_rpos, const Vector &_rvel, const Vessel // ======================================================================= -void SuperVessel::SetGlobalOrientation (const Vector &arot, const Vessel *ref) +void SuperVessel::SetGlobalOrientation (const VECTOR3 &arot, const Vessel *ref) { DWORD i; double sinx = sin(arot.x), cosx = cos(arot.x); @@ -353,7 +353,7 @@ void SuperVessel::SetGlobalOrientation (const Vector &arot, const Vessel *ref) // update rotation for all sub-vessels for (i = 0; i < nv; i++) { Vessel *v = vlist[i].vessel; - v->s0->pos.Set (mul (s0->R, vlist[i].rpos-cg) + s0->pos); + v->s0->pos = mul(s0->R, vlist[i].rpos-cg) + s0->pos; v->s0->Q.Set (s0->Q); v->s0->Q.postmul (vlist[i].rq); v->s0->R.Set (v->s0->Q); @@ -379,7 +379,7 @@ void SuperVessel::SetRotationMatrix (const Matrix &R, const Vessel *ref) // update rotation for all sub-vessels for (i = 0; i < nv; i++) { Vessel *v = vlist[i].vessel; - v->s0->pos.Set (mul (s0->R, vlist[i].rpos-cg) + s0->pos); + v->s0->pos = mul(s0->R, vlist[i].rpos-cg) + s0->pos; v->s0->R.Set (s0->R); v->s0->R.postmul (vlist[i].rrot); v->s0->Q.Set (v->s0->R); @@ -389,14 +389,14 @@ void SuperVessel::SetRotationMatrix (const Matrix &R, const Vessel *ref) // ======================================================================= -void SuperVessel::SetAngVel (const Vector &omega, const Vessel *ref) +void SuperVessel::SetAngVel (const VECTOR3 &omega, const Vessel *ref) { DWORD i; - s0->omega.Set (omega); + s0->omega = omega; if (ref) { for (i = 0; i < nv; i++) if (vlist[i].vessel == ref) { - s0->omega.Set (mul (vlist[i].rrot, omega)); + s0->omega = mul(vlist[i].rrot, omega); } } @@ -409,12 +409,11 @@ void SuperVessel::SetAngVel (const Vector &omega, const Vessel *ref) // ============================================================== -void SuperVessel::GetIntermediateMoments (Vector &acc, Vector &tau, +void SuperVessel::GetIntermediateMoments (VECTOR3 &acc, VECTOR3 &tau, const StateVectors &state, double tfrac, double dt) { // TODO: Move this up to VesselBase - Vector F(Flin); - Vector M(Amom); + VECTOR3 F = Flin, M = Amom; AddSurfaceForces (&F, &M, &state, tfrac, dt); // add ground contact forces and moments RigidBody::GetIntermediateMoments (acc, tau, state, tfrac, dt); // get gravitational component acc += mul (state.Q, F/mass); @@ -481,12 +480,12 @@ bool SuperVessel::Add (Vessel *vessel1, int port1, Vessel *vessel2, int port2, b // calculate orientation of new vessel relative to superstructure // 1. calc position of 2nd vessel relative to 1st - Vector as(vessel2->dock[port2]->dir); - Vector bs(vessel2->dock[port2]->rot); - Vector cs(crossp(as,bs)); - Vector at(-vessel1->dock[port1]->dir); - Vector bt(vessel1->dock[port1]->rot); - Vector ct(crossp(at,bt)); + VECTOR3 as = vessel2->dock[port2]->dir; + VECTOR3 bs = vessel2->dock[port2]->rot; + VECTOR3 cs = cross(as, bs); + VECTOR3 at = -vessel1->dock[port1]->dir; + VECTOR3 bt = vessel1->dock[port1]->rot; + VECTOR3 ct = cross(at, bt); double den = cs.x * (as.y*bs.z - as.z*bs.y) + cs.y * (as.z*bs.x - as.x*bs.z) + cs.z * (as.x*bs.y - as.y*bs.x); @@ -519,15 +518,15 @@ bool SuperVessel::Add (Vessel *vessel1, int port1, Vessel *vessel2, int port2, b at.z * (bs.x*cs.y - bs.y*cs.x)) / den; // 2. premultipy with vessel1's rotation matrix vlist[nv].rrot.premul (vlist[idx1].rrot); - vlist[nv].rq.Set (vlist[nv].rrot); + vlist[nv].rq = vlist[nv].rrot; // position of vessel2 in superstructure - vlist[nv].rpos.Set (vlist[idx1].rpos + mul (vlist[idx1].rrot, vessel1->dock[port1]->ref) - mul (vlist[nv].rrot, vessel2->dock[port2]->ref)); + vlist[nv].rpos = vlist[idx1].rpos + mul(vlist[idx1].rrot, vessel1->dock[port1]->ref) - mul(vlist[nv].rrot, vessel2->dock[port2]->ref); vessel2->SetSuperStruct (this); // flush the state increments - vessel2->rpos_base = vessel2->s0->pos; vessel2->rpos_add.Set(0,0,0); - vessel2->rvel_base = vessel2->s0->vel; vessel2->rvel_add.Set(0,0,0); + vessel2->rpos_base = vessel2->s0->pos; vessel2->rpos_add = {0, 0, 0}; + vessel2->rvel_base = vessel2->s0->vel; vessel2->rvel_add = {0, 0, 0}; vessel2->s0->Q.Set (s0->Q); vessel2->s0->Q.postmul (vlist[nv].rq); vessel2->s0->R.Set (vessel2->s0->Q); @@ -540,18 +539,18 @@ bool SuperVessel::Add (Vessel *vessel1, int port1, Vessel *vessel2, int port2, b // calculate angular velocity from conservation of angular momentum if (mixmoments) { - Vector am; + VECTOR3 am; for (DWORD i = 0; i < nv; i++) { // individual spin of each vessel am += mul (vlist[i].rrot, vlist[i].vessel->AngularMomentum()) * vlist[i].vessel->mass; // contribution of vessel motion to angular momentum - am += crossp (tmul (s0->R, vlist[i].vessel->GVel()-s0->vel), vlist[i].rpos-cg) * vlist[i].vessel->mass; + am += cross(tmul(s0->R, vlist[i].vessel->GVel()-s0->vel), vlist[i].rpos-cg) * vlist[i].vessel->mass; } - s0->omega.Set (am.x/pmi.x, am.y/pmi.y, am.z/pmi.z); + s0->omega = {am.x / pmi.x, am.y / pmi.y, am.z / pmi.z}; s0->omega /= mass; } - vessel2->s0->omega.Set (tmul (vlist[nv-1].rrot, s0->omega)); + vessel2->s0->omega = tmul(vlist[nv - 1].rrot, s0->omega); vessel2->UpdateSurfParams(); return true; @@ -581,12 +580,12 @@ bool SuperVessel::Merge (Vessel *vessel1, int port1, Vessel *vessel2, int port2) // define the rotation matrix from vessel2 to vessel1 Matrix R; - Vector as(vessel2->dock[port2]->dir); - Vector bs(vessel2->dock[port2]->rot); - Vector cs(crossp(as,bs)); - Vector at(-vessel1->dock[port1]->dir); - Vector bt(vessel1->dock[port1]->rot); - Vector ct(crossp(at,bt)); + VECTOR3 as = vessel2->dock[port2]->dir; + VECTOR3 bs = vessel2->dock[port2]->rot; + VECTOR3 cs = cross(as, bs); + VECTOR3 at = -vessel1->dock[port1]->dir; + VECTOR3 bt = vessel1->dock[port1]->rot; + VECTOR3 ct = cross(at, bt); double den = cs.x * (as.y*bs.z - as.z*bs.y) + cs.y * (as.z*bs.x - as.x*bs.z) + cs.z * (as.x*bs.y - as.y*bs.x); @@ -623,11 +622,11 @@ bool SuperVessel::Merge (Vessel *vessel1, int port1, Vessel *vessel2, int port2) for (i = 0; i < nv2; i++) { vlist[nv+i].vessel = sv2->vlist[i].vessel; - vlist[nv+i].rrot.Set (sv2->vlist[i].rrot); + vlist[nv+i].rrot = sv2->vlist[i].rrot; vlist[nv+i].rrot.premul (R); - vlist[nv+i].rq.Set (vlist[nv+i].rrot); - vlist[nv+i].rpos.Set (vlist[idx1].rpos + mul (vlist[idx1].rrot, vessel1->dock[port1]->ref) + - mul (R, sv2->vlist[i].rpos - sv2->vlist[idx2].rpos - mul (sv2->vlist[idx2].rrot, vessel2->dock[port2]->ref))); + vlist[nv+i].rq = vlist[nv + i].rrot; + vlist[nv+i].rpos = vlist[idx1].rpos + mul(vlist[idx1].rrot, vessel1->dock[port1]->ref) + + mul(R, sv2->vlist[i].rpos - sv2->vlist[idx2].rpos - mul(sv2->vlist[idx2].rrot, vessel2->dock[port2]->ref)); vlist[nv+i].vessel->SetSuperStruct (this); vlist[nv+i].vessel->FlushRPos(); vlist[nv+i].vessel->FlushRVel(); @@ -644,13 +643,13 @@ bool SuperVessel::Merge (Vessel *vessel1, int port1, Vessel *vessel2, int port2) return true; } -bool SuperVessel::AddSurfaceForces (Vector *F, Vector *M, const StateVectors *s, double tfrac, double dt) const +bool SuperVessel::AddSurfaceForces (VECTOR3 *F, VECTOR3 *M, const StateVectors *s, double tfrac, double dt) const { bool impact = false; DWORD comp; StateVectors scomp; for (comp = 0; comp < nv; comp++) { - Vector Fcomp, Mcomp; + VECTOR3 Fcomp, Mcomp; ComponentStateVectors (s, &scomp, comp); if (vlist[comp].vessel->AddSurfaceForces (&Fcomp, &Mcomp, &scomp, tfrac, dt)) { AddComponentForceAndMoment (F, M, &Fcomp, &Mcomp, comp); @@ -673,10 +672,10 @@ void SuperVessel::Update (bool force) vlist[0].vessel->FRecorder_Play(); // update lead vessel from playback stream SetStateFromComponent (vlist[0].vessel->s1, 0); // update supervessel from lead vessel - arot.Set (mul (vlist[0].rrot, vlist[0].vessel->arot)); // is the vessel arot valid here? + arot = mul(vlist[0].rrot, vlist[0].vessel->arot); // is the vessel arot valid here? for (i = 1; i < nv; i++) { // update all others from supervessel ComponentStateVectors (s1, vlist[i].vessel->s1, i); - vlist[i].vessel->arot.Set (tmul (vlist[i].rrot, arot)); + vlist[i].vessel->arot = tmul(vlist[i].rrot, arot); } for (i = 0; i < nv; i++) vlist[i].vessel->el_valid = false; @@ -684,13 +683,13 @@ void SuperVessel::Update (bool force) } else if (fstatus == FLIGHTSTATUS_FREEFLIGHT) { // Collect vessel thrust and atmospheric forces - Flin.Set (0,0,0); - Amom.Set (0,0,0); + Flin = {0, 0, 0}; + Amom = {0, 0, 0}; for (i = 0; i < nv; i++) { Vessel *v = vlist[i].vessel; - Vector vAmom (mul (vlist[i].rrot, v->Amom_add)); - Vector vFlin (mul (vlist[i].rrot, v->Flin_add)); - Amom += vAmom + crossp (vFlin, vlist[i].rpos-cg); + VECTOR3 vAmom = mul(vlist[i].rrot, v->Amom_add); + VECTOR3 vFlin = mul(vlist[i].rrot, v->Flin_add); + Amom += vAmom + cross(vFlin, vlist[i].rpos - cg); Flin += vFlin; } @@ -699,7 +698,7 @@ void SuperVessel::Update (bool force) // update state parameters for all sub-vessels for (i = 0; i < nv; i++) { ComponentStateVectors (s1, vlist[i].vessel->s1, i); - vlist[i].vessel->arot.Set (tmul (vlist[i].rrot, arot)); + vlist[i].vessel->arot = tmul(vlist[i].rrot, arot); vlist[i].vessel->el_valid = false; } @@ -707,8 +706,8 @@ void SuperVessel::Update (bool force) proxyplanet->LocalToGlobal_t1 (sp.ploc, s1->pos); double vground = Pi2 * proxyplanet->Size() * sp.clat / proxyplanet->RotT(); - s1->vel.Set (-vground*sp.slng, 0.0, vground*sp.clng); - s1->vel.Set (mul (proxyplanet->s1->R, s1->vel) + proxyplanet->s1->vel); + s1->vel = {-vground * sp.slng, 0.0, vground * sp.clng}; + s1->vel = mul(proxyplanet->s1->R, s1->vel) + proxyplanet->s1->vel; s1->R.Set (land_rot); s1->R.premul (proxyplanet->s1->R); s1->Q.Set (s1->R); @@ -781,14 +780,14 @@ void SuperVessel::InitLanded (Planet *planet, double lng, double lat, double dir double slng = sin(lng), clng = cos(lng); double slat = sin(lat), clat = cos(lat); Matrix L2H (-slng,0,clng, clat*clng,slat,clat*slng, -slat*clng,clat,-slat*slng); - Vector nml (tmul (*hrot, tmul (L2H, Vector(0,1,0)))); + VECTOR3 nml = tmul(*hrot, tmul(L2H, VECTOR3{0, 1, 0})); sp.SetLanded (lng, lat, cgelev, dir, nml, planet); double vground = Pi2 * /*sp.rad*/planet->Size() * sp.clat / planet->RotT(); - s0->vel.Set (-vground*sp.slng, 0.0, vground*sp.clng); - s0->pos.Set (mul (planet->GRot(), sp.ploc) + planet->GPos()); - s0->vel.Set (mul (planet->GRot(), s0->vel) + planet->GVel()); - land_rot.Set (*hrot); + s0->vel = {-vground * sp.slng, 0.0, vground * sp.clng}; + s0->pos = mul (planet->GRot(), sp.ploc) + planet->GPos(); + s0->vel = mul (planet->GRot(), s0->vel) + planet->GVel(); + land_rot = *hrot; s0->Q.Set (land_rot); s0->Q.premul (planet->GQ()); s0->R.Set (s0->Q); @@ -824,9 +823,9 @@ bool SuperVessel::ThrustEngaged () const void SuperVessel::ComponentStateVectors (const StateVectors *s, StateVectors *scomp, int comp) const { - scomp->vel.Set (s->vel + mul (s->R, crossp (vlist[comp].rpos-cg, s->omega))); - scomp->pos.Set (s->pos + mul (s->R, vlist[comp].rpos-cg)); - scomp->omega.Set (tmul (vlist[comp].rrot, s->omega)); + scomp->vel = s->vel + mul(s->R, cross(vlist[comp].rpos-cg, s->omega)); + scomp->pos = s->pos + mul(s->R, vlist[comp].rpos-cg); + scomp->omega = tmul(vlist[comp].rrot, s->omega); scomp->Q.Set (s->Q * vlist[comp].rq); scomp->R.Set (scomp->Q); } @@ -836,20 +835,20 @@ void SuperVessel::SetStateFromComponent (const StateVectors *scomp, int comp) co s0->R.Set (scomp->R); s0->R.postmul (vlist[comp].rrot); s0->Q.Set (s0->R); - s0->omega.Set (mul (vlist[comp].rrot, scomp->omega)); - s0->vel.Set (scomp->vel - mul (s0->R, crossp (vlist[comp].rpos-cg, s0->omega))); - s0->pos.Set (scomp->pos - mul (s0->R, vlist[comp].rpos-cg)); + s0->omega = mul(vlist[comp].rrot, scomp->omega); + s0->vel = scomp->vel - mul(s0->R, cross(vlist[comp].rpos-cg, s0->omega)); + s0->pos = scomp->pos - mul(s0->R, vlist[comp].rpos-cg); } -void SuperVessel::AddComponentForceAndMoment (Vector *F, Vector *M, - const Vector *Fcomp, const Vector *Mcomp, int comp) const +void SuperVessel::AddComponentForceAndMoment (VECTOR3 *F, VECTOR3 *M, + const VECTOR3 *Fcomp, const VECTOR3 *Mcomp, int comp) const { - Vector Ftrans (mul (vlist[comp].rrot, *Fcomp)); + VECTOR3 Ftrans = mul(vlist[comp].rrot, *Fcomp); *F += Ftrans; - *M += mul (vlist[comp].rrot, *Mcomp) + crossp (Ftrans, vlist[comp].rpos-cg); + *M += mul(vlist[comp].rrot, *Mcomp) + cross(Ftrans, vlist[comp].rpos-cg); } -void SuperVessel::NotifyShiftVesselOrigin (Vessel *vessel, const Vector &dr) +void SuperVessel::NotifyShiftVesselOrigin (Vessel *vessel, const VECTOR3 &dr) { for (DWORD i = 0; i < nv; i++) { if (vlist[i].vessel == vessel) { @@ -859,29 +858,29 @@ void SuperVessel::NotifyShiftVesselOrigin (Vessel *vessel, const Vector &dr) } } -bool SuperVessel::GetCG (const Vessel *vessel, Vector &vcg) +bool SuperVessel::GetCG (const Vessel *vessel, VECTOR3 &vcg) { for (DWORD i = 0; i < nv; i++) { if (vlist[i].vessel == vessel) { - vcg.Set (tmul (vlist[i].rrot, cg-vlist[i].rpos)); + vcg = tmul(vlist[i].rrot, cg - vlist[i].rpos); return true; } } return false; } -bool SuperVessel::GetPMI (const Vessel *vessel, Vector &vpmi) +bool SuperVessel::GetPMI (const Vessel *vessel, VECTOR3 &vpmi) { for (DWORD i = 0; i < nv; i++) { if (vlist[i].vessel == vessel) { - vpmi.Set (0,0,0); - Vector r0[6], rt; + vpmi = {0, 0, 0}; + VECTOR3 r0[6], rt; double rtx2, rty2, rtz2; r0[1].x = -(r0[0].x = 0.5 * sqrt (fabs (-pmi.x + pmi.y + pmi.z))); r0[3].y = -(r0[2].y = 0.5 * sqrt (fabs ( pmi.x - pmi.y + pmi.z))); r0[5].z = -(r0[4].z = 0.5 * sqrt (fabs ( pmi.x + pmi.y - pmi.z))); for (DWORD j = 0; j < 6; j++) { - rt.Set (tmul (vlist[i].rrot, r0[j] + cg - vlist[i].rpos)); + rt = tmul(vlist[i].rrot, r0[j] + cg - vlist[i].rpos); rtx2 = rt.x*rt.x, rty2 = rt.y*rt.y, rtz2 = rt.z*rt.z; vpmi.x += rty2 + rtz2; vpmi.y += rtx2 + rtz2; @@ -903,8 +902,8 @@ void SuperVessel::ResetSize () { size = 0.0; for (DWORD i = 0; i < nv; i++) { - Vector p (vlist[i].rpos - cg); - double r = p.length() + vlist[i].vessel->Size(); + VECTOR3 p = vlist[i].rpos - cg; + double r = len(p) + vlist[i].vessel->Size(); if (r > size) size = r; } } @@ -912,7 +911,7 @@ void SuperVessel::ResetSize () void SuperVessel::ResetMassAndCG () { // centre of gravity and total mass - Vector cg_new; + VECTOR3 cg_new; mass = 0.0; for (DWORD i = 0; i < nv; i++) { mass += vlist[i].vessel->mass; @@ -921,7 +920,7 @@ void SuperVessel::ResetMassAndCG () cg_new /= mass; // shift CG - Vector dp = mul (s0->R, cg_new-cg); + VECTOR3 dp = mul(s0->R, cg_new-cg); s0->pos += dp; rpos_add += dp; cpos += dp; @@ -934,15 +933,15 @@ void SuperVessel::CalcPMI () // values. For details see Doc/Technotes/composite.pdf. DWORD i, j; - Vector r0[6], rt; + VECTOR3 r0[6], rt; double rtx2, rty2, rtz2, vmass; double vpmix, vpmiy, vpmiz; - pmi.Set (0,0,0); + pmi = {0, 0, 0}; for (i = 0; i < nv; i++) { Vessel *v = vlist[i].vessel; - Vector &vpmi = v->pmi; + VECTOR3 &vpmi = v->pmi; vmass = v->mass/6.0; r0[1].x = -(r0[0].x = sqrt (1.5 * fabs (-vpmi.x + vpmi.y + vpmi.z))); r0[3].y = -(r0[2].y = sqrt (1.5 * fabs ( vpmi.x - vpmi.y + vpmi.z))); @@ -950,7 +949,7 @@ void SuperVessel::CalcPMI () vpmix = vpmiy = vpmiz = 0.0; for (j = 0; j < 6; j++) { - rt.Set (mul (vlist[i].rrot, r0[j]) + vlist[i].rpos - cg); + rt = mul(vlist[i].rrot, r0[j]) + vlist[i].rpos - cg; rtx2 = rt.x*rt.x, rty2 = rt.y*rt.y, rtz2 = rt.z*rt.z; vpmix += rty2 + rtz2; vpmiy += rtx2 + rtz2; @@ -981,7 +980,7 @@ TOUCHDOWN_VTX *SuperVessel::HullvtxFirst () TOUCHDOWN_VTX *tdv = vlist[next_hullvessel].vessel->HullvtxFirst(); if (tdv) { hullvtx = *tdv; - hullvtx.pos.Set (mul(vlist[next_hullvessel].rrot, tdv->pos)+vlist[next_hullvessel].rpos-cg); + hullvtx.pos = mul(vlist[next_hullvessel].rrot, tdv->pos) + vlist[next_hullvessel].rpos - cg; return &hullvtx; } else return NULL; @@ -995,7 +994,7 @@ TOUCHDOWN_VTX *SuperVessel::HullvtxNext () tdv = vlist[next_hullvessel].vessel->HullvtxFirst(); if (tdv) { hullvtx = *tdv; - hullvtx.pos.Set (mul(vlist[next_hullvessel].rrot, tdv->pos)+vlist[next_hullvessel].rpos-cg); + hullvtx.pos = mul(vlist[next_hullvessel].rrot, tdv->pos) + vlist[next_hullvessel].rpos - cg; return &hullvtx; } } @@ -1017,7 +1016,7 @@ void SuperVessel::AddGravityGradientTorque (Vector &Torque) double r0 = R0.length(); Vector Re = R0/r0; double mag = 3.0 * Ggrav * cbody->Mass() / pow(r0,3.0); - Vector M = crossp (pmi*Re, Re) * mag; + Vector M = cross(pmi * Re, Re) * mag; // damping of angular velocity double damp = tidaldamp * mag; diff --git a/Src/Orbiter/SuperVessel.h b/Src/Orbiter/SuperVessel.h index 5b7dc5571..f46e9cf77 100644 --- a/Src/Orbiter/SuperVessel.h +++ b/Src/Orbiter/SuperVessel.h @@ -44,7 +44,7 @@ typedef struct { // vessel component specs Vessel *vessel; // vessel pointer - Vector rpos; // rel vessel position in SuperVessel coords + VECTOR3 rpos; // rel vessel position in SuperVessel coords Matrix rrot; // rel vessel orientation: vessel -> supervessel Quaternion rq; // rel vessel orientation in quaternion representation } SubVesselData; @@ -91,11 +91,11 @@ class SuperVessel: public VesselBase { void Detach (Vessel *vessel, DWORD port, double vsep = 0.2); // detach "vessel" from the super-structure - void RPlace (const Vector &_rpos, const Vector &_rvel, const Vessel *ref = 0); + void RPlace (const VECTOR3 &_rpos, const VECTOR3 &_rvel, const Vessel *ref = 0); // Sets the supervessel's position and velocity state vectors in parent coordinates // If ref is set, then rpos refers to that vessel. Otherwise it refers to the supervessel CG. - void SetGlobalOrientation (const Vector &arot, const Vessel *ref = 0); + void SetGlobalOrientation (const VECTOR3 &arot, const Vessel *ref = 0); // Set superstructure orientation from vector of Euler angles // If ref is set, then arot refers to that vessel. @@ -103,7 +103,7 @@ class SuperVessel: public VesselBase { // Set global superstructure rotation matrix to R // If ref is set, then arot refers to that vessel. - void SetAngVel (const Vector &omega, const Vessel *ref = 0); + void SetAngVel (const VECTOR3 &omega, const Vessel *ref = 0); // Set angular velocity components to omega [rad/s] // If ref is set, then avel refers to that vessel. @@ -114,7 +114,7 @@ class SuperVessel: public VesselBase { void Refuel (); // Re-fill all tank in all components - void GetIntermediateMoments (Vector &acc, Vector &tau, + void GetIntermediateMoments (VECTOR3 &acc, VECTOR3 &tau, const StateVectors &state, double tfrac, double dt); // Returns acceleration acc and torque tau, at time SimT0+tfrac*SimDT // and step size dt, given intermediate state in global frame @@ -124,17 +124,17 @@ class SuperVessel: public VesselBase { void PostUpdate (); - bool AddSurfaceForces (Vector *F, Vector *M, + bool AddSurfaceForces (VECTOR3 *F, VECTOR3 *M, const StateVectors *s = NULL, double tfrac = 1.0, double dt = 0.0) const; - void NotifyShiftVesselOrigin (Vessel *vessel, const Vector &dr); + void NotifyShiftVesselOrigin (Vessel *vessel, const VECTOR3 &dr); // sent by a vessel to notify a shift of its local coordinate origin (i.e. its centre of mass) - bool GetCG (const Vessel *vessel, Vector &vcg); + bool GetCG (const Vessel *vessel, VECTOR3 &vcg); // Sets 'vcg' to centre of gravity of super-structure in coordinates of 'vessel', if vessel is // part of the super-structure. Otherwise returns false - bool GetPMI (const Vessel *vessel, Vector &vpmi); + bool GetPMI (const Vessel *vessel, VECTOR3 &vpmi); // Returns PMI values of supervessel in 'vpmi' rotated into coordinate frame of // vessel 'vessel' @@ -195,8 +195,8 @@ class SuperVessel: public VesselBase { // Returns state vectors scomp for component vessel comp, given supervessel // state vectors s - void AddComponentForceAndMoment (Vector *F, Vector *M, - const Vector *Fcomp, const Vector *Mcomp, int comp) const; + void AddComponentForceAndMoment (VECTOR3 *F, VECTOR3 *M, + const VECTOR3 *Fcomp, const VECTOR3 *Mcomp, int comp) const; // Adds component force Fcomp and moment Mcomp from component vessel 'comp' to the // supervessel force F and moment M @@ -205,11 +205,11 @@ class SuperVessel: public VesselBase { DWORD nv; // length of vlist; // *** global data *** - Vector cg; // centre of gravity in supervessel coords + VECTOR3 cg; // centre of gravity in supervessel coords // Note: The supervessel origin is the origin of the first vessel in the // list, not the CG of the composite structure. - Vector Flin, Amom; + VECTOR3 Flin, Amom; // linear, angular forces on structure other than gravitational; // collected from vessel components diff --git a/Src/Orbiter/TileMgr.cpp b/Src/Orbiter/TileMgr.cpp index 4e49d7e5e..73ed9bd41 100644 --- a/Src/Orbiter/TileMgr.cpp +++ b/Src/Orbiter/TileMgr.cpp @@ -73,7 +73,7 @@ TileManager::TileManager (const Planet *_cbody) maxlvl = min (maxlvl, (DWORD)SURF_MAX_PATCHLEVEL); maxbaselvl = min ((DWORD)8, maxlvl); int maxidx = patchidx[maxbaselvl]; - pcdir.Set (1,0,0); + pcdir = {1, 0, 0}; bRipple = (g_pOrbiter->Cfg()->CfgVisualPrm.bSpecularRipple && cbody->bWaterMicrotex); bPreloadTile = (g_pOrbiter->Cfg()->CfgPRenderPrm.PreloadMode > 0); lightfac = g_pOrbiter->Cfg()->CfgVisualPrm.LightBrightness; @@ -496,16 +496,16 @@ void TileManager::Render (LPDIRECT3DDEVICE7 dev, D3DMATRIX &wmat, double scale, VMAT_copy (RenderParam.wmat_tmp, wmat); RenderParam.grot = cbody->GRot() * scale; RenderParam.cpos = vbody->CPos() * scale; - RenderParam.cdir.Set (tmul (cbody->GRot(), g_camera->GPos()-cbody->GPos())); - RenderParam.cdist = RenderParam.cdir.length()/cbody->Size(); - RenderParam.cdir.unify(); - RenderParam.sdir.Set (tmul (cbody->GRot(), -cbody->GPos())); - RenderParam.sdir.unify(); + RenderParam.cdir = tmul(cbody->GRot(), g_camera->GPos()-cbody->GPos()); + RenderParam.cdist = len(RenderParam.cdir) / cbody->Size(); + RenderParam.cdir = unit(RenderParam.cdir); + RenderParam.sdir = tmul(cbody->GRot(), -cbody->GPos()); + RenderParam.sdir = unit(RenderParam.sdir); RenderParam.viewap = acos (1.0/(max (RenderParam.cdist, 1.0))); RenderParam.fog = addfog; // limit resolution for fast camera movements - double limitstep, cstep = acos (dotp (RenderParam.cdir, pcdir)); + double limitstep, cstep = std::acos(dot(RenderParam.cdir, pcdir)); int maxlevel = SURF_MAX_PATCHLEVEL; static double limitstep0 = 5.12 * pow(2.0, -(double)SURF_MAX_PATCHLEVEL); for (limitstep = limitstep0; cstep > limitstep && maxlevel > 5; limitstep *= 2.0) @@ -579,7 +579,7 @@ void TileManager::Render (LPDIRECT3DDEVICE7 dev, D3DMATRIX &wmat, double scale, dev->SetTextureStageState (1, D3DTSS_COLORARG2, D3DTA_CURRENT); } - pcdir.Set (RenderParam.cdir); // store camera direction + pcdir = RenderParam.cdir; // store camera direction // temporary //if (!strcmp (cbody->Name(), "Earth")) @@ -594,9 +594,9 @@ void TileManager::ProcessTile (int lvl, int hemisp, int ilat, int nlat, int ilng { // Check if patch is visible from camera position static const double rad0 = sqrt(2.0)*Pi05*0.5; - Vector cnt = TileCentre (hemisp, ilat, nlat, ilng, nlng); + VECTOR3 cnt = TileCentre(hemisp, ilat, nlat, ilng, nlng); double rad = rad0/(double)nlat; - double alpha = acos (dotp (RenderParam.cdir, cnt)); // angle between tile centre and camera from planet centre + double alpha = std::acos(dot(RenderParam.cdir, cnt)); // angle between tile centre and camera from planet centre double adist = alpha - rad; // angle between closest tile corner and camera if (adist >= RenderParam.viewap) { tilebuf->DeleteSubTiles (tile); // remove tile descriptions below @@ -680,7 +680,7 @@ void TileManager::ProcessTile (int lvl, int hemisp, int ilat, int nlat, int ilng } } else { // actually render the tile at this level - double sdist = acos (dotp (RenderParam.sdir, cnt)); + double sdist = std::acos(dot(RenderParam.sdir, cnt)); if (bCoarseTex) { if (sdist > Pi05+rad && bkp_flag & 2) bkp_flag &= 0xFD, bkp_flag |= 1; // supress specular reflection on dark side RenderTile (lvl, hemisp, ilat, nlat, ilng, nlng, sdist, tile, bkp_range, bkp_tex, bkp_ltex, bkp_flag); @@ -899,12 +899,12 @@ void TileManager::RenderSimple (int level, TILEDESC *tile) // returns the direction of the tile centre from the planet centre in local // planet coordinates -Vector TileManager::TileCentre (int hemisp, int ilat, int nlat, int ilng, int nlng) +VECTOR3 TileManager::TileCentre (int hemisp, int ilat, int nlat, int ilng, int nlng) { double cntlat = Pi05 * ((double)ilat+0.5)/(double)nlat, slat = sin(cntlat), clat = cos(cntlat); double cntlng = Pi2 * ((double)ilng+0.5)/(double)nlng + Pi, slng = sin(cntlng), clng = cos(cntlng); - if (hemisp) return Vector (clat*clng, -slat, -clat*slng); - else return Vector (clat*clng, slat, clat*slng); + return hemisp ? VECTOR3{clat * clng, -slat, -clat * slng} + : VECTOR3{clat * clng, slat, clat * slng}; } // ======================================================================= @@ -986,7 +986,7 @@ bool TileManager::SpecularColour (D3DCOLORVALUE *col) const ATMCONST *ap = cbody->AtmParams(); if (ap) { double fac = 0.7; // adjust! - double cosa = dotp (RenderParam.cdir, RenderParam.sdir); + double cosa = dot(RenderParam.cdir, RenderParam.sdir); double alpha = 0.5*acos(cosa); // sun reflection angle double scale = sin(alpha)*fac; diff --git a/Src/Orbiter/TileMgr.h b/Src/Orbiter/TileMgr.h index a64c94f6b..618284ee0 100644 --- a/Src/Orbiter/TileMgr.h +++ b/Src/Orbiter/TileMgr.h @@ -151,7 +151,7 @@ class TileManager { void RenderSimple (int lvl, TILEDESC *tile); // Render a full sphere (used for low resolutions) - Vector TileCentre (int hemisp, int ilat, int nlat, int ilng, int nlng); + VECTOR3 TileCentre (int hemisp, int ilat, int nlat, int ilng, int nlng); // returns the direction of the tile centre from the planet centre in local // planet coordinates @@ -183,7 +183,7 @@ class TileManager { bool bRipple; // render ripples in specular reflection bool bPreloadTile; // preload high-resolution tile textures double lightfac; // city light intensity factor - Vector pcdir; // previous camera direction + VECTOR3 pcdir; // previous camera direction // object-independent configuration parameters static bool bSpecular; // surface contains areas with specular reflection @@ -197,11 +197,11 @@ class TileManager { D3DMATRIX wmat; // world matrix D3DMATRIX wmat_tmp; // copy of world matrix used as work buffer Matrix grot; // planet rotation matrix - Vector cpos; // planet offset vector (in global frame) + VECTOR3 cpos; // planet offset vector (in global frame) VPlanet *vbody; // pointer to visual int tgtlvl; // target resolution level - Vector sdir; // sun direction from planet centre (in planet frame) - Vector cdir; // camera direction from planet centre (in planet frame) + VECTOR3 sdir; // sun direction from planet centre (in planet frame) + VECTOR3 cdir; // camera direction from planet centre (in planet frame) double cdist; // camera distance from planet centre (in units of planet radii) double viewap; // aperture of surface cap visible from camera pos bool fog; // distance fog active? diff --git a/Src/Orbiter/Util.h b/Src/Orbiter/Util.h index 3cd4ae2c5..4b80275f1 100644 --- a/Src/Orbiter/Util.h +++ b/Src/Orbiter/Util.h @@ -31,31 +31,10 @@ bool MakePath (const char *fname); // case-insensitive comparison of std::strings bool iequal(const std::string& s1, const std::string& s2); -// conversion between Vector and VECTOR3 structures - -inline Vector MakeVector (const VECTOR3 &v) -{ return Vector(v.x, v.y, v.z); } - -inline VECTOR3 MakeVECTOR3 (const Vector &v) -{ return _V(v.x, v.y, v.z); } - -inline VECTOR4 MakeVECTOR4 (const Vector &v) +inline VECTOR4 MakeVECTOR4(const VECTOR3 &v) { return _V(v.x, v.y, v.z, 1.0); } -inline void CopyVector (const VECTOR3 &v3, Vector &v) -{ v.x = v3.x, v.y = v3.y, v.z = v3.z; } - -inline void CopyVector (const Vector &v, VECTOR3 &v3) -{ v3.x = v.x, v3.y = v.y, v3.z = v.z; } - -inline void EulerAngles (const Matrix &R, Vector &e) -{ - e.x = atan2 (R.m23, R.m33); - e.y = -asin (R.m13); - e.z = atan2 (R.m12, R.m11); -} - -inline void EulerAngles (const Matrix &R, VECTOR3 &e) +inline void EulerAngles(const Matrix &R, VECTOR3 &e) { e.x = atan2 (R.m23, R.m33); e.y = -asin (R.m13); diff --git a/Src/Orbiter/VBase.cpp b/Src/Orbiter/VBase.cpp index 8dceeb251..662ae860c 100644 --- a/Src/Orbiter/VBase.cpp +++ b/Src/Orbiter/VBase.cpp @@ -298,7 +298,7 @@ void VBase::Update (bool moving, bool force) if (sundir.y != csun) { csun = sundir.y; // cosine of sun over horizon if (have_shadows = (enable_shadows && csun > 0.07)) { - Vector shdir = sundir/(-csun); + VECTOR3 shdir = sundir / -csun; double az = atan2 (shdir.z, shdir.x); for (DWORD i = 0; i < base->nobj; i++) base->obj[i]->UpdateShadow (shdir, az); @@ -477,24 +477,24 @@ void VBase::RenderShadows (LPDIRECT3DDEVICE7 dev) if (nshmesh) { double d, nr0; const Planet *planet = base->RefPlanet(); - Vector pp = planet->GPos(); // planet global pos - Vector sd = base->GPos(); // base global pos - Vector pvr = sd-pp; // planet-relative base position - d = pvr.length(); // planet radius at base location - sd.unify(); // shadow projection direction + VECTOR3 pp = planet->GPos(); // planet global pos + VECTOR3 sd = base->GPos(); // base global pos + VECTOR3 pvr = sd - pp; // planet-relative base position + d = len(pvr); // planet radius at base location + sd = unit(sd); // shadow projection direction - //double fac1 = dotp (sd, pvr); + //double fac1 = dot(sd, pvr); //if (fac1 > 0.0) // base is on planet night-side // return; Matrix vR = base->GRot(); - Vector sdv = tmul (vR, sd); // projection direction in base frame - Vector hnp = pvr.unit(); - Vector hn = tmul (vR, hnp); // horizon normal in vessel frame + VECTOR3 sdv = tmul(vR, sd); // projection direction in base frame + VECTOR3 hnp = unit(pvr); + VECTOR3 hn = tmul(vR, hnp); // horizon normal in vessel frame // perform projections - double nd = dotp (hn, sdv); - Vector sdvs = sdv / nd; + double nd = dot(hn, sdv); + VECTOR3 sdvs = sdv / nd; if (!sdvs.y) return; // required for plane offset correction DWORD i; @@ -649,13 +649,13 @@ void VBase::RenderGroundShadow (LPDIRECT3DDEVICE7 dev) static const double shadow_elev_limit = 0.07; double d, csun, nr0; const Planet *planet = base->RefPlanet(); - Vector pp = planet->GPos(); // planet global pos - Vector sd = base->GPos(); // base global pos - Vector pvr = sd-pp; // planet-relative base position - d = pvr.length(); // planet radius at base location - sd.unify(); // shadow projection direction + VECTOR3 pp = planet->GPos(); // planet global pos + VECTOR3 sd = base->GPos(); // base global pos + VECTOR3 pvr = sd - pp; // planet-relative base position + d = len(pvr); // planet radius at base location + sd = unit(sd); // shadow projection direction - double fac1 = dotp (sd, pvr); + double fac1 = dot(sd, pvr); if (fac1 > 0.0) // base is on planet night-side return; csun = -fac1/d; // sun elevation above horizon @@ -663,13 +663,13 @@ void VBase::RenderGroundShadow (LPDIRECT3DDEVICE7 dev) return; Matrix vR = base->GRot(); - Vector sdv = tmul (vR, sd); // projection direction in base frame - Vector hnp = pvr.unit(); - Vector hn = tmul (vR, hnp); // horizon normal in vessel frame + VECTOR3 sdv = tmul(vR, sd); // projection direction in base frame + VECTOR3 hnp = unit(pvr); + VECTOR3 hn = tmul(vR, hnp); // horizon normal in vessel frame // perform projections - double nd = dotp (hn, sdv); - Vector sdvs = sdv / nd; + double nd = dot(hn, sdv); + VECTOR3 sdvs = sdv / nd; if (!sdvs.y) return; // required for plane offset correction DWORD i; @@ -727,19 +727,19 @@ bool VBase::ModLighting (LPD3DLIGHT7 light) { const CelestialBody *cb = base->RefPlanet(); Star *sun = g_psys->GetStar(0); // should really loop over all suns - Vector S(sun->GPos() - base->GPos()); - double s = S.length(); + VECTOR3 S = sun->GPos() - base->GPos(); + double s = len(S); double as = asin (sun->Size()/s); // apparent size of sun disc [rad] - Vector lcol (1,1,1); + VECTOR3 lcol{1, 1, 1}; double amb = 0; bool lightmod = false; int j; // calculate shadowing by planet - Vector P(cb->GPos() - base->GPos()); - double p = P.length(); - double phi = acos (dotp(S,P)/(s*p)); // angular distance between sun and planet + VECTOR3 P = cb->GPos() - base->GPos(); + double p = len(P); + double phi = std::acos(dot(S, P) / (s * p)); // angular distance between sun and planet static const double ap = PI05; // apparent size of planet disc [rad] if (cb->Type() == OBJTP_PLANET && ((Planet*)cb)->HasAtmosphere()) { // case 1: planet has atmosphere @@ -752,9 +752,9 @@ bool VBase::ModLighting (LPD3DLIGHT7 light) if (as+ap1 >= phi) { // overlap double dap = ap1-ap; - Vector plight(1,1,1); + VECTOR3 plight{1, 1, 1}; if (phi < ap-as) { // totality (sun below horizon) - plight.Set(0,0,0); + plight = {0, 0, 0}; } else { double dispersion = max (0.02, min (0.9, log (atm->rho0+1.0))); double r0 = 1.0-0.40*dispersion; diff --git a/Src/Orbiter/VBase.h b/Src/Orbiter/VBase.h index 6470175ea..83a4d3e92 100644 --- a/Src/Orbiter/VBase.h +++ b/Src/Orbiter/VBase.h @@ -32,7 +32,7 @@ class VBase: public VObject { void RenderStructures (LPDIRECT3DDEVICE7 dev); void RenderGroundShadow (LPDIRECT3DDEVICE7 dev); const Base *GetBase() const { return base; } - Vector SunDir () const { return sundir; } + auto SunDir() const { return sundir; } double csun; // cosine of sun's zenith distance @@ -77,7 +77,7 @@ class VBase: public VObject { bool lights; double CheckLightT; // time for next lighting check double BlinkT; // counter for blinking landing lights - Vector sundir; // direction of sun in local coords + VECTOR3 sundir; // direction of sun in local coords bool enable_shadows; // true if shadow rendering is enabled bool have_shadows; // true if object shadows should be drawn bool surftile_alpha; // surface tiles support alpha blending? diff --git a/Src/Orbiter/VCockpit.cpp b/Src/Orbiter/VCockpit.cpp index c6fe3b49a..63031845f 100644 --- a/Src/Orbiter/VCockpit.cpp +++ b/Src/Orbiter/VCockpit.cpp @@ -53,7 +53,7 @@ void VirtualCockpit::SetConnections (int left, int right, int top, int bottom) connect[3] = bottom; } -void VirtualCockpit::Shift (const Vector &shift) +void VirtualCockpit::Shift (const VECTOR3 &shift) { ShiftHUDPos (shift); ShiftAreas (shift); @@ -218,7 +218,7 @@ void VirtualCockpit::ReleaseAreas () narea = nareabuf = 0; } -void VirtualCockpit::ShiftAreas (const Vector &shift) +void VirtualCockpit::ShiftAreas (const VECTOR3 &shift) { for (int i = 0; i < narea; i++) { switch (area[i]->cmode) { @@ -252,13 +252,9 @@ void VirtualCockpit::DestroyHUDSurface () } } -void VirtualCockpit::ShiftHUDPos (const Vector &shift) +void VirtualCockpit::ShiftHUDPos (const VECTOR3 &shift) { - if (hud.surf) { - hud.spec.hudcnt.x += (float)shift.x; - hud.spec.hudcnt.y += (float)shift.y; - hud.spec.hudcnt.z += (float)shift.z; - } + if (hud.surf) hud.spec.hudcnt += shift; } void VirtualCockpit::ClearHUD () @@ -290,25 +286,25 @@ void VirtualCockpit::SetHUDCol (COLORREF col, double intens) #endif } -bool VirtualCockpit::SetClickZone_Spherical (int i, const Vector &cnt, double rad) +bool VirtualCockpit::SetClickZone_Spherical (int i, const VECTOR3 &cnt, double rad) { - area[i]->cnt.Set (cnt); + area[i]->cnt = cnt; area[i]->rad = rad; area[i]->cmode = Area::CMODE_SPHERICAL; return true; } bool VirtualCockpit::SetClickZone_Quadrilateral (int i, - const Vector &p1, const Vector &p2, const Vector &p3, const Vector &p4) + const VECTOR3 &p1, const VECTOR3 &p2, const VECTOR3 &p3, const VECTOR3 &p4) { const double EPS = 1e-8; int j; // save corner points - area[i]->p[0].Set (p1); - area[i]->p[1].Set (p2); - area[i]->p[2].Set (p3); - area[i]->p[3].Set (p4); + area[i]->p[0] = p1; + area[i]->p[1] = p2; + area[i]->p[2] = p3; + area[i]->p[3] = p4; // global coefficients of equation of the plane: ax+by+cz+d = 0 double a, b, c, d; @@ -320,8 +316,8 @@ bool VirtualCockpit::SetClickZone_Quadrilateral (int i, double pdst = fabs(PointPlaneDist(p4, a, b, c, d)); if (pdst < EPS) { // the 4 points are coplanar, so we need to avoid singularity - Vector nml(PlaneNormal(a, b, c, d)); - area[i]->p[3].Set(p4 + nml * EPS); + VECTOR3 nml = PlaneNormal(a, b, c, d); + area[i]->p[3] = p4 + nml * EPS; } // calculate coefficients for mapping global quadrilateral to local square (0,1)x(0,1) @@ -333,14 +329,14 @@ bool VirtualCockpit::SetClickZone_Quadrilateral (int i, area[i]->p[3].x, area[i]->p[3].y, area[i]->p[3].z, 1 ); Matrix4 P2(P1); - Vector4 cc, dd, r; - Vector4 u(0,1,0,1), v(0,0,1,1); + VECTOR4 cc{ }, dd{ }; + VECTOR4 u{0, 1, 0, 1}, v{0, 0, 1, 1}; qrdcmp (P1, cc, dd); qrsolv (P1, cc, dd, u); - for (j = 0; j < 4; j++) area[i]->u[j] = (float)u(j); + for (j = 0; j < 4; j++) area[i]->u[j] = (float)u[j]; qrdcmp (P2, cc, dd); qrsolv (P2, cc, dd, v); - for (j = 0; j < 4; j++) area[i]->v[j] = (float)v(j); + for (j = 0; j < 4; j++) area[i]->v[j] = (float)v[j]; area[i]->cmode = Area::CMODE_QUAD; return true; @@ -367,12 +363,12 @@ bool VirtualCockpit::ProcessMouse (UINT event, DWORD state, int x, int y) idx_mfocus = -1; // convert mouse position into vessel-local ray - Vector gdir, ldir; + VECTOR3 gdir, ldir; g_camera->ViewportToGlobalDir (x, y, gdir); ldir = tmul (g_focusobj->GRot(), gdir); // vessel-local camera position - Vector cpos (tmul (g_focusobj->GRot(), *g_camera->GPosPtr() - g_focusobj->GPos())); + VECTOR3 cpos = tmul(g_focusobj->GRot(), *g_camera->GPosPtr() - g_focusobj->GPos()); int i, imatch; double minreldist, mx = 0, my = 0; @@ -380,7 +376,7 @@ bool VirtualCockpit::ProcessMouse (UINT event, DWORD state, int x, int y) switch (area[i]->cmode) { case Area::CMODE_SPHERICAL: { - if (dotp(ldir, area[i]->cnt-cpos) > 0.0) { // otherwise target is behind camera + if (dot(ldir, area[i]->cnt-cpos) > 0.0) { // otherwise target is behind camera double d = PointLineDist (area[i]->cnt, cpos, ldir); if (d < area[i]->rad) { if (d/area[i]->rad < minreldist) { @@ -392,9 +388,9 @@ bool VirtualCockpit::ProcessMouse (UINT event, DWORD state, int x, int y) } } break; case Area::CMODE_QUAD: { - Vector r; + VECTOR3 r; if (LinePlaneIntersect (area[i]->a, area[i]->b, area[i]->c, area[i]->d, cpos, ldir, r)) { - if (dotp(ldir, r-cpos) > 0.0) { // otherwise target is behind camera + if (dot(ldir, r-cpos) > 0.0) { // otherwise target is behind camera mx = area[i]->u[0]*r.x + area[i]->u[1]*r.y + area[i]->u[2]*r.z + area[i]->u[3]; my = area[i]->v[0]*r.x + area[i]->v[1]*r.y + area[i]->v[2]*r.z + area[i]->v[3]; if (mx >= 0 && mx <= 1 && my >= 0 && my <= 1) { @@ -424,7 +420,7 @@ bool VirtualCockpit::ProcessMouse (UINT event, DWORD state, int x, int y) } } -void VirtualCockpit::GetMouseState (int &idx, int &state, Vector &xs) const +void VirtualCockpit::GetMouseState (int &idx, int &state, VECTOR3 &xs) const { if (mstate & PANEL_MOUSE_PRESSED) { POINT pt; @@ -433,12 +429,12 @@ void VirtualCockpit::GetMouseState (int &idx, int &state, Vector &xs) const ScreenToClient (cwnd, &pt); // calculate ray intersection with current focus area - Vector gdir, ldir; + VECTOR3 gdir, ldir; g_camera->ViewportToGlobalDir (pt.x, pt.y, gdir); ldir = tmul (g_focusobj->GRot(), gdir); // vessel-local camera position - Vector cpos (tmul (g_focusobj->GRot(), *g_camera->GPosPtr() - g_focusobj->GPos())); + VECTOR3 cpos = tmul(g_focusobj->GRot(), *g_camera->GPosPtr() - g_focusobj->GPos()); switch (area[idx_mfocus]->cmode) { case Area::CMODE_SPHERICAL: { @@ -448,7 +444,7 @@ void VirtualCockpit::GetMouseState (int &idx, int &state, Vector &xs) const mouse_r.y = mouse_r.z = 0.0; } break; case Area::CMODE_QUAD: { - Vector r; + VECTOR3 r; LinePlaneIntersect (area[idx_mfocus]->a, area[idx_mfocus]->b, area[idx_mfocus]->c, area[idx_mfocus]->d, cpos, ldir, r); mouse_r.x = area[idx_mfocus]->u[0]*r.x + area[idx_mfocus]->u[1]*r.y + area[idx_mfocus]->u[2]*r.z + area[idx_mfocus]->u[3]; mouse_r.y = area[idx_mfocus]->v[0]*r.x + area[idx_mfocus]->v[1]*r.y + area[idx_mfocus]->v[2]*r.z + area[idx_mfocus]->v[3]; diff --git a/Src/Orbiter/VCockpit.h b/Src/Orbiter/VCockpit.h index 8c70eea4a..558fd2244 100644 --- a/Src/Orbiter/VCockpit.h +++ b/Src/Orbiter/VCockpit.h @@ -28,7 +28,7 @@ class VirtualCockpit { inline int Connect (int dir) const { return connect[dir]; } // return connected panel id for specified direction - void Shift (const Vector &shift); + void Shift (const VECTOR3 &shift); // shift the HUD position and active areas by vector 'shift' void DefineArea (int aid, const RECT &texrect, int draw_mode, int mouse_mode, int bkmode, SURFHANDLE tgt); @@ -43,7 +43,7 @@ class VirtualCockpit { void RedrawArea (int idx, int event); void RedrawAllAreas (int event); void ReleaseAreas (); - void ShiftAreas (const Vector &shift); + void ShiftAreas (const VECTOR3 &shift); SURFHANDLE CreateHUDSurface (const VCHUDSPEC *spec, COLORREF col = 0x00ff00, double intens = 1.0); // create a surface for the VC HUD (returns surface handle) @@ -53,18 +53,18 @@ class VirtualCockpit { void ClearHUD (); void SetHUDCol (COLORREF col = 0, double intens = 0.0); - void ShiftHUDPos (const Vector &shift); + void ShiftHUDPos (const VECTOR3 &shift); inline const SURFHANDLE GetHUDSurf () const { return hud.surf; } inline const VCHUDSPEC *GetHUDParams () const { return &hud.spec; /*return (hud.surf ? &hud.spec : NULL);*/ } void RedrawHUD (); - bool SetClickZone_Spherical (int i, const Vector &cnt, double rad); - bool SetClickZone_Quadrilateral (int i, const Vector &p1, const Vector &p2, const Vector &p3, const Vector &p4); + bool SetClickZone_Spherical (int i, const VECTOR3 &cnt, double rad); + bool SetClickZone_Quadrilateral (int i, const VECTOR3 &p1, const VECTOR3 &p2, const VECTOR3 &p3, const VECTOR3 &p4); bool ProcessMouse (UINT event, DWORD state, int x, int y); - void GetMouseState (int &idx, int &state, Vector &xs) const; + void GetMouseState (int &idx, int &state, VECTOR3 &xs) const; inline void SetMouseState (int state) { mstate = state; } static bool Read (std::ifstream &ifs); @@ -91,7 +91,7 @@ class VirtualCockpit { int connect[4]; // connected panels (left,right,up,down) -1=none int idx_mfocus; // index of area currently receiving mouse focus int mstate; // current mouse state - mutable Vector mouse_r; // mouse position coefficients (area-type dependent) + mutable VECTOR3 mouse_r; // mouse position coefficients (area-type dependent) HWND cwnd; // window handle for mouse position offset calculations struct { // HUD parameters @@ -102,7 +102,7 @@ class VirtualCockpit { } hud; struct Area { - Area() {} + Area() { } int id; // area identifier RECT texrect; // area rectangle in texture int w, h; // width, height of texture area @@ -115,11 +115,11 @@ class VirtualCockpit { enum ClickMode { CMODE_NONE, CMODE_SPHERICAL, CMODE_QUAD } cmode; union { struct { - Vector cnt; // centre of click area in local vessel coords + VECTOR3 cnt; // centre of click area in local vessel coords double rad; // radius of click area }; struct { - Vector p[4]; // corner points + VECTOR3 p[4]; // corner points float a, b, c, d; // coeffs for equation of plane: ax+by+cz+d = 0 float u[4], v[4]; // coefficients for transforming to local quad frame }; diff --git a/Src/Orbiter/VPlanet.cpp b/Src/Orbiter/VPlanet.cpp index 4fae80542..40d99d8da 100644 --- a/Src/Orbiter/VPlanet.cpp +++ b/Src/Orbiter/VPlanet.cpp @@ -369,7 +369,7 @@ void VPlanet::Render (LPDIRECT3DDEVICE7 dev) if (fogfactor < 0.0) prm.bFog = false; else { // day/nighttime fog lighting - double cosa = dotp (planet->GPos().unit(), (planet->GPos() - g_camera->GPos()).unit()); + double cosa = dot(unit(planet->GPos()), unit(planet->GPos() - g_camera->GPos())); double bright = 1.0 * max (0.0, min (1.0, cosa + 0.3)); float rfog = (float)(bright*(min(1.0,fogcol.x)+0.0)); // "whiten" the fog colour float gfog = (float)(bright*(min(1.0,fogcol.y)+0.0)); @@ -641,8 +641,8 @@ void VPlanet::RenderRing (LPDIRECT3DDEVICE7 dev, bool addbkg) { DWORD amb = g_pOrbiter->Cfg()->AmbientColour; DWORD bpp = g_pOrbiter->ViewBPP(); - Vector ppos (tmul (planet->GRot(), -cpos)); // camera pos in planet coords - Vector spos (tmul (planet->GRot(), -planet->GPos())); // sun pos in planet coords + VECTOR3 ppos = tmul(planet->GRot(), -cpos); // camera pos in planet coords + VECTOR3 spos = tmul(planet->GRot(), -planet->GPos()); // sun pos in planet coords bool islit = (ppos.y*spos.y >= 0.0); // we are facing the lit side of the rings static D3DMATRIX imat, *ringmat; if (ppos.y >= 0) { // camera above equator @@ -703,7 +703,7 @@ int VPlanet::ShadowPlanetOnRing (VERTEX_XYZC *&vtx, DWORD &nvtx) double r1 = planet->ringmax; // outer rim radius // sun in planet local coords - Vector spos (tmul (planet->R_ecl, -planet->GPos())); + VECTOR3 spos = tmul(planet->R_ecl, -planet->GPos()); bool flip = (spos.y < 0.0); // is underside of rings lit? // semi-minor axis of shadow ellipse (= planet radius) @@ -711,7 +711,7 @@ int VPlanet::ShadowPlanetOnRing (VERTEX_XYZC *&vtx, DWORD &nvtx) double b2 = b*b; // square of semi-major axis of shadow ellipse - double a2 = b2*spos.length2()/(spos.y*spos.y); + double a2 = b2 * len_2(spos) / (spos.y * spos.y); double a = sqrt (a2); // intersection of shadow with inner rim @@ -791,7 +791,7 @@ bool VPlanet::ModLighting (DWORD &ambient) if (!planet->HasAtmosphere()) return false; if (cdist >= planet->Size()+prm.atm_href) return false; - double alpha = acos (dotp (g_camera->GPos().unit(), (g_camera->GPos()-planet->GPos()).unit())); + double alpha = std::acos(dot(unit(g_camera->GPos()), unit(g_camera->GPos() - planet->GPos()))); // angular distance between sun and planet as seen from camera double sunelev = alpha - PI05; // elevation of sun above horizon (assuming camera on ground) diff --git a/Src/Orbiter/VPlanet.h b/Src/Orbiter/VPlanet.h index cddb98d57..d79bc59d0 100644 --- a/Src/Orbiter/VPlanet.h +++ b/Src/Orbiter/VPlanet.h @@ -52,7 +52,7 @@ class VPlanet: public VObject { bool bFog; // render distance fog? bool bTint; // render atmospheric tint? bool bCloudFlatShadows; // render cloud shadows onto a sphere? - Vector rgbTint; // tint colour + VECTOR3 rgbTint; // tint colour double cloudrot; // cloud layer rotation state } prm; diff --git a/Src/Orbiter/Vecmat.cpp b/Src/Orbiter/Vecmat.cpp index 963266f0b..8ddf5f713 100644 --- a/Src/Orbiter/Vecmat.cpp +++ b/Src/Orbiter/Vecmat.cpp @@ -12,39 +12,6 @@ int irand (int range) return (int)((double)rand()*(double)range/drand_max); } -// ======================================================================= -// class Vector - -double Vector::dist2 (const Vector &vec) const -{ - double dx = x-vec.x; - double dy = y-vec.y; - double dz = z-vec.z; - return dx*dx + dy*dy + dz*dz; -} - -Vector Vector::unit () const -{ - double ilen = 1.0/length(); - return Vector (x*ilen, y*ilen, z*ilen); -} - -void Vector::unify () -{ - double ilen = 1.0/length(); - x *= ilen, y *= ilen, z *= ilen; -} - -double xangle (const Vector &a, const Vector &b) -{ - double cosa = dotp (a.unit(), b.unit()); - if (cosa < 1.0) { // also need to check for > -1 - double angle = acos(cosa); - if (cosa >= 0.0) return angle; - else return Pi2 - angle; - } else return 0.0; -} - // ======================================================================= // class Matrix @@ -93,7 +60,7 @@ void Matrix::Set (const Quaternion &q) m33 = 1.0-qxx2-qyy2; } -void Matrix::Set (const Vector &rot) +void Matrix::Set (const VECTOR3 &rot) { // set rotation matrix from axis rotation vector double sinx = sin(rot.x), cosx = cos(rot.x); @@ -202,20 +169,22 @@ Matrix IMatrix() return Matrix (1.0,0.0,0.0, 0.0,1.0,0.0, 0.0,0.0,1.0); } -Vector mul (const Matrix &A, const Vector &b) +VECTOR3 mul(const Matrix &A, const VECTOR3 &b) { - return Vector ( + return VECTOR3{ A.m11*b.x + A.m12*b.y + A.m13*b.z, A.m21*b.x + A.m22*b.y + A.m23*b.z, - A.m31*b.x + A.m32*b.y + A.m33*b.z); + A.m31*b.x + A.m32*b.y + A.m33*b.z + }; } -Vector tmul (const Matrix &A, const Vector &b) +VECTOR3 tmul(const Matrix &A, const VECTOR3 &b) { - return Vector ( + return VECTOR3{ A.m11*b.x + A.m21*b.y + A.m31*b.z, A.m12*b.x + A.m22*b.y + A.m32*b.z, - A.m13*b.x + A.m23*b.y + A.m33*b.z); + A.m13*b.x + A.m23*b.y + A.m33*b.z + }; } Matrix inv (const Matrix &A) @@ -244,24 +213,24 @@ Matrix transp (const Matrix &A) void Matrix::orthogonalise (int axis) { - Vector b1, b2, b3; + VECTOR3 b1, b2, b3; switch (axis) { case 0: - b1.Set (m11, m12, m13); b1.unify(); - b2.Set (m21, m22, m23); b2.unify(); - b3 = crossp(b1,b2); + b1 = unit(VECTOR3{m11, m12, m13}); + b2 = unit(VECTOR3{m21, m22, m23}); + b3 = cross(b1, b2); m31 = b3.x, m32 = b3.y, m33 = b3.z; break; case 1: - b1.Set (m11, m12, m13); b1.unify(); - b3.Set (m31, m32, m33); b3.unify(); - b2 = crossp (b3,b1); + b1 = unit(VECTOR3{m11, m12, m13}); + b3 = unit(VECTOR3{m31, m32, m33}); + b2 = cross(b3, b1); m21 = b2.x, m22 = b2.y, m23 = b2.z; break; case 2: - b2.Set (m21, m22, m23); b2.unify(); - b3.Set (m31, m32, m33); b3.unify(); - b1 = crossp (b2,b3); + b2 = unit(VECTOR3{m21, m22, m23}); + b3 = unit(VECTOR3{m31, m32, m33}); + b1 = cross(b2, b3); m11 = b1.x, m12 = b1.y, m13 = b1.z; break; } @@ -281,7 +250,7 @@ Matrix4::Matrix4 (const Matrix4 &A) } -void qrdcmp (Matrix4 &a, Vector4 &c, Vector4 &d, int *sing) +void qrdcmp (Matrix4 &a, VECTOR4 &c, VECTOR4 &d, int *sing) { int i, j, k; double scale, sigma, sum, tau; @@ -293,7 +262,7 @@ void qrdcmp (Matrix4 &a, Vector4 &c, Vector4 &d, int *sing) scale = std::max (scale, fabs(a(i,k))); if (scale == 0.0) { if (sing) *sing = 1; - c(k) = d(k) = 0.0; + c[k] = d[k] = 0.0; } else { for (i = k; i < 4; i++) a(i,k) /= scale; @@ -301,43 +270,43 @@ void qrdcmp (Matrix4 &a, Vector4 &c, Vector4 &d, int *sing) sum += a(i,k)*a(i,k); sigma = (a(k,k) < 0 ? -sqrt(sum) : sqrt(sum)); a(k,k) += sigma; - c(k) = sigma*a(k,k); - d(k) = -scale*sigma; + c[k] = sigma * a(k, k); + d[k] = -scale * sigma; for (j = k+1; j < 4; j++) { for (sum = 0.0,i = k; i < 4; i++) sum += a(i,k)*a(i,j); - tau = sum/c(k); + tau = sum / c[k]; for (i = k; i < 4; i++) a(i,j) -= tau*a(i,k); } } } - d(3) = a(3,3); - if (sing && d(3) == 0.0) *sing = 1; + d[3] = a(3, 3); + if (sing && d[3] == 0.0) *sing = 1; } -void qrsolv (const Matrix4 &a, const Vector4 &c, const Vector4 &d, Vector4 &b) +void qrsolv (const Matrix4 &a, const VECTOR4 &c, const VECTOR4 &d, VECTOR4 &b) { int i, j; double sum, tau; for (j = 0; j < 3; j++) { for (sum = 0.0, i = j; i < 4; i++) - sum += a(i,j)*b(i); - tau = sum/c(j); + sum += a(i, j) * b[i]; + tau = sum / c[j]; for (i = j; i < 4; i++) - b(i) -= tau*a(i,j); + b[i] -= tau * a(i, j); } - b(3) /= d(3); + b[3] /= d[3]; for (i = 2; i >= 0; i--) { for (sum = 0.0, j = i+1; j < 4; j++) - sum += a(i,j)*b(j); - b(i) = (b(i)-sum)/d(i); + sum += a(i, j) * b[j]; + b[i] = (b[i] - sum) / d[i]; } } -void QRFactorize (Matrix4 &A, Vector4 &c, Vector4 &d) +void QRFactorize (Matrix4 &A, VECTOR4 &c, VECTOR4 &d) { int i, j, k; double sum, b, f; @@ -345,9 +314,9 @@ void QRFactorize (Matrix4 &A, Vector4 &c, Vector4 &d) for (k = 0; k < 4; k++) { for (sum = 0, i = k; i < 4; i++) sum += A(i,k)*A(i,k); - d(k) = (A(k,k) < 0 ? -sqrt(sum) : sqrt(sum)); - b = sqrt(2.0*d(k)*(A(k,k) + d(k))); - A(k,k) = (A(k,k) + d(k))/b; + d[k] = A(k, k) < 0 ? -sqrt(sum) : sqrt(sum); + b = sqrt(2.0 * d[k] * (A(k, k) + d[k])); + A(k, k) = (A(k, k) + d[k]) / b; for (i = k+1; i < 4; i++) A(i,k) /= b; for (j = k+1; j < 4; j++) { @@ -360,20 +329,20 @@ void QRFactorize (Matrix4 &A, Vector4 &c, Vector4 &d) } } -void RSolve (const Matrix4 &A, const Vector4 &d, Vector4 &b) +void RSolve (const Matrix4 &A, const VECTOR4 &d, VECTOR4 &b) { int i, j; double sum; - b(3) /= -d(3); + b[3] /= -d[3]; for (i = 2; i >= 0; i--) { for (sum = 0.0, j = i+1; j < 4; j++) - sum += A(i,j) * b(j); - b(i) = (b(i)-sum) / -d(i); + sum += A(i, j) * b[j]; + b[i] = (b[i] - sum) / -d[i]; } } -void QRSolve (const Matrix4 &A, const Vector4 &c, - const Vector4 &d, const Vector4 &b, Vector4 &x) +void QRSolve (const Matrix4 &A, const VECTOR4 &c, + const VECTOR4 &d, const VECTOR4 &b, VECTOR4 &x) { int i, k; double sum; @@ -382,17 +351,17 @@ void QRSolve (const Matrix4 &A, const Vector4 &c, x = b; for (k = 0; k < 4; k++) { for (sum = 0, i = k; i < 4; i++) - sum += A(i,k)*x(i); + sum += A(i,k) * x[i]; sum *= 2.0; for (i = k; i < 4; i++) - x(i) -= sum*A(i,k); + x[i] -= sum * A(i, k); } // Solves Rx = y RSolve (A, d, x); } -void qrdcmp (Matrix &a, Vector &c, Vector &d, int *sing) +void qrdcmp (Matrix &a, VECTOR3 &c, VECTOR3 &d, int *sing) { int i, j, k; double scale, sigma, sum, tau; @@ -404,7 +373,7 @@ void qrdcmp (Matrix &a, Vector &c, Vector &d, int *sing) scale = std::max (scale, fabs(a(i,k))); if (scale == 0.0) { if (sing) *sing = 1; - c(k) = d(k) = 0.0; + c[k] = d[k] = 0.0; } else { for (i = k; i < 3; i++) a(i,k) /= scale; @@ -412,38 +381,38 @@ void qrdcmp (Matrix &a, Vector &c, Vector &d, int *sing) sum += a(i,k)*a(i,k); sigma = (a(k,k) < 0 ? -sqrt(sum) : sqrt(sum)); a(k,k) += sigma; - c(k) = sigma*a(k,k); - d(k) = -scale*sigma; + c[k] = sigma * a(k, k); + d[k] = -scale * sigma; for (j = k+1; j < 3; j++) { for (sum = 0.0,i = k; i < 3; i++) sum += a(i,k)*a(i,j); - tau = sum/c(k); + tau = sum / c[k]; for (i = k; i < 3; i++) a(i,j) -= tau*a(i,k); } } } - d(2) = a(2,2); - if (sing && d(2) == 0.0) *sing = 1; + d[2] = a(2, 2); + if (sing && d[2] == 0.0) *sing = 1; } -void qrsolv (const Matrix &a, const Vector &c, const Vector &d, Vector &b) +void qrsolv (const Matrix &a, const VECTOR3 &c, const VECTOR3 &d, VECTOR3 &b) { int i, j; double sum, tau; for (j = 0; j < 2; j++) { for (sum = 0.0, i = j; i < 3; i++) - sum += a(i,j)*b(i); - tau = sum/c(j); + sum += a(i, j) * b[i]; + tau = sum / c[j]; for (i = j; i < 3; i++) - b(i) -= tau*a(i,j); + b[i] -= tau * a(i, j); } - b(2) /= d(2); + b[2] /= d[2]; for (i = 1; i >= 0; i--) { for (sum = 0.0, j = i+1; j < 3; j++) - sum += a(i,j)*b(j); - b(i) = (b(i)-sum)/d(i); + sum += a(i, j) * b[j]; + b[i] = (b[i] - sum) / d[i]; } } @@ -496,7 +465,7 @@ double dotp (const Quaternion &q1, const Quaternion &q2) return q1.qs*q2.qs + q1.qvx*q2.qvx + q1.qvy*q2.qvy + q1.qvz*q2.qvz; } -void Quaternion::Rotate (const Vector &omega) +void Quaternion::Rotate (const VECTOR3 &omega) { double dvx = 0.5*( qs *omega.x - qvy*omega.z + qvz*omega.y); double dvy = 0.5*( qs *omega.y - qvz*omega.x + qvx*omega.z); @@ -521,7 +490,7 @@ void Quaternion::Rotate (const Vector &omega) } } -Quaternion Quaternion::Rot (const Vector &omega) const +Quaternion Quaternion::Rot (const VECTOR3 &omega) const { return Quaternion (qvx + 0.5*( qs *omega.x - qvy*omega.z + qvz*omega.y), qvy + 0.5*( qs *omega.y - qvz*omega.x + qvx*omega.z), @@ -613,7 +582,7 @@ Quaternion Quaternion::operator* (const Quaternion &Q) const ); } -Vector mul (const Quaternion &q, const Vector &p) +VECTOR3 mul(const Quaternion &q, const VECTOR3 &p) { // note that the implementations of mul and tmul are switched w.r.t. a right-handed system double vx = q.qs*p.x - q.qvy*p.z + q.qvz*p.y; @@ -622,12 +591,14 @@ Vector mul (const Quaternion &q, const Vector &p) double qvx2 = -2.0*q.qvx; double qvy2 = -2.0*q.qvy; double qvz2 = -2.0*q.qvz; - return Vector (p.x + qvy2*vz - qvz2*vy, - p.y + qvz2*vx - qvx2*vz, - p.z + qvx2*vy - qvy2*vx); + return VECTOR3{ + p.x + qvy2 * vz - qvz2 * vy, + p.y + qvz2 * vx - qvx2 * vz, + p.z + qvx2 * vy - qvy2 * vx + }; } -Vector tmul (const Quaternion &q, const Vector &p) +VECTOR3 tmul(const Quaternion &q, const VECTOR3 &p) { // note that the implementations of mul and tmul are switched w.r.t. a right-handed system double vx = q.qs*p.x + q.qvy*p.z - q.qvz*p.y; @@ -636,9 +607,11 @@ Vector tmul (const Quaternion &q, const Vector &p) double qvx2 = 2.0*q.qvx; double qvy2 = 2.0*q.qvy; double qvz2 = 2.0*q.qvz; - return Vector (p.x + qvy2*vz - qvz2*vy, - p.y + qvz2*vx - qvx2*vz, - p.z + qvx2*vy - qvy2*vx); + return VECTOR3{ + p.x + qvy2 * vz - qvz2 * vy, + p.y + qvz2 * vx - qvx2 * vz, + p.z + qvx2 * vy - qvy2 * vx + }; } void Quaternion::interp (const Quaternion &A, const Quaternion &B, double u) @@ -693,20 +666,20 @@ double angle (const Quaternion &A, const Quaternion &B) // ======================================================================= // StateVectors -void StateVectors::Set (const StateVectors &s) +void StateVectors::Set(const StateVectors &s) { - vel.Set (s.vel); - pos.Set (s.pos); - omega.Set (s.omega); + vel = s.vel; + pos = s.pos; + omega = s.omega; Q.Set (s.Q); R.Set (s.R); } -void StateVectors::Set (const Vector &v, const Vector &p, const Vector &av, const Quaternion &ap) +void StateVectors::Set(const VECTOR3 &v, const VECTOR3 &p, const VECTOR3 &av, const Quaternion &ap) { - vel.Set (v); - pos.Set (p); - omega.Set (av); + vel = v; + pos = p; + omega = av; Q.Set (ap); R.Set (ap); } @@ -723,7 +696,7 @@ void StateVectors::SetRot (const Quaternion &q) R.Set (q); } -void StateVectors::Advance (double dt, const Vector &a, const Vector &v, const Vector &aa, const Vector &av) +void StateVectors::Advance (double dt, const VECTOR3 &a, const VECTOR3 &v, const VECTOR3 &aa, const VECTOR3 &av) { vel += a*dt; pos += v*dt; @@ -735,7 +708,7 @@ void StateVectors::Advance (double dt, const Vector &a, const Vector &v, const V // ======================================================================= // Geometric utility functions -void PlaneCoeffs (const Vector &p1, const Vector &p2, const Vector &p3, +void PlaneCoeffs (const VECTOR3 &p1, const VECTOR3 &p2, const VECTOR3 &p3, double &a, double &b, double &c, double &d) { a = p1.y*(p2.z-p3.z) - p2.y*(p1.z-p3.z) + p3.y*(p1.z-p2.z); @@ -744,14 +717,14 @@ void PlaneCoeffs (const Vector &p1, const Vector &p2, const Vector &p3, d = -p1.x*a - p1.y*b - p1.z*c; } -double PointPlaneDist(const Vector& p, double a, double b, double c, double d) +double PointPlaneDist(const VECTOR3& p, double a, double b, double c, double d) { double D = -sqrt(a * a + b * b + c * c); // for a valid plane definition, this should never be 0, so we don't check for division by zero here return (a * p.x + b * p.y + c * p.z + d) / D; } -bool LinePlaneIntersect (double a, double b, double c, double d, const Vector &p, const Vector &s, Vector &r) +bool LinePlaneIntersect (double a, double b, double c, double d, const VECTOR3 &p, const VECTOR3 &s, VECTOR3 &r) { double D = a*s.x + b*s.y + c*s.z; if (!D) return false; @@ -761,17 +734,17 @@ bool LinePlaneIntersect (double a, double b, double c, double d, const Vector &p return true; } -void VectorBasisToMatrix(const Vector &X, const Vector &Y, const Vector &Z, Matrix &R) +void VectorBasisToMatrix(const VECTOR3 &X, const VECTOR3 &Y, const VECTOR3 &Z, Matrix &R) { R.Set(X.x, X.y, X.z, Y.x, Y.y, Y.z, Z.x, Z.y, Z.z); } -void DirRotToMatrix(const Vector &Z, const Vector &Y, Matrix &R) +void DirRotToMatrix(const VECTOR3 &Z, const VECTOR3 &Y, Matrix &R) { // Compute the third orthogonal direction vector from Z and Y - Vector X(crossp(Y, Z)); // left-handed + VECTOR3 X = cross(Y, Z); // left-handed VectorBasisToMatrix(X, Y, Z, R); } \ No newline at end of file diff --git a/Src/Orbiter/Vecmat.h b/Src/Orbiter/Vecmat.h index cf1179f53..2688d0633 100644 --- a/Src/Orbiter/Vecmat.h +++ b/Src/Orbiter/Vecmat.h @@ -4,6 +4,8 @@ #ifndef __VECMAT_H #define __VECMAT_H +#include "vector.hpp" + #include #include #include @@ -68,105 +70,6 @@ inline double acosh (double x) // note: sign undefined } -// ======================================================================= -// class Vector - -class Vector { -public: - inline Vector () - { x = y = z = 0.0; } - - inline Vector (double _x, double _y, double _z) - { x = _x, y = _y, z = _z; } - - inline Vector (const Vector &vec) - { x = vec.x, y = vec.y, z = vec.z; } - - inline void Set (double _x, double _y, double _z) - { x = _x, y = _y, z = _z; } - - inline void Set (const Vector &vec) - { x = vec.x, y = vec.y, z = vec.z; } - - inline double &operator() (int i) - { return data[i]; } - - inline double operator() (int i) const - { return data[i]; } - - inline Vector &operator= (const Vector &vec) - { x = vec.x, y = vec.y, z = vec.z; return *this; } - - inline Vector operator+ (const Vector &vec) const - { return Vector (x+vec.x, y+vec.y, z+vec.z); } - - inline Vector operator- (const Vector &vec) const - { return Vector (x-vec.x, y-vec.y, z-vec.z); } - - inline Vector operator- () const // unary minus - { return Vector (-x, -y, -z); } - - inline Vector operator* (double f) const - { return Vector (x*f, y*f, z*f); } - - inline Vector operator* (const Vector &vec) const - { return Vector (x*vec.x, y*vec.y, z*vec.z); } - - inline Vector operator/ (double f) const - { return Vector (x/f, y/f, z/f); } - - inline Vector operator/ (const Vector &vec) const - { return Vector (x/vec.x, y/vec.y, z/vec.z); } - - inline double operator& (const Vector &vec) const // scalar product - { return x*vec.x + y*vec.y + z*vec.z; } - - inline Vector &operator+= (const Vector &vec) - { x += vec.x, y += vec.y, z += vec.z; return *this; } - - inline Vector &operator-= (const Vector &vec) - { x -= vec.x, y -= vec.y, z -= vec.z; return *this; } - - inline Vector &operator*= (const double f) - { x *= f, y *= f, z *= f; return *this; } - - inline Vector &operator/= (const double f) - { x /= f, y /= f, z /= f; return *this; } - - friend Vector crossp (const Vector &a, const Vector &b) // cross product - { return Vector (a.y*b.z - b.y*a.z, a.z*b.x - b.z*a.x, a.x*b.y - b.x*a.y); } - - friend double dotp (const Vector &a, const Vector &b) // scalar product - { return a.x*b.x + a.y*b.y + a.z*b.z; } - - inline double length2 () const // square of vector length - { return x*x + y*y + z*z; } - - inline double length () const // vector length - { return sqrt (length2()); } - - double dist2 (const Vector &vec) const; // square of distance between two points - - inline double dist (const Vector &vec) const // distance between two points - { return sqrt (dist2 (vec)); } - - Vector unit () const; // return unit vector in direction of *this - - void unify (); // set length of *this to unity - - friend double xangle (const Vector &a, const Vector &b); - // angle between two straight lines through the origin, defined - // by directions of a and b - - friend std::ostream &operator<< (std::ostream &os, const Vector &v) - { os << v.x << ' ' << v.y << ' ' << v.z; return os; } - - union { - double data[3]; - struct { double x, y, z; }; - }; -}; - // ======================================================================= // class Matrix @@ -188,7 +91,7 @@ class Matrix { void Set (const Quaternion &q); - void Set (const Vector &rot); + void Set (const VECTOR3 &rot); // Set from axis rotation vector inline double &operator() (int i, int j) @@ -215,8 +118,8 @@ class Matrix { void orthogonalise (int axis); - friend void qrdcmp (Matrix &a, Vector &c, Vector &d, int *sing = 0); - friend void qrsolv (const Matrix &a, const Vector &c, const Vector &d, Vector &b); + friend void qrdcmp (Matrix &a, VECTOR3 &c, VECTOR3 &d, int *sing = 0); + friend void qrsolv (const Matrix &a, const VECTOR3 &c, const VECTOR3 &d, VECTOR3 &b); union { double data[9]; @@ -226,43 +129,11 @@ class Matrix { Matrix IMatrix(); // returns identity matrix -Vector mul (const Matrix &A, const Vector &b); // returns A * b -Vector tmul (const Matrix &A, const Vector &b); // returns A^T * b +VECTOR3 mul (const Matrix &A, const VECTOR3 &b); // returns A * b +VECTOR3 tmul (const Matrix &A, const VECTOR3 &b); // returns A^T * b Matrix inv (const Matrix &A); // inverse of A Matrix transp (const Matrix &A); // transpose of A -// ======================================================================= -// class Vector4: 4-element vector - -class Vector4 { -public: - inline Vector4 () - { x = y = z = w = 0.0; } - - inline Vector4 (double _x, double _y, double _z, double _w) - { x = _x, y = _y, z = _z, w = _w; } - - inline Vector4 (const Vector4 &vec) - { memcpy (data, vec.data, 4*sizeof(double)); } - - inline void Set (double _x, double _y, double _z, double _w) - { x = _x, y = _y, z = _z, w = _w; } - - inline void Set (const Vector4 &vec) - { memcpy (data, vec.data, 4*sizeof(double)); } - - inline double &operator() (int i) - { return data[i]; } - - inline double operator() (int i) const - { return data[i]; } - - union { - double data[4]; - struct { double x, y, z, w; }; - }; -}; - // ======================================================================= // class Matrix4: 4x4 dense matrix @@ -298,12 +169,12 @@ class Matrix4 { inline double operator() (int i, int j) const { return data[i*4+j]; } - friend void qrdcmp (Matrix4 &a, Vector4 &c, Vector4 &d, int *sing = 0); - friend void qrsolv (const Matrix4 &a, const Vector4 &c, const Vector4 &d, Vector4 &b); - friend void QRFactorize (Matrix4 &A, Vector4 &c, Vector4 &d); - friend void RSolve (const Matrix4 &A, const Vector4 &d, Vector4 &b); - friend void QRSolve (const Matrix4 &A, const Vector4 &c, - const Vector4 &d, const Vector4 &b, Vector4 &x); + friend void qrdcmp (Matrix4 &a, VECTOR4 &c, VECTOR4 &d, int *sing = 0); + friend void qrsolv (const Matrix4 &a, const VECTOR4 &c, const VECTOR4 &d, VECTOR4 &b); + friend void QRFactorize (Matrix4 &A, VECTOR4 &c, VECTOR4 &d); + friend void RSolve (const Matrix4 &A, const VECTOR4 &d, VECTOR4 &b); + friend void QRSolve (const Matrix4 &A, const VECTOR4 &c, + const VECTOR4 &d, const VECTOR4 &b, VECTOR4 &x); union { double data[16]; @@ -325,7 +196,7 @@ class Quaternion { inline Quaternion (double vx, double vy, double vz, double s) { Set (vx, vy, vz, s); } // Constructor from scalar parameters - inline Quaternion (const Vector &v, double s) { Set (v, s); } + inline Quaternion (const VECTOR3 &v, double s) { Set (v, s); } // Constructor from vector+scalar parameters inline Quaternion (const Matrix &R) { Set (R); } @@ -340,7 +211,7 @@ class Quaternion { inline void Set (double vx, double vy, double vz, double s) { qvx = vx, qvy = vy, qvz = vz, qs = s; } - inline void Set (const Vector &v, double s) + inline void Set (const VECTOR3 &v, double s) { qvx = v.x, qvy = v.y, qvz = v.z, qs = s; } // set the quaternion from a vector and scalar component @@ -356,16 +227,16 @@ class Quaternion { inline void normalise () { double len = norm(); qs /= len; qvx /= len; qvy /= len; qvz /= len; } - void Rotate (const Vector &omega); + void Rotate (const VECTOR3 &omega); // rotate the quaternion by rotation angles omega - Quaternion Rot (const Vector &omega) const; + Quaternion Rot (const VECTOR3 &omega) const; // returns the quaternion rotated by angles omega - friend Vector mul (const Quaternion &q, const Vector &b); + friend VECTOR3 mul (const Quaternion &q, const VECTOR3 &b); // Returns vector p rotated by quaternion - friend Vector tmul (const Quaternion &q, const Vector &p); + friend VECTOR3 tmul (const Quaternion &q, const VECTOR3 &p); // Returns vector p rotated by inverse quaternion Quaternion &operator+= (const Quaternion &Q); @@ -400,22 +271,22 @@ class StateVectors { public: void Set (const StateVectors &s); - void Set (const Vector &v, const Vector &p, const Vector &av, const Quaternion &ap); + void Set (const VECTOR3 &v, const VECTOR3 &p, const VECTOR3 &av, const Quaternion &ap); // Set state vectors to linear velocity v, position p, angular velocity av and // orientation ap. void SetRot (const Matrix &r); // set rotation state from a rotation matrix void SetRot (const Quaternion &q); // set rotation state from a quaternion - void Advance (double dt, const Vector &a, const Vector &v, const Vector &aa, const Vector &av); + void Advance (double dt, const VECTOR3 &a, const VECTOR3 &v, const VECTOR3 &aa, const VECTOR3 &av); // Advance the state vectors by dt, given linear acceleration a, linear velocity v, // angular acceleration aa and angular velocity av. - Vector pos; // position in associated frame - Vector vel; // linear velocity in associated frame + VECTOR3 pos; // position in associated frame + VECTOR3 vel; // linear velocity in associated frame Matrix R; // rotation matrix in associated frame Quaternion Q; // orientation in associated frame - Vector omega; // angular velocity components in associated frame + VECTOR3 omega; // angular velocity components in associated frame }; // ======================================================================= @@ -423,31 +294,30 @@ class StateVectors { // Calculate the coefficients of a plane, ax+by+cz+d = 0, from 3 points spanning the plane // (Note that this assumes a left-handed coordinate system) -void PlaneCoeffs (const Vector &p1, const Vector &p2, const Vector &p3, +void PlaneCoeffs (const VECTOR3 &p1, const VECTOR3 &p2, const VECTOR3 &p3, double &a, double &b, double &c, double &d); // Distance of point 'a' from a line defined by a point 'p' and direction vector 'd' -inline double PointLineDist (const Vector &a, const Vector &p, const Vector &d) +inline double PointLineDist (const VECTOR3 &a, const VECTOR3 &p, const VECTOR3 &d) { - return crossp (d.unit(), a-p).length(); - //return dotp(d,a-p)/d.length(); + return len(cross(unit(d), a - p)); } // Distance of point 'p' from a plane defined by coefficients a,b,c,d (ax+by+cz+d=0) // This is a signed distance, so return value < 0 is possible -double PointPlaneDist(const Vector& p, double a, double b, double c, double d); +double PointPlaneDist(const VECTOR3& p, double a, double b, double c, double d); // Calculate intersection r of a line (given by point p and direction s) with a plane // given by coefficients ax+by+cz+d = 0. If return value=false then no intersection exists -bool LinePlaneIntersect (double a, double b, double c, double d, const Vector &p, const Vector &s, Vector &r); +bool LinePlaneIntersect (double a, double b, double c, double d, const VECTOR3 &p, const VECTOR3 &s, VECTOR3 &r); // Return the normal to the plane defined by coefficients a,b,c,d -inline Vector PlaneNormal(double a, double b, double c, double d) { return Vector(a, b, c).unit(); } +inline auto PlaneNormal(double a, double b, double c, double d) { return unit(VECTOR3{a, b, c}); } // Convert a cartesian reference frame given by orthonormal vectors X, Y, Z (expressed in the global frame) into // a rotation matrix, such that a point p in the global frame is transformed to p' in the XYZ frame by p' = Rp. // Note: X,Y,Z must be orthonormal (orthogonal, normalised) vectors (not tested) -void VectorBasisToMatrix(const Vector &X, const Vector &Y, const Vector &Z, Matrix &R); +void VectorBasisToMatrix(const VECTOR3 &X, const VECTOR3 &Y, const VECTOR3 &Z, Matrix &R); // Convert a cartesian reference frame given by orthonormal vectors Y, Z (expressed in the global frame) into // a rotation matrix, such that a point p in the global frame is transformed to p' in the YZ frame by p' = Rp. @@ -455,6 +325,6 @@ void VectorBasisToMatrix(const Vector &X, const Vector &Y, const Vector &Z, Matr // Note: Y,Z must be orthonormal (orthogonal, normalised) vectors (not tested) // This function is useful for rotations involving docking ports which are defined by an approach direction (Z) // and an up direction (Y) that defines the longitudinal rotation reference. -void DirRotToMatrix(const Vector &Z, const Vector &Y, Matrix &R); +void DirRotToMatrix(const VECTOR3 &Z, const VECTOR3 &Y, Matrix &R); -#endif // !__VECMAT_H \ No newline at end of file +#endif // !__VECMAT_H diff --git a/Src/Orbiter/VectorMap.cpp b/Src/Orbiter/VectorMap.cpp index 257345325..4c391c5b7 100644 --- a/Src/Orbiter/VectorMap.cpp +++ b/Src/Orbiter/VectorMap.cpp @@ -262,7 +262,7 @@ void VectorMap::Update () //if (focuscenter) SetCenter (drawdata.focuslng, drawdata.focuslat); } if (drawdata.sun_disp = true) { - cbody->GlobalToEquatorial (Vector(0,0,0), lng, lat, rad); + cbody->GlobalToEquatorial({0, 0, 0}, lng, lat, rad); drawdata.sunlng = lng; drawdata.sunlat = lat; } @@ -1284,12 +1284,12 @@ void VectorMap::CalcOrbitProj (const Elements *el, const CelestialBody *body, VP el->sint, 0, el->cost)); R.tpremul (body->GRot()); - Vector r, rt; + VECTOR3 r, rt; for (i = 0; i < NVTX_CIRCLE; i++) { r.x = cosp[i]; r.z = sinp[i]; - rt.Set (mul (R, r)); + rt = mul(R, r); p[i].lng = atan2 (rt.z, rt.x); p[i].lat = Pi05-acos(rt.y); } @@ -1306,7 +1306,7 @@ VPoint *VectorMap::GreatCircle (double lng, double lat) Matrix R(clat,slat,0, -slat,clat,0, 0,0,1); Matrix R2(clng,0,-slng, 0,1,0, slng,0,clng); R.premul(R2); - Vector pt, ptt; + VECTOR3 pt, ptt; static VPoint vp[nvtx]; for (i = 0; i < nvtx; i++) { @@ -1332,7 +1332,7 @@ VPoint *VectorMap::SmallCircle (double lng, double lat, double dst) Matrix R(clat,slat,0, -slat,clat,0, 0,0,1); Matrix R2(clng,0,-slng, 0,1,0, slng,0,clng); R.premul(R2); - Vector pt, ptt; + VECTOR3 pt, ptt; static VPoint vp[nvtx]; for (i = 0; i < nvtx; i++) { @@ -1518,7 +1518,7 @@ void CustomMkrSpec::Convert () for (int i = 0; i < nvtx; i++) { VECTOR3 &p = list->marker[i].pos; vtx[i].lng = atan2 (p.z, p.x); - vtx[i].lat = asin (p.y / length(p)); + vtx[i].lat = std::asin(p.y / len(p)); } } @@ -1604,10 +1604,10 @@ void Groundtrack::Reset (const CelestialBody *body, const Elements *_el) void Groundtrack::CalcPoint (VPointGT &p, double *angvel) { double r, ta, lng, lat, rad; - Vector pos, loc; + VECTOR3 pos, loc; el->RelPos (r, ta, p.t); el->Pol2Crt (r, ta, pos); - loc.Set (tmul (cbody->GRot(), pos)); + loc = tmul(cbody->GRot(), pos); cbody->LocalToEquatorial (loc, lng, lat, rad); p.lng = normangle(lng - Pi2*(p.t-td.SimT0)/cbody->RotT()); p.lat = lat; diff --git a/Src/Orbiter/Vessel.cpp b/Src/Orbiter/Vessel.cpp index 2b87c8bfa..e9d16c67a 100644 --- a/Src/Orbiter/Vessel.cpp +++ b/Src/Orbiter/Vessel.cpp @@ -68,10 +68,10 @@ const char noclass[] = "unknown"; const double holdaltDT = 0.1; // update interval for "hold altitude" mode static VECTOR3 DefExhaustDir[4] = {{0,0,-1}, {0,0,1}, {0,-1,0}, {0,0,-1}}; -static Vector DefAttExhaustDir[12] = { - Vector(0,-1,0), Vector(0,1,0), Vector(0,1,0), Vector(0,-1,0), - Vector(-1,0,0), Vector(1,0,0), Vector(1,0,0), Vector(-1,0,0), - Vector(0,-1,0), Vector(0,1,0), Vector(0,1,0), Vector(0,-1,0) +static VECTOR3 DefAttExhaustDir[12] = { + {0,-1,0}, {0,1,0}, {0,1,0}, {0,-1,0}, + {-1,0,0}, {1,0,0}, {1,0,0}, {-1,0,0}, + {0,-1,0}, {0,1,0}, {0,1,0}, {0,-1,0} }; // ============================================================== @@ -278,12 +278,12 @@ void Vessel::SetDefaultState () VesselBase::SetDefaultState (); - Flin.Set (0,0,0); // sum of linear forces - Amom.Set (0,0,0); // torque (sum of angular moments) - Flin_add.Set (0,0,0); - Amom_add.Set (0,0,0); - Thrust.Set (0,0,0); - Weight.Set (0,0,0); + Flin = {0, 0, 0}; // sum of linear forces + Amom = {0, 0, 0}; // torque (sum of angular moments) + Flin_add = {0, 0, 0}; + Amom_add = {0, 0, 0}; + Thrust = {0, 0, 0}; + Weight = {0, 0, 0}; weight_valid = false; torque_valid = false; fmass = pfmass = 0.0; @@ -325,8 +325,9 @@ void Vessel::SetDefaultState () nforcevec = 0; forcevecbuf = 10; - forcevec = new Vector[forcevecbuf]; - forcepos = new Vector[forcevecbuf]; + // TODO: re-write without raw pointers + forcevec = new VECTOR3[forcevecbuf]; + forcepos = new VECTOR3[forcevecbuf]; proxyT = -(double)rand()*100.0/(double)RAND_MAX - 1.0; commsT = -(double)rand()*5.0/(double)RAND_MAX - 1.0; @@ -362,10 +363,10 @@ void Vessel::DefaultGenericCaps () bElevTrim = false; pitch_moment_scale = 0.0; bank_moment_scale = 0.0; - cs.Set (20,20,20); - rdrag.Set (0.01,0.01,0.01); - campos.Set (0,0,0); - camdir0.Set (0,0,1); // "forward" + cs = {20, 20, 20}; + rdrag = {0.01, 0.01, 0.01}; + campos = {0, 0, 0}; + camdir0 = {0, 0, 1}; // "forward" camtilt0 = 0.0; camcatchangle = RAD*5.0; camdp_left = camdp_right = 0.8*Pi; @@ -376,9 +377,9 @@ void Vessel::DefaultGenericCaps () mu = 0.5; // default isotropic/lateral friction coefficient mu_lng = 0.1; // default longitudinal friction coefficient TOUCHDOWNVTX tdvtx[3]; - tdvtx[0].pos = _V( 0,-2,10); - tdvtx[1].pos = _V(-3,-2,-5); - tdvtx[2].pos = _V( 3,-2,-5); + tdvtx[0].pos = { 0,-2,10}; + tdvtx[1].pos = {-3,-2,-5}; + tdvtx[2].pos = { 3,-2,-5}; for (i = 0; i < 3; i++) { tdvtx[i].stiffness = 1e6; tdvtx[i].damping = 1e5; @@ -529,7 +530,7 @@ void Vessel::ReadGenericCaps (ifstream &ifs) GetItemVector (ifs, "RotResistance", rdrag); GetItemVector (ifs, "CameraOffset", campos); - Vector ref, dir, rot; + VECTOR3 ref, dir, rot; if (GetItemVector (ifs, "DockRef", ref) && GetItemVector (ifs, "DockDir", dir) && GetItemVector (ifs, "DockRot", rot)) { @@ -542,7 +543,7 @@ void Vessel::ReadGenericCaps (ifstream &ifs) if (m_thrusterGroupDef[0].ts.size()) { for (i = 0;; i++) { sprintf (cbuf, "MEngineRef%d", i+1); - if (!GetItemVECTOR (ifs, cbuf, tmp)) break; + if (!GetItemVector(ifs, cbuf, tmp)) break; EXHAUSTSPEC es = {(THRUSTER_HANDLE)m_thrusterGroupDef[0].ts[0], NULL, &tmp, NULL, 16.0, 1.0, 0.0, 0.0, NULL, EXHAUST_CONSTANTPOS}; AddExhaust (&es); } @@ -551,7 +552,7 @@ void Vessel::ReadGenericCaps (ifstream &ifs) if (m_thrusterGroupDef[1].ts.size()) { for (i = 0;; i++) { sprintf (cbuf, "REngineRef%d", i+1); - if (!GetItemVECTOR (ifs, cbuf, tmp)) break; + if (!GetItemVector(ifs, cbuf, tmp)) break; EXHAUSTSPEC es = {(THRUSTER_HANDLE)m_thrusterGroupDef[1].ts[0], NULL, &tmp, NULL, 8.0, 0.5, 0.0, 0.0, NULL, EXHAUST_CONSTANTPOS}; AddExhaust (&es); } @@ -560,13 +561,13 @@ void Vessel::ReadGenericCaps (ifstream &ifs) if (m_thrusterGroupDef[2].ts.size()) { for (i = 0;; i++) { sprintf (cbuf, "HEngineRef%d", i+1); - if (!GetItemVECTOR (ifs, cbuf, tmp)) break; + if (!GetItemVector(ifs, cbuf, tmp)) break; EXHAUSTSPEC es = {(THRUSTER_HANDLE)m_thrusterGroupDef[2].ts[0], NULL, &tmp, NULL, 12.0, 1.0, 0.0, 0.0, NULL, EXHAUST_CONSTANTPOS}; AddExhaust (&es); } } // attitude thruster exhaust refs - if (GetItemVECTOR (ifs, "AttRefX00", tmp)) { + if (GetItemVector(ifs, "AttRefX00", tmp)) { if (m_thrusterGroupDef[THGROUP_ATT_PITCHUP].ts.size() >= 1) { EXHAUSTSPEC es = {(THRUSTER_HANDLE)m_thrusterGroupDef[THGROUP_ATT_PITCHUP].ts[0], NULL, &tmp, NULL, 3, 0.39, 0, 0, NULL, EXHAUST_CONSTANTPOS}; AddExhaust (&es); @@ -576,7 +577,7 @@ void Vessel::ReadGenericCaps (ifstream &ifs) AddExhaust (&es); } } - if (GetItemVECTOR (ifs, "AttRefX01", tmp)) { + if (GetItemVector(ifs, "AttRefX01", tmp)) { if (m_thrusterGroupDef[THGROUP_ATT_PITCHUP].ts.size() >= 2) { EXHAUSTSPEC es = {(THRUSTER_HANDLE)m_thrusterGroupDef[THGROUP_ATT_PITCHUP].ts[1], NULL, &tmp, NULL, 3, 0.39, 0, 0, NULL, EXHAUST_CONSTANTPOS}; AddExhaust (&es); @@ -586,7 +587,7 @@ void Vessel::ReadGenericCaps (ifstream &ifs) AddExhaust (&es); } } - if (GetItemVECTOR (ifs, "AttRefX10", tmp)) { + if (GetItemVector(ifs, "AttRefX10", tmp)) { if (m_thrusterGroupDef[THGROUP_ATT_PITCHDOWN].ts.size() >= 1) { EXHAUSTSPEC es = {(THRUSTER_HANDLE)m_thrusterGroupDef[THGROUP_ATT_PITCHDOWN].ts[0], NULL, &tmp, NULL, 3, 0.39, 0, 0, NULL, EXHAUST_CONSTANTPOS}; AddExhaust (&es); @@ -596,7 +597,7 @@ void Vessel::ReadGenericCaps (ifstream &ifs) AddExhaust (&es); } } - if (GetItemVECTOR (ifs, "AttRefX11", tmp)) { + if (GetItemVector(ifs, "AttRefX11", tmp)) { if (m_thrusterGroupDef[THGROUP_ATT_PITCHDOWN].ts.size() >= 2) { EXHAUSTSPEC es = {(THRUSTER_HANDLE)m_thrusterGroupDef[THGROUP_ATT_PITCHDOWN].ts[1], NULL, &tmp, NULL, 3, 0.39, 0, 0, NULL, EXHAUST_CONSTANTPOS}; AddExhaust (&es); @@ -606,7 +607,7 @@ void Vessel::ReadGenericCaps (ifstream &ifs) AddExhaust (&es); } } - if (GetItemVECTOR (ifs, "AttRefY01", tmp)) { + if (GetItemVector(ifs, "AttRefY01", tmp)) { if (m_thrusterGroupDef[THGROUP_ATT_YAWLEFT].ts.size() >= 1) { EXHAUSTSPEC es = {(THRUSTER_HANDLE)m_thrusterGroupDef[THGROUP_ATT_YAWLEFT].ts[0], NULL, &tmp, NULL, 3, 0.39, 0, 0, NULL, EXHAUST_CONSTANTPOS}; AddExhaust (&es); @@ -616,7 +617,7 @@ void Vessel::ReadGenericCaps (ifstream &ifs) AddExhaust (&es); } } - if (GetItemVECTOR (ifs, "AttRefY00", tmp)) { + if (GetItemVector(ifs, "AttRefY00", tmp)) { if (m_thrusterGroupDef[THGROUP_ATT_YAWLEFT].ts.size() >= 2) { EXHAUSTSPEC es = {(THRUSTER_HANDLE)m_thrusterGroupDef[THGROUP_ATT_YAWLEFT].ts[1], NULL, &tmp, NULL, 3, 0.39, 0, 0, NULL, EXHAUST_CONSTANTPOS}; AddExhaust (&es); @@ -626,7 +627,7 @@ void Vessel::ReadGenericCaps (ifstream &ifs) AddExhaust (&es); } } - if (GetItemVECTOR (ifs, "AttRefY11", tmp)) { + if (GetItemVector(ifs, "AttRefY11", tmp)) { if (m_thrusterGroupDef[THGROUP_ATT_YAWRIGHT].ts.size() >= 1) { EXHAUSTSPEC es = {(THRUSTER_HANDLE)m_thrusterGroupDef[THGROUP_ATT_YAWRIGHT].ts[0], NULL, &tmp, NULL, 3, 0.39, 0, 0, NULL, EXHAUST_CONSTANTPOS}; AddExhaust (&es); @@ -636,7 +637,7 @@ void Vessel::ReadGenericCaps (ifstream &ifs) AddExhaust (&es); } } - if (GetItemVECTOR (ifs, "AttRefY10", tmp)) { + if (GetItemVector(ifs, "AttRefY10", tmp)) { if (m_thrusterGroupDef[THGROUP_ATT_YAWRIGHT].ts.size() >= 2) { EXHAUSTSPEC es = {(THRUSTER_HANDLE)m_thrusterGroupDef[THGROUP_ATT_YAWRIGHT].ts[1], NULL, &tmp, NULL, 3, 0.39, 0, 0, NULL, EXHAUST_CONSTANTPOS}; AddExhaust (&es); @@ -646,22 +647,22 @@ void Vessel::ReadGenericCaps (ifstream &ifs) AddExhaust (&es); } } - if (GetItemVECTOR (ifs, "AttRefZ00", tmp)) + if (GetItemVector(ifs, "AttRefZ00", tmp)) if (m_thrusterGroupDef[THGROUP_ATT_BANKRIGHT].ts.size() >= 1) { EXHAUSTSPEC es = {(THRUSTER_HANDLE)m_thrusterGroupDef[THGROUP_ATT_BANKRIGHT].ts[0], NULL, &tmp, NULL, 3, 0.39, 0, 0, NULL, EXHAUST_CONSTANTPOS}; AddExhaust (&es); } - if (GetItemVECTOR (ifs, "AttRefZ01", tmp)) + if (GetItemVector(ifs, "AttRefZ01", tmp)) if (m_thrusterGroupDef[THGROUP_ATT_BANKRIGHT].ts.size() >= 2) { EXHAUSTSPEC es = {(THRUSTER_HANDLE)m_thrusterGroupDef[THGROUP_ATT_BANKRIGHT].ts[1], NULL, &tmp, NULL, 3, 0.39, 0, 0, NULL, EXHAUST_CONSTANTPOS}; AddExhaust (&es); } - if (GetItemVECTOR (ifs, "AttRefZ11", tmp)) + if (GetItemVector(ifs, "AttRefZ11", tmp)) if (m_thrusterGroupDef[THGROUP_ATT_BANKLEFT].ts.size() >= 1) { EXHAUSTSPEC es = {(THRUSTER_HANDLE)m_thrusterGroupDef[THGROUP_ATT_BANKLEFT].ts[0], NULL, &tmp, NULL, 3, 0.39, 0, 0, NULL, EXHAUST_CONSTANTPOS}; AddExhaust (&es); } - if (GetItemVECTOR (ifs, "AttRefZ10", tmp)) + if (GetItemVector(ifs, "AttRefZ10", tmp)) if (m_thrusterGroupDef[THGROUP_ATT_BANKLEFT].ts.size() >= 2) { EXHAUSTSPEC es = {(THRUSTER_HANDLE)m_thrusterGroupDef[THGROUP_ATT_BANKLEFT].ts[1], NULL, &tmp, NULL, 3, 0.39, 0, 0, NULL, EXHAUST_CONSTANTPOS}; AddExhaust (&es); @@ -669,7 +670,7 @@ void Vessel::ReadGenericCaps (ifstream &ifs) if (m_thrusterGroupDef[THGROUP_ATT_BACK].ts.size()) { for (i = 0;; i++) { sprintf (cbuf, "LongAttRef0%d", i); - if (!GetItemVECTOR (ifs, cbuf, tmp)) break; + if (!GetItemVector(ifs, cbuf, tmp)) break; EXHAUSTSPEC es = {(THRUSTER_HANDLE)m_thrusterGroupDef[THGROUP_ATT_BACK].ts[0], NULL, &tmp, NULL, 3, 0.39, 0, 0, NULL, EXHAUST_CONSTANTPOS}; AddExhaust (&es); } @@ -677,7 +678,7 @@ void Vessel::ReadGenericCaps (ifstream &ifs) if (m_thrusterGroupDef[THGROUP_ATT_FORWARD].ts.size()) { for (i = 0;; i++) { sprintf (cbuf, "LongAttRef1%d", i); - if (!GetItemVECTOR (ifs, cbuf, tmp)) break; + if (!GetItemVector(ifs, cbuf, tmp)) break; EXHAUSTSPEC es = {(THRUSTER_HANDLE)m_thrusterGroupDef[THGROUP_ATT_FORWARD].ts[0], NULL, &tmp, NULL, 3, 0.39, 0, 0, NULL, EXHAUST_CONSTANTPOS}; AddExhaust (&es); } @@ -685,7 +686,7 @@ void Vessel::ReadGenericCaps (ifstream &ifs) if (FindLine (ifs, "BEGIN_DOCKLIST")) { for (;;) { - Vector pos, dir, rot; + VECTOR3 pos, dir, rot; int n, ids_step; if (!ifs.getline (cbuf, 256) || !_strnicmp (cbuf, "END_DOCKLIST", 12)) break; n = sscanf (cbuf, "%lf%lf%lf%lf%lf%lf%lf%lf%lf%d", @@ -700,7 +701,7 @@ void Vessel::ReadGenericCaps (ifstream &ifs) } if (FindLine (ifs, "BEGIN_ATTACHMENT")) { - Vector pos, dir, rot; + VECTOR3 pos, dir, rot; char type; int n; bool toparent; @@ -845,7 +846,7 @@ const VesselBase *Vessel::GetSuperStructure () const // ============================================================== -void Vessel::RPlace (const Vector &rpos, const Vector &rvel) +void Vessel::RPlace (const VECTOR3 &rpos, const VECTOR3 &rvel) { if (supervessel) supervessel->RPlace (rpos, rvel, this); else RPlace_individual (rpos, rvel); @@ -853,7 +854,7 @@ void Vessel::RPlace (const Vector &rpos, const Vector &rvel) // ============================================================== -void Vessel::RPlace_individual (const Vector &rpos, const Vector &rvel) +void Vessel::RPlace_individual (const VECTOR3 &rpos, const VECTOR3 &rvel) { // this version enforces the repositioning of the vessel without reporting // to the supervessel @@ -877,7 +878,7 @@ void Vessel::RPlace_individual (const Vector &rpos, const Vector &rvel) // ============================================================== -void Vessel::SetGlobalOrientation (const Vector &arot) +void Vessel::SetGlobalOrientation (const VECTOR3 &arot) { if (supervessel) { supervessel->SetGlobalOrientation (arot, this); @@ -908,11 +909,11 @@ void Vessel::SetRotationMatrix (const Matrix &R) // ============================================================== -void Vessel::GetIntermediateMoments (Vector &acc, Vector &tau, const StateVectors &state, double tfrac, double dt) +void Vessel::GetIntermediateMoments (VECTOR3 &acc, VECTOR3 &tau, const StateVectors &state, double tfrac, double dt) { // TODO: Move this up to VesselBase - Vector F(Flin_add); // linear forces excluding gravitational and ground contact forces - Vector M(Amom_add); // angular momentum excluding gravity gradient torque and ground contact torques + VECTOR3 F = Flin_add; // linear forces excluding gravitational and ground contact forces + VECTOR3 M = Amom_add; // angular momentum excluding gravity gradient torque and ground contact torques collision_during_update |= AddSurfaceForces (&F, &M, &state, tfrac, dt, update_with_collision); // add ground contact forces and moments // note: we may want to remove aerodynamic forces from Flin_add/Amom_add and calculate @@ -924,14 +925,14 @@ void Vessel::GetIntermediateMoments (Vector &acc, Vector &tau, const StateVector // ============================================================== -void Vessel::GetIntermediateMoments_pert (Vector &acc, Vector &tau, +void Vessel::GetIntermediateMoments_pert (VECTOR3 &acc, VECTOR3 &tau, const StateVectors &state_rel, double tfrac, double dt, const CelestialBody *cbody) { StateVectors state(state_rel); state.pos += cbody->InterpolatePosition (tfrac); - Vector F(Flin_add); // linear forces excluding gravitational and ground contact forces - Vector M(Amom_add); // angular momentum excluding gravity gradient torque and ground contact torques + VECTOR3 F = Flin_add; // linear forces excluding gravitational and ground contact forces + VECTOR3 M = Amom_add; // angular momentum excluding gravity gradient torque and ground contact torques collision_during_update |= AddSurfaceForces (&F, &M, &state, tfrac, dt, update_with_collision); // add ground contact forces and moments // note: we may want to remove aerodynamic forces from Flin_add/Amom_add and calculate @@ -943,17 +944,17 @@ void Vessel::GetIntermediateMoments_pert (Vector &acc, Vector &tau, // ============================================================== -Vector Vessel::GetTorque () const +VECTOR3 Vessel::GetTorque () const { - static Vector F(0,0,0); - Vector M(Amom); + static VECTOR3 F{0, 0, 0}; + VECTOR3 M = Amom; AddSurfaceForces (&F, &M, s0, 0, 0); return RigidBody::GetTorque() + M/mass; } // ============================================================== -Vector Vessel::GetMomentumFlux () const +VECTOR3 Vessel::GetMomentumFlux () const { // map momentum flux into vessel frame return tmul (s0->R, g_psys->GetMomentumFlux (s0->pos)); @@ -961,7 +962,7 @@ Vector Vessel::GetMomentumFlux () const // ============================================================== -void Vessel::SetAngVel (const Vector &omega) +void Vessel::SetAngVel (const VECTOR3 &omega) { if (supervessel) supervessel->SetAngVel (omega, this); @@ -971,7 +972,7 @@ void Vessel::SetAngVel (const Vector &omega) // ============================================================== -void Vessel::SetAngVel_individual (const Vector &omega) +void Vessel::SetAngVel_individual (const VECTOR3 &omega) { RigidBody::SetAngVel (omega); } @@ -1148,7 +1149,7 @@ bool Vessel::SetTouchdownPoints (const TOUCHDOWNVTX *tdvtx, DWORD ntp) touchdown_vtx = new TOUCHDOWN_VTX[ntouchdown_vtx = ntp]; } for (i = 0; i < ntp; i++) { - touchdown_vtx[i].pos.Set (MakeVector(tdvtx[i].pos)); + touchdown_vtx[i].pos = tdvtx[i].pos; touchdown_vtx[i].stiffness = tdvtx[i].stiffness; touchdown_vtx[i].damping = tdvtx[i].damping; touchdown_vtx[i].mu = tdvtx[i].mu; @@ -1157,12 +1158,11 @@ bool Vessel::SetTouchdownPoints (const TOUCHDOWNVTX *tdvtx, DWORD ntp) // The rest of this function refers to the first 3 (primary) touchdown points // upward normal of touchdown plane - Vector tp[3]; - for (i = 0; i < 3; i++) - tp[i].Set (touchdown_vtx[i].pos); + VECTOR3 tp[3]; + for (i = 0; i < 3; i++) tp[i] = touchdown_vtx[i].pos; - touchdown_nm = crossp (tp[0] - (tp[1] + tp[2])*0.5, tp[2] - tp[1]); - double len = touchdown_nm.length(); + touchdown_nm = cross(tp[0] - (tp[1] + tp[2]) * 0.5, tp[2] - tp[1]); + double len = ::len(touchdown_nm); if (len > eps) touchdown_nm /= len; // normalise else return false; @@ -1176,16 +1176,16 @@ bool Vessel::SetTouchdownPoints (const TOUCHDOWNVTX *tdvtx, DWORD ntp) // elevation of CoM over ground when landed cog_elev = fabs(d/scl); - touchdown_cg.Set (-a*cog_elev/scl, -b*cog_elev/scl, -c*cog_elev/scl); + touchdown_cg = {-a * cog_elev / scl, -b * cog_elev / scl, -c * cog_elev / scl}; // precompute equilibrium suspension compression parameters // 1. Compute rotation matrix that rotates touchdown points into y=const plane - Vector ex((touchdown_vtx[2].pos-touchdown_vtx[1].pos).unit()); - Vector ez(crossp(ex,touchdown_nm)); + VECTOR3 ex = unit(touchdown_vtx[2].pos - touchdown_vtx[1].pos); + VECTOR3 ez = cross(ex, touchdown_nm); Matrix R(ex.x,ex.y,ex.z, touchdown_nm.x,touchdown_nm.y, touchdown_nm.z, ez.x,ez.y,ez.z); // 2. Compute the compression factors (actual compression length is given by factor*mg) // See Doc/Technotes/dynsurf.pdf for details - Vector tr[3]; + VECTOR3 tr[3]; a = b = c = d = e = f = 0.0; for (i = 0; i < 3; i++) { tr[i] = mul (R, touchdown_vtx[i].pos); @@ -1231,86 +1231,85 @@ void Vessel::SetSurfaceFrictionCoeff (double mlng, double mlat) // ============================================================== -bool Vessel::GetWeightVector (Vector &G) const +bool Vessel::GetWeightVector (VECTOR3 &G) const { if (!weight_valid) { - Weight.Set (tmul (s0->R, g_psys->Gacc (s0->pos, this, &gfielddata)) * mass); + Weight = tmul(s0->R, g_psys->Gacc(s0->pos, this, &gfielddata)) * mass; weight_valid = true; } - G.Set (Weight); + G = Weight; return true; } // ============================================================== -bool Vessel::GetThrustVector (Vector &T) const +bool Vessel::GetThrustVector (VECTOR3 &T) const { - if (m_bThrustEngaged) T.Set (Thrust); - else T.Set (0,0,0); + T = m_bThrustEngaged ? Thrust : VECTOR3{ }; return m_bThrustEngaged; } // ============================================================== -bool Vessel::GetLiftVector (Vector &L) const +bool Vessel::GetLiftVector (VECTOR3 &L) const { if (!Lift) { - L.Set (0, 0, 0); + L = {0, 0, 0}; return false; } else { double v0 = std::hypot (sp.airvel_ship.y, sp.airvel_ship.z); double scale = (v0 ? Lift/v0 : 0.0); - L.Set (0, sp.airvel_ship.z*scale, -sp.airvel_ship.y*scale); + L = {0, sp.airvel_ship.z * scale, -sp.airvel_ship.y * scale}; return true; } } // ============================================================== -bool Vessel::GetDragVector (Vector &D) const +bool Vessel::GetDragVector (VECTOR3 &D) const { if (!Drag) { - D.Set (0, 0, 0); + D = {0, 0, 0}; return false; } else { - double v0 = -sp.airvel_ship.length(); - D.Set (sp.airvel_ship * (v0 ? Drag/v0 : 0.0)); + double v0 = -len(sp.airvel_ship); + D = sp.airvel_ship * (v0 ? Drag / v0 : 0.0); return true; } } // ============================================================== -bool Vessel::GetForceVector (Vector &F) const +bool Vessel::GetForceVector (VECTOR3 &F) const { // Obtain total force vector from acceleration vector // This also captures ground contact effects, docking, etc. - F.Set (tmul (s0->R, acc) * mass); - //F.Set (tmul (s0->R, (s0->vel - prvel) * (mass*td.iSimDT))); + F = tmul(s0->R, acc) * mass; + //F = tmul(s0->R, (s0->vel - prvel) * (mass*td.iSimDT)); return true; } // ============================================================== -bool Vessel::GetTorqueVector (Vector &M) const +bool Vessel::GetTorqueVector (VECTOR3 &M) const { if (!torque_valid) { - Torque.Set (GetTorque()); + Torque = GetTorque(); torque_valid = true; } - M.Set (Torque); + M = Torque; return true; } // ============================================================== -ThrustSpec *Vessel::CreateThruster (const Vector &pos, const Vector &dir, double maxth0, +ThrustSpec *Vessel::CreateThruster (const VECTOR3 &pos, const VECTOR3 &dir, double maxth0, TankSpec *ts, double isp0, double isp_ref, double p_ref) { ThrustSpec* thruster = new ThrustSpec; - thruster->ref = MakeVECTOR3(pos); - thruster->dir = MakeVECTOR3(dir.unit()); + thruster->ref = pos; + thruster->dir = unit(dir); thruster->maxth0 = maxth0; thruster->tank = ts; thruster->isp0 = (isp0 > 0.0 ? isp0 : m_defaultIsp); @@ -1371,37 +1370,36 @@ bool Vessel::DelThruster (ThrustSpec *ts) // ============================================================== -void Vessel::ShiftThrusters (const Vector &shift) +void Vessel::ShiftThrusters (const VECTOR3 &shift) { - for (auto it = m_thruster.begin(); it != m_thruster.end(); it++) - (*it)->ref += MakeVECTOR3(shift); + for (auto& th : m_thruster) th->ref += shift; } // ============================================================== -Vector Vessel::GetThrusterForce (const ThrustSpec *ts) const +VECTOR3 Vessel::GetThrusterForce (const ThrustSpec *ts) const { if (!ts->tank || !ts->tank->mass) { - return Vector(0,0,0); + return {0, 0, 0}; } else { double th = ts->maxth0 * ts->level; th *= ThrusterAtmScale (ts, sp.atmp); - return MakeVector(ts->dir *th); + return ts->dir * th; } } // ============================================================== -void Vessel::GetThrusterMoment (const ThrustSpec *ts, Vector &F, Vector &T) const +void Vessel::GetThrusterMoment (const ThrustSpec *ts, VECTOR3 &F, VECTOR3 &T) const { if (!ts->tank || !ts->tank->mass) { - F.Set(0,0,0); - T.Set(0,0,0); + F = {0, 0, 0}; + T = {0, 0, 0}; } else { double th = ts->maxth0 * ts->level; th *= ThrusterAtmScale (ts, sp.atmp); - F = MakeVector(ts->dir * th); - T = crossp (F, MakeVector(ts->ref)); + F = ts->dir * th; + T = cross(F, ts->ref); } } @@ -1521,10 +1519,10 @@ ThrustGroupSpec *Vessel::CreateThrusterGroup (ThrustSpec **ts, DWORD nts, THGROU } // rotational attitude mode: calculate max. angular momentum if (thgt >= THGROUP_ATT_PITCHUP && thgt <= THGROUP_ATT_BANKRIGHT) { - Vector M; + VECTOR3 M; for (i = 0; i < nts; i++) - M += MakeVector(crossp (ts[i]->dir * ts[i]->maxth0, ts[i]->ref)); - max_angular_moment[thgt-THGROUP_ATT_PITCHUP] = M.length(); + M += cross(ts[i]->dir * ts[i]->maxth0, ts[i]->ref); + max_angular_moment[thgt-THGROUP_ATT_PITCHUP] = len(M); } return tgs; @@ -1701,27 +1699,26 @@ double Vessel::GetThrusterGroupMaxth(THGROUP_TYPE thgt) const // ============================================================== -Vector Vessel::GetThrusterGroupForce (THGROUP_TYPE thgt) const +VECTOR3 Vessel::GetThrusterGroupForce (THGROUP_TYPE thgt) const { const ThrustGroupSpec* tgs = GetThrusterGroup(thgt); - return (tgs ? GetThrusterGroupForce(tgs) : Vector(0, 0, 0)); + return tgs ? GetThrusterGroupForce(tgs) : VECTOR3{ }; } // ============================================================== -Vector Vessel::GetThrusterGroupForce (const ThrustGroupSpec *tgs) const +VECTOR3 Vessel::GetThrusterGroupForce (const ThrustGroupSpec *tgs) const { dCHECK(tgs, "Zero ThrustGroupSpec pointer not permitted.") - Vector F; - for (auto it = tgs->ts.begin(); it != tgs->ts.end(); it++) - F += GetThrusterForce (*it); + VECTOR3 F; + for (auto& th : tgs->ts) F += GetThrusterForce(th); return F; } // ============================================================== -AirfoilSpec *Vessel::CreateAirfoil (AIRFOIL_ORIENTATION align, const Vector &ref, AirfoilCoeffFunc cf, double c, double S, double A) +AirfoilSpec *Vessel::CreateAirfoil (AIRFOIL_ORIENTATION align, const VECTOR3 &ref, AirfoilCoeffFunc cf, double c, double S, double A) { AirfoilSpec *af, **tmp = new AirfoilSpec*[nairfoil+1]; TRACENEW if (nairfoil) { @@ -1733,7 +1730,7 @@ AirfoilSpec *Vessel::CreateAirfoil (AIRFOIL_ORIENTATION align, const Vector &ref af = airfoil[nairfoil++] = new AirfoilSpec; TRACENEW af->version = 0; af->align = align; - af->ref.Set (ref); + af->ref = ref; af->cf = cf; af->context = 0; af->c = c; @@ -1744,7 +1741,7 @@ AirfoilSpec *Vessel::CreateAirfoil (AIRFOIL_ORIENTATION align, const Vector &ref // ============================================================== -AirfoilSpec *Vessel::CreateAirfoil (AIRFOIL_ORIENTATION align, const Vector &ref, AirfoilCoeffFuncEx cf, void *context, double c, double S, double A) +AirfoilSpec *Vessel::CreateAirfoil (AIRFOIL_ORIENTATION align, const VECTOR3 &ref, AirfoilCoeffFuncEx cf, void *context, double c, double S, double A) { AirfoilSpec *af, **tmp = new AirfoilSpec*[nairfoil+1]; TRACENEW if (nairfoil) { @@ -1756,7 +1753,7 @@ AirfoilSpec *Vessel::CreateAirfoil (AIRFOIL_ORIENTATION align, const Vector &ref af = airfoil[nairfoil++] = new AirfoilSpec; TRACENEW af->version = 1; af->align = align; - af->ref.Set (ref); + af->ref = ref; af->cf = (AirfoilCoeffFunc)cf; af->context = context; af->c = c; @@ -1771,7 +1768,7 @@ bool Vessel::GetAirfoilParam (AirfoilSpec *af, VECTOR3 *ref, AirfoilCoeffFunc *c { for (DWORD i = 0; i < nairfoil; i++) { if (af == airfoil[i]) { - if (ref) *ref = MakeVECTOR3(af->ref); + if (ref) *ref = af->ref; if (cf) *cf = af->cf; if (context) *context = af->context; if (c) *c = af->c; @@ -1785,9 +1782,9 @@ bool Vessel::GetAirfoilParam (AirfoilSpec *af, VECTOR3 *ref, AirfoilCoeffFunc *c // ============================================================== -void Vessel::EditAirfoil (AirfoilSpec *af, DWORD flag, const Vector &ref, AirfoilCoeffFunc cf, double c, double S, double A) +void Vessel::EditAirfoil (AirfoilSpec *af, DWORD flag, const VECTOR3 &ref, AirfoilCoeffFunc cf, double c, double S, double A) { - if (flag & 0x01) af->ref.Set (ref); + if (flag & 0x01) af->ref= ref; if (flag & 0x02) af->cf = cf; if (flag & 0x04) af->c = c; if (flag & 0x08) af->S = S; @@ -1837,11 +1834,11 @@ void Vessel::ClearAirfoilDefinitions () // ============================================================== -CtrlsurfSpec *Vessel::CreateControlSurface (AIRCTRL_TYPE ctrl, double area, double dCl, const Vector &ref, int axis, double delay, UINT anim) +CtrlsurfSpec *Vessel::CreateControlSurface (AIRCTRL_TYPE ctrl, double area, double dCl, const VECTOR3 &ref, int axis, double delay, UINT anim) { CtrlsurfSpec *css = new CtrlsurfSpec; TRACENEW css->ctrl = ctrl; - css->ref.Set (ref); + css->ref = ref; css->area = area; css->dCl = dCl; css->anim = anim; @@ -1965,10 +1962,10 @@ void Vessel::ApplyControlSurfaceLevels () // ============================================================== -void Vessel::CreateVariableDragElement (const double *drag, double factor, const Vector &ref) +void Vessel::CreateVariableDragElement (const double *drag, double factor, const VECTOR3 &ref) { DragElementSpec *des = new DragElementSpec; TRACENEW - des->ref.Set (ref); + des->ref = ref; des->drag = drag; des->factor = factor; @@ -2059,7 +2056,7 @@ bool Vessel::SetMaxThrust_old (ENGINETYPE eng, double maxth) switch (eng) { case ENGINE_MAIN: if (!m_thrusterGroupDef[THGROUP_MAIN].ts.size()) { - ts = CreateThruster (Vector(0,0,0), Vector(0,0,1), maxth, tnk, m_defaultIsp); + ts = CreateThruster({0, 0, 0}, {0, 0, 1}, maxth, tnk, m_defaultIsp); CreateThrusterGroup (&ts, 1, THGROUP_MAIN); return true; } else if (m_thrusterGroupDef[THGROUP_MAIN].ts.size() == 1) { @@ -2069,7 +2066,7 @@ bool Vessel::SetMaxThrust_old (ENGINETYPE eng, double maxth) } else return false; case ENGINE_RETRO: if (!m_thrusterGroupDef[THGROUP_RETRO].ts.size()) { - ts = CreateThruster (Vector(0,0,0), Vector(0,0,-1), maxth, tnk, m_defaultIsp); + ts = CreateThruster({0, 0, 0}, {0, 0, -1}, maxth, tnk, m_defaultIsp); CreateThrusterGroup (&ts, 1, THGROUP_RETRO); return true; } else if (m_thrusterGroupDef[THGROUP_RETRO].ts.size() == 1) { @@ -2079,7 +2076,7 @@ bool Vessel::SetMaxThrust_old (ENGINETYPE eng, double maxth) } else return false; case ENGINE_HOVER: if (!m_thrusterGroupDef[THGROUP_HOVER].ts.size()) { - ts = CreateThruster (Vector(0,0,0), Vector(0,1,0), maxth, tnk, m_defaultIsp); + ts = CreateThruster({0, 0, 0}, {0, 1, 0}, maxth, tnk, m_defaultIsp); CreateThrusterGroup (&ts, 1, THGROUP_HOVER); return true; } else if (m_thrusterGroupDef[THGROUP_HOVER].ts.size() == 1) { @@ -2099,38 +2096,38 @@ void Vessel::CreateDefaultAttitudeSet (double maxth) TankSpec *tnk = (ntank ? tank[0] : 0); // linear groups - ts_lin = CreateThruster (Vector (0,0,0), Vector (0, 1,0), maxth, tnk, m_defaultIsp); + ts_lin = CreateThruster({0, 0, 0}, { 0, 1, 0}, maxth, tnk, m_defaultIsp); CreateThrusterGroup (&ts_lin, 1, THGROUP_ATT_UP); - ts_lin = CreateThruster (Vector (0,0,0), Vector (0,-1,0), maxth, tnk, m_defaultIsp); + ts_lin = CreateThruster({0, 0, 0}, { 0,-1, 0}, maxth, tnk, m_defaultIsp); CreateThrusterGroup (&ts_lin, 1, THGROUP_ATT_DOWN); - ts_lin = CreateThruster (Vector (0,0,0), Vector (-1,0,0), maxth, tnk, m_defaultIsp); + ts_lin = CreateThruster({0, 0, 0}, {-1, 0, 0}, maxth, tnk, m_defaultIsp); CreateThrusterGroup (&ts_lin, 1, THGROUP_ATT_LEFT); - ts_lin = CreateThruster (Vector (0,0,0), Vector ( 1,0,0), maxth, tnk, m_defaultIsp); + ts_lin = CreateThruster({0, 0, 0}, { 1, 0, 0}, maxth, tnk, m_defaultIsp); CreateThrusterGroup (&ts_lin, 1, THGROUP_ATT_RIGHT); - ts_lin = CreateThruster (Vector (0,0,0), Vector (0,0, 1), maxth, tnk, m_defaultIsp); + ts_lin = CreateThruster({0, 0, 0}, { 0, 0, 1}, maxth, tnk, m_defaultIsp); CreateThrusterGroup (&ts_lin, 1, THGROUP_ATT_FORWARD); - ts_lin = CreateThruster (Vector (0,0,0), Vector (0,0,-1), maxth, tnk, m_defaultIsp); + ts_lin = CreateThruster({0, 0, 0}, { 0, 0,-1}, maxth, tnk, m_defaultIsp); CreateThrusterGroup (&ts_lin, 1, THGROUP_ATT_BACK); // rotational groups maxth *= 0.5; // since each group has 2 thrusters - ts_rot[0] = CreateThruster (Vector(0,0, size), Vector(0, 1,0), maxth, tnk, m_defaultIsp); - ts_rot[1] = CreateThruster (Vector(0,0,-size), Vector(0,-1,0), maxth, tnk, m_defaultIsp); + ts_rot[0] = CreateThruster({ 0, 0, size}, { 0, 1, 0}, maxth, tnk, m_defaultIsp); + ts_rot[1] = CreateThruster({ 0, 0,-size}, { 0,-1, 0}, maxth, tnk, m_defaultIsp); CreateThrusterGroup (ts_rot, 2, THGROUP_ATT_PITCHUP); - ts_rot[0] = CreateThruster (Vector(0,0, size), Vector(0,-1,0), maxth, tnk, m_defaultIsp); - ts_rot[1] = CreateThruster (Vector(0,0,-size), Vector(0, 1,0), maxth, tnk, m_defaultIsp); + ts_rot[0] = CreateThruster({ 0, 0, size}, { 0,-1, 0}, maxth, tnk, m_defaultIsp); + ts_rot[1] = CreateThruster({ 0, 0,-size}, { 0, 1, 0}, maxth, tnk, m_defaultIsp); CreateThrusterGroup (ts_rot, 2, THGROUP_ATT_PITCHDOWN); - ts_rot[0] = CreateThruster (Vector(0,0, size), Vector(-1,0,0), maxth, tnk, m_defaultIsp); - ts_rot[1] = CreateThruster (Vector(0,0,-size), Vector( 1,0,0), maxth, tnk, m_defaultIsp); + ts_rot[0] = CreateThruster({ 0, 0, size}, {-1, 0, 0}, maxth, tnk, m_defaultIsp); + ts_rot[1] = CreateThruster({ 0, 0,-size}, { 1, 0, 0}, maxth, tnk, m_defaultIsp); CreateThrusterGroup (ts_rot, 2, THGROUP_ATT_YAWLEFT); - ts_rot[0] = CreateThruster (Vector(0,0, size), Vector( 1,0,0), maxth, tnk, m_defaultIsp); - ts_rot[1] = CreateThruster (Vector(0,0,-size), Vector(-1,0,0), maxth, tnk, m_defaultIsp); + ts_rot[0] = CreateThruster({ 0, 0, size}, { 1, 0, 0}, maxth, tnk, m_defaultIsp); + ts_rot[1] = CreateThruster({ 0, 0,-size}, {-1, 0, 0}, maxth, tnk, m_defaultIsp); CreateThrusterGroup (ts_rot, 2, THGROUP_ATT_YAWRIGHT); - ts_rot[0] = CreateThruster (Vector( size,0,0), Vector(0, 1,0), maxth, tnk, m_defaultIsp); - ts_rot[1] = CreateThruster (Vector(-size,0,0), Vector(0,-1,0), maxth, tnk, m_defaultIsp); + ts_rot[0] = CreateThruster({ size, 0, 0}, { 0, 1, 0}, maxth, tnk, m_defaultIsp); + ts_rot[1] = CreateThruster({-size, 0, 0}, { 0,-1, 0}, maxth, tnk, m_defaultIsp); CreateThrusterGroup (ts_rot, 2, THGROUP_ATT_BANKLEFT); - ts_rot[0] = CreateThruster (Vector(-size,0,0), Vector(0, 1,0), maxth, tnk, m_defaultIsp); - ts_rot[1] = CreateThruster (Vector( size,0,0), Vector(0,-1,0), maxth, tnk, m_defaultIsp); + ts_rot[0] = CreateThruster({-size, 0, 0}, { 0, 1, 0}, maxth, tnk, m_defaultIsp); + ts_rot[1] = CreateThruster({ size, 0, 0}, { 0,-1, 0}, maxth, tnk, m_defaultIsp); CreateThrusterGroup (ts_rot, 2, THGROUP_ATT_BANKRIGHT); } @@ -2162,7 +2159,7 @@ UINT Vessel::AddExhaust (EXHAUSTSPEC *spec) es->flags &= ~EXHAUST_CONSTANTPOS; } else if (!es->lpos || (es->flags & EXHAUST_CONSTANTPOS)) { es->lpos = new VECTOR3; - *es->lpos = (spec->lpos ? *spec->lpos : _V(0,0,0)); + *es->lpos = (spec->lpos ? *spec->lpos : VECTOR3{0, 0, 0}); es->flags |= EXHAUST_CONSTANTPOS; } @@ -2171,7 +2168,7 @@ UINT Vessel::AddExhaust (EXHAUSTSPEC *spec) es->flags &= ~EXHAUST_CONSTANTDIR; } else if (!es->ldir || (es->flags & EXHAUST_CONSTANTDIR)) { es->ldir = new VECTOR3; - *es->ldir = (spec->ldir ? *spec->ldir : _V(0,0,1)); + *es->ldir = (spec->ldir ? *spec->ldir : VECTOR3{0,0,1}); es->flags |= EXHAUST_CONSTANTDIR; } @@ -2212,7 +2209,7 @@ bool Vessel::DelExhaust (UINT idx) // ============================================================== -oapi::ParticleStream *Vessel::AddParticleStream (PARTICLESTREAMSPEC *pss, const Vector &pos, const Vector &dir, double *lvl) +oapi::ParticleStream *Vessel::AddParticleStream (PARTICLESTREAMSPEC *pss, const VECTOR3 &pos, const VECTOR3 &dir, double *lvl) { if (!g_pOrbiter->Cfg()->CfgVisualPrm.bParticleStreams) return 0; oapi::GraphicsClient *gc = g_pOrbiter->GetGraphicsClient (); @@ -2224,13 +2221,13 @@ oapi::ParticleStream *Vessel::AddParticleStream (PARTICLESTREAMSPEC *pss, const delete []contrail; } contrail = tmp; - contrail[ncontrail] = gc->clbkCreateExhaustStream (pss, (OBJHANDLE)this, lvl, MakeVECTOR3(pos), MakeVECTOR3(-dir)); + contrail[ncontrail] = gc->clbkCreateExhaustStream(pss, (OBJHANDLE)this, lvl, pos, -dir); return contrail[ncontrail++]; } // ============================================================== -oapi::ParticleStream *Vessel::AddExhaustStream (ThrustSpec *ts, PARTICLESTREAMSPEC *pss, const Vector *pos, const Vector *dir) +oapi::ParticleStream *Vessel::AddExhaustStream (ThrustSpec *ts, PARTICLESTREAMSPEC *pss, const VECTOR3 *pos, const VECTOR3 *dir) { if (!g_pOrbiter->Cfg()->CfgVisualPrm.bParticleStreams) return 0; oapi::GraphicsClient *gc = g_pOrbiter->GetGraphicsClient (); @@ -2244,9 +2241,9 @@ oapi::ParticleStream *Vessel::AddExhaustStream (ThrustSpec *ts, PARTICLESTREAMSP contrail = tmp; contrail[ncontrail] = gc->clbkCreateExhaustStream (pss, (OBJHANDLE)this, &ts->level, &ts->ref, &ts->dir); if (pos) // local position reference - contrail[ncontrail]->SetFixedPos (MakeVECTOR3(*pos)); + contrail[ncontrail]->SetFixedPos(*pos); if (dir) // local direction reference - contrail[ncontrail]->SetFixedDir (MakeVECTOR3(*dir)); + contrail[ncontrail]->SetFixedDir(*dir); return contrail[ncontrail++]; } @@ -2526,7 +2523,7 @@ double Vessel::GetPropellantFlowrate (const TankSpec *ts) const // ============================================================== -PortSpec *Vessel::CreateDock (const Vector &pos, const Vector &dir, const Vector &rot) +PortSpec *Vessel::CreateDock (const VECTOR3 &pos, const VECTOR3 &dir, const VECTOR3 &rot) { PortSpec **tmp = new PortSpec*[ndock+1]; TRACENEW if (ndock) { @@ -2535,9 +2532,9 @@ PortSpec *Vessel::CreateDock (const Vector &pos, const Vector &dir, const Vector } dock = tmp; dock[ndock] = new PortSpec; TRACENEW - dock[ndock]->ref.Set (pos); - dock[ndock]->dir.Set (dir); - dock[ndock]->rot.Set (rot); + dock[ndock]->ref = pos; + dock[ndock]->dir = dir; + dock[ndock]->rot = rot; dock[ndock]->mate = 0; dock[ndock]->ids = 0; dock[ndock]->pending = 0; @@ -2547,16 +2544,16 @@ PortSpec *Vessel::CreateDock (const Vector &pos, const Vector &dir, const Vector // ============================================================== -void Vessel::SetDockParams (PortSpec *dock, const Vector &pos, const Vector &dir, const Vector &rot) +void Vessel::SetDockParams (PortSpec *dock, const VECTOR3 &pos, const VECTOR3 &dir, const VECTOR3 &rot) { - dock->ref.Set (pos); - dock->dir.Set (dir); - dock->rot.Set (rot); + dock->ref = pos; + dock->dir = dir; + dock->rot = rot; } // ============================================================== -void Vessel::ShiftDocks (const Vector &ofs) +void Vessel::ShiftDocks (const VECTOR3 &ofs) { for (DWORD i = 0; i < ndock; i++) SetDockParams (dock[i], dock[i]->ref+ofs, dock[i]->dir, dock[i]->rot); @@ -2663,7 +2660,7 @@ int Vessel::Dock (Vessel *target, DWORD mydid, DWORD tgtdid, DWORD mode) // error: we are already docked to the target (directly or indirectly) if (mode) { - Vector P; + VECTOR3 P; Matrix R; if (mode == 1) { // drag target to our current position RelDockingPos (target, mydid, tgtdid, P, R); @@ -2773,18 +2770,18 @@ void Vessel::UndockInteractive (const Vessel *exclude, double vsep) // ============================================================== -void Vessel::RelDockingPos (const Vessel *target, UINT mydid, UINT tgtdid, Vector &P, Matrix &R) +void Vessel::RelDockingPos (const Vessel *target, UINT mydid, UINT tgtdid, VECTOR3 &P, Matrix &R) { // Calculate the relative position 'P' and orientation 'R' of 'target' // in my reference frame, if we are docked between 'mydid' and 'tgtdid' // relative orientation - Vector as(target->dock[tgtdid]->dir); - Vector bs(target->dock[tgtdid]->rot); - Vector cs(crossp(as,bs)); - Vector at(-dock[mydid]->dir); - Vector bt( dock[mydid]->rot); - Vector ct(crossp(at,bt)); + VECTOR3 as = target->dock[tgtdid]->dir; + VECTOR3 bs = target->dock[tgtdid]->rot; + VECTOR3 cs = cross(as, bs); + VECTOR3 at = -dock[mydid]->dir; + VECTOR3 bt = dock[mydid]->rot; + VECTOR3 ct = cross(at, bt); double den = cs.x * (as.y*bs.z - as.z*bs.y) + cs.y * (as.z*bs.x - as.x*bs.z) + cs.z * (as.x*bs.y - as.y*bs.x); @@ -2817,11 +2814,11 @@ void Vessel::RelDockingPos (const Vessel *target, UINT mydid, UINT tgtdid, Vecto at.z * (bs.x*cs.y - bs.y*cs.x)) / den; // relative position - P.Set (dock[mydid]->ref - mul (R, target->dock[tgtdid]->ref)); + P = dock[mydid]->ref - mul(R, target->dock[tgtdid]->ref); } -AttachmentSpec *Vessel::CreateAttachment (bool toparent, const Vector &pos, const Vector &dir, const Vector &rot, const char *id, bool loose) +AttachmentSpec *Vessel::CreateAttachment (bool toparent, const VECTOR3 &pos, const VECTOR3 &dir, const VECTOR3 &rot, const char *id, bool loose) { AttachmentSpec *as; if (toparent) { // create attachment to parent vessel @@ -2841,9 +2838,9 @@ AttachmentSpec *Vessel::CreateAttachment (bool toparent, const Vector &pos, cons cattach = tmp; as = cattach[ncattach++] = new AttachmentSpec; TRACENEW } - as->ref.Set (pos); - as->dir.Set (dir); - as->rot.Set (rot); + as->ref = pos; + as->dir = dir; + as->rot = rot; as->toparent = toparent; as->loose = loose; as->mate = 0; @@ -2918,15 +2915,15 @@ void Vessel::ClearAttachments () } } -void Vessel::SetAttachmentParams (AttachmentSpec *as, const Vector &pos, const Vector &dir, const Vector &rot) +void Vessel::SetAttachmentParams (AttachmentSpec *as, const VECTOR3 &pos, const VECTOR3 &dir, const VECTOR3 &rot) { - Vector at(-as->dir); - Vector bt( as->rot); - Vector ct(crossp(at,bt)); + VECTOR3 at = -as->dir; + VECTOR3 bt = as->rot; + VECTOR3 ct = cross(at, bt); - as->ref.Set (pos); - as->dir.Set (dir); - as->rot.Set (rot); + as->ref = pos; + as->dir = dir; + as->rot = rot; if (as->mate) { if (as->toparent) { @@ -2935,12 +2932,12 @@ void Vessel::SetAttachmentParams (AttachmentSpec *as, const Vector &pos, const V UpdatePassive (); } else { Matrix R1(at.x, at.y, at.z, bt.x, bt.y, bt.z, ct.x, ct.y, ct.z); - at.Set (-as->dir), bt.Set (as->rot), ct.Set (crossp(at,bt)); + at = -as->dir; bt = as->rot; ct = cross(at, bt); Matrix R2(at.x, bt.x, ct.x, at.y, bt.y, ct.y, at.z, bt.z, ct.z); as->mate->attach_rrot.premul (R1); as->mate->attach_rrot.premul (R2); as->mate->attach_rrot.orthogonalise (++orthoaxis % 3); - as->mate->attach_rpos.Set (as->ref - mul (as->mate->attach_rrot, as->mate_attach->ref)); + as->mate->attach_rpos = as->ref - mul(as->mate->attach_rrot, as->mate_attach->ref); as->mate->UpdatePassive (); } } @@ -2991,16 +2988,16 @@ bool Vessel::DetachFromParent (double v) if (!attach || !proxybody) return false; // we are not attached to any parent Vessel *prnt = attach->mate; - Vector vel(s0->vel); + VECTOR3 vel = s0->vel; cbody = prnt->cbody; - vel += mul (prnt->GRot(), crossp (attach_rpos, prnt->s0->omega)); + vel += mul(prnt->GRot(), cross(attach_rpos, prnt->s0->omega)); if (v) { // ejection velocity vel += mul (s0->R, tmul (attach_rrot, attach->mate_attach->dir)) * v; } //fstatus = FLIGHTSTATUS_FREEFLIGHT; RPlace (s0->pos, vel); UpdateProxies (); - sp.alt = s0->pos.dist (proxybody->GPos()) - proxybody->Size(); + sp.alt = dist(s0->pos, proxybody->GPos()) - proxybody->Size(); UpdateSurfParams (); bSurfaceContact = CheckSurfaceContact(); attach->mate = 0; @@ -3022,17 +3019,17 @@ void Vessel::InitAttachmentToParent (AttachmentSpec *asc, bool allow_loose) if (allow_loose && asp->loose) { // freeze current relative child orientation - attach_rrot.Set (GRot()); + attach_rrot = GRot(); attach_rrot.tpremul (asc->mate->GRot()); } else { - Vector as(asc->dir); - Vector bs(asc->rot); - Vector cs(crossp(as,bs)); - Vector at(-asp->dir); - Vector bt( asp->rot); - Vector ct(crossp(at,bt)); + VECTOR3 as = asc->dir; + VECTOR3 bs = asc->rot; + VECTOR3 cs = cross(as, bs); + VECTOR3 at = -asp->dir; + VECTOR3 bt = asp->rot; + VECTOR3 ct = cross(at, bt); double den = cs.x * (as.y*bs.z - as.z*bs.y) + cs.y * (as.z*bs.x - as.x*bs.z) + cs.z * (as.x*bs.y - as.y*bs.x); @@ -3066,7 +3063,7 @@ void Vessel::InitAttachmentToParent (AttachmentSpec *asc, bool allow_loose) } // child position relative to parent - attach_rpos.Set (asp->ref - mul (attach_rrot, asc->ref)); + attach_rpos = asp->ref - mul(attach_rrot, asc->ref); attach = asc; } @@ -3094,7 +3091,7 @@ DWORD Vessel::GetAttachmentIndex (AttachmentSpec *as) const // ============================================================== -void Vessel::ShiftAttachments (const Vector &ofs) +void Vessel::ShiftAttachments (const VECTOR3 &ofs) { DWORD i; for (i = 0; i < npattach; i++) @@ -3346,34 +3343,34 @@ void Vessel::InitLanded (Planet *planet, double lng, double lat, double dir, con { dCHECK(!g_bStateUpdate, "Vessel::InitLanded must not be called during state update") // not valid during update phase - Vector nml; + VECTOR3 nml; int i; if (!hrot) { // Calculate compressed touchdown points at equilibrium double prad = planet->Size(); double mg = Ggrav * planet->Mass() * mass / (prad*prad); // approximate vessel weight - Vector tp_comp[3]; + VECTOR3 tp_comp[3]; for (i = 0; i < 3; i++) tp_comp[i] = touchdown_vtx[i].pos + touchdown_nm*(touchdown_vtx[i].compression*mg); // equilibrium touchdown plane normal - nml = crossp (tp_comp[0]-(tp_comp[1]+tp_comp[2])*0.5, tp_comp[2]-tp_comp[1]).unit(); + nml = unit(cross(tp_comp[0] - (tp_comp[1] + tp_comp[2]) * 0.5, tp_comp[2] - tp_comp[1])); // Distance of origin from compressed touchdown plane - cgelev = dotp (nml, -tp_comp[0]); + cgelev = dot(nml, -tp_comp[0]); } else { double slng = sin(lng), clng = cos(lng); double slat = sin(lat), clat = cos(lat); Matrix L2H (-slng,0,clng, clat*clng,slat,clat*slng, -slat*clng,clat,-slat*slng); - nml = tmul (*hrot, tmul (L2H, Vector(0,1,0))); + nml = tmul(*hrot, tmul(L2H, VECTOR3{0, 1, 0})); } proxybody = proxyplanet = planet; sp.SetLanded (lng, lat, cgelev, dir, nml, planet); if (hrot) { - land_rot.Set (*hrot); + land_rot = *hrot; } else { double sdir = sin(dir), cdir = cos(dir); planet->EquatorialToLocal (sp.slng, sp.clng, sp.slat, sp.clat, sp.rad, sp.ploc); @@ -3401,12 +3398,12 @@ void Vessel::InitLanded (Planet *planet, double lng, double lat, double dir, con } double vground = Pi2 * sp.rad * sp.clat / planet->RotT(); - s0->vel.Set (-vground*sp.slng, 0.0, vground*sp.clng); - s0->pos.Set (mul (planet->GRot(), sp.ploc) + planet->GPos()); - s0->vel.Set (mul (planet->GRot(), s0->vel) + planet->GVel()); - rvel_base.Set (s0->vel); - rvel_add.Set (0,0,0); - Amom.Set (0,0,0); // this is not quite true since the planet rotates ... + s0->vel = {-vground * sp.slng, 0.0, vground * sp.clng}; + s0->pos = mul(planet->GRot(), sp.ploc) + planet->GPos(); + s0->vel = mul(planet->GRot(), s0->vel) + planet->GVel(); + rvel_base = s0->vel; + rvel_add = {0, 0, 0}; + Amom = {0, 0, 0}; // this is not quite true since the planet rotates ... s0->Q.Set (land_rot); s0->Q.premul (planet->GQ()); s0->R.Set (s0->Q); @@ -3434,12 +3431,12 @@ void Vessel::InitLanded (Planet *planet, double lng, double lat, double dir, con void Vessel::InitDocked (const Vessel *vessel, int port) { if (!ndock) return; // problems! - Vector as(dock[0]->dir); - Vector bs(dock[0]->rot); - Vector cs(crossp(as,bs)); - Vector at(vessel->dock[0]->dir); - Vector bt(vessel->dock[0]->rot); - Vector ct(crossp(at,bt)); + VECTOR3 as = dock[0]->dir; + VECTOR3 bs = dock[0]->rot; + VECTOR3 cs = cross(as, bs); + VECTOR3 at = vessel->dock[0]->dir; + VECTOR3 bt = vessel->dock[0]->rot; + VECTOR3 ct = cross(at, bt); double den = cs.x * (as.y*bs.z - as.z*bs.y) + cs.y * (as.z*bs.x - as.x*bs.z) + cs.z * (as.x*bs.y - as.y*bs.x); @@ -3472,7 +3469,7 @@ void Vessel::InitDocked (const Vessel *vessel, int port) at.z * (bs.x*cs.y - bs.y*cs.x)) / den; // can land_rot be expressed directly in quaternion representation? - Vector dockpos; + VECTOR3 dockpos; vessel->LocalToGlobal (vessel->dock[0]->ref, dockpos); s0->Q.Set (land_rot); s0->Q.premul (vessel->GQ()); @@ -3481,7 +3478,7 @@ void Vessel::InitDocked (const Vessel *vessel, int port) fstatus = FLIGHTSTATUS_FREEFLIGHT; } -void Vessel::InitOrbiting (const Vector &relr, const Vector &relv, const Vector &rot, const Vector *_vrot) +void Vessel::InitOrbiting (const VECTOR3 &relr, const VECTOR3 &relv, const VECTOR3 &rot, const VECTOR3 *_vrot) { cpos = relr, cvel = relv; @@ -3498,7 +3495,7 @@ void Vessel::InitOrbiting (const Vector &relr, const Vector &relv, const Vector int reslvl = (int)(32.0-log(max(alt0,100.0))*LOG2); elev = emgr->Elevation (lat, lng, reslvl, &etile); } else { - rad = cpos.length(); + rad = len(cpos); } if (rad < cbody->Size() + elev) { double scale = (cbody->Size() + elev) / rad; @@ -3511,7 +3508,7 @@ void Vessel::InitOrbiting (const Vector &relr, const Vector &relv, const Vector s0->R.Set (rot); s0->Q.Set (s0->R); - if (_vrot) s0->omega.Set (*_vrot); + if (_vrot) s0->omega = *_vrot; RPlace(cpos + cbody->GPos(), cvel + cbody->GVel()); } @@ -3690,10 +3687,10 @@ int Vessel::ConsumeBufferedKey (DWORD key, bool down, char *kstate) // superstructure CG in vessel coordinates and return true. // Otherwise: set 'cg' to (0,0,0) and return false -bool Vessel::GetSuperStructCG (Vector &cg) const +bool Vessel::GetSuperStructCG (VECTOR3 &cg) const { if (!supervessel) { - cg.Set(0,0,0); + cg = {0, 0, 0}; return false; } else { supervessel->GetCG (this, cg); @@ -3708,13 +3705,13 @@ double Vessel::MaxAngularMoment (int axis) const dCHECK(axis >= 0 && axis < 6, "Invalid axis index.") if (!supervessel) return max_angular_moment[axis]; - Vector vcg; - VECTOR3 M = {0,0,0}; + VECTOR3 vcg; supervessel->GetCG (this, vcg); const ThrustGroupSpec *tgs = &m_thrusterGroupDef[THGROUP_ATT_PITCHUP+axis]; - for (auto it = tgs->ts.begin(); it != tgs->ts.end(); it++) - M += crossp ((*it)->dir * (*it)->maxth0, (*it)->ref-MakeVECTOR3(vcg)); - return length (M); + + VECTOR3 M; + for (auto& th : tgs->ts) M += cross(th->dir * th->maxth0, th->ref - vcg); + return len(M); } // ======================================================================= @@ -3757,7 +3754,7 @@ void Vessel::UpdateBodyForces () void Vessel::UpdateThrustForces () { UINT j; - Vector F; + VECTOR3 F; // Navigation computer sequences if (navmode) { @@ -3765,14 +3762,14 @@ void Vessel::UpdateThrustForces () int navmode_core = (modIntf.v->Version() >= 3 ? ((VESSEL4*)modIntf.v)->clbkNavProcess(navmode) : navmode); // allow module to process the navigation modes itself - Vector fpmi, *fullpmi; + VECTOR3 fpmi, *fullpmi; if (supervessel) { fullpmi = &fpmi; supervessel->GetPMI (this, fpmi); } else { fullpmi = &pmi; } - //const Vector *fullpmi = (supervessel ? supervessel->GetPMI() : &pmi); + //const VECTOR3 *fullpmi = (supervessel ? supervessel->GetPMI() : &pmi); double mam[6]; for (int i = 0; i < 6; i++) mam[i] = MaxAngularMoment(i) * 10.0; @@ -3812,7 +3809,7 @@ void Vessel::UpdateThrustForces () } //if (finished && ++killrot_delay > 8) // add a delay to improve performance at high time acceleration - if (s0->omega.length() < 1e-5) + if (len(s0->omega) < 1e-5) ClrNavMode (NAVMODE_KILLROT); //sprintf (DBG_MSG, "vrot: x=%e, y=%e, z=%e", vrot.x, vrot.y, vrot.z); @@ -3846,15 +3843,15 @@ void Vessel::UpdateThrustForces () // "turn prograde/retrograde/normal/antinormal" navcomp mode if (navmode_core & (NAVBIT_PROGRADE|NAVBIT_RETROGRADE|NAVBIT_NORMAL|NAVBIT_ANTINORMAL)) { double v1, dth; - Vector tgtdir; + VECTOR3 tgtdir; if (navmode_core & (NAVBIT_PROGRADE|NAVBIT_RETROGRADE)) { - tgtdir.Set (tmul (GRot(), GVel() - cbody->GVel())); // prograde direction in ship coordinates + tgtdir = tmul(GRot(), GVel() - cbody->GVel()); // prograde direction in ship coordinates if (navmode_core & NAVBIT_RETROGRADE) tgtdir = -tgtdir; } else { - tgtdir.Set (tmul (GRot(), crossp (GVel()-cbody->GVel(), GPos()-cbody->GPos()))); // remember left-handed system + tgtdir = tmul(GRot(), cross(GVel() - cbody->GVel(), GPos() - cbody->GPos())); // remember left-handed system if (navmode_core & NAVBIT_ANTINORMAL) tgtdir = -tgtdir; } - tgtdir.unify(); + tgtdir = unit(tgtdir); const double dvmax = 5.0*RAD; // max change in angular velocity [rad/s] const double alpha0 = 20.0*RAD; // angular distance from target at which thrust is being reduced @@ -3874,8 +3871,7 @@ void Vessel::UpdateThrustForces () else SetThrusterGroupOverride (THGROUP_ATT_YAWRIGHT, min (-dth, 0.4)); - tgtdir.Set (tmul (GRot(), GPos()- cbody->GPos())); - tgtdir.unify(); + tgtdir = unit(tmul(GRot(), GPos() - cbody->GPos())); v1 = asin(tgtdir.y) * ((navmode_core & (NAVBIT_PROGRADE|NAVBIT_NORMAL)) ? -f0:f0); if (v1 >= 0.0) dth = (min (v1, dvmax)-s0->omega.z)/max_angular_moment[5]; else dth = (max (v1,-dvmax)-s0->omega.z)/max_angular_moment[4]; @@ -3900,7 +3896,7 @@ void Vessel::UpdateThrustForces () // update thruster-induced forces m_bThrustEngaged = false; - Thrust.Set (0,0,0); + Thrust = {0, 0, 0}; for (auto it = m_thruster.begin(); it != m_thruster.end(); it++) { ThrustSpec* thruster = *it; if (thruster->level = max (0.0, min (1.0, thruster->level_permanent + thruster->level_override))) { @@ -3911,9 +3907,9 @@ void Vessel::UpdateThrustForces () if (ts->mass < 0.0) ts->mass = 0.0; } th *= ThrusterAtmScale (thruster, sp.atmp); // atmospheric thrust scaling - F = MakeVector(thruster->dir * th); + F = thruster->dir * th; Thrust += F; - Amom_add += crossp (F, MakeVector(thruster->ref)); + Amom_add += cross(F, thruster->ref); m_bThrustEngaged = true; } else thruster->level = thruster->level_permanent = 0.0; // no fuel } @@ -3963,16 +3959,12 @@ void Vessel::UpdateRadiationForces () double illum = IlluminationFactor(); if (!illum) return; // we are in shadow - Vector mflux = GetMomentumFlux() * illum; - Vector F, r; + VECTOR3 mflux = GetMomentumFlux() * illum; + VECTOR3 F, r; if (modIntf.v->Version() >= 2) { // retrieve customised force calculation - VECTOR3 Mflux, p, pos; - Mflux.x = mflux.x, Mflux.y = mflux.y, Mflux.z = mflux.z; - ((VESSEL3*)modIntf.v)->clbkGetRadiationForce (Mflux, p, pos); - F.x = p.x, F.y = p.y, F.z = p.z; - r.x = pos.x, r.y = pos.y, r.z = pos.z; + ((VESSEL3*)modIntf.v)->clbkGetRadiationForce(mflux, F, r); } else { // simplistic implementation double cs = size*size; @@ -3981,7 +3973,7 @@ void Vessel::UpdateRadiationForces () } Flin_add += F; if (r.x || r.y || r.z) - Amom_add += crossp (F, r); + Amom_add += cross(F, r); } // ======================================================================= @@ -4028,9 +4020,9 @@ void Vessel::UpdateAerodynamicForces () #endif - Vector ddir (-sp.airvel_ship.unit()); // freestream airflow direction (= drag direction) - Vector ldir (0, sp.airvel_ship.z, -sp.airvel_ship.y); ldir.unify(); // lift direction (vertical on drag and transversal ship axis) - Vector sdir (sp.airvel_ship.z, 0, -sp.airvel_ship.x); sdir.unify(); // sidelift direction (vertical on drag and vertical ship axis) + VECTOR3 ddir = unit(-sp.airvel_ship); // freestream airflow direction (= drag direction) + VECTOR3 ldir = unit(VECTOR3{0, sp.airvel_ship.z, -sp.airvel_ship.y}); // lift direction (vertical on drag and transversal ship axis) + VECTOR3 sdir = unit(VECTOR3{sp.airvel_ship.z, 0, -sp.airvel_ship.x}); // sidelift direction (vertical on drag and vertical ship axis) double lift, drag, S; double Cl, Cm, Cd; // lift, moment, drag coeffs @@ -4125,13 +4117,13 @@ void Vessel::UpdateAerodynamicForces_OLD () // lift and drag. Note: this only generates a linear force. Angular momentum is // generated by the hack above. - Vector vnorm (sp.airvel_ship/sp.airspd); + VECTOR3 vnorm = sp.airvel_ship / sp.airspd; double Cl; // lift coeff // === wing lift === if (LiftCoeff && (Cl = LiftCoeff (aoa))) { Lift = Cl * sp.dynp * cs.y; // lift magnitude - Vector L (0, sp.airvel_ship.z, -sp.airvel_ship.y); // lift direction + VECTOR3 L{0, sp.airvel_ship.z, -sp.airvel_ship.y}; // lift direction double lnorm = std::hypot (sp.airvel_ship.z, sp.airvel_ship.y); if (lnorm) { L *= Lift / lnorm; @@ -4156,7 +4148,7 @@ void Vessel::UpdateAerodynamicForces_OLD () // If tfrac==1, the full step is calculated // Note that no interpolation of rotation states is performed -bool Vessel::AddSurfaceForces (Vector *F, Vector *M, const StateVectors *s, double tfrac, double dt, bool allow_groundcontact) const +bool Vessel::AddSurfaceForces (VECTOR3 *F, VECTOR3 *M, const StateVectors *s, double tfrac, double dt, bool allow_groundcontact) const { nforcevec = 0; // should move higher up E_comp = 0.0; // compression energy @@ -4178,15 +4170,15 @@ bool Vessel::AddSurfaceForces (Vector *F, Vector *M, const StateVectors *s, doub if (!dt) dt = td.SimDT; if (!s) { // full step, based on pre-step vessel position (but new planet position!) - ls.pos.Set (s0->pos); - ls.vel.Set (s0->vel); + ls.pos = s0->pos; + ls.vel = s0->vel; ls.Q.Set (s0->Q); - ls.omega.Set (s0->omega); + ls.omega = s0->omega; s = &ls; } else { // partial step, based on intermediate position // we need to propagate the gravbody backwards, since it has been updated already } - alt = s->pos.dist (ps.pos) - proxybody->Size(); // altitude over normal zero + alt = dist(s->pos, ps.pos) - proxybody->Size(); // altitude over normal zero if (alt > sp.elev + 1e4) return false; // add safety margin surfp.Set (*s, ps, proxybody, &etile, &windp); // intermediate surface parameters @@ -4219,9 +4211,9 @@ bool Vessel::AddSurfaceForces (Vector *F, Vector *M, const StateVectors *s, doub int reslvl = 1; if (emgr) reslvl = (int)(32.0-log(max(alt,100.0))*LOG2); - Vector shift = tmul(ps.R, s->pos - ps.pos); + VECTOR3 shift = tmul(ps.R, s->pos - ps.pos); for (i = 0; i < ntouchdown_vtx; i++) { - Vector p (mul (T, touchdown_vtx[i].pos) + shift); + VECTOR3 p = mul(T, touchdown_vtx[i].pos) + shift; double lng, lat, rad, elev = 0.0; proxybody->LocalToEquatorial (p, lng, lat, rad); if (emgr) @@ -4252,14 +4244,14 @@ bool Vessel::AddSurfaceForces (Vector *F, Vector *M, const StateVectors *s, doub double fn_tot_undamped = 0.0, fn_tot = 0.0, flng_tot = 0.0, flat_tot = 0.0; // longitudinal touchdown direction - could be precalculated - Vector d1 ((touchdown_vtx[0].pos-(touchdown_vtx[1].pos+touchdown_vtx[2].pos)*0.5)); + VECTOR3 d1 = (touchdown_vtx[0].pos - (touchdown_vtx[1].pos + touchdown_vtx[2].pos) * 0.5); // horizon normal in vessel frame //Vector hn (tmul (s->R, s->pos - ps.pos).unit()); - Vector hn (tmul (T, tmul (surfp.L2H, surfp.surfnml))); + VECTOR3 hn = tmul(T, tmul(surfp.L2H, surfp.surfnml)); // project d1 (longitudinal touchdown direction) into horizon plane - Vector d1h ((d1 - hn * dotp (d1, hn)).unit()); + VECTOR3 d1h = unit(d1 - hn * dot(d1, hn)); // lateral touchdown direction - Vector d2h (crossp (hn, d1h)); + VECTOR3 d2h = cross(hn, d1h); if (bDynamicGroundContact) { @@ -4273,16 +4265,16 @@ bool Vessel::AddSurfaceForces (Vector *F, Vector *M, const StateVectors *s, doub for (i = 0; i < ntouchdown_vtx; i++) { if (tdy[i] < 0.0) { tidx[ntouch++] = i; - Vector gV (surfp.groundvel_ship + crossp(touchdown_vtx[i].pos,s->omega)); // ground velocity of touchdown point in vessel frame - gv_n = dotp (gV, hn); // gv projected on horizon normal in vessel frame - gv_lon = dotp (gV, d1h); // longitudinal speed component for touchdown point i - gv_lat = dotp (gV, d2h); // lateral speed component + VECTOR3 gV = surfp.groundvel_ship + cross(touchdown_vtx[i].pos, s->omega); // ground velocity of touchdown point in vessel frame + gv_n = dot(gV, hn); // gv projected on horizon normal in vessel frame + gv_lon = dot(gV, d1h); // longitudinal speed component for touchdown point i + gv_lat = dot(gV, d2h); // lateral speed component - Vector gV_hor = d1h*gv_lon + d2h*gv_lat; - Vector gV_hor2 = gV - hn*gv_n; // is this the same? + VECTOR3 gV_hor = d1h * gv_lon + d2h * gv_lat; + VECTOR3 gV_hor2 = gV - hn * gv_n; // is this the same? gv_hor = hypot(gv_lon,gv_lat); - Vector gV_hor0 (gV_hor/gv_hor); + VECTOR3 gV_hor0 = gV_hor / gv_hor; fn[i] = -tdy[i]*touchdown_vtx[i].stiffness; // horizon-normal force component: gear compression forces @@ -4328,7 +4320,7 @@ bool Vessel::AddSurfaceForces (Vector *F, Vector *M, const StateVectors *s, doub for (i = 0; i < ntouch; i++) { j = tidx[i]; if (tdy[j] < 0.0) { - *M += crossp (hn*fn[j]+d1h*flng[j]+d2h*flat[j], touchdown_vtx[j].pos); + *M += cross(hn * fn[j] + d1h * flng[j] + d2h * flat[j], touchdown_vtx[j].pos); } } } @@ -4340,10 +4332,10 @@ bool Vessel::AddSurfaceForces (Vector *F, Vector *M, const StateVectors *s, doub if (tdy[i] < 0.0) { // ground contact on point i! tdy[i] = max(tdy[i], -1.0); // DEBUG tidx[ntouch++] = i; - Vector gv (surfp.groundvel_ship + crossp(touchdown_vtx[i].pos,s->omega)); // ground velocity of touchdown point in vessel frame - gv_n = dotp (gv, hn); // gv projected on horizon normal in vessel frame - gv_lon = dotp (gv, d1h); // longitudinal speed component for touchdown point i - gv_lat = dotp (gv, d2h); // lateral speed component + VECTOR3 gv = surfp.groundvel_ship + cross(touchdown_vtx[i].pos, s->omega); // ground velocity of touchdown point in vessel frame + gv_n = dot(gv, hn); // gv projected on horizon normal in vessel frame + gv_lon = dot(gv, d1h); // longitudinal speed component for touchdown point i + gv_lat = dot(gv, d2h); // lateral speed component fn[i] = -tdy[i]*touchdown_vtx[i].stiffness; // horizon-normal force component: gear compression forces double maxpress = min (-tdy[i], 0.1)*touchdown_vtx[i].stiffness; @@ -4386,9 +4378,9 @@ bool Vessel::AddSurfaceForces (Vector *F, Vector *M, const StateVectors *s, doub } // limit forces to avoid velocity reversal - gv_lon = dotp (surfp.groundvel_ship, d1h); - gv_lat = dotp (surfp.groundvel_ship, d2h); - gv_n = dotp (surfp.groundvel_ship, hn); + gv_lon = dot(surfp.groundvel_ship, d1h); + gv_lat = dot(surfp.groundvel_ship, d2h); + gv_n = dot(surfp.groundvel_ship, hn); double fmax_lon = -gv_lon * massdt; if ((fmax_lon >= 0.0 && flng_tot > fmax_lon) || (fmax_lon <= 0.0 && flng_tot < fmax_lon)) { double scale = fmax_lon/flng_tot; @@ -4408,7 +4400,7 @@ bool Vessel::AddSurfaceForces (Vector *F, Vector *M, const StateVectors *s, doub double d_eff = -E/fn_tot_undamped*2.0/ntouch; // effective compression depth E += 0.5*mass*gv_n*gv_n; // add current linear kinetic energy - E += 0.5*mass*dotp(s->omega*pmi, s->omega); + E += 0.5*mass*dot(s->omega*pmi, s->omega); double dv = fn_tot/mass*dt; double gv_n_new = gv_n + dv; double d_eff_new = d_eff + dv*dt; @@ -4434,15 +4426,15 @@ bool Vessel::AddSurfaceForces (Vector *F, Vector *M, const StateVectors *s, doub // fn[tidx[i]] *= scale; //} - Vector M_surf, F_surf = hn*fn_tot + d1h*flng_tot + d2h*flat_tot; + VECTOR3 M_surf, F_surf = hn * fn_tot + d1h * flng_tot + d2h * flat_tot; for (i = 0; i < ntouch; i++) { j = tidx[i]; - M_surf += crossp (hn*fn[j]+d1h*flng[j]+d2h*flat[j], touchdown_vtx[j].pos); + M_surf += cross(hn * fn[j] + d1h * flng[j] + d2h * flat[j], touchdown_vtx[j].pos); } // limit the change in angle over the current time step induced by impact forces - Vector dA = EulerInv_full (M_surf/mass, s->omega)*dt*dt; - double da = dA.length(); + VECTOR3 dA = EulerInv_full(M_surf / mass, s->omega) * dt * dt; + double da = len(dA); static double da_max = 0.0; if (da > da_max) da_max = da; if (da > 10.0*RAD) { @@ -4452,30 +4444,30 @@ bool Vessel::AddSurfaceForces (Vector *F, Vector *M, const StateVectors *s, doub #ifdef UNDEF - Vector V0 = surfp.groundvel_ship; - Vector V1 = V0 + F_surf * (dt/mass); - double E0_kin_lin = 0.5*mass*dotp(V0,V0); - double E1_kin_lin = 0.5*mass*dotp(V1,V1); + VECTOR3 V0 = surfp.groundvel_ship; + VECTOR3 V1 = V0 + F_surf * (dt/mass); + double E0_kin_lin = 0.5*mass*dot(V0,V0); + double E1_kin_lin = 0.5*mass*dot(V1,V1); double dE_kin = E1_kin_lin-E0_kin_lin; // change in linear kinetic energy over time step - Vector W0 = s->omega; - Vector W1 = W0 + EulerInv_full (M_surf/mass, s->omega)*dt; - double E0_kin_rot = 0.5*mass*dotp(W0*pmi, W0); - double E1_kin_rot = 0.5*mass*dotp(W1*pmi, W1); + VECTOR3 W0 = s->omega; + VECTOR3 W1 = W0 + EulerInv_full (M_surf/mass, s->omega)*dt; + double E0_kin_rot = 0.5*mass*dot(W0*pmi, W0); + double E1_kin_rot = 0.5*mass*dot(W1*pmi, W1); dE_kin += E1_kin_rot-E0_kin_rot; // change in rotational kinetic energy over time step double dE_comp = E_comp-E0_comp; if (dE_kin + dE_comp > 1e5) { // limit kinetic energy double E1_kin_rot_fix = max(0, E1_kin_rot - (dE_kin+dE_comp-1e5)); double alpha = sqrt(E1_kin_rot_fix/E1_kin_rot); - Vector W1_fix = W1*alpha; - Vector Wdot = (W1_fix - W0)/dt; - Vector tau = Euler_full(Wdot, s->omega); + VECTOR3 W1_fix = W1*alpha; + VECTOR3 Wdot = (W1_fix - W0)/dt; + VECTOR3 tau = Euler_full(Wdot, s->omega); M_surf = tau*mass; // sanity check W1 = W0 + EulerInv_full (M_surf/mass, s->omega)*dt; dE_kin -= E1_kin_rot; - E1_kin_rot = 0.5*mass*dotp(W1*pmi, W1); + E1_kin_rot = 0.5*mass*dot(W1*pmi, W1); dE_kin += E1_kin_rot; double de = dE_kin + dE_comp; } @@ -4491,9 +4483,9 @@ bool Vessel::AddSurfaceForces (Vector *F, Vector *M, const StateVectors *s, doub double v1, v2; for (i = 0; i < 3; i++) { if (tdy[i] < 0.0) { - Vector gv (surfp.groundvel_ship + crossp(touchdown_vtx[i].pos,s->omega)); // ground velocity of touchdown point in vessel frame - v1 = dotp (gv, d1h); // longitudinal speed component for touchdown point i - v2 = dotp (gv, d2h); // lateral speed component + VECTOR3 gv = surfp.groundvel_ship + cross(touchdown_vtx[i].pos, s->omega); // ground velocity of touchdown point in vessel frame + v1 = dot(gv, d1h); // longitudinal speed component for touchdown point i + v2 = dot(gv, d2h); // lateral speed component // longitudinal forces flng[i] = touchdown_vtx[i].mu_lng * mass * 9.81; // friction: generalise! @@ -4515,9 +4507,9 @@ bool Vessel::AddSurfaceForces (Vector *F, Vector *M, const StateVectors *s, doub } // project ground speed vector into horizon plane (vessel frame) - Vector vh (sp.groundvel_ship - hn * dotp (sp.groundvel_ship, hn)); - v1 = dotp (vh, d1h); - v2 = dotp (vh, d2h); + VECTOR3 vh = sp.groundvel_ship - hn * dot(sp.groundvel_ship, hn); + v1 = dot(vh, d1h); + v2 = dot(vh, d2h); // limit linear force fmax = v1*massdt; if (flng_tot*fmax < 0.0) { @@ -4537,10 +4529,10 @@ bool Vessel::AddSurfaceForces (Vector *F, Vector *M, const StateVectors *s, doub // apply angular forces for (i = 0; i < 3; i++) { if (tdy[i] < 0.0) { - Vector f_attack(touchdown_vtx[i].pos); + VECTOR3 f_attack = touchdown_vtx[i].pos; //f_attack.y = 0.0; // hack to avoid nicking - Vector F(d1h*flng[i] + d2h*flat[i]); - *M -= crossp (F, f_attack); + VECTOR3 F = d1h * flng[i] + d2h * flat[i]; + *M -= cross(F, f_attack); } } } @@ -4608,8 +4600,8 @@ void Vessel::Update (bool force) // simplified state update for idle vessels proxyplanet->LocalToGlobal_t1 (sp.ploc, s1->pos); double vground = Pi2 * proxyplanet->Size() * sp.clat / proxyplanet->RotT(); - s1->vel.Set (-vground*sp.slng, 0.0, vground*sp.clng); - s1->vel.Set (mul (proxyplanet->s1->R, s1->vel) + proxyplanet->s1->vel); + s1->vel = {-vground * sp.slng, 0.0, vground * sp.clng}; + s1->vel = mul(proxyplanet->s1->R, s1->vel) + proxyplanet->s1->vel; s1->R.Set (land_rot); s1->R.premul (proxyplanet->s1->R); s1->Q.Set (s1->R); @@ -4626,10 +4618,10 @@ void Vessel::Update (bool force) if (lstatus == 3 || lstatus == 5) lstatus = 1; // need to synchronise state vectors - DO WE NEED THIS? - rpos_base = s1->pos; rpos_add.Set (0,0,0); + rpos_base = s1->pos; rpos_add = {0, 0, 0}; s1->vel += rvel_add; // MS-071005: rvel_add included to fix "stuck at latitude 90" bug - rvel_base = s1->vel; rvel_add.Set (0,0,0); - s1->omega.Set (0,0,0); + rvel_base = s1->vel; rvel_add = {0, 0, 0}; + s1->omega = {0, 0, 0}; } //if (bFRplayback) @@ -4655,7 +4647,7 @@ void Vessel::Update (bool force) double py, pymin; int imin; for (i = 0; i < 3; i++) { - Vector p (mul (T, touchdown_vtx[i].pos)); + VECTOR3 p = mul(T, touchdown_vtx[i].pos); py = p.y + sp.alt; // vertical position if (!i || py < pymin) pymin = py, imin = i; } @@ -4666,27 +4658,27 @@ void Vessel::Update (bool force) // Calculate compressed touchdown points at equilibrium double mg = GetWeight(); - Vector tp_comp[3]; + VECTOR3 tp_comp[3]; for (i = 0; i < 3; i++) tp_comp[i] = touchdown_vtx[i].pos + touchdown_nm*(touchdown_vtx[i].compression*mg); // equilibrium touchdown plane normal - Vector tnm_comp = crossp (tp_comp[0]-(tp_comp[1]+tp_comp[2])*0.5, tp_comp[2]-tp_comp[1]).unit(); + VECTOR3 tnm_comp = unit(cross(tp_comp[0] - (tp_comp[1] + tp_comp[2]) * 0.5, tp_comp[2] - tp_comp[1])); // horizon normal in vessel frame - Vector horizon_nm (T.m21, T.m22, T.m23); - double tilt = acos (dotp (tnm_comp, horizon_nm)); + VECTOR3 horizon_nm{T.m21, T.m22, T.m23}; + double tilt = std::acos(dot(tnm_comp, horizon_nm)); if (tilt > 1e-10) { // rotate rotation axis into vessel x-axis - Vector raxis (crossp (tnm_comp, horizon_nm).unit()); + VECTOR3 raxis = unit(cross(tnm_comp, horizon_nm)); double theta = asin (raxis.y); double phi = atan2 (raxis.z, raxis.x); double sint = sin (theta), cost = cos (theta); double sinp = sin (phi), cosp = cos (phi); Matrix R (cost*cosp, sint, cost*sinp, -sint*cosp, cost, -sint*sinp, -sinp, 0, cosp); // rotate around x-axis to compensate tilt - double arm = touchdown_vtx[imin].pos.dist(touchdown_cg)/size; + double arm = dist(touchdown_vtx[imin].pos, touchdown_cg) / size; // rotate around x-axis to compensate tilt double dtilt = min (tilt, -pymin * arm * 0.03 /*0.005e-1*/); double sina = sin(dtilt), cosa = cos(dtilt); @@ -4695,7 +4687,7 @@ void Vessel::Update (bool force) R.premul (Matrix (cost*cosp, -sint*cosp, -sinp, sint, cost, 0, cost*sinp, -sint*sinp, cosp)); // modify angular velocity - Vector dv = raxis * (dtilt*td.iSimDT); + VECTOR3 dv = raxis * (dtilt * td.iSimDT); s1->omega -= dv; // limit angular velocity when we are flat on the ground @@ -4714,7 +4706,7 @@ void Vessel::Update (bool force) // Update touchdown points for compression for (i = 0; i < 3; i++) { - Vector p (mul (T, tp_comp[i])); + VECTOR3 p = mul(T, tp_comp[i]); py = p.y + sp.alt; if (!i || py < pymin) pymin = py, imin = i; } @@ -4723,13 +4715,13 @@ void Vessel::Update (bool force) if (pymin < 0.0) { sp.rad -= pymin; sp.alt -= pymin; - Vector loc; + VECTOR3 loc; proxyplanet->EquatorialToLocal (sp.slng, sp.clng, sp.slat, sp.clat, sp.rad, loc); - Vector pgpos(s1->pos); + VECTOR3 pgpos = s1->pos; SetRPos (mul (proxyplanet->s1->R, loc) + proxyplanet->s1->pos); - Vector dv ((s1->pos-pgpos)*td.iSimDT); + VECTOR3 dv = (s1->pos - pgpos) * td.iSimDT; double ay = mul (sp.L2H, tmul (proxyplanet->s1->R, acc)).y; - if (ay < 0) dv -= mul (proxyplanet->s1->R, tmul(sp.L2H, Vector (0, ay, 0)))*0.5*td.SimDT; + if (ay < 0) dv -= mul(proxyplanet->s1->R, tmul(sp.L2H, VECTOR3{0, ay, 0})) * 0.5 * td.SimDT; AddRVel (dv); } @@ -4791,10 +4783,10 @@ void Vessel::Update (bool force) ((VESSEL2*)modIntf.v)->clbkAnimate (td.SimT1); } - Flin.Set (Flin_add); // store current linear force - Amom.Set (Amom_add); // store current torque - Flin_add.Set (0,0,0); // reset linear force - Amom_add.Set (0,0,0); // reset angular moments + Flin = Flin_add; // store current linear force + Amom = Amom_add; // store current torque + Flin_add = {0, 0, 0}; // reset linear force + Amom_add = {0, 0, 0}; // reset angular moments E0_comp = E_comp; // store compression energy //for (i = 0; i < 2; i++) wbrake_override[i] = 0; weight_valid = torque_valid = false; @@ -4814,22 +4806,22 @@ void Vessel::UpdatePassive () AttachmentSpec *pa = attach->mate_attach; StateVectors *ps = (s1 ? prnt->s1 : prnt->s0); - s->pos.Set (mul (ps->R, attach_rpos) + ps->pos); + s->pos = mul(ps->R, attach_rpos) + ps->pos; rpos_base = s->pos; - rpos_add.Set (0,0,0); - s->vel.Set (ps->vel); + rpos_add = {0, 0, 0}; + s->vel = ps->vel; rvel_base = s->vel; - rvel_add.Set (0,0,0); + rvel_add = {0, 0, 0}; s->R.Set (ps->R); s->R.postmul (attach_rrot); s->Q.Set (s->R); - s->omega.Set (tmul (attach_rrot, ps->omega)); - acc.Set (prnt->acc); + s->omega = tmul(attach_rrot, ps->omega); + acc = prnt->acc; - Flin.Set (Flin_add); // store current linear force - Amom.Set (Amom_add); // store current torque - Flin_add.Set (0,0,0); // reset linear force - Amom_add.Set (0,0,0); // reset angular moments + Flin = Flin_add; // store current linear force + Amom = Amom_add; // store current torque + Flin_add = {0, 0, 0}; // reset linear force + Amom_add = {0, 0, 0}; // reset angular moments proxybody = prnt->proxybody; proxyplanet = prnt->proxyplanet; @@ -4873,18 +4865,18 @@ void Vessel::PostUpdate () if (++scanvessel >= g_psys->nVessel()) scanvessel = 0; Vessel *v = g_psys->GetVessel(scanvessel); if (v != this && v->ndock && v->proxybody == proxybody) { - double dst = s0->pos.dist (v->GPos()); + double dst = dist(s0->pos, v->GPos()); if ((dst < 1.5 * (size + v->Size()) || (dst < size + v->Size() + 1e3))) { // valid candidate - Vector dref, gref, vref; + VECTOR3 dref, gref, vref; for (j = 0; j < ndock; j++) { // loop over my own docks if (dock[j]->mate) continue; // dock already busy if (dockmode == 0) { // legacy docking mode - if (dotp (s0->vel - v->GVel(), mul (s0->R, dock[j]->dir)) < -0.01) continue; // moving away from dock + if (dot(s0->vel - v->GVel(), mul(s0->R, dock[j]->dir)) < -0.01) continue; // moving away from dock for (k = 0; k < v->ndock; k++) { // loop over other vessel's docks if (v->dock[k]->mate) continue; // dock already busy - dref.Set (tmul (v->GRot(), mul (s0->R, dock[j]->ref) + s0->pos - v->GPos())); - double d = dref.dist (v->dock[k]->ref); + dref = tmul(v->GRot(), mul(s0->R, dock[j]->ref) + s0->pos - v->GPos()); + double d = dist(dref, v->dock[k]->ref); if (d < MIN_DOCK_DIST) { Dock (v, j, k); } @@ -4892,12 +4884,12 @@ void Vessel::PostUpdate () } else { // new docking mode for (k = 0; k < v->ndock; k++) { // loop over other vessel's docks if (v->dock[k]->mate) continue; // dock already busy - gref.Set (mul (s0->R, dock[j]->ref) + s0->pos); // my dock in global frame - vref.Set (mul (v->GRot(), v->dock[k]->ref) + v->GPos()); // target dock in global frame - //dref.Set (tmul (v->GRot(), mul (*grot, dock[j]->ref) + *gpos - v->GPos())); // my dock in the target's frame - double d = gref.dist(vref); //dref.dist (v->dock[k]->ref); + gref = mul(s0->R, dock[j]->ref) + s0->pos; // my dock in global frame + vref = mul(v->GRot(), v->dock[k]->ref) + v->GPos(); // target dock in global frame + //dref = tmul(v->GRot(), mul (*grot, dock[j]->ref) + *gpos - v->GPos()); // my dock in the target's frame + double d = dist(gref, vref); //dref.dist (v->dock[k]->ref); if (d < MIN_DOCK_DIST) { - if (dotp (s0->vel - v->GVel(), vref-gref) >= 0) { // on approach + if (dot(s0->vel - v->GVel(), vref-gref) >= 0) { // on approach dock[j]->pending = v; } else if (dock[j]->pending == v) { Dock (v, j, k); @@ -4908,15 +4900,15 @@ void Vessel::PostUpdate () } // update information about closest dock in range of our dock 0 if (closedock.vessel && closedock.vessel->ndock && closedock.dock < closedock.vessel->ndock) { - dref.Set (tmul (closedock.vessel->GRot(), mul (s0->R, dock[0]->ref) + s0->pos - closedock.vessel->GPos())); - closedock.dist = dref.dist (closedock.vessel->dock[closedock.dock]->ref); + dref = tmul(closedock.vessel->GRot(), mul(s0->R, dock[0]->ref) + s0->pos - closedock.vessel->GPos()); + closedock.dist = dist(dref, closedock.vessel->dock[closedock.dock]->ref); } else { closedock.dist = 1e50; } for (k = 0; k < v->ndock; k++) { if (v->dock[k]->mate) continue; - dref.Set (tmul (v->GRot(), mul (s0->R, dock[0]->ref) + s0->pos - v->GPos())); - double d = dref.dist (v->dock[k]->ref); + dref = tmul(v->GRot(), mul(s0->R, dock[0]->ref) + s0->pos - v->GPos()); + double d = dist(dref, v->dock[k]->ref); if (d < closedock.dist) { closedock.dist = d; closedock.vessel = v; @@ -4942,7 +4934,7 @@ bool Vessel::CheckSurfaceContact () const T.tpostmul (proxybody->s0->R); T.postmul (s0->R); for (DWORD i = 0; i < ntouchdown_vtx; i++) { - Vector p (mul (T, touchdown_vtx[i].pos)); + VECTOR3 p = mul(T, touchdown_vtx[i].pos); if (p.y + alt < 0.0) return true; } return false; @@ -4973,8 +4965,8 @@ void Vessel::Timejump (double dt, int mode) case PROP_SORBITAL_FIXEDSURF: { double dphi = Pi2*dt/proxyplanet->RotT(), cphi = cos(dphi), sphi = sin(dphi); Matrix Rb (cphi,0,-sphi, 0,1,0, sphi,0,cphi); - Vector cp = mul (proxyplanet->GRot(), mul (Rb, tmul (proxyplanet->GRot(), cpos))); - Vector cv = mul (proxyplanet->GRot(), mul (Rb, tmul (proxyplanet->GRot(), cvel))); + VECTOR3 cp = mul(proxyplanet->GRot(), mul(Rb, tmul(proxyplanet->GRot(), cpos))); + VECTOR3 cv = mul(proxyplanet->GRot(), mul(Rb, tmul(proxyplanet->GRot(), cvel))); s0->R.tpremul (proxyplanet->GRot()); s0->R.premul (Rb); s0->R.premul (proxyplanet->GRot()); @@ -4994,8 +4986,8 @@ void Vessel::Timejump (double dt, int mode) proxyplanet->LocalToGlobal (sp.ploc, s0->pos); double vground = Pi2 * proxyplanet->Size() * sp.clat / proxyplanet->RotT(); - s0->vel.Set (-vground*sp.slng, 0.0, vground*sp.clng); - s0->vel.Set (mul (proxyplanet->GRot(), s0->vel) + proxyplanet->GVel()); + s0->vel = {-vground * sp.slng, 0.0, vground * sp.clng}; + s0->vel = mul(proxyplanet->GRot(), s0->vel) + proxyplanet->GVel(); s0->R.Set (land_rot); s0->R.premul (proxyplanet->GRot()); s0->Q.Set (s0->R); @@ -5089,7 +5081,7 @@ void Vessel::UpdateProxies () for (i = g_psys->nVessel()-1, proxydist2 = 1e100; i >= 0; i--) { Vessel *vessel = g_psys->GetVessel(i); if (vessel == this) continue; - if ((dist2 = s0->pos.dist2 (vessel->GPos())) < proxydist2) { + if ((dist2 = dist_2(s0->pos, vessel->GPos())) < proxydist2) { proxydist2 = dist2; proxyvessel = vessel; } @@ -5145,7 +5137,7 @@ void Vessel::UpdateReceiverStatus (DWORD idx) // scan surface-base related signal transmitters for (i = 0; i < proxyplanet->nBase(); i++) { Base *base = proxyplanet->GetBase(i); - if ((s0->pos.dist2 (base->GPos()) < 1e12) && (nn = base->nNav())) { + if ((dist_2(s0->pos, base->GPos()) < 1e12) && (nn = base->nNav())) { for (n = 0; n < nn; n++) { const Nav *navsend = base->NavMgr().GetNav (n); for (m = n0; m < n1; m++) { @@ -5165,7 +5157,7 @@ void Vessel::UpdateReceiverStatus (DWORD idx) for (i = g_psys->nVessel()-1; i >= 0; i--) { Vessel *vessel = g_psys->GetVessel(i); if (vessel == this) continue; - if ((dist2 = s0->pos.dist2 (vessel->GPos())) < 1e12) { // max XPDR range 1000 km + if ((dist2 = dist_2(s0->pos, vessel->GPos())) < 1e12) { // max XPDR range 1000 km for (n = n0; n < n1; n++) { if (vessel->xpdr && vessel->xpdr->GetStep() == nav[n].step) { @@ -5220,16 +5212,16 @@ double Vessel::IlluminationFactor () const lightfac_T1 = lightfac_T0+updt; return lightfac; } - Vector S(sun->GPos() - s0->pos); - double s = S.length(); + VECTOR3 S = sun->GPos() - s0->pos; + double s = len(S); double as = asin (sun->Size()/s); int i; for (i = 0;; i++) { - Vector P(cb->GPos() - s0->pos); - double p = P.length(); + VECTOR3 P = cb->GPos() - s0->pos; + double p = len(P); if (p < s) { // shadow only if planet closer than sun - double phi = acos (dotp(S,P)/(s*p)); + double phi = std::acos(dot(S, P) / (s * p)); double ap = asin (cb->Size()/p); // for now disregard atmospheric effects @@ -5453,16 +5445,16 @@ void Vessel::SetCameraMovement (const VECTOR3 &fwdpos, double fwdphi, double fwd const VECTOR3 &lpos, double lphi, double ltht, const VECTOR3 &rpos, double rphi, double rtht) { - camfwd.pos.Set (fwdpos.x, fwdpos.y, fwdpos.z); camfwd.phi = fwdphi; camfwd.tht = fwdtht; - camleft.pos.Set (lpos.x, lpos.y, lpos.z); camleft.phi = lphi; camleft.tht = ltht; - camright.pos.Set (rpos.x, rpos.y, rpos.z); camright.phi = rphi; camright.tht = rtht; + camfwd.pos = fwdpos; camfwd.phi = fwdphi; camfwd.tht = fwdtht; + camleft.pos = lpos; camleft.phi = lphi; camleft.tht = ltht; + camright.pos = rpos; camright.phi = rphi; camright.tht = rtht; } void Vessel::UnsetCameraMovement () { - camfwd.pos.Set (0,0,0); camfwd.phi = camfwd.tht = 0; - camleft.pos.Set (0,0,0); camleft.phi = camleft.tht = 0; - camright.pos.Set (0,0,0); camright.phi = camright.tht = 0; + camfwd.pos = {0, 0, 0}; camfwd.phi = camfwd.tht = 0; + camleft.pos = {0, 0, 0}; camleft.phi = camleft.tht = 0; + camright.pos = {0, 0, 0}; camright.phi = camright.tht = 0; } void Vessel::RegisterVisual (VISHANDLE vis) @@ -5551,12 +5543,12 @@ bool Vessel::VCRedrawEvent (int id, int event, SURFHANDLE surf) const return false; } -bool Vessel::VCMouseEvent (int id, int event, Vector &p) const +bool Vessel::VCMouseEvent (int id, int event, VECTOR3 &p) const { - if (modIntf.v && modIntf.v->Version() >= 1) { - VECTOR3 v = _V(p.x,p.y,p.z); - return ((VESSEL2*)modIntf.v)->clbkVCMouseEvent (id, event, v); - } + if (modIntf.v && modIntf.v->Version() >= 1) { + VECTOR3 v{p.x,p.y,p.z}; + return ((VESSEL2*)modIntf.v)->clbkVCMouseEvent (id, event, v); + } else return false; } @@ -5565,8 +5557,8 @@ void Vessel::LeanCamera (int dir, bool smooth) { switch (dir) { case 0: // default position - if (smooth) g_camera->MoveTo (Vector(0,0,0)); - else g_camera->MoveToDirect (Vector(0,0,0)); + if (smooth) g_camera->MoveTo({0, 0, 0}); + else g_camera->MoveToDirect({0, 0, 0}); g_camera->ResetCockpitDir (smooth); break; case 1: // forward @@ -5919,8 +5911,8 @@ bool Vessel::Read (ifstream &scn) //vs.xpdr = 0; //vs.nfuel = vs.nthruster = vs.ndockinfo = 0; //vs.surf_lng = vs.surf_lat = vs.surf_hdg = 0.0; - //veccpy (vs.vrot, _V(0,0,0)); - //veccpy (vs.arot, _V(0,0,0)); + //veccpy (vs.vrot, {0, 0, 0}); + //veccpy (vs.arot, {0, 0, 0}); void *vsptr = (void*)&vs; if (modIntf.v->Version() >= 1) { @@ -6029,7 +6021,7 @@ void Vessel::WriteDefault (ostream &ofs) const ofs << " AROT " << setprecision(3) << DEG*atan2 (s0->R.m23, s0->R.m33) << ' ' << -DEG*asin (s0->R.m13) << ' ' << DEG*atan2 (s0->R.m12, s0->R.m11) << endl; - if (s0->omega.length2() > 1e-8) + if (len_2(s0->omega) > 1e-8) ofs << " VROT " << setprecision(4) << DEG*s0->omega.x << ' ' << DEG*s0->omega.y << ' ' << DEG*s0->omega.z << endl; } break; @@ -6294,9 +6286,7 @@ double VESSEL::GetCOG_elev () const void VESSEL::GetCrossSections (VECTOR3 &cs) const { - cs.x = vessel->cs.x; - cs.y = vessel->cs.y; - cs.z = vessel->cs.z; + cs = vessel->cs; } void VESSEL::GetCW (double &cw_z_pos, double &cw_z_neg, double &cw_x, double &cw_y) const @@ -6319,30 +6309,22 @@ double VESSEL::GetWingEffectiveness () const void VESSEL::GetRotDrag (VECTOR3 &rd) const { - rd.x = vessel->rdrag.x; - rd.y = vessel->rdrag.y; - rd.z = vessel->rdrag.z; + rd = vessel->rdrag; } void VESSEL::GetPMI (VECTOR3 &pmi) const { - pmi.x = vessel->pmi.x; - pmi.y = vessel->pmi.y; - pmi.z = vessel->pmi.z; + pmi = vessel->pmi; } void VESSEL::GetCameraOffset (VECTOR3 &co) const { - co.x = vessel->campos.x; - co.y = vessel->campos.y; - co.z = vessel->campos.z; + co = vessel->campos; } void VESSEL::GetCameraDefaultDirection (VECTOR3 &cd) const { - cd.x = vessel->camdir0.x; - cd.y = vessel->camdir0.y; - cd.z = vessel->camdir0.z; + cd = vessel->camdir0; } double VESSEL::GetAtmTemperature () const @@ -6406,65 +6388,47 @@ const OBJHANDLE VESSEL::GetAtmRef () const void VESSEL::GetGlobalPos (VECTOR3 &pos) const { - pos.x = vessel->s0->pos.x; - pos.y = vessel->s0->pos.y; - pos.z = vessel->s0->pos.z; + pos = vessel->s0->pos; } void VESSEL::GetGlobalVel (VECTOR3 &vel) const { - vel.x = vessel->s0->vel.x; - vel.y = vessel->s0->vel.y; - vel.z = vessel->s0->vel.z; + vel = vessel->s0->vel; } void VESSEL::GetRelativePos (OBJHANDLE hRef, VECTOR3 &pos) const { - Vector dp (vessel->GPos() - ((Body*)hRef)->GPos()); - pos.x = dp.x; - pos.y = dp.y; - pos.z = dp.z; + pos = vessel->GPos() - ((Body*)hRef)->GPos(); } void VESSEL::GetRelativeVel (OBJHANDLE hRef, VECTOR3 &vel) const { - Vector dv (vessel->GVel() - ((Body*)hRef)->GVel()); - vel.x = dv.x; - vel.y = dv.y; - vel.z = dv.z; + vel = vessel->GVel() - ((Body*)hRef)->GVel(); } void VESSEL::GetLinearMoment (VECTOR3 &F) const { - F.x = vessel->Flin.x; - F.y = vessel->Flin.y; - F.z = vessel->Flin.z; + F = vessel->Flin; } void VESSEL::GetAngularVel (VECTOR3 &avel) const { - avel.x = vessel->s0->omega.x; - avel.y = vessel->s0->omega.y; - avel.z = vessel->s0->omega.z; + avel = vessel->s0->omega; } void VESSEL::SetAngularVel (const VECTOR3 &avel) const { - vessel->SetAngVel (MakeVector (avel)); + vessel->SetAngVel(avel); } void VESSEL::GetAngularAcc (VECTOR3 &aacc) const { - aacc.x = vessel->arot.x; - aacc.y = vessel->arot.y; - aacc.z = vessel->arot.z; + aacc = vessel->arot; } void VESSEL::GetAngularMoment (VECTOR3 &amom) const { - amom.x = vessel->Amom.x; - amom.y = vessel->Amom.y; - amom.z = vessel->Amom.z; + amom = vessel->Amom; } void VESSEL::GetGlobalOrientation (VECTOR3 &arot) const @@ -6474,7 +6438,7 @@ void VESSEL::GetGlobalOrientation (VECTOR3 &arot) const void VESSEL::SetGlobalOrientation (const VECTOR3 &arot) const { - vessel->SetGlobalOrientation (MakeVector (arot)); + vessel->SetGlobalOrientation(arot); } OBJHANDLE VESSEL::GetEquPos (double &longitude, double &latitude, double &radius) const @@ -6532,23 +6496,17 @@ bool VESSEL::GetGroundspeedVector (REFFRAME frame, VECTOR3 &v) const case FRAME_LOCAL: v.x = sp->groundvel_ship.x, v.y = sp->groundvel_ship.y, v.z = sp->groundvel_ship.z; return true; - case FRAME_REFLOCAL: { - Vector hvel (tmul (sp->ref->GRot(), sp->groundvel_glob)); - v.x = hvel.x, v.y = hvel.y, v.z = hvel.z; - } return true; - case FRAME_HORIZON: { - Vector hvel (tmul (sp->ref->GRot(), sp->groundvel_glob)); - hvel.Set (mul (sp->L2H, hvel)); - v.x = hvel.x, v.y = hvel.y, v.z = hvel.z; - } return true; - default: - v.x = v.y = v.z = 0.0; - return false; + case FRAME_REFLOCAL: + v = tmul(sp->ref->GRot(), sp->groundvel_glob); + return true; + case FRAME_HORIZON: + v = mul(sp->L2H, tmul(sp->ref->GRot(), sp->groundvel_glob)); + return true; } - } else { - v.x = v.y = v.z = 0.0; - return false; } + + v = {0, 0, 0}; + return false; } double VESSEL::GetAirspeed (void) const @@ -6569,23 +6527,17 @@ bool VESSEL::GetAirspeedVector (REFFRAME frame, VECTOR3 &v) const case FRAME_LOCAL: v.x = sp->airvel_ship.x, v.y = sp->airvel_ship.y, v.z = sp->airvel_ship.z; return true; - case FRAME_REFLOCAL: { - Vector hvel (tmul (sp->ref->GRot(), sp->airvel_glob)); - v.x = hvel.x, v.y = hvel.y, v.z = hvel.z; - } return true; - case FRAME_HORIZON: { - Vector hvel (tmul (sp->ref->GRot(), sp->airvel_glob)); - hvel.Set (mul (sp->L2H, hvel)); - v.x = hvel.x, v.y = hvel.y, v.z = hvel.z; - } return true; - default: - v.x = v.y = v.z = 0.0; - return false; + case FRAME_REFLOCAL: + v = tmul(sp->ref->GRot(), sp->airvel_glob); + return true; + case FRAME_HORIZON: + v = mul(sp->L2H, tmul(sp->ref->GRot(), sp->airvel_glob)); + return true; } - } else { - v.x = v.y = v.z = 0.0; - return false; } + + v = {0, 0, 0}; + return false; } bool VESSEL::GetShipAirspeedVector (VECTOR3 &v) const @@ -6606,12 +6558,10 @@ bool VESSEL::GetHorizonAirspeedVector (VECTOR3 &v) const LOGOUT_OBSOLETE; const SurfParam *sp = vessel->GetSurfParam(); if (sp) { - Vector hvel (tmul (sp->ref->GRot(), sp->airvel_glob)); - hvel.Set (mul (sp->L2H, hvel)); - v.x = hvel.x, v.y = hvel.y, v.z = hvel.z; + v = mul(sp->L2H, tmul(sp->ref->GRot(), sp->airvel_glob)); return true; } else { - v.x = v.y = v.z = 0.0; + v = {0, 0, 0}; return false; } } @@ -6655,7 +6605,7 @@ double VESSEL::GetSurfaceElevation () const VECTOR3 VESSEL::GetSurfaceNormal () const { const SurfParam *sp = vessel->GetSurfParam(); - return sp ? _V(sp->surfnml.x, sp->surfnml.y, sp->surfnml.z): _V(0,0,0); + return sp ? VECTOR3{sp->surfnml.x, sp->surfnml.y, sp->surfnml.z}: VECTOR3{0, 0, 0}; } double VESSEL::GetLift (void) const @@ -6668,52 +6618,34 @@ double VESSEL::GetDrag (void) const return vessel->Drag; } -bool VESSEL::GetWeightVector (VECTOR3 &G) const +bool VESSEL::GetWeightVector(VECTOR3 &G) const { - static Vector F; - bool bWeight = vessel->GetWeightVector (F); - CopyVector (F, G); - return bWeight; + return vessel->GetWeightVector(G); } -bool VESSEL::GetThrustVector (VECTOR3 &T) const +bool VESSEL::GetThrustVector(VECTOR3 &T) const { - static Vector F; - bool bThrust = vessel->GetThrustVector (F); - CopyVector (F, T); - return bThrust; + return vessel->GetThrustVector(T); } -bool VESSEL::GetLiftVector (VECTOR3 &L) const +bool VESSEL::GetLiftVector(VECTOR3 &L) const { - static Vector F; - bool bLift = vessel->GetLiftVector (F); - CopyVector (F, L); - return bLift; + return vessel->GetLiftVector(L); } -bool VESSEL::GetDragVector (VECTOR3 &D) const +bool VESSEL::GetDragVector(VECTOR3 &D) const { - static Vector F; - bool bDrag = vessel->GetDragVector (F); - CopyVector (F, D); - return bDrag; + return vessel->GetDragVector(D); } -bool VESSEL::GetForceVector (VECTOR3 &F) const +bool VESSEL::GetForceVector(VECTOR3 &F) const { - static Vector FF; - bool bForce = vessel->GetForceVector (FF); - CopyVector (FF, F); - return bForce; + return vessel->GetForceVector(F); } -bool VESSEL::GetTorqueVector (VECTOR3 &M) const +bool VESSEL::GetTorqueVector(VECTOR3 &M) const { - static Vector F; - bool bTorque = vessel->GetTorqueVector (F); - CopyVector (F, M); - return bTorque; + return vessel->GetTorqueVector(M); } OBJHANDLE VESSEL::GetElements (ELEMENTS &el, double &mjd_ref) const @@ -6738,8 +6670,8 @@ bool VESSEL::GetElements (OBJHANDLE hRef, ELEMENTS &el, ORBITPARAM *prm, double const CelestialBody *ref = (hRef ? (CelestialBody*)hRef : vessel->cbody); Elements els (1, 0, 0, 0, 0, 0, mjd_ref ? mjd_ref : td.MJD0); els.SetMasses (0, ref->Mass()); - Vector p (vessel->GPos()-ref->GPos()); - Vector v (vessel->GVel()-ref->GVel()); + VECTOR3 p = vessel->GPos() - ref->GPos(); + VECTOR3 v = vessel->GVel() - ref->GVel(); // rotate ecliptic -> equatorial frame if (frame == FRAME_EQU) { @@ -6780,7 +6712,7 @@ bool VESSEL::SetElements (OBJHANDLE hRef, const ELEMENTS &el, ORBITPARAM *prm, d if (!mjd_ref) mjd_ref = td.MJD0; els.Set (el.a, el.e, el.i, el.theta, el.omegab, el.L, mjd_ref); els.Setup (0, ref->Mass(), mjd_ref); - Vector p, v; + VECTOR3 p, v; if (prm) { els.Update (p, v); prm->SMi = els.SMi(); @@ -6802,7 +6734,7 @@ bool VESSEL::SetElements (OBJHANDLE hRef, const ELEMENTS &el, ORBITPARAM *prm, d p = mul (ref->RotObliq(), p); v = mul (ref->RotObliq(), v); } - if (p.length() < ref->Size()) + if (len(p) < ref->Size()) return false; // don't allow vessel below planet surface vessel->RPlace (p + ref->GPos(), v + ref->GVel()); @@ -7026,11 +6958,11 @@ void VESSEL::SetCOG_elev (double cog) const void VESSEL::SetCrossSections (const VECTOR3 &cs) const { - vessel->cs.Set (cs.x, cs.y, cs.z); - vessel->vd_forw = cs.z * 0.5*vessel->CWz[0]; - vessel->vd_back = cs.z * 0.5*vessel->CWz[1]; - vessel->vd_vert = cs.y * 0.5*vessel->CWy; - vessel->vd_side = cs.x * 0.5*vessel->CWx; + vessel->cs = cs; + vessel->vd_forw = cs.z * 0.5 * vessel->CWz[0]; + vessel->vd_back = cs.z * 0.5 * vessel->CWz[1]; + vessel->vd_vert = cs.y * 0.5 * vessel->CWy; + vessel->vd_side = cs.x * 0.5 * vessel->CWx; } void VESSEL::SetCW (double cw_z_pos, double cw_z_neg, double cw_x, double cw_y) const @@ -7060,7 +6992,7 @@ void VESSEL::SetWingEffectiveness (double eff) const void VESSEL::SetRotDrag (const VECTOR3 &rd) const { - vessel->rdrag.Set (rd.x, rd.y, rd.z); + vessel->rdrag = rd; } double VESSEL::GetPitchMomentScale () const @@ -7097,12 +7029,12 @@ void VESSEL::SetBankMomentScale (double scale) const void VESSEL::SetPMI (const VECTOR3 &pmi) const { - vessel->pmi.Set (pmi.x, pmi.y, pmi.z); + vessel->pmi = pmi; } void VESSEL::SetAlbedoRGB (const VECTOR3 &albedo) const { - vessel->albedo.Set(albedo.x, albedo.y, albedo.z); + vessel->albedo = albedo; } double VESSEL::GetTrimScale () const @@ -7118,19 +7050,19 @@ void VESSEL::SetTrimScale (double scale) const void VESSEL::SetCameraOffset (const VECTOR3 &co) const { - vessel->campos.Set (co.x, co.y, co.z); + vessel->campos = co; } void VESSEL::SetCameraDefaultDirection (const VECTOR3 &cd) const { - vessel->camdir0.Set (cd.x, cd.y, cd.z); + vessel->camdir0 = cd; vessel->camtilt0 = 0; if (vessel == g_focusobj) g_camera->SetDefaultCockpitDir (vessel->camdir0); } void VESSEL::SetCameraDefaultDirection (const VECTOR3 &cd, double tilt) const { - vessel->camdir0.Set (cd.x, cd.y, cd.z); + vessel->camdir0 = cd; vessel->camtilt0 = tilt; if (vessel == g_focusobj) g_camera->SetDefaultCockpitDir (vessel->camdir0, tilt); } @@ -7180,7 +7112,7 @@ void VESSEL::SetLiftCoeffFunc (LiftCoeffFunc lcf) const DOCKHANDLE VESSEL::CreateDock (const VECTOR3 &pos, const VECTOR3 &dir, const VECTOR3 &rot) const { - return (DOCKHANDLE)vessel->CreateDock (MakeVector (pos), MakeVector (dir), MakeVector (rot)); + return (DOCKHANDLE)vessel->CreateDock(pos, dir, rot); } bool VESSEL::DelDock (DOCKHANDLE hDock) const @@ -7196,14 +7128,14 @@ void VESSEL::ClearDockDefinitions () const void VESSEL::SetDockParams (const VECTOR3 &pos, const VECTOR3 &dir, const VECTOR3 &rot) const { if (!vessel->ndock) - vessel->CreateDock (MakeVector (pos), MakeVector (dir), MakeVector (rot)); + vessel->CreateDock(pos, dir, rot); else - vessel->SetDockParams (vessel->dock[0], MakeVector (pos), MakeVector (dir), MakeVector (rot)); + vessel->SetDockParams(vessel->dock[0], pos, dir, rot); } void VESSEL::SetDockParams (DOCKHANDLE dock, const VECTOR3 &pos, const VECTOR3 &dir, const VECTOR3 &rot) const { - vessel->SetDockParams ((PortSpec*)dock, MakeVector (pos), MakeVector (dir), MakeVector (rot)); + vessel->SetDockParams((PortSpec*)dock, pos, dir, rot); } void VESSEL::GetDockParams (DOCKHANDLE dock, VECTOR3 &pos, VECTOR3 &dir, VECTOR3 &rot) const @@ -7252,7 +7184,7 @@ void VESSEL::SetDockMode (int mode) const ATTACHMENTHANDLE VESSEL::CreateAttachment (bool toparent, const VECTOR3 &pos, const VECTOR3 &dir, const VECTOR3 &rot, const char *id, bool loose) const { - return (ATTACHMENTHANDLE)vessel->CreateAttachment (toparent, MakeVector (pos), MakeVector (dir), MakeVector (rot), id, loose); + return (ATTACHMENTHANDLE)vessel->CreateAttachment(toparent, pos, dir, rot, id, loose); } bool VESSEL::DelAttachment (ATTACHMENTHANDLE attachment) const @@ -7267,7 +7199,7 @@ void VESSEL::ClearAttachments () const void VESSEL::SetAttachmentParams (ATTACHMENTHANDLE attachment, const VECTOR3 &pos, const VECTOR3 &dir, const VECTOR3 &rot) const { - vessel->SetAttachmentParams ((AttachmentSpec*)attachment, MakeVector (pos), MakeVector (dir), MakeVector (rot)); + vessel->SetAttachmentParams((AttachmentSpec*)attachment, pos, dir, rot); } void VESSEL::GetAttachmentParams (ATTACHMENTHANDLE attachment, VECTOR3 &pos, VECTOR3 &dir, VECTOR3 &rot) const @@ -7369,12 +7301,7 @@ void VESSEL::ClearLightEmitters () const bool VESSEL::GetSuperstructureCG (VECTOR3 &cg) const { - Vector vcg; - bool ok = vessel->GetSuperStructCG (vcg); - cg.x = vcg.x; - cg.y = vcg.y; - cg.z = vcg.z; - return ok; + return vessel->GetSuperStructCG (cg); } void VESSEL::SetTouchdownPoints (const VECTOR3 &pt1, const VECTOR3 &pt2, const VECTOR3 &pt3) const @@ -7400,9 +7327,9 @@ void VESSEL::SetTouchdownPoints (const TOUCHDOWNVTX *tdvtx, DWORD ntdvtx) const void VESSEL::GetTouchdownPoints (VECTOR3 &pt1, VECTOR3 &pt2, VECTOR3 &pt3) const { - CopyVector (vessel->touchdown_vtx[0].pos, pt1); - CopyVector (vessel->touchdown_vtx[1].pos, pt2); - CopyVector (vessel->touchdown_vtx[2].pos, pt3); + pt1 = vessel->touchdown_vtx[0].pos; + pt2 = vessel->touchdown_vtx[1].pos; + pt3 = vessel->touchdown_vtx[2].pos; } bool VESSEL::GetTouchdownPoint (TOUCHDOWNVTX &tdvtx, DWORD idx) const @@ -7644,8 +7571,8 @@ UINT VESSEL::AddAttExhaustRef (const VECTOR3 &pos, const VECTOR3 &dir, double ws vessel->oexhaust = NULL; } tmp[n] = new OldExhaustSpec; TRACENEW - tmp[n]->ref = MakeVector(pos); - tmp[n]->dir = -MakeVector(dir); + tmp[n]->ref = pos; + tmp[n]->dir = -dir; tmp[n]->lscale = 3.0*lscale; tmp[n]->wscale = 0.387*wscale; vessel->oexhaust = tmp; @@ -7704,12 +7631,11 @@ void VESSEL::ClearAttExhaustRefs (void) const void VESSEL::ShiftCentreOfMass (const VECTOR3 &shift) { if (vessel->bFRrecord) vessel->FRecorder_Save (true); - Vector dr (shift.x, shift.y, shift.z); - Vector gdr (mul (vessel->GRot(), dr)); + VECTOR3 gdr = mul(vessel->GRot(), shift); vessel->FlushRPos (); if (!vessel->bFRplayback) { // ignore during playback vessel->AddRPos (gdr); - if (vessel->supervessel) vessel->supervessel->NotifyShiftVesselOrigin (vessel, dr); + if (vessel->supervessel) vessel->supervessel->NotifyShiftVesselOrigin (vessel, shift); } g_pOrbiter->NotifyObjectJump (vessel, gdr); if (vessel->bFRrecord) vessel->FRecorder_Save (true); @@ -7717,17 +7643,16 @@ void VESSEL::ShiftCentreOfMass (const VECTOR3 &shift) void VESSEL::ShiftCG (const VECTOR3 &shift) { - VECTOR3 nshift = -shift; - Vector vs = MakeVector (nshift); - ShiftMeshes (nshift); - vessel->ShiftThrusters (vs); - vessel->ShiftAttachments (vs); - vessel->ShiftDocks (vs); - vessel->ShiftLightEmitters (nshift); - vessel->campos.Set (vessel->campos+vs); + auto nshift = -shift; + ShiftMeshes(nshift); + vessel->ShiftThrusters(nshift); + vessel->ShiftAttachments(nshift); + vessel->ShiftDocks(nshift); + vessel->ShiftLightEmitters(nshift); + vessel->campos = vessel->campos + nshift; // only shift the vc of this vessel - if ((g_pane) && (g_focusobj == vessel)) g_pane->ShiftVC (vs); - ShiftCentreOfMass (shift); + if ((g_pane) && (g_focusobj == vessel)) g_pane->ShiftVC(nshift); + ShiftCentreOfMass(shift); } void VESSEL::GetRotationMatrix (MATRIX3 &R) const @@ -7744,52 +7669,34 @@ void VESSEL::SetRotationMatrix (const MATRIX3 &R) const void VESSEL::GlobalRot (const VECTOR3 &rloc, VECTOR3 &rglob) const { - Vector loc(rloc.x, rloc.y, rloc.z); - Vector glob (mul (vessel->GRot(), loc)); - rglob.x = glob.x; - rglob.y = glob.y; - rglob.z = glob.z; + rglob = mul(vessel->GRot(), rloc); } void VESSEL::HorizonRot (const VECTOR3 &rloc, VECTOR3 &rhorizon) const { if (!vessel->proxyplanet) return; - Vector h (mul (vessel->sp.L2H, tmul (vessel->proxyplanet->GRot(), mul (vessel->GRot(), MakeVector(rloc))))); - rhorizon = _V(h.x, h.y, h.z); + rhorizon = mul(vessel->sp.L2H, tmul(vessel->proxyplanet->GRot(), mul(vessel->GRot(), rloc))); } void VESSEL::HorizonInvRot (const VECTOR3 &rhorizon, VECTOR3 &rloc) const { if (!vessel->proxyplanet) return; - Vector r (tmul (vessel->GRot(), mul (vessel->proxyplanet->GRot(), tmul (vessel->sp.L2H, MakeVector (rhorizon))))); - rloc = _V(r.x, r.y, r.z); + rloc = tmul(vessel->GRot(), mul(vessel->proxyplanet->GRot(), tmul(vessel->sp.L2H, rhorizon))); } void VESSEL::Local2Global (const VECTOR3 &local, VECTOR3 &global) const { - Vector loc(local.x, local.y, local.z); - Vector glob (mul (vessel->GRot(), loc) + vessel->GPos()); - global.x = glob.x; - global.y = glob.y; - global.z = glob.z; + global = mul(vessel->GRot(), local) + vessel->GPos(); } void VESSEL::Global2Local (const VECTOR3 &global, VECTOR3 &local) const { - Vector glob(global.x, global.y, global.z); - Vector loc (tmul (vessel->GRot(), glob - vessel->GPos())); - local.x = loc.x; - local.y = loc.y; - local.z = loc.z; + local = tmul(vessel->GRot(), global - vessel->GPos()); } void VESSEL::Local2Rel (const VECTOR3 &local, VECTOR3 &rel) const { - Vector loc(local.x, local.y, local.z); - Vector r (mul (vessel->GRot(), loc) + vessel->GPos() - vessel->cbody->GPos()); - rel.x = r.x; - rel.y = r.y; - rel.z = r.z; + rel = mul(vessel->GRot(), local) + vessel->GPos() - vessel->cbody->GPos(); } void VESSEL::RegisterAnimation (void) const @@ -7861,12 +7768,8 @@ SUPERVESSELHANDLE VESSEL::GetSupervessel () const VECTOR3 VESSEL::GetSupervesselCG () const { - VECTOR3 cg = _V(0,0,0); - if (vessel->supervessel) { - Vector vcg; - if (vessel->supervessel->GetCG (vessel, vcg)) - cg = MakeVECTOR3 (vcg); - } + VECTOR3 cg{0, 0, 0}; + if (vessel->supervessel) vessel->supervessel->GetCG(vessel, cg); return cg; } @@ -7892,7 +7795,7 @@ void VESSEL::SaveDefaultState (FILEHANDLE scn) const void VESSEL::AddForce (const VECTOR3 &F, const VECTOR3 &r) const { - vessel->AddForce (MakeVector(F), MakeVector(r)); + vessel->AddForce(F, r); } PROPELLANT_HANDLE VESSEL::CreatePropellantResource (double maxmass, double mass, double efficiency) const @@ -7981,8 +7884,7 @@ double VESSEL::GetTotalPropellantFlowrate () const THRUSTER_HANDLE VESSEL::CreateThruster (const VECTOR3 &pos, const VECTOR3 &dir, double maxth0, PROPELLANT_HANDLE hp, double isp0, double isp_ref, double p_ref) const { - return (THRUSTER_HANDLE)vessel->CreateThruster (MakeVector(pos), MakeVector(dir), - maxth0, (TankSpec*)hp, isp0, isp_ref, p_ref); + return (THRUSTER_HANDLE)vessel->CreateThruster(pos, dir, maxth0, (TankSpec*)hp, isp0, isp_ref, p_ref); } bool VESSEL::DelThruster (THRUSTER_HANDLE &th) const @@ -8014,9 +7916,7 @@ void VESSEL::SetThrusterRef (THRUSTER_HANDLE th, const VECTOR3 &pos) const void VESSEL::GetThrusterRef (THRUSTER_HANDLE th, VECTOR3 &pos) const { - pos.x = ((ThrustSpec*)th)->ref.x; - pos.y = ((ThrustSpec*)th)->ref.y; - pos.z = ((ThrustSpec*)th)->ref.z; + pos = ((ThrustSpec*)th)->ref; } void VESSEL::SetThrusterDir (THRUSTER_HANDLE th, const VECTOR3 &dir) const @@ -8026,9 +7926,7 @@ void VESSEL::SetThrusterDir (THRUSTER_HANDLE th, const VECTOR3 &dir) const void VESSEL::GetThrusterDir (THRUSTER_HANDLE th, VECTOR3 &dir) const { - dir.x = ((ThrustSpec*)th)->dir.x; - dir.y = ((ThrustSpec*)th)->dir.y; - dir.z = ((ThrustSpec*)th)->dir.z; + dir = ((ThrustSpec*)th)->dir; } void VESSEL::SetThrusterMax0 (THRUSTER_HANDLE th, double maxth0) const @@ -8137,14 +8035,7 @@ double VESSEL::GetThrusterLevel (THRUSTER_HANDLE th) const void VESSEL::GetThrusterMoment (THRUSTER_HANDLE th, VECTOR3 &F, VECTOR3 &T) const { - Vector f, t; - vessel->GetThrusterMoment ((ThrustSpec*)th, f, t); - F.x = f.x; - F.y = f.y; - F.z = f.z; - T.x = t.x; - T.y = t.y; - T.z = t.z; + vessel->GetThrusterMoment ((ThrustSpec*)th, F, T); } THGROUP_HANDLE VESSEL::CreateThrusterGroup (THRUSTER_HANDLE *th, int nth, THGROUP_TYPE thgt) const @@ -8274,8 +8165,7 @@ UINT VESSEL::AddExhaust (THRUSTER_HANDLE th, double lscale, double wscale, doubl UINT VESSEL::AddExhaust (THRUSTER_HANDLE th, double lscale, double wscale, const VECTOR3 &pos, const VECTOR3 &dir, SURFHANDLE tex) const { - VECTOR3 p = {pos.x, pos.y, pos.z}; - VECTOR3 d = {-dir.x, -dir.y, -dir.z}; + VECTOR3 p = pos, d = -dir; EXHAUSTSPEC es = {th, NULL, &p, &d, lscale, wscale, 0, 0, tex, EXHAUST_CONSTANTPOS|EXHAUST_CONSTANTDIR}; return vessel->AddExhaust (&es); } @@ -8327,9 +8217,7 @@ double VESSEL::GetExhaustLevel (UINT idx) const PSTREAM_HANDLE VESSEL::AddParticleStream (PARTICLESTREAMSPEC *pss, const VECTOR3 &pos, const VECTOR3 &dir, double *lvl) const { - Vector p (pos.x, pos.y, pos.z); - Vector d (dir.x, dir.y, dir.z); - return (PSTREAM_HANDLE)vessel->AddParticleStream (pss, p, d, lvl); + return (PSTREAM_HANDLE)vessel->AddParticleStream (pss, pos, dir, lvl); } PSTREAM_HANDLE VESSEL::AddExhaustStream (THRUSTER_HANDLE th, PARTICLESTREAMSPEC *pss) const @@ -8339,8 +8227,7 @@ PSTREAM_HANDLE VESSEL::AddExhaustStream (THRUSTER_HANDLE th, PARTICLESTREAMSPEC PSTREAM_HANDLE VESSEL::AddExhaustStream (THRUSTER_HANDLE th, const VECTOR3 &pos, PARTICLESTREAMSPEC *pss) const { - Vector p (pos.x, pos.y, pos.z); - return (PSTREAM_HANDLE)vessel->AddExhaustStream ((ThrustSpec*)th, pss, &p); + return (PSTREAM_HANDLE)vessel->AddExhaustStream((ThrustSpec*)th, pss, &pos); } bool VESSEL::DelExhaustStream (PSTREAM_HANDLE ch) const @@ -8357,20 +8244,17 @@ PSTREAM_HANDLE VESSEL::AddReentryStream (PARTICLESTREAMSPEC *pss) const void VESSEL::CreateAirfoil (AIRFOIL_ORIENTATION align, const VECTOR3 &ref, AirfoilCoeffFunc cf, double c, double S, double A) const { - Vector r(MakeVector(ref)); - vessel->CreateAirfoil (align, r, cf, c, S, A); + vessel->CreateAirfoil(align, ref, cf, c, S, A); } AIRFOILHANDLE VESSEL::CreateAirfoil2 (AIRFOIL_ORIENTATION align, const VECTOR3 &ref, AirfoilCoeffFunc cf, double c, double S, double A) const { - Vector r(MakeVector(ref)); - return (AIRFOILHANDLE)vessel->CreateAirfoil (align, r, cf, c, S, A); + return (AIRFOILHANDLE)vessel->CreateAirfoil(align, ref, cf, c, S, A); } AIRFOILHANDLE VESSEL::CreateAirfoil3 (AIRFOIL_ORIENTATION align, const VECTOR3 &ref, AirfoilCoeffFuncEx cf, void *context, double c, double S, double A) const { - Vector r(MakeVector(ref)); - return (AIRFOILHANDLE)vessel->CreateAirfoil (align, r, cf, context, c, S, A); + return (AIRFOILHANDLE)vessel->CreateAirfoil(align, ref, cf, context, c, S, A); } bool VESSEL::GetAirfoilParam (AIRFOILHANDLE hAirfoil, VECTOR3 *ref, AirfoilCoeffFunc *cf, void **context, double *c, double *S, double *A) const @@ -8380,7 +8264,7 @@ bool VESSEL::GetAirfoilParam (AIRFOILHANDLE hAirfoil, VECTOR3 *ref, AirfoilCoeff void VESSEL::EditAirfoil (AIRFOILHANDLE hAirfoil, DWORD flag, const VECTOR3 &ref, AirfoilCoeffFunc cf, double c, double S, double A) const { - vessel->EditAirfoil ((AirfoilSpec*)hAirfoil, flag, MakeVector(ref), cf, c, S, A); + vessel->EditAirfoil((AirfoilSpec*)hAirfoil, flag, ref, cf, c, S, A); } bool VESSEL::DelAirfoil (AIRFOILHANDLE hAirfoil) const @@ -8395,17 +8279,17 @@ void VESSEL::ClearAirfoilDefinitions () const void VESSEL::CreateControlSurface (AIRCTRL_TYPE type, double area, double dCl, const VECTOR3 &ref, int axis, UINT anim) const { - vessel->CreateControlSurface (type, area, dCl, MakeVector(ref), axis, 1.0, anim); + vessel->CreateControlSurface(type, area, dCl, ref, axis, 1.0, anim); } CTRLSURFHANDLE VESSEL::CreateControlSurface2 (AIRCTRL_TYPE type, double area, double dCl, const VECTOR3 &ref, int axis, UINT anim) const { - return vessel->CreateControlSurface (type, area, dCl, MakeVector(ref), axis, 1.0, anim); + return vessel->CreateControlSurface(type, area, dCl, ref, axis, 1.0, anim); } CTRLSURFHANDLE VESSEL::CreateControlSurface3 (AIRCTRL_TYPE type, double area, double dCl, const VECTOR3 &ref, int axis, double delay, UINT anim) const { - return vessel->CreateControlSurface (type, area, dCl, MakeVector(ref), axis, delay, anim); + return vessel->CreateControlSurface(type, area, dCl, ref, axis, delay, anim); } bool VESSEL::DelControlSurface (CTRLSURFHANDLE hCtrlSurf) const @@ -8436,12 +8320,12 @@ double VESSEL::GetControlSurfaceLevel (AIRCTRL_TYPE type) const void VESSEL::CreateVariableDragElement (double *drag, double factor, const VECTOR3 &ref) const { LOGOUT_OBSOLETE; - vessel->CreateVariableDragElement (drag, factor, MakeVector(ref)); + vessel->CreateVariableDragElement(drag, factor, ref); } void VESSEL::CreateVariableDragElement (const double *drag, double factor, const VECTOR3 &ref) const { - vessel->CreateVariableDragElement (drag, factor, MakeVector(ref)); + vessel->CreateVariableDragElement(drag, factor, ref); } void VESSEL::ClearVariableDragElements () const @@ -8711,7 +8595,7 @@ int VESSEL2::clbkConsumeBufferedKey (DWORD key, bool down, char *keystate) bool VESSEL2::clbkLoadGenericCockpit () { - SetCameraDefaultDirection (_V(0,0,1)); + SetCameraDefaultDirection ({0,0,1}); return true; } @@ -8818,7 +8702,7 @@ void VESSEL3::clbkGetRadiationForce (const VECTOR3 &mflux, VECTOR3 &F, VECTOR3 & double albedo = 1.5; // simplistic albedo (mixture of absorption, reflection) F = mflux * (cs*albedo); - pos = _V(0,0,0); // don't induce torque + pos = {0, 0, 0}; // don't induce torque } @@ -8850,4 +8734,4 @@ bool VESSEL4::UnregisterMFDMode (int mode) int VESSEL4::clbkNavProcess (int mode) { return mode; -} +} diff --git a/Src/Orbiter/Vessel.h b/Src/Orbiter/Vessel.h index 83ebfc09f..e0fbbd7ce 100644 --- a/Src/Orbiter/Vessel.h +++ b/Src/Orbiter/Vessel.h @@ -55,10 +55,10 @@ struct ScenarioData { // packed vessel state BYTE fstate; // flight status union { struct { - Vector rpos; // reference body-relative position - Vector rvel; // reference body-relative velocity - Vector arot; // orientation (Euler angles) - Vector vrot; // angular velocity + VECTOR3 rpos; // reference body-relative position + VECTOR3 rvel; // reference body-relative velocity + VECTOR3 arot; // orientation (Euler angles) + VECTOR3 vrot; // angular velocity }; struct { double lng; // longitude of landing site [rad] @@ -99,15 +99,15 @@ struct ThrustGroupSpec { // thruster group definition }; typedef struct { // obsolete exhaust render definition - Vector ref; // exhaust reference pos - Vector dir; // exhaust reference dir + VECTOR3 ref; // exhaust reference pos + VECTOR3 dir; // exhaust reference dir double lscale, wscale; // exhaust size scaling } OldExhaustSpec; typedef struct { // airfoil definition int version; // 0: uses AirfoilCoeffFunc, 1: uses AirfoilCoeffFuncEx AIRFOIL_ORIENTATION align; // vertical or horizontal - Vector ref; // lift,drag attack reference point + VECTOR3 ref; // lift,drag attack reference point AirfoilCoeffFunc cf; // pointer to coefficients callback function void *context; // user-defined pointer passed to AirfoilCoeffFuncEx double c; // airfoil chord length @@ -117,7 +117,7 @@ typedef struct { // airfoil definition typedef struct { // airfoil control surface definition AIRCTRL_TYPE ctrl; // control type - Vector ref; // lift/drag attack point + VECTOR3 ref; // lift/drag attack point int axis; // axis orientation: 1=+Y, 2=-Y, 3=+X, 4=-X (should allow freely defined axes) double area; // surface area double dCl; // lift coefficient differential @@ -125,15 +125,15 @@ typedef struct { // airfoil control surface definition } CtrlsurfSpec; typedef struct { // variable drag element definition - Vector ref; // drag attack point + VECTOR3 ref; // drag attack point const double *drag; // pointer to external drag magnitude double factor; // drag magnitude multiplier: *drag * factor = Cd } DragElementSpec; typedef struct { // docking port definition - Vector ref; // docking port reference pos - Vector dir; // approach direction - Vector rot; // longitudinal rotation alignment direction + VECTOR3 ref; // docking port reference pos + VECTOR3 dir; // approach direction + VECTOR3 rot; // longitudinal rotation alignment direction Vessel *mate; // vessel attached to port (NULL for none) Vessel *pending; // vessel being currently docked/undocked int status; // 0=normal (docked/free), 1=docking in progress, 2=undocking in progress @@ -142,9 +142,9 @@ typedef struct { // docking port definition } PortSpec; typedef struct tagAttachmentSpec { // parent/child attachment definition - Vector ref; // reference pos - Vector dir; // approach direction - Vector rot; // longitudinal rotation alignment direction + VECTOR3 ref; // reference pos + VECTOR3 dir; // approach direction + VECTOR3 rot; // longitudinal rotation alignment direction bool toparent; // attachment is from child to parent bool loose; // loose attachment allowed (orientation not enforced) Vessel *mate; // attached vessel @@ -185,8 +185,8 @@ struct FRecord { // flight recorder status sample int frm; // 0=ecliptic, 1=equatorial int crd; // 0=cartesian, 1=polar const CelestialBody *ref; // status reference object - Vector rpos; // planet-relative position - Vector rvel; // planet-relative velocity + VECTOR3 rpos; // planet-relative position + VECTOR3 rvel; // planet-relative velocity }; struct FRecord_att { // flight recorder attitude sample @@ -290,16 +290,16 @@ class Vessel: public VesselBase { void SetClipRadius (double rad) { clipradius = rad; } // near plane render clipping distance - void RPlace (const Vector &rpos, const Vector &rvel); + void RPlace(const VECTOR3 &rpos, const VECTOR3 &rvel); // Set vessel position and velocity in parent coords // If the vessel is part of a superstructure, the complete structure // is moved accordingly - void RPlace_individual (const Vector &rpos, const Vector &rvel); + void RPlace_individual(const VECTOR3 &rpos, const VECTOR3 &rvel); // this version enforces the repositioning of the vessel without reporting // to the supervessel - void SetGlobalOrientation (const Vector &arot); + void SetGlobalOrientation(const VECTOR3 &arot); // Set vessel orientation from vector of Euler angles // If the vessel is part of a superstructure, the complete structure is // rotated @@ -309,27 +309,27 @@ class Vessel: public VesselBase { // If the vessel is part of a superstructure, the complete structure is // rotated - void GetIntermediateMoments (Vector &acc, Vector &tau, + void GetIntermediateMoments(VECTOR3 &acc, VECTOR3 &tau, const StateVectors &state, double tfrac, double dt); // Returns acceleration acc and torque tau, at time SimT0+tfrac*SimDT // and step size dt, given intermediate state in global frame - void GetIntermediateMoments_pert (Vector &acc, Vector &tau, + void GetIntermediateMoments_pert(VECTOR3 &acc, VECTOR3 &tau, const StateVectors &state_rel, double tfrac, double dt, const CelestialBody *cbody); - Vector GetTorque () const; + VECTOR3 GetTorque() const; // Returns mass-normalised torque at state s0. - Vector GetMomentumFlux () const; + VECTOR3 GetMomentumFlux() const; // returns the momentum flux vector due to solar radiation at current spacecraft position - void SetAngVel (const Vector &omega); - void SetAngVel_individual (const Vector &omega); + void SetAngVel(const VECTOR3 &omega); + void SetAngVel_individual(const VECTOR3 &omega); // Set angular velocity components to omega [rad/s] // If the vessel is part of a superstructure, SetAngVel applies the spin is to the // complete structure, while SetAngVel_individual only affects the single vessel - inline const Vector &Flin_induced() { return Flin; } + inline const VECTOR3 &Flin_induced() { return Flin; } // Return linear forces (other than gravity) currently acting on the vessel void FocusChanged (bool getfocus, Vessel *newvessel, Vessel *oldvessel); @@ -360,35 +360,35 @@ class Vessel: public VesselBase { double GetLift () const { return Lift; } double GetDrag () const { return Drag; } - double GetWeight () const { Vector G; GetWeightVector(G); return G.length(); } + double GetWeight() const { VECTOR3 G; GetWeightVector(G); return len(G); } - bool GetWeightVector (Vector &G) const; + bool GetWeightVector(VECTOR3 &G) const; // Returns gravitational force vector (weight) (in local vessel frame). - bool GetThrustVector (Vector &T) const; + bool GetThrustVector(VECTOR3 &T) const; // Returns linear thrust vector in T (in local vessel frame). // Return value indicates if thrust is present - bool GetLiftVector (Vector &L) const; + bool GetLiftVector(VECTOR3 &L) const; // Returns lift vector in L (in local vessel frame). // Return value indicates if lift is present - bool GetDragVector (Vector &D) const; + bool GetDragVector(VECTOR3 &D) const; // Returns drag vector in D (in local vessel frame). // Return value indicates if drag is present - bool GetForceVector (Vector &F) const; + bool GetForceVector(VECTOR3 &F) const; // Returns total linear force vector acting on the vessel // Return value is always true - bool GetTorqueVector (Vector &M) const; + bool GetTorqueVector(VECTOR3 &M) const; // Returns the total torque vector acting on the vessel // Return value is always true // ======================================================================== // thruster management - ThrustSpec *CreateThruster (const Vector &pos, const Vector &dir, double maxth0, + ThrustSpec *CreateThruster(const VECTOR3 &pos, const VECTOR3 &dir, double maxth0, TankSpec *ts=0, double isp0=0.0, double isp_ref=0.0, double p_ref=101.4e3); // Add a (logical) thruster with given position, thrust direction and max vacuum thrust [N] // If ts=0 then the thruster is disabled until it is linked to a propellant resource @@ -400,13 +400,13 @@ class Vessel: public VesselBase { bool DelThruster (ThrustSpec *ts); // delete thruster ts from list - void ShiftThrusters (const Vector &shift); + void ShiftThrusters(const VECTOR3 &shift); // shift all thruster reference points (usually in response to CG shift) - Vector GetThrusterForce (const ThrustSpec *ts) const; + VECTOR3 GetThrusterForce(const ThrustSpec *ts) const; // returns linear force F currently produced by thruster ts - void GetThrusterMoment (const ThrustSpec *ts, Vector &F, Vector &T) const; + void GetThrusterMoment(const ThrustSpec *ts, VECTOR3 &F, VECTOR3 &T) const; // returns linear force F and torque T currently produced by thruster ts void ClearThrusterDefinitions (); @@ -669,14 +669,14 @@ class Vessel: public VesselBase { * or a user-defined type (THGROUP_USER+x) * \return Current linear force vector generated by the group [N] */ - Vector GetThrusterGroupForce (THGROUP_TYPE thgt) const; + VECTOR3 GetThrusterGroupForce(THGROUP_TYPE thgt) const; /** * \brief Return the linear force vector currently produced by all thrusters in a group * \param tgs Pointer to thruster group object (must not be 0) * \return Current linear force vector generated by the group [N] */ - Vector GetThrusterGroupForce (const ThrustGroupSpec *tgs) const; + VECTOR3 GetThrusterGroupForce(const ThrustGroupSpec *tgs) const; void IncMainRetroLevel (double dlevel); // This is a special treatment of the main/retro groups: increase forward thrust by @@ -708,11 +708,11 @@ class Vessel: public VesselBase { bool DelExhaust (UINT idx); // removes the idx-th exhaust render specification from the list - oapi::ParticleStream *AddParticleStream (PARTICLESTREAMSPEC *pss, const Vector &pos, const Vector &dir, double *lvl); + oapi::ParticleStream *AddParticleStream(PARTICLESTREAMSPEC *pss, const VECTOR3 &pos, const VECTOR3 &dir, double *lvl); // Add a generic particle stream to the vessel for given position and direction. // Lvl is a pointer to an external level control variable - oapi::ParticleStream *AddExhaustStream (ThrustSpec *ts, PARTICLESTREAMSPEC *pss = 0, const Vector *pos = 0, const Vector *dir = 0); + oapi::ParticleStream *AddExhaustStream(ThrustSpec *ts, PARTICLESTREAMSPEC *pss = 0, const VECTOR3 *pos = 0, const VECTOR3 *dir = 0); // Add a particle exhaust stream render specification for thruster ts, using its 'level' // parameter for controlling the particle emission system @@ -738,10 +738,10 @@ class Vessel: public VesselBase { // ======================================================================== // light emitter management - LightEmitter *AddPointLight (const VECTOR3 &pos, double range, double att0, double att1, double att2, COLOUR4 col_diff, COLOUR4 col_spec, COLOUR4 col_ambi); + LightEmitter *AddPointLight(const VECTOR3 &pos, double range, double att0, double att1, double att2, COLOUR4 col_diff, COLOUR4 col_spec, COLOUR4 col_ambi); // Add a point light emitter to the vessel with the specified specs, intensity, position and direction references - LightEmitter *AddSpotLight (const VECTOR3 &pos, const VECTOR3 &dir, double range, double att0, double att1, double att2, double umbra, double penumbra, COLOUR4 col_diff, COLOUR4 col_spec, COLOUR4 col_ambi); + LightEmitter *AddSpotLight(const VECTOR3 &pos, const VECTOR3 &dir, double range, double att0, double att1, double att2, double umbra, double penumbra, COLOUR4 col_diff, COLOUR4 col_spec, COLOUR4 col_ambi); // Add a spot light emitter to the vessel with the specified specs, intensity, position and direction references bool DelLightEmitter (LightEmitter *le); @@ -759,7 +759,7 @@ class Vessel: public VesselBase { void LightEmitterState (LightEmitter *le, int param, void *value); // Notification of emitter state change - void ShiftLightEmitters (const VECTOR3 &ofs); + void ShiftLightEmitters(const VECTOR3 &ofs); // Shift all light emitter positions by 'ofs' (usually to react to a shift in CG) // ======================================================================== @@ -799,16 +799,16 @@ class Vessel: public VesselBase { // ======================================================================== // aerodynamics - AirfoilSpec *CreateAirfoil (AIRFOIL_ORIENTATION align, const Vector &ref, AirfoilCoeffFunc cf, double c, double S, double A); + AirfoilSpec *CreateAirfoil(AIRFOIL_ORIENTATION align, const VECTOR3 &ref, AirfoilCoeffFunc cf, double c, double S, double A); // Create a new airfoil - AirfoilSpec *CreateAirfoil (AIRFOIL_ORIENTATION align, const Vector &ref, AirfoilCoeffFuncEx cf, void *context, double c, double S, double A); + AirfoilSpec *CreateAirfoil(AIRFOIL_ORIENTATION align, const VECTOR3 &ref, AirfoilCoeffFuncEx cf, void *context, double c, double S, double A); // Create a new airfoil; extended version - bool GetAirfoilParam (AirfoilSpec *af, VECTOR3 *ref, AirfoilCoeffFunc *cf, void **context, double *c, double *S, double *A); + bool GetAirfoilParam(AirfoilSpec *af, VECTOR3 *ref, AirfoilCoeffFunc *cf, void **context, double *c, double *S, double *A); // Return airfoil parameters - void EditAirfoil (AirfoilSpec *af, DWORD flag, const Vector &ref, AirfoilCoeffFunc cf, double c, double S, double A); + void EditAirfoil(AirfoilSpec *af, DWORD flag, const VECTOR3 &ref, AirfoilCoeffFunc cf, double c, double S, double A); // Edit an existing airfoil definition bool DelAirfoil (AirfoilSpec *af); @@ -820,7 +820,7 @@ class Vessel: public VesselBase { void ClearAirfoilDefinitions (); // Remove all airfoil lift,drag definitions - CtrlsurfSpec *CreateControlSurface (AIRCTRL_TYPE ctrl, double area, double dCl, const Vector &ref, int axis, double delay = 1.0, UINT anim = (UINT)-1); + CtrlsurfSpec *CreateControlSurface(AIRCTRL_TYPE ctrl, double area, double dCl, const VECTOR3 &ref, int axis, double delay = 1.0, UINT anim = (UINT)-1); // Create a new control surface definition of the specified type bool DelControlSurface (CtrlsurfSpec *cs); @@ -840,7 +840,7 @@ class Vessel: public VesselBase { void ApplyControlSurfaceLevels (); // synchronise actual with target airfoil control surface levels - void CreateVariableDragElement (const double *drag, double factor, const Vector &ref); + void CreateVariableDragElement(const double *drag, double factor, const VECTOR3 &ref); // creates a drag source whose magnitude is controlled by external variable "drag" // useful for drag generated by landing gear, speed brakes etc. @@ -876,10 +876,10 @@ class Vessel: public VesselBase { inline void SetEnableFocus (bool enable) { enablefocus = enable; } // get/set input focus enabled state - inline Vector *CamPos () { return &campos; } + inline VECTOR3 *CamPos() { return &campos; } // camera position offset - inline Vector *CamDir0 () { return &camdir0; } + inline VECTOR3 *CamDir0() { return &camdir0; } inline double CamTilt0 () { return camtilt0; } // camera default view direction and rotation around that direction @@ -963,21 +963,21 @@ class Vessel: public VesselBase { // ======================================================================== // Docking port management - PortSpec *CreateDock (const Vector &pos, const Vector &dir, const Vector &rot); + PortSpec *CreateDock(const VECTOR3 &pos, const VECTOR3 &dir, const VECTOR3 &rot); // Create a new docking port and return a pointer to it - void SetDockParams (PortSpec *dock, const Vector &pos, const Vector &dir, const Vector &rot); + void SetDockParams(PortSpec *dock, const VECTOR3 &pos, const VECTOR3 &dir, const VECTOR3 &rot); // Reset parameters of an existing dock inline void SetDockMode (int mode) { dockmode = mode; } inline int GetDockMode () const { return dockmode; } - void ShiftDocks (const Vector &ofs); + void ShiftDocks(const VECTOR3 &ofs); // shift all dock positions by ofs inline const PortSpec *GetDockParams (DWORD did) const { return dock[did]; } - Vector GetDockGPos (const PortSpec *dock) const + VECTOR3 GetDockGPos(const PortSpec *dock) const { return (mul (s0->R, dock->ref) + s0->pos); } // Dock position in global coordinates @@ -1013,14 +1013,14 @@ class Vessel: public VesselBase { inline DWORD nDock () const { return ndock; } inline Vessel *DockMate (DWORD n) const { return dock[n]->mate; } - void RelDockingPos (const Vessel *target, UINT mydid, UINT tgtdid, Vector &P, Matrix &R); + void RelDockingPos(const Vessel *target, UINT mydid, UINT tgtdid, VECTOR3 &P, Matrix &R); // Calculate the relative position 'P' and orientation 'R' of 'target' // in my reference frame, if we are docked between 'mydid' and 'tgtdid' // ======================================================================== // attachment management - AttachmentSpec *CreateAttachment (bool toparent, const Vector &pos, const Vector &dir, const Vector &rot, const char *id, bool loose = false); + AttachmentSpec *CreateAttachment(bool toparent, const VECTOR3 &pos, const VECTOR3 &dir, const VECTOR3 &rot, const char *id, bool loose = false); // create a new defintion for a parent/child attachment point // if loose==true, we freeze current relative orientation between child and parent; // otherwise, the orientation defined by the attachment orientation axes is used @@ -1031,7 +1031,7 @@ class Vessel: public VesselBase { void ClearAttachments (); // remove all attachment definitions - void SetAttachmentParams (AttachmentSpec *as, const Vector &pos, const Vector &dir, const Vector &rot); + void SetAttachmentParams(AttachmentSpec *as, const VECTOR3 &pos, const VECTOR3 &dir, const VECTOR3 &rot); // reset parameters of an existing attachment point bool AttachChild (Vessel *child, AttachmentSpec *as, AttachmentSpec *asc, bool allow_loose = true); @@ -1062,7 +1062,7 @@ class Vessel: public VesselBase { AttachmentSpec *GetAttachmentFromIndex (bool toparent, DWORD i); // returns the attachment for a given index from either the to-parent or the to-child list - void ShiftAttachments (const Vector &ofs); + void ShiftAttachments(const VECTOR3 &ofs); // move all attachment points by offset ofs // ======================================================================== @@ -1121,7 +1121,7 @@ class Vessel: public VesselBase { void UpdateRadiationForces (); void UpdateAerodynamicForces (); void UpdateAerodynamicForces_OLD (); - bool AddSurfaceForces (Vector *F, Vector *M, + bool AddSurfaceForces(VECTOR3 *F, VECTOR3 *M, const StateVectors *s=NULL, double tfrac=1.0, double dt=0.0, bool allow_groundcontact=true) const; @@ -1179,7 +1179,7 @@ class Vessel: public VesselBase { inline SuperVessel *SuperStruct() const { return supervessel; } inline void SetSuperStruct (SuperVessel *sv) { supervessel = sv; } - bool GetSuperStructCG (Vector &cg) const; + bool GetSuperStructCG(VECTOR3 &cg) const; // If vessel is part of a superstructure: set 'cg' to coordinates of // superstructure CG in vessel coordinates and return true. // Otherwise: set 'cg' to (0,0,0) and return false @@ -1260,7 +1260,7 @@ class Vessel: public VesselBase { bool VCRedrawEvent (int id, int event, SURFHANDLE surf) const; // pass an area redraw request to the vessel's virtual cockpit redraw method - bool VCMouseEvent (int id, int event, Vector &p) const; + bool VCMouseEvent(int id, int event, VECTOR3 &p) const; // pass a mouse event to the vessel's virtual cockpit mouse event handler void LeanCamera (int dir, bool smooth = true); @@ -1299,10 +1299,10 @@ class Vessel: public VesselBase { bool IsComponent () const { return supervessel != 0 || attach; } const VesselBase *GetSuperStructure () const; - inline void AddForce (const Vector &F, const Vector &r) + inline void AddForce(const VECTOR3 &F, const VECTOR3 &r) { Flin_add += F; - Amom_add += crossp (F, r); + Amom_add += cross(F, r); } // given a force vector F and attack point r, this updates the linear and angular force // vectors Flin and Amom for the rigid-body model @@ -1364,17 +1364,17 @@ class Vessel: public VesselBase { void ReadGenericCaps (std::ifstream &ifs); // read generic vessel caps from a class cfg file - UINT AddMesh (const char *mname, const VECTOR3 *ofs = 0); + UINT AddMesh(const char *mname, const VECTOR3 *ofs = 0); // add a mesh with offset to the list (load from file). Return value is mesh index - UINT AddMesh (MESHHANDLE hMesh, const VECTOR3 *ofs = 0); + UINT AddMesh(MESHHANDLE hMesh, const VECTOR3 *ofs = 0); // add a mesh with offset to the list (copy from handle). Return value is mesh index - UINT InsertMesh (const char *mname, UINT idx, const VECTOR3 *ofs = 0); + UINT InsertMesh(const char *mname, UINT idx, const VECTOR3 *ofs = 0); // Insert a mesh at a particular position (load from file). If a mesh is already registered // with index 'idx', the existing mesh is replaced - UINT InsertMesh (MESHHANDLE hMesh, UINT idx, const VECTOR3 *ofs = 0); + UINT InsertMesh(MESHHANDLE hMesh, UINT idx, const VECTOR3 *ofs = 0); // Insert a mesh at a particular position (copy from handle). If a mesh is already registered // with index 'idx', the existing mesh is replaced @@ -1387,7 +1387,7 @@ class Vessel: public VesselBase { // remove all entries from mesh list // If retain_anim=true, animations are not removed. - bool ShiftMesh (UINT idx, const VECTOR3 &ofs); + bool ShiftMesh(UINT idx, const VECTOR3 &ofs); // shift mesh 'idx' by 'ofs' from current position const MESHHANDLE GetMeshTemplate (UINT idx) const; @@ -1461,7 +1461,7 @@ class Vessel: public VesselBase { void InitDocked (const Vessel *vessel, int port); // init vessel docked in orbit to another vessel - void InitOrbiting (const Vector &relr, const Vector &relv, const Vector &rot, const Vector *_vrot = 0); + void InitOrbiting(const VECTOR3 &relr, const VECTOR3 &relv, const VECTOR3 &rot, const VECTOR3 *_vrot = 0); // init vessel as orbiting around cbody with rel. position relr, rel. velocity relv and // orientation rot (all w.r.t. ecliptic axis orientation). _vrot is rotation vector (rad/s) around the // three axes, if provided @@ -1549,7 +1549,7 @@ class Vessel: public VesselBase { DWORD npattach, ncattach; // list lengths AttachmentSpec *attach; // the current attachment to a parent, if applicable Matrix attach_rrot; // rotation matrix from vessel to current parent - Vector attach_rpos; // position of vessel in current parent's frame + VECTOR3 attach_rpos; // position of vessel in current parent's frame struct { // this structure is used when parsing attachment DWORD ci, pi; // info from a scenario to prepare deferred attachment @@ -1589,8 +1589,8 @@ class Vessel: public VesselBase { double wbrake_permanent[2]; // current permanent wheel brake level [0..1] (left and right) double wbrake_override[2]; // wheel brake override level for current frame [0..1] (left and right) double wbrake[2]; // current wheel brake levels - Vector cs; // ship's cross-sections in the three axis direction (z=longitudinal) [m^2] - Vector rdrag; // resistance constant against rotation in the three directions + VECTOR3 cs; // ship's cross-sections in the three axis direction (z=longitudinal) [m^2] + VECTOR3 rdrag; // resistance constant against rotation in the three directions bool enablefocus; // can vessel get input focus? bool burnfuel; // no unlimited fuel bool extpassmesh; @@ -1634,34 +1634,34 @@ class Vessel: public VesselBase { double surf_rad; // surface distance from planet centre at landing site Matrix rot_land; // vessel's local rotation matrix when landed on a planet surface // such that grot = grot(planet) * rot_land - Vector touchdown_nm; // upward normal of touchdown plane (vessel frame) - Vector touchdown_cg; // projection of CG onto touchdown plane + VECTOR3 touchdown_nm; // upward normal of touchdown plane (vessel frame) + VECTOR3 touchdown_cg; // projection of CG onto touchdown plane TOUCHDOWN_VTX *touchdown_vtx; DWORD ntouchdown_vtx; // number of touchdown vertices DWORD next_hullvtx; // used by hull vertex iterator - Vector campos; // internal camera position (cockpit mode); - Vector camdir0; // internal default camera direction (cockpit mode) + VECTOR3 campos; // internal camera position (cockpit mode); + VECTOR3 camdir0; // internal default camera direction (cockpit mode) double camtilt0; // internal default camera rotation around default direction (cockpit mode) double camcatchangle; // internal camera autochenter catch range double camdp_left, camdp_right, camdt_up, camdt_down; // cockpit camera rotation ranges static struct LeanCam { // cockpit camera 'leaning' ranges' LeanCam() { phi = tht = 0; } - Vector pos; + VECTOR3 pos; double phi, tht; } camfwd, camleft, camright; double trim_scale; // effect of trimming (0 = can't trim) - OBSOLETE - Vector Flin; // linear moment (force) - Vector Amom; // angular moment (torque) - Vector Flin_add; // linear body force - Vector Amom_add; // used for collecting torque components - mutable Vector Torque; // torque vector + VECTOR3 Flin; // linear moment (force) + VECTOR3 Amom; // angular moment (torque) + VECTOR3 Flin_add; // linear body force + VECTOR3 Amom_add; // used for collecting torque components + mutable VECTOR3 Torque; // torque vector mutable bool torque_valid; // flag for 'Torque' up to date - Vector Thrust; // linear thrust vector (sum of all thruster contributions) - mutable Vector Weight; // weight vector (due to gravitational acceleration) + VECTOR3 Thrust; // linear thrust vector (sum of all thruster contributions) + mutable VECTOR3 Weight; // weight vector (due to gravitational acceleration) mutable bool weight_valid; // flag for 'Weight' up to date double Lift, Drag; // current lift and drag magnitudes @@ -1676,8 +1676,8 @@ class Vessel: public VesselBase { //double refalt, palt, valt; // reference+prev altitude for "hold altitude" mode //double holdaltT; - Vector *forcevec; // list of force vectors to render - Vector *forcepos; // list of force vector attack points + VECTOR3 *forcevec; // list of force vectors to render + VECTOR3 *forcepos; // list of force vector attack points int forcevecbuf; // length of vector list mutable int nforcevec; // number of vectors to render diff --git a/Src/Orbiter/Vesselbase.cpp b/Src/Orbiter/Vesselbase.cpp index 135fa49f7..728ea6b0b 100644 --- a/Src/Orbiter/Vesselbase.cpp +++ b/Src/Orbiter/Vesselbase.cpp @@ -25,14 +25,14 @@ void SurfParam::Set (const StateVectors &s, const StateVectors &s_ref, const Cel ref = _ref; Planet *planet = (ref->Type() == OBJTP_PLANET ? (Planet*)ref : 0); - Vector Prel = s.pos - s_ref.pos; + VECTOR3 Prel = s.pos - s_ref.pos; ploc = tmul (s_ref.R, Prel); ref->LocalToEquatorial (ploc, lng, lat, rad); slng = sin(lng), clng = cos(lng); slat = sin(lat), clat = cos(lat); alt0 = alt = rad - ref->Size(); elev = 0.0; - surfnml.Set(0,1,0); + surfnml = {0, 1, 0}; if (etilecache && alt < alt_max) { if (ref->Type() == OBJTP_PLANET) { ElevationManager *emgr = ((Planet*)ref)->ElevMgr(); @@ -44,8 +44,7 @@ void SurfParam::Set (const StateVectors &s, const StateVectors &s_ref, const Cel } } - Vector Snm (tmul (s.R, Prel)); - Snm.unify(); // planet surface normal below ship in ship's local coords + VECTOR3 Snm = unit(tmul(s.R, Prel)); // planet surface normal below ship in ship's local coords pitch = asin (Snm.z); if (fabs (Snm.x) > eps || fabs (Snm.y) > eps) bank = atan2 (Snm.x, Snm.y); @@ -53,23 +52,23 @@ void SurfParam::Set (const StateVectors &s, const StateVectors &s_ref, const Cel bank = 0.0; // ground speed - Vector vrel = s.vel - s_ref.vel; + VECTOR3 vrel = s.vel - s_ref.vel; double vref = Pi2/ref->RotT() * rad * clat; // speed of a point at vessel position fixed in planet frame - groundvel_glob.Set (vrel - mul (s_ref.R, Vector(-vref*slng,0.0,vref*clng))); // ground velocity in global frame - groundvel_ship.Set (tmul (s.R, groundvel_glob)); // ground velocity in ship frame - groundspd = groundvel_glob.length(); + groundvel_glob = vrel - mul(s_ref.R, VECTOR3{-vref * slng, 0.0, vref * clng}); // ground velocity in global frame + groundvel_ship = tmul(s.R, groundvel_glob); // ground velocity in ship frame + groundspd = len(groundvel_glob); // vertical velocity - vspd = dotp(vrel, Prel.unit()); + vspd = dot(vrel, unit(Prel)); // airspeed - Vector windvel_glob(0,0,0); + VECTOR3 windvel_glob{0, 0, 0}; if (planet) - windvel_glob.Set (mul (s_ref.R, planet->WindVelocity (lng, lat, alt, 1, windprm))); + windvel_glob = mul(s_ref.R, planet->WindVelocity(lng, lat, alt, 1, windprm)); - airvel_glob.Set (groundvel_glob - windvel_glob); - airvel_ship.Set (tmul (s.R, airvel_glob)); - airspd = airvel_glob.length(); + airvel_glob = groundvel_glob - windvel_glob; + airvel_ship = tmul(s.R, airvel_glob); + airspd = len(airvel_glob); // rotation from planet local coords to local horizon L2H.Set (-slng, 0, clng, @@ -77,11 +76,11 @@ void SurfParam::Set (const StateVectors &s, const StateVectors &s_ref, const Cel -slat*clng, clat, -slat*slng); // map ship's forward axis into local horizon frame - Vector RZloc = mul(L2H, tmul(s_ref.R, Vector (s.R.m13, s.R.m23, s.R.m33))); + VECTOR3 RZloc = mul(L2H, tmul(s_ref.R, VECTOR3{s.R.m13, s.R.m23, s.R.m33})); if (fabs (RZloc.x) > eps || fabs(RZloc.z) > eps) dir = atan2 (RZloc.x, RZloc.z); else { // ship is pointing vertically up - take ship's negative y-axis for direction - Vector RYloc = mul(L2H, tmul(s_ref.R, Vector (-s.R.m12, -s.R.m22, -s.R.m32))); + VECTOR3 RYloc = mul(L2H, tmul(s_ref.R, VECTOR3{-s.R.m12, -s.R.m22, -s.R.m32})); dir = atan2 (RYloc.x, RYloc.z); } if (dir < 0.0) dir += Pi2; @@ -109,7 +108,7 @@ double SurfParam::ComputeAltitude(const StateVectors &s, const StateVectors &s_r static const double alt_max = 1e5; // for now double _lng, _lat, _rad; - Vector ploc = tmul (s_ref.R, s.pos - s_ref.pos); + VECTOR3 ploc = tmul(s_ref.R, s.pos - s_ref.pos); _ref->LocalToEquatorial (ploc, _lng, _lat, _rad); double _alt = _rad - _ref->Size(); if (etilecache && _alt < alt_max && _ref->Type() == OBJTP_PLANET) { @@ -125,7 +124,7 @@ double SurfParam::ComputeAltitude(const StateVectors &s, const StateVectors &s_r // ----------------------------------------------------------------------- -void SurfParam::SetLanded (double _lng, double _lat, double _alt, double _dir, const Vector &nml, const CelestialBody *_ref) +void SurfParam::SetLanded (double _lng, double _lat, double _alt, double _dir, const VECTOR3 &nml, const CelestialBody *_ref) { static const double eps = 1e-6; @@ -149,10 +148,10 @@ void SurfParam::SetLanded (double _lng, double _lat, double _alt, double _dir, c else bank = 0.0; dir = _dir; - airvel_glob.Set (0,0,0); - airvel_ship.Set (0,0,0); - groundvel_glob.Set (0,0,0); - groundvel_ship.Set (0,0,0); + airvel_glob = {0, 0, 0}; + airvel_ship = {0, 0, 0}; + groundvel_glob = {0, 0, 0}; + groundvel_ship = {0, 0, 0}; airspd = groundspd = 0.0; if (is_in_atm = (planet && planet->HasAtmosphere() && rad < planet->AtmRadLimit())) { @@ -180,7 +179,7 @@ VesselBase::VesselBase (): RigidBody () // ======================================================================= -VesselBase::VesselBase (double _mass, double _size, const Vector &_pmi) +VesselBase::VesselBase (double _mass, double _size, const VECTOR3 &_pmi) : RigidBody (_mass, _size, _pmi) { etile.resize(2); @@ -203,7 +202,7 @@ void VesselBase::SetDefaultState () // distribute update times windp.pert_t = 0; - windp.pert_v.Set(0,0,0); + windp.pert_v = {0, 0, 0}; } // ======================================================================= @@ -213,9 +212,9 @@ bool VesselBase::Activate (bool force) if (fstatus == FLIGHTSTATUS_LANDED || force) { fstatus = FLIGHTSTATUS_FREEFLIGHT; rpos_base = s0->pos; - rpos_add.Set (0,0,0); + rpos_add = {0, 0, 0}; rvel_base = s0->vel; - rvel_add.Set (0,0,0); + rvel_add = {0, 0, 0}; return true; } else return false; @@ -255,10 +254,10 @@ void VesselBase::CheckLanded () LandingTest.testing = false; else { static const double eps = 1e-4; - Vector prel (tmul(proxybody->s0->R, s0->pos - proxybody->s0->pos)); // vessel position in planet local coords + VECTOR3 prel = tmul(proxybody->s0->R, s0->pos - proxybody->s0->pos); // vessel position in planet local coords double dt = td.SimT0 - LandingTest.testt; if (dt < 0.1) return; - double dst2 = prel.dist2 (LandingTest.surfpos); + double dst2 = dist_2(prel, LandingTest.surfpos); double dangle = angle (s0->Q, LandingTest.surfrot); LandingTest.surfpos = prel; LandingTest.surfrot.Set (s0->Q); @@ -287,7 +286,7 @@ void VesselBase::CheckLanded () if (bSurfaceContact && !ThrustEngaged()) { LandingTest.testing = true; LandingTest.testt = td.SimT0; - LandingTest.surfpos.Set (tmul(proxybody->s0->R, s0->pos - proxybody->s0->pos)); + LandingTest.surfpos = tmul(proxybody->s0->R, s0->pos - proxybody->s0->pos); LandingTest.surfrot.Set (s0->Q); // should really subtract proxybody rotation here } } @@ -302,11 +301,11 @@ double VesselBase::LandedHeading (double lng, double lat) const double slng = sin(lng), clng = cos(lng); double slat = sin(lat), clat = cos(lat); Matrix L2H (-slng,0,clng, clat*clng,slat,clat*slng, -slat*clng,clat,-slat*slng); - Vector RZloc = mul(L2H, tmul (proxybody->s0->R, Vector (s0->R.m13, s0->R.m23, s0->R.m33))); + VECTOR3 RZloc = mul(L2H, tmul(proxybody->s0->R, VECTOR3{s0->R.m13, s0->R.m23, s0->R.m33})); if (fabs(RZloc.x) > eps || fabs(RZloc.z) > eps) dir = atan2(RZloc.x, RZloc.z); else { - Vector RYloc = mul(L2H, tmul(proxybody->s0->R, Vector(-s0->R.m12, -s0->R.m22, -s0->R.m32))); + VECTOR3 RYloc = mul(L2H, tmul(proxybody->s0->R, VECTOR3{-s0->R.m12, -s0->R.m22, -s0->R.m32})); dir = atan2(RYloc.x, RYloc.z); } if (dir < 0.0) dir += Pi2; @@ -315,7 +314,7 @@ double VesselBase::LandedHeading (double lng, double lat) const // ======================================================================= -void VesselBase::GetIntermediateMoments (Vector &acc, Vector &tau, +void VesselBase::GetIntermediateMoments (VECTOR3 &acc, VECTOR3 &tau, const StateVectors &state, double tfrac, double dt) { } @@ -332,7 +331,7 @@ void VesselBase::UpdateProxies () // Check for closest celestial body and planet for (i = 0, proxydist2 = proxypdist2 = 1e100; i < ng; i++) { grav = g_psys->GetGravObj(i); - dist2 = s0->pos.dist2 (grav->s0->pos) - grav->Size(); // distance squared from body surface + dist2 = dist_2(s0->pos, grav->s0->pos) - grav->Size(); // distance squared from body surface if (dist2 < proxydist2) { proxydist2 = dist2; proxybody = grav; @@ -349,7 +348,7 @@ void VesselBase::UpdateProxies () if (proxyplanet) { for (i = 0, proxydist2 = 1e100; i < proxyplanet->nBase(); i++) { Base *base = (Base*)proxyplanet->GetBase(i); - if ((dist2 = s0->pos.dist2 (base->s0->pos)) < proxydist2) { + if ((dist2 = dist_2(s0->pos, base->s0->pos)) < proxydist2) { proxydist2 = dist2; proxybase = base; } @@ -410,10 +409,10 @@ bool VesselBase::ValidateStateUpdate (StateVectors *s) } else if (!collision_speed_checked) { collision_speed_checked = true; double vsmax = -0.1 * MaxSubStep()/td.SimDT; // allow max 0.1m / substep surface penetration - Vector hn (tmul(GRot(), GPos()-proxybody->GPos()).unit()); - double vs = dotp (sp.groundvel_ship, hn); + VECTOR3 hn = unit(tmul(GRot(), GPos() - proxybody->GPos())); + double vs = dot(sp.groundvel_ship, hn); if (vs < vsmax) { - Vector gv(sp.groundvel_ship * (vsmax/vs)); // rescaled surface-relative velocity + VECTOR3 gv = sp.groundvel_ship * (vsmax / vs); // rescaled surface-relative velocity gv = mul (GRot(), gv); // map to global s0->vel += (gv - sp.groundvel_glob); rvel_base += (gv - sp.groundvel_glob); @@ -426,7 +425,7 @@ bool VesselBase::ValidateStateUpdate (StateVectors *s) // ======================================================================= -bool VesselBase::AddSurfaceForces (Vector *F, Vector *M, +bool VesselBase::AddSurfaceForces (VECTOR3 *F, VECTOR3 *M, const StateVectors *s, double tfrac, double dt) const { return false; diff --git a/Src/Orbiter/Vesselbase.h b/Src/Orbiter/Vesselbase.h index 696f17fcc..f42320f1a 100644 --- a/Src/Orbiter/Vesselbase.h +++ b/Src/Orbiter/Vesselbase.h @@ -17,7 +17,7 @@ typedef enum { } FlightStatus; typedef struct { // touchdown vertex specifications - Vector pos; // touchdown point position (uncompressed) in vessel frame + VECTOR3 pos; // touchdown point position (uncompressed) in vessel frame double stiffness; // suspension stiffness double damping; // suspension damping double compression; // suspension compression factor @@ -36,15 +36,15 @@ struct SurfParam {//Surface-relative vessel state std::vector *etilecache=NULL); // recalculate altitude - void SetLanded (double lng, double lat, double alt, double dir, const Vector &nml, const CelestialBody *ref); + void SetLanded (double lng, double lat, double alt, double dir, const VECTOR3 &nml, const CelestialBody *ref); // Set surface parameters for a landed object const CelestialBody *ref; // body to which data refer - Vector ploc; // ship position in planet local cartesian coords - Vector groundvel_glob; // ground-relative velocity in global frame - Vector groundvel_ship; // ground-relative velocity in local vessel frame - Vector airvel_glob; // airspeed vector in global frame - Vector airvel_ship; // airspeed vector in local vessel frame + VECTOR3 ploc; // ship position in planet local cartesian coords + VECTOR3 groundvel_glob; // ground-relative velocity in global frame + VECTOR3 groundvel_ship; // ground-relative velocity in local vessel frame + VECTOR3 airvel_glob; // airspeed vector in global frame + VECTOR3 airvel_ship; // airspeed vector in local vessel frame double groundspd; // ground-relative velocity magnitude double airspd; // airspeed magnitude double vspd; // vertical velocity (negative for descent) @@ -54,7 +54,7 @@ struct SurfParam {//Surface-relative vessel state double alt0; // ship altitude over mean radius double elev; // ground elevation with respect to mean planet radius int elev_lvl; // resolution level at which elevation was computed - Vector surfnml; // surface normal in local horizon frame (+y=up) + VECTOR3 surfnml; // surface normal in local horizon frame (+y=up) double pitch, bank; // vessel orientation w.r.t. horizon double dir; // compass orientation bool is_in_atm; // true if ship is within a planetary atmosphere @@ -68,7 +68,7 @@ struct SurfParam {//Surface-relative vessel state struct WindPrm { // per-vessel wind parameters double pert_t; // time for wind perturbation vector - Vector pert_v; // wind perturbation vector + VECTOR3 pert_v; // wind perturbation vector }; // ======================================================================= @@ -82,7 +82,7 @@ class Base; class VesselBase: public RigidBody { public: VesselBase (); - VesselBase (double _mass, double _size, const Vector &_pmi); + VesselBase (double _mass, double _size, const VECTOR3 &_pmi); virtual void Update (bool force = false) = 0; // Update vessel state by propagating across current time step @@ -97,7 +97,7 @@ class VesselBase: public RigidBody { inline Base *ProxyBase () const { return proxybase; } // closest surface base - virtual void RPlace (const Vector &rpos, const Vector &rvel) {} + virtual void RPlace (const VECTOR3 &rpos, const VECTOR3 &rvel) {} // Set vessel position and velocity in parent coords // If the vessel is part of a superstructure, the complete structure // is moved accordingly @@ -147,7 +147,7 @@ class VesselBase: public RigidBody { // Returns the heading of a vessel landed at lng/lat // using state vectors s0 - virtual void GetIntermediateMoments (Vector &acc, Vector &tau, + virtual void GetIntermediateMoments (VECTOR3 &acc, VECTOR3 &tau, const StateVectors &state, double tfrac, double dt); // Returns acceleration acc and torque tau, at time SimT0+tfrac*SimDT // and step size dt, given intermediate state in global frame @@ -176,7 +176,7 @@ class VesselBase: public RigidBody { virtual bool ValidateStateUpdate (StateVectors *s); - virtual bool AddSurfaceForces (Vector *F, Vector *M, + virtual bool AddSurfaceForces (VECTOR3 *F, VECTOR3 *M, const StateVectors *s = NULL, double tfrac = 1.0, double dt = 0.0) const; // Return linear force F and angular moment M due to planet surface interaction, // given state vectors s at fraction tfrac (0..1) of the current time step, with @@ -209,7 +209,7 @@ class VesselBase: public RigidBody { struct LANDING_TEST { // parameters for testing LANDED status eligibility bool testing; double testt; - Vector surfpos; + VECTOR3 surfpos; Quaternion surfrot; } LandingTest; diff --git a/Src/Orbiter/Vesselstatus.cpp b/Src/Orbiter/Vesselstatus.cpp index 30bd0a85b..8443bd68b 100644 --- a/Src/Orbiter/Vesselstatus.cpp +++ b/Src/Orbiter/Vesselstatus.cpp @@ -80,7 +80,7 @@ bool Vessel::ParseScenarioLine (char *line, VESSELSTATUS &vs) sscanf (line+4, "%lf%lf%lf", &vs.rvel.x, &vs.rvel.y, &vs.rvel.z); } else if (!_strnicmp (line, "ELEMENTS", 8)) { double a, e, i, theta, omegab, L, elmjd; - Vector rpos, rvel; + VECTOR3 rpos, rvel; sscanf (line+8, "%lf%lf%lf%lf%lf%lf%lf", &a, &e, &i, &theta, &omegab, &L, &elmjd); if (vs.rbody) { el->Set (a, e, i*RAD, theta*RAD, omegab*RAD, L*RAD, elmjd); @@ -324,7 +324,7 @@ bool Vessel::ParseScenarioLine2 (char *line, void *status) sscanf (line+3, "%lf", &vs->vrot.x); } else if (!_strnicmp (line, "ELEMENTS", 8)) { double a, e, i, theta, omegab, L, elmjd; - Vector rpos, rvel; + VECTOR3 rpos, rvel; sscanf (line+8, "%lf%lf%lf%lf%lf%lf%lf", &a, &e, &i, &theta, &omegab, &L, &elmjd); if (vs->rbody) { el->Set (a, e, i*RAD, theta*RAD, omegab*RAD, L*RAD, elmjd); @@ -448,7 +448,7 @@ void Vessel::ApplyPackedState (const char *data) void Vessel::SetState (const VESSELSTATUS &status) { double lng, lat, dir; - Vector rpos, rvel, orient, vrot; + VECTOR3 rpos, rvel, orient, vrot; cbody = (CelestialBody*)status.rbody; if (!cbody) cbody = g_psys->GetStar(0); // use first sun if no reference is set @@ -474,11 +474,11 @@ void Vessel::SetState (const VESSELSTATUS &status) switch (status.status) { case 0: // freeflight - rpos.Set (status.rpos.x, status.rpos.y, status.rpos.z); - rvel.Set (status.rvel.x, status.rvel.y, status.rvel.z); - orient.Set (status.arot.x, status.arot.y, status.arot.z); - vrot.Set (status.vrot.x, status.vrot.y, status.vrot.z); - if (rpos.length() < cbody->Size()) { // sanity check + rpos = status.rpos; + rvel = status.rvel; + orient = status.arot; + vrot = status.vrot; + if (len(rpos) < cbody->Size()) { // sanity check rpos.x = rpos.y = 0.0; rpos.z = 1.1*cbody->Size(); // desparate default } @@ -562,15 +562,9 @@ void Vessel::SetState2 (const void *status) // state vectors switch (vs->status) { - case 0: { // freeflight - if (!attach_status.pname) { - Vector rp (vs->rpos.x, vs->rpos.y, vs->rpos.z); - Vector rv (vs->rvel.x, vs->rvel.y, vs->rvel.z); - Vector orient (vs->arot.x, vs->arot.y, vs->arot.z); - Vector vr (vs->vrot.x, vs->vrot.y, vs->vrot.z); - InitOrbiting (rp, rv, orient, &vr); - } - } break; + case 0: // freeflight + if (!attach_status.pname) InitOrbiting(vs->rpos, vs->rvel, vs->arot, &vs->vrot); + break; case 1: // landed if (vs->base) { landtgt = (Base*)vs->base; @@ -580,7 +574,7 @@ void Vessel::SetState2 (const void *status) } if (vs->arot.x <= 4.0) { // extended information available Matrix lrot; - lrot.Set (MakeVector(vs->arot)); + lrot.Set(vs->arot); double alt = vs->vrot.x; InitLanded ((Planet*)cbody, vs->surf_lng, vs->surf_lat, vs->surf_hdg, &lrot, alt); } else { @@ -604,23 +598,15 @@ void Vessel::GetState (VESSELSTATUS &status) { memset (&status, 0, sizeof(VESSELSTATUS)); status.rbody = (OBJHANDLE)cbody; - Vector dp (GPos() - cbody->GPos()); - status.rpos.x = dp.x; - status.rpos.y = dp.y; - status.rpos.z = dp.z; - Vector dv (GVel() - cbody->GVel()); - status.rvel.x = dv.x; - status.rvel.y = dv.y; - status.rvel.z = dv.z; + status.rpos = GPos() - cbody->GPos(); + status.rvel = GVel() - cbody->GVel(); if (fstatus == FLIGHTSTATUS_LANDED) { status.vrot.x = sp.alt; status.vrot.y = 0.0; status.vrot.z = 0.0; EulerAngles (land_rot, status.arot); } else { - status.vrot.x = s0->omega.x; - status.vrot.y = s0->omega.y; - status.vrot.z = s0->omega.z; + status.vrot = s0->omega; EulerAngles (s0->R, status.arot); } TankSpec *ts = PropellantHandle(0); @@ -663,11 +649,9 @@ void Vessel::GetState2 (void *status) vs->rbody = (OBJHANDLE)cbody; vs->base = proxybase; vs->port = nport; - Vector dp (GPos() - cbody->GPos()); - Vector dv (GVel() - cbody->GVel()); - vs->rpos = _V(dp.x, dp.y, dp.z); - vs->rvel = _V(dv.x, dv.y, dv.z); - vs->vrot = (fstatus == FLIGHTSTATUS_LANDED ? _V(sp.alt, 0, 0) : _V(s0->omega.x, s0->omega.y, s0->omega.z)); + vs->rpos = GPos() - cbody->GPos(); + vs->rvel = GVel() - cbody->GVel(); + vs->vrot = (fstatus == FLIGHTSTATUS_LANDED ? VECTOR3{sp.alt, 0, 0} : VECTOR3{s0->omega.x, s0->omega.y, s0->omega.z}); EulerAngles (fstatus == FLIGHTSTATUS_LANDED ? land_rot : s0->R, vs->arot); vs->surf_lng = sp.lng; vs->surf_lat = sp.lat; diff --git a/Src/Orbiter/Vobject.cpp b/Src/Orbiter/Vobject.cpp index 4950d108d..7f187114a 100644 --- a/Src/Orbiter/Vobject.cpp +++ b/Src/Orbiter/Vobject.cpp @@ -75,11 +75,11 @@ bool veccomp(const VObject::BodyVectorRec& v1, const VObject::BodyVectorRec& v2) void VObject::Update (bool moving, bool force) { if (body == g_camera->Target()) - cpos.Set (-(*g_camera->GSPosPtr())); + cpos = -(*g_camera->GSPosPtr()); else - cpos.Set (body->GPos() - g_camera->GPos()); + cpos = body->GPos() - g_camera->GPos(); campos = tmul(body->GRot(), -cpos); - cdist = cpos.length(); + cdist = len(cpos); if (force) { apprad_factor = g_camera->TanAperture() / @@ -127,13 +127,13 @@ void VObject::UpdateRenderVectors() double scale = body->Size() * *(float*)gc->GetConfigParam(CFGPRM_FRAMEAXISSCALE); double rad = body->Size() * 0.01; float alpha = *(float*)gc->GetConfigParam(CFGPRM_FRAMEAXISOPACITY); - AddVector(Vector(scale, 0, 0), Vector(0, 0, 0), rad, std::string("+x"), Vector(1, 1, 1), alpha, D3DRGB(1, 1, 1)); - AddVector(Vector(0, scale, 0), Vector(0, 0, 0), rad, std::string("+y"), Vector(1, 1, 1), alpha, D3DRGB(1, 1, 1)); - AddVector(Vector(0, 0, scale), Vector(0, 0, 0), rad, std::string("+z"), Vector(1, 1, 1), alpha, D3DRGB(1, 1, 1)); + AddVector({scale, 0, 0}, {0, 0, 0}, rad, std::string("+x"), {1, 1, 1}, alpha, D3DRGB(1, 1, 1)); + AddVector({0, scale, 0}, {0, 0, 0}, rad, std::string("+y"), {1, 1, 1}, alpha, D3DRGB(1, 1, 1)); + AddVector({0, 0, scale}, {0, 0, 0}, rad, std::string("+z"), {1, 1, 1}, alpha, D3DRGB(1, 1, 1)); if (flag & FAV_NEGATIVE) { - AddVector(Vector(-scale, 0, 0), Vector(0, 0, 0), rad, std::string("-x"), Vector(1, 1, 1), alpha, D3DRGB(1, 1, 1)); - AddVector(Vector(0, -scale, 0), Vector(0, 0, 0), rad, std::string("-y"), Vector(1, 1, 1), alpha, D3DRGB(1, 1, 1)); - AddVector(Vector(0, 0, -scale), Vector(0, 0, 0), rad, std::string("-z"), Vector(1, 1, 1), alpha, D3DRGB(1, 1, 1)); + AddVector({-scale, 0, 0}, {0, 0, 0}, rad, std::string("-x"), {1, 1, 1}, alpha, D3DRGB(1, 1, 1)); + AddVector({0, -scale, 0}, {0, 0, 0}, rad, std::string("-y"), {1, 1, 1}, alpha, D3DRGB(1, 1, 1)); + AddVector({0, 0, -scale}, {0, 0, 0}, rad, std::string("-z"), {1, 1, 1}, alpha, D3DRGB(1, 1, 1)); } } } @@ -148,18 +148,17 @@ void VObject::RenderAsDisc (LPDIRECT3DDEVICE7 dev) // scale down intensity with angle of illumination const double ambient = 0.3; // assumed unlit/lit emission ratio - double cosa = dotp (body->GPos().unit(), (body->GPos() - g_camera->GPos()).unit()); + double cosa = dot(unit(body->GPos()), unit(body->GPos() - g_camera->GPos())); double illum = 0.5 * ((1.0-ambient)*cosa + 1.0+ambient); // scale down intensity with distance from sun (only very gently) - double sundist = body->GPos().length() * iAU; + double sundist = len(body->GPos()) * iAU; illum *= pow(sundist, -0.4); // scale with albedo components - const Vector &albedo = body->Albedo(); - double abr = albedo.x*illum; - double abg = albedo.y*illum; - double abb = albedo.z*illum; + double abr = body->Albedo().x * illum; + double abg = body->Albedo().y * illum; + double abb = body->Albedo().z * illum; double abmax = max (abr, max (abg, abb)); if (abmax > 1.0) { rad *= sqrt(abmax); @@ -168,7 +167,7 @@ void VObject::RenderAsDisc (LPDIRECT3DDEVICE7 dev) abb *= 1.0/abmax; } - RenderSpot (dev, 0, (float)rad, Vector(abr,abg,abb), false, 0); + RenderSpot (dev, 0, (float)rad, {abr, abg, abb}, false, 0); } void VObject::RenderAsPixel (LPDIRECT3DDEVICE7 dev) @@ -202,13 +201,12 @@ void VObject::RenderAsPixel (LPDIRECT3DDEVICE7 dev) // 2. angle of illumination const double ambient = 0.3; - double cosa = dotp (body->GPos().unit(), (body->GPos() - g_camera->GPos()).unit()); + double cosa = dot(unit(body->GPos()), unit(body->GPos() - g_camera->GPos())); intens *= 0.5 * ((1.0-ambient)*cosa + 1.0+ambient); - const Vector &albedo = body->Albedo(); - double abr = albedo.x; - double abg = albedo.y; - double abb = albedo.z; + double abr = body->Albedo().x; + double abg = body->Albedo().y; + double abb = body->Albedo().z; double abmax = max (abr, max (abg, abb)); intens *= abmax; abr *= 256.0/abmax; @@ -254,13 +252,13 @@ void VObject::RenderAsPixel (LPDIRECT3DDEVICE7 dev) } } -void VObject::RenderSpot (LPDIRECT3DDEVICE7 dev, const Vector *ofs, float size, const Vector &col, bool lighting, int shape) +void VObject::RenderSpot (LPDIRECT3DDEVICE7 dev, const VECTOR3 *ofs, float size, const VECTOR3 &col, bool lighting, int shape) { static D3DMATRIX W = {0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,1}; - Vector pos (cpos); + auto pos = cpos; if (ofs) pos += mul (body->GRot(), *ofs); - double dist = pos.length(); + double dist = len(pos); double maxdist = 0.9*g_camera->Farplane(); if (dist > maxdist) { @@ -269,14 +267,14 @@ void VObject::RenderSpot (LPDIRECT3DDEVICE7 dev, const Vector *ofs, float size, dist = maxdist; } - Vector bdir(pos/dist); + VECTOR3 bdir = pos / dist; double hz = std::hypot (bdir.x, bdir.z); double phi = atan2 (bdir.z, bdir.x); float sphi = (float)sin(phi), cphi = (float)cos(phi); DWORD alphamode; const double ambient = 0.2; - double cosa = dotp (body->GPos().unit(), (body->GPos() - g_camera->GPos()).unit()); + double cosa = dot(unit(body->GPos()), unit(body->GPos() - g_camera->GPos())); double intens = (lighting ? 0.5 * ((1.0-ambient)*cosa + 1.0+ambient) : 1.0); W._11 = (float)bdir.x; @@ -325,17 +323,17 @@ void VObject::RenderAsSpot (LPDIRECT3DDEVICE7 dev, D3DCOLORVALUE *illumination) // scale blob size so that apparent size reduces linearly from d0 to d1 if (size < 0.0) return; // sanity check dev->SetRenderState (D3DRENDERSTATE_ALPHABLENDENABLE, TRUE); - RenderSpot (dev, 0, size, illumination ? body->Albedo()*Vector(illumination->r,illumination->g,illumination->b) : body->Albedo(), true); + RenderSpot(dev, 0, size, illumination ? body->Albedo() * VECTOR3{illumination->r, illumination->g, illumination->b} : body->Albedo(), true); dev->SetRenderState (D3DRENDERSTATE_ALPHABLENDENABLE, FALSE); } -void VObject::AddVector (const Vector &v, const Vector &orig, double rad, const std::string& label, const Vector &col, float alpha, DWORD lcol, float lsize) +void VObject::AddVector (const VECTOR3 &v, const VECTOR3 &orig, double rad, const std::string& label, const VECTOR3 &col, float alpha, DWORD lcol, float lsize) { - double len = v.length(); + double len = ::len(v); if (len < 2.0*rad) return; // too short to be rendered - Vector vu = v / len; - double dist = (vu - campos).length(); + VECTOR3 vu = v / len; + double dist = ::len(vu - campos); BodyVectorRec rec; rec.v = v; @@ -355,7 +353,7 @@ void VObject::RenderVectors (LPDIRECT3DDEVICE7 dev) { if (veclist.size()) { float palpha = -1.0f; - Vector pcol(-1, -1, -1); + VECTOR3 pcol{-1, -1, -1}; for (auto&& vec : veclist) { if (vec.alpha != palpha || vec.col.x != pcol.x || vec.col.y != pcol.y || vec.col.z != pcol.z) { dev->SetRenderState(D3DRENDERSTATE_TEXTUREFACTOR, D3DRGBA(vec.col.x, vec.col.y, vec.col.z, vec.alpha)); @@ -372,14 +370,14 @@ void VObject::RenderVectorLabels(LPDIRECT3DDEVICE7 dev) for (auto&& vec : veclist) { if (vec.label.size()) { double scale = (vec.lsize >= 0 ? vec.lsize : body->Size()); - scene->Render3DLabel (mul (body->GRot(), vec.v + vec.v.unit()*(scale*0.1)) + body->GPos(), + scene->Render3DLabel(mul(body->GRot(), vec.v + unit(vec.v) * (scale * 0.1)) + body->GPos(), vec.label.c_str(), scale, vec.lcol); } } } } -bool VObject::DrawVector (LPDIRECT3DDEVICE7 dev, const Vector &end, const Vector &orig, double rad) +bool VObject::DrawVector (LPDIRECT3DDEVICE7 dev, const VECTOR3 &end, const VECTOR3 &orig, double rad) { static const float EPS = 1e-2f; static const int nseg = 8; @@ -428,7 +426,7 @@ bool VObject::DrawVector (LPDIRECT3DDEVICE7 dev, const Vector &end, const Vector } float w = (float)rad; - float h = (float)end.length(); + float h = (float)len(end); if (h < EPS) return false; float hb = max (h-4.0f*w, 0.0f); @@ -442,7 +440,7 @@ bool VObject::DrawVector (LPDIRECT3DDEVICE7 dev, const Vector &end, const Vector } // rotate vector - Vector d(end/h); + VECTOR3 d = end / h; double tht = acos(d.y), phi = atan2(d.z, d.x); float cost = (float)cos(tht), sint = (float)sin(tht); float cosp = (float)cos(phi), sinp = (float)sin(phi); @@ -458,8 +456,8 @@ bool VObject::DrawVector (LPDIRECT3DDEVICE7 dev, const Vector &end, const Vector D3DMath_MatrixMultiply (W, mWorld, R); dev->SetTransform (D3DTRANSFORMSTATE_WORLD, &W); - Vector cp (tmul (body->GRot(), -cpos)); - if (dotp (d, (end - cp).unit()) > 0) + VECTOR3 cp = tmul(body->GRot(), -cpos); + if (dot(d, unit(end - cp)) > 0) Idx = Idx1, nIdx = nIdx1; else Idx = Idx0, nIdx = nIdx0; diff --git a/Src/Orbiter/Vobject.h b/Src/Orbiter/Vobject.h index 8105f07e0..d43f7eec4 100644 --- a/Src/Orbiter/Vobject.h +++ b/Src/Orbiter/Vobject.h @@ -30,7 +30,7 @@ class VObject { static void CreateDeviceObjects (OrbiterGraphics *gclient); static void DestroyDeviceObjects (); - static D3DCOLORVALUE ColorToD3D(Vector4 col) { return { (float)col.x, (float)col.y, (float)col.z, (float)col.w }; }; + static D3DCOLORVALUE ColorToD3D(VECTOR4 col) { return { (float)col.x, (float)col.y, (float)col.z, (float)col.w }; }; virtual unsigned long GetCaps () const { return 0; } @@ -66,7 +66,7 @@ class VObject { // allows objects to render light beacons or similar inline double CDist () const { return cdist; } - inline const Vector &CPos () const { return cpos; } + inline const VECTOR3 &CPos () const { return cpos; } inline double ScaleFactor () const { return apprad_factor; } inline double AppRad () const { return 1.0/iapprad; } @@ -76,11 +76,11 @@ class VObject { // Notification of visual event (e.g. mesh addition/deletion) struct BodyVectorRec { - Vector v; - Vector orig; + VECTOR3 v; + VECTOR3 orig; double rad; double dist; - Vector col; + VECTOR3 col; float alpha; std::string label; DWORD lcol; @@ -100,24 +100,24 @@ class VObject { void RenderAsDisc (LPDIRECT3DDEVICE7 dev); // Render distant object as a billboard disc texture - void RenderSpot (LPDIRECT3DDEVICE7 dev, const Vector *ofs, float size, const Vector &col, bool lighting, int shape = 0); + void RenderSpot (LPDIRECT3DDEVICE7 dev, const VECTOR3 *ofs, float size, const VECTOR3 &col, bool lighting, int shape = 0); // Render a spot with the given parameters (representing either a // complete object, or a beacon etc.) void RenderAsSpot (LPDIRECT3DDEVICE7 dev, D3DCOLORVALUE *illumination = 0); // Render distant object as circular blob with a billboard texture - void AddVector(const Vector& v, const Vector& orig, double rad, const std::string& label, const Vector& col, float alpha = 1.0f, DWORD lcol = 0, float lsize = -1.0); + void AddVector(const VECTOR3& v, const VECTOR3& orig, double rad, const std::string& label, const VECTOR3& col, float alpha = 1.0f, DWORD lcol = 0, float lsize = -1.0); - bool DrawVector(LPDIRECT3DDEVICE7 dev, const Vector& end, const Vector& orig, double rad = 1.0); + bool DrawVector(LPDIRECT3DDEVICE7 dev, const VECTOR3& end, const VECTOR3& orig, double rad = 1.0); const Body *body; // reference to logical object static Scene *scene; // reference to scene D3DMATRIX mWorld; // world transform matrix MATRIX4 dmWorld; // world transformation matrix in double precision - Vector cpos; // object position relative to camera in global frame - Vector campos; // camera position in object frame + VECTOR3 cpos; // object position relative to camera in global frame + VECTOR3 campos; // camera position in object frame double cdist; // current distance from camera double iapprad; // inverse of apparent radius std::vector veclist; // list of body vectors to be rendered diff --git a/Src/Orbiter/Vstar.cpp b/Src/Orbiter/Vstar.cpp index bed04ca3f..79fcd7567 100644 --- a/Src/Orbiter/Vstar.cpp +++ b/Src/Orbiter/Vstar.cpp @@ -69,7 +69,7 @@ void VStar::Update (bool moving, bool force) VObject::Update (moving, force); - Vector bdir (cpos.unit()); + VECTOR3 bdir = unit(cpos); double hz = std::hypot (bdir.x, bdir.z); double phi = atan2 (bdir.z, bdir.x); FLOAT sphi = (FLOAT)sin(phi), cphi = (FLOAT)cos(phi); @@ -107,7 +107,7 @@ void VStar::Update (bool moving, bool force) mWorld._31 *= rad_scale; mWorld._32 *= rad_scale; mWorld._33 *= rad_scale; } -void VStar::BlindColour (const Camera *cam, Vector &col) +void VStar::BlindColour (const Camera *cam, VECTOR3 &col) { //double alpha = xangle (cam->Direction(), cpos); //double ratio = alpha/cam->Aperture(); @@ -118,13 +118,13 @@ void VStar::BlindColour (const Camera *cam, Vector &col) appsize += 0.02; if (appsize > 0.3) appsize = 0.3; double val = /* scl* */ appsize*3.0; // 0.9 max - col.Set (val,val,val); // grey + col = {val, val, val}; // grey //} } COLORREF VStar::CenterPixelColor () { - Vector orig (cpos * (1.0/cdist)); + VECTOR3 orig = cpos * (1.0 / cdist); int x, y; COLORREF col; if (g_pane->GlobalToScreen (orig, x, y)) { diff --git a/Src/Orbiter/Vstar.h b/Src/Orbiter/Vstar.h index 6d572fafe..febffde7b 100644 --- a/Src/Orbiter/Vstar.h +++ b/Src/Orbiter/Vstar.h @@ -24,7 +24,7 @@ class VStar: public VObject { void RenderVectors (LPDIRECT3DDEVICE7 dev) {} COLORREF CenterPixelColor(); - void BlindColour (const Camera *cam, Vector &col); + void BlindColour (const Camera *cam, VECTOR3 &col); // returns background colour including blind effect // depending on camera direction // Vector is interpreted as RGB (0-1) diff --git a/Src/Orbiter/Vvessel.cpp b/Src/Orbiter/Vvessel.cpp index e1c5cbf62..0df4880a0 100644 --- a/Src/Orbiter/Vvessel.cpp +++ b/Src/Orbiter/Vvessel.cpp @@ -494,8 +494,8 @@ void SetExhaustVertices (const VECTOR3 &edir, const VECTOR3 &cdir, const VECTOR3 { // need to rotate the billboard so it faces the observer const float flarescale = 7.0; - VECTOR3 sdir = unit (crossp (cdir, edir)); - VECTOR3 tdir = unit (crossp (cdir, sdir)); + VECTOR3 sdir = unit(cross(cdir, edir)); + VECTOR3 tdir = unit(cross(cdir, sdir)); D3DVALUE rx = (D3DVALUE)ref.x, ry = (D3DVALUE)ref.y, rz = (D3DVALUE)ref.z; if (lofs) rx += (D3DVALUE)(edir.x*lofs), ry += (D3DVALUE)(edir.y*lofs), rz += (D3DVALUE)(edir.z*lofs); D3DVALUE sx = (D3DVALUE)(sdir.x*wscale); @@ -529,8 +529,8 @@ void SetReentryVertices (const VECTOR3 &edir, const VECTOR3 &cdir, const VECTOR3 const float flarescale = 1.0; const float lscale1 = (float)(lscale*llen * (1.0 + 0.1*rand()/(double)RAND_MAX)); const float lscale2 = (float)(lscale * 0.125); - VECTOR3 sdir = unit (crossp (cdir, edir)); - VECTOR3 tdir = unit (crossp (cdir, sdir)); + VECTOR3 sdir = unit(cross(cdir, edir)); + VECTOR3 tdir = unit(cross(cdir, sdir)); D3DVALUE rx = (D3DVALUE)ref.x, ry = (D3DVALUE)ref.y, rz = (D3DVALUE)ref.z; D3DVALUE sx = (D3DVALUE)(sdir.x*wscale); D3DVALUE sy = (D3DVALUE)(sdir.y*wscale); @@ -594,8 +594,8 @@ void VVessel::RenderBeacons (LPDIRECT3DDEVICE7 dev) continue; double size = bs->size; if (cdist > 50.0) size *= pow (cdist/50.0, bs->falloff); - Vector pos (MakeVector (*bs->pos)); - Vector col (MakeVector (*bs->col)); + auto pos = *bs->pos; + auto col = *bs->col; if (need_setup) { dev->SetRenderState (D3DRENDERSTATE_ALPHABLENDENABLE, TRUE); dev->SetRenderState (D3DRENDERSTATE_ZWRITEENABLE, FALSE); @@ -630,7 +630,7 @@ void VVessel::RenderExhaust (LPDIRECT3DDEVICE7 dev, LPDIRECTDRAWSURFACE7 default dev->SetRenderState (D3DRENDERSTATE_ZWRITEENABLE, FALSE); dev->SetMaterial (&engmat); dev->SetTransform (D3DTRANSFORMSTATE_WORLD, &mWorld); - cdir = MakeVECTOR3 (tmul (body->GRot(), cpos)); + cdir = tmul(body->GRot(), cpos); #ifdef EXHAUST_SCALEALPHA dev->SetTextureStageState (0, D3DTSS_ALPHAOP, D3DTOP_MODULATE); dev->SetTextureStageState (0, D3DTSS_ALPHAARG2, D3DTA_TFACTOR); @@ -678,7 +678,7 @@ void VVessel::RenderExhaust (LPDIRECT3DDEVICE7 dev, LPDIRECTDRAWSURFACE7 default dev->SetRenderState (D3DRENDERSTATE_ZWRITEENABLE, FALSE); //dev->SetMaterial (&engmat); dev->SetTransform (D3DTRANSFORMSTATE_WORLD, &mWorld); - cdir = MakeVECTOR3 (tmul (body->GRot(), cpos)); + cdir = tmul(body->GRot(), cpos); need_setup = false; } @@ -690,8 +690,8 @@ void VVessel::RenderExhaust (LPDIRECT3DDEVICE7 dev, LPDIRECTDRAWSURFACE7 default mat.emissive.g = (float)(0.7+0.3*opac); mat.emissive.b = (float)(0.5+0.5*opac); dev->SetMaterial (&mat); - VECTOR3 dir = unit (MakeVECTOR3 (vessel->sp.airvel_ship)); - VECTOR3 ref = dir*(0.2*vessel->size); + VECTOR3 dir = unit(vessel->sp.airvel_ship); + VECTOR3 ref = dir * (0.2 * vessel->size); SetReentryVertices (-dir, cdir, ref, vessel->reentry.lscale*vessel->size, vessel->reentry.wscale*(0.15+max(opac,0.5))*vessel->size, opac, ReentryVtx); @@ -720,31 +720,31 @@ void VVessel::RenderGroundShadow (LPDIRECT3DDEVICE7 dev, const Planet *planet) double depth = planet->ShadowDepth(); if (!depth) return; - Vector pp (planet->GPos()); // planet position - Vector pv (vessel->GPos()); // vessel position - Vector pvr (pv-pp); // rel. vessel position - Vector sd (pv.unit()); // shadow projection direction + VECTOR3 pp = planet->GPos(); // planet position + VECTOR3 pv = vessel->GPos(); // vessel position + VECTOR3 pvr = pv - pp; // rel. vessel position + VECTOR3 sd = unit(pv); // shadow projection direction double R = planet->Size(); // planet radius R += sp->elev; // Note: this only works at low vessel altitudes (shadow close to vessel position) // calculate the intersection of the vessel's shadow with the planet surface - double fac1 = dotp (sd, pvr); + double fac1 = dot(sd, pvr); if (fac1 > 0.0) return; // shadow doesn't intersect planet surface - double csun = -fac1/pvr.length(); // sun elevation above horizon + double csun = -fac1 / len(pvr); // sun elevation above horizon if (csun < shadow_elev_limit) return; // sun too low to cast shadow - double arg = fac1*fac1 - (dotp (pvr, pvr) - R*R); + double arg = fac1 * fac1 - (dot(pvr, pvr) - R * R); if (arg <= 0.0) return; // shadow doesn't intersect with planet surface double a = -fac1 - sqrt(arg); - Vector sdv (tmul (vessel->GRot(), sd)); // projection direction in vessel frame - Vector shp (sdv*a); // projection point + VECTOR3 sdv = tmul(vessel->GRot(), sd); // projection direction in vessel frame + VECTOR3 shp = sdv * a; // projection point //Vector hn (tmul (vessel->GRot(), (sd*a + pvr).unit())); // horizon normal in vessel frame - Vector hn (tmul (vessel->GRot(), mul (planet->GRot(), tmul (sp->L2H, sp->surfnml)))); + VECTOR3 hn = tmul(vessel->GRot(), mul(planet->GRot(), tmul(sp->L2H, sp->surfnml))); // perform projections - double nr0 = dotp (hn, shp); - double nd = dotp (hn, sdv); - Vector sdvs (sdv / nd); + double nr0 = dot(hn, shp); + double nd = dot(hn, sdv); + VECTOR3 sdvs = sdv / nd; VERTEX_XYZ *pvtx; // shadow vertex buffer double ndr, vx, vy, vz; @@ -803,47 +803,47 @@ void VVessel::UpdateRenderVectors() double pscale = *(float*)gc->GetConfigParam(CFGPRM_FORCEVECTORSCALE); float alpha = *(float*)gc->GetConfigParam(CFGPRM_FORCEVECTOROPACITY); char cbuf[256]; - Vector F; + VECTOR3 F; if ((flag & BFV_WEIGHT) && vessel->GetWeightVector (F)) { - sprintf (cbuf, "G =%sN", FloatStr (len = F.length(), 4)); + sprintf(cbuf, "G =%sN", FloatStr(len = ::len(F), 4)); if (logscale) len = log(len+shift) - lshift; else len *= scale; - AddVector (F.unit()*(len*pscale), Vector(0,0,0), scale2, std::string(cbuf), Vector (1,1,0), alpha, D3DRGB (1,1,0)); + AddVector(unit(F) * (len * pscale), {0, 0, 0}, scale2, std::string{cbuf}, {1, 1, 0}, alpha, D3DRGB(1, 1, 0)); } if ((flag & BFV_THRUST) && vessel->GetThrustVector (F)) { - sprintf (cbuf, "T =%sN", FloatStr (len = F.length(), 4)); + sprintf(cbuf, "T =%sN", FloatStr(len = ::len(F), 4)); if (logscale) len = log(len+shift) - lshift; else len *= scale; - AddVector (F.unit()*(len*pscale), Vector(0,0,0), scale2, std::string(cbuf), Vector (0,0,1), alpha, D3DRGB (0.5,0.5,1)); + AddVector(unit(F) * (len * pscale), {0, 0, 0}, scale2, std::string{cbuf}, {0, 0, 1}, alpha, D3DRGB(0.5, 0.5, 1)); } if ((flag & BFV_LIFT) && vessel->GetLiftVector (F)) { - sprintf (cbuf, "L =%sN", FloatStr (len = F.length(), 4)); + sprintf(cbuf, "L =%sN", FloatStr(len = ::len(F), 4)); if (logscale) len = log(len+shift) - lshift; else len *= scale; - AddVector (F.unit()*(len*pscale), Vector(0,0,0), scale2, std::string(cbuf), Vector (0,1,0), alpha, D3DRGB (0.5,1,0.5)); + AddVector(unit(F) * (len * pscale), {0, 0, 0}, scale2, std::string{cbuf}, {0, 1, 0}, alpha, D3DRGB(0.5, 1, 0.5)); } if ((flag & BFV_DRAG) && vessel->GetDragVector (F)) { - sprintf (cbuf, "D =%sN", FloatStr (len = vessel->Drag, 4)); + sprintf(cbuf, "D =%sN", FloatStr(len = vessel->Drag, 4)); if (logscale) len = log(len+shift) - lshift; else len *= scale; - AddVector (F.unit()*(len*pscale), Vector(0,0,0), scale2, std::string(cbuf), Vector (1,0,0), alpha, D3DRGB (1,0.5,0.5)); + AddVector(unit(F) * (len * pscale), {0, 0, 0}, scale2, std::string{cbuf}, {1, 0, 0}, alpha, D3DRGB(1, 0.5, 0.5)); } if ((flag & BFV_TOTAL) && vessel->GetForceVector (F)) { - sprintf (cbuf, "F =%sN", FloatStr (len = F.length(), 4)); + sprintf(cbuf, "F =%sN", FloatStr(len = ::len(F), 4)); if (logscale) len = log(len+shift) - lshift; else len *= scale; - AddVector (F.unit()*(len*pscale), Vector(0,0,0), scale2, std::string(cbuf), Vector (1,1,1), alpha, D3DRGB (1,1,1)); + AddVector(unit(F) * (len * pscale), {0, 0, 0}, scale2, std::string{cbuf}, {1, 1, 1}, alpha, D3DRGB(1, 1, 1)); } if (1) { for (int i = 0; i < vessel->nforcevec; i++) { F = vessel->forcevec[i]; - sprintf (cbuf, "F =%sN", FloatStr (len = F.length(), 4)); + sprintf(cbuf, "F =%sN", FloatStr(len = ::len(F), 4)); len *= 1e-2; if (logscale) len = log(len+shift) - lshift; else len *= scale; - AddVector (F.unit()*(len*pscale), vessel->forcepos[i], scale2, std::string(cbuf), Vector (0,1,1), alpha, D3DRGB (1,1,1)); + AddVector(unit(F) * (len * pscale), vessel->forcepos[i], scale2, std::string{cbuf}, {0, 1, 1}, alpha, D3DRGB(1, 1, 1)); } } if ((flag & BFV_TORQUE) && vessel->GetTorqueVector(F)) { - if (len = F.length()) { + if (len = ::len(F)) { sprintf(cbuf, "M =%sNm", FloatStr(len, 4)); if (logscale) len = log(len + 1e-5) - log(1e-5); else len *= scale * 1e5; - AddVector(F.unit() * (len * pscale), Vector(0, 0, 0), scale2 * 0.5, std::string(cbuf), Vector(1, 0, 1), alpha, D3DRGB(1, 0, 1), (float)(0.5 * vessel->size)); + AddVector(unit(F) * (len * pscale), {0, 0, 0}, scale2 * 0.5, std::string{cbuf}, {1, 0, 1}, alpha, D3DRGB(1, 0, 1), (float)(0.5 * vessel->size)); } } } @@ -859,7 +859,7 @@ void VVessel::RenderAttachmentMarkers (LPDIRECT3DDEVICE7 dev, bool pa) AttachmentSpec **attach; DWORD i, j, nattach; D3DMATERIAL7 *mat; - Vector v; + VECTOR3 v; if (pa) { nattach = vessel->npattach; @@ -879,17 +879,17 @@ void VVessel::RenderAttachmentMarkers (LPDIRECT3DDEVICE7 dev, bool pa) //if (as->id[0] != 'G') continue; // only mark grappling points float ux = (float)as->ref.x, uy = (float)as->ref.y, uz = (float)as->ref.z; vtx[0].x = 0; vtx[0].y = 0; vtx[0].z = 0; - v.Set ((as->dir+as->rot)*0.25); + v = (as->dir + as->rot) * 0.25; vtx[1].x = (float)v.x; vtx[1].y = (float)v.y; vtx[1].z = (float)v.z; - v.Set (as->dir*0.25 + as->rot*0.125); + v = as->dir * 0.25 + as->rot * 0.125; vtx[2].x = (float)v.x; vtx[2].y = (float)v.y; vtx[2].z = (float)v.z; - v.Set (as->dir*0.5 + as->rot*0.125); + v = as->dir * 0.5 + as->rot * 0.125; vtx[3].x = (float)v.x; vtx[3].y = (float)v.y; vtx[3].z = (float)v.z; - v.Set (as->dir*0.5 - as->rot*0.125); + v = as->dir * 0.5 - as->rot * 0.125; vtx[4].x = (float)v.x; vtx[4].y = (float)v.y; vtx[4].z = (float)v.z; - v.Set (as->dir*0.25 - as->rot*0.125); + v = as->dir * 0.25 - as->rot * 0.125; vtx[5].x = (float)v.x; vtx[5].y = (float)v.y; vtx[5].z = (float)v.z; - v.Set ((as->dir-as->rot)*0.25); + v = (as->dir - as->rot) * 0.25; vtx[6].x = (float)v.x; vtx[6].y = (float)v.y; vtx[6].z = (float)v.z; for (j = 0; j < 7; j++) { vtx[j].x += ux, vtx[j].y += uy, vtx[j].z += uz; @@ -903,10 +903,10 @@ bool VVessel::ModLighting (LPD3DLIGHT7 light) const CelestialBody *cb = vessel->ProxyPlanet(); if (!cb) return false; Star *sun = g_psys->GetStar(0); // should really loop over all suns - Vector S(sun->GPos() - vessel->GPos()); - double s = S.length(); + VECTOR3 S = sun->GPos() - vessel->GPos(); + double s = len(S); double as = asin (sun->Size()/s); // apparent size of sun disc [rad] - Vector lcol (1,1,1); + VECTOR3 lcol{1, 1, 1}; double amb = 0; double dt = 1.0; bool lightmod = false; @@ -915,10 +915,10 @@ bool VVessel::ModLighting (LPD3DLIGHT7 light) // calculate shadowing by planet for (i = 0;; i++) { - Vector P(cb->GPos() - vessel->GPos()); - double p = P.length(); + VECTOR3 P = cb->GPos() - vessel->GPos(); + double p = len(P); if (p < s) { // shadow only if planet closer than sun - double phi = acos (dotp(S,P)/(s*p)); // angular distance between sun and planet + double phi = std::acos(dot(S, P) / (s * p)); // angular distance between sun and planet double ap = (cb->Size() < p ? asin(cb->Size() / p) : Pi05); // apparent size of planet disc [rad] if (cb->Type() == OBJTP_PLANET && ((Planet*)cb)->HasAtmosphere()) { // case 1: planet has atmosphere @@ -937,10 +937,10 @@ bool VVessel::ModLighting (LPD3DLIGHT7 light) if (as+ap1 >= phi && ap/as > 0.1) { // overlap and significant planet size double dap = ap1-ap; - Vector plight(1,1,1); + VECTOR3 plight{1, 1, 1}; if (as < ap) { // planet disc larger than sun disc if (phi < ap-as) { // totality (sun below horizon) - plight.Set(0,0,0); + plight = {0, 0, 0}; } else { double dispersion = max (0.02, min (0.9, log (atm->rho0+1.0))); double r0 = 1.0-0.40*dispersion; @@ -962,10 +962,10 @@ bool VVessel::ModLighting (LPD3DLIGHT7 light) } else { double maxcover = ap*ap / (as*as); if (phi < as-ap) - plight.Set(1.0-maxcover,1.0-maxcover,1.0-maxcover); // annularity + plight = {1.0 - maxcover, 1.0 - maxcover, 1.0 - maxcover}; // annularity else { double frac = 1.0 - 0.5*maxcover * (1.0 + (as-phi)/ap); // partial cover - plight.Set (frac,frac,frac); + plight = {frac, frac, frac}; dt = 0.1; } } diff --git a/Src/Orbiter/elevmgr.cpp b/Src/Orbiter/elevmgr.cpp index ac0bcb2b5..fdb14d917 100644 --- a/Src/Orbiter/elevmgr.cpp +++ b/Src/Orbiter/elevmgr.cpp @@ -260,7 +260,7 @@ bool ElevationManager::LoadElevationTile_mod (int lvl, int ilat, int ilng, doubl return false; } -double ElevationManager::Elevation (double lat, double lng, int reqlvl, std::vector *tilecache, Vector *normal, int *reslvl) const +double ElevationManager::Elevation (double lat, double lng, int reqlvl, std::vector *tilecache, VECTOR3 *normal, int *reslvl) const { double e = 0.0; if (reslvl) *reslvl = 0; @@ -349,12 +349,12 @@ double ElevationManager::Elevation (double lat, double lng, int reqlvl, std::vec double nx01 = eptr[1]-eptr[0]; double nx02 = eptr[elev_stride+1]-eptr[elev_stride]; double nx = w_lat*nx02 + (1.0-w_lat)*nx01; - Vector vnx(dx,nx,0); + VECTOR3 vnx{dx, nx, 0}; double nz01 = eptr[elev_stride]-eptr[0]; double nz02 = eptr[elev_stride+1]-eptr[1]; double nz = w_lng*nz02 + (1.0-w_lng)*nz01; - Vector vnz(0,nz,dz); - *normal = crossp(vnz,vnx).unit(); + VECTOR3 vnz{0, nz, dz}; + *normal = unit(cross(vnz, vnx)); } } else { // cubic spline interpolation double a_m1, a_0, a_p1, a_p2, b_m1, b_0, b_p1, b_p2; @@ -413,7 +413,7 @@ double ElevationManager::Elevation (double lat, double lng, int reqlvl, std::vec normal->x = -dex; normal->z = -dez; normal->y = 0.5*(dx+dz); - normal->unify(); + *normal = unit(*normal); } } t->last_access = td.SysT0; diff --git a/Src/Orbiter/elevmgr.h b/Src/Orbiter/elevmgr.h index cd85b8d1a..f3af0ab4b 100644 --- a/Src/Orbiter/elevmgr.h +++ b/Src/Orbiter/elevmgr.h @@ -24,14 +24,14 @@ struct ElevationTile { int lat0 = 0, lng0 = 0; bool celldiag = false; int nmlidx = 0; - Vector normal; + VECTOR3 normal; }; class ElevationManager { public: ElevationManager (const CelestialBody *_cbody); ~ElevationManager(); - double Elevation (double lat, double lng, int reqlvl=0, std::vector *tilecache = 0, Vector *normal=0, int *lvl=0) const; + double Elevation (double lat, double lng, int reqlvl=0, std::vector *tilecache = 0, VECTOR3 *normal=0, int *lvl=0) const; /** * \brief Synthesize an elevation tile by interpolating from the parent * \param ilat latitude index of target tile diff --git a/Src/Orbiter/hud.cpp b/Src/Orbiter/hud.cpp index 63350bed6..30987cb76 100644 --- a/Src/Orbiter/hud.cpp +++ b/Src/Orbiter/hud.cpp @@ -24,8 +24,8 @@ extern char DBG_MSG[256]; const double MAXALT_HUD = 1e15; // make user-selectable -void BoxCoord (const Vector &dockpos, const Vector &dockdir, - const Vector &refdir, double dist, Vector *crd); +void BoxCoord (const VECTOR3 &dockpos, const VECTOR3 &dockdir, + const VECTOR3 &refdir, double dist, VECTOR3 *crd); // ======================================================================= // class HUD @@ -87,7 +87,7 @@ void HUD::Draw (oapi::Sketchpad *skp) if (g_camera->IsExternal()) return; // nothing to do if (bVC) { - HUDofs.Set ((VCcnt - g_camera->CockpitPos()) * VCscale); + HUDofs = (VCcnt - g_camera->CockpitPos()) * VCscale; spec.Scale = HUDofs.z * onedeg; } else { spec.Scale = g_camera->Scale() * onedeg; @@ -99,7 +99,7 @@ void HUD::Draw (oapi::Sketchpad *skp) bCNTvis = (spec.CX >= 0 && spec.CX < spec.W && spec.CY >= 0 && spec.CY < spec.H); } else { D3DVECTOR homog; - bCNTvis = pane->GlobalToHomog (mul (g_focusobj->GRot(), Vector(0,0,1)), homog); + bCNTvis = pane->GlobalToHomog(mul(g_focusobj->GRot(), VECTOR3{0, 0, 1}), homog); if (bCNTforward = (homog.z > 0.0)) { spec.CX = (int)(HRES05*(1.0f+homog.x)); spec.CY = (int)(VRES05*(1.0f-homog.y)); @@ -161,7 +161,7 @@ void HUD::Render () bCNTvis = (spec.CX >= 0 && spec.CX < spec.W && spec.CY >= 0 && spec.CY < spec.H); } else { D3DVECTOR homog; - bCNTvis = pane->GlobalToHomog (mul (g_focusobj->GRot(), Vector(0,0,1)), homog); + bCNTvis = pane->GlobalToHomog(mul(g_focusobj->GRot(), VECTOR3{0, 0, 1}), homog); if (bCNTforward = (homog.z > 0.0)) { spec.CX = (int)(HRES05*(1.0f+homog.x)); spec.CY = (int)(VRES05*(1.0f-homog.y)); @@ -186,8 +186,7 @@ void HUD::Resize (bool isVC) HRES05 = VRES05 = (spec.W/2); ladder_width = (HRES05*60)/128; ladder_range = 250; - const VECTOR3 &cnt = pane->GetVC()->GetHUDParams()->hudcnt; - VCcnt.Set (cnt.x, cnt.y, cnt.z); + VCcnt = pane->GetVC()->GetHUDParams()->hudcnt; VCscale = spec.H / pane->GetVC()->GetHUDParams()->size; spec.Markersize = 6+(10*HRES05)/128; boxx = fW*3; @@ -197,7 +196,7 @@ void HUD::Resize (bool isVC) VRES05 = (spec.H = pane->H)/2; ladder_width = 0.12*spec.W; ladder_range = 0.43*spec.H; - HUDofs.Set (0, 0, g_camera->Scale()); + HUDofs = {0, 0, g_camera->Scale()}; spec.Markersize = max(20,spec.H/25); // spec.W/40; boxx = spec.Markersize*10; //HRES05 >> 1; h = spec.H/50; @@ -375,7 +374,7 @@ void HUD::AddMesh_CenterMarker (int &ivtx, int &iidx) ivtx += nvtx; } -bool HUD::AddMesh_Marker (int &ivtx, int &iidx, const Vector &dir, int markerid, double *xcnt, double *ycnt) +bool HUD::AddMesh_Marker (int &ivtx, int &iidx, const VECTOR3 &dir, int markerid, double *xcnt, double *ycnt) { double x, y; @@ -408,7 +407,7 @@ bool HUD::AddMesh_Marker (int &ivtx, int &iidx, const Vector &dir, int markerid, } } -void HUD::AddMesh_DirectionMarker (int &ivtx, int &iidx, const Vector &dir, bool prograde, double *xcnt, double *ycnt) +void HUD::AddMesh_DirectionMarker (int &ivtx, int &iidx, const VECTOR3 &dir, bool prograde, double *xcnt, double *ycnt) { int i; //double scal = VRES05*0.00075; // HRES05*0.0012; @@ -416,9 +415,9 @@ void HUD::AddMesh_DirectionMarker (int &ivtx, int &iidx, const Vector &dir, bool double dy = spec.Markersize*0.83;//scal*39; double rad = dy*4.0; - Vector d; - if (bVC) d.Set (tmul (g_focusobj->GRot(), dir)); - else d.Set (tmul (g_camera->GRot(), dir)); + VECTOR3 d; + if (bVC) d = tmul(g_focusobj->GRot(), dir); + else d = tmul(g_camera->GRot(), dir); double len = std::hypot (d.x, d.y); if (!len) return; double cosa = d.y/len, sina = -d.x/len; @@ -940,10 +939,10 @@ void HUD::AddMesh_DockApproachGates (int &ivtx, int &iidx, const Body *tgt, cons int i, j; double x[16], y[16], dx1, dy1, dx2, dy2, rx, ry; double linew = renderprm.scal*3; - Vector dpos (mul (tgt->GRot(), ps->ref) + tgt->GPos() - g_camera->GPos()); - Vector ddir (mul (tgt->GRot(), -ps->dir)); - Vector ydir (mul (tgt->GRot(), ps->rot)); - Vector p[4]; + VECTOR3 dpos = mul(tgt->GRot(), ps->ref) + tgt->GPos() - g_camera->GPos(); + VECTOR3 ddir = mul(tgt->GRot(), -ps->dir); + VECTOR3 ydir = mul(tgt->GRot(), ps->rot); + VECTOR3 p[4]; double dist = 50; float dx = -(float)(ddir.x*dist); float dy = -(float)(ddir.y*dist); @@ -992,7 +991,7 @@ void HUD::AddMesh_DockApproachGates (int &ivtx, int &iidx, const Body *tgt, cons y[12]= y[0]+ry; y[13]= y[1]+ry; x[14]= x[13]+dx1;x[15]= x[12]+dx1; y[14]= y[13]+dy1;y[15]= y[12]+dy1; - if (dotp(dpos.unit(), ddir) >= 0.0) { + if (dot(unit(dpos), ddir) >= 0.0) { for (j = 0; j < 30; j++) gs->Idx[iidx++] = ivtx + boxidx1[j]; } else { @@ -1168,12 +1167,12 @@ void HUD::DrawTiltedRibbon (oapi::Sketchpad *skp, double phi, double alpha) skp->SetTextAlign (oapi::Sketchpad::LEFT); } -bool HUD::GlobalToHUD (const Vector &dir, int &x, int &y) const +bool HUD::GlobalToHUD (const VECTOR3 &dir, int &x, int &y) const { bool vis; if (bVC) { - Vector ldir = tmul (g_focusobj->GRot(), dir); + VECTOR3 ldir = tmul(g_focusobj->GRot(), dir); if (ldir.z <= 0.0) vis = false; else { double fac = HUDofs.z/ldir.z; @@ -1187,12 +1186,12 @@ bool HUD::GlobalToHUD (const Vector &dir, int &x, int &y) const return vis; } -bool HUD::GlobalToHUD (const Vector &dir, double &x, double &y) const +bool HUD::GlobalToHUD (const VECTOR3 &dir, double &x, double &y) const { bool vis; if (bVC) { - Vector ldir = tmul (g_focusobj->GRot(), dir); + VECTOR3 ldir = tmul(g_focusobj->GRot(), dir); if (ldir.z <= 0.0) vis = false; else { double fac = HUDofs.z/ldir.z; @@ -1206,7 +1205,7 @@ bool HUD::GlobalToHUD (const Vector &dir, double &x, double &y) const return vis; } -bool HUD::GlobalDrawMarker (oapi::Sketchpad *skp, const Vector &dir, int style) const +bool HUD::GlobalDrawMarker (oapi::Sketchpad *skp, const VECTOR3 &dir, int style) const { int x, y; if (GlobalToHUD (dir, x, y)) { @@ -1225,14 +1224,14 @@ bool HUD::GlobalDrawMarker (oapi::Sketchpad *skp, const Vector &dir, int style) return false; } -oapi::IVECTOR2 *HUD::OffscreenDirMarker (const Vector &dir) const +oapi::IVECTOR2 *HUD::OffscreenDirMarker (const VECTOR3 &dir) const { static oapi::IVECTOR2 pt[4]; - Vector d; + VECTOR3 d; if (bVC) { - d.Set (tmul (g_focusobj->GRot(), dir)); + d = tmul(g_focusobj->GRot(), dir); } else { - d.Set (tmul (g_camera->GRot(), dir)); + d = tmul(g_camera->GRot(), dir); } double len = std::hypot (d.y, d.x); double scale = spec.Markersize * 0.6; @@ -1323,9 +1322,9 @@ void HUD_Orbit::Display (oapi::Sketchpad *skp) sprintf (cbuf, "[%s]", cntobj->Name()); skp->Text (10+6*fW, 0, cbuf, strlen (cbuf)); - Vector V = self->GVel() - cntobj->GVel(); - Vector Vunit = V.unit(); - Vector Vrel = tmul (self->GRot(), V).unit(); + VECTOR3 V = self->GVel() - cntobj->GVel(); + VECTOR3 Vunit = unit(V); + VECTOR3 Vrel = unit(tmul(self->GRot(), V)); if (!GlobalDrawMarker (skp, Vunit, 6) && !GlobalDrawMarker (skp, -Vunit, 4)) { oapi::IVECTOR2 *pt = OffscreenDirMarker (Vunit); @@ -1333,7 +1332,7 @@ void HUD_Orbit::Display (oapi::Sketchpad *skp) skp->Text (pt[3].x-fW, pt[3].y-spec.Markersize-fH-2, "PG", 2); } - Vector P = self->GPos() - cntobj->GPos(); + VECTOR3 P = self->GPos() - cntobj->GPos(); // radius indicator dx = fW*7; @@ -1342,7 +1341,7 @@ void HUD_Orbit::Display (oapi::Sketchpad *skp) y = fH*3; char spd_mag = 0; // speed magnitude character char rad_mag = 0; // radius magnitude character - if ((v=P.length()) < MAXALT_HUD) { + if ((v = ::len(P)) < MAXALT_HUD) { strcpy (cbuf, FloatStr (v)); len = strlen(cbuf + 1); if (cbuf[len] >= 'M') { @@ -1358,7 +1357,7 @@ void HUD_Orbit::Display (oapi::Sketchpad *skp) skp->Rectangle (xbr, y, xbr+dx, y+2+fH); // orbital velocity indicator - if ((v = V.length()) >= 0.0) { + if ((v = ::len(V)) >= 0.0) { if (v < MAXALT_HUD) { strcpy (cbuf, FloatStr (v)); len = strlen(cbuf + 1); @@ -1387,7 +1386,7 @@ void HUD_Orbit::Display (oapi::Sketchpad *skp) skp->SetTextAlign(oapi::Sketchpad::LEFT); skp->SetFont(font); - Vector Prel = tmul (self->GRot(), P).unit(); + VECTOR3 Prel = unit(tmul(self->GRot(), P)); //if (Prel.z < 0.0) Prel = -Prel; fac = VRES05 / (Prel.z * g_camera->TanAperture()); px = HRES05 + (int)(Prel.x * fac); @@ -1419,13 +1418,13 @@ void HUD_Orbit::Display (oapi::Sketchpad *skp) } // Orbital plane azimuth angle ribbon - Vector Z0 (-c*a, -c*b, a*a+b*b); // projection of vessel forward direction into orbital plane + VECTOR3 Z0{-c * a, -c * b, a * a + b * b}; // projection of vessel forward direction into orbital plane if (Z0.x || Z0.y || Z0.z) { - Z0.unify(); - double cosa = dotp (Vrel, Z0); + Z0 = unit(Z0); + double cosa = dot(Vrel, Z0); double phi = acos(cosa); - Vector VV (Vrel.y*c - Vrel.z*b, Vrel.z*a - Vrel.x*c, Vrel.x*b - Vrel.y*a); // Vector perpendicular to V in orbital plane - if (dotp (Z0, VV) > 0.0) phi = Pi2-phi; + VECTOR3 VV{Vrel.y * c - Vrel.z * b, Vrel.z * a - Vrel.x * c, Vrel.x * b - Vrel.y * a}; // Vector perpendicular to V in orbital plane + if (dot(Z0, VV) > 0.0) phi = Pi2 - phi; DrawTiltedRibbon (skp, phi, alpha); } } @@ -1451,8 +1450,8 @@ void HUD_Orbit::UpdateMesh (int &ivtx, int &iidx) } AddMesh_Billboard (ivtx, iidx, spec.CX-renderprm.scal*refwidth*0.7, renderprm.scal*10, renderprm.scal*refwidth*1.4, renderprm.scal*19.6, 0, 242, refwidth, 14); - Vector V = self->GVel() - cntobj->GVel(); - Vector Vunit = V.unit(); + VECTOR3 V = self->GVel() - cntobj->GVel(); + VECTOR3 Vunit = unit(V); if (!AddMesh_Marker (ivtx, iidx, Vunit, 1) && !AddMesh_Marker (ivtx, iidx, -Vunit, 0)) { AddMesh_DirectionMarker (ivtx, iidx, Vunit, true); @@ -1460,17 +1459,17 @@ void HUD_Orbit::UpdateMesh (int &ivtx, int &iidx) if (g_camera->IsCockpitForward()) { static double step = tan (RAD*10.0); - Vector Vrel = tmul (self->GRot(), V).unit(); - Vector P = self->GPos() - cntobj->GPos(); - Vector Prel = tmul (self->GRot(), P).unit(); + VECTOR3 Vrel = unit(tmul(self->GRot(), V)); + VECTOR3 P = self->GPos() - cntobj->GPos(); + VECTOR3 Prel = unit(tmul(self->GRot(), P)); // Radius readout char cbuf[64]; - strcpy (cbuf, (v=P.length()) < MAXALT_HUD ? FloatStr (v) : " ----"); + strcpy(cbuf, (v = len(P)) < MAXALT_HUD ? FloatStr (v) : " ----"); AddMesh_Readout (ivtx, iidx, 1, cbuf+1, 2); // Orbital velocity readout - strcpy (cbuf, (v=V.length()) < MAXALT_HUD ? FloatStr (v) : " ----"); + strcpy(cbuf, (v = len(V)) < MAXALT_HUD ? FloatStr (v) : " ----"); AddMesh_Readout (ivtx, iidx, 0, cbuf+1, 4); a = Prel.z*Vrel.y - Prel.y*Vrel.z; @@ -1493,13 +1492,13 @@ void HUD_Orbit::UpdateMesh (int &ivtx, int &iidx) } // Orbital plane azimuth angle ribbon - Vector Z0 (-c*a, -c*b, a*a+b*b); // projection of vessel forward direction into orbital plane + VECTOR3 Z0{-c * a, -c * b, a * a + b * b}; // projection of vessel forward direction into orbital plane if (Z0.x || Z0.y || Z0.z) { - Z0.unify(); - double cosa = dotp (Vrel, Z0); + Z0 = unit(Z0); + double cosa = dot(Vrel, Z0); double phi = acos(cosa); - Vector VV (Vrel.y*c - Vrel.z*b, Vrel.z*a - Vrel.x*c, Vrel.x*b - Vrel.y*a); // Vector perpendicular to V in orbital plane - if (dotp (Z0, VV) > 0.0) phi = Pi2-phi; + VECTOR3 VV{Vrel.y * c - Vrel.z * b, Vrel.z * a - Vrel.x * c, Vrel.x * b - Vrel.y * a}; // Vector perpendicular to V in orbital plane + if (dot(Z0, VV) > 0.0) phi = Pi2 - phi; AddMesh_AzimuthTape (ivtx, iidx, phi, alpha); } } @@ -1587,7 +1586,7 @@ void HUD_Surface::Display (oapi::Sketchpad *skp) // velocity marker if (sp->groundspd > 1.0) - GlobalDrawMarker (skp, sp->groundvel_glob.unit(), 6); + GlobalDrawMarker(skp, unit(sp->groundvel_glob), 6); // altitude indicator dx = fW*7; @@ -1721,7 +1720,7 @@ void HUD_Surface::UpdateMesh (int &ivtx, int &iidx) // velocity marker if (sp->groundspd > 1.0) - AddMesh_Marker (ivtx, iidx, sp->groundvel_glob.unit(), 1); + AddMesh_Marker(ivtx, iidx, unit(sp->groundvel_glob), 1); if (g_camera->IsCockpitForward()) { // Altitude readout @@ -1867,8 +1866,8 @@ void HUD_Docking::Display (oapi::Sketchpad *skp) skp->Text (10+5*fW, 0, cbuf, strlen (cbuf)); // rel velocity marker - Vector vrel = self->GVel() - tgt->GVel(); - double len = vrel.length(); vrel /= len; + VECTOR3 vrel = self->GVel() - tgt->GVel(); + double len = ::len(vrel); vrel /= len; sprintf (cbuf, "V[%s]", tgt->Name()); if (GlobalToHUD (vrel, x, y)) { @@ -1891,8 +1890,8 @@ void HUD_Docking::Display (oapi::Sketchpad *skp) skp->Text (x-(slen*fW)/2, y+spec.Markersize, cbuf+1, slen); // target marker - Vector prel = tgt->GPos() - self->GPos(); - len = prel.length(); prel /= len; + VECTOR3 prel = tgt->GPos() - self->GPos(); + len = ::len(prel); prel /= len; if (GlobalToHUD (prel, x, y)) { skp->Rectangle (x-spec.Markersize, y-spec.Markersize, x+spec.Markersize+1, y+spec.Markersize+1); } else { @@ -1909,10 +1908,10 @@ void HUD_Docking::Display (oapi::Sketchpad *skp) // approach path indicator if (ps) { int i, j, x, y; - Vector dpos (mul (tgt->GRot(), ps->ref) + tgt->GPos() - g_camera->GPos()); - Vector ddir (mul (tgt->GRot(), -ps->dir)); - Vector ydir (mul (tgt->GRot(), ps->rot)); - Vector p[4], pp[2]; + VECTOR3 dpos = mul(tgt->GRot(), ps->ref) + tgt->GPos() - g_camera->GPos(); + VECTOR3 ddir = mul(tgt->GRot(), -ps->dir); + VECTOR3 ydir = mul(tgt->GRot(), ps->rot); + VECTOR3 p[4], pp[2]; oapi::IVECTOR2 pt[4]; double dist = 50.0; float dx = -(float)(ddir.x*dist); @@ -2007,9 +2006,9 @@ void HUD_Docking::UpdateMesh (int &ivtx, int &iidx) // rel velocity marker double xcnt, ycnt; - Vector vrel = self->GVel() - tgt->GVel(); - double len = vrel.length(); - Vector Vunit = vrel/len; + VECTOR3 vrel = self->GVel() - tgt->GVel(); + double len = ::len(vrel); + VECTOR3 Vunit = vrel / len; sprintf (cbuf, "-V[%s]%s", tgt->Name(), DistStr(len)); char *pc = cbuf+1; @@ -2028,8 +2027,8 @@ void HUD_Docking::UpdateMesh (int &ivtx, int &iidx) AddMesh_Billboard (ivtx, iidx, xcnt-0.7*renderprm.scal*vstr1width, ycnt-renderprm.scal*60, 1.4*renderprm.scal*vstr1width, renderprm.scal*19.6, 0, 216, vstr1width, 13); // target marker - Vector prel = tgt->GPos() - self->GPos(); - len = prel.length(); prel /= len; + VECTOR3 prel = tgt->GPos() - self->GPos(); + len = ::len(prel); prel /= len; if (!AddMesh_Marker (ivtx, iidx, prel, 2, &xcnt, &ycnt)) AddMesh_DirectionMarker (ivtx, iidx, prel, false, &xcnt, &ycnt); sprintf (cbuf, "D[%s]%s", tgt->Name(), DistStr(len)); @@ -2140,12 +2139,12 @@ void HUD_Docking::ReadParams (ifstream &ifs) } } -void BoxCoord (const Vector &dockpos, const Vector &dockdir, - const Vector &refdir, double dist, Vector *crd) +void BoxCoord (const VECTOR3 &dockpos, const VECTOR3 &dockdir, + const VECTOR3 &refdir, double dist, VECTOR3 *crd) { const double size1 = 7.0, size2 = 5.0; - Vector xdir (crossp (dockdir, refdir)); - Vector s (dockpos - dockdir*dist); + VECTOR3 xdir = cross(dockdir, refdir); + VECTOR3 s = dockpos - dockdir * dist; for (int i = 0; i < 4; i++) crd[i] = s + refdir * (i <= 1 ? size2 : -size2) + xdir * (i == 0 || i == 3 ? size1 : -size1); } diff --git a/Src/Orbiter/hud.h b/Src/Orbiter/hud.h index fad362b3b..1709a743b 100644 --- a/Src/Orbiter/hud.h +++ b/Src/Orbiter/hud.h @@ -54,8 +54,8 @@ class HUD { void AddMesh_Billboard (int &ivtx, int &iidx, double x0, double y0, double dx, double dy, int texx, int texy, int texw, int texh); void AddMesh_CenterMarker (int &ivtx, int &iidx); - bool AddMesh_Marker (int &ivtx, int &iidx, const Vector &dir, int markerid, double *xcnt=0, double *ycnt=0); - void AddMesh_DirectionMarker (int &ivtx, int &iidx, const Vector &dir, bool prograde=false, double *xcnt=0, double *ycnt=0); + bool AddMesh_Marker (int &ivtx, int &iidx, const VECTOR3 &dir, int markerid, double *xcnt=0, double *ycnt=0); + void AddMesh_DirectionMarker (int &ivtx, int &iidx, const VECTOR3 &dir, bool prograde=false, double *xcnt=0, double *ycnt=0); void AddMesh_Readout (int &ivtx, int &iidx, int side, const char *str, int label=0); void AddMesh_LadderBar (int &ivtx, int &iidx, double sina, double cosa, @@ -67,18 +67,18 @@ class HUD { int TexBltString (const char *str, int tgtx, int tgty); - bool GlobalToHUD (const Vector &dir, int &x, int &y) const; - bool GlobalToHUD (const Vector &dir, double &x, double &y) const; + bool GlobalToHUD (const VECTOR3 &dir, int &x, int &y) const; + bool GlobalToHUD (const VECTOR3 &dir, double &x, double &y) const; // maps a global direction into HUD pixel coordinates (also works for VC) // 'dir' must be unit length - bool GlobalDrawMarker (oapi::Sketchpad *skp, const Vector &dir, int style) const; + bool GlobalDrawMarker (oapi::Sketchpad *skp, const VECTOR3 &dir, int style) const; // draw a marker on the HUD pointing in global direction dir // return value indicates dir within sight // styles (can be combined with OR): // 1=rectangle, 2=circle, 4=cross - oapi::IVECTOR2 *OffscreenDirMarker (const Vector &dir) const; + oapi::IVECTOR2 *OffscreenDirMarker (const VECTOR3 &dir) const; // returns points to draw a triangle to point in the direction of global direction dir // from viewport centre. Used to indicate direction of offscreen markers @@ -88,7 +88,7 @@ class HUD { const Pane *pane; // pane instance oapi::GraphicsClient *gc; // client instance int colidx; // HUD colour index - Vector HUDofs; // HUD centre offset from observer point [pixel] + VECTOR3 HUDofs; // HUD centre offset from observer point [pixel] double ladder_width; // elevation ladder parameters double ladder_range; int HRES05, VRES05; // semi-dimensions @@ -101,7 +101,7 @@ class HUD { // virtual cockpit parameters bool bVC; // virtual cockpit flag - Vector VCcnt; // HUD centre in VC [(m,m,m)] + VECTOR3 VCcnt; // HUD centre in VC [(m,m,m)] double VCscale; // HUD semi-size in VC [m] HUDPAINTSPEC spec; // parameters required for painting the HUD (defined in Orbitersdk.h) diff --git a/Src/Orbiter/surfmgr2.cpp b/Src/Orbiter/surfmgr2.cpp index c1a49e8ea..20b137f29 100644 --- a/Src/Orbiter/surfmgr2.cpp +++ b/Src/Orbiter/surfmgr2.cpp @@ -487,7 +487,7 @@ void SurfTile::Render () bool has_shadows = false; bool has_lights = false; if (ltex || render_shadows) { - sdist = acos (dotp (smgr->prm.sdir, cnt)); + sdist = std::acos(dot(smgr->prm.sdir, cnt)); rad = rad0/(double)(2<mgr->Cbody(); - Vector campos = tmul(pl->GRot(), g_camera->GPos() - pl->GPos()); // camera pos in planet frame + VECTOR3 campos = tmul(pl->GRot(), g_camera->GPos() - pl->GPos()); // camera pos in planet frame for (i = 0; i < nrenderlabel; i++) { - Vector camlabelpos = campos-renderlabel[i]->pos; - if (dotp (renderlabel[i]->pos, camlabelpos) >= 0.0) { - double fontscale = 1e4/camlabelpos.length()*(13-min(tile->lvl,12)*1); + VECTOR3 camlabelpos = campos - renderlabel[i]->pos; + if (dot(renderlabel[i]->pos, camlabelpos) >= 0.0) { + double fontscale = 1e4 / len(camlabelpos) * (13 - min(tile->lvl, 12) * 1); int idx = max(0, min(3, (int)fontscale)); if (idx != *fontidx) { skp->SetFont(labelfont[idx]); @@ -230,7 +230,7 @@ void TileLabel::Render(oapi::Sketchpad *skp, oapi::Font **labelfont, int *fontid } scale = symscale[idx]; sp = mul(pl->GRot(), renderlabel[i]->pos) + pl->GPos() - g_camera->GPos(); - dir = sp.unit(); + dir = unit(sp); if (g_camera->Direction2Viewport(dir, x, y)) { active = false; // default for label types not listed in the legend diff --git a/Src/Orbiter/tilelabel.h b/Src/Orbiter/tilelabel.h index 71807155d..1f3225fab 100644 --- a/Src/Orbiter/tilelabel.h +++ b/Src/Orbiter/tilelabel.h @@ -20,7 +20,7 @@ class TileLabel { TLABEL() { labeltype = 0; label = 0; } ~TLABEL() { if(label) delete[] label; } double lat, lng, alt; - Vector pos; + VECTOR3 pos; char labeltype; char *label; }; diff --git a/Src/Orbiter/tilemgr2.cpp b/Src/Orbiter/tilemgr2.cpp index 4ca3c312d..405c9af64 100644 --- a/Src/Orbiter/tilemgr2.cpp +++ b/Src/Orbiter/tilemgr2.cpp @@ -117,17 +117,17 @@ bool Tile::InView (const MATRIX4 &transform) // returns the direction of the tile centre from the planet centre in local // planet coordinates -Vector Tile::Centre () const +VECTOR3 Tile::Centre () const { if (lvl >= 0) { int nlat = 1 << lvl; int nlng = 2 << lvl; double cntlat = Pi05 - Pi * ((double)ilat + 0.5) / (double)nlat, slat = sin(cntlat), clat = cos(cntlat); double cntlng = Pi2 * ((double)ilng + 0.5) / (double)nlng + Pi, slng = sin(cntlng), clng = cos(cntlng); - return Vector(clat*clng, slat, clat*slng); + return {clat * clng, slat, clat * slng}; } else { - return Vector(1.0, 0.0, 0.0); + return {1, 0, 0}; } } @@ -149,7 +149,7 @@ void Tile::Extents (double *latmin, double *latmax, double *lngmin, double *lngm // ----------------------------------------------------------------------- VBMESH *Tile::CreateMesh_quadpatch (int grdlat, int grdlng, INT16 *elev, double elev_scale, double globelev, - const TEXCRDRANGE2 *range, bool shift_origin, Vector *shift, double bb_excess) + const TEXCRDRANGE2 *range, bool shift_origin, VECTOR3 *shift, double bb_excess) { const float TEX2_MULTIPLIER = 4.0f; // was: 16.0f const float c1 = 1.0f, c2 = 0.0f; // -1.0f/512.0f; // assumes 256x256 texture patches @@ -164,7 +164,7 @@ VBMESH *Tile::CreateMesh_quadpatch (int grdlat, int grdlng, INT16 *elev, double double minlng = 0; double maxlng = Pi2/(double)nlng; double radius = (mgr->Cbody() ? mgr->Cbody()->Size() : 1.0); - Vector pos, tpos, nml; + VECTOR3 pos, tpos, nml; if (!range) range = &fullrange; float turange = range->tumax-range->tumin; float tvrange = range->tvmax-range->tvmin; @@ -182,12 +182,12 @@ VBMESH *Tile::CreateMesh_quadpatch (int grdlat, int grdlng, INT16 *elev, double double clng0 = cos(minlng), slng0 = sin(minlng); double clat1 = cos(maxlat), slat1 = sin(maxlat); double clng1 = cos(maxlng), slng1 = sin(maxlng); - Vector ex(clat0*clng1 - clat0*clng0, 0, clat0*slng1 - clat0*slng0); ex.unify(); - Vector ey(0.5*(clng0+clng1)*(clat1-clat0), slat1-slat0, 0.5*(slng0+slng1)*(clat1-clat0)); ey.unify(); - Vector ez(crossp (ey, ex)); + auto ex = unit(VECTOR3{clat0 * clng1 - clat0 * clng0, 0, clat0 * slng1 - clat0 * slng0}); + auto ey = unit(VECTOR3{0.5 * (clng0 + clng1) * (clat1 - clat0), slat1 - slat0, 0.5 * (slng0 + slng1) * (clat1 - clat0)}); + auto ez = cross(ey, ex); Matrix R(ex.x, ex.y, ex.z, ey.x, ey.y, ey.z, ez.x, ez.y, ez.z); - Vector pref (radius*clat0*0.5*(clng1+clng0), radius*slat0, radius*clat0*0.5*(slng1+slng0)); // origin - Vector tpmin, tpmax; + VECTOR3 pref{radius * clat0 * 0.5 * (clng1 + clng0), radius * slat0, radius * clat0 * 0.5 * (slng1 + slng0)}; // origin + VECTOR3 tpmin, tpmax; // patch translation vector if (shift_origin) { @@ -212,8 +212,8 @@ VBMESH *Tile::CreateMesh_quadpatch (int grdlat, int grdlng, INT16 *elev, double eradius = radius + globelev; // radius including node elevation if (elev) eradius += (double)elev[(i+1)*TILE_ELEVSTRIDE + j+1]*elev_scale; - nml.Set (clat*clng, slat, clat*slng); - pos.Set (nml*eradius); + nml = {clat * clng, slat, clat * slng}; + pos = nml * eradius; tpos = mul (R, pos-pref); if (!n) { tpmin = tpos; @@ -316,8 +316,10 @@ VBMESH *Tile::CreateMesh_quadpatch (int grdlat, int grdlng, INT16 *elev, double #ifdef QUICK_NORMALS // This version avoids the normalisation of the 4 intermediate face normals // It's faster and doesn't seem to make much difference - Vector nml(2.0*dydz, dz*elev_scale*(elev[en-TILE_ELEVSTRIDE]-elev[en+TILE_ELEVSTRIDE]), dy*elev_scale*(elev[en-1]-elev[en+1])); - nml.unify(); + auto nml = unit(VECTOR3{2.0 * dydz, + dz * elev_scale * (elev[en - TILE_ELEVSTRIDE] - elev[en + TILE_ELEVSTRIDE]), + dy * elev_scale * (elev[en - 1] - elev[en + 1]) + }); #else double dy_dezp = -dy*(elev[en+1]-elev[en]); double dy_dezm = dy*(elev[en-1]-elev[en]); @@ -370,14 +372,14 @@ VBMESH *Tile::CreateMesh_quadpatch (int grdlat, int grdlng, INT16 *elev, double pref.x -= dx; pref.y -= dy; mesh->bbvtx = new VECTOR4[8]; - mesh->bbvtx[0] = MakeVECTOR4 (tmul (R, Vector(tpmin.x, tpmin.y, tpmin.z)) + pref); - mesh->bbvtx[1] = MakeVECTOR4 (tmul (R, Vector(tpmax.x, tpmin.y, tpmin.z)) + pref); - mesh->bbvtx[2] = MakeVECTOR4 (tmul (R, Vector(tpmin.x, tpmax.y, tpmin.z)) + pref); - mesh->bbvtx[3] = MakeVECTOR4 (tmul (R, Vector(tpmax.x, tpmax.y, tpmin.z)) + pref); - mesh->bbvtx[4] = MakeVECTOR4 (tmul (R, Vector(tpmin.x, tpmin.y, tpmax.z)) + pref); - mesh->bbvtx[5] = MakeVECTOR4 (tmul (R, Vector(tpmax.x, tpmin.y, tpmax.z)) + pref); - mesh->bbvtx[6] = MakeVECTOR4 (tmul (R, Vector(tpmin.x, tpmax.y, tpmax.z)) + pref); - mesh->bbvtx[7] = MakeVECTOR4 (tmul (R, Vector(tpmax.x, tpmax.y, tpmax.z)) + pref); + mesh->bbvtx[0] = MakeVECTOR4(tmul(R, VECTOR3{tpmin.x, tpmin.y, tpmin.z}) + pref); + mesh->bbvtx[1] = MakeVECTOR4(tmul(R, VECTOR3{tpmax.x, tpmin.y, tpmin.z}) + pref); + mesh->bbvtx[2] = MakeVECTOR4(tmul(R, VECTOR3{tpmin.x, tpmax.y, tpmin.z}) + pref); + mesh->bbvtx[3] = MakeVECTOR4(tmul(R, VECTOR3{tpmax.x, tpmax.y, tpmin.z}) + pref); + mesh->bbvtx[4] = MakeVECTOR4(tmul(R, VECTOR3{tpmin.x, tpmin.y, tpmax.z}) + pref); + mesh->bbvtx[5] = MakeVECTOR4(tmul(R, VECTOR3{tpmax.x, tpmin.y, tpmax.z}) + pref); + mesh->bbvtx[6] = MakeVECTOR4(tmul(R, VECTOR3{tpmin.x, tpmax.y, tpmax.z}) + pref); + mesh->bbvtx[7] = MakeVECTOR4(tmul(R, VECTOR3{tpmax.x, tpmax.y, tpmax.z}) + pref); mesh->MapVertices (TileManager2Base::D3d(), TileManager2Base::Dev(), VB_MemFlag); // TODO return mesh; @@ -385,7 +387,7 @@ VBMESH *Tile::CreateMesh_quadpatch (int grdlat, int grdlng, INT16 *elev, double // ----------------------------------------------------------------------- -VBMESH *Tile::CreateMesh_tripatch (int grd, INT16 *elev, bool shift_origin, Vector *shift) +VBMESH *Tile::CreateMesh_tripatch (int grd, INT16 *elev, bool shift_origin, VECTOR3 *shift) { int nlng = 2 << lvl; int nlat = 1 << lvl; @@ -402,7 +404,7 @@ VBMESH *Tile::CreateMesh_tripatch (int grd, INT16 *elev, bool shift_origin, Vect double minlng = 0; double maxlng = Pi2/(double)nlng; double eradius, radius = mgr->cbody->Size(); - Vector pos, tpos, nml; + VECTOR3 pos, tpos, nml; int nvtx = (grd+1)*(grd+1) - ((grd+1)*grd)/2; int nvtxbuf = nvtx + (grd+1)*2; @@ -417,12 +419,12 @@ VBMESH *Tile::CreateMesh_tripatch (int grd, INT16 *elev, bool shift_origin, Vect double clng0 = cos(minlng), slng0 = sin(minlng); double clat1 = cos(maxlat), slat1 = sin(maxlat); double clng1 = cos(maxlng), slng1 = sin(maxlng); - Vector ex(clat0*clng1 - clat0*clng0, 0, clat0*slng1 - clat0*slng0); ex.unify(); - Vector ey(0.5*(clng0+clng1)*(clat1-clat0), slat1-slat0, 0.5*(slng0+slng1)*(clat1-clat0)); ey.unify(); - Vector ez(crossp (ey, ex)); + auto ex = unit(VECTOR3{clat0 * clng1 - clat0 * clng0, 0, clat0 * slng1 - clat0 * slng0}); + auto ey = unit(VECTOR3{0.5 * (clng0 + clng1) * (clat1 - clat0), slat1 - slat0, 0.5 * (slng0 + slng1) * (clat1 - clat0)}); + auto ez = cross(ey, ex); Matrix R(ex.x, ex.y, ex.z, ey.x, ey.y, ey.z, ez.x, ez.y, ez.z); - Vector pref (radius*clat0*0.5*(clng1+clng0), radius*slat0, radius*clat0*0.5*(slng1+slng0)); // origin - Vector tpmin, tpmax; + VECTOR3 pref{radius * clat0 * 0.5 * (clng1 + clng0), radius * slat0, radius * clat0 * 0.5 * (slng1 + slng0)}; // origin + VECTOR3 tpmin, tpmax; // patch translation vector if (shift_origin) { @@ -446,8 +448,8 @@ VBMESH *Tile::CreateMesh_tripatch (int grd, INT16 *elev, bool shift_origin, Vect lng = (nseg ? minlng + (maxlng-minlng) * (double)j/(double)nseg : 0.0); slng = sin(lng), clng = cos(lng); eradius = radius; // TODO: elevation - nml.Set (clat*clng, slat, clat*slng); - pos.Set (nml * eradius); + nml = {clat * clng, slat, clat * slng}; + pos = nml * eradius; tpos = mul (R, pos-pref); if (!n) { tpmin = tpos; @@ -528,14 +530,14 @@ VBMESH *Tile::CreateMesh_tripatch (int grd, INT16 *elev, bool shift_origin, Vect pref.x -= dx; pref.y -= dy; mesh->bbvtx = new VECTOR4[8]; - mesh->bbvtx[0] = MakeVECTOR4 (tmul (R, Vector(tpmin.x, tpmin.y, tpmin.z)) + pref); - mesh->bbvtx[1] = MakeVECTOR4 (tmul (R, Vector(tpmax.x, tpmin.y, tpmin.z)) + pref); - mesh->bbvtx[2] = MakeVECTOR4 (tmul (R, Vector(tpmin.x, tpmax.y, tpmin.z)) + pref); - mesh->bbvtx[3] = MakeVECTOR4 (tmul (R, Vector(tpmax.x, tpmax.y, tpmin.z)) + pref); - mesh->bbvtx[4] = MakeVECTOR4 (tmul (R, Vector(tpmin.x, tpmin.y, tpmax.z)) + pref); - mesh->bbvtx[5] = MakeVECTOR4 (tmul (R, Vector(tpmax.x, tpmin.y, tpmax.z)) + pref); - mesh->bbvtx[6] = MakeVECTOR4 (tmul (R, Vector(tpmin.x, tpmax.y, tpmax.z)) + pref); - mesh->bbvtx[7] = MakeVECTOR4 (tmul (R, Vector(tpmax.x, tpmax.y, tpmax.z)) + pref); + mesh->bbvtx[0] = MakeVECTOR4(tmul(R, VECTOR3{tpmin.x, tpmin.y, tpmin.z}) + pref); + mesh->bbvtx[1] = MakeVECTOR4(tmul(R, VECTOR3{tpmax.x, tpmin.y, tpmin.z}) + pref); + mesh->bbvtx[2] = MakeVECTOR4(tmul(R, VECTOR3{tpmin.x, tpmax.y, tpmin.z}) + pref); + mesh->bbvtx[3] = MakeVECTOR4(tmul(R, VECTOR3{tpmax.x, tpmax.y, tpmin.z}) + pref); + mesh->bbvtx[4] = MakeVECTOR4(tmul(R, VECTOR3{tpmin.x, tpmin.y, tpmax.z}) + pref); + mesh->bbvtx[5] = MakeVECTOR4(tmul(R, VECTOR3{tpmax.x, tpmin.y, tpmax.z}) + pref); + mesh->bbvtx[6] = MakeVECTOR4(tmul(R, VECTOR3{tpmin.x, tpmax.y, tpmax.z}) + pref); + mesh->bbvtx[7] = MakeVECTOR4(tmul(R, VECTOR3{tpmax.x, tpmax.y, tpmax.z}) + pref); mesh->MapVertices (TileManager2::d3d, TileManager2::dev, VB_MemFlag); return mesh; @@ -548,7 +550,7 @@ VBMESH *Tile::CreateMesh_hemisphere (int grd, INT16 *elev, double globelev) const int texres = 512; double radius = mgr->cbody->Size() + globelev; double eradius, slat, clat, slng, clng; - Vector pos, nml; + VECTOR3 pos, nml; // Allocate memory for the vertices and indices int nVtx = (grd-1)*(grd+1)+2; @@ -580,8 +582,8 @@ VBMESH *Tile::CreateMesh_hemisphere (int grd, INT16 *elev, double globelev) slng = sin(lng), clng = cos(lng); eradius = radius + globelev; // radius including node elevation if (elev) eradius += (double)elev[(grd+1-y)*TILE_ELEVSTRIDE + x+1]; - nml.Set (slat*clng, clat, slat*slng); - pos.Set (nml*eradius); + nml = {slat * clng, clat, slat * slng}; + pos = nml * eradius; vtx->x = D3DVAL(pos.x); vtx->nx = D3DVAL(nml.x); vtx->y = D3DVAL(pos.y); vtx->ny = D3DVAL(nml.y); vtx->z = D3DVAL(pos.z); vtx->nz = D3DVAL(nml.z); @@ -613,8 +615,8 @@ VBMESH *Tile::CreateMesh_hemisphere (int grd, INT16 *elev, double globelev) for (x = 0; x < x2; x++) mn += (double)elev[TILE_ELEVSTRIDE*(grd+1) + x+1]; eradius += mn/x2; } - nml.Set (0,1,0); - pos.Set (nml*eradius); + nml = {0, 1, 0}; + pos = nml * eradius; vtx->x = D3DVAL(pos.x); vtx->nx = D3DVAL(nml.x); vtx->y = D3DVAL(pos.y); vtx->ny = D3DVAL(nml.y); vtx->z = D3DVAL(pos.z); vtx->nz = D3DVAL(nml.z); @@ -631,8 +633,8 @@ VBMESH *Tile::CreateMesh_hemisphere (int grd, INT16 *elev, double globelev) for (x = 0; x < x2; x++) mn += (double)elev[TILE_ELEVSTRIDE + x+1]; eradius += mn/x2; } - nml.Set (0,-1,0); - pos.Set (nml*eradius); + nml = {0, -1, 0}; + pos = nml * eradius; vtx->x = D3DVAL(pos.x); vtx->nx = D3DVAL(nml.x); vtx->y = D3DVAL(pos.y); vtx->ny = D3DVAL(nml.y); vtx->z = D3DVAL(pos.z); vtx->nz = D3DVAL(nml.z); @@ -679,8 +681,10 @@ VBMESH *Tile::CreateMesh_hemisphere (int grd, INT16 *elev, double globelev) if (!ilng) lng -= Pi; slng = sin(lng), clng = cos(lng); en = (grd+1-y)*TILE_ELEVSTRIDE + x+1; - Vector nml(2.0*dydz, dz*(elev[en-TILE_ELEVSTRIDE]-elev[en+TILE_ELEVSTRIDE]), dy*(elev[en-1]-elev[en+1])); - nml.unify(); + auto nml = unit(VECTOR3{2.0 * dydz, + dz * (elev[en - TILE_ELEVSTRIDE] - elev[en + TILE_ELEVSTRIDE]), + dy * (elev[en - 1] - elev[en + 1]) + }); // rotate into place nx1 = nml.x*clat - nml.y*slat; ny1 = nml.x*slat + nml.y*clat; @@ -923,11 +927,11 @@ void TileManager2Base::SetRenderPrm (MATRIX4 &dwmat, double prerot, VPlanet *vbo prm.cdist = vbody->CDist() / cbody->Size(); // camera distance from planet centre in units of planet radius } else { - prm.cpos.Set(Vector(0, 0, 0)); + prm.cpos = {0, 0, 0}; prm.cdist = 0.0; } - prm.cdir.Set (tmul (prm.grot, -prm.cpos.unit())); // camera direction in local planet coords - prm.sdir.Set (tmul (prm.grot, -cbody->GPos().unit())); // sun direction in local planet coords + prm.cdir = tmul(prm.grot, -unit(prm.cpos)); // camera direction in local planet coords + prm.sdir = tmul(prm.grot, -unit(cbody->GPos())); // sun direction in local planet coords prm.viewap = acos (rprm.horizon_minrad/(max (prm.cdist, 1.0+minalt))); prm.scale = 1.0; prm.fog = rprm.bFog; diff --git a/Src/Orbiter/tilemgr2.h b/Src/Orbiter/tilemgr2.h index 161ca0de3..b9b07aff1 100644 --- a/Src/Orbiter/tilemgr2.h +++ b/Src/Orbiter/tilemgr2.h @@ -81,14 +81,14 @@ class Tile { virtual void Render () {} - Vector Centre () const; + VECTOR3 Centre () const; // Returns the direction of the tile centre from the planet centre in local planet coordinates VBMESH *CreateMesh_quadpatch (int grdlat, int grdlng, INT16 *elev=0, double elev_scale=1.0, double globelev=0.0, - const TEXCRDRANGE2 *range=0, bool shift_origin=false, Vector *shift=0, double bb_excess=0.0); + const TEXCRDRANGE2 *range=0, bool shift_origin=false, VECTOR3 *shift=0, double bb_excess=0.0); // Creates a quadrilateral patch mesh - VBMESH *CreateMesh_tripatch (int grd, INT16 *elev=0, bool shift_origin=false, Vector *shift=0); + VBMESH *CreateMesh_tripatch (int grd, INT16 *elev=0, bool shift_origin=false, VECTOR3 *shift=0); // Creates a triangular patch mesh for north or south pole VBMESH *CreateMesh_hemisphere (int grd, INT16 *elev=0, double globelev=0.0); @@ -102,8 +102,8 @@ class Tile { bool owntex; // true: tile owns the texture, false: tile uses ancestor subtexture TEXCRDRANGE2 texrange; // texture coordinate subrange (if using ancestor subtexture) VBMESH *mesh; // vertex-buffered tile mesh - Vector cnt; // tile centre in local planet coords - Vector vtxshift; + VECTOR3 cnt; // tile centre in local planet coords + VECTOR3 vtxshift; bool edgeok; // edges have been checked in this frame TileState state; // tile load/active/render state flags int lngnbr_lvl, latnbr_lvl, dianbr_lvl; // neighbour levels to which edges have been adapted @@ -161,9 +161,9 @@ class TileManager2Base { MATRIX4 dwmat_tmp; // modifyable planet world matrix, double precision MATRIX4 dviewproj; // view+projection matrix, double precision Matrix grot; // planet rotation matrix - Vector cpos; // planet offset vector (in global frame) - Vector cdir; // camera direction from planet centre (in planet frame) - Vector sdir; // sun direction in local planet coords + VECTOR3 cpos; // planet offset vector (in global frame) + VECTOR3 cdir; // camera direction from planet centre (in planet frame) + VECTOR3 sdir; // sun direction in local planet coords double cdist; // camera distance from planet centre (in units of planet radii) double viewap; // aperture of surface cap visible from camera pos double scale; @@ -171,7 +171,7 @@ class TileManager2Base { bool tint; // apply atmospheric tint? float shadowcol; // cloud shadow colour bool flatshadow; // render cloud shadows onto sphere? - Vector atm_tint; // atmospheric RGB surface tint at high atmosphere + VECTOR3 atm_tint; // atmospheric RGB surface tint at high atmosphere TileManager2 *cloudmgr; // cloud manager (for shadow projection); NULL if no clouds double cloudrot; // cloud layer rotation angle } prm; diff --git a/Src/Orbiter/tilemgr2_imp.hpp b/Src/Orbiter/tilemgr2_imp.hpp index 849e923f8..812ee7772 100644 --- a/Src/Orbiter/tilemgr2_imp.hpp +++ b/Src/Orbiter/tilemgr2_imp.hpp @@ -85,10 +85,10 @@ void TileManager2Base::ProcessNode (QuadTreeNode *node) } // check if patch is visible from camera position - Vector &cnt = tile->cnt; // tile centre in unit planet frame + VECTOR3 &cnt = tile->cnt; // tile centre in unit planet frame static const double rad0 = sqrt(2.0)*Pi05; double rad = rad0/(double)nlat; - double alpha = acos (dotp (prm.cdir, cnt)); // angle between tile centre and camera from planet centre + double alpha = std::acos(dot(prm.cdir, cnt)); // angle between tile centre and camera from planet centre double adist = alpha - rad; // angle between closest tile corner and camera if (adist >= prm.viewap) { if (lvl == 0) diff --git a/Src/Plugin/ScnEditor/Editor.cpp b/Src/Plugin/ScnEditor/Editor.cpp index 74a7f6bd3..88725d5a5 100644 --- a/Src/Plugin/ScnEditor/Editor.cpp +++ b/Src/Plugin/ScnEditor/Editor.cpp @@ -279,8 +279,8 @@ bool ScnEditor::CreateVessel (char *name, char *classname) if (!vs.rbody) vs.rbody = oapiGetGbodyByIndex (0); double rad = 1.1 * oapiGetSize (vs.rbody); double vel = sqrt (GGRAV * oapiGetMass (vs.rbody) / rad); - vs.rpos = _V(rad,0,0); - vs.rvel = _V(0,0,vel); + vs.rpos = {rad,0,0}; + vs.rvel = {0,0,vel}; // create the vessel OBJHANDLE newvessel = oapiCreateVesselEx (name, classname, &vs); if (!newvessel) return false; // failure @@ -2039,8 +2039,8 @@ void EditorTab_Statevec::Apply () needrefresh = true; } #endif - veccpy (vs.rpos, pos); - veccpy (vs.rvel, vel); + vs.rpos = pos; + vs.rvel = vel; vessel->DefSetState (&vs); if (needrefresh) Refresh(); } @@ -2236,7 +2236,7 @@ void EditorTab_Landed::Refresh (OBJHANDLE hV) oapiGetRelativePos (ed->hVessel, hRef, &pos); oapiGetRotationMatrix (hRef, &rot); pos = tmul (rot, pos); - VECTOR3 vel = _V(0,0,0); + VECTOR3 vel{0, 0, 0}; Crt2Pol (pos, vel); sprintf (lngstr, "%lf", pos.data[1] * DEG); sprintf (latstr, "%lf", pos.data[2] * DEG); diff --git a/Src/Plugin/TransX/BodyProvider.cpp b/Src/Plugin/TransX/BodyProvider.cpp index c6d397684..cbfe7fd7a 100644 --- a/Src/Plugin/TransX/BodyProvider.cpp +++ b/Src/Plugin/TransX/BodyProvider.cpp @@ -87,7 +87,7 @@ void BodyProvider::InitialiseSolarSystem() VECTOR3 pos; oapiGetRelativePos(body->bodyhandle, (*it)->bodyhandle, &pos); - double distance2 = dotp(pos, pos); + double distance2 = dot(pos, pos); if(distance2 < (*it)->soisize2) { currparent = *it; diff --git a/Src/Plugin/TransX/basefunction.cpp b/Src/Plugin/TransX/basefunction.cpp index c71c93448..d1ef5c37e 100644 --- a/Src/Plugin/TransX/basefunction.cpp +++ b/Src/Plugin/TransX/basefunction.cpp @@ -630,7 +630,7 @@ void basefunction::calculate(VECTOR3 *targetvel) VECTOR3 pos,vel; oapiGetRelativeVel(hcraft,hmajor,&vel); oapiGetRelativePos(hcraft,hmajor,&pos); - double distance=length(pos); + double distance = len(pos); double velenergy=length2my(vel)*0.5; double overallenergy=-GRAVITY*oapiGetMass(hmajor)/distance+velenergy; craft.init(hmajor, hcraft); @@ -928,14 +928,14 @@ void basefunction::doupdate(oapi::Sketchpad *sketchpad,int tw, int th,int viewmo //Describe targeting quality int hpos=8*linespacing; int wpos=0; - double closestApp = length(craftpos-targetpos); + double closestApp = len(craftpos-targetpos); TextShow(sketchpad, "Cl. App.: ", wpos, hpos, closestApp); hpos+=linespacing; TextShow(sketchpad, "Hohmann dv: ", wpos, hpos, GetHohmannDV()); hpos+=linespacing; VECTOR3 relvel; primary.getrelvel(&relvel); - TextShow(sketchpad,"Enc. V:", wpos, hpos, length(relvel)); + TextShow(sketchpad,"Enc. V:", wpos, hpos, len(relvel)); hpos+=linespacing; double intercepttime=primary.gettimeintercept(); double arrmjd=oapiTime2MJD(intercepttime); @@ -999,7 +999,7 @@ void basefunction::Getmode2hypo(VECTOR3 *targetvel) //basisorbit.timetovectors(difftime, &ejradius, &ejvel); VECTOR3 forward=unit(ejvel)*m_prograde; - VECTOR3 outward=unit(crossp(ejvel, basisorbit.getplanevector()))*m_outwardvel; + VECTOR3 outward = unit(cross(ejvel, basisorbit.getplanevector())) * m_outwardvel; VECTOR3 sideward=unit(basisorbit.getplanevector())*m_chplvel; VECTOR3 ejectvector=forward+outward+sideward; //=Eject vector in basisorbit frame @@ -1043,8 +1043,8 @@ double basefunction::GetHohmannDV() VECTOR3 posSrc, posTgt; oapiGetRelativePos(currentMinor, hmajor, &posSrc); oapiGetRelativePos(hmajtarget, hmajor, &posTgt); - double radSrc = length(posSrc); - double radTgt = length(posTgt); + double radSrc = len(posSrc); + double radTgt = len(posTgt); double dv = GetHohmannDVExtend(radSrc, radTgt, oapiGetMass(hmajor)); if (radTgt > radSrc) return dv; @@ -1057,18 +1057,16 @@ VECTOR3 basefunction::GetPlaneAxis(const OBJHANDLE hObj, const OBJHANDLE hRef) VECTOR3 pos, vel; oapiGetRelativePos(hObj, hRef, &pos); oapiGetRelativeVel(hObj, hRef, &vel); - const VECTOR3& axis = crossp(pos, vel); - return axis; + return cross(pos, vel); } VECTOR3 basefunction::GetLineOfNodes() { OBJHANDLE currentMinor = hminor ? hminor : oapiGetFocusObject(); // Eject or Manoeuvre? - if (!currentMinor || !hmajor || !hmajtarget) - return _V(0,0,0); - const VECTOR3 & planeMinor = GetPlaneAxis(currentMinor, hmajor); - const VECTOR3 & planeMajor = GetPlaneAxis(hmajtarget, hmajor); - const VECTOR3 & lineOfNodes = crossp(planeMinor, planeMajor); - return lineOfNodes; + if (!currentMinor || !hmajor || !hmajtarget) return {0, 0, 0}; + + auto planeMinor = GetPlaneAxis(currentMinor, hmajor); + auto planeMajor = GetPlaneAxis(hmajtarget, hmajor); + return cross(planeMinor, planeMajor); } diff --git a/Src/Plugin/TransX/globals.cpp b/Src/Plugin/TransX/globals.cpp index 6798b2759..ad01df227 100644 --- a/Src/Plugin/TransX/globals.cpp +++ b/Src/Plugin/TransX/globals.cpp @@ -215,7 +215,7 @@ double length2my(const VECTOR3 &v) double cosangle(const VECTOR3 &veca,const VECTOR3 &vecb) { - return dotp(veca,vecb)/sqrt(length2my(veca)*length2my(vecb)); + return dot(veca, vecb) / sqrt(length2my(veca) * length2my(vecb)); } void getinvrotmatrix(VECTOR3 arot, MATRIX3 *invrotmatrix)//arot not really a vector - see arot defn from vessel struct diff --git a/Src/Plugin/TransX/graph.cpp b/Src/Plugin/TransX/graph.cpp index 178800a3c..3711bbe9f 100644 --- a/Src/Plugin/TransX/graph.cpp +++ b/Src/Plugin/TransX/graph.cpp @@ -114,8 +114,8 @@ void Graph::setprojection(const VECTOR3 &projection) { VECTOR3 temp={0,-1,0}; // Ecliptic vector zaxis=unit(projection); - VECTOR3 cross=unit(crossp(temp, zaxis)); // Vector of LAN x+z only - VECTOR3 xcross=crossp(cross, zaxis); //90 around - max out of plane + VECTOR3 cross = unit(::cross(temp, zaxis)); // Vector of LAN x+z only + VECTOR3 xcross = ::cross(cross, zaxis); // 90 around - max out of plane xaxis=cross*cross.x+xcross*cross.z; // Back around the orbit yaxis=xcross*cross.x-cross*cross.z; } @@ -136,14 +136,14 @@ void Graph::drawtwovector(oapi::Sketchpad *sketchpad, const VECTOR3 &line1, cons xpos=int(xoffset); ypos=int(yoffset); sketchpad->MoveTo(xpos, ypos); - xpos=int(dotp(xaxis, line1)*scale+xoffset); - ypos=int(dotp(yaxis, line1)*scale+yoffset); + xpos = int(dot(xaxis, line1) * scale + xoffset); + ypos = int(dot(yaxis, line1) * scale + yoffset); sketchpad->LineTo(xpos, ypos); xpos=int(xoffset); ypos=int(yoffset); sketchpad->MoveTo(xpos, ypos); - xpos=int(dotp(xaxis, line2)*scale+xoffset); - ypos=int(dotp(yaxis, line2)*scale+yoffset); + xpos = int(dot(xaxis, line2) * scale + xoffset); + ypos = int(dot(yaxis, line2) * scale + yoffset); sketchpad->LineTo(xpos, ypos); } @@ -156,8 +156,8 @@ void Graph::drawvector(oapi::Sketchpad *sketchpad,const VECTOR3 &line1) xpos=int(xoffset); ypos=int(yoffset); sketchpad->MoveTo(xpos, ypos); - xpos=int(dotp(xaxis, line1)*scale+xoffset); - ypos=int(dotp(yaxis, line1)*scale+yoffset); + xpos = int(dot(xaxis, line1) * scale + xoffset); + ypos = int(dot(yaxis, line1) * scale + yoffset); sketchpad->LineTo(xpos, ypos); } @@ -169,8 +169,8 @@ void Graph::drawvectorline(oapi::Sketchpad *sketchpad, const VECTOR3 &line) const double yoffset=(iystart+iyend)*0.5; int xpos, ypos; VECTOR3 temp=unit(line)*(windowsize/2); - double xline=dotp(xaxis, temp); - double yline=dotp(yaxis, temp); + double xline = dot(xaxis, temp); + double yline = dot(yaxis, temp); xpos=int(xoffset-xline); ypos=int(yoffset-yline); sketchpad->MoveTo(xpos, ypos); @@ -285,7 +285,7 @@ double Graph::vectorpointdisplay(oapi::Sketchpad *sketchpad, const VECTOR3 &targ sketchpad->LineTo(xpos + crossSize, ypos + crossSize); sketchpad->MoveTo(xpos - crossSize, ypos + crossSize); sketchpad->LineTo(xpos + crossSize, ypos - crossSize); - return length(trtarget); + return len(trtarget); } void Graph::drawmarker(oapi::Sketchpad *sketchpad, const VECTOR3 & location, Shape shape) @@ -294,8 +294,8 @@ void Graph::drawmarker(oapi::Sketchpad *sketchpad, const VECTOR3 & location, Sha int y = (iystart + iyend) / 2; const int radius = 3; - double xpos = dotp(xaxis, location) * scale; - double ypos = dotp(yaxis, location) * scale; + double xpos = dot(xaxis, location) * scale; + double ypos = dot(yaxis, location) * scale; int left = (int)(x + xpos - radius + 0.5); // add 0.5 to round off rather than floor int right = (int)(x + xpos + radius + 0.5); int top = (int)(y + ypos - radius + 0.5); diff --git a/Src/Plugin/TransX/intercept.cpp b/Src/Plugin/TransX/intercept.cpp index c98f678ce..d00e14b6e 100644 --- a/Src/Plugin/TransX/intercept.cpp +++ b/Src/Plugin/TransX/intercept.cpp @@ -138,7 +138,7 @@ void Intercept::improveinterceptstraightline(const OrbitElements &craft, const O //Now use dotp to estimate remaining course correction VECTOR3 relcraftpos=icraftpos-itargetpos; VECTOR3 relcraftvel=icraftvel-itargetvel; - double timecorrection=-dotp(relcraftpos,relcraftvel)/dotp(relcraftvel,relcraftvel); + double timecorrection = -dot(relcraftpos, relcraftvel) / dot(relcraftvel, relcraftvel); if (timecorrection*lasttimecorrection<0 && fabs(timecorrection/orbittime)>0.0001) {//Oscillatory gain=gain*0.5; @@ -158,7 +158,7 @@ void Intercept::improveinterceptstraightline(const OrbitElements &craft, const O icepttimeoffset=crafttimeest+timecorrection*gain; itimeintercept=icepttimeoffset+target.gettimestamp(); - if (length(relcraftpos)*3>length(icraftpos))//Allows method to switch back if solution is no longer good + if (len(relcraftpos) * 3 > len(icraftpos)) //Allows method to switch back if solution is no longer good { iceptmethod=1; } @@ -178,7 +178,7 @@ void Intercept::updateintercept(const OrbitElements &craft, const OrbitElements { if (!craft.isvalid() || !target.isvalid()) return;//Ensure no void updates! double timeoffset=craft.gettimestamp()-target.gettimestamp(); - iplanecept=crossp(craft.getplanevector(),target.getplanevector()); + iplanecept = cross(craft.getplanevector(), target.getplanevector()); if (iceptmethod==2) { improveinterceptstraightline(craft,target); @@ -268,7 +268,7 @@ void Intercept::updateintercept(const OrbitElements &craft, const OrbitElements if (abetter) { //a is better - iceptradius=(length(betaposa)+iceptradius)/2;// Takes average of new and old as this converges better + iceptradius = (len(betaposa) + iceptradius) / 2;// Takes average of new and old as this converges better itimeintercept=timea; if (length2my(betaposa-alphaposa)*9gravbodyratio2); + radius = sqrt(dot(vecradius, vecradius) * body->gravbodyratio2); } return radius; } diff --git a/Src/Plugin/TransX/orbitelements.cpp b/Src/Plugin/TransX/orbitelements.cpp index 62eb53bb5..d983680cf 100644 --- a/Src/Plugin/TransX/orbitelements.cpp +++ b/Src/Plugin/TransX/orbitelements.cpp @@ -131,9 +131,9 @@ void OrbitElements::majortominorinit(OBJHANDLE target, OBJHANDLE object, const I closestapproach.getrelvel(&minorvel); //First use dotp to get to closest approach exactly - double minorvelsize=length(minorvel); - double firsttime=dotp(minorpos,minorvel)/(minorvelsize*minorvelsize);//Small correction - not the problem, though - minorpos=minorpos-minorvel*(dotp(minorpos,minorvel)/minorvelsize); + double minorvelsize = len(minorvel); + double firsttime = dot(minorpos, minorvel) / (minorvelsize * minorvelsize); //Small correction - not the problem, though + minorpos=minorpos - minorvel * (dot(minorpos, minorvel) / minorvelsize); //Now precisely at closest approach //Now use pythagoras to find required length back to 10xSOI double backradius=100*soisize*soisize; @@ -144,7 +144,7 @@ void OrbitElements::majortominorinit(OBJHANDLE target, OBJHANDLE object, const I oapiGetRelativePos(object, target,&currvector); double actdistance2=length2my(currvector); if (actdistance2 0 ? sqrt(backradius) : 0; double timeoffset=backradius/minorvelsize-firsttime; @@ -175,7 +175,7 @@ void OrbitElements::radiustovectors(double radius, bool outward, VECTOR3 *positi if (!outward) sinthi=-sinthi; *position=majoraxis*(radius*costhi)+minoraxis*(radius*sinthi); VECTOR3 outvector=unit(*position); - VECTOR3 roundvector=unit(crossp(planevector, outvector)); + VECTOR3 roundvector=unit(cross(planevector, outvector)); double rndvel2=angularmomentum2/(radius*radius); double outvel=eccentricity*planet*sinthi/sqrt(angularmomentum2); *velocity=outvector*outvel+roundvector*sqrt(rndvel2); @@ -254,23 +254,23 @@ void OrbitElements::init(const VECTOR3 &rposition, const VECTOR3 &rvelocity, dou void OrbitElements::init(const VECTOR3 &rposition, const VECTOR3 &rvelocity, double ttimestamp, double gmplanet) { VECTOR3 *ptr = const_cast(&rvelocity); - if(length(rvelocity) < 0.00000001) + if(len(rvelocity) < 0.00000001) ptr->x = 0.00000000001; // If it is zero, it causes problems, so make it very small. valid=true; - planevector=crossp(rposition,rvelocity); - angularmomentum2=dotp(planevector, planevector); //Angular momentum squared (don't usually need it non-squared) + planevector = cross(rposition, rvelocity); + angularmomentum2 = dot(planevector, planevector); //Angular momentum squared (don't usually need it non-squared) - double rvel2=dotp(rvelocity, rvelocity); - double radius=length(rposition); + double rvel2 = dot(rvelocity, rvelocity); + double radius = len(rposition); if (radius != 0) { - eccvector=(rposition*(rvel2-gmplanet/radius)-rvelocity*dotp(rposition, rvelocity))*(1/gmplanet); //Eccentricity vector + eccvector = (rposition * (rvel2 - gmplanet / radius) - rvelocity * dot(rposition, rvelocity)) * (1/gmplanet); //Eccentricity vector semimajor=gmplanet/(rvel2-2*gmplanet/radius); //Length of semimajor axis - is NEGATIVE if orbit is elliptical, POSITIVE if hyperbolic - eccentricity=length(eccvector); //Eccentricity of orbit + eccentricity = len(eccvector); //Eccentricity of orbit majoraxis=unit(eccvector); //Vector towards Periapsis - minoraxis=unit(crossp(planevector, majoraxis)); // Vector parallel to Minor axis of orbit - important for extracting vectors later - currcosthi=dotp(rposition, majoraxis)/radius; //cos thi is angle from periapsis, as measured from planet centre - currsinthi=dotp(rposition, minoraxis)/radius; + minoraxis = unit(cross(planevector, majoraxis)); // Vector parallel to Minor axis of orbit - important for extracting vectors later + currcosthi = dot(rposition, majoraxis) / radius; //cos thi is angle from periapsis, as measured from planet centre + currsinthi = dot(rposition, minoraxis) / radius; currposition=rposition; currvelocity=rvelocity; planet=gmplanet; @@ -518,8 +518,8 @@ double OrbitElements::GetTimeToThi(double costhi, double sinthi,int fullorbits,i void OrbitElements::vectortothi(const VECTOR3 &vector,double *costhi,double *sinthi) const { - double majorsize=dotp(vector,majoraxis); - double minorsize=dotp(vector,minoraxis); + double majorsize = dot(vector, majoraxis); + double minorsize = dot(vector, minoraxis); double scaling=sqrt(majorsize*majorsize+minorsize*minorsize); *costhi=majorsize/scaling; *sinthi=minorsize/scaling; @@ -553,12 +553,12 @@ double OrbitElements::getapodistance() const double OrbitElements::getcurrradius() const { - return length(currposition); + return len(currposition); } VECTOR3 OrbitElements::getintersectvector(const OrbitElements &torbit) const { - return crossp(planevector, torbit.planevector); + return cross(planevector, torbit.planevector); } double OrbitElements::geteccentricity() const @@ -741,8 +741,8 @@ void OrbitElements::draworbit(oapi::Sketchpad *sketchpad, const Graph *graph, bo { ct=0; currvector=majoraxis*(topconstant/(eccentricity+1)); - xposd= dotp(xaxis, currvector)*scale +xoffset; - yposd= dotp(yaxis, currvector)*scale +yoffset; + xposd = dot(xaxis, currvector) * scale + xoffset; + yposd = dot(yaxis, currvector) * scale + yoffset; if (xposdxend || yposdxend) return; // Makes safe if orbit too large to fit screen! xpos=int(xposd); ypos=int(yposd); @@ -764,8 +764,8 @@ void OrbitElements::draworbit(oapi::Sketchpad *sketchpad, const Graph *graph, bo } currentradius=topconstant/currdivisor; currvector=majoraxis*(currcos*currentradius)+minoraxis*(currentradius*currsin); - xposd=dotp(xaxis,currvector)*scale+xoffset; - yposd=dotp(yaxis,currvector)*scale+yoffset; + xposd = dot(xaxis, currvector) * scale + xoffset; + yposd = dot(yaxis, currvector) * scale + yoffset; // Following four if statements ensure proper truncation of line segments attempting to draw // beyond the boundaries of the MFD if (xposdMoveTo(xpos, ypos); currvector=currposition; - xpos= int(dotp(xaxis, currvector)*scale +xoffset); - ypos= int(dotp(yaxis, currvector)*scale +yoffset); + xpos = int(dot(xaxis, currvector) * scale + xoffset); + ypos = int(dot(yaxis, currvector) * scale + yoffset); sketchpad->LineTo(xpos, ypos); } } diff --git a/Src/Plugin/TransX/planfunction.cpp b/Src/Plugin/TransX/planfunction.cpp index d717c288a..0518b0741 100644 --- a/Src/Plugin/TransX/planfunction.cpp +++ b/Src/Plugin/TransX/planfunction.cpp @@ -127,7 +127,7 @@ void slingshot::calculate(class MFDvarhandler *vars,basefunction *base) return; } if (!craft.isvalid()) return; - inwardvelocity=length(inward); + inwardvelocity = len(inward); if (ejectvelocity2<1 || inwardvelocity<1) return; //We now have both vectors @@ -166,7 +166,7 @@ void slingshot::calculate(class MFDvarhandler *vars,basefunction *base) //set up coordinate system ratiotoradius=periapsisguess/oapiGetSize(hmajor); VECTOR3 asvel=inward*(1/inwardvelocity); - VECTOR3 rightangletovel=unit(asvel*dotp(asvel,ejectvector)-ejectvector); + VECTOR3 rightangletovel = unit(asvel * dot(asvel, ejectvector) - ejectvector); double cosfirst=sqrt(1-sinfirst*sinfirst); VECTOR3 peposition=(rightangletovel*cosfirst+asvel*sinfirst)*periapsisguess; VECTOR3 pevel=rightangletovel*(-sinfirst)+asvel*cosfirst; @@ -198,7 +198,7 @@ void minorejectplan::graphscale(Graph *graph) svelocity=unit(svelocity); //unit to give vector parallel to rotation oapiGetFocusRelativePos(hmajor,&craftpos); VECTOR3 tradius=unit(craftpos);//Get unit radius vector - VECTOR3 tvector=unit(crossp(tradius, svelocity)); + VECTOR3 tvector=unit(cross(tradius, svelocity)); double longitude, latitude, tnumber; oapiGetFocusEquPos(&longitude, &latitude, &tnumber);//Only works if current planet's surface dominates double cosl=cos(-latitude); @@ -247,9 +247,9 @@ bool slingshot::maingraph(oapi::Sketchpad *sketchpad,Graph *graph,basefunction * graph->setviewscalesize(planetsize); VECTOR3 planpos,craftpos,velvector; planorbit.thitovectors(1,0,&planpos,&velvector); - graph->setviewscalesize(length(planpos)); + graph->setviewscalesize(len(planpos)); craft.thitovectors(1,0,&craftpos,&velvector); - graph->setviewscalesize(length(craftpos)); + graph->setviewscalesize(len(craftpos)); craft.getinfinityvelvector(false,&velvector);//Now finally set for real graph->setprojection(velvector); @@ -344,7 +344,7 @@ void minorejectplan::wordupdate(oapi::Sketchpad *sketchpad, int width, int heigh pos += linespacing; // Get the target LAN (absolute wrt global coordinates) - VECTOR3 LAN = crossp(planorbit.getplanevector(), down); + VECTOR3 LAN = cross(planorbit.getplanevector(), down); double lan = atan2(LAN.z, LAN.x) * 180 / PI; if(lan < 0) lan += 360; @@ -356,7 +356,7 @@ void minorejectplan::wordupdate(oapi::Sketchpad *sketchpad, int width, int heigh { //Vessel is landed! VECTOR3 tintersectvector=planorbit.getintersectvector(craft);//Gets intersection vector tpos=status.rpos; - if (dotp(tintersectvector,tpos)<0) + if (dot(tintersectvector, tpos) < 0) angle+=90; else angle=90-angle; @@ -379,8 +379,8 @@ void minorejectplan::wordupdate(oapi::Sketchpad *sketchpad, int width, int heigh // Calculate Delta-v if (status.rbody!=base->gethmajor()) return; //if (craft.getpedistance()GetTimeIntercept() - m_ejdate; TextShow(sketchpad,"TOF (days):",wpos,22*linespacing,numDays); - double totaldv=length(ejectvector); + double totaldv = len(ejectvector); if (totaldv>0.1) { //bottom right, watch both glass cockpit AND panel view for correct placement. @@ -644,7 +644,7 @@ bool majorejectplan::init(class MFDvarhandler *vars, class basefunction *base) void majorejectplan::calcejectvector(const VECTOR3 &rminplane,const VECTOR3 &minorvel, double inheritedvelocity) {//Final param not used here VECTOR3 forward=unit(minorvel)*m_prograde; - VECTOR3 outward=unit(crossp(minorvel, rminplane))*m_outwardvel; + VECTOR3 outward=unit(cross(minorvel, rminplane))*m_outwardvel; VECTOR3 sideward=unit(rminplane)*m_chplvel; ejectvector=forward+outward+sideward; //=Eject vector in RMin frame } @@ -652,7 +652,7 @@ void majorejectplan::calcejectvector(const VECTOR3 &rminplane,const VECTOR3 &min void slingejectplan::calcejectvector(const VECTOR3 &rminplane,const VECTOR3 &minorvel, double inheritedvelocity) { VECTOR3 forward=unit(minorvel)*m_outwardangle.getcos()*m_incangle.getcos(); - VECTOR3 outward=unit(crossp(minorvel,rminplane))*m_outwardangle.getsin()*m_incangle.getcos(); + VECTOR3 outward=unit(cross(minorvel,rminplane))*m_outwardangle.getsin()*m_incangle.getcos(); VECTOR3 sideward=unit(rminplane)*m_incangle.getsin(); ejectvector=forward+outward+sideward; if (m_inheritvel==0 && inheritedvelocity>0) @@ -762,7 +762,7 @@ void minorejectplan::calculate(class MFDvarhandler *vars,basefunction *base) { ejectvector=nextplan->getvelocityvector(); ejecttime=nextplan->geteventtime(); - ejectvelocity2=dotp(ejectvector,ejectvector); + ejectvelocity2 = dot(ejectvector, ejectvector); } } else @@ -778,8 +778,8 @@ void minorejectplan::calculate(class MFDvarhandler *vars,basefunction *base) //Set up temporary coordinate system VECTOR3 rminplane=(base->getcontextorbit()).getplanevector(); VECTOR3 txaxis=unit(ejectvector); - VECTOR3 tzaxis=unit(crossp(ejectvector, rminplane)); - VECTOR3 tyaxis=unit(crossp(ejectvector, tzaxis)); + VECTOR3 tzaxis=unit(cross(ejectvector, rminplane)); + VECTOR3 tyaxis=unit(cross(ejectvector, tzaxis)); double ejorientsinvalue = m_ejorient.getsin(); double ejorientcosvalue = m_ejorient.getcos(); VECTOR3 tnaxis=tzaxis*ejorientcosvalue+tyaxis*ejorientsinvalue; diff --git a/Src/Vessel/Atlantis/Atlantis/AscentAP.cpp b/Src/Vessel/Atlantis/Atlantis/AscentAP.cpp index 876436301..a8aa83f71 100644 --- a/Src/Vessel/Atlantis/Atlantis/AscentAP.cpp +++ b/Src/Vessel/Atlantis/Atlantis/AscentAP.cpp @@ -275,22 +275,22 @@ void AscentAP::SetLaunchAzimuth (double azimuth) oapiGlobalToLocal (hRef, &pos, &equ); oapiLocalToEqu (hRef, equ, &lng, &lat, &rad); slng = sin(lng), clng = cos(lng), slat = sin(lat), clat = cos(lat); - normalise(equ); // unit radius vector + equ = unit(equ); // unit radius vector // launch direction in local planet frame - dir = _V(-clng*slat*caz - slng*saz, clat*caz, -slng*slat*caz + clng*saz); + dir = {-clng*slat*caz - slng*saz, clat*caz, -slng*slat*caz + clng*saz}; // normal of orbital plane in local planet frame - nml = crossp(dir, equ); + nml = cross(dir, equ); // normal of equator plane in local planet frame - ne = _V(0,1,0); + ne = {0,1,0}; // direction of ascending node - nd = unit (crossp(nml, ne)); + nd = unit(cross(nml, ne)); // orbit inclination - tgt.inc = acos(dotp(nml, ne)); + tgt.inc = std::acos(dot(nml, ne)); // longitude of ascending node tgt.lan = atan2(nd.z, nd.x); @@ -315,10 +315,10 @@ double AscentAP::CalcTargetAzimuth () const oapiGetRotationMatrix (hRef, &pR); vessel->GetGlobalPos(pos); oapiGlobalToLocal (hRef, &pos, &equ); // vessel position in planet frame - normalise(equ); + equ = unit(equ); ep = tmul(tgt.R,equ); // rotate to equator plane double elng = atan2(ep.z, ep.x); // longitude of rotated position - dir = _V(-sin(elng),0,cos(elng)); // rotated target direction + dir = {-sin(elng),0,cos(elng)}; // rotated target direction dir = mul(tgt.R,dir); // target direction in planet frame dir = mul(pR, dir); // target direction in global frame vessel->GetRotationMatrix (vR); @@ -402,7 +402,7 @@ void AscentAP::GetTargetDirection (double met, VECTOR3 &dir, double &tgt_hdg) co double tgt_pitch = tgt.pitch; double xz = cos(tgt_pitch); - vessel->HorizonInvRot(_V(xz*sin(tgt_hdg), sin(tgt_pitch), xz*cos(tgt_hdg)), dir); + vessel->HorizonInvRot({xz*sin(tgt_hdg), sin(tgt_pitch), xz*cos(tgt_hdg)}, dir); } // -------------------------------------------------------------- @@ -482,7 +482,7 @@ double AscentAP::GetTargetRollRate (double tgt, bool tgt_is_heading) const double dh, droll = avel.z; if (tgt_is_heading) { - vessel->HorizonRot (_V(0,1,0), yh); + vessel->HorizonRot ({0,1,0}, yh); double yhdg = atan2(yh.x, yh.z); dh = yhdg-tgt; if (dh > PI) dh -= PI2; diff --git a/Src/Vessel/Atlantis/Atlantis/Atlantis.cpp b/Src/Vessel/Atlantis/Atlantis/Atlantis.cpp index 46a94a8cb..595afb44c 100644 --- a/Src/Vessel/Atlantis/Atlantis/Atlantis.cpp +++ b/Src/Vessel/Atlantis/Atlantis/Atlantis.cpp @@ -86,7 +86,7 @@ Atlantis::Atlantis (OBJHANDLE hObj, int fmodel) engine_light_level = 0.0; COLOUR4 col_diff = {1,0.8,0.8,0}; COLOUR4 col_zero = {0,0,0,0}; - engine_light = AddPointLight (_V(0,0,-25), 300, 2e-4, 0, 4e-4, col_diff, col_zero, col_zero); + engine_light = AddPointLight ({0,0,-25}, 300, 2e-4, 0, 4e-4, col_diff, col_zero, col_zero); engine_light->SetIntensityRef (&engine_light_level); LoadMeshes(); @@ -111,19 +111,19 @@ Atlantis::Atlantis (OBJHANDLE hObj, int fmodel) // Aerodynamics CreateAirfoils(); - CreateDock (ORBITER_DOCKPOS, _V(0,1,0), _V(0,0,-1)); - hDockET = CreateDock (_V(0.0,-2.48, 8.615), _V(0,-1,0), _V(0,0,1)); + CreateDock (ORBITER_DOCKPOS, {0,1,0}, {0,0,-1}); + hDockET = CreateDock ({0.0,-2.48, 8.615}, {0,-1,0}, {0,0,1}); pET = NULL; // ET reference center_arm = false; arm_moved = arm_scheduled = false; bManualSeparate = false; - ofs_sts_sat = _V(0,0,0); + ofs_sts_sat = {0,0,0}; do_eva = false; do_plat = false; do_cargostatic = false; vis = NULL; - cargo_static_ofs =_V(0,0,0); + cargo_static_ofs ={0,0,0}; // default arm status: stowed arm_sy = 0.5; @@ -132,11 +132,11 @@ Atlantis::Atlantis (OBJHANDLE hObj, int fmodel) arm_wp = 0.5; arm_wy = 0.5; arm_wr = 0.5; - arm_tip[0] = _V(-2.26,1.71,-6.5); - arm_tip[1] = _V(-2.26,1.71,-7.5); - arm_tip[2] = _V(-2.26,2.71,-6.5); + arm_tip[0] = {-2.26,1.71,-6.5}; + arm_tip[1] = {-2.26,1.71,-7.5}; + arm_tip[2] = {-2.26,2.71,-6.5}; - sat_attach = CreateAttachment (false, ofs_sts_sat, _V(0,1,0), _V(0,0,1), "X"); + sat_attach = CreateAttachment (false, ofs_sts_sat, {0,1,0}, {0,0,1}, "X"); rms_attach = CreateAttachment (false, arm_tip[0], arm_tip[1]-arm_tip[0], arm_tip[2]-arm_tip[0], "G", true); // Entry particle stream @@ -234,105 +234,105 @@ void Atlantis::CreateRCS() // set of attitude thrusters (idealised). The arrangement is such that no angular // momentum is created in linear mode, and no linear momentum is created in rotational mode. THRUSTER_HANDLE th_att_rot[4], th_att_lin[4]; - th_att_rot[0] = th_att_lin[0] = CreateThruster (_V(0,0, 15.5), _V(0, 1,0), ORBITER_RCS_THRUST, NULL, ORBITER_RCS_ISP0, ORBITER_RCS_ISP1); - th_att_rot[1] = th_att_lin[3] = CreateThruster (_V(0,0,-15.5), _V(0,-1,0), ORBITER_RCS_THRUST, NULL, ORBITER_RCS_ISP0, ORBITER_RCS_ISP1); - th_att_rot[2] = th_att_lin[2] = CreateThruster (_V(0,0, 15.5), _V(0,-1,0), ORBITER_RCS_THRUST, NULL, ORBITER_RCS_ISP0, ORBITER_RCS_ISP1); - th_att_rot[3] = th_att_lin[1] = CreateThruster (_V(0,0,-15.5), _V(0, 1,0), ORBITER_RCS_THRUST, NULL, ORBITER_RCS_ISP0, ORBITER_RCS_ISP1); + th_att_rot[0] = th_att_lin[0] = CreateThruster ({0,0, 15.5}, {0, 1,0}, ORBITER_RCS_THRUST, NULL, ORBITER_RCS_ISP0, ORBITER_RCS_ISP1); + th_att_rot[1] = th_att_lin[3] = CreateThruster ({0,0,-15.5}, {0,-1,0}, ORBITER_RCS_THRUST, NULL, ORBITER_RCS_ISP0, ORBITER_RCS_ISP1); + th_att_rot[2] = th_att_lin[2] = CreateThruster ({0,0, 15.5}, {0,-1,0}, ORBITER_RCS_THRUST, NULL, ORBITER_RCS_ISP0, ORBITER_RCS_ISP1); + th_att_rot[3] = th_att_lin[1] = CreateThruster ({0,0,-15.5}, {0, 1,0}, ORBITER_RCS_THRUST, NULL, ORBITER_RCS_ISP0, ORBITER_RCS_ISP1); CreateThrusterGroup (th_att_rot, 2, THGROUP_ATT_PITCHUP); CreateThrusterGroup (th_att_rot+2, 2, THGROUP_ATT_PITCHDOWN); CreateThrusterGroup (th_att_lin, 2, THGROUP_ATT_UP); CreateThrusterGroup (th_att_lin+2, 2, THGROUP_ATT_DOWN); - AddExhaust (th_att_rot[0], eh, ew1, _V( 1.60,-0.20, 18.78), _V( 0.4339,-0.8830,-0.1793), tex_rcs);//F2D - AddExhaust (th_att_rot[0], eh, ew1, _V( 1.68,-0.18, 18.40), _V( 0.4339,-0.8830,-0.1793), tex_rcs);//F4D - AddExhaust (th_att_rot[0], eh, ew1, _V(-1.55,-0.20, 18.78), _V(-0.4339,-0.8830,-0.1793), tex_rcs);//F1D - AddExhaust (th_att_rot[0], eh, ew1, _V(-1.63,-0.18, 18.40), _V(-0.4339,-0.8830,-0.1793), tex_rcs);//F3D + AddExhaust (th_att_rot[0], eh, ew1, { 1.60,-0.20, 18.78}, { 0.4339,-0.8830,-0.1793}, tex_rcs);//F2D + AddExhaust (th_att_rot[0], eh, ew1, { 1.68,-0.18, 18.40}, { 0.4339,-0.8830,-0.1793}, tex_rcs);//F4D + AddExhaust (th_att_rot[0], eh, ew1, {-1.55,-0.20, 18.78}, {-0.4339,-0.8830,-0.1793}, tex_rcs);//F1D + AddExhaust (th_att_rot[0], eh, ew1, {-1.63,-0.18, 18.40}, {-0.4339,-0.8830,-0.1793}, tex_rcs);//F3D - AddExhaust (th_att_rot[1], eh, ew1, _V(-3.46, 3.20,-12.30), _V(0, 1,0), tex_rcs);//L4U - AddExhaust (th_att_rot[1], eh, ew1, _V(-3.46, 3.20,-12.70), _V(0, 1,0), tex_rcs);//L2U - AddExhaust (th_att_rot[1], eh, ew1, _V(-3.46, 3.20,-13.10), _V(0, 1,0), tex_rcs);//L1U + AddExhaust (th_att_rot[1], eh, ew1, {-3.46, 3.20,-12.30}, {0, 1,0}, tex_rcs);//L4U + AddExhaust (th_att_rot[1], eh, ew1, {-3.46, 3.20,-12.70}, {0, 1,0}, tex_rcs);//L2U + AddExhaust (th_att_rot[1], eh, ew1, {-3.46, 3.20,-13.10}, {0, 1,0}, tex_rcs);//L1U - AddExhaust (th_att_rot[1], eh, ew1, _V( 3.43, 3.20,-12.30), _V(0, 1,0), tex_rcs);//R4U - AddExhaust (th_att_rot[1], eh, ew1, _V( 3.43, 3.20,-12.70), _V(0, 1,0), tex_rcs);//R2U - AddExhaust (th_att_rot[1], eh, ew1, _V( 3.43, 3.20,-13.10), _V(0, 1,0), tex_rcs);//R1U + AddExhaust (th_att_rot[1], eh, ew1, { 3.43, 3.20,-12.30}, {0, 1,0}, tex_rcs);//R4U + AddExhaust (th_att_rot[1], eh, ew1, { 3.43, 3.20,-12.70}, {0, 1,0}, tex_rcs);//R2U + AddExhaust (th_att_rot[1], eh, ew1, { 3.43, 3.20,-13.10}, {0, 1,0}, tex_rcs);//R1U - AddExhaust (th_att_rot[2], eh, ew1, _V(-0.4 , 1.10, 18.3 ), _V(0, 1,0), tex_rcs);//F1U - AddExhaust (th_att_rot[2], eh, ew1, _V( 0.0 , 1.15 ,18.3 ), _V(0, 1,0), tex_rcs);//F3U - AddExhaust (th_att_rot[2], eh, ew1, _V( 0.4 , 1.10, 18.3 ), _V(0, 1,0), tex_rcs);//F2U + AddExhaust (th_att_rot[2], eh, ew1, {-0.4 , 1.10, 18.3 }, {0, 1,0}, tex_rcs);//F1U + AddExhaust (th_att_rot[2], eh, ew1, { 0.0 , 1.15 ,18.3 }, {0, 1,0}, tex_rcs);//F3U + AddExhaust (th_att_rot[2], eh, ew1, { 0.4 , 1.10, 18.3 }, {0, 1,0}, tex_rcs);//F2U - AddExhaust (th_att_rot[3], eh, ew1, _V(-3.1 , 1.55,-12.45), _V(-0.2844,-0.9481,-0.1422), tex_rcs);//L4D - AddExhaust (th_att_rot[3], eh, ew1, _V(-3.1 , 1.6 ,-12.8 ), _V(-0.2844,-0.9481,-0.1422), tex_rcs);//L2D - AddExhaust (th_att_rot[3], eh, ew1, _V(-3.1 , 1.65,-13.15), _V(-0.2844,-0.9481,-0.1422), tex_rcs);//L3D + AddExhaust (th_att_rot[3], eh, ew1, {-3.1 , 1.55,-12.45}, {-0.2844,-0.9481,-0.1422}, tex_rcs);//L4D + AddExhaust (th_att_rot[3], eh, ew1, {-3.1 , 1.6 ,-12.8 }, {-0.2844,-0.9481,-0.1422}, tex_rcs);//L2D + AddExhaust (th_att_rot[3], eh, ew1, {-3.1 , 1.65,-13.15}, {-0.2844,-0.9481,-0.1422}, tex_rcs);//L3D - AddExhaust (th_att_rot[3], eh, ew1, _V( 3.15, 1.55,-12.45), _V( 0.2844,-0.9481,-0.1422), tex_rcs);//R4D - AddExhaust (th_att_rot[3], eh, ew1, _V( 3.15, 1.6 ,-12.8 ), _V( 0.2844,-0.9481,-0.1422), tex_rcs);//R2D - AddExhaust (th_att_rot[3], eh, ew1, _V( 3.15, 1.65,-13.15), _V( 0.2844,-0.9481,-0.1422), tex_rcs);//R3D + AddExhaust (th_att_rot[3], eh, ew1, { 3.15, 1.55,-12.45}, { 0.2844,-0.9481,-0.1422}, tex_rcs);//R4D + AddExhaust (th_att_rot[3], eh, ew1, { 3.15, 1.6 ,-12.8 }, { 0.2844,-0.9481,-0.1422}, tex_rcs);//R2D + AddExhaust (th_att_rot[3], eh, ew1, { 3.15, 1.65,-13.15}, { 0.2844,-0.9481,-0.1422}, tex_rcs);//R3D - th_att_rot[0] = th_att_lin[0] = CreateThruster (_V(0,0, 15.5), _V(-1,0,0), ORBITER_RCS_THRUST, NULL, ORBITER_RCS_ISP0, ORBITER_RCS_ISP1); - th_att_rot[1] = th_att_lin[3] = CreateThruster (_V(0,0,-15.5), _V( 1,0,0), ORBITER_RCS_THRUST, NULL, ORBITER_RCS_ISP0, ORBITER_RCS_ISP1); - th_att_rot[2] = th_att_lin[2] = CreateThruster (_V(0,0, 15.5), _V( 1,0,0), ORBITER_RCS_THRUST, NULL, ORBITER_RCS_ISP0, ORBITER_RCS_ISP1); - th_att_rot[3] = th_att_lin[1] = CreateThruster (_V(0,0,-15.5), _V(-1,0,0), ORBITER_RCS_THRUST, NULL, ORBITER_RCS_ISP0, ORBITER_RCS_ISP1); + th_att_rot[0] = th_att_lin[0] = CreateThruster ({0,0, 15.5}, {-1,0,0}, ORBITER_RCS_THRUST, NULL, ORBITER_RCS_ISP0, ORBITER_RCS_ISP1); + th_att_rot[1] = th_att_lin[3] = CreateThruster ({0,0,-15.5}, { 1,0,0}, ORBITER_RCS_THRUST, NULL, ORBITER_RCS_ISP0, ORBITER_RCS_ISP1); + th_att_rot[2] = th_att_lin[2] = CreateThruster ({0,0, 15.5}, { 1,0,0}, ORBITER_RCS_THRUST, NULL, ORBITER_RCS_ISP0, ORBITER_RCS_ISP1); + th_att_rot[3] = th_att_lin[1] = CreateThruster ({0,0,-15.5}, {-1,0,0}, ORBITER_RCS_THRUST, NULL, ORBITER_RCS_ISP0, ORBITER_RCS_ISP1); CreateThrusterGroup (th_att_rot, 2, THGROUP_ATT_YAWLEFT); CreateThrusterGroup (th_att_rot+2, 2, THGROUP_ATT_YAWRIGHT); CreateThrusterGroup (th_att_lin, 2, THGROUP_ATT_LEFT); CreateThrusterGroup (th_att_lin+2, 2, THGROUP_ATT_RIGHT); - AddExhaust (th_att_rot[0], eh, ew2, _V( 1.8 ,-0.3 , 18.0 ), _V( 1,0,0), tex_rcs);//F4R - AddExhaust (th_att_rot[0], eh, ew2, _V( 1.75, 0.1 , 18.05), _V( 1,0,0), tex_rcs);//F2R - AddExhaust (th_att_rot[2], eh, ew2, _V(-1.7 ,-0.3 , 18.0 ), _V(-1,0,0), tex_rcs);//F1L - AddExhaust (th_att_rot[2], eh, ew2, _V(-1.65,-0.1 , 18.05), _V(-1,0,0), tex_rcs);//F3L - - AddExhaust (th_att_rot[1], eh, ew2, _V(-4.0 , 2.35,-12.35), _V(-1,0,0), tex_rcs);//L4L - AddExhaust (th_att_rot[1], eh, ew2, _V(-4.0 , 2.35,-12.6 ), _V(-1,0,0), tex_rcs);//L2L - AddExhaust (th_att_rot[1], eh, ew2, _V(-4.0 , 2.35,-13.0 ), _V(-1,0,0), tex_rcs);//L3L - AddExhaust (th_att_rot[1], eh, ew2, _V(-4.0 , 2.35,-13.35), _V(-1,0,0), tex_rcs);//L1L - - AddExhaust (th_att_rot[3], eh, ew2, _V( 4.0 , 2.35,-12.35), _V( 1,0,0), tex_rcs);//R4R - AddExhaust (th_att_rot[3], eh, ew2, _V( 4.0 , 2.35,-12.6 ), _V( 1,0,0), tex_rcs);//R2R - AddExhaust (th_att_rot[3], eh, ew2, _V( 4.0 , 2.35,-13.0 ), _V( 1,0,0), tex_rcs);//R3R - AddExhaust (th_att_rot[3], eh, ew2, _V( 4.0, 2.35,-13.35), _V( 1,0,0), tex_rcs);//R1R - - th_att_rot[0] = CreateThruster (_V( 2.7,0,0), _V(0, 1,0), ORBITER_RCS_THRUST, NULL, ORBITER_RCS_ISP0, ORBITER_RCS_ISP1); - th_att_rot[1] = CreateThruster (_V(-2.7,0,0), _V(0,-1,0), ORBITER_RCS_THRUST, NULL, ORBITER_RCS_ISP0, ORBITER_RCS_ISP1); - th_att_rot[2] = CreateThruster (_V(-2.7,0,0), _V(0, 1,0), ORBITER_RCS_THRUST, NULL, ORBITER_RCS_ISP0, ORBITER_RCS_ISP1); - th_att_rot[3] = CreateThruster (_V( 2.7,0,0), _V(0,-1,0), ORBITER_RCS_THRUST, NULL, ORBITER_RCS_ISP0, ORBITER_RCS_ISP1); + AddExhaust (th_att_rot[0], eh, ew2, { 1.8 ,-0.3 , 18.0 }, { 1,0,0}, tex_rcs);//F4R + AddExhaust (th_att_rot[0], eh, ew2, { 1.75, 0.1 , 18.05}, { 1,0,0}, tex_rcs);//F2R + AddExhaust (th_att_rot[2], eh, ew2, {-1.7 ,-0.3 , 18.0 }, {-1,0,0}, tex_rcs);//F1L + AddExhaust (th_att_rot[2], eh, ew2, {-1.65,-0.1 , 18.05}, {-1,0,0}, tex_rcs);//F3L + + AddExhaust (th_att_rot[1], eh, ew2, {-4.0 , 2.35,-12.35}, {-1,0,0}, tex_rcs);//L4L + AddExhaust (th_att_rot[1], eh, ew2, {-4.0 , 2.35,-12.6 }, {-1,0,0}, tex_rcs);//L2L + AddExhaust (th_att_rot[1], eh, ew2, {-4.0 , 2.35,-13.0 }, {-1,0,0}, tex_rcs);//L3L + AddExhaust (th_att_rot[1], eh, ew2, {-4.0 , 2.35,-13.35}, {-1,0,0}, tex_rcs);//L1L + + AddExhaust (th_att_rot[3], eh, ew2, { 4.0 , 2.35,-12.35}, { 1,0,0}, tex_rcs);//R4R + AddExhaust (th_att_rot[3], eh, ew2, { 4.0 , 2.35,-12.6 }, { 1,0,0}, tex_rcs);//R2R + AddExhaust (th_att_rot[3], eh, ew2, { 4.0 , 2.35,-13.0 }, { 1,0,0}, tex_rcs);//R3R + AddExhaust (th_att_rot[3], eh, ew2, { 4.0, 2.35,-13.35}, { 1,0,0}, tex_rcs);//R1R + + th_att_rot[0] = CreateThruster ({ 2.7,0,0}, {0, 1,0}, ORBITER_RCS_THRUST, NULL, ORBITER_RCS_ISP0, ORBITER_RCS_ISP1); + th_att_rot[1] = CreateThruster ({-2.7,0,0}, {0,-1,0}, ORBITER_RCS_THRUST, NULL, ORBITER_RCS_ISP0, ORBITER_RCS_ISP1); + th_att_rot[2] = CreateThruster ({-2.7,0,0}, {0, 1,0}, ORBITER_RCS_THRUST, NULL, ORBITER_RCS_ISP0, ORBITER_RCS_ISP1); + th_att_rot[3] = CreateThruster ({ 2.7,0,0}, {0,-1,0}, ORBITER_RCS_THRUST, NULL, ORBITER_RCS_ISP0, ORBITER_RCS_ISP1); CreateThrusterGroup (th_att_rot, 2, THGROUP_ATT_BANKLEFT); CreateThrusterGroup (th_att_rot+2, 2, THGROUP_ATT_BANKRIGHT); - AddExhaust (th_att_rot[0], eh, ew1, _V( 1.60,-0.20, 18.78), _V( 0.4339,-0.8830,-0.1793), tex_rcs);//F2D - AddExhaust (th_att_rot[0], eh, ew1, _V( 1.68,-0.18, 18.40), _V( 0.4339,-0.8830,-0.1793), tex_rcs);//F4D - AddExhaust (th_att_rot[2], eh, ew1, _V(-1.55,-0.20, 18.78), _V(-0.4339,-0.8830,-0.1793), tex_rcs);//F1D - AddExhaust (th_att_rot[2], eh, ew1, _V(-1.63,-0.18, 18.40), _V(-0.4339,-0.8830,-0.1793), tex_rcs);//F3D + AddExhaust (th_att_rot[0], eh, ew1, { 1.60,-0.20, 18.78}, { 0.4339,-0.8830,-0.1793}, tex_rcs);//F2D + AddExhaust (th_att_rot[0], eh, ew1, { 1.68,-0.18, 18.40}, { 0.4339,-0.8830,-0.1793}, tex_rcs);//F4D + AddExhaust (th_att_rot[2], eh, ew1, {-1.55,-0.20, 18.78}, {-0.4339,-0.8830,-0.1793}, tex_rcs);//F1D + AddExhaust (th_att_rot[2], eh, ew1, {-1.63,-0.18, 18.40}, {-0.4339,-0.8830,-0.1793}, tex_rcs);//F3D - AddExhaust (th_att_rot[1], eh, ew1, _V(-3.46, 3.20,-12.30), _V(0, 1,0), tex_rcs);//L4U - AddExhaust (th_att_rot[1], eh, ew1, _V(-3.46, 3.20,-12.70), _V(0, 1,0), tex_rcs);//L2U - AddExhaust (th_att_rot[1], eh, ew1, _V(-3.46, 3.20,-13.10), _V(0, 1,0), tex_rcs);//L1U + AddExhaust (th_att_rot[1], eh, ew1, {-3.46, 3.20,-12.30}, {0, 1,0}, tex_rcs);//L4U + AddExhaust (th_att_rot[1], eh, ew1, {-3.46, 3.20,-12.70}, {0, 1,0}, tex_rcs);//L2U + AddExhaust (th_att_rot[1], eh, ew1, {-3.46, 3.20,-13.10}, {0, 1,0}, tex_rcs);//L1U - AddExhaust (th_att_rot[3], eh, ew1, _V( 3.43, 3.20,-12.30), _V(0, 1,0), tex_rcs);//R4U - AddExhaust (th_att_rot[3], eh, ew1, _V( 3.43, 3.20,-12.70), _V(0, 1,0), tex_rcs);//R2U - AddExhaust (th_att_rot[3], eh, ew1, _V( 3.43, 3.20,-13.10), _V(0, 1,0), tex_rcs);//R1U + AddExhaust (th_att_rot[3], eh, ew1, { 3.43, 3.20,-12.30}, {0, 1,0}, tex_rcs);//R4U + AddExhaust (th_att_rot[3], eh, ew1, { 3.43, 3.20,-12.70}, {0, 1,0}, tex_rcs);//R2U + AddExhaust (th_att_rot[3], eh, ew1, { 3.43, 3.20,-13.10}, {0, 1,0}, tex_rcs);//R1U - AddExhaust (th_att_rot[2], eh, ew1, _V(-3.1 , 1.55,-12.45), _V(-0.2844,-0.9481,-0.1422), tex_rcs);//L4D - AddExhaust (th_att_rot[2], eh, ew1, _V(-3.1 , 1.6 ,-12.8 ), _V(-0.2844,-0.9481,-0.1422), tex_rcs);//L2D - AddExhaust (th_att_rot[2], eh, ew1, _V(-3.1 , 1.65,-13.15), _V(-0.2844,-0.9481,-0.1422), tex_rcs);//L3D + AddExhaust (th_att_rot[2], eh, ew1, {-3.1 , 1.55,-12.45}, {-0.2844,-0.9481,-0.1422}, tex_rcs);//L4D + AddExhaust (th_att_rot[2], eh, ew1, {-3.1 , 1.6 ,-12.8 }, {-0.2844,-0.9481,-0.1422}, tex_rcs);//L2D + AddExhaust (th_att_rot[2], eh, ew1, {-3.1 , 1.65,-13.15}, {-0.2844,-0.9481,-0.1422}, tex_rcs);//L3D - AddExhaust (th_att_rot[0], eh, ew1, _V( 3.15, 1.55,-12.45), _V( 0.2844,-0.9481,-0.1422), tex_rcs);//R4D - AddExhaust (th_att_rot[0], eh, ew1, _V( 3.15, 1.6 ,-12.8 ), _V( 0.2844,-0.9481,-0.1422), tex_rcs);//R2D - AddExhaust (th_att_rot[0], eh, ew1, _V( 3.15, 1.65,-13.15), _V( 0.2844,-0.9481,-0.1422), tex_rcs);//R3D + AddExhaust (th_att_rot[0], eh, ew1, { 3.15, 1.55,-12.45}, { 0.2844,-0.9481,-0.1422}, tex_rcs);//R4D + AddExhaust (th_att_rot[0], eh, ew1, { 3.15, 1.6 ,-12.8 }, { 0.2844,-0.9481,-0.1422}, tex_rcs);//R2D + AddExhaust (th_att_rot[0], eh, ew1, { 3.15, 1.65,-13.15}, { 0.2844,-0.9481,-0.1422}, tex_rcs);//R3D - th_att_lin[0] = CreateThruster (_V(0,0,-16), _V(0,0, 1), ORBITER_RCS_THRUST, NULL, ORBITER_RCS_ISP0, ORBITER_RCS_ISP1); - th_att_lin[1] = CreateThruster (_V(0,0, 16), _V(0,0,-1), ORBITER_RCS_THRUST, NULL, ORBITER_RCS_ISP0, ORBITER_RCS_ISP1); + th_att_lin[0] = CreateThruster ({0,0,-16}, {0,0, 1}, ORBITER_RCS_THRUST, NULL, ORBITER_RCS_ISP0, ORBITER_RCS_ISP1); + th_att_lin[1] = CreateThruster ({0,0, 16}, {0,0,-1}, ORBITER_RCS_THRUST, NULL, ORBITER_RCS_ISP0, ORBITER_RCS_ISP1); CreateThrusterGroup (th_att_lin, 1, THGROUP_ATT_FORWARD); CreateThrusterGroup (th_att_lin+1, 1, THGROUP_ATT_BACK); - AddExhaust (th_att_lin[0], eh, ew1, _V(-3.59, 2.8 ,-13.6 ), _V(0,0,-1), tex_rcs);//L1A - AddExhaust (th_att_lin[0], eh, ew1, _V(-3.27, 2.8 ,-13.6 ), _V(0,0,-1), tex_rcs);//L3A - AddExhaust (th_att_lin[0], eh, ew1, _V( 3.64, 2.8 ,-13.6 ), _V(0,0,-1), tex_rcs);//R1A - AddExhaust (th_att_lin[0], eh, ew1, _V( 3.27, 2.8 ,-13.6 ), _V(0,0,-1), tex_rcs);//R3A + AddExhaust (th_att_lin[0], eh, ew1, {-3.59, 2.8 ,-13.6 }, {0,0,-1}, tex_rcs);//L1A + AddExhaust (th_att_lin[0], eh, ew1, {-3.27, 2.8 ,-13.6 }, {0,0,-1}, tex_rcs);//L3A + AddExhaust (th_att_lin[0], eh, ew1, { 3.64, 2.8 ,-13.6 }, {0,0,-1}, tex_rcs);//R1A + AddExhaust (th_att_lin[0], eh, ew1, { 3.27, 2.8 ,-13.6 }, {0,0,-1}, tex_rcs);//R3A - AddExhaust (th_att_lin[1], eh, ew1, _V( 0.0 , 0.75, 19.2 ), _V(0, 0.0499, 0.9988), tex_rcs);//F3F - AddExhaust (th_att_lin[1], eh, ew1, _V(-0.4 , 0.7 , 19.2 ), _V(0, 0.0499, 0.9988), tex_rcs);//F1F - AddExhaust (th_att_lin[1], eh, ew1, _V( 0.4 , 0.7 , 19.2 ), _V(0, 0.0499, 0.9988), tex_rcs);//F2F + AddExhaust (th_att_lin[1], eh, ew1, { 0.0 , 0.75, 19.2 }, {0, 0.0499, 0.9988}, tex_rcs);//F3F + AddExhaust (th_att_lin[1], eh, ew1, {-0.4 , 0.7 , 19.2 }, {0, 0.0499, 0.9988}, tex_rcs);//F1F + AddExhaust (th_att_lin[1], eh, ew1, { 0.4 , 0.7 , 19.2 }, {0, 0.0499, 0.9988}, tex_rcs);//F2F } // -------------------------------------------------------------- @@ -340,18 +340,18 @@ void Atlantis::CreateRCS() // -------------------------------------------------------------- void Atlantis::CreateAirfoils () { - CreateAirfoil (LIFT_VERTICAL, _V(0,0,-0.5), VLiftCoeff, 20, 270, 2.266); - CreateAirfoil (LIFT_HORIZONTAL, _V(0,0,-4), HLiftCoeff, 20, 50, 1.5); + CreateAirfoil (LIFT_VERTICAL, {0,0,-0.5}, VLiftCoeff, 20, 270, 2.266); + CreateAirfoil (LIFT_HORIZONTAL, {0,0,-4}, HLiftCoeff, 20, 50, 1.5); - CreateControlSurface (AIRCTRL_ELEVATOR, 5.0, 1.5, _V( 0, 0, -15), AIRCTRL_AXIS_XPOS, anim_elev); - CreateControlSurface (AIRCTRL_RUDDER, 2.0, 1.5, _V( 0, 3, -16), AIRCTRL_AXIS_YPOS, anim_rudder); - CreateControlSurface (AIRCTRL_AILERON, 3.0, 1.5, _V( 7,-0.5,-15), AIRCTRL_AXIS_XPOS, anim_raileron); - CreateControlSurface (AIRCTRL_AILERON, 3.0, 1.5, _V(-7,-0.5,-15), AIRCTRL_AXIS_XNEG, anim_laileron); + CreateControlSurface (AIRCTRL_ELEVATOR, 5.0, 1.5, { 0, 0, -15}, AIRCTRL_AXIS_XPOS, anim_elev); + CreateControlSurface (AIRCTRL_RUDDER, 2.0, 1.5, { 0, 3, -16}, AIRCTRL_AXIS_YPOS, anim_rudder); + CreateControlSurface (AIRCTRL_AILERON, 3.0, 1.5, { 7,-0.5,-15}, AIRCTRL_AXIS_XPOS, anim_raileron); + CreateControlSurface (AIRCTRL_AILERON, 3.0, 1.5, {-7,-0.5,-15}, AIRCTRL_AXIS_XNEG, anim_laileron); - CreateVariableDragElement (&spdb_proc, 5, _V(0, 7.5, -14)); // speedbrake drag - CreateVariableDragElement (&gear_proc, 2, _V(0,-3,0)); // landing gear drag - CreateVariableDragElement (&rdoor_drag, 7, _V(2.9,0,10)); // right cargo door drag - CreateVariableDragElement (&ldoor_drag, 7, _V(-2.9,0,10)); // right cargo door drag + CreateVariableDragElement (&spdb_proc, 5, {0, 7.5, -14}); // speedbrake drag + CreateVariableDragElement (&gear_proc, 2, {0,-3,0}); // landing gear drag + CreateVariableDragElement (&rdoor_drag, 7, {2.9,0,10}); // right cargo door drag + CreateVariableDragElement (&ldoor_drag, 7, {-2.9,0,10}); // right cargo door drag } // -------------------------------------------------------------- @@ -500,10 +500,10 @@ void Atlantis::DefineAnimations (void) static UINT RCargoDoorGrp[4] = {GRP_cargodooroutR,GRP_cargodoorinR,GRP_radiatorFR,GRP_radiatorBR}; static MGROUP_ROTATE RCargoDoor (midx, RCargoDoorGrp, 4, - _V(2.88, 1.3, 0), _V(0,0,1), (float)(-175.5*RAD)); + {2.88, 1.3, 0}, {0,0,1}, (float)(-175.5*RAD)); static UINT LCargoDoorGrp[4] = {GRP_cargodooroutL,GRP_cargodoorinL,GRP_radiatorFL,GRP_radiatorBL}; static MGROUP_ROTATE LCargoDoor (midx, LCargoDoorGrp, 4, - _V(-2.88, 1.3, 0), _V(0,0,1), (float)(175.5*RAD)); + {-2.88, 1.3, 0}, {0,0,1}, (float)(175.5*RAD)); anim_door = CreateAnimation (0); AddAnimationComponent (anim_door, 0.0, 0.4632, &RCargoDoor); @@ -511,10 +511,10 @@ void Atlantis::DefineAnimations (void) static UINT RRadiatorGrp[1] = {GRP_radiatorFR}; static MGROUP_ROTATE RRadiator (midx, RRadiatorGrp, 1, - _V(2.88, 1.3, 0), _V(0,0,1), (float)(35.5*RAD)); + {2.88, 1.3, 0}, {0,0,1}, (float)(35.5*RAD)); static UINT LRadiatorGrp[1] = {GRP_radiatorFL}; static MGROUP_ROTATE LRadiator (midx, LRadiatorGrp, 1, - _V(-2.88, 1.3, 0), _V(0,0,1), (float)(-35.5*RAD)); + {-2.88, 1.3, 0}, {0,0,1}, (float)(-35.5*RAD)); anim_rad = CreateAnimation (0); AddAnimationComponent (anim_rad, 0, 1, &RRadiator); @@ -524,22 +524,22 @@ void Atlantis::DefineAnimations (void) static UINT LNosewheelDoorGrp[1] = {GRP_nosedoorL}; static MGROUP_ROTATE LNosewheelDoor (midx, LNosewheelDoorGrp, 1, - _V(-0.78, -2.15, 17), _V(0, 0.195, 0.981), (float)(-60.0*RAD)); + {-0.78, -2.15, 17}, {0, 0.195, 0.981}, (float)(-60.0*RAD)); static UINT RNosewheelDoorGrp[1] = {GRP_nosedoorR}; static MGROUP_ROTATE RNosewheelDoor (midx, RNosewheelDoorGrp, 1, - _V(0.78, -2.15, 17), _V(0, 0.195, 0.981), (float)(60.0*RAD)); + {0.78, -2.15, 17}, {0, 0.195, 0.981}, (float)(60.0*RAD)); static UINT NosewheelGrp[2] = {GRP_nosewheel,GRP_nosegear}; static MGROUP_ROTATE Nosewheel (midx, NosewheelGrp, 2, - _V(0.0, -1.95, 17.45), _V(1, 0, 0), (float)(109.0*RAD)); + {0.0, -1.95, 17.45}, {1, 0, 0}, (float)(109.0*RAD)); static UINT RGearDoorGrp[1] = {GRP_geardoorR}; static MGROUP_ROTATE RGearDoor (midx, RGearDoorGrp, 1, - _V(4.35, -2.64, -1.69), _V(0, 0.02, 0.9), (float)(96.2*RAD)); + {4.35, -2.64, -1.69}, {0, 0.02, 0.9}, (float)(96.2*RAD)); static UINT LGearDoorGrp[1] = {GRP_geardoorL}; static MGROUP_ROTATE LGearDoor (midx, LGearDoorGrp, 1, - _V(-4.35, -2.64, -1.69), _V(0, 0.02, 0.9), (float)(-96.2*RAD)); + {-4.35, -2.64, -1.69}, {0, 0.02, 0.9}, (float)(-96.2*RAD)); static UINT MainGearGrp[4] = {GRP_wheelR,GRP_gearR,GRP_wheelL,GRP_gearL}; static MGROUP_ROTATE MainGear (midx, MainGearGrp, 4, - _V(0, -2.66, -3.68), _V(1, 0, 0), (float)(94.5*RAD)); + {0, -2.66, -3.68}, {1, 0, 0}, (float)(94.5*RAD)); anim_gear = CreateAnimation (0); AddAnimationComponent (anim_gear, 0, 0.5, &LNosewheelDoor); @@ -553,13 +553,13 @@ void Atlantis::DefineAnimations (void) static UINT KuBand1Grp[3] = {GRP_startrackers,GRP_KUband1,GRP_KUband2}; static MGROUP_ROTATE KuBand1 (midx, KuBand1Grp, 3, - _V(2.85, 0.85, 0), _V(0,0,1), (float)(-18*RAD)); + {2.85, 0.85, 0}, {0,0,1}, (float)(-18*RAD)); static UINT KuBand2Grp[1] = {GRP_KUband2}; static MGROUP_ROTATE KuBand2 (midx, KuBand2Grp, 1, - _V(2.78, 1.7, 0), _V(0,0,1), (float)(-90*RAD)); + {2.78, 1.7, 0}, {0,0,1}, (float)(-90*RAD)); static UINT KuBand3Grp[2] = {GRP_KUband1,GRP_KUband2}; static MGROUP_ROTATE KuBand3 (midx, KuBand3Grp, 2, - _V(2.75, 2.05, 11.47), _V(0,1,0), (float)(-113*RAD)); + {2.75, 2.05, 11.47}, {0,1,0}, (float)(-113*RAD)); anim_kubd = CreateAnimation (0); AddAnimationComponent (anim_kubd, 0, 0.333, &KuBand1); @@ -570,7 +570,7 @@ void Atlantis::DefineAnimations (void) static UINT ElevGrp[4] = {GRP_flapR,GRP_flapL,GRP_aileronL,GRP_aileronR}; static MGROUP_ROTATE Elevator (midx, ElevGrp, 4, - _V(0,-2.173,-8.84), _V(1,0,0), (float)(30.0*RAD)); + {0,-2.173,-8.84}, {1,0,0}, (float)(30.0*RAD)); anim_elev = CreateAnimation (0.5); AddAnimationComponent (anim_elev, 0, 1, &Elevator); @@ -578,10 +578,10 @@ void Atlantis::DefineAnimations (void) static UINT LAileronGrp[2] = {GRP_flapL,GRP_aileronL}; static MGROUP_ROTATE LAileron (midx, LAileronGrp, 2, - _V(0,-2.173,-8.84), _V(-1,0,0), (float)(10.0*RAD)); + {0,-2.173,-8.84}, {-1,0,0}, (float)(10.0*RAD)); static UINT RAileronGrp[2] = {GRP_flapR,GRP_aileronR}; static MGROUP_ROTATE RAileron (midx, RAileronGrp, 2, - _V(0,-2.173,-8.84), _V(1,0,0), (float)(10.0*RAD)); + {0,-2.173,-8.84}, {1,0,0}, (float)(10.0*RAD)); anim_laileron = CreateAnimation (0.5); AddAnimationComponent (anim_laileron, 0, 1, &LAileron); anim_raileron = CreateAnimation (0.5); @@ -591,7 +591,7 @@ void Atlantis::DefineAnimations (void) static UINT RudderGrp[2] = {GRP_rudderR,GRP_rudderL}; static MGROUP_ROTATE Rudder (midx, RudderGrp, 2, - _V(0,5.77,-12.17), _V(-0.037,0.833,-0.552), (float)(-54.2*RAD)); + {0,5.77,-12.17}, {-0.037,0.833,-0.552}, (float)(-54.2*RAD)); anim_rudder = CreateAnimation (0.5); AddAnimationComponent (anim_rudder, 0, 1, &Rudder); @@ -599,10 +599,10 @@ void Atlantis::DefineAnimations (void) static UINT SB1Grp[1] = {GRP_rudderR}; static MGROUP_ROTATE SB1 (midx, SB1Grp, 1, - _V(0.32,5.77,-12.17), _V(-0.037,0.833,-0.552), (float)(-49.3*RAD)); + {0.32,5.77,-12.17}, {-0.037,0.833,-0.552}, (float)(-49.3*RAD)); static UINT SB2Grp[1] = {GRP_rudderL}; static MGROUP_ROTATE SB2 (midx, SB2Grp, 1, - _V(-0.32,5.77,-12.17), _V(0.037,0.833,-0.552), (float)(49.3*RAD)); + {-0.32,5.77,-12.17}, {0.037,0.833,-0.552}, (float)(49.3*RAD)); anim_spdb = CreateAnimation (0); AddAnimationComponent (anim_spdb, 0, 1, &SB1); @@ -616,36 +616,36 @@ void Atlantis::DefineAnimations (void) static UINT RMSShoulderYawGrp[1] = {GRP_Shoulder}; rms_anim[0] = new MGROUP_ROTATE (midx, RMSShoulderYawGrp, 1, - _V(-2.26, 1.70, 9.65), _V(0, 1, 0), (float)(-360*RAD)); // -180 .. +180 + {-2.26, 1.70, 9.65}, {0, 1, 0}, (float)(-360*RAD)); // -180 .. +180 anim_arm_sy = CreateAnimation (0.5); parent = AddAnimationComponent (anim_arm_sy, 0, 1, rms_anim[0]); static UINT RMSShoulderPitchGrp[1] = {GRP_Humerus}; rms_anim[1] = new MGROUP_ROTATE (midx, RMSShoulderPitchGrp, 1, - _V(-2.26, 1.70, 9.65), _V(1, 0, 0), (float)(147*RAD)); // -2 .. +145 + {-2.26, 1.70, 9.65}, {1, 0, 0}, (float)(147*RAD)); // -2 .. +145 anim_arm_sp = CreateAnimation (0.0136); parent = AddAnimationComponent (anim_arm_sp, 0, 1, rms_anim[1], parent); static UINT RMSElbowPitchGrp[3] = {GRP_radii,GRP_RMScamera,GRP_RMScamera_pivot}; rms_anim[2] = new MGROUP_ROTATE (midx, RMSElbowPitchGrp, 3, - _V(-2.26,1.55,3.10), _V(1,0,0), (float)(-162*RAD)); // -160 .. +2 + {-2.26,1.55,3.10}, {1,0,0}, (float)(-162*RAD)); // -160 .. +2 anim_arm_ep = CreateAnimation (0.0123); parent = AddAnimationComponent (anim_arm_ep, 0, 1, rms_anim[2], parent); static UINT RMSWristPitchGrp[1] = {GRP_wrist}; rms_anim[3] = new MGROUP_ROTATE (midx, RMSWristPitchGrp, 1, - _V(-2.26,1.7,-3.55), _V(1,0,0), (float)(240*RAD)); // -120 .. +120 + {-2.26,1.7,-3.55}, {1,0,0}, (float)(240*RAD)); // -120 .. +120 anim_arm_wp = CreateAnimation (0.5); parent = AddAnimationComponent (anim_arm_wp, 0, 1, rms_anim[3], parent); static UINT RMSWristYawGrp[1] = {GRP_endeffecter}; rms_anim[4] = new MGROUP_ROTATE (midx, RMSWristYawGrp, 1, - _V(-2.26,1.7,-4.9), _V(0,1,0), (float)(-240*RAD)); // -120 .. +120 + {-2.26,1.7,-4.9}, {0,1,0}, (float)(-240*RAD)); // -120 .. +120 anim_arm_wy = CreateAnimation (0.5); parent = AddAnimationComponent (anim_arm_wy, 0, 1, rms_anim[4], parent); rms_anim[5] = new MGROUP_ROTATE (LOCALVERTEXLIST, MAKEGROUPARRAY(arm_tip), 3, - _V(-2.26,1.7,-6.5), _V(0,0,1), (float)(894*RAD)); // -447 .. +447 + {-2.26,1.7,-6.5}, {0,0,1}, (float)(894*RAD)); // -447 .. +447 anim_arm_wr = CreateAnimation (0.5); hAC_arm = AddAnimationComponent (anim_arm_wr, 0, 1, rms_anim[5], parent); @@ -655,15 +655,15 @@ void Atlantis::DefineAnimations (void) anim_ssme = CreateAnimation (init_gimbal/max_gimbal); static UINT SSMEL_Grp = GRP_SSMEL; - ssme_anim[0] = new MGROUP_ROTATE (midx, &SSMEL_Grp, 1, _V(-1.55,-0.37,-12.5), _V(-1,0,0), max_gimbal); + ssme_anim[0] = new MGROUP_ROTATE (midx, &SSMEL_Grp, 1, {-1.55,-0.37,-12.5}, {-1,0,0}, max_gimbal); AddAnimationComponent (anim_ssme, 0, 1, ssme_anim[0]); static UINT SSMER_Grp = GRP_SSMER; - ssme_anim[1] = new MGROUP_ROTATE (midx, &SSMER_Grp, 1, _V( 1.55,-0.37,-12.5), _V(-1,0,0), max_gimbal); + ssme_anim[1] = new MGROUP_ROTATE (midx, &SSMER_Grp, 1, { 1.55,-0.37,-12.5}, {-1,0,0}, max_gimbal); AddAnimationComponent (anim_ssme, 0, 1, ssme_anim[1]); static UINT SSMET_Grp = GRP_SSMET; - ssme_anim[2] = new MGROUP_ROTATE (midx, &SSMET_Grp, 1, _V(0.0, 2.7, -12.5), _V(-1,0,0), max_gimbal); + ssme_anim[2] = new MGROUP_ROTATE (midx, &SSMET_Grp, 1, {0.0, 2.7, -12.5}, {-1,0,0}, max_gimbal); AddAnimationComponent (anim_ssme, 0, 1, ssme_anim[2]); // ====================================================== @@ -1017,7 +1017,7 @@ void Atlantis::AutoGimbal (const VECTOR3 &tgt_rate) // Set SRB gimbals if (status < 2 && pET) { pET->SetSRBGimbal (gimbal_pos); - SetSSMEGimbal (_V(gimbal_pos.x,0,0)); // If SRBs are available, we gimbal the SSMEs only in pitch + SetSSMEGimbal ({gimbal_pos.x,0,0}); // If SRBs are available, we gimbal the SSMEs only in pitch } else { SetSSMEGimbal (gimbal_pos); } @@ -1080,7 +1080,7 @@ void Atlantis::LaunchClamps () { // TODO #ifdef UNDEF - VECTOR3 F, T, r = _V(0,0,0), Fc = _V(0,0,0), Tc = _V(0,0,0); + VECTOR3 F, T, r = {0,0,0}, Fc = {0,0,0}, Tc = {0,0,0}; GetThrusterMoment (th_srb[0], F, T); Fc.z = -2*F.z; Tc.x = 2*T.x; @@ -1095,7 +1095,7 @@ void Atlantis::LaunchClamps () r.z = (Fc.y ? Tc.x/Fc.y : 0); AddForce (Fc, r); - Tc = _V(0,0,0); + Tc = {0,0,0}; GetThrusterMoment(th_srb[0], F, T); Tc += T; GetThrusterMoment(th_srb[1], F, T); @@ -1110,35 +1110,35 @@ void Atlantis::LaunchClamps () void Atlantis::SetGearParameters (double state) { static TOUCHDOWNVTX tdvtx[14] = { - {_V( 0, -3.3,18.75), 1e8, 1e6, 1.6, 0.1}, - {_V(-3.96, -5.5, -3.2), 1e8, 1e6, 3, 0.2}, - {_V( 3.96, -5.5, -3.2), 1e8, 1e6, 3, 0.2}, - {_V(-11.9, -2.1, -10), 1e8, 1e6, 3}, - {_V( 11.9, -2.1, -10), 1e8, 1e6, 3}, - {_V(-11.3, -2.1, -6), 1e8, 1e6, 3}, - {_V( 11.3, -2.1, -6), 1e8, 1e6, 3}, - {_V(-2.95, -2.0,-14.35),1e8, 1e6, 3}, - {_V( 2.95, -2.0,-14.35),1e8, 1e6, 3}, - {_V(-1.9, -1.0,-14.8), 1e8, 1e6, 3}, - {_V( 1.9, -1.0,-14.8), 1e8, 1e6, 3}, - {_V( 0, 11.2,-16.4), 1e8, 1e6, 3}, - {_V( 0, 11.3,-14.0), 1e8, 1e6, 3}, - {_V( 0, -0.9, 20.6), 1e8, 1e6, 3} + {{ 0, -3.3,18.75}, 1e8, 1e6, 1.6, 0.1}, + {{-3.96, -5.5, -3.2}, 1e8, 1e6, 3, 0.2}, + {{ 3.96, -5.5, -3.2}, 1e8, 1e6, 3, 0.2}, + {{-11.9, -2.1, -10}, 1e8, 1e6, 3}, + {{ 11.9, -2.1, -10}, 1e8, 1e6, 3}, + {{-11.3, -2.1, -6}, 1e8, 1e6, 3}, + {{ 11.3, -2.1, -6}, 1e8, 1e6, 3}, + {{-2.95, -2.0,-14.35},1e8, 1e6, 3}, + {{ 2.95, -2.0,-14.35},1e8, 1e6, 3}, + {{-1.9, -1.0,-14.8}, 1e8, 1e6, 3}, + {{ 1.9, -1.0,-14.8}, 1e8, 1e6, 3}, + {{ 0, 11.2,-16.4}, 1e8, 1e6, 3}, + {{ 0, 11.3,-14.0}, 1e8, 1e6, 3}, + {{ 0, -0.9, 20.6}, 1e8, 1e6, 3} }; if (state == 1.0) { // gear fully deployed static TOUCHDOWNVTX geardn_vtx[3] = { - {_V( 0, -3.95,17.5), 1e8, 1e6, 1.6, 0.1}, - {_V(-3.96, -5.5, -3.2), 1e8, 1e6, 3, 0.2}, - {_V( 3.96, -5.5, -3.2), 1e8, 1e6, 3, 0.2}, + {{ 0, -3.95,17.5}, 1e8, 1e6, 1.6, 0.1}, + {{-3.96, -5.5, -3.2}, 1e8, 1e6, 3, 0.2}, + {{ 3.96, -5.5, -3.2}, 1e8, 1e6, 3, 0.2}, }; memcpy (tdvtx, geardn_vtx, 3*sizeof(TOUCHDOWNVTX)); SetTouchdownPoints (tdvtx, 14); SetSurfaceFrictionCoeff (0.05, 0.4); } else { static TOUCHDOWNVTX gearup_vtx[3] = { - {_V( 0, -2.2,16.75), 1e8, 1e6, 3}, - {_V(-3.96, -2.7, -3.2), 1e8, 1e6, 3}, - {_V( 3.96, -2.7, -3.2), 1e8, 1e6, 3}, + {{ 0, -2.2,16.75}, 1e8, 1e6, 3}, + {{-3.96, -2.7, -3.2}, 1e8, 1e6, 3}, + {{ 3.96, -2.7, -3.2}, 1e8, 1e6, 3}, }; memcpy (tdvtx, gearup_vtx, 3*sizeof(TOUCHDOWNVTX)); SetTouchdownPoints (tdvtx, 14); @@ -1310,10 +1310,10 @@ void Atlantis::clbkSetClassCaps (FILEHANDLE cfg) SetSize (19.6); SetEmptyMass (ORBITER_EMPTY_MASS); - SetPMI (_V(78.2,82.1,10.7)); + SetPMI ({78.2,82.1,10.7}); SetGravityGradientDamping (20.0); SetCrossSections (ORBITER_CS); - SetRotDrag (_V(0.43,0.43,0.29)); // angular drag + SetRotDrag ({0.43,0.43,0.29}); // angular drag SetTrimScale (0.05); launchelev = 0.0; @@ -1389,7 +1389,7 @@ void Atlantis::clbkLoadStateEx (FILEHANDLE scn, void *vs) vs2->arot.z = atan2(clng*slat*cdir+slng*sdir, clng*slat*sdir-slng*cdir); } } else { - double rad = length(vs2->rpos); + double rad = len(vs2->rpos); double alt = rad - oapiGetSize(vs2->rbody); launchelev = max (0.0, alt - 18.962); } @@ -1399,7 +1399,7 @@ void Atlantis::clbkLoadStateEx (FILEHANDLE scn, void *vs) ofs_sts_sat.x=sts_sat_x; ofs_sts_sat.y=sts_sat_y; ofs_sts_sat.z=sts_sat_z; - SetAttachmentParams (sat_attach, ofs_sts_sat, _V(0,1,0), _V(0,0,1)); + SetAttachmentParams (sat_attach, ofs_sts_sat, {0,1,0}, {0,0,1}); } // optional meshes @@ -1407,7 +1407,7 @@ void Atlantis::clbkLoadStateEx (FILEHANDLE scn, void *vs) mesh_cargo = AddMesh (cargo_static_mesh_name, &cargo_static_ofs); } if (do_plat && !mesh_platform) { - VECTOR3 plat_ofs = _V(-2.59805, 1.69209, -5.15524); + VECTOR3 plat_ofs = {-2.59805, 1.69209, -5.15524}; mesh_platform = AddMesh("shuttle_eva_plat", &plat_ofs); } t0 = ascap->GetMT0(); @@ -1552,7 +1552,7 @@ void Atlantis::clbkPreStep (double simt, double simdt, double mjd) engine_light_level = GetThrusterGroupLevel (THGROUP_MAIN); - VECTOR3 tgt_rate = _V(0,0,0); // target rotation rates - used for setting engine gimbals + VECTOR3 tgt_rate = {0,0,0}; // target rotation rates - used for setting engine gimbals if (status >= 1 && status <= 3) { // ascent autopilot @@ -1814,8 +1814,8 @@ void Atlantis::clbkMFDMode (int mfd, int mode) // -------------------------------------------------------------- bool Atlantis::clbkLoadGenericCockpit () { - SetCameraOffset (_V(-0.67,2.55,14.4)); - SetCameraDefaultDirection (_V(0,0,1)); + SetCameraOffset ({-0.67,2.55,14.4}); + SetCameraDefaultDirection ({0,0,1}); return true; } @@ -1826,21 +1826,21 @@ bool Atlantis::clbkLoadGenericCockpit () void Atlantis::RegisterVC_CdrMFD () { // activate MFD function buttons - oapiVCSetAreaClickmode_Quadrilateral (AID_CDR1_BUTTONS, _V(-0.9239,2.0490,15.0595), _V(-0.7448,2.0490,15.0595), _V(-0.9239,2.0280,15.0595), _V(-0.7448,2.0280,15.0595)); - oapiVCSetAreaClickmode_Quadrilateral (AID_CDR2_BUTTONS, _V(-0.6546,2.0490,15.0595), _V(-0.4736,2.0490,15.0595), _V(-0.6546,2.0280,15.0595), _V(-0.4736,2.0280,15.0595)); + oapiVCSetAreaClickmode_Quadrilateral (AID_CDR1_BUTTONS, {-0.9239,2.0490,15.0595}, {-0.7448,2.0490,15.0595}, {-0.9239,2.0280,15.0595}, {-0.7448,2.0280,15.0595}); + oapiVCSetAreaClickmode_Quadrilateral (AID_CDR2_BUTTONS, {-0.6546,2.0490,15.0595}, {-0.4736,2.0490,15.0595}, {-0.6546,2.0280,15.0595}, {-0.4736,2.0280,15.0595}); // D. Beachy: register+activate MFD power buttons const double powerButtonRadius = 0.0075; // radius of power button on each MFD oapiVCRegisterArea (AID_CDR1_PWR, PANEL_REDRAW_NEVER, PANEL_MOUSE_LBDOWN|PANEL_MOUSE_ONREPLAY); oapiVCRegisterArea (AID_CDR2_PWR, PANEL_REDRAW_NEVER, PANEL_MOUSE_LBDOWN|PANEL_MOUSE_ONREPLAY); - oapiVCSetAreaClickmode_Spherical(AID_CDR1_PWR, _V(-0.950, 2.060, 15.060), powerButtonRadius); - oapiVCSetAreaClickmode_Spherical(AID_CDR2_PWR, _V(-0.680, 2.060, 15.060), powerButtonRadius); + oapiVCSetAreaClickmode_Spherical(AID_CDR1_PWR, {-0.950, 2.060, 15.060}, powerButtonRadius); + oapiVCSetAreaClickmode_Spherical(AID_CDR2_PWR, {-0.680, 2.060, 15.060}, powerButtonRadius); // register+activate MFD brightness buttons oapiVCRegisterArea (AID_CDR1_BRT, PANEL_REDRAW_NEVER, PANEL_MOUSE_LBDOWN|PANEL_MOUSE_LBPRESSED|PANEL_MOUSE_ONREPLAY); oapiVCRegisterArea (AID_CDR2_BRT, PANEL_REDRAW_NEVER, PANEL_MOUSE_LBDOWN|PANEL_MOUSE_LBPRESSED|PANEL_MOUSE_ONREPLAY); - oapiVCSetAreaClickmode_Quadrilateral (AID_CDR1_BRT, _V(-0.729,2.0675,15.060), _V(-0.714,2.0675,15.060), _V(-0.729,2.0525,15.060), _V(-0.714,2.0525,15.060)); - oapiVCSetAreaClickmode_Quadrilateral (AID_CDR2_BRT, _V(-0.459,2.0675,15.060), _V(-0.444,2.0675,15.060), _V(-0.459,2.0525,15.060), _V(-0.444,2.0525,15.060)); + oapiVCSetAreaClickmode_Quadrilateral (AID_CDR1_BRT, {-0.729,2.0675,15.060}, {-0.714,2.0675,15.060}, {-0.729,2.0525,15.060}, {-0.714,2.0525,15.060}); + oapiVCSetAreaClickmode_Quadrilateral (AID_CDR2_BRT, {-0.459,2.0675,15.060}, {-0.444,2.0675,15.060}, {-0.459,2.0525,15.060}, {-0.444,2.0525,15.060}); } // -------------------------------------------------------------- @@ -1850,21 +1850,21 @@ void Atlantis::RegisterVC_CdrMFD () void Atlantis::RegisterVC_PltMFD () { // activate MFD function buttons - oapiVCSetAreaClickmode_Quadrilateral (AID_PLT1_BUTTONS, _V(0.4759,2.0490,15.0595), _V(0.6568,2.0490,15.0595), _V(0.4759,2.0280,15.0595), _V(0.6568,2.0280,15.0595)); - oapiVCSetAreaClickmode_Quadrilateral (AID_PLT2_BUTTONS, _V(0.7461,2.0490,15.0595), _V(0.9271,2.0490,15.0595), _V(0.7461,2.0280,15.0595), _V(0.9271,2.0280,15.0595)); + oapiVCSetAreaClickmode_Quadrilateral (AID_PLT1_BUTTONS, {0.4759,2.0490,15.0595}, {0.6568,2.0490,15.0595}, {0.4759,2.0280,15.0595}, {0.6568,2.0280,15.0595}); + oapiVCSetAreaClickmode_Quadrilateral (AID_PLT2_BUTTONS, {0.7461,2.0490,15.0595}, {0.9271,2.0490,15.0595}, {0.7461,2.0280,15.0595}, {0.9271,2.0280,15.0595}); // D. Beachy: register+activate MFD power buttons const double powerButtonRadius = 0.0075; // radius of power button on each MFD oapiVCRegisterArea (AID_PLT1_PWR, PANEL_REDRAW_NEVER, PANEL_MOUSE_LBDOWN|PANEL_MOUSE_ONREPLAY); oapiVCRegisterArea (AID_PLT2_PWR, PANEL_REDRAW_NEVER, PANEL_MOUSE_LBDOWN|PANEL_MOUSE_ONREPLAY); - oapiVCSetAreaClickmode_Spherical(AID_PLT1_PWR, _V( 0.450, 2.060, 15.060), powerButtonRadius); - oapiVCSetAreaClickmode_Spherical(AID_PLT2_PWR, _V( 0.720, 2.060, 15.060), powerButtonRadius); + oapiVCSetAreaClickmode_Spherical(AID_PLT1_PWR, { 0.450, 2.060, 15.060}, powerButtonRadius); + oapiVCSetAreaClickmode_Spherical(AID_PLT2_PWR, { 0.720, 2.060, 15.060}, powerButtonRadius); // register+activate MFD brightness buttons oapiVCRegisterArea (AID_PLT1_BRT, PANEL_REDRAW_NEVER, PANEL_MOUSE_LBDOWN|PANEL_MOUSE_LBPRESSED|PANEL_MOUSE_ONREPLAY); oapiVCRegisterArea (AID_PLT2_BRT, PANEL_REDRAW_NEVER, PANEL_MOUSE_LBDOWN|PANEL_MOUSE_LBPRESSED|PANEL_MOUSE_ONREPLAY); - oapiVCSetAreaClickmode_Quadrilateral (AID_PLT1_BRT, _V(0.671,2.0675,15.060), _V(0.686,2.0675,15.060), _V(0.671,2.0525,15.060), _V(0.686,2.0525,15.060)); - oapiVCSetAreaClickmode_Quadrilateral (AID_PLT2_BRT, _V(0.941,2.0675,15.060), _V(0.956,2.0675,15.060), _V(0.941,2.0525,15.060), _V(0.956,2.0525,15.060)); + oapiVCSetAreaClickmode_Quadrilateral (AID_PLT1_BRT, {0.671,2.0675,15.060}, {0.686,2.0675,15.060}, {0.671,2.0525,15.060}, {0.686,2.0525,15.060}); + oapiVCSetAreaClickmode_Quadrilateral (AID_PLT2_BRT, {0.941,2.0675,15.060}, {0.956,2.0675,15.060}, {0.941,2.0525,15.060}, {0.956,2.0525,15.060}); } // -------------------------------------------------------------- @@ -1874,11 +1874,11 @@ void Atlantis::RegisterVC_PltMFD () void Atlantis::RegisterVC_CntMFD () { // activate MFD function buttons - oapiVCSetAreaClickmode_Quadrilateral (AID_MFD1_BUTTONS, _V(-0.3579,2.1451,15.0863), _V(-0.1770,2.1451,15.0863), _V(-0.3579,2.1241,15.0863), _V(-0.1770,2.1241,15.0863)); - oapiVCSetAreaClickmode_Quadrilateral (AID_MFD2_BUTTONS, _V(-0.3579,1.9143,15.0217), _V(-0.1770,1.9143,15.0217), _V(-0.3579,1.8933,15.0217), _V(-0.1770,1.8933,15.0217)); - oapiVCSetAreaClickmode_Quadrilateral (AID_MFD3_BUTTONS, _V(-0.0888,2.0288,15.0538), _V(0.0922,2.0288,15.0538), _V(-0.0888,2.0078,15.0538), _V(0.0922,2.0078,15.0538)); - oapiVCSetAreaClickmode_Quadrilateral (AID_MFD4_BUTTONS, _V(0.1795,2.1451,15.0863), _V(0.3604,2.1451,15.0863), _V(0.1795,2.1241,15.0863), _V(0.3604,2.1241,15.0863)); - oapiVCSetAreaClickmode_Quadrilateral (AID_MFD5_BUTTONS, _V(0.1795,1.9143,15.0217), _V(0.3604,1.9143,15.0217), _V(0.1795,1.8933,15.0217), _V(0.3604,1.8933,15.0217)); + oapiVCSetAreaClickmode_Quadrilateral (AID_MFD1_BUTTONS, {-0.3579,2.1451,15.0863}, {-0.1770,2.1451,15.0863}, {-0.3579,2.1241,15.0863}, {-0.1770,2.1241,15.0863}); + oapiVCSetAreaClickmode_Quadrilateral (AID_MFD2_BUTTONS, {-0.3579,1.9143,15.0217}, {-0.1770,1.9143,15.0217}, {-0.3579,1.8933,15.0217}, {-0.1770,1.8933,15.0217}); + oapiVCSetAreaClickmode_Quadrilateral (AID_MFD3_BUTTONS, {-0.0888,2.0288,15.0538}, {0.0922,2.0288,15.0538}, {-0.0888,2.0078,15.0538}, {0.0922,2.0078,15.0538}); + oapiVCSetAreaClickmode_Quadrilateral (AID_MFD4_BUTTONS, {0.1795,2.1451,15.0863}, {0.3604,2.1451,15.0863}, {0.1795,2.1241,15.0863}, {0.3604,2.1241,15.0863}); + oapiVCSetAreaClickmode_Quadrilateral (AID_MFD5_BUTTONS, {0.1795,1.9143,15.0217}, {0.3604,1.9143,15.0217}, {0.1795,1.8933,15.0217}, {0.3604,1.8933,15.0217}); // D. Beachy: register+activate MFD power buttons const double powerButtonRadius = 0.0075; // radius of power button on each MFD @@ -1887,11 +1887,11 @@ void Atlantis::RegisterVC_CntMFD () oapiVCRegisterArea (AID_MFD3_PWR, PANEL_REDRAW_NEVER, PANEL_MOUSE_LBDOWN|PANEL_MOUSE_ONREPLAY); oapiVCRegisterArea (AID_MFD4_PWR, PANEL_REDRAW_NEVER, PANEL_MOUSE_LBDOWN|PANEL_MOUSE_ONREPLAY); oapiVCRegisterArea (AID_MFD5_PWR, PANEL_REDRAW_NEVER, PANEL_MOUSE_LBDOWN|PANEL_MOUSE_ONREPLAY); - oapiVCSetAreaClickmode_Spherical(AID_MFD1_PWR, _V(-0.383, 2.153, 15.090), powerButtonRadius); - oapiVCSetAreaClickmode_Spherical(AID_MFD2_PWR, _V(-0.383, 1.922, 15.023), powerButtonRadius); - oapiVCSetAreaClickmode_Spherical(AID_MFD3_PWR, _V(-0.114, 2.037, 15.058), powerButtonRadius); - oapiVCSetAreaClickmode_Spherical(AID_MFD4_PWR, _V( 0.155, 2.153, 15.090), powerButtonRadius); - oapiVCSetAreaClickmode_Spherical(AID_MFD5_PWR, _V( 0.155, 1.922, 15.023), powerButtonRadius); + oapiVCSetAreaClickmode_Spherical(AID_MFD1_PWR, {-0.383, 2.153, 15.090}, powerButtonRadius); + oapiVCSetAreaClickmode_Spherical(AID_MFD2_PWR, {-0.383, 1.922, 15.023}, powerButtonRadius); + oapiVCSetAreaClickmode_Spherical(AID_MFD3_PWR, {-0.114, 2.037, 15.058}, powerButtonRadius); + oapiVCSetAreaClickmode_Spherical(AID_MFD4_PWR, { 0.155, 2.153, 15.090}, powerButtonRadius); + oapiVCSetAreaClickmode_Spherical(AID_MFD5_PWR, { 0.155, 1.922, 15.023}, powerButtonRadius); // register+activate MFD brightness buttons oapiVCRegisterArea (AID_MFD1_BRT, PANEL_REDRAW_NEVER, PANEL_MOUSE_LBDOWN|PANEL_MOUSE_LBPRESSED|PANEL_MOUSE_ONREPLAY); @@ -1899,11 +1899,11 @@ void Atlantis::RegisterVC_CntMFD () oapiVCRegisterArea (AID_MFD3_BRT, PANEL_REDRAW_NEVER, PANEL_MOUSE_LBDOWN|PANEL_MOUSE_LBPRESSED|PANEL_MOUSE_ONREPLAY); oapiVCRegisterArea (AID_MFD4_BRT, PANEL_REDRAW_NEVER, PANEL_MOUSE_LBDOWN|PANEL_MOUSE_LBPRESSED|PANEL_MOUSE_ONREPLAY); oapiVCRegisterArea (AID_MFD5_BRT, PANEL_REDRAW_NEVER, PANEL_MOUSE_LBDOWN|PANEL_MOUSE_LBPRESSED|PANEL_MOUSE_ONREPLAY); - oapiVCSetAreaClickmode_Quadrilateral (AID_MFD1_BRT, _V(-0.162,2.1605,15.090), _V(-0.147,2.1605,15.090), _V(-0.162,2.1455,15.090), _V(-0.147,2.1455,15.090)); - oapiVCSetAreaClickmode_Quadrilateral (AID_MFD2_BRT, _V(-0.162,1.9295,15.023), _V(-0.147,1.9295,15.023), _V(-0.162,1.9145,15.023), _V(-0.147,1.9145,15.023)); - oapiVCSetAreaClickmode_Quadrilateral (AID_MFD3_BRT, _V(0.107,2.0445,15.058), _V(0.122,2.0445,15.058), _V(0.107,2.0295,15.058), _V(0.122,2.0295,15.058)); - oapiVCSetAreaClickmode_Quadrilateral (AID_MFD4_BRT, _V(0.376,2.1605,15.090), _V(0.391,2.1605,15.090), _V(0.376,2.1455,15.090), _V(0.391,2.1455,15.090)); - oapiVCSetAreaClickmode_Quadrilateral (AID_MFD5_BRT, _V(0.376,1.9295,15.023), _V(0.391,1.9295,15.023), _V(0.376,1.9145,15.023), _V(0.391,1.9145,15.023)); + oapiVCSetAreaClickmode_Quadrilateral (AID_MFD1_BRT, {-0.162,2.1605,15.090}, {-0.147,2.1605,15.090}, {-0.162,2.1455,15.090}, {-0.147,2.1455,15.090}); + oapiVCSetAreaClickmode_Quadrilateral (AID_MFD2_BRT, {-0.162,1.9295,15.023}, {-0.147,1.9295,15.023}, {-0.162,1.9145,15.023}, {-0.147,1.9145,15.023}); + oapiVCSetAreaClickmode_Quadrilateral (AID_MFD3_BRT, {0.107,2.0445,15.058}, {0.122,2.0445,15.058}, {0.107,2.0295,15.058}, {0.122,2.0295,15.058}); + oapiVCSetAreaClickmode_Quadrilateral (AID_MFD4_BRT, {0.376,2.1605,15.090}, {0.391,2.1605,15.090}, {0.376,2.1455,15.090}, {0.391,2.1455,15.090}); + oapiVCSetAreaClickmode_Quadrilateral (AID_MFD5_BRT, {0.376,1.9295,15.023}, {0.391,1.9295,15.023}, {0.376,1.9145,15.023}, {0.391,1.9145,15.023}); } // -------------------------------------------------------------- @@ -1915,16 +1915,16 @@ void Atlantis::RegisterVC_AftMFD () // register+activate aft MFD function buttons SURFHANDLE tex1 = oapiGetTextureHandle (hOrbiterVCMesh, 7); oapiVCRegisterArea (AID_MFDA_BUTTONS, _R(0,127,255,140), PANEL_REDRAW_USER, PANEL_MOUSE_LBDOWN|PANEL_MOUSE_LBUP|PANEL_MOUSE_LBPRESSED|PANEL_MOUSE_ONREPLAY, PANEL_MAP_BACKGROUND, tex1); - oapiVCSetAreaClickmode_Quadrilateral (AID_MFDA_BUTTONS, _V(1.3862,2.2570,13.8686), _V(1.3862,2.2570,13.6894), _V(1.3678,2.2452,13.8686), _V(1.3678,2.2452,13.6894)); + oapiVCSetAreaClickmode_Quadrilateral (AID_MFDA_BUTTONS, {1.3862,2.2570,13.8686}, {1.3862,2.2570,13.6894}, {1.3678,2.2452,13.8686}, {1.3678,2.2452,13.6894}); // register+activate MFD power button const double powerButtonRadius = 0.0075; // radius of power button on each MFD oapiVCRegisterArea (AID_MFDA_PWR, PANEL_REDRAW_NEVER, PANEL_MOUSE_LBDOWN|PANEL_MOUSE_ONREPLAY); - oapiVCSetAreaClickmode_Spherical(AID_MFDA_PWR, _V(1.3929,2.2632,13.8947), powerButtonRadius); + oapiVCSetAreaClickmode_Spherical(AID_MFDA_PWR, {1.3929,2.2632,13.8947}, powerButtonRadius); // register+activate MFD brightness buttons oapiVCRegisterArea (AID_MFDA_BRT, PANEL_REDRAW_NEVER, PANEL_MOUSE_LBDOWN|PANEL_MOUSE_LBPRESSED|PANEL_MOUSE_ONREPLAY); - oapiVCSetAreaClickmode_Quadrilateral (AID_MFDA_BRT, _V(1.4024,2.2675,13.6736), _V(1.4024,2.2675,13.6586), _V(1.3893,2.2590,13.6736), _V(1.3893,2.2590,13.6586)); + oapiVCSetAreaClickmode_Quadrilateral (AID_MFDA_BRT, {1.4024,2.2675,13.6736}, {1.4024,2.2675,13.6586}, {1.3893,2.2590,13.6736}, {1.3893,2.2590,13.6586}); } // -------------------------------------------------------------- @@ -1976,10 +1976,10 @@ bool Atlantis::clbkLoadVC (int id) switch (id) { case 0: // commander position - SetCameraOffset (_V(-0.67,2.55,14.4)); - SetCameraDefaultDirection (_V(0,0,1)); - SetCameraMovement (_V(0,0,0.3), 0, 0, _V(-0.3,0,0), 75*RAD, -5*RAD, _V(0.3,0,0), -20*RAD, -27*RAD); - huds.hudcnt = _V(-0.671257, 2.523535, 14.969); + SetCameraOffset ({-0.67,2.55,14.4}); + SetCameraDefaultDirection ({0,0,1}); + SetCameraMovement ({0,0,0.3}, 0, 0, {-0.3,0,0}, 75*RAD, -5*RAD, {0.3,0,0}, -20*RAD, -27*RAD); + huds.hudcnt = {-0.671257, 2.523535, 14.969}; oapiVCSetNeighbours (-1, 1, -1, 2); RegisterVC_CdrMFD (); // activate commander MFD controls @@ -1988,10 +1988,10 @@ bool Atlantis::clbkLoadVC (int id) ok = true; break; case 1: // pilot position - SetCameraOffset (_V(0.67,2.55,14.4)); - SetCameraDefaultDirection (_V(0,0,1)); - SetCameraMovement (_V(0,0,0.3), 0, 0, _V(-0.3,0,0), 20*RAD, -27*RAD, _V(0.3,0,0), -75*RAD, -5*RAD); - huds.hudcnt = _V(0.671257, 2.523535, 14.969); + SetCameraOffset ({0.67,2.55,14.4}); + SetCameraDefaultDirection ({0,0,1}); + SetCameraMovement ({0,0,0.3}, 0, 0, {-0.3,0,0}, 20*RAD, -27*RAD, {0.3,0,0}, -75*RAD, -5*RAD); + huds.hudcnt = {0.671257, 2.523535, 14.969}; oapiVCSetNeighbours (0, -1, -1, 2); RegisterVC_PltMFD (); // activate pilot MFD controls @@ -2000,9 +2000,9 @@ bool Atlantis::clbkLoadVC (int id) ok = true; break; case 2: // payload view position - SetCameraOffset (_V(0.4,3.15,13.0)); - SetCameraDefaultDirection (_V(0,0,-1)); - SetCameraMovement (_V(0,-0.1,-0.1), 0, 80.0*RAD, _V(0.3,-0.3,0.15), 60.0*RAD, -50.0*RAD, _V(-0.8,0,0), 0, 0); + SetCameraOffset ({0.4,3.15,13.0}); + SetCameraDefaultDirection ({0,0,-1}); + SetCameraMovement ({0,-0.1,-0.1}, 0, 80.0*RAD, {0.3,-0.3,0.15}, 60.0*RAD, -50.0*RAD, {-0.8,0,0}, 0, 0); oapiVCSetNeighbours (1, 0, -1, 0); RegisterVC_AftMFD (); // activate aft MFD controls diff --git a/Src/Vessel/Atlantis/Atlantis/PlBayOp.cpp b/Src/Vessel/Atlantis/Atlantis/PlBayOp.cpp index e22b69bcd..dbbfa6147 100644 --- a/Src/Vessel/Atlantis/Atlantis/PlBayOp.cpp +++ b/Src/Vessel/Atlantis/Atlantis/PlBayOp.cpp @@ -365,7 +365,7 @@ void PayloadBayOp::RegisterVC () // register the complete panel for mouse events oapiVCRegisterArea (AID_R13L, PANEL_REDRAW_NEVER, PANEL_MOUSE_LBDOWN); - oapiVCSetAreaClickmode_Quadrilateral (AID_R13L, _V(1.3543,2.23023,12.8581), _V(1.3543,2.23023,12.5486), _V(1.0868,2.0547,12.8581), _V(1.0868,2.0547,12.5486)); + oapiVCSetAreaClickmode_Quadrilateral (AID_R13L, {1.3543,2.23023,12.8581}, {1.3543,2.23023,12.5486}, {1.0868,2.0547,12.8581}, {1.0868,2.0547,12.5486}); // register the talkbacks oapiVCRegisterArea (AID_R13L_TKBK1, _R( 0,0, 32,18), PANEL_REDRAW_USER, PANEL_MOUSE_IGNORE, PANEL_MAP_NONE, tkbk_tex); diff --git a/Src/Vessel/Atlantis/Atlantis_SRB/Atlantis_SRB.cpp b/Src/Vessel/Atlantis/Atlantis_SRB/Atlantis_SRB.cpp index 280adc3c4..aa1dc35e5 100644 --- a/Src/Vessel/Atlantis/Atlantis_SRB/Atlantis_SRB.cpp +++ b/Src/Vessel/Atlantis/Atlantis_SRB/Atlantis_SRB.cpp @@ -25,19 +25,19 @@ static const int ntdvtx = 13; static const TOUCHDOWNVTX tdvtx[ntdvtx] = { - {_V( 0, 2.5, -21.18), 1e9, 1e7, 0.3 }, - {_V( 2.1651,-1.25,-21.18), 1e9, 1e7, 0.3 }, - {_V(-2.1651,-1.25,-21.18), 1e9, 1e7, 0.3 }, - {_V( 2.1651, 1.25,-21.18), 1e9, 1e7, 0.3 }, - {_V( 0, -2.5 ,-21.18), 1e9, 1e7, 0.3 }, - {_V(-2.1651, 1.25,-21.18), 1e9, 1e7, 0.3 }, - {_V( 0, 1.85, 18.95), 1e9, 1e7, 0.3 }, - {_V( 1.6021,-0.925,18.95), 1e9, 1e7, 0.3 }, - {_V(-1.6021,-0.925,18.95), 1e9, 1e7, 0.3 }, - {_V( 1.6021, 0.925,18.95), 1e9, 1e7, 0.3 }, - {_V( 0, -1.85, 18.95), 1e9, 1e7, 0.3 }, - {_V(-1.6021, 0.925,18.95), 1e9, 1e7, 0.3 }, - {_V( 0, 0, 23.78), 1e9, 1e7, 0.3 } + {{ 0, 2.5, -21.18}, 1e9, 1e7, 0.3 }, + {{ 2.1651,-1.25,-21.18}, 1e9, 1e7, 0.3 }, + {{-2.1651,-1.25,-21.18}, 1e9, 1e7, 0.3 }, + {{ 2.1651, 1.25,-21.18}, 1e9, 1e7, 0.3 }, + {{ 0, -2.5 ,-21.18}, 1e9, 1e7, 0.3 }, + {{-2.1651, 1.25,-21.18}, 1e9, 1e7, 0.3 }, + {{ 0, 1.85, 18.95}, 1e9, 1e7, 0.3 }, + {{ 1.6021,-0.925,18.95}, 1e9, 1e7, 0.3 }, + {{-1.6021,-0.925,18.95}, 1e9, 1e7, 0.3 }, + {{ 1.6021, 0.925,18.95}, 1e9, 1e7, 0.3 }, + {{ 0, -1.85, 18.95}, 1e9, 1e7, 0.3 }, + {{-1.6021, 0.925,18.95}, 1e9, 1e7, 0.3 }, + {{ 0, 0, 23.78}, 1e9, 1e7, 0.3 } }; // Constructor @@ -153,16 +153,16 @@ void Atlantis_SRB::clbkSetClassCaps (FILEHANDLE cfg) SetSize (23.0); SetEmptyMass (SRB_EMPTY_MASS); SetCW (0.1, 0.3, 1.4, 1.4); - SetCrossSections (_V(162.1,162.1,26.6)); - SetRotDrag (_V(0.7,0.7,0.1)); - SetPMI (_V(154.3,154.3,1.83)); + SetCrossSections ({162.1,162.1,26.6}); + SetRotDrag ({0.7,0.7,0.1}); + SetPMI ({154.3,154.3,1.83}); //SetGravityGradientDamping (10.0); SetTouchdownPoints (tdvtx, ntdvtx); SetLiftCoeffFunc (0); // ************************* docking port ************************************** - CreateDock (_V(1.95,0,5),_V(1,0,0),_V(0,0,1)); // ET attachment + CreateDock ({1.95,0,5},{1,0,0},{0,0,1}); // ET attachment // ************************* propellant specs ********************************** @@ -171,21 +171,21 @@ void Atlantis_SRB::clbkSetClassCaps (FILEHANDLE cfg) // *********************** thruster definitions ******************************** // main engine - th_main = CreateThruster (_V(0,0,-21), THRUSTGIMBAL_LAUNCH, SRB_THRUST, ph_main, SRB_ISP0, SRB_ISP1); + th_main = CreateThruster ({0,0,-21}, THRUSTGIMBAL_LAUNCH, SRB_THRUST, ph_main, SRB_ISP0, SRB_ISP1); SURFHANDLE tex = oapiRegisterExhaustTexture ((char*)"Exhaust2"); srb_exhaust.tex = oapiRegisterParticleTexture ((char*)"Contrail2"); AddExhaust (th_main, 16.0, 2.0, tex); - AddExhaustStream (th_main, _V(0,0,-30), &srb_contrail); - AddExhaustStream (th_main, _V(0,0,-25), &srb_exhaust); + AddExhaustStream (th_main, {0,0,-30}, &srb_contrail); + AddExhaustStream (th_main, {0,0,-25}, &srb_exhaust); // separation bolts - th_bolt = CreateThruster (_V(0,0,3.0), _V(-1,0,0), 3e6, ph_main, 1e7); + th_bolt = CreateThruster ({0,0,3.0}, {-1,0,0}, 3e6, ph_main, 1e7); // for simplicity, the separation bolts directly use SRB propellant. We give // them an insanely high ISP to avoid significant propellant drainage - AddExhaust (th_bolt, 0.7, 0.1, _V(2.1,0,-8), _V(-1,0,0)); - AddExhaust (th_bolt, 0.7, 0.1, _V(2.1,0,11), _V(-1,0,0)); - AddExhaustStream (th_bolt, _V(2.1,0,0), &srb_bolt); + AddExhaust (th_bolt, 0.7, 0.1, {2.1,0,-8}, {-1,0,0}); + AddExhaust (th_bolt, 0.7, 0.1, {2.1,0,11}, {-1,0,0}); + AddExhaustStream (th_bolt, {2.1,0,0}, &srb_bolt); // ************************ visual parameters ********************************** @@ -212,7 +212,7 @@ void Atlantis_SRB::clbkPostCreation () } } if (srbpos != SRB_UNDEFINED) - SetThrusterDir(th_bolt, srbpos == SRB_LEFT ? _V(-0.4,-0.9165,0) : _V(-0.4,0.9165,0)); + SetThrusterDir(th_bolt, srbpos == SRB_LEFT ? VECTOR3{-0.4,-0.9165,0} : VECTOR3{-0.4,0.9165,0}); } // Read current state @@ -260,7 +260,7 @@ void Atlantis_SRB::clbkPostStep (double simt, double simdt, double mjd) double dg_max = simdt*SRB_GIMBAL_SPEED; VECTOR3 gimbalcur = GetThrustGimbal(); VECTOR3 gdiff = gimbalcmd-gimbalcur; - double dg = length(gdiff); + double dg = len(gdiff); if (dg > dg_max) { gdiff *= dg_max/dg; } else { diff --git a/Src/Vessel/Atlantis/Atlantis_Tank/Atlantis_Tank.cpp b/Src/Vessel/Atlantis/Atlantis_Tank/Atlantis_Tank.cpp index 0161d073a..e190e1973 100644 --- a/Src/Vessel/Atlantis/Atlantis_Tank/Atlantis_Tank.cpp +++ b/Src/Vessel/Atlantis/Atlantis_Tank/Atlantis_Tank.cpp @@ -19,21 +19,21 @@ static const int ntdvtx = 15; static const TOUCHDOWNVTX tdvtx[ntdvtx] = { - {_V( 0, 5.85, 3.1 ), 1e9, 1e7, 0.3 }, - {_V( 2.4, 5.1, -21.3 ), 1e9, 1e7, 0.3 }, - {_V(-2.4, 5.1, -21.3 ), 1e9, 1e7, 0.3 }, - {_V( 4.2, 0, -21 ), 1e9, 1e7, 0.3 }, - {_V( 2.1,-3.637,-21 ), 1e9, 1e7, 0.3 }, - {_V(-2.1,-3.637,-21 ), 1e9, 1e7, 0.3 }, - {_V(-4.2, 0, -21 ), 1e9, 1e7, 0.3 }, - {_V( 4.2, 0, 15 ), 1e9, 1e7, 0.3 }, - {_V( 2.1,-3.637,15 ), 1e9, 1e7, 0.3 }, - {_V(-2.1,-3.637,15 ), 1e9, 1e7, 0.3 }, - {_V(-4.2, 0, 15 ), 1e9, 1e7, 0.3 }, - {_V(-2.1, 3.637,15 ), 1e9, 1e7, 0.3 }, - {_V( 2.1, 3.637,15 ), 1e9, 1e7, 0.3 }, - {_V( 0, 0, -23.57), 1e9, 1e7, 0.3 }, - {_V( 0, 0, 23.57), 1e9, 1e7, 0.3 } + {{ 0, 5.85, 3.1 }, 1e9, 1e7, 0.3 }, + {{ 2.4, 5.1, -21.3 }, 1e9, 1e7, 0.3 }, + {{-2.4, 5.1, -21.3 }, 1e9, 1e7, 0.3 }, + {{ 4.2, 0, -21 }, 1e9, 1e7, 0.3 }, + {{ 2.1,-3.637,-21 }, 1e9, 1e7, 0.3 }, + {{-2.1,-3.637,-21 }, 1e9, 1e7, 0.3 }, + {{-4.2, 0, -21 }, 1e9, 1e7, 0.3 }, + {{ 4.2, 0, 15 }, 1e9, 1e7, 0.3 }, + {{ 2.1,-3.637,15 }, 1e9, 1e7, 0.3 }, + {{-2.1,-3.637,15 }, 1e9, 1e7, 0.3 }, + {{-4.2, 0, 15 }, 1e9, 1e7, 0.3 }, + {{-2.1, 3.637,15 }, 1e9, 1e7, 0.3 }, + {{ 2.1, 3.637,15 }, 1e9, 1e7, 0.3 }, + {{ 0, 0, -23.57}, 1e9, 1e7, 0.3 }, + {{ 0, 0, 23.57}, 1e9, 1e7, 0.3 } }; // ============================================================== @@ -52,9 +52,9 @@ Atlantis_Tank::Atlantis_Tank (OBJHANDLE hObj) hProp = CreatePropellantResource (TANK_MAX_PROPELLANT_MASS); // docking ports - CreateDock (_V(0,5.5,-5), _V(0,1,0), _V(0,0,1)); // orbiter attachment - CreateDock (_V(-4.25,0,-6.4), _V(-1,0,0), _V(0,0,1)); // left SRB attachment - CreateDock (_V( 4.25,0,-6.4), _V( 1,0,0), _V(0,0,1)); // right SRB attachment + CreateDock ({0,5.5,-5}, {0,1,0}, {0,0,1}); // orbiter attachment + CreateDock ({-4.25,0,-6.4}, {-1,0,0}, {0,0,1}); // left SRB attachment + CreateDock ({ 4.25,0,-6.4}, { 1,0,0}, {0,0,1}); // right SRB attachment // by default, disable orbiter and SRB connectors hDockOrbiter = NULL; @@ -107,7 +107,7 @@ void Atlantis_Tank::clbkSetClassCaps (FILEHANDLE cfg) // since the Tank doesn't define a 'cockpit' SetCOG_elev (-5.0); - //SetTouchdownPoints (_V(0,9,3), _V(-1,1,-3), _V(1,1,-3)); + //SetTouchdownPoints ({0,9,3}, {-1,1,-3}, {1,1,-3}); SetTouchdownPoints (tdvtx, ntdvtx); SetLiftCoeffFunc (0); @@ -150,7 +150,7 @@ Atlantis_SRB *Atlantis_Tank::GetSRB (int which) const void Atlantis_Tank::EnableOrbiterConnector () { //if (!hDockOrbiter) { - // hDockOrbiter = CreateDock (_V(0.0, 4.64, -9.285), _V(0,1,0), _V(1,0,0)); + // hDockOrbiter = CreateDock ({0.0, 4.64, -9.285}, {0,1,0}, {1,0,0}); //} } @@ -192,7 +192,7 @@ void Atlantis_Tank::SetSRBGimbal (const VECTOR3 &angle) const VECTOR3 Atlantis_Tank::GetSRBThrustDir (int which) const { if (pSRB[which]) return pSRB[which]->GetThrustGimbal(); - else return _V(0,0,1); + else return {0,0,1}; } bool Atlantis_Tank::IgniteSRBs () const @@ -218,7 +218,7 @@ void Atlantis_Tank::SeparateSRBs () for (int i = 0; i < 2; i++) { if (pSRB[i]) { const double angle = 0.25*PI; - VECTOR3 dir = _V(0.0, i ? -0.04 : 0.04, 0.9992); + VECTOR3 dir = {0.0, i ? -0.04 : 0.04, 0.9992}; Undock (i+1); pSRB[i]->CmdThrustGimbal (dir); // set SRB gimbals for safe separation pSRB[i]->FireBolt(); diff --git a/Src/Vessel/DeltaGlider/AerodynSubsys.cpp b/Src/Vessel/DeltaGlider/AerodynSubsys.cpp index 114396f8d..1bbcee667 100644 --- a/Src/Vessel/DeltaGlider/AerodynSubsys.cpp +++ b/Src/Vessel/DeltaGlider/AerodynSubsys.cpp @@ -226,14 +226,14 @@ Airbrake::Airbrake (AerodynCtrlSubsystem *_subsys) static UINT LRudderGrp[2] = {GRP_LRudder1,GRP_LRudder2}; static UINT UpperBrakeGrp[4] = {GRP_RUAileron1,GRP_LUAileron1,GRP_LUAileron2,GRP_RUAileron2}; static MGROUP_ROTATE UpperBrake (0, UpperBrakeGrp, 4, - _V(0,-0.4,-6.0), _V(1,0,0), (float)(50*RAD)); + {0,-0.4,-6.0}, {1,0,0}, (float)(50*RAD)); static UINT LowerBrakeGrp[4] = {GRP_LLAileron1,GRP_RLAileron1,GRP_LLAileron2,GRP_RLAileron2}; static MGROUP_ROTATE LowerBrake (0, LowerBrakeGrp, 4, - _V(0,-0.4,-6.0), _V(1,0,0), (float)(-50*RAD)); + {0,-0.4,-6.0}, {1,0,0}, (float)(-50*RAD)); static MGROUP_ROTATE RRudderBrake (0, RRudderGrp, 2, - _V( 8.668,0.958,-6.204), _V( 0.143,0.975,-0.172), (float)( 25*RAD)); + { 8.668,0.958,-6.204}, { 0.143,0.975,-0.172}, (float)( 25*RAD)); static MGROUP_ROTATE LRudderBrake (0, LRudderGrp, 2, - _V(-8.668,0.958,-6.204), _V(-0.143,0.975,-0.172), (float)(-25*RAD)); + {-8.668,0.958,-6.204}, {-0.143,0.975,-0.172}, (float)(-25*RAD)); anim_brake = DG()->CreateAnimation (0); DG()->AddAnimationComponent (anim_brake, 0, 1, &UpperBrake); diff --git a/Src/Vessel/DeltaGlider/DeltaGlider.cpp b/Src/Vessel/DeltaGlider/DeltaGlider.cpp index 8d5e710f8..fa3d74981 100644 --- a/Src/Vessel/DeltaGlider/DeltaGlider.cpp +++ b/Src/Vessel/DeltaGlider/DeltaGlider.cpp @@ -55,36 +55,36 @@ static HELPCONTEXT g_hc = { static const DWORD ntdvtx_geardown = 13; static TOUCHDOWNVTX tdvtx_geardown[ntdvtx_geardown] = { - {_V( 0 ,-2.57,10 ), 1e6, 1e5, 1.6, 0.1}, - {_V(-3.5 ,-2.57,-1 ), 1e6, 1e5, 3.0, 0.2}, - {_V( 3.5 ,-2.57,-1 ), 1e6, 1e5, 3.0, 0.2}, - {_V(-8.5 ,-0.3 ,-7.05), 1e7, 1e5, 3.0}, - {_V( 8.5 ,-0.3 ,-7.05), 1e7, 1e5, 3.0}, - {_V(-8.5 ,-0.4 ,-3 ), 1e7, 1e5, 3.0}, - {_V( 8.5 ,-0.4 ,-3 ), 1e7, 1e5, 3.0}, - {_V(-8.85, 2.3 ,-5.05), 1e7, 1e5, 3.0}, - {_V( 8.85, 2.3 ,-5.05), 1e7, 1e5, 3.0}, - {_V(-8.85, 2.3 ,-7.05), 1e7, 1e5, 3.0}, - {_V( 8.85, 2.3 ,-7.05), 1e7, 1e5, 3.0}, - {_V( 0 , 2 , 6.2 ), 1e7, 1e5, 3.0}, - {_V( 0 ,-0.6 ,10.65), 1e7, 1e5, 3.0} + {{ 0 ,-2.57,10 }, 1e6, 1e5, 1.6, 0.1}, + {{-3.5 ,-2.57,-1 }, 1e6, 1e5, 3.0, 0.2}, + {{ 3.5 ,-2.57,-1 }, 1e6, 1e5, 3.0, 0.2}, + {{-8.5 ,-0.3 ,-7.05}, 1e7, 1e5, 3.0}, + {{ 8.5 ,-0.3 ,-7.05}, 1e7, 1e5, 3.0}, + {{-8.5 ,-0.4 ,-3 }, 1e7, 1e5, 3.0}, + {{ 8.5 ,-0.4 ,-3 }, 1e7, 1e5, 3.0}, + {{-8.85, 2.3 ,-5.05}, 1e7, 1e5, 3.0}, + {{ 8.85, 2.3 ,-5.05}, 1e7, 1e5, 3.0}, + {{-8.85, 2.3 ,-7.05}, 1e7, 1e5, 3.0}, + {{ 8.85, 2.3 ,-7.05}, 1e7, 1e5, 3.0}, + {{ 0 , 2 , 6.2 }, 1e7, 1e5, 3.0}, + {{ 0 ,-0.6 ,10.65}, 1e7, 1e5, 3.0} }; static const DWORD ntdvtx_gearup = 13; static TOUCHDOWNVTX tdvtx_gearup[ntdvtx_gearup] = { - {_V( 0 ,-1.5 ,9), 1e7, 1e5, 3.0, 3.0}, - {_V(-6 ,-0.8 ,-5), 1e7, 1e5, 3.0, 3.0}, - {_V( 3 ,-1.2 ,-5), 1e7, 1e5, 3.0, 3.0}, - {_V(-8.5 ,-0.3 ,-7.05), 1e7, 1e5, 3.0}, - {_V( 8.5 ,-0.3 ,-7.05), 1e7, 1e5, 3.0}, - {_V(-8.5 ,-0.4 ,-3 ), 1e7, 1e5, 3.0}, - {_V( 8.5 ,-0.4 ,-3 ), 1e7, 1e5, 3.0}, - {_V(-8.85, 2.3 ,-5.05), 1e7, 1e5, 3.0}, - {_V( 8.85, 2.3 ,-5.05), 1e7, 1e5, 3.0}, - {_V(-8.85, 2.3 ,-7.05), 1e7, 1e5, 3.0}, - {_V( 8.85, 2.3 ,-7.05), 1e7, 1e5, 3.0}, - {_V( 0 , 2 , 6.2 ), 1e7, 1e5, 3.0}, - {_V( 0 ,-0.6 ,10.65), 1e7, 1e5, 3.0} + {{ 0 ,-1.5 ,9}, 1e7, 1e5, 3.0, 3.0}, + {{-6 ,-0.8 ,-5}, 1e7, 1e5, 3.0, 3.0}, + {{ 3 ,-1.2 ,-5}, 1e7, 1e5, 3.0, 3.0}, + {{-8.5 ,-0.3 ,-7.05}, 1e7, 1e5, 3.0}, + {{ 8.5 ,-0.3 ,-7.05}, 1e7, 1e5, 3.0}, + {{-8.5 ,-0.4 ,-3 }, 1e7, 1e5, 3.0}, + {{ 8.5 ,-0.4 ,-3 }, 1e7, 1e5, 3.0}, + {{-8.85, 2.3 ,-5.05}, 1e7, 1e5, 3.0}, + {{ 8.85, 2.3 ,-5.05}, 1e7, 1e5, 3.0}, + {{-8.85, 2.3 ,-7.05}, 1e7, 1e5, 3.0}, + {{ 8.85, 2.3 ,-7.05}, 1e7, 1e5, 3.0}, + {{ 0 , 2 , 6.2 }, 1e7, 1e5, 3.0}, + {{ 0 ,-0.6 ,10.65}, 1e7, 1e5, 3.0} }; // ============================================================== @@ -242,10 +242,10 @@ void DeltaGlider::DefineAnimations () // ***** Rudder animation ***** static UINT RRudderGrp[2] = {GRP_RRudder1,GRP_RRudder2}; static MGROUP_ROTATE RRudder (0, RRudderGrp, 2, - _V( 8.668,0.958,-6.204), _V( 0.143,0.975,-0.172), (float)(-60*RAD)); + { 8.668,0.958,-6.204}, { 0.143,0.975,-0.172}, (float)(-60*RAD)); static UINT LRudderGrp[2] = {GRP_LRudder1,GRP_LRudder2}; static MGROUP_ROTATE LRudder (0, LRudderGrp, 2, - _V(-8.668,0.958,-6.204), _V(-0.143,0.975,-0.172), (float)(-60*RAD)); + {-8.668,0.958,-6.204}, {-0.143,0.975,-0.172}, (float)(-60*RAD)); anim_rudder = CreateAnimation (0.5); AddAnimationComponent (anim_rudder, 0, 1, &RRudder); AddAnimationComponent (anim_rudder, 0, 1, &LRudder); @@ -253,26 +253,26 @@ void DeltaGlider::DefineAnimations () // ***** Elevator animation ***** static UINT ElevatorGrp[8] = {GRP_LUAileron1,GRP_LUAileron2,GRP_LLAileron1,GRP_LLAileron2,GRP_RUAileron1,GRP_RUAileron2,GRP_RLAileron1,GRP_RLAileron2}; static MGROUP_ROTATE Elevator (0, ElevatorGrp, 8, - _V(0,-0.4,-6.0), _V(1,0,0), (float)(40*RAD)); + {0,-0.4,-6.0}, {1,0,0}, (float)(40*RAD)); anim_elevator = CreateAnimation (0.5); AddAnimationComponent (anim_elevator, 0, 1, &Elevator); // ***** Elevator trim animation ***** static MGROUP_ROTATE ElevatorTrim (0, ElevatorGrp, 8, - _V(0,-0.4,-6.0), _V(1,0,0), (float)(10*RAD)); + {0,-0.4,-6.0}, {1,0,0}, (float)(10*RAD)); anim_elevatortrim = CreateAnimation (0.5); AddAnimationComponent (anim_elevatortrim, 0, 1, &ElevatorTrim); // ***** Aileron animation ***** static UINT LAileronGrp[4] = {GRP_LUAileron1,GRP_LUAileron2,GRP_LLAileron1,GRP_LLAileron2}; static MGROUP_ROTATE LAileron (0, LAileronGrp, 4, - _V(0,-0.4,-6.0), _V(1,0,0), (float)(-20*RAD)); + {0,-0.4,-6.0}, {1,0,0}, (float)(-20*RAD)); anim_laileron = CreateAnimation (0.5); AddAnimationComponent (anim_laileron, 0, 1, &LAileron); static UINT RAileronGrp[4] = {GRP_RUAileron1,GRP_RUAileron2,GRP_RLAileron1,GRP_RLAileron2}; static MGROUP_ROTATE RAileron (0, RAileronGrp, 4, - _V(0,-0.4,-6.0), _V(1,0,0), (float)(20*RAD)); + {0,-0.4,-6.0}, {1,0,0}, (float)(20*RAD)); anim_raileron = CreateAnimation (0.5); AddAnimationComponent (anim_raileron, 0, 1, &RAileron); } @@ -612,7 +612,7 @@ void DeltaGlider::ApplyDamage () { double balance = (rwingstatus-lwingstatus)*3.0; double surf = (rwingstatus+lwingstatus)*35.0 + 20.0; - EditAirfoil (hwing, 0x09, _V(balance,0,-0.3), 0, 0, surf, 0); + EditAirfoil (hwing, 0x09, {balance,0,-0.3}, 0, 0, surf, 0); if (rwingstatus < 1 || lwingstatus < 1) ssys_failure->MWSActivate(); @@ -624,11 +624,11 @@ void DeltaGlider::RepairDamage () { int i; lwingstatus = rwingstatus = 1.0; - EditAirfoil (hwing, 0x09, _V(0,0,-0.3), 0, 0, 90.0, 0); + EditAirfoil (hwing, 0x09, {0,0,-0.3}, 0, 0, 90.0, 0); if (!hlaileron) - hlaileron = CreateControlSurface2 (AIRCTRL_AILERON, 0.3, 1.5, _V( 7.5,0,-7.2), AIRCTRL_AXIS_XPOS, anim_raileron); + hlaileron = CreateControlSurface2 (AIRCTRL_AILERON, 0.3, 1.5, { 7.5,0,-7.2}, AIRCTRL_AXIS_XPOS, anim_raileron); if (!hraileron) - hraileron = CreateControlSurface2 (AIRCTRL_AILERON, 0.3, 1.5, _V(-7.5,0,-7.2), AIRCTRL_AXIS_XNEG, anim_laileron); + hraileron = CreateControlSurface2 (AIRCTRL_AILERON, 0.3, 1.5, {-7.5,0,-7.2}, AIRCTRL_AXIS_XNEG, anim_laileron); for (i = 0; i < 4; i++) aileronfail[i] = false; ssys_pressurectrl->RepairDamage (); @@ -885,16 +885,16 @@ void DeltaGlider::clbkSetClassCaps (FILEHANDLE cfg) VECTOR3 r[2] = {{0,0,6}, {0,0,-4}}; SetSize (10.0); SetVisibilityLimit (7.5e-4, 1.5e-3); - SetAlbedoRGB (_V(0.77,0.20,0.13)); + SetAlbedoRGB ({0.77,0.20,0.13}); SetGravityGradientDamping (20.0); SetCW (0.09, 0.09, 2, 1.4); SetWingAspect (0.7); SetWingEffectiveness (2.5); - SetCrossSections (_V(53.0,186.9,25.9)); + SetCrossSections ({53.0,186.9,25.9}); SetMaxWheelbrakeForce (2e5); - SetPMI (_V(15.5,22.1,7.7)); + SetPMI ({15.5,22.1,7.7}); - SetDockParams (_V(0,-0.49,10.076), _V(0,0,1), _V(0,1,0)); + SetDockParams ({0,-0.49,10.076}, {0,0,1}, {0,1,0}); SetTouchdownPoints (tdvtx_geardown, ntdvtx_geardown); SetNosewheelSteering (true); bGearIsDown = true; @@ -946,34 +946,34 @@ void DeltaGlider::clbkSetClassCaps (FILEHANDLE cfg) }; // main thrusters - th_main[0] = CreateThruster (_V(-1,0.0,-7.7), _V(0,0,1), MAX_MAIN_THRUST[modelidx], ph_main, ISP, ISP*ispscale); - th_main[1] = CreateThruster (_V( 1,0.0,-7.7), _V(0,0,1), MAX_MAIN_THRUST[modelidx], ph_main, ISP, ISP*ispscale); + th_main[0] = CreateThruster ({-1,0.0,-7.7}, {0,0,1}, MAX_MAIN_THRUST[modelidx], ph_main, ISP, ISP*ispscale); + th_main[1] = CreateThruster ({ 1,0.0,-7.7}, {0,0,1}, MAX_MAIN_THRUST[modelidx], ph_main, ISP, ISP*ispscale); thg_main = CreateThrusterGroup (th_main, 2, THGROUP_MAIN); EXHAUSTSPEC es_main[2] = { {th_main[0], NULL, NULL, NULL, 12, 1, 0, 0.1, NULL}, {th_main[1], NULL, NULL, NULL, 12, 1, 0, 0.1, NULL} }; for (i = 0; i < 2; i++) AddExhaust (es_main+i); - AddExhaustStream (th_main[0], _V(-1,0,-15), &contrail); - AddExhaustStream (th_main[1], _V( 1,0,-15), &contrail); - AddExhaustStream (th_main[0], _V(-1,0,-10), &exhaust_main); - AddExhaustStream (th_main[1], _V( 1,0,-10), &exhaust_main); + AddExhaustStream (th_main[0], {-1,0,-15}, &contrail); + AddExhaustStream (th_main[1], { 1,0,-15}, &contrail); + AddExhaustStream (th_main[0], {-1,0,-10}, &exhaust_main); + AddExhaustStream (th_main[1], { 1,0,-10}, &exhaust_main); //DWORD i = GetGroupThrusterCount (THGROUP_MAIN); // retro thrusters // note that we have to tilt retros slightly downwards to avoid inducing // an angular momentum, since they are mounted below the level of CG. // This also means that retros will induce an upward linear component. - th_retro[0] = CreateThruster (_V(-3,-0.236,5.6), _V(0,0.04210548,-0.99911317), MAX_RETRO_THRUST, ph_main, ISP, ISP*ispscale); - th_retro[1] = CreateThruster (_V( 3,-0.236,5.6), _V(0,0.04210548,-0.99911317), MAX_RETRO_THRUST, ph_main, ISP, ISP*ispscale); + th_retro[0] = CreateThruster ({-3,-0.236,5.6}, {0,0.04210548,-0.99911317}, MAX_RETRO_THRUST, ph_main, ISP, ISP*ispscale); + th_retro[1] = CreateThruster ({ 3,-0.236,5.6}, {0,0.04210548,-0.99911317}, MAX_RETRO_THRUST, ph_main, ISP, ISP*ispscale); thg_retro = CreateThrusterGroup (th_retro, 2, THGROUP_RETRO); EXHAUSTSPEC es_retro[2] = {{th_retro[0], NULL, NULL, NULL, 3, 0.4, 0, 0.1, NULL}, {th_retro[1], NULL, NULL, NULL, 3, 0.4, 0, 0.1, NULL}}; for (i = 0; i < 2; i++) AddExhaust (es_retro+i); // hover thrusters - th_hover[0] = CreateThruster (_V(0,0,3), _V(0,1,0), MAX_HOVER_THRUST[modelidx], ph_main, ISP, ISP*ispscale); - th_hover[1] = CreateThruster (_V(-3,0,-4.55), _V(0,1,0), 3.0/4.55*0.5*MAX_HOVER_THRUST[modelidx], ph_main, ISP, ISP*ispscale); - th_hover[2] = CreateThruster (_V( 3,0,-4.55), _V(0,1,0), 3.0/4.55*0.5*MAX_HOVER_THRUST[modelidx], ph_main, ISP, ISP*ispscale); + th_hover[0] = CreateThruster ({0,0,3}, {0,1,0}, MAX_HOVER_THRUST[modelidx], ph_main, ISP, ISP*ispscale); + th_hover[1] = CreateThruster ({-3,0,-4.55}, {0,1,0}, 3.0/4.55*0.5*MAX_HOVER_THRUST[modelidx], ph_main, ISP, ISP*ispscale); + th_hover[2] = CreateThruster ({ 3,0,-4.55}, {0,1,0}, 3.0/4.55*0.5*MAX_HOVER_THRUST[modelidx], ph_main, ISP, ISP*ispscale); thg_hover = CreateThrusterGroup (th_hover, 3, THGROUP_HOVER); VECTOR3 hoverp0 = {0,-1.5, 3}, hoverp1 = {-3,-1.3,-4.55}, hoverp2 = {3,-1.3,-4.55}, hoverd = {0,1,0}; EXHAUSTSPEC es_hover[3] = { @@ -982,92 +982,92 @@ void DeltaGlider::clbkSetClassCaps (FILEHANDLE cfg) {th_hover[2], NULL, &hoverp2, &hoverd, 6, 0.5, 0, 0.1, NULL, EXHAUST_CONSTANTPOS|EXHAUST_CONSTANTDIR} }; for (i = 0; i < 3; i++) AddExhaust (es_hover+i); - AddExhaustStream (th_hover[0], _V(0,-4,0), &contrail); - AddExhaustStream (th_hover[0], _V(0,-2,3), &exhaust_hover); - AddExhaustStream (th_hover[1], _V(-3,-2,-4.55), &exhaust_hover); - AddExhaustStream (th_hover[2], _V( 3,-2,-4.55), &exhaust_hover); + AddExhaustStream (th_hover[0], {0,-4,0}, &contrail); + AddExhaustStream (th_hover[0], {0,-2,3}, &exhaust_hover); + AddExhaustStream (th_hover[1], {-3,-2,-4.55}, &exhaust_hover); + AddExhaustStream (th_hover[2], { 3,-2,-4.55}, &exhaust_hover); // set of attitude thrusters (idealised). The arrangement is such that no angular // momentum is created in linear mode, and no linear momentum is created in rotational mode. THRUSTER_HANDLE th_att_rot[4], th_att_lin[4]; - th_att_rot[0] = th_att_lin[0] = CreateThruster (_V(0,0, 8), _V(0, 1,0), MAX_RCS_THRUST, ph_rcs, ISP); - th_att_rot[1] = th_att_lin[3] = CreateThruster (_V(0,0,-8), _V(0,-1,0), MAX_RCS_THRUST, ph_rcs, ISP); - th_att_rot[2] = th_att_lin[2] = CreateThruster (_V(0,0, 8), _V(0,-1,0), MAX_RCS_THRUST, ph_rcs, ISP); - th_att_rot[3] = th_att_lin[1] = CreateThruster (_V(0,0,-8), _V(0, 1,0), MAX_RCS_THRUST, ph_rcs, ISP); + th_att_rot[0] = th_att_lin[0] = CreateThruster ({0,0, 8}, {0, 1,0}, MAX_RCS_THRUST, ph_rcs, ISP); + th_att_rot[1] = th_att_lin[3] = CreateThruster ({0,0,-8}, {0,-1,0}, MAX_RCS_THRUST, ph_rcs, ISP); + th_att_rot[2] = th_att_lin[2] = CreateThruster ({0,0, 8}, {0,-1,0}, MAX_RCS_THRUST, ph_rcs, ISP); + th_att_rot[3] = th_att_lin[1] = CreateThruster ({0,0,-8}, {0, 1,0}, MAX_RCS_THRUST, ph_rcs, ISP); CreateThrusterGroup (th_att_rot, 2, THGROUP_ATT_PITCHUP); CreateThrusterGroup (th_att_rot+2, 2, THGROUP_ATT_PITCHDOWN); CreateThrusterGroup (th_att_lin, 2, THGROUP_ATT_UP); CreateThrusterGroup (th_att_lin+2, 2, THGROUP_ATT_DOWN); - AddExhaust (th_att_rot[0], 0.6, 0.078, _V( -0.816081, -0.616431, 9.594813 ), _V(0,-1,0)); - AddExhaust (th_att_rot[0], 0.6, 0.078, _V( 0.816081, -0.616431, 9.594813 ), _V(0,-1,0)); - AddExhaust (th_att_rot[1], 0.79, 0.103, _V( -0.120063, 0.409999, -7.357354 ), _V(0, 1,0)); - AddExhaust (th_att_rot[1], 0.79, 0.103, _V( 0.120063, 0.409999, -7.357354 ), _V(0, 1,0)); - AddExhaust (th_att_rot[2], 0.6, 0.078, _V( -0.816081, -0.35857, 9.594813 ), _V(0, 1,0)); - AddExhaust (th_att_rot[2], 0.6, 0.078, _V( 0.816081, -0.35857, 9.594813 ), _V(0, 1,0)); - AddExhaust (th_att_rot[3], 0.79, 0.103, _V( -0.120063, -0.409999, -7.357354 ), _V(0,-1,0)); - AddExhaust (th_att_rot[3], 0.79, 0.103, _V( 0.120063, -0.409999, -7.357354 ), _V(0,-1,0)); - - th_att_rot[0] = th_att_lin[0] = CreateThruster (_V(0,0, 6), _V(-1,0,0), MAX_RCS_THRUST, ph_rcs, ISP); - th_att_rot[1] = th_att_lin[3] = CreateThruster (_V(0,0,-6), _V( 1,0,0), MAX_RCS_THRUST, ph_rcs, ISP); - th_att_rot[2] = th_att_lin[2] = CreateThruster (_V(0,0, 6), _V( 1,0,0), MAX_RCS_THRUST, ph_rcs, ISP); - th_att_rot[3] = th_att_lin[1] = CreateThruster (_V(0,0,-6), _V(-1,0,0), MAX_RCS_THRUST, ph_rcs, ISP); + AddExhaust (th_att_rot[0], 0.6, 0.078, { -0.816081, -0.616431, 9.594813 }, {0,-1,0}); + AddExhaust (th_att_rot[0], 0.6, 0.078, { 0.816081, -0.616431, 9.594813 }, {0,-1,0}); + AddExhaust (th_att_rot[1], 0.79, 0.103, { -0.120063, 0.409999, -7.357354 }, {0, 1,0}); + AddExhaust (th_att_rot[1], 0.79, 0.103, { 0.120063, 0.409999, -7.357354 }, {0, 1,0}); + AddExhaust (th_att_rot[2], 0.6, 0.078, { -0.816081, -0.35857, 9.594813 }, {0, 1,0}); + AddExhaust (th_att_rot[2], 0.6, 0.078, { 0.816081, -0.35857, 9.594813 }, {0, 1,0}); + AddExhaust (th_att_rot[3], 0.79, 0.103, { -0.120063, -0.409999, -7.357354 }, {0,-1,0}); + AddExhaust (th_att_rot[3], 0.79, 0.103, { 0.120063, -0.409999, -7.357354 }, {0,-1,0}); + + th_att_rot[0] = th_att_lin[0] = CreateThruster ({0,0, 6}, {-1,0,0}, MAX_RCS_THRUST, ph_rcs, ISP); + th_att_rot[1] = th_att_lin[3] = CreateThruster ({0,0,-6}, { 1,0,0}, MAX_RCS_THRUST, ph_rcs, ISP); + th_att_rot[2] = th_att_lin[2] = CreateThruster ({0,0, 6}, { 1,0,0}, MAX_RCS_THRUST, ph_rcs, ISP); + th_att_rot[3] = th_att_lin[1] = CreateThruster ({0,0,-6}, {-1,0,0}, MAX_RCS_THRUST, ph_rcs, ISP); CreateThrusterGroup (th_att_rot, 2, THGROUP_ATT_YAWLEFT); CreateThrusterGroup (th_att_rot+2, 2, THGROUP_ATT_YAWRIGHT); CreateThrusterGroup (th_att_lin, 2, THGROUP_ATT_LEFT); CreateThrusterGroup (th_att_lin+2, 2, THGROUP_ATT_RIGHT); - AddExhaust (th_att_rot[0], 0.6, 0.078, _V( 0.888971, -0.488177, 9.3408 ), _V(1,0,0)); - AddExhaust (th_att_rot[1], 0.94, 0.122, _V( -2.029295, 0.182903, -6.043046 ), _V(-1,0,0)); - AddExhaust (th_att_rot[2], 0.6, 0.078, _V( -0.888971, -0.488177, 9.3408 ), _V(-1,0,0)); - AddExhaust (th_att_rot[3], 0.94, 0.122, _V( 2.029295, 0.182903, -6.043046 ), _V(1,0,0)); - - th_att_rot[0] = CreateThruster (_V( 6,0,0), _V(0, 1,0), MAX_RCS_THRUST, ph_rcs, ISP); - th_att_rot[1] = CreateThruster (_V(-6,0,0), _V(0,-1,0), MAX_RCS_THRUST, ph_rcs, ISP); - th_att_rot[2] = CreateThruster (_V(-6,0,0), _V(0, 1,0), MAX_RCS_THRUST, ph_rcs, ISP); - th_att_rot[3] = CreateThruster (_V( 6,0,0), _V(0,-1,0), MAX_RCS_THRUST, ph_rcs, ISP); + AddExhaust (th_att_rot[0], 0.6, 0.078, { 0.888971, -0.488177, 9.3408 }, {1,0,0}); + AddExhaust (th_att_rot[1], 0.94, 0.122, { -2.029295, 0.182903, -6.043046 }, {-1,0,0}); + AddExhaust (th_att_rot[2], 0.6, 0.078, { -0.888971, -0.488177, 9.3408 }, {-1,0,0}); + AddExhaust (th_att_rot[3], 0.94, 0.122, { 2.029295, 0.182903, -6.043046 }, {1,0,0}); + + th_att_rot[0] = CreateThruster ({ 6,0,0}, {0, 1,0}, MAX_RCS_THRUST, ph_rcs, ISP); + th_att_rot[1] = CreateThruster ({-6,0,0}, {0,-1,0}, MAX_RCS_THRUST, ph_rcs, ISP); + th_att_rot[2] = CreateThruster ({-6,0,0}, {0, 1,0}, MAX_RCS_THRUST, ph_rcs, ISP); + th_att_rot[3] = CreateThruster ({ 6,0,0}, {0,-1,0}, MAX_RCS_THRUST, ph_rcs, ISP); CreateThrusterGroup (th_att_rot, 2, THGROUP_ATT_BANKLEFT); CreateThrusterGroup (th_att_rot+2, 2, THGROUP_ATT_BANKRIGHT); - AddExhaust (th_att_rot[0], 1.03, 0.134, _V( -5.121185, -0.073903, 0.375386 ), _V(0, 1,0)); - AddExhaust (th_att_rot[1], 1.03, 0.134, _V( 5.121185, -0.654322, 0.375386 ), _V(0,-1,0)); - AddExhaust (th_att_rot[2], 1.03, 0.134, _V( 5.121185, -0.073903, 0.375386 ), _V(0, 1,0)); - AddExhaust (th_att_rot[3], 1.03, 0.134, _V( -5.121185, -0.654322, 0.375386 ), _V(0,-1,0)); + AddExhaust (th_att_rot[0], 1.03, 0.134, { -5.121185, -0.073903, 0.375386 }, {0, 1,0}); + AddExhaust (th_att_rot[1], 1.03, 0.134, { 5.121185, -0.654322, 0.375386 }, {0,-1,0}); + AddExhaust (th_att_rot[2], 1.03, 0.134, { 5.121185, -0.073903, 0.375386 }, {0, 1,0}); + AddExhaust (th_att_rot[3], 1.03, 0.134, { -5.121185, -0.654322, 0.375386 }, {0,-1,0}); - th_att_lin[0] = CreateThruster (_V(0,0,-7), _V(0,0, 1), 2*MAX_RCS_THRUST, ph_rcs, ISP); - th_att_lin[1] = CreateThruster (_V(0,0, 7), _V(0,0,-1), 2*MAX_RCS_THRUST, ph_rcs, ISP); + th_att_lin[0] = CreateThruster ({0,0,-7}, {0,0, 1}, 2*MAX_RCS_THRUST, ph_rcs, ISP); + th_att_lin[1] = CreateThruster ({0,0, 7}, {0,0,-1}, 2*MAX_RCS_THRUST, ph_rcs, ISP); CreateThrusterGroup (th_att_lin, 1, THGROUP_ATT_FORWARD); CreateThrusterGroup (th_att_lin+1, 1, THGROUP_ATT_BACK); - AddExhaust (th_att_lin[0], 0.6, 0.078, _V( 0.0, -0.228914, -7.462329 ), _V(0,0,-1)); - AddExhaust (th_att_lin[0], 0.6, 0.078, _V( 0.0, 0.229, -7.462329 ), _V(0,0,-1)); - AddExhaust (th_att_lin[1], 0.6, 0.078, _V( -0.817096, -0.488177, 9.729635 ), _V(0,0,1)); - AddExhaust (th_att_lin[1], 0.6, 0.078, _V( 0.817096, -0.488177, 9.729635 ), _V(0,0,1)); + AddExhaust (th_att_lin[0], 0.6, 0.078, { 0.0, -0.228914, -7.462329 }, {0,0,-1}); + AddExhaust (th_att_lin[0], 0.6, 0.078, { 0.0, 0.229, -7.462329 }, {0,0,-1}); + AddExhaust (th_att_lin[1], 0.6, 0.078, { -0.817096, -0.488177, 9.729635 }, {0,0,1}); + AddExhaust (th_att_lin[1], 0.6, 0.078, { 0.817096, -0.488177, 9.729635 }, {0,0,1}); COLOUR4 col_d = {0.9,0.8,1,0}; COLOUR4 col_s = {1.9,0.8,1,0}; COLOUR4 col_a = {0,0,0,0}; COLOUR4 col_white = {1,1,1,0}; - LightEmitter *le = AddPointLight (_V(0,0,-10), 200, 1e-3, 0, 2e-3, col_d, col_s, col_a); + LightEmitter *le = AddPointLight ({0,0,-10}, 200, 1e-3, 0, 2e-3, col_d, col_s, col_a); le->SetIntensityRef (&th_main_level); // ********************* aerodynamics *********************** - hwing = CreateAirfoil3 (LIFT_VERTICAL, _V(0,0,-0.3), VLiftCoeff, 0, 5, 90, 1.5); + hwing = CreateAirfoil3 (LIFT_VERTICAL, {0,0,-0.3}, VLiftCoeff, 0, 5, 90, 1.5); // wing and body lift+drag components - CreateAirfoil3 (LIFT_HORIZONTAL, _V(0,0,-4), HLiftCoeff, 0, 5, 15, 1.5); + CreateAirfoil3 (LIFT_HORIZONTAL, {0,0,-4}, HLiftCoeff, 0, 5, 15, 1.5); // vertical stabiliser and body lift and drag components - CreateControlSurface3 (AIRCTRL_ELEVATOR, 1.4, 1.7, _V( 0,0,-7.2), AIRCTRL_AXIS_XPOS, 1.0, anim_elevator); - CreateControlSurface3 (AIRCTRL_RUDDER, 0.8, 1.7, _V( 0,0,-7.2), AIRCTRL_AXIS_YPOS, 1.0, anim_rudder); - hlaileron = CreateControlSurface3 (AIRCTRL_AILERON, 0.3, 1.7, _V( 7.5,0,-7.2), AIRCTRL_AXIS_XPOS, 1.0, anim_raileron); - hraileron = CreateControlSurface3 (AIRCTRL_AILERON, 0.3, 1.7, _V(-7.5,0,-7.2), AIRCTRL_AXIS_XNEG, 1.0, anim_laileron); - CreateControlSurface3 (AIRCTRL_ELEVATORTRIM, 0.3, 1.7, _V( 0,0,-7.2), AIRCTRL_AXIS_XPOS, 1.0, anim_elevatortrim); + CreateControlSurface3 (AIRCTRL_ELEVATOR, 1.4, 1.7, { 0,0,-7.2}, AIRCTRL_AXIS_XPOS, 1.0, anim_elevator); + CreateControlSurface3 (AIRCTRL_RUDDER, 0.8, 1.7, { 0,0,-7.2}, AIRCTRL_AXIS_YPOS, 1.0, anim_rudder); + hlaileron = CreateControlSurface3 (AIRCTRL_AILERON, 0.3, 1.7, { 7.5,0,-7.2}, AIRCTRL_AXIS_XPOS, 1.0, anim_raileron); + hraileron = CreateControlSurface3 (AIRCTRL_AILERON, 0.3, 1.7, {-7.5,0,-7.2}, AIRCTRL_AXIS_XNEG, 1.0, anim_laileron); + CreateControlSurface3 (AIRCTRL_ELEVATORTRIM, 0.3, 1.7, { 0,0,-7.2}, AIRCTRL_AXIS_XPOS, 1.0, anim_elevatortrim); - CreateVariableDragElement (ssys_gear->GearState().StatePtr(), 0.8, _V(0, -1, 0)); // landing gear - CreateVariableDragElement (ssys_mainretro->RetroCoverState().StatePtr(), 0.2, _V(0,-0.5,6.5)); // retro covers - CreateVariableDragElement (ssys_docking->NconeState().StatePtr(), 3, _V(0, 0, 8)); // nose cone - CreateVariableDragElement (ssys_thermal->RadiatorState().StatePtr(), 1, _V(0,1.5,-4)); // radiator - CreateVariableDragElement (ssys_aerodyn->AirbrakeState().StatePtr(), 4, _V(0,0,-8)); // airbrake + CreateVariableDragElement (ssys_gear->GearState().StatePtr(), 0.8, {0, -1, 0}); // landing gear + CreateVariableDragElement (ssys_mainretro->RetroCoverState().StatePtr(), 0.2, {0,-0.5,6.5}); // retro covers + CreateVariableDragElement (ssys_docking->NconeState().StatePtr(), 3, {0, 0, 8}); // nose cone + CreateVariableDragElement (ssys_thermal->RadiatorState().StatePtr(), 1, {0,1.5,-4}); // radiator + CreateVariableDragElement (ssys_aerodyn->AirbrakeState().StatePtr(), 4, {0,0,-8}); // airbrake - SetRotDrag (_V(0.10,0.13,0.04)); + SetRotDrag ({0.10,0.13,0.04}); // angular damping // ************************* mesh *************************** @@ -1339,7 +1339,7 @@ void DeltaGlider::clbkPostStep (double simt, double simdt, double mjd) bool DeltaGlider::clbkLoadGenericCockpit () { - SetCameraOffset (_V(0,1.467,6.782)); + SetCameraOffset ({0,1.467,6.782}); oapiSetDefNavDisplay (1); oapiSetDefRCSDisplay (1); campos = CAM_GENERIC; @@ -1360,14 +1360,14 @@ bool DeltaGlider::clbkLoadPanel2D (int id, PANELHANDLE hPanel, DWORD viewW, DWOR DefinePanelMain (hPanel); SetPanelScale (hPanel, viewW, viewH); oapiSetPanelNeighbours (-1,-1,1,-1); - SetCameraDefaultDirection (_V(0,0,1)); // forward + SetCameraDefaultDirection ({0,0,1}); // forward oapiCameraSetCockpitDir (0,0); // look forward return true; case 1: DefinePanelOverhead (hPanel); SetPanelScale (hPanel, viewW, viewH); oapiSetPanelNeighbours (-1,-1,-1,0); - SetCameraDefaultDirection (_V(0,0,1)); // forward + SetCameraDefaultDirection ({0,0,1}); // forward oapiCameraSetCockpitDir (0,20*RAD); // look up return true; default: @@ -1454,15 +1454,15 @@ bool DeltaGlider::clbkLoadVC (int id) InitVC (id); - SetCameraDefaultDirection (_V(0,0,1)); // forward + SetCameraDefaultDirection ({0,0,1}); // forward oapiVCRegisterHUD (&huds); // HUD parameters oapiVCRegisterMFD (MFD_LEFT, &mfds_left); // left MFD oapiVCRegisterMFD (MFD_RIGHT, &mfds_right); // right MFD switch (id) { case 0: // pilot - SetCameraOffset (_V(0,1.467,6.782)); - SetCameraShiftRange (_V(0,0,0.1), _V(-0.2,0,0), _V(0.2,0,0)); + SetCameraOffset ({0,1.467,6.782}); + SetCameraShiftRange ({0,0,0.1}, {-0.2,0,0}, {0.2,0,0}); oapiVCSetNeighbours (1, 2, -1, -1); // main/retro/hover engine indicators @@ -1480,29 +1480,29 @@ bool DeltaGlider::clbkLoadVC (int id) break; case 1: // front left passenger - SetCameraOffset (_V(-0.7, 1.15, 5.55)); - SetCameraMovement (_V(0.2,-0.05,0.3), -10*RAD, 10*RAD, _V(-0.3,0,0), 80*RAD, 0, _V(0.4,0,0), -90*RAD, 0); + SetCameraOffset ({-0.7, 1.15, 5.55}); + SetCameraMovement ({0.2,-0.05,0.3}, -10*RAD, 10*RAD, {-0.3,0,0}, 80*RAD, 0, {0.4,0,0}, -90*RAD, 0); oapiVCSetNeighbours (-1, 2, 0, 3); campos = CAM_VCPSNGR1; break; case 2: // front right passenger - SetCameraOffset (_V(0.7, 1.15, 5.55)); - SetCameraMovement (_V(-0.2,-0.05,0.3), 10*RAD, 10*RAD, _V(-0.4,0,0), 90*RAD, 0, _V(0.3,0,0), -80*RAD, 0); + SetCameraOffset ({0.7, 1.15, 5.55}); + SetCameraMovement ({-0.2,-0.05,0.3}, 10*RAD, 10*RAD, {-0.4,0,0}, 90*RAD, 0, {0.3,0,0}, -80*RAD, 0); oapiVCSetNeighbours (1, -1, 0, 4); campos = CAM_VCPSNGR2; break; case 3: // rear left passenger - SetCameraOffset (_V(-0.8, 1.2, 4.4)); - SetCameraMovement (_V(0.4,0,0), 0, 0, _V(-0.3,0,0), 70*RAD, 0, _V(0.4,0,0), -90*RAD, 0); + SetCameraOffset ({-0.8, 1.2, 4.4}); + SetCameraMovement ({0.4,0,0}, 0, 0, {-0.3,0,0}, 70*RAD, 0, {0.4,0,0}, -90*RAD, 0); oapiVCSetNeighbours (-1, 4, 1, -1); campos = CAM_VCPSNGR3; break; case 4: // rear right passenger - SetCameraOffset (_V(0.8, 1.2, 4.4)); - SetCameraMovement (_V(-0.4,0,0), 0, 0, _V(-0.4,0,0), 90*RAD, 0, _V(0.3,0,0), -70*RAD, 0); + SetCameraOffset ({0.8, 1.2, 4.4}); + SetCameraMovement ({-0.4,0,0}, 0, 0, {-0.4,0,0}, 90*RAD, 0, {0.3,0,0}, -70*RAD, 0); oapiVCSetNeighbours (3, -1, 2, -1); campos = CAM_VCPSNGR4; break; diff --git a/Src/Vessel/DeltaGlider/DockingSubsys.cpp b/Src/Vessel/DeltaGlider/DockingSubsys.cpp index 3c987ab25..ec80418e8 100644 --- a/Src/Vessel/DeltaGlider/DockingSubsys.cpp +++ b/Src/Vessel/DeltaGlider/DockingSubsys.cpp @@ -94,25 +94,25 @@ NoseconeCtrl::NoseconeCtrl (DockingCtrlSubsystem *_subsys) // Nosecone animation static UINT NConeTLGrp[2] = {GRP_NConeTL1,GRP_NConeTL2}; static MGROUP_ROTATE NConeTL (0, NConeTLGrp, 2, - _V(-0.424,-0.066,9.838), _V(-0.707,-0.707,0), (float)(150*RAD)); + {-0.424,-0.066,9.838}, {-0.707,-0.707,0}, (float)(150*RAD)); static UINT NConeTRGrp[2] = {GRP_NConeTR1,GRP_NConeTR2}; static MGROUP_ROTATE NConeTR (0, NConeTRGrp, 2, - _V( 0.424,-0.066,9.838), _V(-0.707, 0.707,0), (float)(150*RAD)); + { 0.424,-0.066,9.838}, {-0.707, 0.707,0}, (float)(150*RAD)); static UINT NConeBLGrp[2] = {GRP_NConeBL1,GRP_NConeBL2}; static MGROUP_ROTATE NConeBL (0, NConeBLGrp, 2, - _V(-0.424,-0.914,9.838), _V( 0.707,-0.707,0), (float)(150*RAD)); + {-0.424,-0.914,9.838}, { 0.707,-0.707,0}, (float)(150*RAD)); static UINT NConeBRGrp[2] = {GRP_NConeBR1,GRP_NConeBR2}; static MGROUP_ROTATE NConeBR (0, NConeBRGrp, 2, - _V( 0.424,-0.914,9.838), _V( 0.707, 0.707,0), (float)(150*RAD)); + { 0.424,-0.914,9.838}, { 0.707, 0.707,0}, (float)(150*RAD)); static UINT NConeDockGrp[1] = {GRP_NConeDock}; - static MGROUP_TRANSLATE NConeDock (0, NConeDockGrp, 1, _V(0,0,0.06)); + static MGROUP_TRANSLATE NConeDock (0, NConeDockGrp, 1, {0,0,0.06}); // virtual cockpit mesh animation (nose cone visible from cockpit) static UINT VCNConeTLGrp[1] = {GRP_NOSECONE_L_VC}; static MGROUP_ROTATE VCNConeTL (1, VCNConeTLGrp, 1, - _V(-0.424,-0.066,9.838), _V(-0.707,-0.707,0), (float)(150*RAD)); + {-0.424,-0.066,9.838}, {-0.707,-0.707,0}, (float)(150*RAD)); static UINT VCNConeTRGrp[1] = {GRP_NOSECONE_R_VC}; static MGROUP_ROTATE VCNConeTR (1, VCNConeTRGrp, 1, - _V( 0.424,-0.066,9.838), _V(-0.707, 0.707,0), (float)(150*RAD)); + { 0.424,-0.066,9.838}, {-0.707, 0.707,0}, (float)(150*RAD)); anim_nose = DG()->CreateAnimation (0); DG()->AddAnimationComponent (anim_nose, 0.01, 0.92, &NConeTL); DG()->AddAnimationComponent (anim_nose, 0.01, 0.92, &VCNConeTL); @@ -541,9 +541,9 @@ EscapeLadderCtrl::EscapeLadderCtrl (DockingCtrlSubsystem *_subsys) // Escape ladder animation static UINT LadderGrp[2] = {GRP_Ladder1,GRP_Ladder2}; - static MGROUP_TRANSLATE Ladder1 (0, LadderGrp, 2, _V(0,0,1.1)); + static MGROUP_TRANSLATE Ladder1 (0, LadderGrp, 2, {0,0,1.1}); static MGROUP_ROTATE Ladder2 (0, LadderGrp, 2, - _V(0,-1.05,9.85), _V(1,0,0), (float)(80*RAD)); + {0,-1.05,9.85}, {1,0,0}, (float)(80*RAD)); anim_ladder = DG()->CreateAnimation (0); DG()->AddAnimationComponent (anim_ladder, 0, 0.5, &Ladder1); DG()->AddAnimationComponent (anim_ladder, 0.5, 1, &Ladder2); diff --git a/Src/Vessel/DeltaGlider/GearSubsys.cpp b/Src/Vessel/DeltaGlider/GearSubsys.cpp index d014b958f..c255c6775 100644 --- a/Src/Vessel/DeltaGlider/GearSubsys.cpp +++ b/Src/Vessel/DeltaGlider/GearSubsys.cpp @@ -66,42 +66,42 @@ GearControl::GearControl (GearSubsystem *_subsys) // Landing gear animation static UINT NWheelStrutGrp[2] = {GRP_NWheelStrut1,GRP_NWheelStrut2}; static MGROUP_ROTATE NWheelStrut (0, NWheelStrutGrp, 2, - _V(0,-1.048,8.561), _V(1,0,0), (float)(-95*RAD)); + {0,-1.048,8.561}, {1,0,0}, (float)(-95*RAD)); static UINT NWheelFCoverGrp[2] = {GRP_NWheelFCover1,GRP_NWheelFCover2}; static MGROUP_ROTATE NWheelFCover (0, NWheelFCoverGrp, 2, - _V(0,-1.145,8.65), _V(1,0,0), (float)(-90*RAD)); + {0,-1.145,8.65}, {1,0,0}, (float)(-90*RAD)); static UINT NWheelLCoverGrp[2] = {GRP_NWheelLCover1,GRP_NWheelLCover2}; static MGROUP_ROTATE NWheelLCover1 (0, NWheelLCoverGrp, 2, - _V(-0.3,-1.222,7.029), _V(0,0.052,0.999), (float)(-90*RAD)); + {-0.3,-1.222,7.029}, {0,0.052,0.999}, (float)(-90*RAD)); static MGROUP_ROTATE NWheelLCover2 (0, NWheelLCoverGrp, 2, - _V(-0.3,-1.222,7.029), _V(0,0.052,0.999), (float)( 90*RAD)); + {-0.3,-1.222,7.029}, {0,0.052,0.999}, (float)( 90*RAD)); static UINT NWheelRCoverGrp[2] = {GRP_NWheelRCover1,GRP_NWheelRCover2}; static MGROUP_ROTATE NWheelRCover1 (0, NWheelRCoverGrp, 2, - _V( 0.3,-1.222,7.029), _V(0,0.052,0.999), (float)( 90*RAD)); + { 0.3,-1.222,7.029}, {0,0.052,0.999}, (float)( 90*RAD)); static MGROUP_ROTATE NWheelRCover2 (0, NWheelRCoverGrp, 2, - _V( 0.3,-1.222,7.029), _V(0,0.052,0.999), (float)(-90*RAD)); + { 0.3,-1.222,7.029}, {0,0.052,0.999}, (float)(-90*RAD)); static UINT LWheelStrutGrp[2] = {GRP_LWheelStrut1,GRP_LWheelStrut2}; static MGROUP_ROTATE LWheelStrut (0, LWheelStrutGrp, 2, - _V(-3.607,-1.137,-3.08), _V(0,0,1), (float)(-90*RAD)); + {-3.607,-1.137,-3.08}, {0,0,1}, (float)(-90*RAD)); static UINT RWheelStrutGrp[2] = {GRP_RWheelStrut1,GRP_RWheelStrut2}; static MGROUP_ROTATE RWheelStrut (0, RWheelStrutGrp, 2, - _V( 3.607,-1.137,-3.08), _V(0,0,1), (float)(90*RAD)); + { 3.607,-1.137,-3.08}, {0,0,1}, (float)(90*RAD)); static UINT LWheelOCoverGrp[4] = {GRP_LWheelOCover1,GRP_LWheelOCover2,GRP_LWheelOCover3,GRP_LWheelOCover4}; static MGROUP_ROTATE LWheelOCover (0, LWheelOCoverGrp, 4, - _V(-3.658,-1.239,-3.038), _V(0,0,1), (float)(-110*RAD)); + {-3.658,-1.239,-3.038}, {0,0,1}, (float)(-110*RAD)); static UINT LWheelICoverGrp[2] = {GRP_LWheelICover1,GRP_LWheelICover2}; static MGROUP_ROTATE LWheelICover1 (0, LWheelICoverGrp, 2, - _V(-2.175,-1.178,-3.438), _V(0,0,1), (float)(90*RAD)); + {-2.175,-1.178,-3.438}, {0,0,1}, (float)(90*RAD)); static MGROUP_ROTATE LWheelICover2 (0, LWheelICoverGrp, 2, - _V(-2.175,-1.178,-3.438), _V(0,0,1), (float)(-90*RAD)); + {-2.175,-1.178,-3.438}, {0,0,1}, (float)(-90*RAD)); static UINT RWheelOCoverGrp[4] = {GRP_RWheelOCover1,GRP_RWheelOCover2,GRP_RWheelOCover3,GRP_RWheelOCover4}; static MGROUP_ROTATE RWheelOCover (0, RWheelOCoverGrp, 4, - _V( 3.658,-1.239,-3.038), _V(0,0,1), (float)( 110*RAD)); + { 3.658,-1.239,-3.038}, {0,0,1}, (float)( 110*RAD)); static UINT RWheelICoverGrp[2] = {GRP_RWheelICover1,GRP_RWheelICover2}; static MGROUP_ROTATE RWheelICover1 (0, RWheelICoverGrp, 2, - _V( 2.175,-1.178,-3.438), _V(0,0,1), (float)(-90*RAD)); + { 2.175,-1.178,-3.438}, {0,0,1}, (float)(-90*RAD)); static MGROUP_ROTATE RWheelICover2 (0, RWheelICoverGrp, 2, - _V( 2.175,-1.178,-3.438), _V(0,0,1), (float)( 90*RAD)); + { 2.175,-1.178,-3.438}, {0,0,1}, (float)( 90*RAD)); anim_gear = DG()->CreateAnimation (1); DG()->AddAnimationComponent (anim_gear, 0.3, 1, &NWheelStrut); DG()->AddAnimationComponent (anim_gear, 0.3, 0.9, &NWheelFCover); diff --git a/Src/Vessel/DeltaGlider/HoverSubsys.cpp b/Src/Vessel/DeltaGlider/HoverSubsys.cpp index 77cb577f0..6a3ae62c2 100644 --- a/Src/Vessel/DeltaGlider/HoverSubsys.cpp +++ b/Src/Vessel/DeltaGlider/HoverSubsys.cpp @@ -564,7 +564,7 @@ HoverManualComponent::HoverManualComponent (HoverSubsystem *_subsys) // Hover throttle VC animation static UINT HoverThrottleGrp[2] = {GRP_THROTTLE_HOVER_1_VC,GRP_THROTTLE_HOVER_2_VC}; static MGROUP_ROTATE HoverThrottle (1, HoverThrottleGrp, 2, - _V(-0.41,0.85,6.9226), _V(1,0,0), (float)(50*RAD)); + {-0.41,0.85,6.9226}, {1,0,0}, (float)(50*RAD)); anim_hoverthrottle = DG()->CreateAnimation (0); DG()->AddAnimationComponent (anim_hoverthrottle, 0, 1, &HoverThrottle); @@ -591,7 +591,7 @@ bool HoverManualComponent::clbkLoadVC (int vcid) // Hover throttle oapiVCRegisterArea (ELID_THROTTLE, PANEL_REDRAW_ALWAYS, PANEL_MOUSE_LBDOWN|PANEL_MOUSE_LBPRESSED); - oapiVCSetAreaClickmode_Quadrilateral (ELID_THROTTLE, _V(-0.44,0.87,6.81), _V(-0.35,0.87,6.81), _V(-0.44,0.95,6.91), _V(-0.35,0.95,6.91)); + oapiVCSetAreaClickmode_Quadrilateral (ELID_THROTTLE, {-0.44,0.87,6.81}, {-0.35,0.87,6.81}, {-0.44,0.95,6.91}, {-0.35,0.95,6.91}); return true; } diff --git a/Src/Vessel/DeltaGlider/HudCtrl.cpp b/Src/Vessel/DeltaGlider/HudCtrl.cpp index 7d34c2400..e3f6ddfe5 100644 --- a/Src/Vessel/DeltaGlider/HudCtrl.cpp +++ b/Src/Vessel/DeltaGlider/HudCtrl.cpp @@ -43,9 +43,9 @@ HUDControl::HUDControl (DeltaGlider *vessel) static UINT HudGrp1[2] = {GRP_HUD_FRAME_VC, GRP_HUD_PANE_VC}; static UINT HudGrp2[3] = {GRP_HUD_FRAME_VC, GRP_HUD_PANE_VC, GRP_HUD_RAIL_VC}; static MGROUP_ROTATE HudTransform1 (1, HudGrp1, 2, - _V(0,1.5836,7.1280), _V(1,0,0), (float)(-62*RAD)); + {0,1.5836,7.1280}, {1,0,0}, (float)(-62*RAD)); static MGROUP_ROTATE HudTransform2 (1, HudGrp2, 3, - _V(0,0.99,6.53), _V(1,0,0), (float)(-26*RAD)); + {0,0.99,6.53}, {1,0,0}, (float)(-26*RAD)); anim_vc_hud = DG()->CreateAnimation (0); DG()->AddAnimationComponent (anim_vc_hud, 0, 0.4, &HudTransform1); DG()->AddAnimationComponent (anim_vc_hud, 0.4, 1, &HudTransform2); diff --git a/Src/Vessel/DeltaGlider/LightSubsys.cpp b/Src/Vessel/DeltaGlider/LightSubsys.cpp index 24b098c02..30f0b38af 100644 --- a/Src/Vessel/DeltaGlider/LightSubsys.cpp +++ b/Src/Vessel/DeltaGlider/LightSubsys.cpp @@ -242,7 +242,7 @@ void CockpitLight::SetLight (int mode, bool force) static const COLOUR4 wcol = {1.0f,1.0f,1.0f,0.0f}; static const COLOUR4 rcol = {0.6f,0.05f,0.0f,0.0f}; COLOUR4 col = (mode == 1 ? wcol : rcol); - light = (PointLight*)DG()->AddPointLight(_V(0,1.65,6.68), 3, 0, 0, 3, col, col, zero); + light = (PointLight*)DG()->AddPointLight({0,1.65,6.68}, 3, 0, 0, 3, col, col, zero); light->SetVisibility (LightEmitter::VIS_COCKPIT); light->Activate(true); double intens = (float)(0.2 + brightness*0.8); @@ -387,10 +387,10 @@ void LandDockLight::SetLight (int mode, bool force) COLOUR4 col_a = {0,0,0,0}; COLOUR4 col_white = {1,1,1,0}; if (mode == 1) { - light = (SpotLight*)DG()->AddSpotLight(_V(0.3,0.3,8.5), _V(0,0,1), 150, 1e-3, 0, 1e-3, RAD*30, RAD*60, col_white, col_white, col_a); + light = (SpotLight*)DG()->AddSpotLight({0.3,0.3,8.5}, {0,0,1}, 150, 1e-3, 0, 1e-3, RAD*30, RAD*60, col_white, col_white, col_a); } else { double tilt = -10.0*RAD; - light = (SpotLight*)DG()->AddSpotLight(_V(0.1,-0.3,7.5), _V(0,sin(tilt),cos(tilt)), 5000, 1e-3, 1e-5, 2e-7, RAD*25, RAD*40, col_white, col_white, col_a); + light = (SpotLight*)DG()->AddSpotLight({0.1,-0.3,7.5}, {0,sin(tilt),cos(tilt)}, 5000, 1e-3, 1e-5, 2e-7, RAD*25, RAD*40, col_white, col_white, col_a); } light->SetVisibility (LightEmitter::VIS_ALWAYS); } diff --git a/Src/Vessel/DeltaGlider/MainRetroSubsys.cpp b/Src/Vessel/DeltaGlider/MainRetroSubsys.cpp index d84467106..c967c7d45 100644 --- a/Src/Vessel/DeltaGlider/MainRetroSubsys.cpp +++ b/Src/Vessel/DeltaGlider/MainRetroSubsys.cpp @@ -97,14 +97,14 @@ MainRetroThrottle::MainRetroThrottle (MainRetroSubsystem *_subsys) // VC animation: Left main engine throttle static UINT MainThrottleLGrp[2] = {GRP_THROTTLE_MAIN_L1_VC,GRP_THROTTLE_MAIN_L2_VC}; static MGROUP_ROTATE MainThrottleL (1, MainThrottleLGrp, 2, - _V(0,0.72,6.9856), _V(1,0,0), (float)(50*RAD)); + {0,0.72,6.9856}, {1,0,0}, (float)(50*RAD)); anim_lever[0] = DG()->CreateAnimation (0.4); DG()->AddAnimationComponent (anim_lever[0], 0, 1, &MainThrottleL); // VC animation: Right main engine throttle static UINT MainThrottleRGrp[2] = {GRP_THROTTLE_MAIN_R1_VC,GRP_THROTTLE_MAIN_R2_VC}; static MGROUP_ROTATE MainThrottleR (1, MainThrottleRGrp, 2, - _V(0,0.72,6.9856), _V(1,0,0), (float)(50*RAD)); + {0,0.72,6.9856}, {1,0,0}, (float)(50*RAD)); anim_lever[1] = DG()->CreateAnimation (0.4); DG()->AddAnimationComponent (anim_lever[1], 0, 1, &MainThrottleR); } @@ -129,7 +129,7 @@ bool MainRetroThrottle::clbkLoadVC (int vcid) // Throttle lever animations oapiVCRegisterArea (ELID_LEVERS, PANEL_REDRAW_ALWAYS, PANEL_MOUSE_LBDOWN|PANEL_MOUSE_LBPRESSED); - oapiVCSetAreaClickmode_Quadrilateral (ELID_LEVERS, _V(-0.372,0.918,6.905), _V(-0.279,0.918,6.905), _V(-0.372,0.885,7.11), _V(-0.279,0.885,7.11)); + oapiVCSetAreaClickmode_Quadrilateral (ELID_LEVERS, {-0.372,0.918,6.905}, {-0.279,0.918,6.905}, {-0.372,0.885,7.11}, {-0.279,0.885,7.11}); return true; } @@ -975,16 +975,16 @@ RetroCoverControl::RetroCoverControl (MainRetroSubsystem *_subsys) // Retro cover animation static UINT RCoverTLGrp[2] = {GRP_RCoverTL1,GRP_RCoverTL2}; static MGROUP_ROTATE RCoverTL (0, RCoverTLGrp, 2, - _V(-2.156,-0.49,6.886), _V(-0.423,0.23,-0.877), (float)( 70*RAD)); + {-2.156,-0.49,6.886}, {-0.423,0.23,-0.877}, (float)( 70*RAD)); static UINT RCoverBLGrp[2] = {GRP_RCoverBL1,GRP_RCoverBL2}; static MGROUP_ROTATE RCoverBL (0, RCoverBLGrp, 2, - _V(-2.156,-0.49,6.886), _V(-0.434,-0.037,-0.9), (float)(-70*RAD)); + {-2.156,-0.49,6.886}, {-0.434,-0.037,-0.9}, (float)(-70*RAD)); static UINT RCoverTRGrp[2] = {GRP_RCoverTR1,GRP_RCoverTR2}; static MGROUP_ROTATE RCoverTR (0, RCoverTRGrp, 2, - _V( 2.156,-0.49,6.886), _V( 0.423,0.23,-0.877), (float)(-70*RAD)); + { 2.156,-0.49,6.886}, { 0.423,0.23,-0.877}, (float)(-70*RAD)); static UINT RCoverBRGrp[2] = {GRP_RCoverBR1,GRP_RCoverBR2}; static MGROUP_ROTATE RCoverBR (0, RCoverBRGrp, 2, - _V( 2.156,-0.49,6.886), _V( 0.434,-0.037,-0.9), (float)( 70*RAD)); + { 2.156,-0.49,6.886}, { 0.434,-0.037,-0.9}, (float)( 70*RAD)); anim_rcover = DG()->CreateAnimation (0); DG()->AddAnimationComponent (anim_rcover, 0, 1, &RCoverTL); DG()->AddAnimationComponent (anim_rcover, 0, 1, &RCoverBL); diff --git a/Src/Vessel/DeltaGlider/MfdSubsys.cpp b/Src/Vessel/DeltaGlider/MfdSubsys.cpp index 4cebbaf21..663df369e 100644 --- a/Src/Vessel/DeltaGlider/MfdSubsys.cpp +++ b/Src/Vessel/DeltaGlider/MfdSubsys.cpp @@ -121,13 +121,13 @@ bool MfdSubsystem::clbkLoadVC (int vcid) const double xofs = (mfdid == MFD_LEFT ? -0.2684 : 0.0616); oapiVCRegisterArea (ELID_BTNROW, PANEL_REDRAW_MOUSE, PANEL_MOUSE_LBDOWN|PANEL_MOUSE_LBUP|PANEL_MOUSE_LBPRESSED|PANEL_MOUSE_ONREPLAY); - oapiVCSetAreaClickmode_Quadrilateral (ELID_BTNROW, _V(0.0840+xofs, 1.0745, 7.2238), _V(0.1228+xofs, 1.0745, 7.2238), _V(0.0840+xofs, 1.0587, 7.2180), _V(0.1228+xofs, 1.0587, 7.2180)); + oapiVCSetAreaClickmode_Quadrilateral (ELID_BTNROW, {0.0840+xofs, 1.0745, 7.2238}, {0.1228+xofs, 1.0745, 7.2238}, {0.0840+xofs, 1.0587, 7.2180}, {0.1228+xofs, 1.0587, 7.2180}); oapiVCRegisterArea (ELID_BTNCOL[0], PANEL_REDRAW_MOUSE|PANEL_REDRAW_USER, PANEL_MOUSE_LBDOWN|PANEL_MOUSE_LBUP|PANEL_MOUSE_LBPRESSED|PANEL_MOUSE_ONREPLAY); - oapiVCSetAreaClickmode_Quadrilateral (ELID_BTNCOL[0], _V(0+xofs, 1.2155, 7.2751), _V(0.0168+xofs, 1.2155, 7.2751), _V(0+xofs, 1.0963, 7.2317), _V(0.0168+xofs, 1.0963, 7.2317)); + oapiVCSetAreaClickmode_Quadrilateral (ELID_BTNCOL[0], {0+xofs, 1.2155, 7.2751}, {0.0168+xofs, 1.2155, 7.2751}, {0+xofs, 1.0963, 7.2317}, {0.0168+xofs, 1.0963, 7.2317}); oapiVCRegisterArea (ELID_BTNCOL[1], PANEL_REDRAW_MOUSE|PANEL_REDRAW_USER, PANEL_MOUSE_LBDOWN|PANEL_MOUSE_LBUP|PANEL_MOUSE_LBPRESSED|PANEL_MOUSE_ONREPLAY); - oapiVCSetAreaClickmode_Quadrilateral (ELID_BTNCOL[1], _V(0.1900+xofs, 1.2155, 7.2751), _V(0.2068+xofs, 1.2155, 7.2751), _V(0.1900+xofs, 1.0963, 7.2317), _V(0.2068+xofs, 1.0963, 7.2317)); + oapiVCSetAreaClickmode_Quadrilateral (ELID_BTNCOL[1], {0.1900+xofs, 1.2155, 7.2751}, {0.2068+xofs, 1.2155, 7.2751}, {0.1900+xofs, 1.0963, 7.2317}, {0.2068+xofs, 1.0963, 7.2317}); return true; } diff --git a/Src/Vessel/DeltaGlider/PressureSubsys.cpp b/Src/Vessel/DeltaGlider/PressureSubsys.cpp index 15fd95934..75cefe37e 100644 --- a/Src/Vessel/DeltaGlider/PressureSubsys.cpp +++ b/Src/Vessel/DeltaGlider/PressureSubsys.cpp @@ -288,10 +288,10 @@ AirlockCtrl::AirlockCtrl (PressureSubsystem *_subsys) // Outer airlock animation static UINT OLockGrp[2] = {GRP_OLock1,GRP_OLock2}; static MGROUP_ROTATE OLock (0, OLockGrp, 2, - _V(0,-0.080,9.851), _V(1,0,0), (float)(110*RAD)); + {0,-0.080,9.851}, {1,0,0}, (float)(110*RAD)); static UINT VCOLockGrp[1] = {13}; static MGROUP_ROTATE VCOLock (1, VCOLockGrp, 1, - _V(0,-0.080,9.851), _V(1,0,0), (float)(110*RAD)); + {0,-0.080,9.851}, {1,0,0}, (float)(110*RAD)); anim_olock = DG()->CreateAnimation (0); DG()->AddAnimationComponent (anim_olock, 0, 1, &OLock); DG()->AddAnimationComponent (anim_olock, 0, 1, &VCOLock); @@ -299,11 +299,11 @@ AirlockCtrl::AirlockCtrl (PressureSubsystem *_subsys) // Inner airlock animation static UINT ILockGrp[2] = {GRP_ILock1,GRP_ILock2}; static MGROUP_ROTATE ILock (0, ILockGrp, 2, - _V(0,-0.573,7.800), _V(1,0,0), (float)(85*RAD)); + {0,-0.573,7.800}, {1,0,0}, (float)(85*RAD)); // virtual cockpit mesh animation (inner airlock visible from cockpit) static UINT VCILockGrp[4] = {GRP_ILOCK1_VC,GRP_ILOCK2_VC,GRP_ILOCK3_VC,GRP_ILOCK_GLASS_VC}; static MGROUP_ROTATE VCILock (1, VCILockGrp, 4, - _V(0,-0.573,7.800), _V(1,0,0), (float)(85*RAD)); + {0,-0.573,7.800}, {1,0,0}, (float)(85*RAD)); anim_ilock = DG()->CreateAnimation (0); DG()->AddAnimationComponent (anim_ilock, 0, 1, &ILock); DG()->AddAnimationComponent (anim_ilock, 0, 1, &VCILock); @@ -609,22 +609,22 @@ TophatchCtrl::TophatchCtrl (PressureSubsystem *_subsys) // Top hatch animation static UINT HatchGrp[2] = {GRP_Hatch1,GRP_Hatch2}; static MGROUP_ROTATE Hatch (0, HatchGrp, 2, - _V(0,2.069,5.038), _V(1,0,0), (float)(110*RAD)); + {0,2.069,5.038}, {1,0,0}, (float)(110*RAD)); static UINT VCHatchGrp[1] = {GRP_HATCH_VC}; static MGROUP_ROTATE VCHatch (1, VCHatchGrp, 1, - _V(0,2.069,5.038), _V(1,0,0), (float)(110*RAD)); + {0,2.069,5.038}, {1,0,0}, (float)(110*RAD)); static UINT RearLadderGrp[2] = {GRP_RearLadder1,GRP_RearLadder2}; static MGROUP_ROTATE RearLadder1 (0, RearLadderGrp, 2, - _V(0,1.7621,4.0959), _V(1,0,0), (float)(-20*RAD)); + {0,1.7621,4.0959}, {1,0,0}, (float)(-20*RAD)); static MGROUP_ROTATE RearLadder2 (0, RearLadderGrp+1, 1, - _V(0,1.1173,4.1894), _V(1,0,0), (float)(180*RAD)); + {0,1.1173,4.1894}, {1,0,0}, (float)(180*RAD)); // virtual cockpit ladder animation static UINT VCRearLadderGrp[2] = {GRP_LADDER1_VC,GRP_LADDER2_VC}; static MGROUP_ROTATE VCRearLadder1 (1, VCRearLadderGrp, 2, - _V(0,1.7621,4.0959), _V(1,0,0), (float)(-20*RAD)); + {0,1.7621,4.0959}, {1,0,0}, (float)(-20*RAD)); static MGROUP_ROTATE VCRearLadder2 (1, VCRearLadderGrp+1, 1, - _V(0,1.1173,4.1894), _V(1,0,0), (float)(180*RAD)); + {0,1.1173,4.1894}, {1,0,0}, (float)(180*RAD)); anim_hatch = DG()->CreateAnimation (0); DG()->AddAnimationComponent (anim_hatch, 0, 1, &Hatch); DG()->AddAnimationComponent (anim_hatch, 0, 1, &VCHatch); diff --git a/Src/Vessel/DeltaGlider/ScramSubsys.cpp b/Src/Vessel/DeltaGlider/ScramSubsys.cpp index 56de95e58..6fd0e0cd5 100644 --- a/Src/Vessel/DeltaGlider/ScramSubsys.cpp +++ b/Src/Vessel/DeltaGlider/ScramSubsys.cpp @@ -157,10 +157,10 @@ ScramSubsystem::ScramSubsystem (DeltaGlider *dg) PARTICLESTREAMSPEC::ATM_PLOG, 1e-5, 0.1 }; for (int i = 0; i < 2; i++) { - hScram[i] = dg->CreateThruster (_V(i?0.9:-0.9, -0.8, -5.6), dir, 0, hProp, 0); + hScram[i] = dg->CreateThruster ({i?0.9:-0.9, -0.8, -5.6}, dir, 0, hProp, 0); scram->AddThrusterDefinition (hScram[i], SCRAM_FHV[modelidx], SCRAM_INTAKE_AREA, SCRAM_TEMAX[modelidx], SCRAM_MAX_DMF[modelidx]); - ph = DG()->AddExhaustStream (hScram[0], _V(i?1:-1,-1.1,-5.4), &exhaust_scram); + ph = DG()->AddExhaustStream(hScram[0], {i ? 1.0 : -1.0, -1.1, -5.4}, &exhaust_scram); if (ph) oapiParticleSetLevelRef (ph, scram_intensity+i); scram_max[i] = scram_intensity[i] = 0.0; } @@ -260,14 +260,14 @@ ScramThrottle::ScramThrottle (DGSubsystem *_subsys) // VC animation: Left scram engine throttle static UINT ScramThrottleLGrp[2] = {GRP_THROTTLE_SCRAM_L1_VC,GRP_THROTTLE_SCRAM_L2_VC}; static MGROUP_ROTATE ScramThrottleL (1, ScramThrottleLGrp, 2, - _V(0,0.7849,6.96), _V(1,0,0), (float)(30*RAD)); + {0,0.7849,6.96}, {1,0,0}, (float)(30*RAD)); anim_lever[0] = DG()->CreateAnimation (0); DG()->AddAnimationComponent (anim_lever[0], 0, 1, &ScramThrottleL); // VC animation: Right scram engine throttle static UINT ScramThrottleRGrp[2] = {GRP_THROTTLE_SCRAM_R1_VC,GRP_THROTTLE_SCRAM_R2_VC}; static MGROUP_ROTATE ScramThrottleR (1, ScramThrottleRGrp, 2, - _V(0,0.7849,6.96), _V(1,0,0), (float)(30*RAD)); + {0,0.7849,6.96}, {1,0,0}, (float)(30*RAD)); anim_lever[1] = DG()->CreateAnimation (0); DG()->AddAnimationComponent (anim_lever[1], 0, 1, &ScramThrottleR); } @@ -292,7 +292,7 @@ bool ScramThrottle::clbkLoadVC (int vcid) // Throttle lever animations oapiVCRegisterArea (ELID_LEVER, PANEL_REDRAW_ALWAYS, PANEL_MOUSE_LBDOWN|PANEL_MOUSE_LBPRESSED); - oapiVCSetAreaClickmode_Quadrilateral (ELID_LEVER, _V(-0.45,0.98,6.94), _V(-0.39,0.98,6.94), _V(-0.45,0.95,7.07), _V(-0.39,0.95,7.07)); + oapiVCSetAreaClickmode_Quadrilateral (ELID_LEVER, {-0.45,0.98,6.94}, {-0.39,0.98,6.94}, {-0.45,0.95,7.07}, {-0.39,0.95,7.07}); return true; } diff --git a/Src/Vessel/DeltaGlider/ThermalSubsys.cpp b/Src/Vessel/DeltaGlider/ThermalSubsys.cpp index b081dc160..1cf831ef1 100644 --- a/Src/Vessel/DeltaGlider/ThermalSubsys.cpp +++ b/Src/Vessel/DeltaGlider/ThermalSubsys.cpp @@ -233,14 +233,14 @@ double ThermalSubsystem::SolarRadiation(VECTOR3 *sdir) VECTOR3 Ppos, Vpos; double vdist, pdist, prad, srad; DG()->GetGlobalPos(Vpos); - vdist = length(Vpos); // distance from sun + vdist = len(Vpos); // distance from sun OBJHANDLE hObj = DG()->GetSurfaceRef(); while (hObj && oapiGetObjectType(hObj) == OBJTP_PLANET) { prad = oapiGetSize(hObj); oapiGetGlobalPos(hObj, &Ppos); - pdist = length(Ppos); + pdist = len(Ppos); if (vdist > pdist) { - double d = length(crossp(Ppos, Ppos-Vpos))/vdist; + double d = len(cross(Ppos, Ppos - Vpos)) / vdist; if (d < prad) return 0.0; } hObj = oapiGetGbodyParent(hObj); @@ -267,7 +267,7 @@ double ThermalSubsystem::PlanetRadiation(VECTOR3 *pdir) double prad = oapiGetSize(hObj); oapiGetGlobalPos(hObj, &Ppos); DG()->GetGlobalPos(Vpos); - double pdist = length(Ppos-Vpos); + double pdist = len(Ppos-Vpos); if (pdir) *pdir = (Ppos-Vpos)/pdist; double alt_ratio = prad/pdist; const double Hplanet = 237.0; // W/m^2; only true for Earth @@ -293,8 +293,8 @@ void ThermalSubsystem::AddAlbedoReflection (double rPower, const VECTOR3 &dir, d OBJHANDLE hObj = DG()->GetSurfaceRef(); oapiGetGlobalPos(hObj, &Ppos); DG()->GetGlobalPos(Vpos); - double cosphi = dotp(unit(Vpos-Ppos), unit(-Ppos)); - double irelalt = oapiGetSize(hObj)/length(Vpos-Ppos); + double cosphi = dot(unit(Vpos - Ppos), unit(-Ppos)); + double irelalt = oapiGetSize(hObj) / len(Vpos - Ppos); rPower *= albedo * irelalt*irelalt * cosphi; AddIrradiance (rPower, dir, compartmentQ); } @@ -353,8 +353,8 @@ void ThermalSubsystem::AddRadiatorIrradiance (double rPower, const VECTOR3 &dir, // panel 1 pprog = min(1.0, rstate/0.33); alpha = (pprog*175.0-100.0)*RAD; - paneldir = _V(0, sin(alpha), -cos(alpha)); - cosa = dotp(dir, paneldir); // irradiance cosine + paneldir = {0, sin(alpha), -cos(alpha)}; + cosa = dot(dir, paneldir); // irradiance cosine if (cosa > 0.0) { if (pprog < 0.5) cosa *= pprog*2.0; cs = cosa * A_radiatorpanel2; @@ -365,8 +365,8 @@ void ThermalSubsystem::AddRadiatorIrradiance (double rPower, const VECTOR3 &dir, // panel 2 pprog = max (0.0, min(1.0, (rstate-0.5)*4.0)); alpha = pprog*145.0*RAD; - paneldir = _V(-sin(alpha), -cos(alpha), 0); - cosa = dotp(dir, paneldir); + paneldir = {-sin(alpha), -cos(alpha), 0}; + cosa = dot(dir, paneldir); if (cosa > 0.0) { if (pprog < 0.5) cosa *= pprog*2.0; cs = cosa * A_radiatorpanel1; @@ -377,8 +377,8 @@ void ThermalSubsystem::AddRadiatorIrradiance (double rPower, const VECTOR3 &dir, // panel 3 pprog = max (0.0, min(1.0, (rstate-0.75)*4.0)); alpha = pprog*145.0*RAD; - paneldir = _V(sin(alpha), -cos(alpha), 0); - cosa = dotp(dir, paneldir); + paneldir = {sin(alpha), -cos(alpha), 0}; + cosa = dot(dir, paneldir); if (cosa > 0.0) { if (pprog < 0.5) cosa *= pprog*2.0; cs = cosa * A_radiatorpanel1; @@ -1009,34 +1009,34 @@ RadiatorControl::RadiatorControl (ThermalSubsystem *_subsys) // Radiator animation static UINT RaddoorGrp[3] = {GRP_Raddoor1,GRP_Raddoor2,GRP_Radiator4}; static MGROUP_ROTATE Raddoor (0, RaddoorGrp, 3, - _V(0,1.481,-3.986), _V(1,0,0), (float)(175*RAD)); + {0,1.481,-3.986}, {1,0,0}, (float)(175*RAD)); static UINT FRadiatorGrp[1] = {GRP_Radiator4}; static MGROUP_ROTATE FRadiator (0, FRadiatorGrp, 1, - _V(0,1.91,-2.965), _V(1,0,0), (float)(185*RAD)); + {0,1.91,-2.965}, {1,0,0}, (float)(185*RAD)); static UINT RadiatorGrp[7] = {GRP_Radiator1,GRP_Radiator1a,GRP_Radiator1b, GRP_Radiator2,GRP_Radiator2a,GRP_Radiator2b,GRP_Radiator3}; static MGROUP_TRANSLATE Radiator (0, RadiatorGrp, 7, - _V(0,0.584,-0.157)); + {0,0.584,-0.157}); static UINT LRadiatorGrp[3] = {GRP_Radiator1,GRP_Radiator1a,GRP_Radiator1b}; static MGROUP_ROTATE LRadiator (0, LRadiatorGrp, 3, - _V(-0.88,1.94,-4.211), _V(0,0.260,0.966), (float)(145*RAD)); + {-0.88,1.94,-4.211}, {0,0.260,0.966}, (float)(145*RAD)); static UINT RRadiatorGrp[3] = {GRP_Radiator2,GRP_Radiator2a,GRP_Radiator2b}; static MGROUP_ROTATE RRadiator (0, RRadiatorGrp, 3, - _V(0.93,1.91,-4.211), _V(0,0.260,0.966), (float)(-145*RAD)); + {0.93,1.91,-4.211}, {0,0.260,0.966}, (float)(-145*RAD)); static VECTOR3 axis1 = {cos(145*RAD),sin(145*RAD)*cos(0.26292),sin(145*RAD)*sin(-0.26292)}; static UINT LaRadiatorGrp[1] = {GRP_Radiator1a}; static MGROUP_ROTATE LaRadiator (0, LaRadiatorGrp, 1, - _V(-0.91, 1.86, -5.055), axis1, (float)(180*RAD)); + {-0.91, 1.86, -5.055}, axis1, (float)(180*RAD)); static UINT LbRadiatorGrp[1] = {GRP_Radiator1b}; static MGROUP_ROTATE LbRadiator (0, LbRadiatorGrp, 1, - _V(-0.91, 2.075, -4.315), axis1, (float)(-180*RAD)); + {-0.91, 2.075, -4.315}, axis1, (float)(-180*RAD)); static VECTOR3 axis2 = {cos(-145*RAD),sin(-145*RAD)*cos(0.26292),sin(-145*RAD)*sin(-0.26292)}; static UINT RaRadiatorGrp[1] = {GRP_Radiator2a}; static MGROUP_ROTATE RaRadiator (0, RaRadiatorGrp, 1, - _V(0.91, 1.675, -5.01), axis2, (float)(180*RAD)); + {0.91, 1.675, -5.01}, axis2, (float)(180*RAD)); static UINT RbRadiatorGrp[1] = {GRP_Radiator2b}; static MGROUP_ROTATE RbRadiator (0, RbRadiatorGrp, 1, - _V(0.91, 1.89, -4.27), axis2, (float)(-180*RAD)); + {0.91, 1.89, -4.27}, axis2, (float)(-180*RAD)); anim_radiator = DG()->CreateAnimation (0); DG()->AddAnimationComponent (anim_radiator, 0, 0.25, &Raddoor); DG()->AddAnimationComponent (anim_radiator, 0.28, 0.53, &FRadiator); diff --git a/Src/Vessel/Dragonfly/Dragonfly.cpp b/Src/Vessel/Dragonfly/Dragonfly.cpp index 3f599c8c4..8a34fcd18 100644 --- a/Src/Vessel/Dragonfly/Dragonfly.cpp +++ b/Src/Vessel/Dragonfly/Dragonfly.cpp @@ -59,67 +59,81 @@ void Dragonfly::RegisterAnimations() static UINT L_Antena[2]= {61,106}; static ANIMCOMP latch1 = { // outer airlock Latch1, 1, 0.0, 0.6, - 0.25,0,3.06, - 0,1,0, - (float)(45.0/180.0*acos(-1.0)), - 0, - 0, - MESHGROUP_TRANSFORM::ROTATE + MESHGROUP_TRANSFORM{ + 0.25,0,3.06, + 0,1,0, + (float)(45.0/180.0*acos(-1.0)), + 0, + 0, + MESHGROUP_TRANSFORM::ROTATE + } }; static ANIMCOMP latch2 = { // outer airlock Latch2, 1, 0.0, 0.6, - -0.25,0,3.06, - 0,1,0, - (float)(-45.0/180.0*acos(-1.0)), - 0, - 0, - MESHGROUP_TRANSFORM::ROTATE + MESHGROUP_TRANSFORM{ + -0.25,0,3.06, + 0,1,0, + (float)(-45.0/180.0*acos(-1.0)), + 0, + 0, + MESHGROUP_TRANSFORM::ROTATE + } }; static ANIMCOMP latch3 = { // outer airlock Latch3, 1, 0.5, 1.0, - 0,0,0.5, - 0, - 0, - MESHGROUP_TRANSFORM::TRANSLATE + MESHGROUP_TRANSFORM{ + 0,0,0.5, + 0, + 0, + MESHGROUP_TRANSFORM::TRANSLATE + } }; static ANIMCOMP U_yaw_ant = { // outer airlock U_Antena, 2, 0.0, 1.0, - 0,0,0, - 0,1,0, - (float)(300.0/180.0*acos(-1.0)), - 0, - 0, - MESHGROUP_TRANSFORM::ROTATE + MESHGROUP_TRANSFORM{ + 0,0,0, + 0,1,0, + (float)(300.0/180.0*acos(-1.0)), + 0, + 0, + MESHGROUP_TRANSFORM::ROTATE + } }; static ANIMCOMP U_pitch_ant = { // outer airlock U_Antena, 2, 0.0, 1.0, - 0,3.18,0, - 1,0,0, - (float)(-75.0/180.0*acos(-1.0)), - 0, - 0, - MESHGROUP_TRANSFORM::ROTATE + MESHGROUP_TRANSFORM{ + 0,3.18,0, + 1,0,0, + (float)(-75.0/180.0*acos(-1.0)), + 0, + 0, + MESHGROUP_TRANSFORM::ROTATE + } }; Upper_ant_pitch=U_pitch_ant; static ANIMCOMP L_yaw_ant = { // outer airlock L_Antena, 2, 0.0, 1.0, - 0,0,0, - 0,1,0, - (float)(300.0/180.0*acos(-1.0)), - 0, - 0, - MESHGROUP_TRANSFORM::ROTATE + MESHGROUP_TRANSFORM{ + 0,0,0, + 0,1,0, + (float)(300.0/180.0*acos(-1.0)), + 0, + 0, + MESHGROUP_TRANSFORM::ROTATE + } }; static ANIMCOMP L_pitch_ant = { // outer airlock L_Antena, 2, 0.0, 1.0, - 0,-3.18,0, - 1,0,0, - (float)(75.0/180.0*acos(-1.0)), - 0, - 0, - MESHGROUP_TRANSFORM::ROTATE + MESHGROUP_TRANSFORM{ + 0,-3.18,0, + 1,0,0, + (float)(75.0/180.0*acos(-1.0)), + 0, + 0, + MESHGROUP_TRANSFORM::ROTATE + } }; Lower_ant_pitch=L_pitch_ant; @@ -151,9 +165,9 @@ void Dragonfly::SetClassCaps (FILEHANDLE cfg) SetSize (4.0); SetEmptyMass (EMPTY_MASS); - SetCrossSections (_V(23.7,22.5,17.3)); - SetPMI (_V(5.4,5.4,2.5)); - SetCameraOffset (_V(0,1.5,0)); + SetCrossSections ({23.7,22.5,17.3}); + SetPMI ({5.4,5.4,2.5}); + SetCameraOffset ({0,1.5,0}); // ************************* propellant specs ********************************** @@ -162,33 +176,33 @@ void Dragonfly::SetClassCaps (FILEHANDLE cfg) // *********************** thruster definitions ******************************** // thrusters in left pod - th_lp[0] = CreateThruster (_V(-3.5,0,0), _V(1,0,0), 2*MAX_RCS_THRUST, ph_main, ISP); - th_lp[1] = CreateThruster (_V(-2.98,0,-0.8), _V(0,0,1), MAX_RCS_THRUST, ph_main, ISP); - th_lp[2] = CreateThruster (_V(-2.98,0,0.8), _V(0,0,-1), MAX_RCS_THRUST, ph_main, ISP); - th_lp[3] = CreateThruster (_V(-2.98,-0.8,0), _V(0,1,0), MAX_RCS_THRUST, ph_main, ISP); - th_lp[4] = CreateThruster (_V(-2.98,0.8,0), _V(0,-1,0), MAX_RCS_THRUST, ph_main, ISP); + th_lp[0] = CreateThruster ({-3.5,0,0}, {1,0,0}, 2*MAX_RCS_THRUST, ph_main, ISP); + th_lp[1] = CreateThruster ({-2.98,0,-0.8}, {0,0,1}, MAX_RCS_THRUST, ph_main, ISP); + th_lp[2] = CreateThruster ({-2.98,0,0.8}, {0,0,-1}, MAX_RCS_THRUST, ph_main, ISP); + th_lp[3] = CreateThruster ({-2.98,-0.8,0}, {0,1,0}, MAX_RCS_THRUST, ph_main, ISP); + th_lp[4] = CreateThruster ({-2.98,0.8,0}, {0,-1,0}, MAX_RCS_THRUST, ph_main, ISP); // thrusters in right pod - th_rp[0] = CreateThruster (_V(3.5,0,0), _V(-1,0,0), 2*MAX_RCS_THRUST, ph_main, ISP); - th_rp[1] = CreateThruster (_V(2.98,0,-0.8), _V(0,0,1), MAX_RCS_THRUST, ph_main, ISP); - th_rp[2] = CreateThruster (_V(2.98,0,0.8), _V(0,0,-1), MAX_RCS_THRUST, ph_main, ISP); - th_rp[3] = CreateThruster (_V(2.98,-0.8,0), _V(0,1,0), MAX_RCS_THRUST, ph_main, ISP); - th_rp[4] = CreateThruster (_V(2.98,0.8,0), _V(0,-1,0), MAX_RCS_THRUST, ph_main, ISP); + th_rp[0] = CreateThruster ({3.5,0,0}, {-1,0,0}, 2*MAX_RCS_THRUST, ph_main, ISP); + th_rp[1] = CreateThruster ({2.98,0,-0.8}, {0,0,1}, MAX_RCS_THRUST, ph_main, ISP); + th_rp[2] = CreateThruster ({2.98,0,0.8}, {0,0,-1}, MAX_RCS_THRUST, ph_main, ISP); + th_rp[3] = CreateThruster ({2.98,-0.8,0}, {0,1,0}, MAX_RCS_THRUST, ph_main, ISP); + th_rp[4] = CreateThruster ({2.98,0.8,0}, {0,-1,0}, MAX_RCS_THRUST, ph_main, ISP); // thrusters in aft pod (rotational RCS) - th_ap[0] = CreateThruster (_V(-0.8,0,-11.1), _V(1,0,0), MAX_RCS_THRUST, ph_main, ISP); - th_ap[1] = CreateThruster (_V(0.8,0,-11.1), _V(-1,0,0), MAX_RCS_THRUST, ph_main, ISP); - th_ap[2] = CreateThruster (_V(0,-0.8,-11.1), _V(0,1,0), MAX_RCS_THRUST, ph_main, ISP); - th_ap[3] = CreateThruster (_V(0,0.8,-11.1), _V(0,-1,0), MAX_RCS_THRUST, ph_main, ISP); + th_ap[0] = CreateThruster ({-0.8,0,-11.1}, {1,0,0}, MAX_RCS_THRUST, ph_main, ISP); + th_ap[1] = CreateThruster ({0.8,0,-11.1}, {-1,0,0}, MAX_RCS_THRUST, ph_main, ISP); + th_ap[2] = CreateThruster ({0,-0.8,-11.1}, {0,1,0}, MAX_RCS_THRUST, ph_main, ISP); + th_ap[3] = CreateThruster ({0,0.8,-11.1}, {0,-1,0}, MAX_RCS_THRUST, ph_main, ISP); // exhaust definitions for left pod - AddExhaust (th_lp[0], 1, 0.15, _V(-3.5,0.18,-0.18), _V(-1,0,0)); - AddExhaust (th_lp[0], 1, 0.15, _V(-3.5,-0.18,0.18), _V(-1,0,0)); + AddExhaust (th_lp[0], 1, 0.15, {-3.5,0.18,-0.18}, {-1,0,0}); + AddExhaust (th_lp[0], 1, 0.15, {-3.5,-0.18,0.18}, {-1,0,0}); for (i = 1; i < 5; i++) AddExhaust (th_lp[i], 1, 0.15); // exhaust definitions for right pod - AddExhaust (th_rp[0], 1, 0.15, _V(3.5,-0.18,-0.18), _V(1,0,0)); - AddExhaust (th_rp[0], 1, 0.15, _V(3.5,0.18,0.18), _V(1,0,0)); + AddExhaust (th_rp[0], 1, 0.15, {3.5,-0.18,-0.18}, {1,0,0}); + AddExhaust (th_rp[0], 1, 0.15, {3.5,0.18,0.18}, {1,0,0}); for (i = 1; i < 5; i++) AddExhaust (th_rp[i], 1, 0.15); // exhaust definitions for aft pod @@ -199,7 +213,7 @@ void Dragonfly::SetClassCaps (FILEHANDLE cfg) // *************************** docking port ************************************ - SetDockParams (_V(0,0,3.2), _V(0,0,1), _V(0,1,0)); + SetDockParams ({0,0,3.2}, {0,0,1}, {0,1,0}); // ******************************** mesh *************************************** @@ -228,12 +242,12 @@ void Dragonfly::LoadState (FILEHANDLE scn, void *vs) SetAnimState (anim_UY_ant, UY_pos); float ang=(150-UY_pos*300.0)/180.0*acos(-1.0); - Upper_ant_pitch.trans.P.rotparam.axis=_V(cos(ang),0,-sin(ang)); + Upper_ant_pitch.trans.P.rotparam.axis={cos(ang),0,-sin(ang)}; SetAnimState (anim_UP_ant, UP_pos); SetAnimState (anim_LY_ant, LY_pos); ang=(150-LY_pos*300.0)/180.0*acos(-1.0); - Lower_ant_pitch.trans.P.rotparam.axis=_V(cos(ang),0,-sin(ang)); + Lower_ant_pitch.trans.P.rotparam.axis={cos(ang),0,-sin(ang)}; SetAnimState (anim_LP_ant, LP_pos); SetAnimState (anim_latch, dock_latched); @@ -551,7 +565,7 @@ void Dragonfly::Timestep (double simt) if (UY_pos>1) UY_pos=1; SetAnimState (anim_UY_ant, UY_pos); float ang=(150-UY_pos*300.0)/180.0*acos(-1.0); - Upper_ant_pitch.trans.P.rotparam.axis=_V(cos(ang),0,-sin(ang)); + Upper_ant_pitch.trans.P.rotparam.axis={cos(ang),0,-sin(ang)}; }; if ((*AC_power>0)&&(UP_handle)) {if ((UP_handle<0)&&(UP_pos>0)) UP_pos-=oapiGetSysStep()/18.0; @@ -567,7 +581,7 @@ void Dragonfly::Timestep (double simt) if (LY_pos>1) LY_pos=1; SetAnimState (anim_LY_ant, LY_pos); float ang=(150-LY_pos*300.0)/180.0*acos(-1.0); - Lower_ant_pitch.trans.P.rotparam.axis=_V(cos(ang),0,-sin(ang)); + Lower_ant_pitch.trans.P.rotparam.axis={cos(ang),0,-sin(ang)}; }; if ((*AC_power>0)&&(LP_handle)) {if ((LP_handle<0)&&(LP_pos>0)) LP_pos-=oapiGetSysStep()/18.0; diff --git a/Src/Vessel/Dragonfly/Hsystems.cpp b/Src/Vessel/Dragonfly/Hsystems.cpp index 104fedfec..ef2e2146d 100644 --- a/Src/Vessel/Dragonfly/Hsystems.cpp +++ b/Src/Vessel/Dragonfly/Hsystems.cpp @@ -416,7 +416,7 @@ VentValve::VentValve(VESSEL *i_vessel,vector3 i_p,vector3 i_dir,float w,float h, {pos=i_p; dir=i_dir.normalize(); //need a way to inquire force for a vessel vessel=i_vessel; ph=vessel->CreatePropellantResource(0.005); - th=vessel->CreateThruster(_V(pos.x,pos.y,pos.z),_V(dir.x,dir.y,dir.z),10*MaxF,ph,1e99); + th=vessel->CreateThruster({pos.x,pos.y,pos.z},{dir.x,dir.y,dir.z},10*MaxF,ph,1e99); vessel->AddExhaust(th,w,h); }; void VentValve::Set(VESSEL *i_vessel,vector3 i_p,vector3 i_dir,float w,float h ,int i_open,int ct,float i_maxf, Valve *i_src) @@ -424,7 +424,7 @@ void VentValve::Set(VESSEL *i_vessel,vector3 i_p,vector3 i_dir,float w,float h , pos=i_p; dir=i_dir.normalize(); //need a way to inquire force for a vessel vessel=i_vessel; ph=vessel->CreatePropellantResource(0.005); - th=vessel->CreateThruster(_V(pos.x,pos.y,pos.z),_V(dir.x,dir.y,dir.z),10*MaxF,ph,1e99); + th=vessel->CreateThruster({pos.x,pos.y,pos.z},{dir.x,dir.y,dir.z},10*MaxF,ph,1e99); vessel->AddExhaust(th,w,h); }; diff --git a/Src/Vessel/Dragonfly/instruments.cpp b/Src/Vessel/Dragonfly/instruments.cpp index 413fbf296..3564a88ab 100644 --- a/Src/Vessel/Dragonfly/instruments.cpp +++ b/Src/Vessel/Dragonfly/instruments.cpp @@ -1172,7 +1172,7 @@ vector3 Vpos,Vvel,Vnorm; Vvel=_vector3(vel2.x,vel2.y,vel2.z);//this is V vector in local frame Vvel.selfnormalize(); Vnorm.x+=gpos.x;Vnorm.y+=gpos.y;Vnorm.z+=gpos.z; - parent->v->Global2Local(_V(Vnorm.x,Vnorm.y,Vnorm.z),vel2); + parent->v->Global2Local({Vnorm.x,Vnorm.y,Vnorm.z},vel2); Vnorm=_vector3(vel2.x,vel2.y,vel2.z);//and this is N vector in local frame Vnorm.selfnormalize(); diff --git a/Src/Vessel/HST/HST.cpp b/Src/Vessel/HST/HST.cpp index 1604a68a1..a7945d675 100644 --- a/Src/Vessel/HST/HST.cpp +++ b/Src/Vessel/HST/HST.cpp @@ -45,16 +45,16 @@ void HST::DefineAnimations (void) { // 1. Hi-gain antenna static UINT HiGainAnt1Grp[2] = {1,3}; - static MGROUP_ROTATE HiGainAnt1 (0, HiGainAnt1Grp, 2, _V(0.002579,1.993670,0.238158), _V(-1,0,0), (float)(PI*0.51)); + static MGROUP_ROTATE HiGainAnt1 (0, HiGainAnt1Grp, 2, {0.002579,1.993670,0.238158}, {-1,0,0}, (float)(PI*0.51)); static UINT HiGainAnt2Grp[2] = {0,2}; - static MGROUP_ROTATE HiGainAnt2 (0, HiGainAnt2Grp, 2, _V(0.002740,-2.013091,0.238118), _V(1,0,0), (float)(PI*0.51)); + static MGROUP_ROTATE HiGainAnt2 (0, HiGainAnt2Grp, 2, {0.002740,-2.013091,0.238118}, {1,0,0}, (float)(PI*0.51)); anim_ant = CreateAnimation (0.0196); AddAnimationComponent (anim_ant, 0, 0.5, &HiGainAnt1); AddAnimationComponent (anim_ant, 0, 1, &HiGainAnt2); // 2. Main telescope hatch static UINT HatchGrp[1] = {86}; - static MGROUP_ROTATE Hatch (0, HatchGrp, 1, _V(0.089688,1.456229,7.526453), _V(-1,0,0), (float)(RAD*113)); + static MGROUP_ROTATE Hatch (0, HatchGrp, 1, {0.089688,1.456229,7.526453}, {-1,0,0}, (float)(RAD*113)); anim_hatch = CreateAnimation (0); AddAnimationComponent (anim_hatch, 0, 1, &Hatch); @@ -62,17 +62,17 @@ void HST::DefineAnimations (void) anim_array = CreateAnimation (1); static UINT ArrayLFoldGrp[5] = {87,88,89,90,103}; static UINT ArrayRFoldGrp[5] = {92,93,94,95,102}; - static MGROUP_ROTATE ArrayLFold1 (0, ArrayLFoldGrp, 5, _V(-1.9, 0.053583,1.429349), _V(0,-1,0), (float)(PI*0.5)); + static MGROUP_ROTATE ArrayLFold1 (0, ArrayLFoldGrp, 5, {-1.9, 0.053583,1.429349}, {0,-1,0}, (float)(PI*0.5)); AddAnimationComponent (anim_array, 0, 0.4, &ArrayLFold1); - static MGROUP_ROTATE ArrayLFold2 (0, ArrayLFoldGrp, 5, _V(0,0.053583,1.429349), _V(-1,0,0), (float)(PI*0.5)); + static MGROUP_ROTATE ArrayLFold2 (0, ArrayLFoldGrp, 5, {0,0.053583,1.429349}, {-1,0,0}, (float)(PI*0.5)); AddAnimationComponent (anim_array, 0.4, 0.6, &ArrayLFold2); - static MGROUP_SCALE ArrayLFold3 (0, ArrayLFoldGrp, 4, _V(0,0.053583,1.429349), _V(1,1,4)); + static MGROUP_SCALE ArrayLFold3 (0, ArrayLFoldGrp, 4, {0,0.053583,1.429349}, {1,1,4}); AddAnimationComponent (anim_array, 0.6, 1, &ArrayLFold3); - static MGROUP_ROTATE ArrayRFold1 (0, ArrayRFoldGrp, 5, _V( 1.9, 0.053583,1.429349), _V(0, 1,0), (float)(PI*0.5)); + static MGROUP_ROTATE ArrayRFold1 (0, ArrayRFoldGrp, 5, { 1.9, 0.053583,1.429349}, {0, 1,0}, (float)(PI*0.5)); AddAnimationComponent (anim_array, 0, 0.4, &ArrayRFold1); - static MGROUP_ROTATE ArrayRFold2 (0, ArrayRFoldGrp, 5, _V(0,0.053583,1.429349), _V(-1,0,0), (float)(PI*0.5)); + static MGROUP_ROTATE ArrayRFold2 (0, ArrayRFoldGrp, 5, {0,0.053583,1.429349}, {-1,0,0}, (float)(PI*0.5)); AddAnimationComponent (anim_array, 0.4, 0.6, &ArrayRFold2); - static MGROUP_SCALE ArrayRFold3 (0, ArrayRFoldGrp, 4, _V(0,0.053583,1.429349), _V(1,1,4)); + static MGROUP_SCALE ArrayRFold3 (0, ArrayRFoldGrp, 4, {0,0.053583,1.429349}, {1,1,4}); AddAnimationComponent (anim_array, 0.6, 1, &ArrayRFold3); } diff --git a/Src/Vessel/MMU/mmu.cpp b/Src/Vessel/MMU/mmu.cpp index 532c02284..5469753f8 100644 --- a/Src/Vessel/MMU/mmu.cpp +++ b/Src/Vessel/MMU/mmu.cpp @@ -46,124 +46,124 @@ void AddAttitudeJets(VESSEL *vessel) main_tank = vessel->CreatePropellantResource(11.8); - m_exhaust_pos= _V(.37,0.64,-.22); - m_exhaust_ref = _V(0,0,1); + m_exhaust_pos= {.37,0.64,-.22}; + m_exhaust_ref = {0,0,1}; thruster[0] = vessel->CreateThruster(m_exhaust_pos, m_exhaust_ref, JET_THRUST, main_tank, JET_ISP); vessel->AddExhaust(thruster[0],0.2,0.01); - m_exhaust_pos= _V(-.37,0.64,-.22); - m_exhaust_ref = _V(0,0,1); + m_exhaust_pos= {-.37,0.64,-.22}; + m_exhaust_ref = {0,0,1}; thruster[6] = vessel->CreateThruster(m_exhaust_pos, m_exhaust_ref, JET_THRUST, main_tank, JET_ISP); vessel->AddExhaust(thruster[6],0.2,0.01); - m_exhaust_pos= _V(.37,-0.64,-.22); - m_exhaust_ref = _V(0,0,1); + m_exhaust_pos= {.37,-0.64,-.22}; + m_exhaust_ref = {0,0,1}; thruster[12] = vessel->CreateThruster(m_exhaust_pos, m_exhaust_ref, JET_THRUST, main_tank, JET_ISP); vessel->AddExhaust(thruster[12],0.2,0.01); - m_exhaust_pos= _V(-.37,-0.64,-.22); - m_exhaust_ref = _V(0,0,1); + m_exhaust_pos= {-.37,-0.64,-.22}; + m_exhaust_ref = {0,0,1}; thruster[18] = vessel->CreateThruster(m_exhaust_pos, m_exhaust_ref, JET_THRUST, main_tank, JET_ISP); vessel->AddExhaust(thruster[18],0.2,0.01); - m_exhaust_pos= _V(.37,.64,0.22); - m_exhaust_ref = _V(0,0,-1); + m_exhaust_pos= {.37,.64,0.22}; + m_exhaust_ref = {0,0,-1}; thruster[1] = vessel->CreateThruster(m_exhaust_pos, m_exhaust_ref, JET_THRUST, main_tank, JET_ISP); vessel->AddExhaust(thruster[1],0.2,0.01); - m_exhaust_pos= _V(-.37,0.64, 0.22); - m_exhaust_ref = _V(0,0,-1); + m_exhaust_pos= {-.37,0.64, 0.22}; + m_exhaust_ref = {0,0,-1}; thruster[7] = vessel->CreateThruster(m_exhaust_pos, m_exhaust_ref, JET_THRUST, main_tank, JET_ISP); vessel->AddExhaust(thruster[7],0.2,0.01); - m_exhaust_pos= _V(.37,-0.64,0.22); - m_exhaust_ref = _V(0,0,-1); + m_exhaust_pos= {.37,-0.64,0.22}; + m_exhaust_ref = {0,0,-1}; thruster[13] = vessel->CreateThruster(m_exhaust_pos, m_exhaust_ref, JET_THRUST, main_tank, JET_ISP); vessel->AddExhaust(thruster[13],0.2,0.01); - m_exhaust_pos= _V(-.37,-0.64,0.22); - m_exhaust_ref = _V(0,0,-1); + m_exhaust_pos= {-.37,-0.64,0.22}; + m_exhaust_ref = {0,0,-1}; thruster[19] = vessel->CreateThruster(m_exhaust_pos, m_exhaust_ref, JET_THRUST, main_tank, JET_ISP); vessel->AddExhaust(thruster[19],0.2,0.01); - m_exhaust_pos= _V(.40,.64,0.17); - m_exhaust_ref = _V(-1,0,0); + m_exhaust_pos= {.40,.64,0.17}; + m_exhaust_ref = {-1,0,0}; thruster[2] = vessel->CreateThruster(m_exhaust_pos, m_exhaust_ref, JET_THRUST, main_tank, JET_ISP); vessel->AddExhaust(thruster[2],0.2,0.01); - m_exhaust_pos= _V(.40,.64,-0.17); - m_exhaust_ref = _V(-1,0,0); + m_exhaust_pos= {.40,.64,-0.17}; + m_exhaust_ref = {-1,0,0}; thruster[3] = vessel->CreateThruster(m_exhaust_pos, m_exhaust_ref, JET_THRUST, main_tank, JET_ISP); vessel->AddExhaust(thruster[3],0.2,0.01); - m_exhaust_pos= _V(.37,.68,0.17); - m_exhaust_ref = _V(0,-1,0); + m_exhaust_pos= {.37,.68,0.17}; + m_exhaust_ref = {0,-1,0}; thruster[4] = vessel->CreateThruster(m_exhaust_pos, m_exhaust_ref, JET_THRUST, main_tank, JET_ISP); vessel->AddExhaust(thruster[4],0.2,0.01); - m_exhaust_pos= _V(.37,.68,-0.17); - m_exhaust_ref = _V(0,-1,0); + m_exhaust_pos= {.37,.68,-0.17}; + m_exhaust_ref = {0,-1,0}; thruster[5] = vessel->CreateThruster(m_exhaust_pos, m_exhaust_ref, JET_THRUST, main_tank, JET_ISP); vessel->AddExhaust(thruster[5],0.2,0.01); - m_exhaust_pos= _V(-.40,0.64, 0.17); - m_exhaust_ref = _V(1,0,0); + m_exhaust_pos= {-.40,0.64, 0.17}; + m_exhaust_ref = {1,0,0}; thruster[8] = vessel->CreateThruster(m_exhaust_pos, m_exhaust_ref, JET_THRUST, main_tank, JET_ISP); vessel->AddExhaust(thruster[8],0.2,0.01); - m_exhaust_pos= _V(-.40,0.64, -0.17); - m_exhaust_ref = _V(1,0,0); + m_exhaust_pos= {-.40,0.64, -0.17}; + m_exhaust_ref = {1,0,0}; thruster[9] = vessel->CreateThruster(m_exhaust_pos, m_exhaust_ref, JET_THRUST, main_tank, JET_ISP); vessel->AddExhaust(thruster[9],0.2,0.01); - m_exhaust_pos= _V(-.37,0.68, 0.17); - m_exhaust_ref = _V(0,-1,0); + m_exhaust_pos= {-.37,0.68, 0.17}; + m_exhaust_ref = {0,-1,0}; thruster[10] = vessel->CreateThruster(m_exhaust_pos, m_exhaust_ref, JET_THRUST, main_tank, JET_ISP); vessel->AddExhaust(thruster[10],0.2,0.01); - m_exhaust_pos= _V(-.37,0.68, -0.17); - m_exhaust_ref = _V(0,-1,0); + m_exhaust_pos= {-.37,0.68, -0.17}; + m_exhaust_ref = {0,-1,0}; thruster[11] = vessel->CreateThruster(m_exhaust_pos, m_exhaust_ref, JET_THRUST, main_tank, JET_ISP); vessel->AddExhaust(thruster[11],0.2,0.01); - m_exhaust_pos= _V(.40,-0.64,0.17); - m_exhaust_ref = _V(-1,0,0); + m_exhaust_pos= {.40,-0.64,0.17}; + m_exhaust_ref = {-1,0,0}; thruster[14] = vessel->CreateThruster(m_exhaust_pos, m_exhaust_ref, JET_THRUST, main_tank, JET_ISP); vessel->AddExhaust(thruster[14],0.2,0.01); - m_exhaust_pos= _V(.40,-0.64,-0.17); - m_exhaust_ref = _V(-1,0,0); + m_exhaust_pos= {.40,-0.64,-0.17}; + m_exhaust_ref = {-1,0,0}; thruster[15] = vessel->CreateThruster(m_exhaust_pos, m_exhaust_ref, JET_THRUST, main_tank, JET_ISP); vessel->AddExhaust(thruster[15],0.2,0.01); - m_exhaust_pos= _V(.37,-0.68,0.17); - m_exhaust_ref = _V(0,1,0); + m_exhaust_pos= {.37,-0.68,0.17}; + m_exhaust_ref = {0,1,0}; thruster[16] = vessel->CreateThruster(m_exhaust_pos, m_exhaust_ref, JET_THRUST, main_tank, JET_ISP); vessel->AddExhaust(thruster[16],0.2,0.01); - m_exhaust_pos= _V(.37,-0.68,-0.17); - m_exhaust_ref = _V(0,1,0); + m_exhaust_pos= {.37,-0.68,-0.17}; + m_exhaust_ref = {0,1,0}; thruster[17] = vessel->CreateThruster(m_exhaust_pos, m_exhaust_ref, JET_THRUST, main_tank, JET_ISP); vessel->AddExhaust(thruster[17],0.2,0.01); - m_exhaust_pos= _V(-.40,-0.68,0.17); - m_exhaust_ref = _V(1,0,0); + m_exhaust_pos= {-.40,-0.68,0.17}; + m_exhaust_ref = {1,0,0}; thruster[20] = vessel->CreateThruster(m_exhaust_pos, m_exhaust_ref, JET_THRUST, main_tank, JET_ISP); vessel->AddExhaust(thruster[20],0.2,0.01); - m_exhaust_pos= _V(-.40,-0.68,-0.17); - m_exhaust_ref = _V(1,0,0); + m_exhaust_pos= {-.40,-0.68,-0.17}; + m_exhaust_ref = {1,0,0}; thruster[21] = vessel->CreateThruster(m_exhaust_pos, m_exhaust_ref, JET_THRUST, main_tank, JET_ISP); vessel->AddExhaust(thruster[21],0.2,0.01); - m_exhaust_pos= _V(-.37,-0.68,0.17); - m_exhaust_ref = _V(0,1,0); + m_exhaust_pos= {-.37,-0.68,0.17}; + m_exhaust_ref = {0,1,0}; thruster[22] = vessel->CreateThruster(m_exhaust_pos, m_exhaust_ref, JET_THRUST, main_tank, JET_ISP); vessel->AddExhaust(thruster[22],0.2,0.01); - m_exhaust_pos= _V(-.37,-0.68,-0.17); - m_exhaust_ref = _V(0,1,0); + m_exhaust_pos= {-.37,-0.68,-0.17}; + m_exhaust_ref = {0,1,0}; thruster[23] = vessel->CreateThruster(m_exhaust_pos, m_exhaust_ref, JET_THRUST, main_tank, JET_ISP); vessel->AddExhaust(thruster[23],0.2,0.01); @@ -263,15 +263,15 @@ void SetMMU (VESSEL *vessel) // vessel->SetMaxThrust (ENGINE_HOVER, 0); // vessel->SetMaxThrust (ENGINE_ATTITUDE, 31.5); // ============================================================== - vessel->SetPMI (_V(.35,.13,0.35)); - vessel->SetCrossSections (_V(1.64,.77,1.64)); + vessel->SetPMI ({.35,.13,0.35}); + vessel->SetCrossSections ({1.64,.77,1.64}); // ============================================================== vessel->SetCW (0.3, 0.3, .3, .3); - vessel->SetRotDrag (_V(0.7,0.7,1.2)); + vessel->SetRotDrag ({0.7,0.7,1.2}); vessel->SetPitchMomentScale (0); vessel->SetYawMomentScale (0); vessel->SetLiftCoeffFunc (0); - vessel->SetDockParams (_V(0,0,.44), _V(0,0,1), _V(0,1,0)); + vessel->SetDockParams ({0,0,.44}, {0,0,1}, {0,1,0}); // ============================================================== vessel->ClearMeshes(); @@ -279,12 +279,12 @@ void SetMMU (VESSEL *vessel) vessel->ClearAttExhaustRefs(); vessel->ClearPropellantResources(); vessel->ClearThrusterDefinitions(); - mesh_pos = _V(0,-0.24,0.16); + mesh_pos = {0,-0.24,0.16}; vessel->AddMesh("mmu", &mesh_pos); AddAttitudeJets(vessel); - vessel->SetDockParams(_V(0,0,0.5),_V(0,0,1),_V(0,1,0)); - //vessel->SetDockParams(_V(0,0,0),_V(0,-1,0),_V(0,0,1)); - //vessel->CreateDock(_V(0,0,0.22),_V(0,0,1),_V(0,1,0)); + vessel->SetDockParams({0,0,0.5},{0,0,1},{0,1,0}); + //vessel->SetDockParams({0,0,0},{0,-1,0},{0,0,1}); + //vessel->CreateDock({0,0,0.22},{0,0,1},{0,1,0}); } diff --git a/Src/Vessel/Quadcopter/PropulsionSubsys.cpp b/Src/Vessel/Quadcopter/PropulsionSubsys.cpp index c414d905f..987532fdc 100644 --- a/Src/Vessel/Quadcopter/PropulsionSubsys.cpp +++ b/Src/Vessel/Quadcopter/PropulsionSubsys.cpp @@ -37,9 +37,9 @@ Rotor::Rotor(const PropulsionSubsystem *ssys, const VECTOR3 &pos, SpinDirection , m_spin(spin) , m_throttle(0.0) { - m_liftDir = _V(0, 1, 0); + m_liftDir = {0, 1, 0}; VECTOR3 cgDir = unit(-pos); - m_torqueDir = crossp(cgDir, m_liftDir); + m_torqueDir = cross(cgDir, m_liftDir); if (spin == SPIN_RIGHT) m_torqueDir = -m_torqueDir; } @@ -75,10 +75,10 @@ PropulsionSubsystem::PropulsionSubsystem(Quadcopter *qc) { const double px = 0.4, pz = 0.4, py = 0.15; - m_rotor[ROTOR_FL] = new Rotor(this, _V(-px, py, pz), Rotor::SPIN_LEFT); - m_rotor[ROTOR_FR] = new Rotor(this, _V( px, py, pz), Rotor::SPIN_RIGHT); - m_rotor[ROTOR_BL] = new Rotor(this, _V(-px, py, -pz), Rotor::SPIN_RIGHT); - m_rotor[ROTOR_BR] = new Rotor(this, _V( px, py, -pz), Rotor::SPIN_LEFT); + m_rotor[ROTOR_FL] = new Rotor(this, {-px, py, pz}, Rotor::SPIN_LEFT); + m_rotor[ROTOR_FR] = new Rotor(this, { px, py, pz}, Rotor::SPIN_RIGHT); + m_rotor[ROTOR_BL] = new Rotor(this, {-px, py, -pz}, Rotor::SPIN_RIGHT); + m_rotor[ROTOR_BR] = new Rotor(this, { px, py, -pz}, Rotor::SPIN_LEFT); m_holdActive = false; m_throttle = 0.0; @@ -166,7 +166,7 @@ void PropulsionSubsystem::clbkPreStep(double simt, double simdt, double mjd) if (m_autoHeading) { VECTOR3 v; QC()->GetHorizonAirspeedVector(v); - if (length(v) > 5.0) { + if (len(v) > 5.0) { double course = atan2(v.x, v.z); SetHeading(course, dy); fixedHeading = true; diff --git a/Src/Vessel/Quadcopter/Quadcopter.cpp b/Src/Vessel/Quadcopter/Quadcopter.cpp index 8a3a02fea..d73b7d827 100644 --- a/Src/Vessel/Quadcopter/Quadcopter.cpp +++ b/Src/Vessel/Quadcopter/Quadcopter.cpp @@ -22,24 +22,24 @@ Quadcopter::Quadcopter(OBJHANDLE hObj, int fmodel) void Quadcopter::clbkSetClassCaps(FILEHANDLE cfg) { const TOUCHDOWNVTX tdv[12] = { - { _V(-0.3, -0.26, 0.3), 1e3, 5e1, 1.6, 1.6 }, - { _V(-0.3, -0.26, -0.3), 1e3, 5e1, 1.6, 1.6 }, - { _V( 0.3, -0.26, -0.3), 1e3, 5e1, 1.6, 1.6 }, - { _V( 0.3, -0.26, 0.3), 1e3, 5e1, 1.6 }, - { _V( 0.6, 0.15, 0.4), 1e3, 5e1, 1.6 }, - { _V( 0.6, 0.15, -0.4), 1e3, 5e1, 1.6 }, - { _V(-0.6, 0.15, 0.4), 1e3, 5e1, 1.6 }, - { _V(-0.6, 0.15, -0.4), 1e3, 5e1, 1.6 }, - { _V( 0.4, 0.15, 0.6), 1e3, 5e1, 1.6 }, - { _V(-0.4, 0.15, 0.6), 1e3, 5e1, 1.6 }, - { _V( 0.4, 0.15, -0.6), 1e3, 5e1, 1.6 }, - { _V(-0.4, 0.15, -0.6), 1e3, 5e1, 1.6 } + { {-0.3, -0.26, 0.3}, 1e3, 5e1, 1.6, 1.6 }, + { {-0.3, -0.26, -0.3}, 1e3, 5e1, 1.6, 1.6 }, + { { 0.3, -0.26, -0.3}, 1e3, 5e1, 1.6, 1.6 }, + { { 0.3, -0.26, 0.3}, 1e3, 5e1, 1.6 }, + { { 0.6, 0.15, 0.4}, 1e3, 5e1, 1.6 }, + { { 0.6, 0.15, -0.4}, 1e3, 5e1, 1.6 }, + { {-0.6, 0.15, 0.4}, 1e3, 5e1, 1.6 }, + { {-0.6, 0.15, -0.4}, 1e3, 5e1, 1.6 }, + { { 0.4, 0.15, 0.6}, 1e3, 5e1, 1.6 }, + { {-0.4, 0.15, 0.6}, 1e3, 5e1, 1.6 }, + { { 0.4, 0.15, -0.6}, 1e3, 5e1, 1.6 }, + { {-0.4, 0.15, -0.6}, 1e3, 5e1, 1.6 } }; SetEmptyMass(2.0); SetSize(0.3); - SetPMI(_V(0.02, 0.05, 0.02)); - SetCrossSections(_V(0.1, 0.6, 0.1)); + SetPMI({0.02, 0.05, 0.02}); + SetCrossSections({0.1, 0.6, 0.1}); SetCW(1.0, 1.0, 1.0, 1.0); SetTouchdownPoints(tdv, 12); exmesh_tpl = oapiLoadMeshGlobal("Quadcopter\\quadcopter"); @@ -48,7 +48,7 @@ void Quadcopter::clbkSetClassCaps(FILEHANDLE cfg) // Dummy thruster ph = CreatePropellantResource(0.01, 0.01); SetDefaultPropellantResource(ph); - th = CreateThruster(_V(0, 0, 0), _V(0, 1, 0), 1e-10, ph, 1e-5, 1e-5); + th = CreateThruster({0, 0, 0}, {0, 1, 0}, 1e-10, ph, 1e-5, 1e-5); tgh = CreateThrusterGroup(&th, 1, THGROUP_MAIN); } diff --git a/Src/Vessel/ShuttleA/ShuttleA.cpp b/Src/Vessel/ShuttleA/ShuttleA.cpp index 931102398..db330bddd 100644 --- a/Src/Vessel/ShuttleA/ShuttleA.cpp +++ b/Src/Vessel/ShuttleA/ShuttleA.cpp @@ -48,22 +48,22 @@ GDIParams g_Param; static const int ntdvtx = 16; static TOUCHDOWNVTX tdvtx[ntdvtx] = { - {_V(-3 ,-3.05, 12.5), 3.5e6, 3.5e5, 3}, - {_V(-3 ,-3.05,-13.5), 3e6, 3e5, 3}, - {_V( 3 ,-3.05,-13.5), 3e6, 3e5, 3}, - {_V( 3 ,-3.05, 12.5), 3.5e6, 3.5e5, 3}, - {_V(-7.7, 0 ,-0.4 ), 3e7, 3e6, 3}, - {_V( 7.7, 0 ,-0.4 ), 3e7, 3e6, 3}, - {_V(-1.5, 3 ,13.5 ), 3e7, 3e6, 3}, - {_V( 1.5, 3 ,13.5 ), 3e7, 3e6, 3}, - {_V(-1.3, 2.8 ,17 ), 3e7, 3e6, 3}, - {_V( 1.3, 2.8 ,17 ), 3e7, 3e6, 3}, - {_V(-1.8, 0 ,18.3 ), 3e7, 3e6, 3}, - {_V( 1.8, 0 ,18.3 ), 3e7, 3e6, 3}, - {_V(-1.9, 2.2 ,-13.8), 3e7, 3e6, 3}, - {_V( 1.9, 2.2 ,-13.8), 3e7, 3e6, 3}, - {_V(-3.3, 0 ,-14.9), 3e7, 3e6, 3}, - {_V( 3.3, 0 ,-14.9), 3e7, 3e6, 3} + {{-3 ,-3.05, 12.5}, 3.5e6, 3.5e5, 3}, + {{-3 ,-3.05,-13.5}, 3e6, 3e5, 3}, + {{ 3 ,-3.05,-13.5}, 3e6, 3e5, 3}, + {{ 3 ,-3.05, 12.5}, 3.5e6, 3.5e5, 3}, + {{-7.7, 0 ,-0.4 }, 3e7, 3e6, 3}, + {{ 7.7, 0 ,-0.4 }, 3e7, 3e6, 3}, + {{-1.5, 3 ,13.5 }, 3e7, 3e6, 3}, + {{ 1.5, 3 ,13.5 }, 3e7, 3e6, 3}, + {{-1.3, 2.8 ,17 }, 3e7, 3e6, 3}, + {{ 1.3, 2.8 ,17 }, 3e7, 3e6, 3}, + {{-1.8, 0 ,18.3 }, 3e7, 3e6, 3}, + {{ 1.8, 0 ,18.3 }, 3e7, 3e6, 3}, + {{-1.9, 2.2 ,-13.8}, 3e7, 3e6, 3}, + {{ 1.9, 2.2 ,-13.8}, 3e7, 3e6, 3}, + {{-3.3, 0 ,-14.9}, 3e7, 3e6, 3}, + {{ 3.3, 0 ,-14.9}, 3e7, 3e6, 3} }; // ============================================================== @@ -156,10 +156,10 @@ ShuttleA::~ShuttleA () void ShuttleA::DefineAnimations () { static UINT LeftPodGrp[4] = {4,5,7,9}; - static MGROUP_ROTATE leftpod(0,LeftPodGrp,4,_V(0,0,0),_V(1,0,0),(float)PI); + static MGROUP_ROTATE leftpod(0,LeftPodGrp,4,{0,0,0},{1,0,0},(float)PI); static UINT RightPodGrp[4] = {6,8,10,11}; - static MGROUP_ROTATE rightpod(0,RightPodGrp,4,_V(0,0,0),_V(1,0,0),(float)PI); + static MGROUP_ROTATE rightpod(0,RightPodGrp,4,{0,0,0},{1,0,0},(float)PI); // Register animation for hover/retro pods anim_pod[0] = CreateAnimation (0); @@ -168,22 +168,22 @@ void ShuttleA::DefineAnimations () AddAnimationComponent (anim_pod[1], 0.0f,1.0f,&rightpod); static UINT UpperDockHatch = 19; - static MGROUP_ROTATE upperhatch(0,&UpperDockHatch,1,_V(0,0.554f,18.677401f),_V(-1,0,0),(float)PI); + static MGROUP_ROTATE upperhatch(0,&UpperDockHatch,1,{0,0.554f,18.677401f},{-1,0,0},(float)PI); static UINT LowerDockHatch = 18; - static MGROUP_ROTATE lowerhatch(0,&LowerDockHatch,1,_V(0,-0.554f,18.677401f),_V(1,0,0),(float)PI); + static MGROUP_ROTATE lowerhatch(0,&LowerDockHatch,1,{0,-0.554f,18.677401f},{1,0,0},(float)PI); anim_dock = CreateAnimation (0); AddAnimationComponent (anim_dock,0.0f,1.0f, &upperhatch); AddAnimationComponent (anim_dock,0.2f,1.0f, &lowerhatch); // outer airlock static UINT OuterAirlock_groups = GRP_Docking_Hatch; - static MGROUP_ROTATE OuterAirlock_anim(0, &OuterAirlock_groups, 1, _V(0.498895f, 0.0f, 18.6131f), _V(0, -1, 0), (float)(0.51f*PI)); + static MGROUP_ROTATE OuterAirlock_anim(0, &OuterAirlock_groups, 1, {0.498895f, 0.0f, 18.6131f}, {0, -1, 0}, (float)(0.51f*PI)); anim_lock[0] = CreateAnimation (0); AddAnimationComponent (anim_lock[0], 0.0f ,1.0f, &OuterAirlock_anim); // inner airlock static UINT InnerAirlock_groups = GRP_Airlock_Hatch; - static MGROUP_ROTATE InnerAirlock_anim(0, &InnerAirlock_groups, 1, _V(-0.4102f, 0.0f, 16.5474f), _V(0, -1, 0), (float)(0.55f * PI)); + static MGROUP_ROTATE InnerAirlock_anim(0, &InnerAirlock_groups, 1, {-0.4102f, 0.0f, 16.5474f}, {0, -1, 0}, (float)(0.55f * PI)); anim_lock[1] = CreateAnimation (0); AddAnimationComponent(anim_lock[1], 0.0f, 1.0f, &InnerAirlock_anim); @@ -198,17 +198,17 @@ void ShuttleA::DefineAnimations () static UINT GEAR_left_leg_back_p1=36; static UINT GEAR_left_leg_back_p2=23; - static MGROUP_TRANSLATE MGEAR_left_leg_first (0, GEAR_left_leg, 3, _V(-0.194,0.224,0.0)); - static MGROUP_TRANSLATE MGEAR_left_leg_second (0, GEAR_left_leg, 3, _V(-0.091,0.331,0.0)); - static MGROUP_TRANSLATE MGEAR_right_leg_first (0, GEAR_right_leg, 3, _V(0.194,0.224,0.0)); - static MGROUP_TRANSLATE MGEAR_right_leg_second (0, GEAR_right_leg, 3, _V(0.091,0.331,0.0)); + static MGROUP_TRANSLATE MGEAR_left_leg_first (0, GEAR_left_leg, 3, {-0.194,0.224,0.0}); + static MGROUP_TRANSLATE MGEAR_left_leg_second (0, GEAR_left_leg, 3, {-0.091,0.331,0.0}); + static MGROUP_TRANSLATE MGEAR_right_leg_first (0, GEAR_right_leg, 3, {0.194,0.224,0.0}); + static MGROUP_TRANSLATE MGEAR_right_leg_second (0, GEAR_right_leg, 3, {0.091,0.331,0.0}); - static MGROUP_ROTATE MGEAR_left_leg_front_p1(0,&GEAR_left_leg_front_p1,1,_V(-1.655f,-1.942f,0.0f),_V(0,0,-1),0.9948f); - static MGROUP_ROTATE MGEAR_left_leg_front_p2(0,&GEAR_left_leg_front_p2,1,_V(-1.112f,-1.718f,0.0f),_V(0,0,-1),0.5235f); - static MGROUP_ROTATE MGEAR_left_leg_mid_p1(0,&GEAR_left_leg_mid_p1,1,_V(-3.007f,-1.942f,0.0f),_V(0,0,-1),0.9948f); - static MGROUP_ROTATE MGEAR_left_leg_mid_p2(0,&GEAR_left_leg_mid_p2,1,_V(-2.464f,-1.718f,0.0f),_V(0,0,-1),0.5235f); - static MGROUP_ROTATE MGEAR_left_leg_back_p1(0,&GEAR_left_leg_back_p1,1,_V(-2.49f,-1.942f,0.0f),_V(0,0,-1),0.9948f); - static MGROUP_ROTATE MGEAR_left_leg_back_p2(0,&GEAR_left_leg_back_p2,1,_V(-1.947f,-1.718f,0.0f),_V(0,0,-1),0.5235f); + static MGROUP_ROTATE MGEAR_left_leg_front_p1(0,&GEAR_left_leg_front_p1,1,{-1.655f,-1.942f,0.0f},{0,0,-1},0.9948f); + static MGROUP_ROTATE MGEAR_left_leg_front_p2(0,&GEAR_left_leg_front_p2,1,{-1.112f,-1.718f,0.0f},{0,0,-1},0.5235f); + static MGROUP_ROTATE MGEAR_left_leg_mid_p1(0,&GEAR_left_leg_mid_p1,1,{-3.007f,-1.942f,0.0f},{0,0,-1},0.9948f); + static MGROUP_ROTATE MGEAR_left_leg_mid_p2(0,&GEAR_left_leg_mid_p2,1,{-2.464f,-1.718f,0.0f},{0,0,-1},0.5235f); + static MGROUP_ROTATE MGEAR_left_leg_back_p1(0,&GEAR_left_leg_back_p1,1,{-2.49f,-1.942f,0.0f},{0,0,-1},0.9948f); + static MGROUP_ROTATE MGEAR_left_leg_back_p2(0,&GEAR_left_leg_back_p2,1,{-1.947f,-1.718f,0.0f},{0,0,-1},0.5235f); static UINT GEAR_right_leg_front_p1=39; static UINT GEAR_right_leg_front_p2=26; @@ -217,12 +217,12 @@ void ShuttleA::DefineAnimations () static UINT GEAR_right_leg_back_p1=37; static UINT GEAR_right_leg_back_p2=24; - static MGROUP_ROTATE MGEAR_right_leg_front_p1(0,&GEAR_right_leg_front_p1,1,_V(1.655f,-1.942f,0.0f),_V(0,0,1),0.9948f); - static MGROUP_ROTATE MGEAR_right_leg_front_p2(0,&GEAR_right_leg_front_p2,1,_V(1.112f,-1.718f,0.0f),_V(0,0,1),0.5235f); - static MGROUP_ROTATE MGEAR_right_leg_mid_p1(0,&GEAR_right_leg_mid_p1,1,_V(3.007f,-1.942f,0.0f),_V(0,0,1),0.9948f); - static MGROUP_ROTATE MGEAR_right_leg_mid_p2(0,&GEAR_right_leg_mid_p2,1,_V(2.464f,-1.718f,0.0f),_V(0,0,1),0.5235f); - static MGROUP_ROTATE MGEAR_right_leg_back_p1(0,&GEAR_right_leg_back_p1,1,_V(2.49f,-1.942f,0.0f),_V(0,0,1),0.9948f); - static MGROUP_ROTATE MGEAR_right_leg_back_p2(0,&GEAR_right_leg_back_p2,1,_V(1.947f,-1.718f,0.0f),_V(0,0,1),0.5235f); + static MGROUP_ROTATE MGEAR_right_leg_front_p1(0,&GEAR_right_leg_front_p1,1,{1.655f,-1.942f,0.0f},{0,0,1},0.9948f); + static MGROUP_ROTATE MGEAR_right_leg_front_p2(0,&GEAR_right_leg_front_p2,1,{1.112f,-1.718f,0.0f},{0,0,1},0.5235f); + static MGROUP_ROTATE MGEAR_right_leg_mid_p1(0,&GEAR_right_leg_mid_p1,1,{3.007f,-1.942f,0.0f},{0,0,1},0.9948f); + static MGROUP_ROTATE MGEAR_right_leg_mid_p2(0,&GEAR_right_leg_mid_p2,1,{2.464f,-1.718f,0.0f},{0,0,1},0.5235f); + static MGROUP_ROTATE MGEAR_right_leg_back_p1(0,&GEAR_right_leg_back_p1,1,{2.49f,-1.942f,0.0f},{0,0,1},0.9948f); + static MGROUP_ROTATE MGEAR_right_leg_back_p2(0,&GEAR_right_leg_back_p2,1,{1.947f,-1.718f,0.0f},{0,0,1},0.5235f); anim_gear = CreateAnimation(0.0); AddAnimationComponent (anim_gear, 0.0f, 0.5f, &MGEAR_left_leg_first); @@ -248,8 +248,8 @@ void ShuttleA::DefineAnimations () //auxiliary thrusters static UINT POD_thruster_left[1] = {22}; static UINT POD_thruster_right[1] = {30}; - static MGROUP_TRANSLATE MPOD_thruster_left (1, POD_thruster_left, 1, _V(0,0.05,0.023)); - static MGROUP_TRANSLATE MPOD_thruster_right (1, POD_thruster_right, 1, _V(0,0.05,0.023)); + static MGROUP_TRANSLATE MPOD_thruster_left (1, POD_thruster_left, 1, {0,0.05,0.023}); + static MGROUP_TRANSLATE MPOD_thruster_right (1, POD_thruster_right, 1, {0,0.05,0.023}); anim_pod_thrust_left = CreateAnimation (0); AddAnimationComponent (anim_pod_thrust_left, 0, 1.0, &MPOD_thruster_left); @@ -259,8 +259,8 @@ void ShuttleA::DefineAnimations () //hover thrusters static UINT HOVER_thruster_left[1]={31}; static UINT HOVER_thruster_right[1]={32}; - static MGROUP_TRANSLATE MHOVER_thruster_left(1,HOVER_thruster_left,1,_V(0,0.085,0.037)); - static MGROUP_TRANSLATE MHOVER_thruster_right(1,HOVER_thruster_right,1,_V(0,0.085,0.037)); + static MGROUP_TRANSLATE MHOVER_thruster_left(1,HOVER_thruster_left,1,{0,0.085,0.037}); + static MGROUP_TRANSLATE MHOVER_thruster_right(1,HOVER_thruster_right,1,{0,0.085,0.037}); anim_hover_thrust_left= CreateAnimation(0); AddAnimationComponent (anim_hover_thrust_left, 0, 1.0, &MHOVER_thruster_left); @@ -270,8 +270,8 @@ void ShuttleA::DefineAnimations () //main thrusters static UINT MAIN_thruster_left[1]={27}; static UINT MAIN_thruster_right[1]={28}; - static MGROUP_TRANSLATE MMAIN_thruster_left (1,MAIN_thruster_left,1,_V(0,0.085,0.037)); - static MGROUP_TRANSLATE MMAIN_thruster_right (1,MAIN_thruster_right,1,_V(0,0.085,0.037)); + static MGROUP_TRANSLATE MMAIN_thruster_left (1,MAIN_thruster_left,1,{0,0.085,0.037}); + static MGROUP_TRANSLATE MMAIN_thruster_right (1,MAIN_thruster_right,1,{0,0.085,0.037}); anim_main_thrust_left = CreateAnimation (0); AddAnimationComponent (anim_main_thrust_left, 0, 1.0, &MMAIN_thruster_left); @@ -280,43 +280,43 @@ void ShuttleA::DefineAnimations () // POD angle switch static UINT POD_angle_switch[2]={34,35}; - static MGROUP_ROTATE MPOD_angle_switch(1,POD_angle_switch,2,_V(-0.596666398f,1.98931781f,16.28778112f),//added 0.10 to Z - _V(0.996194179f,0.036831321f,-0.078997542f),1.570796327f); + static MGROUP_ROTATE MPOD_angle_switch(1,POD_angle_switch,2,{-0.596666398f,1.98931781f,16.28778112f},//added 0.10 to Z + {0.996194179f,0.036831321f,-0.078997542f},1.570796327f); anim_pod_angle= CreateAnimation(0.5); AddAnimationComponent(anim_pod_angle,0.0f,1.0f,&MPOD_angle_switch); // RCS mode switch static UINT RCS_mode_switch=33; - static MGROUP_ROTATE MRCS_mode_switch(1,&RCS_mode_switch,1,_V(-0.479842445f,2.100993049f,16.32856942f),//added 0.10 to Z - _V(0.996194179f,0.036831321f,-0.078997542f),1.570796327f); + static MGROUP_ROTATE MRCS_mode_switch(1,&RCS_mode_switch,1,{-0.479842445f,2.100993049f,16.32856942f},//added 0.10 to Z + {0.996194179f,0.036831321f,-0.078997542f},1.570796327f); anim_rcs_mode= CreateAnimation(0.5); AddAnimationComponent(anim_rcs_mode,0.0f,1.0f,&MRCS_mode_switch); //DOCK port switch static UINT DOCK_switch=39; - static MGROUP_ROTATE MDOCK_switch (1,&DOCK_switch,1,_V(-0.212890075f,2.608840923f,16.09495988f), - _V(0.0f,0.061554834f,-0.998103703f),1.570796327f/2.0f); + static MGROUP_ROTATE MDOCK_switch (1,&DOCK_switch,1,{-0.212890075f,2.608840923f,16.09495988f}, + {0.0f,0.061554834f,-0.998103703f},1.570796327f/2.0f); anim_dock_switch= CreateAnimation(0.5); AddAnimationComponent(anim_dock_switch,0.0f,1.0f,&MDOCK_switch); //AIRLOCK switch static UINT AIRLOCK_switch=41; - static MGROUP_ROTATE MAIRLOCK_switch (1,&AIRLOCK_switch,1,_V(-0.243815575f,2.639114618f,16.09778152f), - _V(0.0f,0.061554834f,-0.998103703f),1.570796327f/2.0f); + static MGROUP_ROTATE MAIRLOCK_switch (1,&AIRLOCK_switch,1,{-0.243815575f,2.639114618f,16.09778152f}, + {0.0f,0.061554834f,-0.998103703f},1.570796327f/2.0f); anim_airlock_switch = CreateAnimation(0.5); AddAnimationComponent(anim_airlock_switch,0.0f,1.0f,&MAIRLOCK_switch); //GEAR switch static UINT GEAR_switch=49; - static MGROUP_ROTATE MGEAR_switch (1, &GEAR_switch,1, _V(-0.212890075f,2.610353215f,16.07043827f), - _V(0.0f,0.061554834f,-0.998103703f),1.570796327f/2.0f); + static MGROUP_ROTATE MGEAR_switch (1, &GEAR_switch,1, {-0.212890075f,2.610353215f,16.07043827f}, + {0.0f,0.061554834f,-0.998103703f},1.570796327f/2.0f); anim_gear_switch = CreateAnimation(0.5); AddAnimationComponent(anim_gear_switch,0.0f,1.0f,&MGEAR_switch); //CARGO ARM switch static UINT CARGO_switch=54; - static MGROUP_ROTATE MCARGO_switch (1, &CARGO_switch,1, _V(-0.212890075f,2.616076201f,15.97764079f), - _V(0.0f,0.061554834f,-0.998103703f),1.570796327f/2.0f); + static MGROUP_ROTATE MCARGO_switch (1, &CARGO_switch,1, {-0.212890075f,2.616076201f,15.97764079f}, + {0.0f,0.061554834f,-0.998103703f},1.570796327f/2.0f); anim_cargo_switch = CreateAnimation(0.5); AddAnimationComponent(anim_cargo_switch,0.0f,1.0f,&MCARGO_switch); } @@ -436,7 +436,7 @@ void ShuttleA::SetPodAngle (UINT which, double angle) if (which & (1<GlobalRot(rot,gcrot); v->GlobalRot(dir,gcdir); //should be normal by now - if ((dotp(grot,gcrot)>MAX_GRAPPLING_ANG)&&(dotp(gdir,gcdir)<-MAX_GRAPPLING_ANG))//dotrot=1 and dotdir=-1(same up vector, but opposing dir vectors) + if ((dot(grot, gcrot) > MAX_GRAPPLING_ANG) && (dot(gdir, gcdir) < -MAX_GRAPPLING_ANG))//dotrot=1 and dotdir=-1(same up vector, but opposing dir vectors) { AttachChild (hV, payload_attachment[grapple], hAtt); ComputePayloadMass(); @@ -1102,17 +1102,17 @@ void ShuttleA::clbkSetClassCaps (FILEHANDLE cfg) SetSize (17.0); SetClipRadius(19.0); - SetPMI (_V(86.6, 89.8, 5.5)); + SetPMI ({86.6, 89.8, 5.5}); SetEmptyMass (EMPTY_MASS); payload_mass = 0.0; VECTOR3 r[2] = {{0,0,8}, {0,0,-8}}; SetGravityGradientDamping (20.0); SetCW (0.2, 0.2, 1.5, 1.5); - SetCrossSections (_V(132.2, 237.9, 42.4)); - SetRotDrag (_V(0.7, 0.7, 0.3)); + SetCrossSections ({132.2, 237.9, 42.4}); + SetRotDrag ({0.7, 0.7, 0.3}); SetSurfaceFrictionCoeff (0.5, 0.5); - SetCameraOffset (_V(-0.575f,2.4f,15.9f)); - SetDockParams (_V(0,0,18.677), _V(0,0,1), _V(0,1,0)); + SetCameraOffset ({-0.575f,2.4f,15.9f}); + SetDockParams ({0,0,18.677}, {0,0,1}, {0,1,0}); SetTouchdownPoints (tdvtx, ntdvtx); @@ -1155,29 +1155,29 @@ void ShuttleA::clbkSetClassCaps (FILEHANDLE cfg) }; // main thrusters - th_main[0] = CreateThruster (_V(-1.7598,0,-13.8705), _V(0,0,1), MAX_MAIN_THRUST, ph_main,ISP_P0, ISP); - th_main[1] = CreateThruster (_V( 1.7598,0,-13.8705), _V(0,0,1), MAX_MAIN_THRUST, ph_main, ISP_P0, ISP); + th_main[0] = CreateThruster ({-1.7598,0,-13.8705}, {0,0,1}, MAX_MAIN_THRUST, ph_main,ISP_P0, ISP); + th_main[1] = CreateThruster ({ 1.7598,0,-13.8705}, {0,0,1}, MAX_MAIN_THRUST, ph_main, ISP_P0, ISP); thg_main = CreateThrusterGroup (th_main, 2, THGROUP_MAIN); AddExhaust (th_main[0], 12, 2, 2.2); AddExhaust (th_main[1], 12, 2, 2.2); - AddExhaustStream (th_main[0], _V(0,0,-21), &contrail_main); - AddExhaustStream (th_main[0], _V(-1.7598,0,-16.0), &exhaust_main); - AddExhaustStream (th_main[1], _V( 1.7598,0,-16.0), &exhaust_main); + AddExhaustStream (th_main[0], {0,0,-21}, &contrail_main); + AddExhaustStream (th_main[0], {-1.7598,0,-16.0}, &exhaust_main); + AddExhaustStream (th_main[1], { 1.7598,0,-16.0}, &exhaust_main); // hover thrusters - th_hover[0] = CreateThruster (_V(0,-1.49016, 13.0), _V(0,1,0), MAX_HOVER_THRUST, ph_main, ISP_P0, ISP); - th_hover[1] = CreateThruster (_V(0,-1.49016,-13.0), _V(0,1,0), MAX_HOVER_THRUST, ph_main, ISP_P0, ISP); + th_hover[0] = CreateThruster ({0,-1.49016, 13.0}, {0,1,0}, MAX_HOVER_THRUST, ph_main, ISP_P0, ISP); + th_hover[1] = CreateThruster ({0,-1.49016,-13.0}, {0,1,0}, MAX_HOVER_THRUST, ph_main, ISP_P0, ISP); thg_hover = CreateThrusterGroup (th_hover, 2, THGROUP_HOVER); - AddExhaust (th_hover[0], 10, 1, _V(0,-2.265335, 13.608049), _V(0,-1,0)); - AddExhaust (th_hover[1], 10, 1, _V(0,-2.265335,-12.88175), _V(0,-1,0)); - AddExhaustStream (th_hover[0], _V(0,-6, 13.608049), &contrail_hover); - AddExhaustStream (th_hover[1], _V(0,-6,-12.88175), &contrail_hover); - AddExhaustStream (th_hover[0], _V(0,-4, 13.608049), &exhaust_main); - AddExhaustStream (th_hover[1], _V(0,-4,-12.88175), &exhaust_main); + AddExhaust (th_hover[0], 10, 1, {0,-2.265335, 13.608049}, {0,-1,0}); + AddExhaust (th_hover[1], 10, 1, {0,-2.265335,-12.88175}, {0,-1,0}); + AddExhaustStream (th_hover[0], {0,-6, 13.608049}, &contrail_hover); + AddExhaustStream (th_hover[1], {0,-6,-12.88175}, &contrail_hover); + AddExhaustStream (th_hover[0], {0,-4, 13.608049}, &exhaust_main); + AddExhaustStream (th_hover[1], {0,-4,-12.88175}, &exhaust_main); // retro/hover thrusters - th_pod[0] = CreateThruster (_V(-6.97215,0,0), _V(0,0,-1), MAX_RETRO_THRUST, ph_main,ISP_P0, ISP); - th_pod[1] = CreateThruster (_V( 6.97215,0,0), _V(0,0,-1), MAX_RETRO_THRUST, ph_main, ISP_P0, ISP); + th_pod[0] = CreateThruster ({-6.97215,0,0}, {0,0,-1}, MAX_RETRO_THRUST, ph_main,ISP_P0, ISP); + th_pod[1] = CreateThruster ({ 6.97215,0,0}, {0,0,-1}, MAX_RETRO_THRUST, ph_main, ISP_P0, ISP); thg_pod = CreateThrusterGroup (th_pod, 2, THGROUP_USER); AddExhaust (th_pod[0], 6, 1.0, 1.33422); AddExhaust (th_pod[1], 6, 1.0, 1.33422); @@ -1186,78 +1186,78 @@ void ShuttleA::clbkSetClassCaps (FILEHANDLE cfg) // attitude thrusters THRUSTER_HANDLE th_att_rot[4], th_att_lin[4]; - th_att_rot[0] = CreateThruster (_V(-6.01139, 0.61554,0), _V(0,-1,0), MAX_RCS_THRUST, ph_rcs, ISP); - th_att_rot[1] = CreateThruster (_V( 6.01139,-0.61554,0), _V(0, 1,0), MAX_RCS_THRUST, ph_rcs, ISP); - th_att_rot[2] = CreateThruster (_V(-6.01139,-0.61554,0), _V(0, 1,0), MAX_RCS_THRUST, ph_rcs, ISP); - th_att_rot[3] = CreateThruster (_V( 6.01139, 0.61554,0), _V(0,-1,0), MAX_RCS_THRUST, ph_rcs, ISP); + th_att_rot[0] = CreateThruster ({-6.01139, 0.61554,0}, {0,-1,0}, MAX_RCS_THRUST, ph_rcs, ISP); + th_att_rot[1] = CreateThruster ({ 6.01139,-0.61554,0}, {0, 1,0}, MAX_RCS_THRUST, ph_rcs, ISP); + th_att_rot[2] = CreateThruster ({-6.01139,-0.61554,0}, {0, 1,0}, MAX_RCS_THRUST, ph_rcs, ISP); + th_att_rot[3] = CreateThruster ({ 6.01139, 0.61554,0}, {0,-1,0}, MAX_RCS_THRUST, ph_rcs, ISP); CreateThrusterGroup (th_att_rot, 2, THGROUP_ATT_BANKLEFT); CreateThrusterGroup (th_att_rot+2, 2, THGROUP_ATT_BANKRIGHT); - AddExhaust (th_att_rot[0], 0.7, 0.08, _V(-6.01139, 0.61554,-0.1), _V(0,-1,0)); - AddExhaust (th_att_rot[0], 0.7, 0.08, _V(-6.01139, 0.61554,0.1), _V(0,-1,0)); - AddExhaust (th_att_rot[1], 0.7, 0.08, _V( 6.01139,-0.61554,-0.1), _V(0, 1,0)); - AddExhaust (th_att_rot[1], 0.7, 0.08, _V( 6.01139,-0.61554,0.1), _V(0, 1,0)); - AddExhaust (th_att_rot[2], 0.7, 0.08, _V(-6.01139,-0.61554,-0.1), _V(0, 1,0)); - AddExhaust (th_att_rot[2], 0.7, 0.08, _V(-6.01139,-0.61554,0.1), _V(0, 1,0)); - AddExhaust (th_att_rot[3], 0.7, 0.08, _V( 6.01139, 0.61554,-0.1), _V(0,-1,0)); - AddExhaust (th_att_rot[3], 0.7, 0.08, _V( 6.01139, 0.61554,0.1), _V(0,-1,0)); - - th_att_rot[0] = th_att_lin[0] = CreateThruster (_V(0,0, 15), _V(0, 1,0), MAX_RCS_THRUST, ph_rcs, ISP); - th_att_rot[1] = th_att_lin[2] = CreateThruster (_V(0,0,-15), _V(0,-1,0), MAX_RCS_THRUST, ph_rcs, ISP); - th_att_rot[2] = th_att_lin[3] = CreateThruster (_V(0,0, 15), _V(0,-1,0), MAX_RCS_THRUST, ph_rcs, ISP); - th_att_rot[3] = th_att_lin[1] = CreateThruster (_V(0,0,-15), _V(0, 1,0), MAX_RCS_THRUST, ph_rcs, ISP); + AddExhaust (th_att_rot[0], 0.7, 0.08, {-6.01139, 0.61554,-0.1}, {0,-1,0}); + AddExhaust (th_att_rot[0], 0.7, 0.08, {-6.01139, 0.61554,0.1}, {0,-1,0}); + AddExhaust (th_att_rot[1], 0.7, 0.08, { 6.01139,-0.61554,-0.1}, {0, 1,0}); + AddExhaust (th_att_rot[1], 0.7, 0.08, { 6.01139,-0.61554,0.1}, {0, 1,0}); + AddExhaust (th_att_rot[2], 0.7, 0.08, {-6.01139,-0.61554,-0.1}, {0, 1,0}); + AddExhaust (th_att_rot[2], 0.7, 0.08, {-6.01139,-0.61554,0.1}, {0, 1,0}); + AddExhaust (th_att_rot[3], 0.7, 0.08, { 6.01139, 0.61554,-0.1}, {0,-1,0}); + AddExhaust (th_att_rot[3], 0.7, 0.08, { 6.01139, 0.61554,0.1}, {0,-1,0}); + + th_att_rot[0] = th_att_lin[0] = CreateThruster ({0,0, 15}, {0, 1,0}, MAX_RCS_THRUST, ph_rcs, ISP); + th_att_rot[1] = th_att_lin[2] = CreateThruster ({0,0,-15}, {0,-1,0}, MAX_RCS_THRUST, ph_rcs, ISP); + th_att_rot[2] = th_att_lin[3] = CreateThruster ({0,0, 15}, {0,-1,0}, MAX_RCS_THRUST, ph_rcs, ISP); + th_att_rot[3] = th_att_lin[1] = CreateThruster ({0,0,-15}, {0, 1,0}, MAX_RCS_THRUST, ph_rcs, ISP); CreateThrusterGroup (th_att_rot, 2, THGROUP_ATT_PITCHUP); CreateThrusterGroup (th_att_rot+2, 2, THGROUP_ATT_PITCHDOWN); CreateThrusterGroup (th_att_lin, 2, THGROUP_ATT_UP); CreateThrusterGroup (th_att_lin+2, 2, THGROUP_ATT_DOWN); - AddExhaust (th_att_rot[0], 0.7, 0.08, _V(-0.13,-0.9,17.95), _V(0,-1,0)); - AddExhaust (th_att_rot[0], 0.7, 0.08, _V( 0.13,-0.9,17.95), _V(0,-1,0)); - AddExhaust (th_att_rot[1], 0.7, 0.08, _V( 0, 2.25,-14.0), _V(0, 1,0)); - AddExhaust (th_att_rot[1], 0.7, 0.08, _V( 0, 2.25,-14.23), _V(0, 1,0)); - AddExhaust (th_att_rot[2], 0.7, 0.08, _V(-0.13, 2.03, 17.9), _V(0, 1,0)); - AddExhaust (th_att_rot[2], 0.7, 0.08, _V( 0.13, 2.03, 17.9), _V(0, 1,0)); - AddExhaust (th_att_rot[3], 0.7, 0.08, _V(-0.13,-1.76,-14.1), _V(0,-1,0)); - AddExhaust (th_att_rot[3], 0.7, 0.08, _V( 0.13,-1.76,-14.1), _V(0,-1,0)); - - th_att_rot[0] = th_att_lin[0] = CreateThruster (_V(0,0, 15), _V( 1,0,0), MAX_RCS_THRUST, ph_rcs, ISP); - th_att_rot[1] = th_att_lin[2] = CreateThruster (_V(0,0,-15), _V(-1,0,0), MAX_RCS_THRUST, ph_rcs, ISP); - th_att_rot[2] = th_att_lin[3] = CreateThruster (_V(0,0, 15), _V(-1,0,0), MAX_RCS_THRUST, ph_rcs, ISP); - th_att_rot[3] = th_att_lin[1] = CreateThruster (_V(0,0,-15), _V( 1,0,0), MAX_RCS_THRUST, ph_rcs, ISP); + AddExhaust (th_att_rot[0], 0.7, 0.08, {-0.13,-0.9,17.95}, {0,-1,0}); + AddExhaust (th_att_rot[0], 0.7, 0.08, { 0.13,-0.9,17.95}, {0,-1,0}); + AddExhaust (th_att_rot[1], 0.7, 0.08, { 0, 2.25,-14.0}, {0, 1,0}); + AddExhaust (th_att_rot[1], 0.7, 0.08, { 0, 2.25,-14.23}, {0, 1,0}); + AddExhaust (th_att_rot[2], 0.7, 0.08, {-0.13, 2.03, 17.9}, {0, 1,0}); + AddExhaust (th_att_rot[2], 0.7, 0.08, { 0.13, 2.03, 17.9}, {0, 1,0}); + AddExhaust (th_att_rot[3], 0.7, 0.08, {-0.13,-1.76,-14.1}, {0,-1,0}); + AddExhaust (th_att_rot[3], 0.7, 0.08, { 0.13,-1.76,-14.1}, {0,-1,0}); + + th_att_rot[0] = th_att_lin[0] = CreateThruster ({0,0, 15}, { 1,0,0}, MAX_RCS_THRUST, ph_rcs, ISP); + th_att_rot[1] = th_att_lin[2] = CreateThruster ({0,0,-15}, {-1,0,0}, MAX_RCS_THRUST, ph_rcs, ISP); + th_att_rot[2] = th_att_lin[3] = CreateThruster ({0,0, 15}, {-1,0,0}, MAX_RCS_THRUST, ph_rcs, ISP); + th_att_rot[3] = th_att_lin[1] = CreateThruster ({0,0,-15}, { 1,0,0}, MAX_RCS_THRUST, ph_rcs, ISP); CreateThrusterGroup (th_att_rot, 2, THGROUP_ATT_YAWRIGHT); CreateThrusterGroup (th_att_rot+2, 2, THGROUP_ATT_YAWLEFT); CreateThrusterGroup (th_att_lin, 2, THGROUP_ATT_RIGHT); CreateThrusterGroup (th_att_lin+2, 2, THGROUP_ATT_LEFT); - AddExhaust (th_att_rot[0], 0.7, 0.08, _V(-2.18, 0.13, 17.87), _V(-1,0,0)); - AddExhaust (th_att_rot[0], 0.7, 0.08, _V(-2.18,-0.13, 17.87), _V(-1,0,0)); - AddExhaust (th_att_rot[1], 0.7, 0.08, _V( 3.347, 0, -14.24), _V( 1,0,0)); - AddExhaust (th_att_rot[1], 0.7, 0.08, _V( 3.347, 0, -14.03), _V( 1,0,0)); - AddExhaust (th_att_rot[2], 0.7, 0.08, _V( 2.18, 0.13, 17.87), _V( 1,0,0)); - AddExhaust (th_att_rot[2], 0.7, 0.08, _V( 2.18,-0.13, 17.87), _V( 1,0,0)); - AddExhaust (th_att_rot[3], 0.7, 0.08, _V(-3.347, 0, -14.24), _V(-1,0,0)); - AddExhaust (th_att_rot[3], 0.7, 0.08, _V(-3.347, 0, -14.03), _V(-1,0,0)); - - th_att_lin[0] = CreateThruster (_V( 0,0,0), _V(0,0, 1), 2*MAX_RCS_THRUST, ph_rcs, ISP); - th_att_lin[1] = CreateThruster (_V( 0,0,0), _V(0,0,-1), 2*MAX_RCS_THRUST, ph_rcs, ISP); + AddExhaust (th_att_rot[0], 0.7, 0.08, {-2.18, 0.13, 17.87}, {-1,0,0}); + AddExhaust (th_att_rot[0], 0.7, 0.08, {-2.18,-0.13, 17.87}, {-1,0,0}); + AddExhaust (th_att_rot[1], 0.7, 0.08, { 3.347, 0, -14.24}, { 1,0,0}); + AddExhaust (th_att_rot[1], 0.7, 0.08, { 3.347, 0, -14.03}, { 1,0,0}); + AddExhaust (th_att_rot[2], 0.7, 0.08, { 2.18, 0.13, 17.87}, { 1,0,0}); + AddExhaust (th_att_rot[2], 0.7, 0.08, { 2.18,-0.13, 17.87}, { 1,0,0}); + AddExhaust (th_att_rot[3], 0.7, 0.08, {-3.347, 0, -14.24}, {-1,0,0}); + AddExhaust (th_att_rot[3], 0.7, 0.08, {-3.347, 0, -14.03}, {-1,0,0}); + + th_att_lin[0] = CreateThruster ({ 0,0,0}, {0,0, 1}, 2*MAX_RCS_THRUST, ph_rcs, ISP); + th_att_lin[1] = CreateThruster ({ 0,0,0}, {0,0,-1}, 2*MAX_RCS_THRUST, ph_rcs, ISP); CreateThrusterGroup (th_att_lin, 1, THGROUP_ATT_FORWARD); CreateThrusterGroup (th_att_lin+1, 1, THGROUP_ATT_BACK); - AddExhaust (th_att_lin[0], 0.7, 0.15, _V( 6.01139,0,-1.16102), _V(0,0,-1)); - AddExhaust (th_att_lin[0], 0.7, 0.15, _V(-6.01139,0,-1.16102), _V(0,0,-1)); - AddExhaust (th_att_lin[1], 0.7, 0.15, _V( 6.01139,0, 1.16102), _V(0,0, 1)); - AddExhaust (th_att_lin[1], 0.7, 0.15, _V(-6.01139,0, 1.16102), _V(0,0, 1)); + AddExhaust (th_att_lin[0], 0.7, 0.15, { 6.01139,0,-1.16102}, {0,0,-1}); + AddExhaust (th_att_lin[0], 0.7, 0.15, {-6.01139,0,-1.16102}, {0,0,-1}); + AddExhaust (th_att_lin[1], 0.7, 0.15, { 6.01139,0, 1.16102}, {0,0, 1}); + AddExhaust (th_att_lin[1], 0.7, 0.15, {-6.01139,0, 1.16102}, {0,0, 1}); // ************************ Attachment points **************************** char attach_id[8]={"SH"}; - payload_attachment[0] = CreateAttachment (false,_V(1.76f,0.0f, 6.28f),_V(0.0f,0.0f,-1.0f),_V(0.0f,1.0f,0.0f),attach_id); - payload_attachment[1] = CreateAttachment (false,_V(1.76f,0.0f,-1.28f),_V(0.0f,0.0f,-1.0f),_V(0.0f,1.0f,0.0f),attach_id); - payload_attachment[2] = CreateAttachment (false,_V(1.76f,0.0f,-6.600f),_V(0.0f,0.0f,-1.0f),_V(0.0f,1.0f,0.0f),attach_id); + payload_attachment[0] = CreateAttachment (false,{1.76f,0.0f, 6.28f},{0.0f,0.0f,-1.0f},{0.0f,1.0f,0.0f},attach_id); + payload_attachment[1] = CreateAttachment (false,{1.76f,0.0f,-1.28f},{0.0f,0.0f,-1.0f},{0.0f,1.0f,0.0f},attach_id); + payload_attachment[2] = CreateAttachment (false,{1.76f,0.0f,-6.600f},{0.0f,0.0f,-1.0f},{0.0f,1.0f,0.0f},attach_id); - payload_attachment[3] = CreateAttachment (false,_V(-1.76f,0.0f, 6.28f),_V(0.0f,0.0f,-1.0f),_V(0.0f,1.0f,0.0f),attach_id); - payload_attachment[4] = CreateAttachment (false,_V(-1.76f,0.0f,-1.28f),_V(0.0f,0.0f,-1.0f),_V(0.0f,1.0f,0.0f),attach_id); - payload_attachment[5] = CreateAttachment (false,_V(-1.76f,0.0f,-6.600f),_V(0.0f,0.0f,-1.0f),_V(0.0f,1.0f,0.0f),attach_id); + payload_attachment[3] = CreateAttachment (false,{-1.76f,0.0f, 6.28f},{0.0f,0.0f,-1.0f},{0.0f,1.0f,0.0f},attach_id); + payload_attachment[4] = CreateAttachment (false,{-1.76f,0.0f,-1.28f},{0.0f,0.0f,-1.0f},{0.0f,1.0f,0.0f},attach_id); + payload_attachment[5] = CreateAttachment (false,{-1.76f,0.0f,-6.600f},{0.0f,0.0f,-1.0f},{0.0f,1.0f,0.0f},attach_id); // ************************ Airfoil **************************** ClearAirfoilDefinitions(); - CreateAirfoil (LIFT_VERTICAL, _V(0,0,0), Shuttle_MomentCoeff, 8, 140, 0.1); + CreateAirfoil (LIFT_VERTICAL, {0,0,0}, Shuttle_MomentCoeff, 8, 140, 0.1); // ************************ Meshes **************************** @@ -1454,7 +1454,7 @@ void ShuttleA::clbkPostCreation () pod_angle_request[i] = pod_angle[i]; double sina = sin(pod_angle[i]), cosa = cos(pod_angle[i]); SetAnimation (anim_pod[i], pod_angle[i]/PI); - SetThrusterDir (th_pod[i], _V(0,sina,-cosa)); + SetThrusterDir (th_pod[i], {0,sina,-cosa}); } SetAnimation (anim_dock, dock_proc); for (i = 0; i < 2; i++) @@ -1488,7 +1488,7 @@ void ShuttleA::clbkPostStep (double simt, double simdt, double mjd) pod_angle[i] = pod_angle_request[i]; } double sina = sin(pod_angle[i]), cosa = cos(pod_angle[i]); - SetThrusterDir (th_pod[i], _V(0,sina,-cosa)); + SetThrusterDir (th_pod[i], {0,sina,-cosa}); SetAnimation (anim_pod[i], pod_angle[i]/PI); redraw = true; } @@ -1621,14 +1621,14 @@ bool ShuttleA::clbkLoadPanel2D (int id, PANELHANDLE hPanel, DWORD viewW, DWORD v DefineMainPanel (hPanel); ScalePanel (hPanel, viewW, viewH); oapiSetPanelNeighbours (-1,-1,1,-1); - SetCameraDefaultDirection (_V(0,0,1)); // forward + SetCameraDefaultDirection ({0,0,1}); // forward oapiCameraSetCockpitDir (0,0); // look forward return true; case 1: DefineOverheadPanel (hPanel); ScalePanel (hPanel, viewW, viewH); oapiSetPanelNeighbours (-1,-1,-1,0); - SetCameraDefaultDirection (_V(0,0,1)); // forward + SetCameraDefaultDirection ({0,0,1}); // forward oapiCameraSetCockpitDir (0,20*RAD); // look up return true; default: @@ -2030,24 +2030,24 @@ bool ShuttleA::clbkLoadVC (int id) oapiVCRegisterArea (AID_ENGINEPODLEVEL, PANEL_REDRAW_ALWAYS, PANEL_MOUSE_LBDOWN|PANEL_MOUSE_LBPRESSED); oapiVCSetAreaClickmode_Quadrilateral (AID_ENGINEPODLEVEL, - _V(-0.662748635f,2.000830898f,16.28952821f), - _V(-0.637967796f,2.001747096f,16.2875631f), - _V(-0.662748635f,1.951983908f,16.26675439f), - _V(-0.637967796f,1.952900106f,16.26478928f)); + {-0.662748635f,2.000830898f,16.28952821f}, + {-0.637967796f,2.001747096f,16.2875631f}, + {-0.662748635f,1.951983908f,16.26675439f}, + {-0.637967796f,1.952900106f,16.26478928f}); oapiVCRegisterArea (AID_ENGINEHOVER, PANEL_REDRAW_ALWAYS, PANEL_MOUSE_LBDOWN|PANEL_MOUSE_LBPRESSED); oapiVCSetAreaClickmode_Quadrilateral (AID_ENGINEHOVER, - _V(-0.610236858f,2.113885847f,16.33716825f), - _V(-0.584865999f,2.114823859f,16.33515635f), - _V(-0.610236858f,2.017265428f,16.29212113f), - _V(-0.584865999f,2.01820344f,16.29010923f)); + {-0.610236858f,2.113885847f,16.33716825f}, + {-0.584865999f,2.114823859f,16.33515635f}, + {-0.610236858f,2.017265428f,16.29212113f}, + {-0.584865999f,2.01820344f,16.29010923f}); oapiVCRegisterArea (AID_ENGINEMAIN, PANEL_REDRAW_ALWAYS, PANEL_MOUSE_LBDOWN|PANEL_MOUSE_LBPRESSED); oapiVCSetAreaClickmode_Quadrilateral (AID_ENGINEMAIN, - _V(-0.662158615f,2.111966194f,16.34128561f), - _V(-0.637377776f,2.112882392f,16.3393205f), - _V(-0.662158615f,2.015345775f,16.29623849f), - _V(-0.637377776f,2.016261973f,16.29427338f)); + {-0.662158615f,2.111966194f,16.34128561f}, + {-0.637377776f,2.112882392f,16.3393205f}, + {-0.662158615f,2.015345775f,16.29623849f}, + {-0.637377776f,2.016261973f,16.29427338f}); SURFHANDLE tex1 = oapiGetTextureHandle (vcmesh_tpl,10); //engine thrust tex oapiVCRegisterArea (AID_ENGINEINDICATOR, _R( 4,4, 129,194), PANEL_REDRAW_ALWAYS, PANEL_MOUSE_IGNORE, PANEL_MAP_BACKGROUND, tex1); @@ -2058,76 +2058,76 @@ bool ShuttleA::clbkLoadVC (int id) tex1 = oapiGetTextureHandle (vcmesh_tpl,12); //navmode tex oapiVCRegisterArea (AID_NAVMODE, _R( 0,0, 262,32), PANEL_REDRAW_MOUSE|PANEL_REDRAW_USER, PANEL_MOUSE_LBDOWN, PANEL_MAP_BACKGROUND, tex1); oapiVCSetAreaClickmode_Quadrilateral (AID_NAVMODE, - _V(-0.843884764f,2.123497933f,16.36420527f), - _V(-0.689299533f,2.129213263f,16.35194677f), - _V(-0.843884764f,2.106857749f,16.35644716f), - _V(-0.689299533f,2.112573079f,16.34418865f)); + {-0.843884764f,2.123497933f,16.36420527f}, + {-0.689299533f,2.129213263f,16.35194677f}, + {-0.843884764f,2.106857749f,16.35644716f}, + {-0.689299533f,2.112573079f,16.34418865f}); oapiVCRegisterArea (AID_PODANGLEPRESET, PANEL_REDRAW_NEVER, PANEL_MOUSE_LBDOWN); oapiVCSetAreaClickmode_Quadrilateral (AID_PODANGLEPRESET, - _V(-0.553004921f,2.007572246f,16.28207691f), - _V(-0.528224082f,2.008488444f,16.28011181f), - _V(-0.553004921f,1.980733241f,16.26956382f), - _V(-0.528224082f,1.981649439f,16.26759872f)); + {-0.553004921f,2.007572246f,16.28207691f}, + {-0.528224082f,2.008488444f,16.28011181f}, + {-0.553004921f,1.980733241f,16.26956382f}, + {-0.528224082f,1.981649439f,16.26759872f}); oapiVCRegisterArea (AID_PODANGLESWITCH, PANEL_REDRAW_MOUSE, PANEL_MOUSE_LBDOWN|PANEL_MOUSE_LBPRESSED|PANEL_MOUSE_LBUP); oapiVCSetAreaClickmode_Quadrilateral (AID_PODANGLESWITCH, - _V(-0.602566598f,2.000372049f,16.2835045f), - _V(-0.5730656f,2.001462761f,16.28116509f), - _V(-0.602566598f,1.976753725f,16.27249298f), - _V(-0.5730656f,1.977844437f,16.27015357f)); + {-0.602566598f,2.000372049f,16.2835045f}, + {-0.5730656f,2.001462761f,16.28116509f}, + {-0.602566598f,1.976753725f,16.27249298f}, + {-0.5730656f,1.977844437f,16.27015357f}); oapiVCRegisterArea (AID_ATTITUDEMODE, PANEL_REDRAW_MOUSE, PANEL_MOUSE_LBDOWN); oapiVCSetAreaClickmode_Quadrilateral (AID_ATTITUDEMODE, - _V(-0.485742645f,2.112584069f,16.32454306f), - _V(-0.473942246f,2.113020354f,16.32360729f), - _V(-0.485742645f,2.088965745f,16.31353154f), - _V(-0.473942246f,2.089402029f,16.31259578f)); + {-0.485742645f,2.112584069f,16.32454306f}, + {-0.473942246f,2.113020354f,16.32360729f}, + {-0.485742645f,2.088965745f,16.31353154f}, + {-0.473942246f,2.089402029f,16.31259578f}); // MFD1 buttons tex1 = oapiGetTextureHandle (vcmesh_tpl,13); //mfd buttons tex oapiVCRegisterArea (AID_MFD1_LBUTTONS, _R( 8 ,9, 32,218), PANEL_REDRAW_MOUSE|PANEL_REDRAW_USER,PANEL_MOUSE_LBDOWN|PANEL_MOUSE_LBUP|PANEL_MOUSE_LBPRESSED|PANEL_MOUSE_ONREPLAY, PANEL_MAP_BACKGROUND, tex1); oapiVCSetAreaClickmode_Quadrilateral(AID_MFD1_LBUTTONS, - _V(-0.873975f, 2.07783f, 16.3458f), - _V(-0.898166f, 2.07693f, 16.3477f), - _V(-0.873975f, 1.95705f, 16.2895f), - _V(-0.898166f, 1.95616f, 16.2914f)); + {-0.873975f, 2.07783f, 16.3458f}, + {-0.898166f, 2.07693f, 16.3477f}, + {-0.873975f, 1.95705f, 16.2895f}, + {-0.898166f, 1.95616f, 16.2914f}); oapiVCRegisterArea (AID_MFD1_RBUTTONS, _R( 49,9, 73,218), PANEL_REDRAW_MOUSE|PANEL_REDRAW_USER,PANEL_MOUSE_LBDOWN|PANEL_MOUSE_LBUP|PANEL_MOUSE_LBPRESSED|PANEL_MOUSE_ONREPLAY, PANEL_MAP_BACKGROUND, tex1); oapiVCSetAreaClickmode_Quadrilateral(AID_MFD1_RBUTTONS, - _V(-0.691069f, 2.08459f, 16.3313f), - _V(-0.715260f, 2.08459f, 16.3313f), - _V(-0.691069f, 1.96381f, 16.2750f), - _V(-0.715260f, 1.96381f, 16.2750f)); + {-0.691069f, 2.08459f, 16.3313f}, + {-0.715260f, 2.08459f, 16.3313f}, + {-0.691069f, 1.96381f, 16.2750f}, + {-0.715260f, 1.96381f, 16.2750f}); oapiVCRegisterArea (AID_MFD1_BBUTTONS,PANEL_REDRAW_NEVER,PANEL_MOUSE_LBDOWN|PANEL_MOUSE_ONREPLAY); oapiVCSetAreaClickmode_Quadrilateral(AID_MFD1_BBUTTONS, - _V(-0.833854424f,1.94565778f,16.28032296f), - _V(-0.755381769f,1.948559073f,16.27410013f), - _V(-0.833854424f,1.935458958f,16.27556799f), - _V(-0.755381769f,1.938360251f,16.26934516f)); + {-0.833854424f,1.94565778f,16.28032296f}, + {-0.755381769f,1.948559073f,16.27410013f}, + {-0.833854424f,1.935458958f,16.27556799f}, + {-0.755381769f,1.938360251f,16.26934516f}); //MFD2 buttons oapiVCRegisterArea (AID_MFD2_LBUTTONS, _R(90 ,9,114,218), PANEL_REDRAW_MOUSE|PANEL_REDRAW_USER,PANEL_MOUSE_LBDOWN|PANEL_MOUSE_LBUP|PANEL_MOUSE_LBPRESSED|PANEL_MOUSE_ONREPLAY, PANEL_MAP_BACKGROUND, tex1); oapiVCSetAreaClickmode_Quadrilateral(AID_MFD2_LBUTTONS, - _V(-0.424380f, 2.09445f, 16.3101f), - _V(-0.448571f, 2.09356f, 16.3120f), - _V(-0.424380f, 1.97367f, 16.2538f), - _V(-0.448571f, 1.97278f, 16.2557f)); + {-0.424380f, 2.09445f, 16.3101f}, + {-0.448571f, 2.09356f, 16.3120f}, + {-0.424380f, 1.97367f, 16.2538f}, + {-0.448571f, 1.97278f, 16.2557f}); oapiVCRegisterArea (AID_MFD2_RBUTTONS, _R( 131,9, 155,218), PANEL_REDRAW_MOUSE|PANEL_REDRAW_USER,PANEL_MOUSE_LBDOWN|PANEL_MOUSE_LBUP|PANEL_MOUSE_LBPRESSED|PANEL_MOUSE_ONREPLAY, PANEL_MAP_BACKGROUND, tex1); oapiVCSetAreaClickmode_Quadrilateral(AID_MFD2_RBUTTONS, - _V(-0.241474f, 2.10121f, 16.2956f), - _V(-0.265665f, 2.10032f, 16.2975f), - _V(-0.241474f, 1.98044f, 16.2393f), - _V(-0.265665f, 1.97954f, 16.2412f)); + {-0.241474f, 2.10121f, 16.2956f}, + {-0.265665f, 2.10032f, 16.2975f}, + {-0.241474f, 1.98044f, 16.2393f}, + {-0.265665f, 1.97954f, 16.2412f}); oapiVCRegisterArea (AID_MFD2_BBUTTONS,PANEL_REDRAW_NEVER,PANEL_MOUSE_LBDOWN|PANEL_MOUSE_ONREPLAY); oapiVCSetAreaClickmode_Quadrilateral(AID_MFD2_BBUTTONS, - _V(-0.384259211f,2.015958238f,16.26969654f), - _V(-0.305786556f,2.018859532f,16.26347371f), - _V(-0.384259211f,1.952081406f,16.23991538f), - _V(-0.305786556f,1.954982699f,16.23369255f)); + {-0.384259211f,2.015958238f,16.26969654f}, + {-0.305786556f,2.018859532f,16.26347371f}, + {-0.384259211f,1.952081406f,16.23991538f}, + {-0.305786556f,1.954982699f,16.23369255f}); //OVERHEAD Panel @@ -2145,38 +2145,38 @@ bool ShuttleA::clbkLoadVC (int id) oapiVCRegisterArea(AID_DOCKSWITCH,PANEL_REDRAW_USER, PANEL_MOUSE_LBDOWN); oapiVCSetAreaClickmode_Quadrilateral(AID_DOCKSWITCH, - _V(-0.227115067f,2.608473414f,16.10024382f), - _V(-0.227115067f,2.609185081f,16.08870423f), - _V(-0.209934233f,2.591621747f,16.09921048f), - _V(-0.209934233f,2.592333414f,16.0876709f)); + {-0.227115067f,2.608473414f,16.10024382f}, + {-0.227115067f,2.609185081f,16.08870423f}, + {-0.209934233f,2.591621747f,16.09921048f}, + {-0.209934233f,2.592333414f,16.0876709f}); oapiVCRegisterArea(AID_AIRLOCK1SWITCH,PANEL_REDRAW_USER, PANEL_MOUSE_LBDOWN); oapiVCSetAreaClickmode_Quadrilateral(AID_AIRLOCK1SWITCH, - _V(-0.258040567f,2.638747108f,16.10306545f), - _V(-0.258040567f,2.639458775f,16.09152586f), - _V(-0.240859733f,2.621895442f,16.10203211f), - _V(-0.240859733f,2.622607108f,16.09049253f)); + {-0.258040567f,2.638747108f,16.10306545f}, + {-0.258040567f,2.639458775f,16.09152586f}, + {-0.240859733f,2.621895442f,16.10203211f}, + {-0.240859733f,2.622607108f,16.09049253f}); oapiVCRegisterArea(AID_GEARSWITCH,PANEL_REDRAW_USER, PANEL_MOUSE_LBDOWN); oapiVCSetAreaClickmode_Quadrilateral(AID_GEARSWITCH, - _V(-0.227115067f,2.609985706f,16.0757222f), - _V(-0.227115067f,2.610697372f,16.06418262f), - _V(-0.209934233f,2.593134039f,16.07468887f), - _V(-0.209934233f,2.593845706f,16.06314928f)); + {-0.227115067f,2.609985706f,16.0757222f}, + {-0.227115067f,2.610697372f,16.06418262f}, + {-0.209934233f,2.593134039f,16.07468887f}, + {-0.209934233f,2.593845706f,16.06314928f}); tex1 = oapiGetTextureHandle (vcmesh_tpl,16); //cargo tex oapiVCRegisterArea(AID_CARGO_OPEN, _R( 0, 25, 84, 156), PANEL_REDRAW_MOUSE, PANEL_MOUSE_LBDOWN,PANEL_MAP_BACKGROUND,tex1); oapiVCSetAreaClickmode_Quadrilateral(AID_CARGO_OPEN, - _V(-0.250824617f,2.635761492f,16.03627884f), - _V(-0.250824617f,2.638222672f,15.99637112f), - _V(-0.20615445f,2.591947158f,16.03359218f), - _V(-0.20615445f,2.594408339f,15.99368445f)); + {-0.250824617f,2.635761492f,16.03627884f}, + {-0.250824617f,2.638222672f,15.99637112f}, + {-0.20615445f,2.591947158f,16.03359218f}, + {-0.20615445f,2.594408339f,15.99368445f}); oapiVCRegisterArea(AID_GARGOARMSWITCH,PANEL_REDRAW_USER, PANEL_MOUSE_LBDOWN); oapiVCSetAreaClickmode_Quadrilateral(AID_GARGOARMSWITCH, - _V(-0.227115067f,2.615708692f,15.98292472f), - _V(-0.227115067f,2.616420358f,15.97138514f), - _V(-0.209934233f,2.598857025f,15.98189139f), - _V(-0.209934233f,2.599568692f,15.9703518f)); + {-0.227115067f,2.615708692f,15.98292472f}, + {-0.227115067f,2.616420358f,15.97138514f}, + {-0.209934233f,2.598857025f,15.98189139f}, + {-0.209934233f,2.599568692f,15.9703518f}); diff --git a/Src/Vessel/ShuttleA/ShuttleA_PL/ShuttleA_pl.cpp b/Src/Vessel/ShuttleA/ShuttleA_PL/ShuttleA_pl.cpp index 8a96a4454..709861dc8 100644 --- a/Src/Vessel/ShuttleA/ShuttleA_PL/ShuttleA_pl.cpp +++ b/Src/Vessel/ShuttleA/ShuttleA_PL/ShuttleA_pl.cpp @@ -88,7 +88,7 @@ void ShuttleA_PL::SetNormalConfig() SetMeshVisibilityMode (AddMesh (mesh_main), MESHVIS_EXTERNAL); ClearAirfoilDefinitions(); - CreateAirfoil (LIFT_VERTICAL, _V(0,-4,4), None_MomentCoeff, 4, 2500, 0.5); + CreateAirfoil (LIFT_VERTICAL, {0,-4,4}, None_MomentCoeff, 4, 2500, 0.5); } void ShuttleA_PL::SetDrogueConfig() @@ -98,7 +98,7 @@ void ShuttleA_PL::SetDrogueConfig() SetMeshVisibilityMode (AddMesh (mesh_drogue), MESHVIS_EXTERNAL); ClearAirfoilDefinitions(); - CreateAirfoil (LIFT_VERTICAL, _V(0.0f,-2.0f,0.0f), Drogue_MomentCoeff, 4, 2500, 0.5); + CreateAirfoil (LIFT_VERTICAL, {0.0f,-2.0f,0.0f}, Drogue_MomentCoeff, 4, 2500, 0.5); } @@ -110,7 +110,7 @@ void ShuttleA_PL::SetParachuteConfig() SetMeshVisibilityMode (AddMesh (mesh_parachute), MESHVIS_EXTERNAL); ClearAirfoilDefinitions(); - CreateAirfoil (LIFT_VERTICAL, _V(0.0f,-2.0f,2.0f), Parachute_MomentCoeff, 4, 2500, 0.5); + CreateAirfoil (LIFT_VERTICAL, {0.0f,-2.0f,2.0f}, Parachute_MomentCoeff, 4, 2500, 0.5); } void ShuttleA_PL::SetPostLandingConfig() @@ -191,18 +191,18 @@ void ShuttleA_PL::clbkSetClassCaps (FILEHANDLE cfg) //Common stuff on all configurations SetSize (5.0); - SetPMI (_V(2.56,2.39,2.02)); + SetPMI ({2.56,2.39,2.02}); SetEmptyMass (20000.0f); - SetCrossSections (_V(17.61f, 17.44f, 13.09f)); - SetRotDrag (_V(0.7, 0.7, 0.3)); + SetCrossSections ({17.61f, 17.44f, 13.09f}); + SetRotDrag ({0.7, 0.7, 0.3}); SetSurfaceFrictionCoeff (0.5, 0.5); - SetCameraOffset (_V(0.0f,0.0f,0.0f)); - SetDockParams (_V(2.00f,0.00f,0.00f), _V(1,0,0), _V(0,1,0)); + SetCameraOffset ({0.0f,0.0f,0.0f}); + SetDockParams ({2.00f,0.00f,0.00f}, {1,0,0}, {0,1,0}); char attach_id[8]={"SH"}; - payload_attachment[0]=CreateAttachment (true,_V(-0.319f, 0.0f, 2.5f),_V(0.0f,0.0f,1.0f),_V(0.0f,1.0f,0.0f),attach_id); - payload_attachment[1]=CreateAttachment (true,_V(-0.319f, 0.0f, -2.5f),_V(0.0f,0.0f,-1.0f),_V(0.0f,1.0f,0.0f),attach_id); - payload_attachment[2]=CreateAttachment (true,_V(-0.319f, 2.0f, 0.0f ),_V(0.0f,1.0f, 0.0f),_V(1.0f,0.0f,0.0f),"GS"); // MS 060906: added by request + payload_attachment[0]=CreateAttachment (true,{-0.319f, 0.0f, 2.5f},{0.0f,0.0f,1.0f},{0.0f,1.0f,0.0f},attach_id); + payload_attachment[1]=CreateAttachment (true,{-0.319f, 0.0f, -2.5f},{0.0f,0.0f,-1.0f},{0.0f,1.0f,0.0f},attach_id); + payload_attachment[2]=CreateAttachment (true,{-0.319f, 2.0f, 0.0f },{0.0f,1.0f, 0.0f},{1.0f,0.0f,0.0f},"GS"); // MS 060906: added by request TOUCHDOWNVTX tdvtx[8] = { {{-2,-2, 2.5}, 2e5, 3e4, 5}, diff --git a/Src/Vessel/ShuttleA/adiball.cpp b/Src/Vessel/ShuttleA/adiball.cpp index ca69398b3..e4e197922 100644 --- a/Src/Vessel/ShuttleA/adiball.cpp +++ b/Src/Vessel/ShuttleA/adiball.cpp @@ -70,8 +70,8 @@ ADIBall::ADIBall (VESSEL3 *v, AttitudeReference *attref): PanelElement (v) rho_curr = tht_curr = phi_curr = 0.0; tgtx_curr = tgty_curr = 0.0; ballvtx0 = 0; - peuler = _V(0,0,0); - vrot = _V(0,0,0); + peuler = {0,0,0}; + vrot = {0,0,0}; euler_t = 0; rate_local = true; } @@ -316,9 +316,9 @@ bool ADIBall::Redraw2D (SURFHANDLE surf) double sint = sin(euler_tgt.y), cost = cos(euler_tgt.y); double sinp = sin(euler_tgt.z), cosp = cos(euler_tgt.z); if (layout == 0) { - tgt = _V(rad*sinp*cost, rad*sint, rad*cosp*cost); + tgt = {rad*sinp*cost, rad*sint, rad*cosp*cost}; } else { - tgt = _V(-rad*sint*cosp, rad*sinp, rad*cost*cosp); + tgt = {-rad*sint*cosp, rad*sinp, rad*cost*cosp}; } tgtx = min(max( (a1*tgt.x + b1*tgt.y + c1*tgt.z), -erange), erange); tgty = min(max(-(a2*tgt.x + b2*tgt.y + c2*tgt.z), -erange), erange); diff --git a/Src/Vessel/ShuttleA/adictrl.cpp b/Src/Vessel/ShuttleA/adictrl.cpp index 481c29c47..c2d792dab 100644 --- a/Src/Vessel/ShuttleA/adictrl.cpp +++ b/Src/Vessel/ShuttleA/adictrl.cpp @@ -280,7 +280,7 @@ void ADICtrl::UpdateDisplay (SURFHANDLE surf, bool force) if (!sh->GetAttref()->GetTgtEulerAngles (ofs)) { tgtmode = 0; - ofs = _V(0,0,0); + ofs = {0,0,0}; } DispAngle (surf, ofs.y, 58, 39, dispprm.tgtdev[0]); DispAngle (surf, ofs.z, 86, 39, dispprm.tgtdev[1]); @@ -393,8 +393,8 @@ bool ADICtrl::ProcessSwitches (int event, int mx, int my) if (mx < 23) { if (mx < 17 && (event & PANEL_MOUSE_LBDOWN)) { - if (settgt) sh->GetAttref()->SetTgtOffset (_V(0,0,0)); - else sh->GetAttref()->SetEulerOffset (_V(0,0,0)); + if (settgt) sh->GetAttref()->SetTgtOffset ({0,0,0}); + else sh->GetAttref()->SetEulerOffset ({0,0,0}); return true; } return false; diff --git a/Src/Vessel/ShuttleA/attref.cpp b/Src/Vessel/ShuttleA/attref.cpp index 5605f3c7a..856e85b4d 100644 --- a/Src/Vessel/ShuttleA/attref.cpp +++ b/Src/Vessel/ShuttleA/attref.cpp @@ -21,10 +21,10 @@ AttitudeReference::AttitudeReference (const VESSEL *vessel) valid_axes = false; valid_euler = false; valid_tgteuler = false; - euler_offs = _V(0,0,0); - tgt_offs = _V(0,0,0); - tgt_rvel = _V(0,0,0); - tgt_ppos = _V(0,0,0); + euler_offs = {0,0,0}; + tgt_offs = {0,0,0}; + tgt_rvel = {0,0,0}; + tgt_ppos = {0,0,0}; tgt_ptime = 0; } @@ -94,15 +94,15 @@ const MATRIX3 &AttitudeReference::GetFrameRotMatrix () const VECTOR3 axis1, axis2, axis3; switch (mode) { case 0: // inertial (ecliptic) - axis3 = _V(1,0,0); - axis2 = _V(0,1,0); + axis3 = {1,0,0}; + axis2 = {0,1,0}; break; case 1: { // inertial (equator) MATRIX3 R; oapiGetPlanetObliquityMatrix (v->GetGravityRef(), &R); - //axis3 = _V(R.m13, R.m23, R.m33); - axis3 = _V(R.m11, R.m21, R.m31); - axis2 = _V(R.m12, R.m22, R.m32); + //axis3 = {R.m13, R.m23, R.m33}; + axis3 = {R.m11, R.m21, R.m31}; + axis2 = {R.m12, R.m22, R.m32}; } break; case 2: { // orbital velocity / orbital momentum vector OBJHANDLE hRef = v->GetGravityRef(); @@ -110,8 +110,8 @@ const MATRIX3 &AttitudeReference::GetFrameRotMatrix () const axis3 = unit (axis3); VECTOR3 vv, vm; v->GetRelativePos (hRef, vv); // local vertical - vm = crossp (axis3,vv); // direction of orbital momentum - axis2 = unit (crossp (vm,axis3)); + vm = cross(axis3, vv); // direction of orbital momentum + axis2 = unit(cross(vm, axis3)); } break; case 3: { // local horizon / local north (surface) OBJHANDLE hRef = v->GetSurfaceRef(); @@ -120,14 +120,14 @@ const MATRIX3 &AttitudeReference::GetFrameRotMatrix () const MATRIX3 prot; oapiGetRotationMatrix (hRef, &prot); VECTOR3 paxis = {prot.m12, prot.m22, prot.m32}; // planet rotation axis in global frame - VECTOR3 yaxis = unit (crossp (paxis,axis2)); // direction of yaw=+90 pole in global frame - axis3 = crossp (axis2,yaxis); + VECTOR3 yaxis = unit(cross(paxis, axis2)); // direction of yaw=+90 pole in global frame + axis3 = cross(axis2, yaxis); } break; case 4: { // synced to NAV source (type-specific) NAVDATA ndata; NAVHANDLE hNav = v->GetNavSource (navid); - axis3 = _V(0,0,1); - axis2 = _V(0,1,0); + axis3 = {0,0,1}; + axis2 = {0,1,0}; if (hNav) { oapiGetNavData (hNav, &ndata); switch (ndata.type) { @@ -149,13 +149,13 @@ const MATRIX3 &AttitudeReference::GetFrameRotMatrix () const axis2 = unit (axis2); oapiGetNavPos (hNav, &npos); npos -= spos; - axis3 = unit(crossp(crossp(axis2,npos),axis2)); + axis3 = unit(cross(cross(axis2, npos), axis2)); } break; } } } break; } - axis1 = crossp(axis2,axis3); + axis1 = cross(axis2, axis3); R = _M(axis1.x, axis2.x, axis3.x, axis1.y, axis2.y, axis3.y, axis1.z, axis2.z, axis3.z); valid_axes = true; @@ -284,7 +284,7 @@ void AttitudeReference::PostStep (double simt, double simdt, double mjd) MATRIX3 Rp; oapiGetRotationMatrix (hObj, &Rp); oapiGetGlobalVel (hObj, &tvel); - tvel += mul (Rp, _V(-sin(data.vor.lng),0,cos(data.vor.lng)) * PI2/oapiGetPlanetPeriod(hObj)*oapiGetSize(hObj)*cos(data.vor.lat)); + tvel += mul(Rp, VECTOR3{-std::sin(data.vor.lng), 0, std::cos(data.vor.lng)} * PI2 / oapiGetPlanetPeriod(hObj) * oapiGetSize(hObj) * std::cos(data.vor.lat)); tgt_rvel = svel-tvel; sprintf (oapiDebugString(), "rvel: x=%f, y=%f, z=%f", tgt_rvel.x, tgt_rvel.y, tgt_rvel.z); } return; // done diff --git a/Src/Vessel/ShuttlePB/ShuttlePB.cpp b/Src/Vessel/ShuttlePB/ShuttlePB.cpp index f2133412f..f34f6b5e4 100644 --- a/Src/Vessel/ShuttlePB/ShuttlePB.cpp +++ b/Src/Vessel/ShuttlePB/ShuttlePB.cpp @@ -49,18 +49,18 @@ const VECTOR3 PB_DOCK_ROT = {0,0,-1}; // docking port alignment directi // Define impact convex hull static const DWORD ntdvtx = 12; static TOUCHDOWNVTX tdvtx[ntdvtx] = { - {_V( 0, -1.5, 2 ), 2e4, 1e3, 1.6, 1}, - {_V(-1, -1.5,-1.5), 2e4, 1e3, 3.0, 1}, - {_V( 1, -1.5,-1.5), 2e4, 1e3, 3.0, 1}, - {_V(-0.5,-0.75,3 ), 2e4, 1e3, 3.0}, - {_V( 0.5,-0.75,3 ), 2e4, 1e3, 3.0}, - {_V(-2.6,-1.1,-1.9), 2e4, 1e3, 3.0}, - {_V( 2.6,-1.1,-1.9), 2e4, 1e3, 3.0}, - {_V(-1, 1.3, 0 ), 2e4, 1e3, 3.0}, - {_V( 1, 1.3, 0 ), 2e4, 1e3, 3.0}, - {_V(-1, 1.3,-2 ), 2e4, 1e3, 3.0}, - {_V( 1, 1.3,-2 ), 2e4, 1e3, 3.0}, - {_V( 0, 0.3,-3.8), 2e4, 1e3, 3.0} + {{ 0, -1.5, 2 }, 2e4, 1e3, 1.6, 1}, + {{-1, -1.5,-1.5}, 2e4, 1e3, 3.0, 1}, + {{ 1, -1.5,-1.5}, 2e4, 1e3, 3.0, 1}, + {{-0.5,-0.75,3 }, 2e4, 1e3, 3.0}, + {{ 0.5,-0.75,3 }, 2e4, 1e3, 3.0}, + {{-2.6,-1.1,-1.9}, 2e4, 1e3, 3.0}, + {{ 2.6,-1.1,-1.9}, 2e4, 1e3, 3.0}, + {{-1, 1.3, 0 }, 2e4, 1e3, 3.0}, + {{ 1, 1.3, 0 }, 2e4, 1e3, 3.0}, + {{-1, 1.3,-2 }, 2e4, 1e3, 3.0}, + {{ 1, 1.3,-2 }, 2e4, 1e3, 3.0}, + {{ 0, 0.3,-3.8}, 2e4, 1e3, 3.0} }; // Calculate lift coefficient [Cl] as a function of aoa (angle of attack) over -Pi ... Pi @@ -160,17 +160,17 @@ void ShuttlePB::clbkSetClassCaps (FILEHANDLE cfg) AddAnimationComponent (anim_elevator, 0, 1, &trans_Relevator); // aerodynamic control surface defintions - CreateControlSurface (AIRCTRL_ELEVATOR, 1.5, 0.7, _V( 0,0,-2.5), AIRCTRL_AXIS_XPOS, anim_elevator); - CreateControlSurface (AIRCTRL_AILERON, 1.5, 0.25, _V( 1,0,-2.5), AIRCTRL_AXIS_XPOS, anim_Laileron); - CreateControlSurface (AIRCTRL_AILERON, 1.5, 0.25, _V(-1,0,-2.5), AIRCTRL_AXIS_XNEG, anim_Raileron); + CreateControlSurface (AIRCTRL_ELEVATOR, 1.5, 0.7, { 0,0,-2.5}, AIRCTRL_AXIS_XPOS, anim_elevator); + CreateControlSurface (AIRCTRL_AILERON, 1.5, 0.25, { 1,0,-2.5}, AIRCTRL_AXIS_XPOS, anim_Laileron); + CreateControlSurface (AIRCTRL_AILERON, 1.5, 0.25, {-1,0,-2.5}, AIRCTRL_AXIS_XNEG, anim_Raileron); // propellant resources PROPELLANT_HANDLE hpr = CreatePropellantResource (PB_FUELMASS); // main engine - th_main = CreateThruster (_V(0,0,-4.35), _V(0,0,1), PB_MAXMAINTH, hpr, PB_ISP); + th_main = CreateThruster ({0,0,-4.35}, {0,0,1}, PB_MAXMAINTH, hpr, PB_ISP); CreateThrusterGroup (&th_main, 1, THGROUP_MAIN); - AddExhaust (th_main, 8, 1, _V(0,0.3,-4.35), _V(0,0,-1)); + AddExhaust (th_main, 8, 1, {0,0.3,-4.35}, {0,0,-1}); PARTICLESTREAMSPEC contrail_main = { 0, 5.0, 16, 200, 0.15, 1.0, 5, 3.0, PARTICLESTREAMSPEC::DIFFUSE, @@ -182,14 +182,14 @@ void ShuttlePB::clbkSetClassCaps (FILEHANDLE cfg) PARTICLESTREAMSPEC::LVL_SQRT, 0, 1, PARTICLESTREAMSPEC::ATM_PLOG, 1e-5, 0.1 }; - AddExhaustStream (th_main, _V(0,0.3,-10), &contrail_main); - AddExhaustStream (th_main, _V(0,0.3,-5), &exhaust_main); + AddExhaustStream (th_main, {0,0.3,-10}, &contrail_main); + AddExhaustStream (th_main, {0,0.3,-5}, &exhaust_main); // hover engine - th_hover = CreateThruster (_V(0,-1.5,0), _V(0,1,0), PB_MAXHOVERTH, hpr, PB_ISP); + th_hover = CreateThruster ({0,-1.5,0}, {0,1,0}, PB_MAXHOVERTH, hpr, PB_ISP); CreateThrusterGroup (&th_hover, 1, THGROUP_HOVER); - AddExhaust (th_hover, 8, 1, _V(0,-1.5,1), _V(0,-1,0)); - AddExhaust (th_hover, 8, 1, _V(0,-1.5,-1), _V(0,-1,0)); + AddExhaust (th_hover, 8, 1, {0,-1.5,1}, {0,-1,0}); + AddExhaust (th_hover, 8, 1, {0,-1.5,-1}, {0,-1,0}); PARTICLESTREAMSPEC contrail_hover = { 0, 5.0, 8, 200, 0.15, 1.0, 5, 3.0, PARTICLESTREAMSPEC::DIFFUSE, @@ -202,26 +202,26 @@ void ShuttlePB::clbkSetClassCaps (FILEHANDLE cfg) PARTICLESTREAMSPEC::ATM_PLOG, 1e-5, 0.1 }; - AddExhaustStream (th_hover, _V(0,-3, 1), &contrail_hover); - AddExhaustStream (th_hover, _V(0,-3,-1), &contrail_hover); - AddExhaustStream (th_hover, _V(0,-2, 1), &exhaust_hover); - AddExhaustStream (th_hover, _V(0,-2,-1), &exhaust_hover); + AddExhaustStream (th_hover, {0,-3, 1}, &contrail_hover); + AddExhaustStream (th_hover, {0,-3,-1}, &contrail_hover); + AddExhaustStream (th_hover, {0,-2, 1}, &exhaust_hover); + AddExhaustStream (th_hover, {0,-2,-1}, &exhaust_hover); // RCS engines - th_rcs[ 0] = CreateThruster (_V( 1,0, 3), _V(0, 1,0), PB_MAXRCSTH, hpr, PB_ISP); - th_rcs[ 1] = CreateThruster (_V( 1,0, 3), _V(0,-1,0), PB_MAXRCSTH, hpr, PB_ISP); - th_rcs[ 2] = CreateThruster (_V(-1,0, 3), _V(0, 1,0), PB_MAXRCSTH, hpr, PB_ISP); - th_rcs[ 3] = CreateThruster (_V(-1,0, 3), _V(0,-1,0), PB_MAXRCSTH, hpr, PB_ISP); - th_rcs[ 4] = CreateThruster (_V( 1,0,-3), _V(0, 1,0), PB_MAXRCSTH, hpr, PB_ISP); - th_rcs[ 5] = CreateThruster (_V( 1,0,-3), _V(0,-1,0), PB_MAXRCSTH, hpr, PB_ISP); - th_rcs[ 6] = CreateThruster (_V(-1,0,-3), _V(0, 1,0), PB_MAXRCSTH, hpr, PB_ISP); - th_rcs[ 7] = CreateThruster (_V(-1,0,-3), _V(0,-1,0), PB_MAXRCSTH, hpr, PB_ISP); - th_rcs[ 8] = CreateThruster (_V( 1,0, 3), _V(-1,0,0), PB_MAXRCSTH, hpr, PB_ISP); - th_rcs[ 9] = CreateThruster (_V(-1,0, 3), _V( 1,0,0), PB_MAXRCSTH, hpr, PB_ISP); - th_rcs[10] = CreateThruster (_V( 1,0,-3), _V(-1,0,0), PB_MAXRCSTH, hpr, PB_ISP); - th_rcs[11] = CreateThruster (_V(-1,0,-3), _V( 1,0,0), PB_MAXRCSTH, hpr, PB_ISP); - th_rcs[12] = CreateThruster (_V( 0,0,-3), _V(0,0, 1), PB_MAXRCSTH, hpr, PB_ISP); - th_rcs[13] = CreateThruster (_V( 0,0, 3), _V(0,0,-1), PB_MAXRCSTH, hpr, PB_ISP); + th_rcs[ 0] = CreateThruster ({ 1,0, 3}, {0, 1,0}, PB_MAXRCSTH, hpr, PB_ISP); + th_rcs[ 1] = CreateThruster ({ 1,0, 3}, {0,-1,0}, PB_MAXRCSTH, hpr, PB_ISP); + th_rcs[ 2] = CreateThruster ({-1,0, 3}, {0, 1,0}, PB_MAXRCSTH, hpr, PB_ISP); + th_rcs[ 3] = CreateThruster ({-1,0, 3}, {0,-1,0}, PB_MAXRCSTH, hpr, PB_ISP); + th_rcs[ 4] = CreateThruster ({ 1,0,-3}, {0, 1,0}, PB_MAXRCSTH, hpr, PB_ISP); + th_rcs[ 5] = CreateThruster ({ 1,0,-3}, {0,-1,0}, PB_MAXRCSTH, hpr, PB_ISP); + th_rcs[ 6] = CreateThruster ({-1,0,-3}, {0, 1,0}, PB_MAXRCSTH, hpr, PB_ISP); + th_rcs[ 7] = CreateThruster ({-1,0,-3}, {0,-1,0}, PB_MAXRCSTH, hpr, PB_ISP); + th_rcs[ 8] = CreateThruster ({ 1,0, 3}, {-1,0,0}, PB_MAXRCSTH, hpr, PB_ISP); + th_rcs[ 9] = CreateThruster ({-1,0, 3}, { 1,0,0}, PB_MAXRCSTH, hpr, PB_ISP); + th_rcs[10] = CreateThruster ({ 1,0,-3}, {-1,0,0}, PB_MAXRCSTH, hpr, PB_ISP); + th_rcs[11] = CreateThruster ({-1,0,-3}, { 1,0,0}, PB_MAXRCSTH, hpr, PB_ISP); + th_rcs[12] = CreateThruster ({ 0,0,-3}, {0,0, 1}, PB_MAXRCSTH, hpr, PB_ISP); + th_rcs[13] = CreateThruster ({ 0,0, 3}, {0,0,-1}, PB_MAXRCSTH, hpr, PB_ISP); th_group[0] = th_rcs[0]; th_group[1] = th_rcs[2]; @@ -279,7 +279,7 @@ void ShuttlePB::clbkSetClassCaps (FILEHANDLE cfg) CreateThrusterGroup (th_rcs+13, 1, THGROUP_ATT_BACK); // camera parameters - SetCameraOffset (_V(0,0.8,0)); + SetCameraOffset ({0,0.8,0}); // associate a mesh for the visual AddMesh ("ShuttlePB"); diff --git a/Src/Vessel/Solarsail/Solarsail.cpp b/Src/Vessel/Solarsail/Solarsail.cpp index 016161bf4..9746b182c 100644 --- a/Src/Vessel/Solarsail/Solarsail.cpp +++ b/Src/Vessel/Solarsail/Solarsail.cpp @@ -50,12 +50,12 @@ inline VECTOR3 Nml (const NTVERTEX *v1, const NTVERTEX *v2, const NTVERTEX *v3) float dy1 = v2->y - v1->y, dy2 = v3->y - v1->y; float dz1 = v2->z - v1->z, dz2 = v3->z - v1->z; - return _V(dy1*dz2 - dy2*dz1, dz1*dx2 - dz2*dx1, dx1*dy2 - dx2*dy1); + return {dy1*dz2 - dy2*dz1, dz1*dx2 - dz2*dx1, dx1*dy2 - dx2*dy1}; } inline VECTOR3 crossp (const NTVERTEX *v1, const NTVERTEX *v2) { - return _V(v1->y*v2->z - v2->y*v1->z, v1->z*v2->x - v2->z*v1->x, v1->x*v2->y - v2->x*v1->y); + return {v1->y*v2->z - v2->y*v1->z, v1->z*v2->x - v2->z*v1->x, v1->x*v2->y - v2->x*v1->y}; } // -------------------------------------------------------------- @@ -124,7 +124,7 @@ SolarSail::SolarSail (OBJHANDLE hVessel, int flightmodel) int i; hMesh = NULL; - mf = _V(0,0,0); + mf = {0,0,0}; DefineAnimations(); for (i = 0; i < 4; i++) paddle_rot[i] = paddle_vis[i] = 0.5; @@ -140,10 +140,10 @@ void SolarSail::DefineAnimations () // Steering paddle animations static UINT PaddleGrp[4] = {GRP_paddle1, GRP_paddle2, GRP_paddle3, GRP_paddle4}; - static MGROUP_ROTATE Paddle0 (0, PaddleGrp+0, 1, _V(0,0,0), _V(0,1,0), (float)(180.0*RAD)); - static MGROUP_ROTATE Paddle1 (0, PaddleGrp+1, 1, _V(0,0,0), _V(1,0,0), (float)(180.0*RAD)); - static MGROUP_ROTATE Paddle2 (0, PaddleGrp+2, 1, _V(0,0,0), _V(0,1,0), (float)(180.0*RAD)); - static MGROUP_ROTATE Paddle3 (0, PaddleGrp+3, 1, _V(0,0,0), _V(1,0,0), (float)(180.0*RAD)); + static MGROUP_ROTATE Paddle0 (0, PaddleGrp+0, 1, {0,0,0}, {0,1,0}, (float)(180.0*RAD)); + static MGROUP_ROTATE Paddle1 (0, PaddleGrp+1, 1, {0,0,0}, {1,0,0}, (float)(180.0*RAD)); + static MGROUP_ROTATE Paddle2 (0, PaddleGrp+2, 1, {0,0,0}, {0,1,0}, (float)(180.0*RAD)); + static MGROUP_ROTATE Paddle3 (0, PaddleGrp+3, 1, {0,0,0}, {1,0,0}, (float)(180.0*RAD)); static MGROUP_ROTATE *Paddle[4] = {&Paddle0, &Paddle1, &Paddle2, &Paddle3}; for (i = 0; i < 4; i++) { @@ -175,11 +175,11 @@ void SolarSail::UpdateSail (const VECTOR3 *rpressure) MESHGROUP *sail = oapiMeshGroup (hMesh, sailidx); for (i = 0; i < sail_nvtx; i++) { - F = _V(0,0,rpressure->z*pscale); // note - should be calculated for LOCAL normal + F = {0,0,rpressure->z*pscale}; // note - should be calculated for LOCAL normal vi = sail->Vtx+i; nb = nbhr+i; if (nb->fix) { - sail_vbuf[i] = _V(0,0,0); + sail_vbuf[i] = {0,0,0}; continue; } for (j = 0; j < nb->nnd; j++) { @@ -187,7 +187,7 @@ void SolarSail::UpdateSail (const VECTOR3 *rpressure) dv.x = vj->x - vi->x; dv.y = vj->y - vi->y; dv.z = vj->z - vi->z; - dst = length(dv); + dst = len(dv); if (dst > nb->dst0[j]) { // is stretched F += dv*(elast/nb->dst0[j]); } @@ -255,18 +255,18 @@ void SolarSail::clbkSetClassCaps (FILEHANDLE cfg) SetCW (0.3, 0.3, 0.6, 0.9); SetWingAspect (0.7); SetWingEffectiveness (2.5); - SetCrossSections (_V(10.5,15.0,5.8)); - SetRotDrag (_V(0.6,0.6,0.35)); + SetCrossSections ({10.5,15.0,5.8}); + SetRotDrag ({0.6,0.6,0.35}); if (GetFlightModel() >= 1) { SetPitchMomentScale (1e-4); SetYawMomentScale (1e-4); } - SetPMI (_V(3e3,3e3,6e3)); + SetPMI ({3e3,3e3,6e3}); SetTrimScale (0.05); - SetCameraOffset (_V(0,0.8,0)); + SetCameraOffset ({0,0.8,0}); SetLiftCoeffFunc (LiftCoeff); - SetDockParams (_V(0,1.3,-1), _V(0,1,0), _V(0,0,-1)); - SetTouchdownPoints (_V(0,-1.5,2), _V(-1,-1.5,-1.5), _V(1,-1.5,-1.5)); + SetDockParams ({0,1.3,-1}, {0,1,0}, {0,0,-1}); + SetTouchdownPoints ({0,-1.5,2}, {-1,-1.5,-1.5}, {1,-1.5,-1.5}); // visual specs AddMesh (hMeshTpl); @@ -282,15 +282,15 @@ void SolarSail::clbkPreStep (double simt, double simdt, double mjd) const double paddle_area = 7812.5; const double albedo = 2.0; static VECTOR3 ppos[4] = { - _V(0,-550,0), _V(-550,0,0), _V(0,550,0), _V(550,0,0) + {0,-550,0}, {-550,0,0}, {0,550,0}, {550,0,0} }; VECTOR3 nml; for (i = 0; i < 4; i++) { double phi = (paddle_rot[i]-0.5)*PI; double sphi = sin(phi), cphi = cos(phi); - if (i%2 == 0) nml = _V(-sphi,0,cphi); - else nml = _V(0,sphi,cphi); - double f = dotp (mf, nml); + if (i%2 == 0) nml = {-sphi,0,cphi}; + else nml = {0,sphi,cphi}; + double f = dot(mf, nml); if (f < 0) { nml = -nml; f = -f; @@ -328,8 +328,8 @@ void SolarSail::clbkGetRadiationForce (const VECTOR3 &mflux, VECTOR3 &F, VECTOR3 // Therefore only the z-component of the radiation momentum flux contributes // to change the sail's momentum (Fresnel reflection) double mom = mflux.z * albedo *area; - F = _V(0,0,mom); - pos = _V(0,0,0); // don't induce torque + F = {0,0,mom}; + pos = {0,0,0}; // don't induce torque } // -------------------------------------------------------------- diff --git a/Utils/Shipedit/CMakeLists.txt b/Utils/Shipedit/CMakeLists.txt index bab74178a..d9f82c3f9 100644 --- a/Utils/Shipedit/CMakeLists.txt +++ b/Utils/Shipedit/CMakeLists.txt @@ -3,36 +3,37 @@ if(MFC_FOUND) add_executable(Shipedit - Shipedit.cpp - Shipedit.rc - Mesh.cpp - ShipeditDlg.cpp - TransformDlg.cpp - Vecmat.cpp - StdAfx.cpp + Shipedit.cpp + Shipedit.rc + Mesh.cpp + ShipeditDlg.cpp + TransformDlg.cpp + ${ORBITER_SOURCE_DIR}/Vecmat.cpp + StdAfx.cpp ) target_include_directories(Shipedit - PUBLIC ${ORBITER_SOURCE_DIR} + PUBLIC ${ORBITER_SOURCE_DIR} + PUBLIC ${ORBITER_SOURCE_SDK_INCLUDE_DIR} ) set_target_properties(Shipedit - PROPERTIES - FOLDER Tools + PROPERTIES + FOLDER Tools ) add_definitions(-D_AFXDLL) set_target_properties(Shipedit - PROPERTIES - LINK_FLAGS "/SUBSYSTEM:WINDOWS" - FOLDER Utils + PROPERTIES + LINK_FLAGS "/SUBSYSTEM:WINDOWS" + FOLDER Utils ) install(TARGETS - Shipedit - RUNTIME - DESTINATION ${ORBITER_INSTALL_SDK_DIR}/Utils + Shipedit + RUNTIME + DESTINATION ${ORBITER_INSTALL_SDK_DIR}/Utils ) else() message(WARNING "MFC not found: not building Shipedit utility") diff --git a/Utils/Shipedit/Mesh.cpp b/Utils/Shipedit/Mesh.cpp index 7abb2e0c5..e001fc832 100644 --- a/Utils/Shipedit/Mesh.cpp +++ b/Utils/Shipedit/Mesh.cpp @@ -8,6 +8,30 @@ using namespace std; +char *trim_string (char *cbuf) +{ + char *c; + + // strip comments starting with ';' + for (c = cbuf; *c; c++) { + if (*c == ';') { + *c = '\0'; + break; + } + } + // strip trailing white space + for (--c; c >= cbuf; c--) { + if (*c == ' ' || *c == '\t') *c = '\0'; + else break; + } + // skip leading white space + for (c = cbuf; *c; c++) + if (*c != ' ' && *c != '\t') return c; + + // should never get here + return c; +} + // ======================================================================= // Class Triangle diff --git a/Utils/Shipedit/Shipedit.cpp b/Utils/Shipedit/Shipedit.cpp index 6dd4c21e8..a9545f8f2 100644 --- a/Utils/Shipedit/Shipedit.cpp +++ b/Utils/Shipedit/Shipedit.cpp @@ -316,21 +316,21 @@ void CShipeditApp::InitMesh () pp[i].c = pp[i].x1*(pp[i].y2-pp[i].y3) - pp[i].y1*(pp[i].x2-pp[i].x3) + (pp[i].x2*pp[i].y3 - pp[i].x3*pp[i].y2); pp[i].d = -(pp[i].x1*(pp[i].y2*pp[i].z3-pp[i].y3*pp[i].z2) - pp[i].y1*(pp[i].x2*pp[i].z3-pp[i].x3*pp[i].z2) + pp[i].z1*(pp[i].x2*pp[i].y3-pp[i].x3*pp[i].y2)); - Vector dr, a; - dr.Set (pp[i].x1-pp[i].x2, pp[i].y1-pp[i].y2, pp[i].z1-pp[i].z2); - a.Set (pp[i].x3-pp[i].x2, pp[i].y3-pp[i].y2, pp[i].z3-pp[i].z2); - pp[i].d1 = (float)(dotp (dr, a)/a.length2()); - dr.Set (pp[i].x2-pp[i].x3, pp[i].y2-pp[i].y3, pp[i].z2-pp[i].z3); - a.Set (pp[i].x1-pp[i].x3, pp[i].y1-pp[i].y3, pp[i].z1-pp[i].z3); - pp[i].d2 = (float)(dotp (dr, a)/a.length2()); - dr.Set (pp[i].x3-pp[i].x1, pp[i].y3-pp[i].y1, pp[i].z3-pp[i].z1); - a.Set (pp[i].x2-pp[i].x1, pp[i].y2-pp[i].y1, pp[i].z2-pp[i].z1); - pp[i].d3 = (float)(dotp (dr, a)/a.length2()); + VECTOR3 dr, a; + dr = {pp[i].x1 - pp[i].x2, pp[i].y1 - pp[i].y2, pp[i].z1 - pp[i].z2}; + a = {pp[i].x3 - pp[i].x2, pp[i].y3 - pp[i].y2, pp[i].z3 - pp[i].z2}; + pp[i].d1 = (float)(dot(dr, a) / len(a)); + dr = {pp[i].x2 - pp[i].x3, pp[i].y2 - pp[i].y3, pp[i].z2 - pp[i].z3}; + a = {pp[i].x1 - pp[i].x3, pp[i].y1 - pp[i].y3, pp[i].z1 - pp[i].z3}; + pp[i].d2 = (float)(dot(dr, a) / len(a)); + dr = {pp[i].x3 - pp[i].x1, pp[i].y3 - pp[i].y1, pp[i].z3 - pp[i].z1}; + a = {pp[i].x2 - pp[i].x1, pp[i].y2 - pp[i].y1, pp[i].z2 - pp[i].z1}; + pp[i].d3 = (float)(dot(dr, a) / len(a)); } vol = 0.0; - cg.Set(0,0,0); cg_base.Set(0,0,0); cg_add.Set(0,0,0); - cs.Set(0,0,0); + cg = cg_base = cg_add = {0, 0, 0}; + cs = {0, 0, 0}; J.Set(0,0,0,0,0,0,0,0,0); J_base.Set(J); J_add.Set(J); nop = 0, nvol = 0; for (i = 0; i < 3; i++) ncs[i] = 0; @@ -343,7 +343,7 @@ void CShipeditApp::InitMesh () void CShipeditApp::ProcessPackage () { int i, j, n; - Vector cg_tmp; + VECTOR3 cg_tmp; Matrix J_tmp; for (i = n = 0; i < 1000; i++) { @@ -370,7 +370,7 @@ void CShipeditApp::ProcessPackage () cg_add += cg_tmp; J_add += J_tmp; if (!(++flushcount % 1000)) { - cg_base += cg_add; cg_add.Set(0,0,0); + cg_base += cg_add; cg_add = {0, 0, 0}; J_base += J_add; J_add.Set (0,0,0,0,0,0,0,0,0); } vol = bbvol * (double)nvol / (double)nop; @@ -490,7 +490,7 @@ bool CShipeditApp::scan_gridline (VOXGRID &g, int x, int y, int z, int dir_idx, return isinter; } -void CShipeditApp::analyse_grid (VOXGRID &g, double &vol, Vector &com, Vector &cs, Matrix &pmi) +void CShipeditApp::analyse_grid (VOXGRID &g, double &vol, VECTOR3 &com, VECTOR3 &cs, Matrix &pmi) { int i, j, k, idx, ninside = 0; double x, y, z; @@ -814,7 +814,7 @@ void GridintDlg::OnGridintStart() //#endif double vol; - Vector com, cs; + VECTOR3 com, cs; Matrix pmi; app->analyse_grid (g, vol, com, cs, pmi); sprintf (cbuf, "%0.2f", vol); diff --git a/Utils/Shipedit/Shipedit.h b/Utils/Shipedit/Shipedit.h index 1e913751d..2b0f28b0b 100644 --- a/Utils/Shipedit/Shipedit.h +++ b/Utils/Shipedit/Shipedit.h @@ -58,10 +58,10 @@ class CShipeditApp : public CWinApp { TriParam *pp; D3DVECTOR bbmin, bbmax; // bounding box double bbvol; // bb volume - Vector bbcs; // bb cross sections + VECTOR3 bbcs; // bb cross sections double vol; // volume - Vector cg, cg_base, cg_add; // centre of gravity - Vector cs; // cross sections + VECTOR3 cg, cg_base, cg_add; // centre of gravity + VECTOR3 cs; // cross sections Matrix J, J_base, J_add; // inertia tensor BOOL bBackgroundOp; int flushcount; @@ -70,7 +70,7 @@ class CShipeditApp : public CWinApp { // grid-integration related functions void setup_grid (VOXGRID &g, int level); bool scan_gridline (VOXGRID &g, int x, int y, int z, int dir_idx, int ntri, const TriParam *pp); - void analyse_grid (VOXGRID &g, double &vol, Vector &com, Vector &cs, Matrix &pmi); + void analyse_grid (VOXGRID &g, double &vol, VECTOR3 &com, VECTOR3 &cs, Matrix &pmi); // Overrides // ClassWizard generated virtual function overrides diff --git a/Utils/Shipedit/TransformDlg.cpp b/Utils/Shipedit/TransformDlg.cpp index 150a65558..9475c7770 100644 --- a/Utils/Shipedit/TransformDlg.cpp +++ b/Utils/Shipedit/TransformDlg.cpp @@ -99,19 +99,19 @@ END_MESSAGE_MAP() void RotateDlg::OnDoRotx() { UpdateData(); - mesh->Rotate (mesh->ROTATE_X, (float)(RAD*m_Rotx)); + mesh->Rotate (mesh->ROTATE_X, (float)(_RAD_*m_Rotx)); } void RotateDlg::OnDoRoty() { UpdateData(); - mesh->Rotate (mesh->ROTATE_Y, (float)(RAD*m_Roty)); + mesh->Rotate (mesh->ROTATE_Y, (float)(_RAD_*m_Roty)); } void RotateDlg::OnDoRotz() { UpdateData(); - mesh->Rotate (mesh->ROTATE_Z, (float)(RAD*m_Rotz)); + mesh->Rotate (mesh->ROTATE_Z, (float)(_RAD_*m_Rotz)); } ///////////////////////////////////////////////////////////////////////////// // ScaleDlg dialog diff --git a/Utils/Shipedit/Vecmat.cpp b/Utils/Shipedit/Vecmat.cpp deleted file mode 100644 index 90d812d65..000000000 --- a/Utils/Shipedit/Vecmat.cpp +++ /dev/null @@ -1,179 +0,0 @@ -// Copyright (c) Martin Schweiger -// Licensed under the MIT License - -#include -#include "Vecmat.h" - -int irand (int range) -{ - static const double drand_max = (double)(RAND_MAX+0.1); - return (int)((double)rand()*(double)range/drand_max); -} - -// ======================================================================= -// class Vector - -double Vector::dist2 (const Vector &vec) const -{ - double dx = x-vec.x; - double dy = y-vec.y; - double dz = z-vec.z; - return dx*dx + dy*dy + dz*dz; -} - -Vector Vector::unit () const -{ - double ilen = 1.0/length(); - return Vector (x*ilen, y*ilen, z*ilen); -} - -void Vector::unify () -{ - double ilen = 1.0/length(); - x *= ilen, y *= ilen, z *= ilen; -} - -double xangle (const Vector &a, const Vector &b) -{ - double cosa = dotp (a.unit(), b.unit()); - if (cosa < 1.0) { // also need to check for > -1 - double angle = acos(cosa); - if (cosa >= 0.0) return angle; - else return Pi2 - angle; - } else return 0.0; -} - -// ======================================================================= -// class Matrix - -Matrix::Matrix () -{ - memset (data, 0, 9*sizeof(double)); -} - -Matrix::Matrix (const Matrix &A) -{ - memcpy (data, A.data, 9*sizeof(double)); -} - -Matrix::Matrix (double a11, double a12, double a13, - double a21, double a22, double a23, - double a31, double a32, double a33) -{ - m11 = a11, m12 = a12, m13 = a13; - m21 = a21, m22 = a22, m23 = a23; - m31 = a31, m32 = a32, m33 = a33; -} - -Matrix &Matrix::operator= (const Matrix &A) -{ - memcpy (data, A.data, 9 * sizeof (double)); - return *this; -} - -Matrix Matrix::operator* (const Matrix &A) const -{ - return Matrix ( - m11*A.m11 + m12*A.m21 + m13*A.m31, m11*A.m12 + m12*A.m22 + m13*A.m32, m11*A.m13 + m12*A.m23 + m13*A.m33, - m21*A.m11 + m22*A.m21 + m23*A.m31, m21*A.m12 + m22*A.m22 + m23*A.m32, m21*A.m13 + m22*A.m23 + m23*A.m33, - m31*A.m11 + m32*A.m21 + m33*A.m31, m31*A.m12 + m32*A.m22 + m33*A.m32, m31*A.m13 + m32*A.m23 + m33*A.m33 - ); -} - -void Matrix::premul (const Matrix &A) -{ - Matrix B(*this); - m11 = A.m11*B.m11 + A.m12*B.m21 + A.m13*B.m31; - m12 = A.m11*B.m12 + A.m12*B.m22 + A.m13*B.m32; - m13 = A.m11*B.m13 + A.m12*B.m23 + A.m13*B.m33; - m21 = A.m21*B.m11 + A.m22*B.m21 + A.m23*B.m31; - m22 = A.m21*B.m12 + A.m22*B.m22 + A.m23*B.m32; - m23 = A.m21*B.m13 + A.m22*B.m23 + A.m23*B.m33; - m31 = A.m31*B.m11 + A.m32*B.m21 + A.m33*B.m31; - m32 = A.m31*B.m12 + A.m32*B.m22 + A.m33*B.m32; - m33 = A.m31*B.m13 + A.m32*B.m23 + A.m33*B.m33; -} - -void Matrix::postmul (const Matrix &A) -{ - Matrix B(*this); - m11 = B.m11*A.m11 + B.m12*A.m21 + B.m13*A.m31; - m12 = B.m11*A.m12 + B.m12*A.m22 + B.m13*A.m32; - m13 = B.m11*A.m13 + B.m12*A.m23 + B.m13*A.m33; - m21 = B.m21*A.m11 + B.m22*A.m21 + B.m23*A.m31; - m22 = B.m21*A.m12 + B.m22*A.m22 + B.m23*A.m32; - m23 = B.m21*A.m13 + B.m22*A.m23 + B.m23*A.m33; - m31 = B.m31*A.m11 + B.m32*A.m21 + B.m33*A.m31; - m32 = B.m31*A.m12 + B.m32*A.m22 + B.m33*A.m32; - m33 = B.m31*A.m13 + B.m32*A.m23 + B.m33*A.m33; -} - -Matrix IMatrix() -{ - return Matrix (1.0,0.0,0.0, 0.0,1.0,0.0, 0.0,0.0,1.0); -} - -Vector mul (const Matrix &A, const Vector &b) -{ - return Vector ( - A.m11*b.x + A.m12*b.y + A.m13*b.z, - A.m21*b.x + A.m22*b.y + A.m23*b.z, - A.m31*b.x + A.m32*b.y + A.m33*b.z); -} - -Vector tmul (const Matrix &A, const Vector &b) -{ - return Vector ( - A.m11*b.x + A.m21*b.y + A.m31*b.z, - A.m12*b.x + A.m22*b.y + A.m32*b.z, - A.m13*b.x + A.m32*b.y + A.m33*b.z); -} - -Matrix inv (const Matrix &A) -{ - double det = A.m11 * (A.m22*A.m33 - A.m32*A.m23) - - A.m12 * (A.m21*A.m33 - A.m31*A.m23) + - A.m13 * (A.m21*A.m32 - A.m31*A.m22); - return Matrix ( - ( A.m22*A.m33 - A.m32*A.m23) / det, - (-A.m12*A.m33 + A.m32*A.m13) / det, - ( A.m12*A.m23 - A.m22*A.m13) / det, - (-A.m21*A.m33 + A.m31*A.m23) / det, - ( A.m11*A.m33 - A.m31*A.m13) / det, - (-A.m11*A.m23 + A.m21*A.m13) / det, - ( A.m21*A.m32 - A.m31*A.m22) / det, - (-A.m11*A.m32 + A.m31*A.m12) / det, - ( A.m11*A.m22 - A.m21*A.m12) / det); -} - -Matrix transp (const Matrix &A) -{ - return Matrix (A.m11, A.m21, A.m31, - A.m12, A.m22, A.m32, - A.m13, A.m23, A.m33); -} - -char *trim_string (char *cbuf) -{ - char *c; - - // strip comments starting with ';' - for (c = cbuf; *c; c++) { - if (*c == ';') { - *c = '\0'; - break; - } - } - // strip trailing white space - for (--c; c >= cbuf; c--) { - if (*c == ' ' || *c == '\t') *c = '\0'; - else break; - } - // skip leading white space - for (c = cbuf; *c; c++) - if (*c != ' ' && *c != '\t') return c; - - // should never get here - return c; -} - diff --git a/Utils/Shipedit/Vecmat.h b/Utils/Shipedit/Vecmat.h deleted file mode 100644 index 68b4deea0..000000000 --- a/Utils/Shipedit/Vecmat.h +++ /dev/null @@ -1,188 +0,0 @@ -// Copyright (c) Martin Schweiger -// Licensed under the MIT License - -#ifndef __VECMAT_H -#define __VECMAT_H - -#include -#include -#include - -// ======================================================================= -// Some useful constants - -#pragma optimize ("", off) - -const double Pi = 3.1415926535897932384626433832795; -const double Pi2 = 2.0*Pi; -const double Pi05 = 0.5*Pi; -const double Pi15 = 1.5*Pi; -const double Pi025 = 0.25*Pi; -const double RAD = Pi/180.0; -const double DEG = 180.0/Pi; - -#pragma optimize ("", on) - -inline double Rad (double deg) { return RAD*deg; } -inline double Deg (double rad) { return DEG*rad; } - -// ======================================================================= -// Auxiliary functions - -// Returns integer random number in the range 0 <= r < range -int irand (int range); - -// Normalise argument to range -Pi <= a < Pi -inline double normangle (double angle) -{ - double a = fmod (angle, Pi2); - return (a >= Pi ? a-Pi2 : a < -Pi ? a+Pi2 : a); -} - -// Normalise argument to range 0 <= a < 2Pi -inline double posangle (double angle) -{ - double a = fmod (angle, Pi2); - return (a >= 0.0 ? a : a+Pi2); -} - -char *trim_string (char *cbuf); - -// ======================================================================= -// class Vector - -class Vector { -public: - inline Vector () - { x = y = z = 0.0; } - - inline Vector (double _x, double _y, double _z) - { x = _x, y = _y, z = _z; } - - inline Vector (const Vector &vec) - { x = vec.x, y = vec.y, z = vec.z; } - - inline void Set (double _x, double _y, double _z) - { x = _x, y = _y, z = _z; } - - inline void Set (const Vector &vec) - { x = vec.x, y = vec.y, z = vec.z; } - - inline Vector &operator= (const Vector &vec) - { x = vec.x, y = vec.y, z = vec.z; return *this; } - - inline Vector operator+ (const Vector &vec) const - { return Vector (x+vec.x, y+vec.y, z+vec.z); } - - inline Vector operator- (const Vector &vec) const - { return Vector (x-vec.x, y-vec.y, z-vec.z); } - - inline Vector operator- () const // unary minus - { return Vector (-x, -y, -z); } - - inline Vector operator* (double f) const - { return Vector (x*f, y*f, z*f); } - - inline Vector operator/ (double f) const - { return Vector (x/f, y/f, z/f); } - - inline double operator& (const Vector &vec) const // scalar product - { return x*vec.x + y*vec.y + z*vec.z; } - - inline Vector &operator+= (const Vector &vec) - { x += vec.x, y += vec.y, z += vec.z; return *this; } - - inline Vector &operator-= (const Vector &vec) - { x -= vec.x, y -= vec.y, z -= vec.z; return *this; } - - inline Vector &operator*= (const double f) - { x *= f, y *= f, z *= f; return *this; } - - inline Vector &operator/= (const double f) - { x /= f, y /= f, z /= f; return *this; } - - friend Vector crossp (const Vector &a, const Vector &b) // cross product - { return Vector (a.y*b.z - b.y*a.z, a.z*b.x - b.z*a.x, a.x*b.y - b.x*a.y); } - - friend double dotp (const Vector &a, const Vector &b) // scalar product - { return a.x*b.x + a.y*b.y + a.z*b.z; } - - inline double length2 () const // square of vector length - { return x*x + y*y + z*z; } - - inline double length () const // vector length - { return sqrt (length2()); } - - double dist2 (const Vector &vec) const; // square of distance between two points - - inline double dist (const Vector &vec) const // distance between two points - { return sqrt (dist2 (vec)); } - - Vector unit () const; // return unit vector in direction of *this - - void unify (); // set length of *this to unity - - friend double xangle (const Vector &a, const Vector &b); - // angle between two straight lines through the origin, defined - // by directions of a and b - - friend std::ostream &operator<< (std::ostream &os, const Vector &v) - { os << v.x << ' ' << v.y << ' ' << v.z; return os; } - - union { - double data[3]; - struct { double x, y, z; }; - }; -}; - -// ======================================================================= -// class Matrix - -class Matrix { -public: - Matrix (); - Matrix (const Matrix &A); - Matrix (double a11, double a12, double a13, - double a21, double a22, double a23, - double a31, double a32, double a33); - - void Set (double a11, double a12, double a13, - double a21, double a22, double a23, - double a31, double a32, double a33) - { m11=a11, m12=a12, m13=a13, m21=a21, m22=a22, m23=a23, m31=a31, m32=a32, m33=a33; } - - void Set (const Matrix &A) - { memcpy (data, A.data, 9*sizeof(double)); } - - Matrix &operator= (const Matrix &A); - Matrix operator* (const Matrix &A) const; - - inline Matrix &operator+= (const Matrix &A) - { for (int i = 0; i < 9; i++) data[i] += A.data[i]; return *this; } - - void premul (const Matrix &A); // *this = A * *this - void postmul (const Matrix &A); // *this = *this * A - - friend Matrix IMatrix(); // returns identity matrix - - friend Vector mul (const Matrix &A, const Vector &b); // returns A * b - friend Vector tmul (const Matrix &A, const Vector &b); // returns A^T * b - friend Matrix inv (const Matrix &A); // inverse of A - friend Matrix transp (const Matrix &A); // transpose of A - - union { - double data[9]; - struct { double m11, m12, m13, m21, m22, m23, m31, m32, m33; }; - }; -}; - -// ======================================================================= -// Geometric utility functions - -// Distance of point 'a' from a line defined by a point 'p' and direction vector 'd' -inline double PointLineDist (const Vector &a, const Vector &p, const Vector &d) -{ - return dotp(d,a-p)/d.length(); -} - -#endif // !__VECMAT_H \ No newline at end of file diff --git a/Utils/meshc/CMakeLists.txt b/Utils/meshc/CMakeLists.txt index 513df770f..e8de2c067 100644 --- a/Utils/meshc/CMakeLists.txt +++ b/Utils/meshc/CMakeLists.txt @@ -8,6 +8,7 @@ add_executable(meshc target_include_directories(meshc PUBLIC ${ORBITER_SOURCE_DIR} + PUBLIC ${ORBITER_SOURCE_SDK_INCLUDE_DIR} ) set_target_properties(meshc