Sketch: use the focal distance to determine a correct scale factor for SoDatumLabel

This fixes #7860: Dimensions get unreadable (small) if a 2nd sketch is visible
and fixes #7082: Dimension size on perspective view scales "backwards"
This commit is contained in:
wmayer
2022-11-24 10:21:59 +01:00
parent 29086e608a
commit b91cae4ee5
2 changed files with 8 additions and 2 deletions

View File

@@ -102,6 +102,7 @@
#include <Inventor/elements/SoViewportRegionElement.h>
#include <Inventor/actions/SoGetMatrixAction.h>
#include <Inventor/actions/SoGLRenderAction.h>
#include <Inventor/elements/SoFocalDistanceElement.h>
#include <Inventor/elements/SoModelMatrixElement.h>
#include <Inventor/elements/SoProjectionMatrixElement.h>
#include <Inventor/elements/SoViewingMatrixElement.h>

View File

@@ -43,6 +43,7 @@
# include <Inventor/misc/SoState.h>
# include <cmath>
# include <Inventor/actions/SoGetMatrixAction.h>
# include <Inventor/elements/SoFocalDistanceElement.h>
# include <Inventor/elements/SoFontNameElement.h>
# include <Inventor/elements/SoFontSizeElement.h>
# include <Inventor/elements/SoModelMatrixElement.h>
@@ -433,11 +434,15 @@ void SoDatumLabel::GLRender(SoGLRenderAction * action)
* This is not documented and therefore may change on later coin versions!
*/
const SbViewVolume & vv = SoViewVolumeElement::get(state);
// As reference use the center point the camera is looking at on the near plane
// As reference use the center point the camera is looking at on the focal plane
// because then independent of the camera we get a constant scale factor when panning.
// If we used (0,0,0) instead then the scale factor would change heavily in perspective
// rendering mode. See #0002921 and #0002922.
SbVec3f center = vv.getSightPoint(vv.getNearDist());
// It's important to use the distance to the focal plane an not near or far plane because
// depending on additionally displayed objects they may change heavily and thus impact the
// scale factor. See #7082 and #7860.
float focal = SoFocalDistanceElement::get(state);
SbVec3f center = vv.getSightPoint(focal);
float scale = vv.getWorldToScreenScale(center, 1.f);
const SbViewportRegion & vp = SoViewportRegionElement::get(state);
SbVec2s vp_size = vp.getViewportSizePixels();