【NEWBIE】Question about osg::MatrixTransform::getMatrix().getTrans() and getRotate()

Jiechang Guo osgforum at tevs.eu
Tue May 30 22:43:56 PDT 2017


Hi Wojtek,
I'm so sorry that I replied too late. I was held up by my paper's submission deadline. And the problem I think is solved.
Thank you very much. 
Cheers,
Jiechang

Wojtek wrote:
> Hi Jiechang,
> 
> 
> 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.
> 
> 
> To learn you may try to separate rotations and translations by using two matrix transforms above loaded model. 
> 
> 
> MatrixTransformTranslate->MatrixTransformRotate->Object.
> 
> 
> Apply only rotations to MatrixTransformRotate
> and translations to MatrixTransformTranslate.
> 
> 
> Cheers,
> Wojtek
> 
>  
> 
> 
> 
> 
> 2017-05-06 8:51 GMT+02:00 Jiechang Guo < ()>:
> 
> > Hi Wojtek,
> > First, Thank you very much for your detailed reply.
> > 1. It's my mistake to say rotation around Y axis, I always think the z axis is actually the y axis.
> > 2. The origin variable is
> > osg::Matrix origin = model1->getMatrix();
> > 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.
> > 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.
> > 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...
> > The code is below:
> > osg::ref_ptr<osg::MatrixTransform> model1 = new osg::MatrixTransform;
> > model1->addChild(osgDB::readNodeFile("E:\objdata\FEMUR.obj", a));
> > osg::Matrix origin = model1->getMatrix();
> > model1->setMatrix(origin*osg::Matrix::translate(100, 0, 0));
> > osg::Vec3 Center = model1->getBound().center();
> > origin = model1->getMatrix();
> > osg::Quat quat(osg::PI_4, osg::Z_AXIS);
> > model1->setMatrix(origin*osg::Matrix::translate(-Center)*osg::Matrix::rotate(quat)*osg::Matrix::translate(Center)*osg::Matrix::translate(100, 0, 0));
> > 
> >     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.
> > 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.
> > model1Translation = m1.model->getMatrix().getTrans();
> > model1Quat = m1.model->getMatrix().getRotate();
> > model2Translation = m2.model->getMatrix().getTrans();
> > model2Quat = m2.model->getMatrix().getRotate();
> > osg::Vec3 positionbias = model2Translation - model1Translation;
> > osg::Quat rotationbias = model2Quat - model1Quat;
> > if (abs(positionbias.x()) <= 2 && abs(positionbias.y()) <= 2 && abs(positionbias.z()) <= 2)
> > {
> >         //if (abs(rotationbias.x())<=0.1&&)
> >         //{
> >                 hm->pressNext();
> >         //}
> > }
> > 
> > Cheers,
> >   Jiechang
> > 
> > ------------------
> > Read this topic online here:
> > http://forum.openscenegraph.org/viewtopic.php?p=70887#70887 (http://forum.openscenegraph.org/viewtopic.php?p=70887#70887)
> > 
> > 
> > 
> > 
> > 
> > _______________________________________________
> > osg-users mailing list
> >  ()
> > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org (http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org)
> > 
> > 
> > 
> 
> 
>  ------------------
> Post generated by Mail2Forum


------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=71001#71001








More information about the osg-users mailing list