Core: SoShapeScale fix weird scaling on viewport resize. See https://github.com/FreeCAD/FreeCAD/issues/18382#issuecomment-2527623758

This commit is contained in:
PaddleStroke
2024-12-09 14:25:36 +01:00
committed by wwmayer
parent 09be35359e
commit dbdbc9934e
10 changed files with 21 additions and 19 deletions

View File

@@ -85,24 +85,26 @@ SoShapeScale::initClass()
void
SoShapeScale::GLRender(SoGLRenderAction * action)
{
SoState * state = action->getState();
SoScale * scale = static_cast<SoScale*>(this->getAnyPart(SbName("scale"), true));
auto* scale = static_cast<SoScale*>(this->getAnyPart(SbName("scale"), true));
if (!this->active.getValue()) {
SbVec3f v(1.0f, 1.0f, 1.0f);
if (scale->scaleFactor.getValue() != v)
if (scale->scaleFactor.getValue() != v){
scale->scaleFactor = v;
}
}
else {
SoState* state = action->getState();
const SbViewportRegion & vp = SoViewportRegionElement::get(state);
const SbViewVolume & vv = SoViewVolumeElement::get(state);
SbVec3f center(0.0f, 0.0f, 0.0f);
float nsize = this->scaleFactor.getValue() / float(vp.getViewportSizePixels()[1]);
float nsize = this->scaleFactor.getValue() / float(vp.getViewportSizePixels()[0]);
SoModelMatrixElement::get(state).multVecMatrix(center, center); // world coords
float sf = vv.getWorldToScreenScale(center, nsize);
SbVec3f v(sf, sf, sf);
if (scale->scaleFactor.getValue() != v)
if (scale->scaleFactor.getValue() != v){
scale->scaleFactor = v;
}
}
inherited::GLRender(action);