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

Jiechang Guo osgforum at tevs.eu
Fri May 5 23:51:57 PDT 2017


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








More information about the osg-users mailing list