Triton: movement of the model due to the wave

classic Classic list List threaded Threaded
2 messages Options
marcoma9023 marcoma9023
Reply | Threaded
Open this post in threaded view
|

Triton: movement of the model due to the wave

Hi,

as wrote in the subject, the topic of this thread is Triton and in particular as move the model using the library.

Then, in the following code I wrote and described how it can be, then at the end, the problem thta I need to solve:

1) first of all, I startup the Triton environment:
osg::ref_ptr<osgEarth::Triton::TritonLayer> UpdateTargetMapNodeCallback::getTritonLayer() {
        osgEarth::Triton::TritonOptions tritonOptions;
        tritonOptions.user() = "my_user_name";
        tritonOptions.licenseCode() = "my_license_code";
        tritonOptions.maxAltitude() = 100000;
        tritonOptions.useHeightMap() = true;

        osg::ref_ptr<Triton::TritonIntersections> _isect = new Triton::TritonIntersections();

        TritonSettings tritonSettings;
        osg::ref_ptr<TritonCallback> tritonCallback = new TritonCallback(tritonSettings, _isect);

        osg::ref_ptr<osgEarth::Triton::TritonLayer> tritonLayer = new osgEarth::Triton::TritonLayer(tritonOptions, tritonCallback);
        tritonLayer->setName("triton");
        tritonLayer->addIntersections(_isect.get());

        return tritonLayer;
}

Then, in the following method I bound the "selected target" to the Triton Intersector:

void addBouncySelectedTarget(osg::ref_ptr<Map> map, osg::ref_ptr<Triton::TritonIntersections> isect, SystemTarget::Target* currentSelectedTarget) {
        if (currentSelectedTarget != nullptr) {
                osg::ref_ptr <SpatialReference> wgs84 = SpatialReference::get("wgs84");
       
                osgEarth::GeoPoint geo(wgs84, currentSelectedTarget->getLongitude(), currentSelectedTarget->getLatitude(), AltitudeMode::ALTMODE_RELATIVE);

                isect->setAnchor(geo);

                isect->addLocalPoint(osg::Vec3d(0, 0, 0));
        }
}

Where (if I undestand well) with

- isect->setAnchor(geo): I can define what is the position in which the Intersector must work

- isect->addLocalPoint(osg::Vec3d(0, 0, 0)): define the area for the intersection set, then in my case, correspond to the center of the model with coordinate "geo".

In the last method:

void updateTargetSelectedBuoyancy(osg::ref_ptr<Triton::TritonIntersections> isect, SystemTarget::Target* currentSelectedTarget)
{

        for (unsigned i = 0; i < isect->getHeights().size(); ++i)
        {
                //osg::Vec3d local = isect->getInput()[i];
                //local.z() = isect->getHeights()[i];

                osg::Quat q;
                q.makeRotate(osg::Vec3d(0, 0, 1), isect->getNormals()[i]);

                if (currentSelectedTarget!=nullptr) {
                       
                        osg::Quat headingQuat = currentSelectedTarget->getHeadingQuat();

                        currentSelectedTarget->getAttitude()->setAttitude(headingQuat*q);
                }
        }
}

Each frame, I can assign to the PositionAttitudeTransform of the model the Quat calculated by Triton.


OK, now the problem:
I set the sea state = 0 or 1 or 2, then correspond to calm.

I have models with different size, but the TritonIntersector point always to the center of the model.

The model is subject to the movement of the wave, but even in the case of calm sea, this effect is too high.
Effect that certainly depends on the fact that the position that I pass is the center of the model and also depends on its length, in fact it decreases in the case of short models and vice versa.

How can I improve the code?
Do you have any advice?
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: Triton: movement of the model due to the wave

Perhaps you need to sample more than one point on the hull. For example, sample a triangle of 3 points, and use the normal to that plane as your ship's up vector? The points don't even need to actually be on the ship itself. Just an idea.
Glenn Waldron / Pelican Mapping