<div dir="ltr"><div>Hi.<br></div>I use the following function to convert from degrees to quaternions:<br><br><pre><span class="">Vec4</span> <span class="">degreeToQuaternion</span><span class="">(</span><span class="">const</span> <span class="">Vec3</span> <span class="">&</span><span class="">degree</span><span class="">)</span> <span class="">throw</span> <span class="">()</span>
<a name="Common.cpp-87"></a><span class="">{</span>
<a name="Common.cpp-88"></a>    <span class="">osg</span><span class="">::</span><span class="">Quat</span> <span class="">q</span><span class="">;</span>
<a name="Common.cpp-89"></a>    <span class="">q</span><span class="">.</span><span class="">makeRotate</span><span class="">(</span><span class="">osg</span><span class="">::</span><span class="">DegreesToRadians</span><span class="">(</span><span class="">degree</span><span class="">.</span><span class="">x</span><span class="">),</span> <span class="">osg</span><span class="">::</span><span class="">Vec3</span><span class="">(</span><span class="">1</span><span class="">,</span> <span class="">0</span><span class="">,</span> <span class="">0</span><span class="">),</span>
<a name="Common.cpp-90"></a>                 <span class="">osg</span><span class="">::</span><span class="">DegreesToRadians</span><span class="">(</span><span class="">degree</span><span class="">.</span><span class="">y</span><span class="">),</span> <span class="">osg</span><span class="">::</span><span class="">Vec3</span><span class="">(</span><span class="">0</span><span class="">,</span> <span class="">1</span><span class="">,</span> <span class="">0</span><span class="">),</span>
<a name="Common.cpp-91"></a>                 <span class="">osg</span><span class="">::</span><span class="">DegreesToRadians</span><span class="">(</span><span class="">degree</span><span class="">.</span><span class="">z</span><span class="">),</span> <span class="">osg</span><span class="">::</span><span class="">Vec3</span><span class="">(</span><span class="">0</span><span class="">,</span> <span class="">0</span><span class="">,</span> <span class="">1</span><span class="">));</span>
<a name="Common.cpp-92"></a>    <span class="">return</span> <span class="">Vec4</span><span class="">(</span><span class="">q</span><span class="">.</span><span class="">x</span><span class="">(),</span> <span class="">q</span><span class="">.</span><span class="">y</span><span class="">(),</span> <span class="">q</span><span class="">.</span><span class="">z</span><span class="">(),</span> <span class="">q</span><span class="">.</span><span class="">w</span><span class="">());</span>
<a name="Common.cpp-93"></a><span class="">}<br><br></span></pre><pre><span class="">Vec4 is like osg::Vec4 for my own code.<br></span></pre><br></div><div class="gmail_extra"><br><div class="gmail_quote">2015-09-04 2:08 GMT+07:00 Glenn Waldron <span dir="ltr"><<a href="mailto:gwaldron@gmail.com" target="_blank">gwaldron@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Try this:<div><br></div><div><a href="https://github.com/gwaldron/osgearth/blob/master/src/applications/osgearth_transform/osgearth_transform.cpp#L77" target="_blank">https://github.com/gwaldron/osgearth/blob/master/src/applications/osgearth_transform/osgearth_transform.cpp#L77</a><br></div><div><br></div><div>Good luck.</div></div><div class="gmail_extra"><span class="HOEnZb"><font color="#888888"><br clear="all"><div><div><div dir="ltr"><div>Glenn Waldron</div></div></div></div></font></span><div><div class="h5">
<br><div class="gmail_quote">On Thu, Sep 3, 2015 at 11:09 AM, Guido Knapen <span dir="ltr"><<a href="mailto:guidoknapen@gmail.com" target="_blank">guidoknapen@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello everybody.<br>
<br>
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.<br>
<br>
Basicly I have this code to put some testing arrows in my scene which demonstrate yaw, pitch and roll.<br>
<br>
<br>
Code:<br>
<br>
for(int y = 0; y < 4; y++) // Vertical stuff<br>
      {<br>
          char *ID = 0;<br>
          float lat = 50.0 - 0.1f * y;<br>
          bool increaseYaw = false;<br>
          bool increasePitch = false;<br>
          bool increaseRoll = false;<br>
<br>
          switch(y)<br>
          {<br>
          case 0:<br>
                  increaseYaw = true;<br>
                  ID = "YAW";<br>
                  break;<br>
          case 1:<br>
                  increasePitch = true;<br>
                  ID = "PITCH";<br>
                  break;<br>
          case 2:<br>
                  increaseRoll = true;<br>
                  ID = "ROLL";<br>
                  break;<br>
          case 3:<br>
                  increaseYaw = true;<br>
                  increasePitch = true;<br>
                  ID = "YAW AND PITCH";<br>
                  break;<br>
          case 4:<br>
                  increaseYaw = true;<br>
                  increaseRoll = true;<br>
                  ID = "YAW AND ROLL";<br>
                  break;<br>
          case 5:<br>
                  increasePitch = true;<br>
                  increaseRoll = true;<br>
                  ID = "PITCH AND ROLL";<br>
                  break;<br>
          case 6:<br>
                  increaseYaw = true;<br>
                  increasePitch = true;<br>
                  increaseRoll = true;<br>
                  ID = "YAW, PITCH AND ROLL";<br>
                  break;<br>
          }<br>
<br>
          float yaw = 0.0f;<br>
              float pitch = 0.0f;<br>
                  float roll = 0.0f;<br>
<br>
                  for(int x = 0; x < 8; x++) // Horizontal stuff<br>
                  {<br>
                          float lon = 6.0f + 0.1f * x;<br>
<br>
                          GuiLibViewerEntity *ve = mViewer->createViewerEntity( // align<br>
                               ID,// align<br>
                               GuiLib::GuiLibPosition(lat, lon, 1000.0), // align<br>
                               20.0, // align<br>
                               path, // align<br>
                               x == 0);<br>
                      ve->setRotationRadians(yaw, pitch, roll);<br>
                      ve->setAutoScale(mAutoScale);<br>
<br>
                          if(increaseYaw)<br>
                          {<br>
                                  yaw += osg::PI / 4;<br>
                          }<br>
<br>
                          if(increasePitch)<br>
                          {<br>
                                  pitch += osg::PI / 4;<br>
                          }<br>
<br>
                          if(increaseRoll)<br>
                          {<br>
                                  roll += osg::PI / 4;<br>
                          }<br>
                  }<br>
      }<br>
<br>
<br>
<br>
<br>
However my setRotationRadius does not work properly. One of methods which got me the closest to the proper result is this one:<br>
<br>
<br>
Code:<br>
<br>
void ViewerEntity::setRotationRadians(<br>
         float aYaw,<br>
         float aPitch,<br>
         float aRoll) {<br>
<br>
osg::Matrixd mat;<br>
           mat.makeRotate(aPitch, PITCH_VEC, aYaw, YAW_VEC, aRoll, ROLL_VEC);<br>
<br>
           mModel->setLocalRotation (mat.getRotate());<br>
}<br>
<br>
<br>
<br>
<br>
Which generates this:<br>
/file/d/0B7qBNqPzsL5PMWx1ZjVRR0VHbms/view?usp=sharing<br>
<br>
EDIT: apparently I cant post images. however that's a google drive image feel free to add that to the google drive url.<br>
<br>
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.<br>
<br>
Can anybody please help me out?<br>
<br>
Thanks in advance<br>
<br>
------------------<br>
Read this topic online here:<br>
<a href="http://forum.openscenegraph.org/viewtopic.php?p=65014#65014" rel="noreferrer" target="_blank">http://forum.openscenegraph.org/viewtopic.php?p=65014#65014</a><br>
<br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
osg-users mailing list<br>
<a href="mailto:osg-users@lists.openscenegraph.org" target="_blank">osg-users@lists.openscenegraph.org</a><br>
<a href="http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org" rel="noreferrer" target="_blank">http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org</a><br>
</blockquote></div><br></div></div></div>
<br>_______________________________________________<br>
osg-users mailing list<br>
<a href="mailto:osg-users@lists.openscenegraph.org">osg-users@lists.openscenegraph.org</a><br>
<a href="http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org" rel="noreferrer" target="_blank">http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org</a><br>
<br></blockquote></div><br></div>