Sketcher infinite axes

This commit is contained in:
Florian Foinant-Willig
2024-11-18 23:09:20 +01:00
committed by Yorik van Havre
parent 407b056952
commit ea8814785a
6 changed files with 124 additions and 23 deletions

View File

@@ -91,6 +91,7 @@
#include <Base/Sequencer.h>
#include <Base/Tools.h>
#include <Base/UnitsApi.h>
#include <Base/Tools2D.h>
#include <Quarter/devices/InputDevice.h>
#include <Quarter/eventhandlers/EventFilter.h>
@@ -2657,8 +2658,76 @@ SbVec2f View3DInventorViewer::getNormalizedPosition(const SbVec2s& pnt) const
return {pX, pY};
}
SbVec3f View3DInventorViewer::getPointOnXYPlaneOfPlacement(const SbVec2s& pnt,
const Base::Placement& plc) const
Base::BoundBox2d View3DInventorViewer::getViewportOnXYPlaneOfPlacement(Base::Placement plc) const
{
auto projBBox = Base::BoundBox3d();
projBBox.SetVoid();
SoCamera* pCam = this->getSoRenderManager()->getCamera();
if (!pCam) {
// Return empty box.
return Base::BoundBox2d(0, 0, 0, 0);
}
Base::Vector3d pos = plc.getPosition();
Base::Rotation rot = plc.getRotation();
// Transform the plane LCS into the global one.
Base::Vector3d zAxis(0, 0, 1);
rot.multVec(zAxis, zAxis);
// Get the position and convert Base::Vector3d to SbVec3f
SbVec3f planeNormal(zAxis.x, zAxis.y, zAxis.z);
SbVec3f planePosition(pos.x, pos.y, pos.z);
SbPlane xyPlane(planeNormal, planePosition);
const SbViewportRegion& vp = this->getSoRenderManager()->getViewportRegion();
SbViewVolume vol = pCam->getViewVolume();
float fRatio = vp.getViewportAspectRatio();
float dX, dY;
vp.getViewportSize().getValue(dX, dY);
// Projects a pair of normalized coordinates on the XY plane.
auto projectPoint =
[&](float x, float y) {
if (fRatio > 1.f) {
x = (x - 0.5f * dX) * fRatio + 0.5f * dX;
}
else if (fRatio < 1.f) {
y = (y - 0.5f * dY) / fRatio + 0.5f * dY;
}
SbLine line;
vol.projectPointToLine(SbVec2f(x, y), line);
SbVec3f pt;
// Intersection point on the XY plane.
if (!xyPlane.intersect(line, pt)) {
return;
}
projBBox.Add(Base::convertTo<Base::Vector3d>(pt));
};
// Project the four corners of the viewport plane.
projectPoint(0.f, 0.f);
projectPoint(1.f, 0.f);
projectPoint(0.f, 1.f);
projectPoint(1.f, 1.f);
if (!projBBox.IsValid()) {
// Return empty box.
return Base::BoundBox2d(0, 0, 0, 0);
}
plc.invert();
Base::ViewOrthoProjMatrix proj(plc.toMatrix());
return projBBox.ProjectBox(&proj);
}
SbVec3f View3DInventorViewer::getPointOnXYPlaneOfPlacement(const SbVec2s& pnt, const Base::Placement& plc) const
{
SbVec2f pnt2d = getNormalizedPosition(pnt);
SoCamera* pCam = this->getSoRenderManager()->getCamera();