Sketcher: SoZoomTranslation - expose scaling factor

===================================================

This commit exposes the scale factor used.
This commit is contained in:
Abdullah Tahiri
2023-04-20 19:34:59 +02:00
committed by abdullahtahiriyo
parent 8b1d094fb4
commit 423ff82409
2 changed files with 10 additions and 7 deletions

View File

@@ -66,16 +66,16 @@ void SoZoomTranslation::initClass()
SO_ENABLE(SoGetMatrixAction, SoViewVolumeElement);
}
float SoZoomTranslation::getScaleFactor(SoAction* action) const
float SoZoomTranslation::calculateScaleFactor(SoAction* action) const
{
// Dividing by 5 seems to work well
SbViewVolume vv = SoViewVolumeElement::get(action->getState());
float aspectRatio = SoViewportRegionElement::get(action->getState()).getViewportAspectRatio();
float scale = vv.getWorldToScreenScale(SbVec3f(0.f, 0.f, 0.f), 0.1f) / (5*aspectRatio);
return scale;
scaleFactor = vv.getWorldToScreenScale(SbVec3f(0.f, 0.f, 0.f), 0.1f) / (5*aspectRatio);
return scaleFactor;
}
SoZoomTranslation::SoZoomTranslation()
SoZoomTranslation::SoZoomTranslation(): scaleFactor(0)
{
SO_NODE_CONSTRUCTOR(SoZoomTranslation);
SO_NODE_ADD_FIELD(abPos, (SbVec3f(0.f,0.f,0.f)));
@@ -96,7 +96,7 @@ void SoZoomTranslation::doAction(SoAction * action)
SbVec3f absVtr = this->abPos.getValue();
SbVec3f relVtr = this->translation.getValue();
float sf = this->getScaleFactor(action);
float sf = this->calculateScaleFactor(action);
// For Sketcher Keep Z value the same
relVtr[0] = (relVtr[0] != 0) ? sf * relVtr[0] : 0;
relVtr[1] = (relVtr[1] != 0) ? sf * relVtr[1] : 0;
@@ -116,7 +116,7 @@ void SoZoomTranslation::getMatrix(SoGetMatrixAction * action)
SbVec3f absVtr = this->abPos.getValue();
SbVec3f relVtr = this->translation.getValue();
float sf = this->getScaleFactor(action);
float sf = this->calculateScaleFactor(action);
// For Sketcher Keep Z value the same
relVtr[0] = (relVtr[0] != 0) ? sf * relVtr[0] : 0;
relVtr[1] = (relVtr[1] != 0) ? sf * relVtr[1] : 0;

View File

@@ -39,6 +39,7 @@ public:
static void initClass();
SoZoomTranslation();
SoSFVec3f abPos;
float getScaleFactor() const { return scaleFactor;}
protected:
~SoZoomTranslation() override {}
@@ -49,7 +50,9 @@ protected:
void getBoundingBox(SoGetBoundingBoxAction * action) override;
void callback(SoCallbackAction * action) override;
void pick(SoPickAction * action) override;
float getScaleFactor(SoAction * action) const;
float calculateScaleFactor (SoAction * action) const;
mutable float scaleFactor;
};
}