diff --git a/src/SelectMgr/SelectMgr_RectangularFrustum.cxx b/src/SelectMgr/SelectMgr_RectangularFrustum.cxx index 7bcd65c840..ccc486823d 100644 --- a/src/SelectMgr/SelectMgr_RectangularFrustum.cxx +++ b/src/SelectMgr/SelectMgr_RectangularFrustum.cxx @@ -665,23 +665,30 @@ void SelectMgr_RectangularFrustum::computeClippingRange (const Graphic3d_Sequenc const gp_XYZ& aPlaneDirXYZ = aGeomPlane.Axis().Direction().XYZ(); Standard_Real aDotProduct = myViewRayDir.XYZ().Dot (aPlaneDirXYZ); Standard_Real aDistance = -myNearPickedPnt.XYZ().Dot (aPlaneDirXYZ) - aPlaneD; + Standard_Real aDistToPln = 0.0; // check whether the pick line is parallel to clip plane if (Abs (aDotProduct) < Precision::Angular()) { - // line lies below the plane and is not clipped, skip - continue; + if (aDistance < 0.0) + { + continue; + } + aDistToPln = RealLast(); + aDotProduct = 1.0; } - - // compute distance to point of pick line intersection with the plane - const Standard_Real aParam = aDistance / aDotProduct; - - const gp_Pnt anIntersectionPnt = myNearPickedPnt.XYZ() + myViewRayDir.XYZ() * aParam; - Standard_Real aDistToPln = anIntersectionPnt.Distance (myNearPickedPnt); - if (aParam < 0.0) + else { - // the plane is "behind" the ray - aDistToPln = -aDistToPln; + // compute distance to point of pick line intersection with the plane + const Standard_Real aParam = aDistance / aDotProduct; + + const gp_Pnt anIntersectionPnt = myNearPickedPnt.XYZ() + myViewRayDir.XYZ() * aParam; + aDistToPln = anIntersectionPnt.Distance (myNearPickedPnt); + if (aParam < 0.0) + { + // the plane is "behind" the ray + aDistToPln = -aDistToPln; + } } // change depth limits for case of opposite and directed planes diff --git a/tests/bugs/vis/bug29791 b/tests/bugs/vis/bug29791 index 64190c1951..587f861f2f 100644 --- a/tests/bugs/vis/bug29791 +++ b/tests/bugs/vis/bug29791 @@ -10,12 +10,24 @@ vinit View1 vdisplay -dispMode 1 -highMode 1 b vfit vzbufftrihedron -vviewparams -scale 14.7435 -proj 0.193921 -0.891229 0.410007 -up -0.0205984 0.414149 0.909976 -at 11.3689 1.32152 24.9954 vclipplane p -equation 1 0 0 -20 -set + +# clipping plane orthogonal to the camera direction +vfront +vfit +vmoveto 150 200 +vstate -entities +vselect 150 200 +if { [vreadpixel 150 200 rgb name] != "BLACK" } { puts "Error: object is not clipped" } +if { [vreadpixel 350 200 rgb name] != "GOLDENROD1" } { puts "Error: object should NOT be selected" } +vdump $imagedir/${casename}_1.png + +# depth range starts behinds the picking ray +vviewparams -scale 14.7435 -proj 0.193921 -0.891229 0.410007 -up -0.0205984 0.414149 0.909976 -at 11.3689 1.32152 24.9954 vmoveto 150 200 vstate -entities vselect 150 200 if { [vreadpixel 150 200 rgb name] != "BLACK" } { puts "Error: object is not clipped" } if { [vreadpixel 300 200 rgb name] != "GOLDENROD1" } { puts "Error: object should NOT be selected" } -vdump $imagedir/${casename}.png +vdump $imagedir/${casename}_2.png