Gui: reset model transformation scaling in SoAutoZoomTranslation

This commit is contained in:
Zheng, Lei
2020-04-18 16:56:43 +08:00
committed by wwmayer
parent fc469186e7
commit dcc04f35d0

View File

@@ -100,8 +100,15 @@ void SoAutoZoomTranslation::GLRender(SoGLRenderAction * action)
void SoAutoZoomTranslation::doAction(SoAction * action)
{
float sf = this->getScaleFactor(action);
SoModelMatrixElement::scaleBy(action->getState(), this,
SbVec3f(sf,sf,sf));
auto state = action->getState();
SbRotation r,so;
SbVec3f s,t;
SbMatrix matrix = SoModelMatrixElement::get(action->getState());
matrix.getTransform(t,r,s,so);
matrix.multVecMatrix(SbVec3f(0,0,0),t);
// reset current model scale factor
matrix.setTransform(t,r,SbVec3f(sf,sf,sf));
SoModelMatrixElement::set(state,this,matrix);
}
// set the auto scale factor.
@@ -119,14 +126,15 @@ void SoAutoZoomTranslation::getMatrix(SoGetMatrixAction * action)
{
float sf = this->getScaleFactor(action);
SbVec3f scalevec = SbVec3f(sf,sf,sf);
SbMatrix m;
SbMatrix &m = action->getMatrix();
m.setScale(scalevec);
action->getMatrix().multLeft(m);
SbRotation r,so;
SbVec3f s,t;
m.getTransform(t,r,s,so);
m.multVecMatrix(SbVec3f(0,0,0),t);
m.setTransform(t,r,SbVec3f(sf,sf,sf));
m.setScale(SbVec3f(1.0f / scalevec[0], 1.0f / scalevec[1], 1.0f / scalevec[2]));
action->getInverse().multRight(m);
action->getInverse() = m.inverse();
}
void SoAutoZoomTranslation::callback(SoCallbackAction * action)