[osg-users] Fwd: Fwd: CallBack issue

Ulrich Hertlein u.hertlein at sandbox.de
Sat Mar 28 04:26:32 PDT 2009

Hello Sajjad,

On 28/3/09 10:00 PM, ami guru wrote:
> The following snippet may elaborate more:
> ******************************'
>    mtLeft->setUpdateCallback(new RotateCB);
>    osg::Matrix m;
>    m.makeTranslate(-6.0f,0.0f,0.0f);
>    mtLeft->setMatrix(m);
> *****************************'
> On the above snippet we have made a translation after the callback. And
> that one is appended to the one that has been called inside the RotateCB.

First of all, the fact that you set a translation matrix is irrelevant.  The callback (as 
you have posted in a previous mail) will always overwrite whatever matrix you set during 

I understand the point you're trying to make.  What I'm saying is that when you use 
MatrixTransform->setMatrix(m) you're loosing anything that has been set before.  If you 
want to preserve that (i.e. the translation in your example) you have to take care of that 

 From what I grok you're looking for a way to keep the translation part and only change 
the rotation.  You could try to do something like:
   Matrix m = mt->getMatrix();

Or use decompose(), change the rotation and re-assemble the matrix: scaling, rotation, 
transform and all.

Or pass the translation to the update callback so that it can assemble and set the proper 
transformation matrix.  Or split the translation and the rotation into different 

Many roads lead to Rome.
matrixTransform->setMatrix(Matrix::makeRotate(...)) is not one of them. ;-)

Hope this helps,

More information about the osg-users mailing list