Skip to content

Commit

Permalink
Gui: reset model transformation scaling in SoAutoZoomTranslation
Browse files Browse the repository at this point in the history
  • Loading branch information
realthunder authored and wwmayer committed May 13, 2020
1 parent dd42bfb commit e6f4a17
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/Gui/Inventor/SoAutoZoomTranslation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
Expand Down

0 comments on commit e6f4a17

Please sign in to comment.