<div dir="ltr"><div>Hi Jiechang,</div><div><br></div><div>Few observations:</div><div><br></div><div>1. You write you want rotation around Y axis (0,1,0). But you rotate around Z axis (0,0,1). Btw there are osg::X_AXIS = (1,0,0) , osg::Y_AXIS = (0,1,0), osg::Z_AXIS = (0,0,1) constants defined in OSG which you may directly.</div><div>2. What is the origin variable in your example ? This is probably the other matrix which you premultiply and it influences your results.</div><div>3. Values stored in quaternion fields are rather non intuitive. I suggest you just make simpler experiment. Set quaternion variable directly with osg::Quat quat( Angle, Axis ). For example as osg::Quat quat( osg::PI_4, osg::Z_AXIS) as you do in your example. And then examine under debugger what constructor does and whats actually stored on 4 fields of Quat. Those numbers won't be the same as the ones you passed to constructor. And thats correct. You will find a plenty of info on Quaternions on the web. Look for them if you need to learn more.</div><div>4. This line probably has wrong order of transformations --> <span style="font-size:12.8px">model1->setMatrix(origin*osg::</span><wbr style="font-size:12.8px"><span style="font-size:12.8px">Matrix::translate(-Center)*</span><wbr style="font-size:12.8px"><span style="font-size:12.8px">osg::Matrix::rotate(osg::</span><wbr style="font-size:12.8px"><span style="font-size:12.8px">DegreesToRadians(45.0), 0, 0, 1)*osg::Matrix::translate(</span><wbr style="font-size:12.8px"><span style="font-size:12.8px">Center)); </span></div><div><span style="font-size:12.8px">I suppose you rather want to make it like this --> </span><span style="font-size:12.8px">model1->setMatrix(osg::</span><wbr style="font-size:12.8px"><span style="font-size:12.8px">Matrix::translate(-Center)*</span><wbr style="font-size:12.8px"><span style="font-size:12.8px">osg::Matrix::rotate(osg::</span><wbr style="font-size:12.8px"><span style="font-size:12.8px">DegreesToRadians(45.0), 0, 0, 1)*osg::Matrix::translate(</span><wbr style="font-size:12.8px"><span style="font-size:12.8px">Center)*origin); </span></div><div><span style="font-size:12.8px">Reason for this is OSG uses row major matrices, so if you want to transform vertex by matrix you do it like this: result = vert * matrix. Thus your origin transform should be multiplied as last transform. </span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">Hope this helps,</span></div><div><span style="font-size:12.8px">Wojtek Lewandowski</span></div><div><span style="font-size:12.8px"><br></span></div></div><div class="gmail_extra"><br><div class="gmail_quote">2017-05-05 13:54 GMT+02:00 Jiechang Guo <span dir="ltr"><<a href="mailto:osgforum@tevs.eu" target="_blank">osgforum@tevs.eu</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
     I'm a newbie and not good at math.<br>
     Please....<br>
     I'm so confused with osg::MatrixTransform::<wbr>getMatrix().getTrans() and getRotate().<br>
     I use the code below to rotate an object around y axis about 45 degrees.<br>
<br>
model1->setMatrix(origin*osg::<wbr>Matrix::rotate(osg::<wbr>DegreesToRadians(45.0), 0, 0, 1));<br>
<br>
      I want to get the rotation of the model, so I used the function to get a quat:<br>
<br>
osg::Quat rotation = model1->getMatrix().getRotate(<wbr>);<br>
<br>
      I thought the rotation should be like (0.7853982,0,0,1)。but the result is(0,0,0.382683,0,92388).<br>
      I've checked the source code of OSG, and I cann't get any inspriation from it.<br>
      Another case, I thought I should move the object to its center and do rotate then move it back (according to some book or paper). The code is below.<br>
<br>
osg::Vec3 Center = model1->getBound().center();<br>
model1->setMatrix(origin*osg::<wbr>Matrix::translate(-Center)*<wbr>osg::Matrix::rotate(osg::<wbr>DegreesToRadians(45.0), 0, 0, 1)*osg::Matrix::translate(<wbr>Center));<br>
<br>
The object is on the same position and rotation as the first case.<br>
       I try to get the rotation, I get more confused..<br>
       I thought I didn't change the position of the model, the tranlation I get<br>
<br>
osg::Vec3 translation = model1->getMatrix().getTrans()<wbr>;<br>
<br>
should be (0,0,0) but (-168.184,-141.218, 0) and the rotation is just like the first case.<br>
       Could you please help me to figure out why I got those results?<br>
<br>
Thank you!<br>
<br>
Cheers,<br>
Jiechang<br>
<br>
------------------<br>
Read this topic online here:<br>
<a href="http://forum.openscenegraph.org/viewtopic.php?p=70883#70883" rel="noreferrer" target="_blank">http://forum.openscenegraph.<wbr>org/viewtopic.php?p=70883#<wbr>70883</a><br>
<br>
<br>
<br>
<br>
<br>
______________________________<wbr>_________________<br>
osg-users mailing list<br>
<a href="mailto:osg-users@lists.openscenegraph.org">osg-users@lists.<wbr>openscenegraph.org</a><br>
<a href="http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org" rel="noreferrer" target="_blank">http://lists.openscenegraph.<wbr>org/listinfo.cgi/osg-users-<wbr>openscenegraph.org</a><br>
</blockquote></div><br></div>