<div dir="ltr">Thanks Sebastian!<div><br></div><div>I will write you off-list</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Feb 1, 2017 at 12:36 PM, Sebastian Messerschmidt <span dir="ltr"><<a href="mailto:sebastian.messerschmidt@gmx.de" target="_blank">sebastian.messerschmidt@gmx.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Trajce,<br>
<br>
based on Euler with optional smoothing (to avoid jaggy movement), this algorithm will adapt a local pose conserving heading. The smoothing part is mainly to get a smooth transition between adjacend terrain normals. Sorry for the cluttered code.<br>
<br>
<code><br>
        IN:     gmtl::Vec3d local_normal; gmtl::EulerAngleXZYd  orientation;<br>
                        <br>
<br>
        //extract heading<br>
        const gmtl::Quatd quat  = gmtl::make<gmtl::Quatd>(orient<wbr>ation);<br>
                <br>
        gmtl::Vec3d heading = gmtl::xform(heading, quat, gmtl::Vec3d(0.0,1.0,0.0));<br>
        //project heading to plane and normalize<br>
        heading = gmtl::makeNormal(gmtl::Vec3d(h<wbr>eading[0], heading[1], 0.0));<br>
        // get a vector perpendicular to projected heading and the normal<br>
        const gmtl::Vec3d perpendicular = gmtl::makeCross(local_normal, heading);<br>
        const gmtl::Vec3d perpendicular_2 = gmtl::makeCross(perpendicular, local_normal);<br>
        // construct a new orientation leaving the heading untouched<br>
        orientation = gmtl::EulerAngleZXYd      (<br>
                                                                                orientation[0]<br>
                                                                                ,gmtl::Math::aSin(perpendicula<wbr>r_2[2])<br>
                                                                                ,gmtl::Math::aTan2(perpendicul<wbr>ar[2], local_normal[2])<br>
                                                                                );<br>
        if (smooth_factor < 1.0)<br>
        {<br>
                gmtl::Quatd target_quat = gmtl::makeRot<gmtl::Quatd>(ori<wbr>entation);<br>
                target_quat = gmtl::slerp(target_quat, smooth_factor, quat, target_quat);<br>
                orientation = gmtl::makeRot<gmtl::EulerAngle<wbr>ZXYd>(gmtl::makeRot<gmtl::<wbr>Matrix44d>(target_quat));<br>
        }<br>
</code><br>
<br>
Cheers<br>
Sebastian<br>
<br>
P.S. If you got further questions, simply drop me a private message/email.<span class=""><br>
<br>
<br>
<br>
<br>
Am 2/1/2017 um 11:27 AM schrieb Trajce Nikolov NICK:<br>
</span><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">
Hi Sebastian,<br>
<br>
the code will be welcome. I was expecting that the proper way is to go<br>
through Eulers<br>
<br>
Thanks a lot!<br>
<br>
<br>
On Wed, Feb 1, 2017 at 9:48 AM, Sebastian Messerschmidt<br></span>
<<a href="mailto:sebastian.messerschmidt@gmx.de" target="_blank">sebastian.messerschmidt@gmx.d<wbr>e</a> <mailto:<a href="mailto:sebastian.messerschmidt@gmx.de" target="_blank">sebastian.messerschmid<wbr>t@gmx.de</a>>><div><div class="h5"><br>
wrote:<br>
<br>
    Hi Trajce,<br>
<br>
    Did I miss the question :-) If it is working: fine. :-)<br>
<br>
    In general you are extracting the heading I guess (with the<br>
    modelOrientation) and put it on top the tilted normal, which will<br>
    put you on in this pose. The problem might be, that you introduce<br>
    unwanted roll with this. I can give you some code (not based on OSG,<br>
    but you'll get the idea) adapting a EulerAngle pose to a terrain<br>
    normal using a local tangent plane.<br>
<br>
    Cheers<br>
    Sebastian<br>
<br>
<br>
<br>
<br>
        Hi community,<br>
<br>
        this is sort of easy math question (btw, I missed that part in my<br>
        classes ;-) ) I want to check it with you.<br>
<br>
        It is about node following terrain. my node is MatrixTransform and I<br>
        have to set it in world coordinates. The node has it's own<br>
        rotation and<br>
        I just need to take the terrain normal into account. Here is the<br>
        pseudocode that produces some acceptable results (not sure if<br>
        they are<br>
        correct though, thus asking you for hints)<br>
<br>
        Vec3 terrainNormal;<br>
<br>
        Quat terrainOrientation;<br>
        terrainOrientation.makeRotate(<wbr>Vec3(0,0,1), terrainNormal);<br>
<br>
        Quat modelOrientation;<br>
        modelOrientation.makeRotate(Ve<wbr>c3(0,1,0), whatever);<br>
<br>
        Quat q;<br>
        q = terrainOrientation * modelOrientation; // not sure about this<br>
<br>
        MatrixTransform mxt = ...<br>
        mxt->setMatrix(Matrixd:;rotate<wbr>(q) * ...);<br>
<br>
        Any hints?<br>
<br>
        Thanks a bunch as always!<br>
        Nick<br>
<br>
<br>
        --<br>
        trajce nikolov nick<br>
<br>
<br>
        ______________________________<wbr>_________________<br>
        osg-users mailing list<br>
        <a href="mailto:osg-users@lists.openscenegraph.org" target="_blank">osg-users@lists.openscenegraph<wbr>.org</a><br></div></div>
        <mailto:<a href="mailto:osg-users@lists.openscenegraph.org" target="_blank">osg-users@lists.opensc<wbr>enegraph.org</a>><br>
        <a href="http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org" rel="noreferrer" target="_blank">http://lists.openscenegraph.or<wbr>g/listinfo.cgi/osg-users-opens<wbr>cenegraph.org</a><span class=""><br>
        <<a href="http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org" rel="noreferrer" target="_blank">http://lists.openscenegraph.o<wbr>rg/listinfo.cgi/osg-users-open<wbr>scenegraph.org</a>><br>
<br>
    ______________________________<wbr>_________________<br>
    osg-users mailing list<br>
    <a href="mailto:osg-users@lists.openscenegraph.org" target="_blank">osg-users@lists.openscenegraph<wbr>.org</a><br></span>
    <mailto:<a href="mailto:osg-users@lists.openscenegraph.org" target="_blank">osg-users@lists.opensc<wbr>enegraph.org</a>><br>
    <a href="http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org" rel="noreferrer" target="_blank">http://lists.openscenegraph.or<wbr>g/listinfo.cgi/osg-users-opens<wbr>cenegraph.org</a><span class=""><br>
    <<a href="http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org" rel="noreferrer" target="_blank">http://lists.openscenegraph.o<wbr>rg/listinfo.cgi/osg-users-open<wbr>scenegraph.org</a>><br>
<br>
<br>
<br>
<br>
--<br>
trajce nikolov nick<br>
<br>
<br>
______________________________<wbr>_________________<br>
osg-users mailing list<br>
<a href="mailto:osg-users@lists.openscenegraph.org" target="_blank">osg-users@lists.openscenegraph<wbr>.org</a><br>
<a href="http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org" rel="noreferrer" target="_blank">http://lists.openscenegraph.or<wbr>g/listinfo.cgi/osg-users-opens<wbr>cenegraph.org</a><br>
<br>
</span></blockquote><div class="HOEnZb"><div class="h5">
______________________________<wbr>_________________<br>
osg-users mailing list<br>
<a href="mailto:osg-users@lists.openscenegraph.org" target="_blank">osg-users@lists.openscenegraph<wbr>.org</a><br>
<a href="http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org" rel="noreferrer" target="_blank">http://lists.openscenegraph.or<wbr>g/listinfo.cgi/osg-users-opens<wbr>cenegraph.org</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">trajce nikolov nick<br></div>
</div>