<div dir="ltr"><div>Hi Jiechang,</div><div><br></div><div>I am not sure I am able to pinpoint your problem. I see some weak spots but I am not sure if those are the true causes of your problem. And don't want to give wrong clues. Can you write short repro program which demos your problem ? I may then fix it and send you back.</div><div><br></div><div>To learn you may try to separate rotations and translations by using two matrix transforms above loaded model. </div><div><br></div><div>MatrixTransformTranslate->MatrixTransformRotate->Object.</div><div><br></div><div>Apply only rotations to MatrixTransformRotate</div><div>and translations to MatrixTransformTranslate.</div><div><br></div><div>Cheers,</div><div>Wojtek<br></div><div> <br></div><div><br></div><div class="gmail_extra"><br><div class="gmail_quote">2017-05-06 8:51 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 Wojtek,<br>
First, Thank you very much for your detailed reply.<br>
1. It's my mistake to say rotation around Y axis, I always think the z axis is actually the y axis.<br>
2. The origin variable is<br>
osg::Matrix origin = model1->getMatrix();<br>
I update this variable everytime when I translate or rotate the model. And multiply it with my transform matrix so that I can get the correct result after changing the position or orientation the model many times. Please Correct Me if I'm not correct.<br>
3. OMG..I tried what you told me to. I just... I think I undestand what's going on in side the constructor. No wonder I got that results and some previous work about trackball rotate I did is wrong. Thank you.<br>
4. I've done some experiments about the order of the origin matrix. I get the same result either I multiply it at first or at last...<br>
The code is below:<br>
osg::ref_ptr<osg::<wbr>MatrixTransform> model1 = new osg::MatrixTransform;<br>
model1->addChild(osgDB::<wbr>readNodeFile("E:\\objdata\\<wbr>FEMUR.obj", a));<br>
osg::Matrix origin = model1->getMatrix();<br>
model1->setMatrix(origin*osg::<wbr>Matrix::translate(100, 0, 0));<br>
<span class="">osg::Vec3 Center = model1->getBound().center();<br>
</span>origin = model1->getMatrix();<br>
osg::Quat quat(osg::PI_4, osg::Z_AXIS);<br>
model1->setMatrix(origin*osg::<wbr>Matrix::translate(-Center)*<wbr>osg::Matrix::rotate(quat)*osg:<wbr>:Matrix::translate(Center)*<wbr>osg::Matrix::translate(100, 0, 0));<br>
<br>
The reason that I want to get the Trans() and Rotate() is that I'm doing a task: Compute the deviation of the origin model and target model. These two model are the same and when the origin model is being manipulted to the position of target model(which is a mesh model) I have to compute whether they are overlaped and skip to another task.<br>
Actually, I've already implemented this function, but I was confused by: when I do only rotate task, the trans I get from getMatrix().getTrans() is changing. I even don't know why it works when I only compute the trans deviation. The code is below.<br>
model1Translation = m1.model->getMatrix().<wbr>getTrans();<br>
model1Quat = m1.model->getMatrix().<wbr>getRotate();<br>
model2Translation = m2.model->getMatrix().<wbr>getTrans();<br>
model2Quat = m2.model->getMatrix().<wbr>getRotate();<br>
osg::Vec3 positionbias = model2Translation - model1Translation;<br>
osg::Quat rotationbias = model2Quat - model1Quat;<br>
if (abs(positionbias.x()) <= 2 && abs(positionbias.y()) <= 2 && abs(positionbias.z()) <= 2)<br>
{<br>
//if (abs(rotationbias.x())<=0.1&&)<br>
//{<br>
hm->pressNext();<br>
//}<br>
<span class="">}<br>
<br>
Cheers,<br>
Jiechang<br>
<br>
------------------<br>
Read this topic online here:<br>
</span><a href="http://forum.openscenegraph.org/viewtopic.php?p=70887#70887" rel="noreferrer" target="_blank">http://forum.openscenegraph.<wbr>org/viewtopic.php?p=70887#<wbr>70887</a><br>
<div class="HOEnZb"><div class="h5"><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>
</div></div></blockquote></div><br></div></div>