Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
130 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
c727e94
VECTOR3: don't rely on UB
dimitry-ishenko Jul 6, 2023
c21963e
Baseobj: post-Vector clean-up
dimitry-ishenko Jul 3, 2023
370637d
FlightRecorder: post-Vector clean-up
dimitry-ishenko Jul 3, 2023
255fa32
hud: post-Vector clean-up
dimitry-ishenko Jul 3, 2023
c1183e4
MfdAlign: post-Vector clean-up
dimitry-ishenko Jul 3, 2023
2f5bdec
MfdMap_old: post-Vector clean-up
dimitry-ishenko Jul 3, 2023
ed62d99
MfdTransfer: post-Vector clean-up
dimitry-ishenko Jul 4, 2023
fccfab7
Psys: post-Vector clean-up
dimitry-ishenko Jul 4, 2023
df606af
Rigidbody: post-Vector clean-up
dimitry-ishenko Jul 3, 2023
b7ee1d3
Scene: post-Vector clean-up
dimitry-ishenko Jul 4, 2023
b133cba
Spherepatch: post-Vector clean-up
dimitry-ishenko Jul 3, 2023
8d553a0
SuperVessel: post-Vector clean-up
dimitry-ishenko Jul 3, 2023
05908a0
tilelabel: post-Vector clean-up
dimitry-ishenko Jul 3, 2023
3184199
tilemgr2: post-Vector clean-up
dimitry-ishenko Jul 3, 2023
8e2b13c
VCockpit: post-Vector clean-up
dimitry-ishenko Jul 3, 2023
bf7af48
VectorMap: post-Vector clean-up
dimitry-ishenko Jul 3, 2023
3d8a590
Vessel: post-Vector clean-up
dimitry-ishenko Jul 3, 2023
d7c063e
Vesselstatus: post-Vector clean-up
dimitry-ishenko Jul 3, 2023
2089140
Shipedit: post-Vector clean-up
dimitry-ishenko Jul 3, 2023
5898452
Centralize FVECTOR2
dimitry-ishenko Jul 3, 2023
a4a452c
vector.h: tighten up template params
dimitry-ishenko Jul 3, 2023
4892489
Enable vector conversions
dimitry-ishenko Jul 8, 2023
268d422
Use len() where possible
dimitry-ishenko Jul 4, 2023
ee78887
Centralize COLOUR3 and COLOUR4
dimitry-ishenko Jul 8, 2023
6a713d2
Add color conversion functions
dimitry-ishenko Jul 8, 2023
308aa52
Add max_rgb functions for colors and vectors
dimitry-ishenko Jul 6, 2023
8cdd870
Give FVECTOR3 is_vector3 type trait
dimitry-ishenko Jul 10, 2023
2d948a7
D3D9Client: clean-up & use standard functions
dimitry-ishenko Jul 10, 2023
e590a91
Atlantis: clean-up
dimitry-ishenko Jul 10, 2023
95ce14c
Centralize FVECTOR3
dimitry-ishenko Jul 10, 2023
2f0859d
D3D9Client: remove float2 macro
dimitry-ishenko Jul 14, 2023
3131356
D3D9Client: remove float3 macro
dimitry-ishenko Jul 14, 2023
13d2c96
D3D9Client: remove float4 macro
dimitry-ishenko Jul 14, 2023
ff7916f
D3D9Client: remove float4x4 macro
dimitry-ishenko Jul 14, 2023
c67ce4a
Give FVECTOR4 is_vector4 type trait
dimitry-ishenko Jul 14, 2023
6e513a0
D3D9Client: clean-up & use standard functions
dimitry-ishenko Jul 14, 2023
2b14633
DrawOrbits: clean-up & use standard functions
dimitry-ishenko Jul 14, 2023
95e2031
TerrainToolbox: clean-up & use standard functions
dimitry-ishenko Jul 14, 2023
09210e2
CelSphereAPI: clean-up & use standard functions
dimitry-ishenko Jul 14, 2023
bc1e96d
Centralize FVECTOR4
dimitry-ishenko Jul 14, 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
18 changes: 9 additions & 9 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 @@ -76,7 +76,7 @@ void HazeManager::Render (LPDIRECT3DDEVICE7 dev, D3DMATRIX &wmat, bool dual)

D3DMAT_MatrixInvert (&imat, &wmat);
VECTOR3 rpos = {imat._41, imat._42, imat._43}; // camera in local coords (planet radius = 1)
double cdist = length (rpos);
double cdist = len(rpos);

alpha = dens0 * min (1.0, (cdist-1.0)*200.0);
if (!dual) alpha = 1.0-alpha;
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
26 changes: 13 additions & 13 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 @@ -552,7 +552,7 @@ void ExhaustStream::Update ()
oapiGetGlobalPos (hPlanet, &pp);
rad = oapiGetSize (hPlanet);
VECTOR3 dv = pp-plast->pos; // gravitational dv
double d = length (dv);
double d = len(dv);
dv *= GGRAV * oapiGetMass(hPlanet)/(d*d*d) * dt;

ATMPARAM prm;
Expand Down Expand Up @@ -580,19 +580,19 @@ void ExhaustStream::Update ()
p->size += alpha * dt;

VECTOR3 s (p->pos - pp);
if (length(s) < r) {
VECTOR3 dp = s * (r/length(s)-1.0);
if (len(s) < r) {
VECTOR3 dp = s * (r / len(s) - 1);
p->pos += dp;

static double dv_scale = length(vv)*0.2;
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;
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
15 changes: 7 additions & 8 deletions OVP/D3D7Client/Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,20 +288,20 @@ VECTOR3 Scene::SkyColour ()
oapiCameraGlobalPos (&rc);
oapiGetGlobalPos (hProxy, &rp);
pc = rc-rp;
double cdist = length (pc);
double cdist = len(pc);
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;
if (col[i] > 1) col[i] = 1;
}
return col;
}
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
24 changes: 12 additions & 12 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 Expand Up @@ -423,7 +423,7 @@ bool vBase::ModLighting (LPD3DLIGHT7 light, double &nextcheck)
plight.z = f*b0;
}
}
for (j = 0; j < 3; j++) lcol.data[j] = min (lcol.data[j], plight.data[j]);
for (j = 0; j < 3; j++) lcol[j] = min(lcol[j], plight[j]);
lightmod = true;
}

Expand All @@ -442,7 +442,7 @@ bool vBase::ModLighting (LPD3DLIGHT7 light, double &nextcheck)

if (phi < as+ap) { // overlap
double lfrac = (phi <= ap-as ? 0.0 : (phi+as-ap)/(2.0*as));
for (j = 0; j < 3; j++) lcol.data[j] = min (lcol.data[j], lfrac);
for (j = 0; j < 3; j++) lcol[j] = min(lcol[j], lfrac);
lightmod = true;
}

Expand All @@ -465,4 +465,4 @@ bool vBase::ModLighting (LPD3DLIGHT7 light, double &nextcheck)

nextcheck = max (1.0, 50.0*(sqrt(fabs(phi-PI05)))); // next test
return lightmod;
}
}
Loading