Hi Jiechang, Few observations:
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. 2. What is the origin variable in your example ? This is probably the other matrix which you premultiply and it influences your results. 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. 4. This line probably has wrong order of transformations --> model1->setMatrix(origin*osg::Matrix::translate(-Center)* osg::Matrix::rotate(osg::DegreesToRadians(45.0), 0, 0, 1)*osg::Matrix::translate(Center)); I suppose you rather want to make it like this --> model1->setMatrix(osg:: Matrix::translate(-Center)*osg::Matrix::rotate(osg::DegreesToRadians(45.0), 0, 0, 1)*osg::Matrix::translate(Center)*origin); 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. Hope this helps, Wojtek Lewandowski 2017-05-05 13:54 GMT+02:00 Jiechang Guo <[email protected]>: > Hi, > I'm a newbie and not good at math. > Please.... > I'm so confused with osg::MatrixTransform::getMatrix().getTrans() > and getRotate(). > I use the code below to rotate an object around y axis about 45 > degrees. > > model1->setMatrix(origin*osg::Matrix::rotate(osg::DegreesToRadians(45.0), > 0, 0, 1)); > > I want to get the rotation of the model, so I used the function to > get a quat: > > osg::Quat rotation = model1->getMatrix().getRotate(); > > I thought the rotation should be like (0.7853982,0,0,1)。but the > result is(0,0,0.382683,0,92388). > I've checked the source code of OSG, and I cann't get any > inspriation from it. > 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. > > osg::Vec3 Center = model1->getBound().center(); > model1->setMatrix(origin*osg::Matrix::translate(-Center)* > osg::Matrix::rotate(osg::DegreesToRadians(45.0), 0, 0, > 1)*osg::Matrix::translate(Center)); > > The object is on the same position and rotation as the first case. > I try to get the rotation, I get more confused.. > I thought I didn't change the position of the model, the tranlation > I get > > osg::Vec3 translation = model1->getMatrix().getTrans(); > > should be (0,0,0) but (-168.184,-141.218, 0) and the rotation is just like > the first case. > Could you please help me to figure out why I got those results? > > Thank you! > > Cheers, > Jiechang > > ------------------ > Read this topic online here: > http://forum.openscenegraph.org/viewtopic.php?p=70883#70883 > > > > > > _______________________________________________ > osg-users mailing list > [email protected] > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org >
_______________________________________________ osg-users mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

