Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Centralize basic math types and functions (part 3) #370

Draft
wants to merge 90 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
6471184
OrbiterAPI.h: few small clean-ups
dimitry-ishenko Jun 17, 2023
1933865
DrawAPI.h: remove DirectX 9 specific conversions
dimitry-ishenko Jun 19, 2023
e5dc319
Add template operators and functions for vectors
dimitry-ishenko Jun 18, 2023
f8dcfbf
Add stream operators for vectors
dimitry-ishenko Jun 21, 2023
d592df8
Add pow() for vectors
dimitry-ishenko Jun 23, 2023
0f3080e
Add exp(), lerp() and sqrt() for vectors
dimitry-ishenko Jun 23, 2023
370cde2
Templatize saturate()
dimitry-ishenko Jul 9, 2023
890ea9e
Centralize VECTOR4
dimitry-ishenko Jun 20, 2023
93ceb2f
Centralize VECTOR3
dimitry-ishenko Jun 20, 2023
34229aa
Remove VectorHelpers.h
dimitry-ishenko Jun 20, 2023
cc2e1a4
Clean-up
dimitry-ishenko Jun 20, 2023
bd4b66e
LuaInterpreter: clean-up
dimitry-ishenko Jun 20, 2023
75d6e61
ScnEditor: Clean-up
dimitry-ishenko Jun 20, 2023
fd1faa4
TransX: clean-up
dimitry-ishenko Jun 20, 2023
8954b21
Atlantis: clean-up
dimitry-ishenko Jun 20, 2023
69daccc
DeltaGlider: clean-up
dimitry-ishenko Jun 20, 2023
3c40cde
DragonFly: clean-up
dimitry-ishenko Jun 20, 2023
a69d576
HST: clean-up
dimitry-ishenko Jun 20, 2023
e5911f7
MMU: clean-up
dimitry-ishenko Jun 20, 2023
a6d5295
Quadcopter: clean-up
dimitry-ishenko Jun 20, 2023
4c6493b
ShuttleA: clean-up
dimitry-ishenko Jun 20, 2023
6f21191
ShuttlePB: clean-up
dimitry-ishenko Jun 20, 2023
429d12f
Solarsail: clean-up
dimitry-ishenko Jun 20, 2023
8023441
XRSound: clean-up
dimitry-ishenko Jun 20, 2023
839724f
D3D7Client: clean-up
dimitry-ishenko Jun 20, 2023
479a130
D3D9Client: clean-up
dimitry-ishenko Jun 20, 2023
031394e
DrawOrbits: clean-up
dimitry-ishenko Jun 20, 2023
d7057c0
GenericCamera: clean-up
dimitry-ishenko Jun 20, 2023
c437e8e
TerrainToolBox: clean-up
dimitry-ishenko Jun 20, 2023
5f4ee84
OrbiterAPI.h: remove unused VECTOR3 functions
dimitry-ishenko Jun 20, 2023
1b58b76
Replace Vector4 with VECTOR4
dimitry-ishenko Jun 29, 2023
5b1c8f7
ShipEdit: match names used by Orbiter
dimitry-ishenko Jun 22, 2023
10e47ad
ShipEdit: move trim_string
dimitry-ishenko Jun 22, 2023
a979f8c
ShipEdit: use Orbiter's Vecmat
dimitry-ishenko Jun 22, 2023
e92b5a1
Give Vector is_vector3 type trait
dimitry-ishenko Jul 10, 2023
01dea56
Base: clean-up & use standard functions/operators
dimitry-ishenko Jul 10, 2023
98003a7
Baseobj: clean-up & use standard functions/operators
dimitry-ishenko Jul 10, 2023
e5a1266
Body: clean-up & use standard functions/operators
dimitry-ishenko Jul 10, 2023
51f8603
BodyIntegrator: clean-up & use standard functions/operators
dimitry-ishenko Jul 10, 2023
cf9795f
Camera: clean-up & use standard functions/operators
dimitry-ishenko Jul 10, 2023
85d6f66
Celbody: clean-up & use standard functions/operators
dimitry-ishenko Jul 10, 2023
5e29355
Config: clean-up
dimitry-ishenko Jul 10, 2023
7221bf3
CSphereMgr: clean-up & use standard functions/operators
dimitry-ishenko Jul 10, 2023
0cc4e90
DlgFocus: use standard functions/operators
dimitry-ishenko Jul 10, 2023
fd30724
DlgInfo: use standard functions/operators
dimitry-ishenko Jul 10, 2023
4bc64c8
Element: clean-up & use standard functions/operators
dimitry-ishenko Jul 10, 2023
b8b225c
elevmgr: use standard functions/operators
dimitry-ishenko Jul 10, 2023
a1c445c
FlightRecorder: clean-up & use standard functions/operators
dimitry-ishenko Jul 10, 2023
c9f7295
hud: clean-up & use standard functions/operators
dimitry-ishenko Jul 10, 2023
a5f7e0b
Mfd: use standard functions/operators
dimitry-ishenko Jul 10, 2023
f3e4fdf
MfdAlign: clean-up & use standard functions/operators
dimitry-ishenko Jul 10, 2023
2eff396
MfdDocking: clean-up & use standard functions/operators
dimitry-ishenko Jul 10, 2023
1b350de
MfdLanding: clean-up & use standard functions/operators
dimitry-ishenko Jul 10, 2023
081aec1
MfdMap_old: clean-up & use standard functions/operators
dimitry-ishenko Jul 10, 2023
eaff82d
MfdMap: clean-up & use standard functions/operators
dimitry-ishenko Jul 10, 2023
868c976
MfdSurface: use standard functions/operators
dimitry-ishenko Jul 10, 2023
8a6a523
MfdSync: clean-up & use standard functions/operators
dimitry-ishenko Jul 10, 2023
54152fd
MfdTransfer: clean-up & use standard functions/operators
dimitry-ishenko Jul 10, 2023
ba54d99
Nav: clean-up & use standard functions/operators
dimitry-ishenko Jul 10, 2023
8b39983
Orbiter: use standard functions/operators
dimitry-ishenko Jul 10, 2023
d34004a
OrbiterAPI: clean-up
dimitry-ishenko Jul 10, 2023
2444a8d
Pane: clean-up & use standard functions/operators
dimitry-ishenko Jul 10, 2023
f0999cf
PinesGrav: use standard functions/operators
dimitry-ishenko Jul 10, 2023
2f71ff7
Planet: clean-up & use standard functions/operators
dimitry-ishenko Jul 10, 2023
e413c07
Psys: clean-up & use standard functions/operators
dimitry-ishenko Jul 10, 2023
f428815
Rigidbody: clean-up & use standard functions/operators
dimitry-ishenko Jul 10, 2023
b46b669
Scene: clean-up & use standard functions/operators
dimitry-ishenko Jul 10, 2023
17aedf1
Spherepatch: clean-up & use standard functions/operators
dimitry-ishenko Jul 10, 2023
571654f
SuperVessel: clean-up & use standard functions/operators
dimitry-ishenko Jul 10, 2023
9bb80d6
surfmgr2: use standard functions/operators
dimitry-ishenko Jul 10, 2023
3a3d542
tilelabel: clean-up & use standard functions/operators
dimitry-ishenko Jul 10, 2023
f501838
TileMgr: clean-up & use standard functions/operators
dimitry-ishenko Jul 10, 2023
801eaef
tilemgr2: clean-up & use standard functions/operators
dimitry-ishenko Jul 10, 2023
a2e9b59
VBase: clean-up & use standard functions/operators
dimitry-ishenko Jul 10, 2023
f6f1f5e
VCockpit: clean-up & use standard functions/operators
dimitry-ishenko Jul 10, 2023
b0fe1b2
VectorMap: clean-up
dimitry-ishenko Jul 10, 2023
e63c7e3
Vessel: clean-up & use standard functions/operators
dimitry-ishenko Jul 10, 2023
e30d39b
Vesselbase: clean-up & use standard functions/operators
dimitry-ishenko Jul 10, 2023
0a89bc1
Vesselstatus: clean-up & use standard functions/operators
dimitry-ishenko Jul 10, 2023
6b8f8c7
Vobject: clean-up & use standard functions/operators
dimitry-ishenko Jul 10, 2023
46bebaf
VPlanet: clean-up & use standard functions/operators
dimitry-ishenko Jul 10, 2023
8e19805
Vstar: clean-up & use standard functions/operators
dimitry-ishenko Jul 10, 2023
1b21c7d
Vvessel: clean-up & use standard functions/operators
dimitry-ishenko Jul 10, 2023
3c14ddf
Shipedit: clean-up & use standard functions/operators
dimitry-ishenko Jul 10, 2023
16ce7c5
Vector: remove unnecessary functions and operators
dimitry-ishenko Jul 10, 2023
0b0cd3e
De-unionize TILEBOUNDS
dimitry-ishenko Jul 2, 2023
b2c9fc7
VECTOR4: 0-init by default
dimitry-ishenko Jul 5, 2023
44d4fcb
Add ctor to MESHGROUP_TRANSFORM
dimitry-ishenko Jul 2, 2023
310fb23
VECTOR3: 0-init by default
dimitry-ishenko Jul 6, 2023
6be5f68
Replace Vector with VECTOR3
dimitry-ishenko Jul 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions OVP/D3D7Client/CSphereMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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};
}

// =======================================================================
Expand Down
2 changes: 1 addition & 1 deletion OVP/D3D7Client/CloudMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 8 additions & 8 deletions OVP/D3D7Client/HazeMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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,
Expand All @@ -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);
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions OVP/D3D7Client/Light.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down
16 changes: 8 additions & 8 deletions OVP/D3D7Client/Particle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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);

Expand Down Expand Up @@ -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;
}

Expand Down
11 changes: 5 additions & 6 deletions OVP/D3D7Client/Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -450,7 +450,7 @@ void Scene::Render ()
const std::vector<oapi::GraphicsClient::LABELSPEC>& 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);
}
Expand Down Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion OVP/D3D7Client/SurfMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
20 changes: 9 additions & 11 deletions OVP/D3D7Client/TileMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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};
}

// =======================================================================
Expand Down Expand Up @@ -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);
Expand Down
18 changes: 9 additions & 9 deletions OVP/D3D7Client/VBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -382,16 +382,16 @@ 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;
bool lightmod = false;

// 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);
Expand Down
16 changes: 8 additions & 8 deletions OVP/D3D7Client/VObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions OVP/D3D7Client/VPlanet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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)
Expand Down
Loading