Skip to content

Commit

Permalink
Merge pull request #394 from orbitersim/terrain_elev
Browse files Browse the repository at this point in the history
Fixing terrain collision
  • Loading branch information
jarmonik authored Jan 7, 2024
2 parents f3ffb61 + 5318e92 commit 205f8dd
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 16 deletions.
7 changes: 2 additions & 5 deletions OVP/D3D9Client/Surfmgr2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,6 @@ INT16 *SurfTile::ReadElevationFile (const char *name, int lvl, int ilat, int iln

if (e) {

//
//for (i = 0; i < ndat; i++) elev[i] = (trunc(float(e[i]) * (ehdr.scale / tgt_res)) + trunc(ehdr.offset / tgt_res)) * tgt_res;

if (ehdr.scale != tgt_res) { // rescale the data
double rescale = ehdr.scale / tgt_res;
for (i = 0; i < ndat; i++)
Expand Down Expand Up @@ -371,8 +368,8 @@ INT16 *SurfTile::ReadElevationFile (const char *name, int lvl, int ilat, int iln
phdr->scale = 1.0;
#endif
p += phdr->hdrsize;
rescale = (do_rescale = (phdr->scale != 1.0)) ? phdr->scale : 1.0;
offset = (do_shift = (phdr->offset != 0.0)) ? INT16(phdr->offset) : 0;
rescale = (do_rescale = (phdr->scale != tgt_res)) ? phdr->scale/tgt_res : 1.0;
offset = (do_shift = (phdr->offset != 0.0)) ? INT16(phdr->offset/tgt_res) : 0;

switch(phdr->dtype) {
case 0:
Expand Down
7 changes: 2 additions & 5 deletions OVP/D3D9Client/VPlanet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,12 +377,9 @@ vPlanet::vPlanet (OBJHANDLE _hObj, const Scene *scene) :
physics_patchres = *(DWORD*)oapiGetObjectParam (_hObj, OBJPRM_PLANET_SURFACEMAXLEVEL);
physics_patchres = min (physics_patchres, *(DWORD*)gc->GetConfigParam (CFGPRM_SURFACEMAXLEVEL));

// Push the graphics resolution higher than the one used for physics
// to enable more accurate bilinear interpolation of the terrain.
max_patchres = physics_patchres + 4;
//if (elev_mode == 1) max_patchres = physics_patchres + 4; // Push the graphics resolution higher than the one used for physics
//else max_patchres = physics_patchres; // to enable more accurate bilinear interpolation of the terrain.
// Works well on the Moon, not so well on high-res KSC.

max_patchres = min(max_patchres, *(DWORD*)gc->GetConfigParam(CFGPRM_SURFACEMAXLEVEL));

tilever = *(int*)oapiGetObjectParam (_hObj, OBJPRM_PLANET_TILEENGINE);
if (tilever < 2) {
Expand Down
4 changes: 4 additions & 0 deletions Orbitersdk/include/DrawAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
#include <assert.h>
#include <xmmintrin.h>

#if defined(_MSC_VER) && (_MSC_VER < 1920 ) // Microsoft Visual Studio Version 2017 and lower
#include <algorithm>
#endif

#ifdef D3D9CLIENT_EXPORTS
#include "d3dx9.h"
#endif
Expand Down
4 changes: 4 additions & 0 deletions Orbitersdk/include/OrbiterAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
#include <math.h>
#include <vector>

#if defined(_MSC_VER) && (_MSC_VER < 1920 ) // Microsoft Visual Studio Version 2017 and lower
#include <algorithm>
#endif

extern "C" {
#include "Lua/lua.h"
}
Expand Down
4 changes: 4 additions & 0 deletions Orbitersdk/include/VesselAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
#ifndef __VESSELAPI_H
#define __VESSELAPI_H

#if defined(_MSC_VER) && (_MSC_VER < 1920 ) // Microsoft Visual Studio Version 2017 and lower
#include <algorithm>
#endif

// reference frame flags
#define FRAME_ECL 0
#define FRAME_EQU 1
Expand Down
2 changes: 1 addition & 1 deletion Src/Celbody/Moon/Config/Moon.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ SidRotPeriod = 2360588.15
; === Visualisation Parameters ===
TileFormat = 2
LabelFormat = 2
MaxPatchResolution = 16 ; highest sphere patch level
MaxPatchResolution = 20 ; highest sphere patch level
ElevationResolution = 0.5 ; target resolution of elevation data [m]
HorizonExcess = 0.015 ; prevent mountain tops beyond sphere horizon from disappearing
MaxElevation = 10800
Expand Down
2 changes: 1 addition & 1 deletion Src/Celbody/Vsop87/Earth/Config/Earth.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ CloudMicrotextureAlt = 35e3 300e3
TileFormat = 2
CloudFormat = 2
LabelFormat = 2
MaxPatchResolution = 19 ; surface texture resolution limit (1-19)
MaxPatchResolution = 21 ; surface texture resolution limit (1-19)
MinCloudResolution = 1 ; cloud layer from this resolution
MaxCloudResolution = 9 ; highest cloud resolution level
ElevationResolution = 0.5 ; target resolution of elevation data [m]
Expand Down
2 changes: 1 addition & 1 deletion Src/Celbody/Vsop87/Mars/Config/Mars.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ AtmFogColor = 0.5 0.40 0.3
TileFormat = 2
LabelFormat = 2
AlbedoRGB = 0.52 0.36 0.16
MaxPatchResolution = 16 ; highest sphere patch level
MaxPatchResolution = 20 ; highest sphere patch level
ElevationResolution = 1
HorizonExcess = 0.035 ; prevent mountain tops beyond sphere horizon from disappearing
MinElevation = -8300 ; min surface elevation relative to mean radius
Expand Down
2 changes: 1 addition & 1 deletion Src/Orbiter/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#define PROP_SY8 9

#define SURF_MAX_PATCHLEVEL 14
#define SURF_MAX_PATCHLEVEL2 19
#define SURF_MAX_PATCHLEVEL2 21

class Mesh;
class PlanetarySystem;
Expand Down
2 changes: 1 addition & 1 deletion Src/Orbiter/Orbiter.rc
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ BEGIN
EDITTEXT IDC_OPT_VIS_LTLEVEL,132,55,46,14,ES_AUTOHSCROLL
CONTROL "Surface elevation, using",IDC_OPT_VIS_ELEV,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,74,92,10
COMBOBOX IDC_OPT_VIS_ELEVMODE,132,73,76,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
LTEXT "Max. resolution level (1-19)",IDC_STATIC,12,92,85,8
LTEXT "Max. resolution level (1-21)",IDC_STATIC,12,92,85,8
EDITTEXT IDC_OPT_VIS_MAXLEVEL,132,90,46,14,ES_AUTOHSCROLL
GROUPBOX "General effects",IDC_STATIC,6,117,208,73
CONTROL "Vessel shadows",IDC_OPT_VIS_VSHADOW,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,130,67,10
Expand Down
2 changes: 1 addition & 1 deletion Src/Orbiter/elevmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ using std::max;

static int elev_grid = 256;
static int elev_stride = elev_grid+3;
static int MAXLVL_LIMIT = 11;
static int MAXLVL_LIMIT = SURF_MAX_PATCHLEVEL2 - 7;

extern Orbiter *g_pOrbiter;
extern TimeData td;
Expand Down

0 comments on commit 205f8dd

Please sign in to comment.