mirror of
https://github.com/leozide/leocad
synced 2025-01-17 18:11:42 +01:00
Fixed pan not working when the center of the model is behind the camera. Fixes #161.
This commit is contained in:
parent
945473267f
commit
0621a3848f
2 changed files with 18 additions and 17 deletions
|
@ -1629,9 +1629,7 @@ inline void lcClosestPointsBetweenLines(const lcVector3& Line1a, const lcVector3
|
|||
}
|
||||
}
|
||||
|
||||
// Calculate the intersection of a line segment and a plane and returns false
|
||||
// if they are parallel or the intersection is outside the line segment.
|
||||
inline bool lcLinePlaneIntersection(lcVector3* Intersection, const lcVector3& Start, const lcVector3& End, const lcVector4& Plane)
|
||||
inline bool lcLineSegmentPlaneIntersection(lcVector3* Intersection, const lcVector3& Start, const lcVector3& End, const lcVector4& Plane)
|
||||
{
|
||||
lcVector3 Dir = End - Start;
|
||||
lcVector3 PlaneNormal(Plane[0], Plane[1], Plane[2]);
|
||||
|
@ -1725,7 +1723,7 @@ inline void lcPolygonPlaneClip(lcVector3* InPoints, int NumInPoints, lcVector3*
|
|||
else
|
||||
{
|
||||
// Outside, inside.
|
||||
lcLinePlaneIntersection(&i, *s, *p, Plane);
|
||||
lcLineSegmentPlaneIntersection(&i, *s, *p, Plane);
|
||||
|
||||
OutPoints[*NumOutPoints] = i;
|
||||
*NumOutPoints = *NumOutPoints + 1;
|
||||
|
@ -1738,7 +1736,7 @@ inline void lcPolygonPlaneClip(lcVector3* InPoints, int NumInPoints, lcVector3*
|
|||
if (lcDot3(*s, Plane) + Plane[3] <= 0)
|
||||
{
|
||||
// Inside, outside.
|
||||
lcLinePlaneIntersection(&i, *s, *p, Plane);
|
||||
lcLineSegmentPlaneIntersection(&i, *s, *p, Plane);
|
||||
|
||||
OutPoints[*NumOutPoints] = i;
|
||||
*NumOutPoints = *NumOutPoints + 1;
|
||||
|
|
|
@ -518,7 +518,7 @@ lcMatrix44 View::GetPieceInsertPosition(bool IgnoreSelected, PieceInfo* Info) co
|
|||
lcVector3 Intersection;
|
||||
|
||||
const lcBoundingBox& BoundingBox = Info->GetBoundingBox();
|
||||
if (lcLinePlaneIntersection(&Intersection, ClickPoints[0], ClickPoints[1], lcVector4(0, 0, 1, BoundingBox.Min.z)))
|
||||
if (lcLineSegmentPlaneIntersection(&Intersection, ClickPoints[0], ClickPoints[1], lcVector4(0, 0, 1, BoundingBox.Min.z)))
|
||||
{
|
||||
Intersection = mModel->SnapPosition(Intersection);
|
||||
return lcMatrix44Translation(Intersection);
|
||||
|
@ -1908,7 +1908,7 @@ void View::UpdateTrackTool()
|
|||
lcVector4 Plane(PlaneNormals[AxisIndex], -lcDot(PlaneNormals[AxisIndex], OverlayCenter));
|
||||
lcVector3 Intersection;
|
||||
|
||||
if (!lcLinePlaneIntersection(&Intersection, Start, End, Plane))
|
||||
if (!lcLineSegmentPlaneIntersection(&Intersection, Start, End, Plane))
|
||||
continue;
|
||||
|
||||
float IntersectionDistance = lcLengthSquared(Intersection - Start);
|
||||
|
@ -2468,7 +2468,7 @@ void View::StopTracking(bool Accept)
|
|||
lcVector4 Plane(PlaneNormal, -lcDot(PlaneNormal, Center));
|
||||
lcVector3 Target, Corners[2];
|
||||
|
||||
if (lcLinePlaneIntersection(&Target, Points[0], Points[1], Plane) && lcLinePlaneIntersection(&Corners[0], Points[2], Points[3], Plane) && lcLinePlaneIntersection(&Corners[1], Points[3], Points[4], Plane))
|
||||
if (lcLineSegmentPlaneIntersection(&Target, Points[0], Points[1], Plane) && lcLineSegmentPlaneIntersection(&Corners[0], Points[2], Points[3], Plane) && lcLineSegmentPlaneIntersection(&Corners[1], Points[3], Points[4], Plane))
|
||||
{
|
||||
float AspectRatio = (float)mWidth / (float)mHeight;
|
||||
mModel->ZoomRegionToolClicked(mCamera, AspectRatio, Points[0], Target, Corners);
|
||||
|
@ -2804,11 +2804,11 @@ void View::OnMouseMove()
|
|||
lcVector4 Plane(PlaneNormal, -lcDot(PlaneNormal, Center));
|
||||
lcVector3 Intersection;
|
||||
|
||||
if (lcLinePlaneIntersection(&Intersection, CurrentStart, CurrentEnd, Plane))
|
||||
if (lcLineSegmentPlaneIntersection(&Intersection, CurrentStart, CurrentEnd, Plane))
|
||||
{
|
||||
lcVector3 MoveStart;
|
||||
|
||||
if (lcLinePlaneIntersection(&MoveStart, MouseDownStart, MouseDownEnd, Plane))
|
||||
if (lcLineSegmentPlaneIntersection(&MoveStart, MouseDownStart, MouseDownEnd, Plane))
|
||||
{
|
||||
lcVector3 Distance = Intersection - MoveStart;
|
||||
Distance = lcMul(Distance, lcMatrix33AffineInverse(RelativeRotation));
|
||||
|
@ -2866,11 +2866,11 @@ void View::OnMouseMove()
|
|||
lcVector4 Plane(PlaneNormal, -lcDot(PlaneNormal, Center));
|
||||
lcVector3 Intersection;
|
||||
|
||||
if (lcLinePlaneIntersection(&Intersection, CurrentStart, CurrentEnd, Plane))
|
||||
if (lcLineSegmentPlaneIntersection(&Intersection, CurrentStart, CurrentEnd, Plane))
|
||||
{
|
||||
lcVector3 MoveStart;
|
||||
|
||||
if (lcLinePlaneIntersection(&MoveStart, MouseDownStart, MouseDownEnd, Plane))
|
||||
if (lcLineSegmentPlaneIntersection(&MoveStart, MouseDownStart, MouseDownEnd, Plane))
|
||||
{
|
||||
lcVector3 Distance = Intersection - MoveStart;
|
||||
mModel->UpdateMoveTool(Distance, mTrackButton != LC_TRACKBUTTON_LEFT);
|
||||
|
@ -2983,15 +2983,18 @@ void View::OnMouseMove()
|
|||
|
||||
lcVector3 PlaneNormal(mCamera->mPosition - mCamera->mTargetPosition);
|
||||
lcVector4 Plane(PlaneNormal, -lcDot(PlaneNormal, Center));
|
||||
lcVector3 Intersection;
|
||||
lcVector3 Intersection, MoveStart;
|
||||
|
||||
if (lcLinePlaneIntersection(&Intersection, CurrentStart, CurrentEnd, Plane))
|
||||
if (!lcLineSegmentPlaneIntersection(&Intersection, CurrentStart, CurrentEnd, Plane) || !lcLineSegmentPlaneIntersection(&MoveStart, MouseDownStart, MouseDownEnd, Plane))
|
||||
{
|
||||
lcVector3 MoveStart;
|
||||
Center = MouseDownStart + lcNormalize(MouseDownEnd - MouseDownStart) * 10.0f;
|
||||
Plane = lcVector4(PlaneNormal, -lcDot(PlaneNormal, Center));
|
||||
|
||||
if (lcLinePlaneIntersection(&MoveStart, MouseDownStart, MouseDownEnd, Plane))
|
||||
mModel->UpdatePanTool(mCamera, MoveStart - Intersection);
|
||||
if (!lcLineSegmentPlaneIntersection(&Intersection, CurrentStart, CurrentEnd, Plane) || !lcLineSegmentPlaneIntersection(&MoveStart, MouseDownStart, MouseDownEnd, Plane))
|
||||
break;
|
||||
}
|
||||
|
||||
mModel->UpdatePanTool(mCamera, MoveStart - Intersection);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
Loading…
Reference in a new issue