Skip to content

Commit

Permalink
ImGui updates, fix the Camera panel load/save, fix dirtySettings
Browse files Browse the repository at this point in the history
  • Loading branch information
gwaldron committed Oct 1, 2024
1 parent 75c86e2 commit 3132735
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 104 deletions.
46 changes: 14 additions & 32 deletions src/osgEarth/EarthManipulator
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
#ifndef OSGEARTHUTIL_EARTHMANIPULATOR
#define OSGEARTHUTIL_EARTHMANIPULATOR
#pragma once

#include <osgEarth/Common>
#include <osgEarth/Common>
Expand Down Expand Up @@ -330,14 +329,12 @@ namespace osgEarth { namespace Util
int modkey_mask =0L,
const ActionOptions& options =ActionOptions() );


void bindPinch(
ActionType action, const ActionOptions& =ActionOptions() );

void bindTwist(
ActionType action, const ActionOptions& =ActionOptions() );


void bindMultiDrag(
ActionType action, const ActionOptions& =ActionOptions() );

Expand All @@ -352,11 +349,8 @@ namespace osgEarth { namespace Util
* 1.0 = default; < 1.0 = less sensitive; > 1.0 = more sensitive.
*/
void setMouseSensitivity( double value ) { _mouse_sens = value; }

/**
* Gets the overall mouse sensitivity scale factor. Default = 1.0.
*/
double getMouseSensitivity() const { return _mouse_sens; }
double& mouseSensitivity() { return _mouse_sens; }

/**
* Sets an overall touch sensitivity factor.
Expand All @@ -366,11 +360,8 @@ namespace osgEarth { namespace Util
* 0.005 = default; < 0.005 = less sensitive; > 0.005 = more sensitive.
*/
void setTouchSensitivity( double value ) { _touch_sens = value; }

/**
* Gets the overall touch sensitivity scale factor. Default = 1.0.
*/
double getTouchSensitivity() const { return _touch_sens; }
double& touchSensitivity() { return _touch_sens; }

/**
* Sets the keyboard action sensitivity factor. This applies to navigation actions
Expand All @@ -383,11 +374,8 @@ namespace osgEarth { namespace Util
* 1.0 = default; < 1.0 = less sensitive; > 1.0 = more sensitive.
*/
void setKeyboardSensitivity( double value ) { _keyboard_sens = value; }

/**
* Gets the keyboard action sensitivity scale factor. Default = 1.0.
*/
double getKeyboardSensitivity() const { return _keyboard_sens; }
double& keyboardSensitivity() { return _keyboard_sens; }

/**
* Sets the scroll-wheel sensitivity factor. This applies to navigation actions
Expand All @@ -400,11 +388,8 @@ namespace osgEarth { namespace Util
* 1.0 = default; < 1.0 = less sensitive; > 1.0 = more sensitive.
*/
void setScrollSensitivity( double value ) { _scroll_sens = value; }

/**
* Gets the scroll wheel sensetivity scale factor. Default = 1.0.
*/
double getScrollSensitivity() const { return _scroll_sens; }
double& scrollSensitivity() { return _scroll_sens; }

/**
* When set to true, prevents simultaneous control of pitch and azimuth.
Expand All @@ -416,24 +401,16 @@ namespace osgEarth { namespace Util
* Default = false.
*/
void setSingleAxisRotation( bool value ) { _single_axis_rotation = value; }

/**
* Gets whether simultaneous control over pitch and azimuth is disabled.
* Default = false.
*/
bool getSingleAxisRotation() const { return _single_axis_rotation; }
bool& singleAxisRotation() { return _single_axis_rotation; }

/**
* Sets whether to lock in a camera heading when performing panning operations (i.e.,
* changing the focal point).
*/
void setLockAzimuthWhilePanning( bool value ) { _lock_azim_while_panning = value; }

/**
* Gets true if the manipulator should lock in a camera heading when performing panning
* operations (i.e. changing the focal point.)
*/
bool getLockAzimuthWhilePanning() const { return _lock_azim_while_panning; }
bool& lockAzimuthWhilePanning() { return _lock_azim_while_panning; }

/**
* Sets the minimum and maximum allowable local camera pitch, in degrees.
Expand Down Expand Up @@ -474,6 +451,7 @@ namespace osgEarth { namespace Util
/** Mode used for tethering to a node. */
void setTetherMode( TetherMode value ) { _tether_mode = value; }
TetherMode getTetherMode() const { return _tether_mode; }
TetherMode& tetherMode() { return _tether_mode; }

/** Access to the list of Actions that will automatically break a tether */
ActionTypeVector& getBreakTetherActions() { return _breakTetherActions; }
Expand All @@ -496,23 +474,29 @@ namespace osgEarth { namespace Util
/** Whether to automatically adjust an orthographic camera so that it "tracks" the last known FOV and Aspect Ratio. */
bool getOrthoTracksPerspective() const { return _orthoTracksPerspective; }
void setOrthoTracksPerspective(bool value) { _orthoTracksPerspective = value; }
bool& orthoTracksPerspective() { return _orthoTracksPerspective; }

/** Whether or not to keep the camera from going through the terrain surface */
bool getTerrainAvoidanceEnabled() const { return _terrainAvoidanceEnabled; }
void setTerrainAvoidanceEnabled( bool value ) { _terrainAvoidanceEnabled = value; }
bool& terrainAvoidanceEnabled() { return _terrainAvoidanceEnabled; }

/** Minimum range for terrain avoidance checks in world coordinates */
double getTerrainAvoidanceMinimumDistance() const {return _terrainAvoidanceMinDistance; }
void setTerrainAvoidanceMinimumDistance(double minDistance) { _terrainAvoidanceMinDistance = minDistance; }
double& terrainAvoidanceMinimumDistance() { return _terrainAvoidanceMinDistance; }

void setThrowingEnabled(bool throwingEnabled) { _throwingEnabled = throwingEnabled; }
bool getThrowingEnabled () const { return _throwingEnabled; }
bool& throwingEnabled() { return _throwingEnabled; }

void setThrowDecayRate(double throwDecayRate) { _throwDecayRate = osg::clampBetween(throwDecayRate, 0.0, 1.0); }
double getThrowDecayRate () const { return _throwDecayRate; }
double& throwDecayRate() { return _throwDecayRate; }

void setZoomToMouse(bool value) { _zoomToMouse = value; }
bool getZoomToMouse() const { return _zoomToMouse; }
bool& zoomToMouse() { return _zoomToMouse; }

private:

Expand Down Expand Up @@ -1051,5 +1035,3 @@ namespace osgEarth { namespace Util
};

} }

#endif // OSGEARTHUTIL_EARTHMANIPULATOR
9 changes: 9 additions & 0 deletions src/osgEarth/Math
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,15 @@ namespace osgEarth
return seed;
}

// https://github.com/matteo65/mzHash64 (Public Domain)
inline std::size_t hash_string(const std::string& input, std::size_t seed = 0) {
auto hash = seed ^ 0xD45E69F901E72147L;
auto len = input.length();
for(std::size_t i=0; i<len; ++i)
hash = 0x3631754B22FF2D5CL * (i + input[i]) ^ (hash << 2) ^ (hash >> 2);
return hash;
};

/**
* Utilities to manipulate a projection matrix.
* These functions will automatically handle standard OGL versus Reverse-Z
Expand Down
2 changes: 1 addition & 1 deletion src/osgEarth/PagedNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ PagingManager::update()
{
scoped_lock_if lock(_mergeMutex, _threadsafe);
unsigned count = 0u;
while (!_mergeQueue.empty() && count++ < 64u) //_mergesPerFrame)
while (!_mergeQueue.empty() && count++ < _mergesPerFrame)
{
toMerge.emplace_back(_mergeQueue.front());
_mergeQueue.pop();
Expand Down
110 changes: 49 additions & 61 deletions src/osgEarthImGui/CameraGUI
Original file line number Diff line number Diff line change
Expand Up @@ -30,70 +30,66 @@ namespace osgEarth
*/
struct CameraGUI : public ImGuiPanel
{
bool _first;
bool _singleAxisRotation;
bool _lockAzimuthWhilePanning;
bool _arcViewpointTransitions;
bool _terrainAvoidanceEnabled;
bool _throwing;
float _throwDecayRate;
bool _zoomToMouse;
double _vfov, _ar, _zn, _zf;
EarthManipulator::Settings* _settings = nullptr;
Config _loadConf;

CameraGUI() :
ImGuiPanel("Camera"),
_first(true),
_vfov(30), _ar(1), _zn(1), _zf(100)
{
EarthManipulator::Settings d;
_singleAxisRotation = d.getSingleAxisRotation();
_lockAzimuthWhilePanning = d.getLockAzimuthWhilePanning();
_arcViewpointTransitions = d.getArcViewpointTransitions();
_terrainAvoidanceEnabled = d.getTerrainAvoidanceEnabled();
_throwing = d.getThrowingEnabled();
_throwDecayRate = d.getThrowDecayRate();
_zoomToMouse = d.getZoomToMouse();
//nop
}

void load(const Config& conf) override
{
conf.get("SingleAxisRotation", _singleAxisRotation);
conf.get("LockAzimuthWhilePanning", _lockAzimuthWhilePanning);
conf.get("ArcViewpointTransitions", _arcViewpointTransitions);
conf.get("TerrainAvoidance", _terrainAvoidanceEnabled);
conf.get("Throwing", _throwing);
conf.get("ThrowingDecay", _throwDecayRate);
conf.get("ZoomToMouse", _zoomToMouse);
// remember, the settings come in one at a time so we have to use merge
_loadConf.merge(conf);
}

void save(Config& conf) override
{
conf.set("SingleAxisRotation", _singleAxisRotation);
conf.set("LockAzimuthWhilePanning", _lockAzimuthWhilePanning);
conf.set("ArcViewpointTransitions", _arcViewpointTransitions);
conf.set("TerrainAvoidance", _terrainAvoidanceEnabled);
conf.set("Throwing", _throwing);
conf.set("ThrowingDecay", _throwDecayRate);
conf.set("ZoomToMouse", _zoomToMouse);
if (_settings)
{
conf.set("SingleAxisRotation", _settings->singleAxisRotation());
conf.set("LockAzimuthWhilePanning", _settings->lockAzimuthWhilePanning());
conf.set("TerrainAvoidance", _settings->terrainAvoidanceEnabled());
conf.set("Throwing", _settings->throwingEnabled());
conf.set("ThrowingDecay", _settings->throwDecayRate());
conf.set("ZoomToMouse", _settings->zoomToMouse());
}
}

void draw(osg::RenderInfo& ri)
{
if (!isVisible())
return;

EarthManipulator* man = dynamic_cast<EarthManipulator*>(view(ri)->getCameraManipulator());

EarthManipulator::Settings* s = nullptr;

auto* man = dynamic_cast<EarthManipulator*>(view(ri)->getCameraManipulator());
if (man)
s = man->getSettings();
{
_settings = man->getSettings();
if (_settings && !_loadConf.empty())
{
_loadConf.get("SingleAxisRotation", _settings->singleAxisRotation());
_loadConf.get("LockAzimuthWhilePanning", _settings->lockAzimuthWhilePanning());
_loadConf.get("TerrainAvoidance", _settings->terrainAvoidanceEnabled());
_loadConf.get("Throwing", _settings->throwingEnabled());
_loadConf.get("ThrowingDecay", _settings->throwDecayRate());
_loadConf.get("ZoomToMouse", _settings->zoomToMouse());
_loadConf = {};
}
}

ImGui::Begin(name(), visible());
if (!_settings)
{
//if (ImGui::Checkbox("Single axis continuous rotation", &_singleAxisRotation) || _first)
// s->setSingleAxisRotation(_singleAxisRotation), dirtySettings();
ImGui::TextColored(ImVec4(1, 0, 0, 1), "No earth manipulator");
ImGui::End();
return;
}

ImGui::Begin(name(), visible());
{
if (ImGuiLTable::Begin("CameraGUI"))
{
osg::Matrix pm = camera(ri)->getProjectionMatrix();
Expand All @@ -110,27 +106,24 @@ namespace osgEarth
camera(ri)->setProjectionMatrix(pm);
}

if (s)
if (_settings)
{
if (ImGuiLTable::Checkbox("Lock azimuth", &_lockAzimuthWhilePanning) || _first)
s->setLockAzimuthWhilePanning(_lockAzimuthWhilePanning), dirtySettings();

if (ImGuiLTable::Checkbox("Arc transitions", &_arcViewpointTransitions) || _first)
s->setArcViewpointTransitions(_arcViewpointTransitions), dirtySettings();
if (ImGuiLTable::Checkbox("Lock azimuth", &_settings->lockAzimuthWhilePanning()))
dirtySettings();

if (ImGuiLTable::Checkbox("Avoid terrain", &_terrainAvoidanceEnabled) || _first)
s->setTerrainAvoidanceEnabled(_terrainAvoidanceEnabled), dirtySettings();
if (ImGuiLTable::Checkbox("Avoid terrain", &_settings->terrainAvoidanceEnabled()))
dirtySettings();

if (ImGuiLTable::Checkbox("Zoom to mouse", &_zoomToMouse) || _first)
s->setZoomToMouse(_zoomToMouse), dirtySettings();
if (ImGuiLTable::Checkbox("Zoom to mouse", &_settings->zoomToMouse()))
dirtySettings();

if (ImGuiLTable::Checkbox("Throwing", &_throwing) || _first)
s->setThrowingEnabled(_throwing), dirtySettings();
if (ImGuiLTable::Checkbox("Throwing", &_settings->throwingEnabled()))
dirtySettings();

if (_throwing || _first)
if (_settings->getThrowingEnabled())
{
if (ImGuiLTable::SliderFloat("Decay", &_throwDecayRate, 0.02f, 0.3f) || _first)
s->setThrowDecayRate(_throwDecayRate), dirtySettings();
if (ImGuiLTable::SliderDouble("Decay", &_settings->throwDecayRate(), 0.0f, 0.3f))
dirtySettings();
}
}

Expand All @@ -154,9 +147,7 @@ namespace osgEarth
double vfov, ar, n, f;
ProjectionMatrix::getPerspective(ref_proj, vfov, ar, n, f);
ProjectionMatrix::setPerspective(new_proj, vfov * rangeScale, ar, n, f);

if (s)
s->setOrthoTracksPerspective(true);
_settings->setOrthoTracksPerspective(true);
}
else
{
Expand All @@ -170,9 +161,7 @@ namespace osgEarth
H = (R - L) * rangeScale / 2;
L = M - H, R = M + H;
ProjectionMatrix::setOrtho(new_proj, L, R, B, T, N, F);

if (s)
s->setOrthoTracksPerspective(false);
_settings->setOrthoTracksPerspective(false);
}

camera(ri)->setProjectionMatrix(new_proj);
Expand Down Expand Up @@ -216,7 +205,6 @@ namespace osgEarth
}
}

_first = false;
ImGui::End();
}
};
Expand Down
7 changes: 7 additions & 0 deletions src/osgEarthImGui/ImGuiEventHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@

using namespace osgEarth;

#include "ImGuiPanel"
void ImGuiPanel::dirtySettings()
{
if (ImGui::GetCurrentContext())
ImGui::MarkIniSettingsDirty();
}

namespace
{
struct PreDrawOp : public osg::Camera::DrawCallback
Expand Down
8 changes: 4 additions & 4 deletions src/osgEarthImGui/ImGuiPanel
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,10 @@ namespace osgEarth
save(conf);
}

void dirtySettings()
{
// nop - settings save automatically
}
static void dirtySettings();
//{
// // nop - settings save automatically
//}

//! whether the visibility changed (and resets the flag)
bool visibilityChanged() {
Expand Down
2 changes: 2 additions & 0 deletions src/osgEarthImGui/SystemGUI
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ namespace osgEarth
if (ImGuiLTable::SliderFloat("Font Scale", &ImGui::GetIO().FontGlobalScale, 0.5f, 2.0f))
dirtySettings();

//ImGuiLTable::Text("Dirty timer", "%.1f", ImGui::GetCurrentContext()->SettingsDirtyTimer); // ::GetIO().IniSavingRate);

ImGuiLTable::End();
}

Expand Down
Loading

0 comments on commit 3132735

Please sign in to comment.