[osg-users] Problem converting yaw,pitch,roll to quaternion

michael kapelko kornerr at gmail.com
Fri Sep 4 20:13:15 PDT 2015


Hi.
I use the following function to convert from degrees to quaternions:

Vec4 degreeToQuaternion(const Vec3 &degree) throw (){    osg::Quat q;
  q.makeRotate(osg::DegreesToRadians(degree.x), osg::Vec3(1, 0, 0),
             osg::DegreesToRadians(degree.y), osg::Vec3(0, 1, 0),
           osg::DegreesToRadians(degree.z), osg::Vec3(0, 0, 1));
return Vec4(q.x(), q.y(), q.z(), q.w());}

Vec4 is like osg::Vec4 for my own code.



2015-09-04 2:08 GMT+07:00 Glenn Waldron <gwaldron at gmail.com>:

> Try this:
>
>
> https://github.com/gwaldron/osgearth/blob/master/src/applications/osgearth_transform/osgearth_transform.cpp#L77
>
> Good luck.
>
> Glenn Waldron
>
> On Thu, Sep 3, 2015 at 11:09 AM, Guido Knapen <guidoknapen at gmail.com>
> wrote:
>
>> Hello everybody.
>>
>> I'm new to this forum. For 16 hours I've been trying to solve my problem
>> with no success. I've tried several different methods to convert but all
>> fail.
>>
>> Basicly I have this code to put some testing arrows in my scene which
>> demonstrate yaw, pitch and roll.
>>
>>
>> Code:
>>
>> for(int y = 0; y < 4; y++) // Vertical stuff
>>       {
>>           char *ID = 0;
>>           float lat = 50.0 - 0.1f * y;
>>           bool increaseYaw = false;
>>           bool increasePitch = false;
>>           bool increaseRoll = false;
>>
>>           switch(y)
>>           {
>>           case 0:
>>                   increaseYaw = true;
>>                   ID = "YAW";
>>                   break;
>>           case 1:
>>                   increasePitch = true;
>>                   ID = "PITCH";
>>                   break;
>>           case 2:
>>                   increaseRoll = true;
>>                   ID = "ROLL";
>>                   break;
>>           case 3:
>>                   increaseYaw = true;
>>                   increasePitch = true;
>>                   ID = "YAW AND PITCH";
>>                   break;
>>           case 4:
>>                   increaseYaw = true;
>>                   increaseRoll = true;
>>                   ID = "YAW AND ROLL";
>>                   break;
>>           case 5:
>>                   increasePitch = true;
>>                   increaseRoll = true;
>>                   ID = "PITCH AND ROLL";
>>                   break;
>>           case 6:
>>                   increaseYaw = true;
>>                   increasePitch = true;
>>                   increaseRoll = true;
>>                   ID = "YAW, PITCH AND ROLL";
>>                   break;
>>           }
>>
>>           float yaw = 0.0f;
>>               float pitch = 0.0f;
>>                   float roll = 0.0f;
>>
>>                   for(int x = 0; x < 8; x++) // Horizontal stuff
>>                   {
>>                           float lon = 6.0f + 0.1f * x;
>>
>>                           GuiLibViewerEntity *ve =
>> mViewer->createViewerEntity( // align
>>                                ID,// align
>>                                GuiLib::GuiLibPosition(lat, lon, 1000.0),
>> // align
>>                                20.0, // align
>>                                path, // align
>>                                x == 0);
>>                       ve->setRotationRadians(yaw, pitch, roll);
>>                       ve->setAutoScale(mAutoScale);
>>
>>                           if(increaseYaw)
>>                           {
>>                                   yaw += osg::PI / 4;
>>                           }
>>
>>                           if(increasePitch)
>>                           {
>>                                   pitch += osg::PI / 4;
>>                           }
>>
>>                           if(increaseRoll)
>>                           {
>>                                   roll += osg::PI / 4;
>>                           }
>>                   }
>>       }
>>
>>
>>
>>
>> However my setRotationRadius does not work properly. One of methods which
>> got me the closest to the proper result is this one:
>>
>>
>> Code:
>>
>> void ViewerEntity::setRotationRadians(
>>          float aYaw,
>>          float aPitch,
>>          float aRoll) {
>>
>> osg::Matrixd mat;
>>            mat.makeRotate(aPitch, PITCH_VEC, aYaw, YAW_VEC, aRoll,
>> ROLL_VEC);
>>
>>            mModel->setLocalRotation (mat.getRotate());
>> }
>>
>>
>>
>>
>> Which generates this:
>> /file/d/0B7qBNqPzsL5PMWx1ZjVRR0VHbms/view?usp=sharing
>>
>> EDIT: apparently I cant post images. however that's a google drive image
>> feel free to add that to the google drive url.
>>
>> As you can see the yaw, pitch and roll individually are rotated
>> correctly. However when the yaw and pitch are combined the arrows which
>> have a red circle around them have their yaw wrong by 180 degrees.
>>
>> Can anybody please help me out?
>>
>> Thanks in advance
>>
>> ------------------
>> Read this topic online here:
>> http://forum.openscenegraph.org/viewtopic.php?p=65014#65014
>>
>>
>>
>>
>>
>> _______________________________________________
>> osg-users mailing list
>> osg-users at lists.openscenegraph.org
>> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>>
>
>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20150905/53e35389/attachment-0003.htm>


More information about the osg-users mailing list