gwaldron / osgearth

3D Maps for OpenSceneGraph / C++14
https://www.pelicanmapping.com/home-1/opensource
Other
1.48k stars 774 forks source link

Tethering: How to level out the camera after breaking a tether #2381

Closed gwaldron closed 9 months ago

gwaldron commented 10 months ago

Discussed in https://github.com/gwaldron/osgearth/discussions/2380

Originally posted by **elbarto1980** November 15, 2023 Hi, I have a question about how to restore the correct behavior of the EarthManipulator after having tethered it to a node, using the TETHER_CENTER_AND_ROTATION mode. When I break the tether using the clearViewpoint() method, the camera is left in a weird state and it is not controllable. To restore its correct behavior, I have to change the tether mode to TETHER_CENTER, wait for the camera to be "realigned" and only then I can break the tether. I saw in the the EarthManipulator.cpp file that it does that [here](https://github.com/gwaldron/osgearth/blob/2b61f0e530e0bab78ec4d631c08b0cbd5bc1ec46/src/osgEarth/EarthManipulator.cpp#L2004C20-L2004C20), but I can't figure out how to do that in my code, outside the EarthManipulator class. You can reproduce the issue using the osgeart_manip demo application if you break the tether when the TETHER_CENTER_AND_ROTATION mode is active. What is the best way to restore the manipulator when this happens? Thank you for your help! P.S.: These are my caps... ``` [osgEarth] [Registry] Note: GDAL_DATA environment variable is not set [osgEarth] [Capabilities] Capabilities: [osgEarth] [Capabilities] osgEarth Version: 3.2.0 build 113 [osgEarth] [Capabilities] OSG Version: 3.6.5 [osgEarth] [Capabilities] GDAL Version: 3.0.4 [osgEarth] [Capabilities] GEOS Version: 3.8.0 [osgEarth] [Capabilities] GPU Vendor: NVIDIA Corporation [osgEarth] [Capabilities] GPU Renderer: NVIDIA GeForce RTX 3070 Laptop GPU/PCIe/SSE2 [osgEarth] [Capabilities] GL/Driver Version: 4.6.0 NVIDIA 535.129.03 [osgEarth] [Capabilities] GL Core Profile: no ```
gwaldron commented 10 months ago

Note: This should be a simple matter of applying the "tether break realignment" code as necessary when setViewpoint happens

gwaldron commented 10 months ago

Pushed a patch for this to 79172142e, please test and report back.

elbarto1980 commented 10 months ago

Hi, I am sorry but cannot test it right away because, unfortunately, the latest release that gets along with my code is the osgearth-3.2. Now, I am trying to fix all the build errors... I will let you know asap. Thank you!

elbarto1980 commented 10 months ago

By commenting out here and there, I was finally able to build my code and I can confirm that the patch works flawlessly. Thanks! :+1:

I have a few side effects now (not caused by the patch, of course) because my linux application wasn't ready to move from GL2 to GL3 yet. For example, GL3 gave my models a new fresh coat of radioactive green paint... but I will figure it out eventually (any suggestions are very welcome 😄) GL_Comparison

gwaldron commented 10 months ago

Try running the shader generator on your model.

osgEarth::ShaderGenerator gen;
gen.run(node);
elbarto1980 commented 10 months ago

I did, those lines were already there from a previous attempt to upgrade osgearth. Here's how I load a model:

void DifferentialUGV::loadModel() {
    QDir localPath(QCoreApplication::applicationDirPath());
    localPath.cd("../res");
    auto resPath = localPath.absolutePath().toStdString();

    osg::ref_ptr<osg::Node> body = osgDB::readRefNodeFile(resPath + "/OsgModels/CombatVehicle/CombatVehicle.osgt.osgearth_shadergen");

    ugvGroup = new osg::Group();
    ugvGroup->setName("Differential UGV Group");
    ugvGroup->addChild(body);

    osgUtil::Optimizer opt;
    opt.optimize(ugvGroup, osgUtil::Optimizer::INDEX_MESH);
    osgEarth::ShaderGenerator gen;
    gen.run(ugvGroup);

    if (pat.valid()) {
        pat->addChild(ugvGroup);
    }

    if (root.valid()) {
        optimizer.optimize(root);
    }
}

I noticed that, at a specific yaw angle, the model becomes white and then it turns green again.

I have the same behavior if I load the cessna model from OpenSceneGraph-Data. On the contrary the cow.osgt file is rendered correctly, but it keeps printing the following warning messages:

Warning: detected OpenGL error 'invalid enumerant' at after RenderBin::draw(..)
Warning: TexGen::apply(State&) - not supported.
Warning: TexGen::apply(State&) - not supported.

Thank you! (I do not want to go off topic here... we can move to another discussion if you want)

elbarto1980 commented 9 months ago

@gwaldron, I moved the last comment to Support Q&A #2389, so you could close this issue. Thank you again for your support!