OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

combining Quats


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
Trajce Nikolov NICK
Guest





PostPosted: Wed Feb 01, 2017 8:17 am    Post subject:
combining Quats
Reply with quote

Hi community,

this is sort of easy math question (btw, I missed that part in my classes Wink ) I want to check it with you.


It is about node following terrain. my node is MatrixTransform and I have to set it in world coordinates. The node has it's own rotation and I just need to take the terrain normal into account. Here is the pseudocode that produces some acceptable results (not sure if they are correct though, thus asking you for hints)


Vec3 terrainNormal;


Quat terrainOrientation;
terrainOrientation.makeRotate(Vec3(0,0,1), terrainNormal);


Quat modelOrientation;
modelOrientation.makeRotate(Vec3(0,1,0), whatever);



Quat q;
q = terrainOrientation * modelOrientation; // not sure about this


MatrixTransform mxt = ...
mxt->setMatrix(Matrixd:;rotate(q) * ...);


Any hints?


Thanks a bunch as always!
Nick


--
trajce nikolov nick

------------------
Post generated by Mail2Forum
Back to top
SMesserschmidt (Sebastian Messerschmidt)
Forum Moderator


Joined: 10 Sep 2013
Posts: 826

PostPosted: Wed Feb 01, 2017 8:50 am    Post subject:
combining Quats
Reply with quote

Hi Trajce,

Did I miss the question Smile If it is working: fine. :-)

In general you are extracting the heading I guess (with the
modelOrientation) and put it on top the tilted normal, which will put
you on in this pose. The problem might be, that you introduce unwanted
roll with this. I can give you some code (not based on OSG, but you'll
get the idea) adapting a EulerAngle pose to a terrain normal using a
local tangent plane.

Cheers
Sebastian




Quote:
Hi community,

this is sort of easy math question (btw, I missed that part in my
classes Wink ) I want to check it with you.

It is about node following terrain. my node is MatrixTransform and I
have to set it in world coordinates. The node has it's own rotation and
I just need to take the terrain normal into account. Here is the
pseudocode that produces some acceptable results (not sure if they are
correct though, thus asking you for hints)

Vec3 terrainNormal;

Quat terrainOrientation;
terrainOrientation.makeRotate(Vec3(0,0,1), terrainNormal);

Quat modelOrientation;
modelOrientation.makeRotate(Vec3(0,1,0), whatever);

Quat q;
q = terrainOrientation * modelOrientation; // not sure about this

MatrixTransform mxt = ...
mxt->setMatrix(Matrixd:;rotate(q) * ...);

Any hints?

Thanks a bunch as always!
Nick


--
trajce nikolov nick






------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
Trajce Nikolov NICK
Guest





PostPosted: Wed Feb 01, 2017 10:28 am    Post subject:
combining Quats
Reply with quote

Hi Sebastian,

the code will be welcome. I was expecting that the proper way is to go through Eulers


Thanks a lot!




On Wed, Feb 1, 2017 at 9:48 AM, Sebastian Messerschmidt < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:
Quote:
Hi Trajce,

Did I miss the question Smile If it is working: fine. Smile

In general you are extracting the heading I guess (with the modelOrientation) and put it on top the tilted normal, which will put you on in this pose. The problem might be, that you introduce unwanted roll with this. I can give you some code (not based on OSG, but you'll get the idea) adapting a EulerAngle pose to a terrain normal using a local tangent plane.

Cheers
Sebastian




Quote:
Hi community,

this is sort of easy math question (btw, I missed that part in my
classes Wink ) I want to check it with you.

It is about node following terrain. my node is MatrixTransform and I
have to set it in world coordinates. The node has it's own rotation and
I just need to take the terrain normal into account. Here is the
pseudocode that produces some acceptable results (not sure if they are
correct though, thus asking you for hints)

Vec3 terrainNormal;

Quat terrainOrientation;
terrainOrientation.makeRotate(Vec3(0,0,1), terrainNormal);

Quat modelOrientation;
modelOrientation.makeRotate(Vec3(0,1,0), whatever);

Quat q;
q = terrainOrientation * modelOrientation; // not sure about this

MatrixTransform mxt = ...
mxt->setMatrix(Matrixd:;rotate(q) * ...);

Any hints?

Thanks a bunch as always!
Nick


--
trajce nikolov nick




_______________________________________________
osg-users mailing list
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

_______________________________________________
osg-users mailing list
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org




--
trajce nikolov nick

------------------
Post generated by Mail2Forum
Back to top
SMesserschmidt (Sebastian Messerschmidt)
Forum Moderator


Joined: 10 Sep 2013
Posts: 826

PostPosted: Wed Feb 01, 2017 11:38 am    Post subject:
combining Quats
Reply with quote

Hi Trajce,

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.

<code>
IN: gmtl::Vec3d local_normal; gmtl::EulerAngleXZYd orientation;


//extract heading
const gmtl::Quatd quat = gmtl::make<gmtl::Quatd>(orientation);

gmtl::Vec3d heading = gmtl::xform(heading, quat,
gmtl::Vec3d(0.0,1.0,0.0));
//project heading to plane and normalize
heading = gmtl::makeNormal(gmtl::Vec3d(heading[0], heading[1], 0.0));
// get a vector perpendicular to projected heading and the normal
const gmtl::Vec3d perpendicular = gmtl::makeCross(local_normal, heading);
const gmtl::Vec3d perpendicular_2 = gmtl::makeCross(perpendicular,
local_normal);
// construct a new orientation leaving the heading untouched
orientation = gmtl::EulerAngleZXYd (
orientation[0]
,gmtl::Math::aSin(perpendicular_2[2])
,gmtl::Math::aTan2(perpendicular[2], local_normal[2])
);
if (smooth_factor < 1.0)
{
gmtl::Quatd target_quat = gmtl::makeRot<gmtl::Quatd>(orientation);
target_quat = gmtl::slerp(target_quat, smooth_factor, quat, target_quat);
orientation =
gmtl::makeRot<gmtl::EulerAngleZXYd>(gmtl::makeRot<gmtl::Matrix44d>(target_quat));
}
</code>

Cheers
Sebastian

P.S. If you got further questions, simply drop me a private message/email.




Am 2/1/2017 um 11:27 AM schrieb Trajce Nikolov NICK:
Quote:
Hi Sebastian,

the code will be welcome. I was expecting that the proper way is to go
through Eulers

Thanks a lot!


On Wed, Feb 1, 2017 at 9:48 AM, Sebastian Messerschmidt
< <mailto:>>
wrote:

Hi Trajce,

Did I miss the question Smile If it is working: fine. :-)

In general you are extracting the heading I guess (with the
modelOrientation) and put it on top the tilted normal, which will
put you on in this pose. The problem might be, that you introduce
unwanted roll with this. I can give you some code (not based on OSG,
but you'll get the idea) adapting a EulerAngle pose to a terrain
normal using a local tangent plane.

Cheers
Sebastian




Hi community,

this is sort of easy math question (btw, I missed that part in my
classes Wink ) I want to check it with you.

It is about node following terrain. my node is MatrixTransform and I
have to set it in world coordinates. The node has it's own
rotation and
I just need to take the terrain normal into account. Here is the
pseudocode that produces some acceptable results (not sure if
they are
correct though, thus asking you for hints)

Vec3 terrainNormal;

Quat terrainOrientation;
terrainOrientation.makeRotate(Vec3(0,0,1), terrainNormal);

Quat modelOrientation;
modelOrientation.makeRotate(Vec3(0,1,0), whatever);

Quat q;
q = terrainOrientation * modelOrientation; // not sure about this

MatrixTransform mxt = ...
mxt->setMatrix(Matrixd:;rotate(q) * ...);

Any hints?

Thanks a bunch as always!
Nick


--
trajce nikolov nick


_______________________________________________
osg-users mailing list

<mailto:>
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
<http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org>

_______________________________________________
osg-users mailing list

<mailto:>
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
<http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org>




--
trajce nikolov nick






------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
Trajce Nikolov NICK
Guest





PostPosted: Wed Feb 01, 2017 11:45 am    Post subject:
combining Quats
Reply with quote

Thanks Sebastian!

I will write you off-list


On Wed, Feb 1, 2017 at 12:36 PM, Sebastian Messerschmidt < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:
Quote:
Hi Trajce,

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.

<code>
        IN:     gmtl::Vec3d local_normal; gmtl::EulerAngleXZYd  orientation;
                       

        //extract heading
        const gmtl::Quatd quat  = gmtl::make<gmtl::Quatd>(orientation);
               
        gmtl::Vec3d heading = gmtl::xform(heading, quat, gmtl::Vec3d(0.0,1.0,0.0));
        //project heading to plane and normalize
        heading = gmtl::makeNormal(gmtl::Vec3d(heading[0], heading[1], 0.0));
        // get a vector perpendicular to projected heading and the normal
        const gmtl::Vec3d perpendicular = gmtl::makeCross(local_normal, heading);
        const gmtl::Vec3d perpendicular_2 = gmtl::makeCross(perpendicular, local_normal);
        // construct a new orientation leaving the heading untouched
        orientation = gmtl::EulerAngleZXYd      (
                                                                                orientation[0]
                                                                                ,gmtl::Math::aSin(perpendicular_2[2])
                                                                                ,gmtl::Math::aTan2(perpendicular[2], local_normal[2])
                                                                                );
        if (smooth_factor < 1.0)
        {
                gmtl::Quatd target_quat = gmtl::makeRot<gmtl::Quatd>(orientation);
                target_quat = gmtl::slerp(target_quat, smooth_factor, quat, target_quat);
                orientation = gmtl::makeRot<gmtl::EulerAngleZXYd>(gmtl::makeRot<gmtl::Matrix44d>(target_quat));
        }
</code>

Cheers
Sebastian

P.S. If you got further questions, simply drop me a private message/email.




Am 2/1/2017 um 11:27 AM schrieb Trajce Nikolov NICK:
Quote:
Hi Sebastian,

the code will be welcome. I was expecting that the proper way is to go
through Eulers

Thanks a lot!


On Wed, Feb 1, 2017 at 9:48 AM, Sebastian Messerschmidt
< (
Only registered users can see emails on this board!
Get registred or enter the forums!
) <mailto: (
Only registered users can see emails on this board!
Get registred or enter the forums!
)>>
wrote:

    Hi Trajce,

    Did I miss the question Smile If it is working: fine. Smile

    In general you are extracting the heading I guess (with the
    modelOrientation) and put it on top the tilted normal, which will
    put you on in this pose. The problem might be, that you introduce
    unwanted roll with this. I can give you some code (not based on OSG,
    but you'll get the idea) adapting a EulerAngle pose to a terrain
    normal using a local tangent plane.

    Cheers
    Sebastian




        Hi community,

        this is sort of easy math question (btw, I missed that part in my
        classes Wink ) I want to check it with you.

        It is about node following terrain. my node is MatrixTransform and I
        have to set it in world coordinates. The node has it's own
        rotation and
        I just need to take the terrain normal into account. Here is the
        pseudocode that produces some acceptable results (not sure if
        they are
        correct though, thus asking you for hints)

        Vec3 terrainNormal;

        Quat terrainOrientation;
        terrainOrientation.makeRotate(Vec3(0,0,1), terrainNormal);

        Quat modelOrientation;
        modelOrientation.makeRotate(Vec3(0,1,0), whatever);

        Quat q;
        q = terrainOrientation * modelOrientation; // not sure about this

        MatrixTransform mxt = ...
        mxt->setMatrix(Matrixd:;rotate(q) * ...);

        Any hints?

        Thanks a bunch as always!
        Nick


        --
        trajce nikolov nick


        _______________________________________________
        osg-users mailing list
        (
Only registered users can see emails on this board!
Get registred or enter the forums!
)


        <mailto: (
Only registered users can see emails on this board!
Get registred or enter the forums!
)>
        http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
        <http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org>

    _______________________________________________
    osg-users mailing list
    (
Only registered users can see emails on this board!
Get registred or enter the forums!
)
    <mailto: (
Only registered users can see emails on this board!
Get registred or enter the forums!
)>
    http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
    <http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org>




--
trajce nikolov nick


_______________________________________________
osg-users mailing list
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

_______________________________________________
osg-users mailing list
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org






--
trajce nikolov nick

------------------
Post generated by Mail2Forum
Back to top
Trajce Nikolov NICK
Guest





PostPosted: Wed Feb 01, 2017 12:30 pm    Post subject:
combining Quats
Reply with quote

Hi again list

Actually the math is present in the osgGA::TerrainManipulator (void TerrainManipulator::clampOrientation()) and it works just great with some mods (the 3D transforms for nodes are bit different then for the View matrix.  I am all set.


Sebastian, thanks a lot !


Cheers,
Nick


On Wed, Feb 1, 2017 at 12:43 PM, Trajce Nikolov NICK < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:
Quote:
Thanks Sebastian!

I will write you off-list


On Wed, Feb 1, 2017 at 12:36 PM, Sebastian Messerschmidt < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:
Quote:
Hi Trajce,

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.

<code>
        IN:     gmtl::Vec3d local_normal; gmtl::EulerAngleXZYd  orientation;
                       

        //extract heading
        const gmtl::Quatd quat  = gmtl::make<gmtl::Quatd>(orientation);
               
        gmtl::Vec3d heading = gmtl::xform(heading, quat, gmtl::Vec3d(0.0,1.0,0.0));
        //project heading to plane and normalize
        heading = gmtl::makeNormal(gmtl::Vec3d(heading[0], heading[1], 0.0));
        // get a vector perpendicular to projected heading and the normal
        const gmtl::Vec3d perpendicular = gmtl::makeCross(local_normal, heading);
        const gmtl::Vec3d perpendicular_2 = gmtl::makeCross(perpendicular, local_normal);
        // construct a new orientation leaving the heading untouched
        orientation = gmtl::EulerAngleZXYd      (
                                                                                orientation[0]
                                                                                ,gmtl::Math::aSin(perpendicular_2[2])
                                                                                ,gmtl::Math::aTan2(perpendicular[2], local_normal[2])
                                                                                );
        if (smooth_factor < 1.0)
        {
                gmtl::Quatd target_quat = gmtl::makeRot<gmtl::Quatd>(orientation);
                target_quat = gmtl::slerp(target_quat, smooth_factor, quat, target_quat);
                orientation = gmtl::makeRot<gmtl::EulerAngleZXYd>(gmtl::makeRot<gmtl::Matrix44d>(target_quat));
        }
</code>

Cheers
Sebastian

P.S. If you got further questions, simply drop me a private message/email.




Am 2/1/2017 um 11:27 AM schrieb Trajce Nikolov NICK:
Quote:
Hi Sebastian,

the code will be welcome. I was expecting that the proper way is to go
through Eulers

Thanks a lot!


On Wed, Feb 1, 2017 at 9:48 AM, Sebastian Messerschmidt
< (
Only registered users can see emails on this board!
Get registred or enter the forums!
) <mailto: (
Only registered users can see emails on this board!
Get registred or enter the forums!
)>>
wrote:

    Hi Trajce,

    Did I miss the question Smile If it is working: fine. Smile

    In general you are extracting the heading I guess (with the
    modelOrientation) and put it on top the tilted normal, which will
    put you on in this pose. The problem might be, that you introduce
    unwanted roll with this. I can give you some code (not based on OSG,
    but you'll get the idea) adapting a EulerAngle pose to a terrain
    normal using a local tangent plane.

    Cheers
    Sebastian




        Hi community,

        this is sort of easy math question (btw, I missed that part in my
        classes Wink ) I want to check it with you.

        It is about node following terrain. my node is MatrixTransform and I
        have to set it in world coordinates. The node has it's own
        rotation and
        I just need to take the terrain normal into account. Here is the
        pseudocode that produces some acceptable results (not sure if
        they are
        correct though, thus asking you for hints)

        Vec3 terrainNormal;

        Quat terrainOrientation;
        terrainOrientation.makeRotate(Vec3(0,0,1), terrainNormal);

        Quat modelOrientation;
        modelOrientation.makeRotate(Vec3(0,1,0), whatever);

        Quat q;
        q = terrainOrientation * modelOrientation; // not sure about this

        MatrixTransform mxt = ...
        mxt->setMatrix(Matrixd:;rotate(q) * ...);

        Any hints?

        Thanks a bunch as always!
        Nick


        --
        trajce nikolov nick


        _______________________________________________
        osg-users mailing list
        (
Only registered users can see emails on this board!
Get registred or enter the forums!
)


        <mailto: (
Only registered users can see emails on this board!
Get registred or enter the forums!
)>
        http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
        <http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org>

    _______________________________________________
    osg-users mailing list
    (
Only registered users can see emails on this board!
Get registred or enter the forums!
)
    <mailto: (
Only registered users can see emails on this board!
Get registred or enter the forums!
)>
    http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
    <http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org>




--
trajce nikolov nick


_______________________________________________
osg-users mailing list
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

_______________________________________________
osg-users mailing list
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org








--
trajce nikolov nick






--
trajce nikolov nick

------------------
Post generated by Mail2Forum
Back to top
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts Combining OSG and Qt 5.4 architecture Fawkes General [3rdparty] 1 Wed Apr 15, 2015 8:38 am View latest post
No new posts Combining transformations and referen... Deniz Koçak General 0 Wed Nov 13, 2013 8:21 pm View latest post
No new posts fbx plugin, option to read animation ... hybr General 0 Fri Oct 12, 2012 11:45 am View latest post
No new posts Combining shaders and query about them Pertur General 2 Tue Oct 26, 2010 2:34 pm View latest post
No new posts Combining particles with different te... robertosfield General 1 Wed Nov 18, 2009 2:23 pm View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP