From e5a8eebdb80914650c47b471e31ee455d4a2e691 Mon Sep 17 00:00:00 2001 From: Leonardo Zide Date: Fri, 18 Dec 2020 19:13:03 -0800 Subject: [PATCH] Try to place new pieces near existing parts or the origin #548. --- common/view.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/common/view.cpp b/common/view.cpp index 9b1bb355..39ec78d4 100644 --- a/common/view.cpp +++ b/common/view.cpp @@ -433,15 +433,28 @@ lcMatrix44 View::GetPieceInsertPosition(bool IgnoreSelected, PieceInfo* Info) co Point = lcMul31(Point, InverseMatrix); } + const lcBoundingBox& BoundingBox = Info->GetBoundingBox(); lcVector3 Intersection; - const lcBoundingBox& BoundingBox = Info->GetBoundingBox(); if (lcLineSegmentPlaneIntersection(&Intersection, ClickPoints[0], ClickPoints[1], lcVector4(0, 0, 1, BoundingBox.Min.z))) { Intersection = ActiveModel->SnapPosition(Intersection); return lcMatrix44Translation(Intersection); } + lcVector3 Position; + + if (!ActiveModel->GetFocusPosition(Position)) + Position = ActiveModel->GetSelectionOrModelCenter(); + + lcVector3 FrontVector(mCamera->mTargetPosition - mCamera->mPosition); + + if (lcLineSegmentPlaneIntersection(&Intersection, ClickPoints[0], ClickPoints[1], lcVector4(FrontVector, -lcDot(FrontVector, Position)))) + { + Intersection = ActiveModel->SnapPosition(Intersection); + return lcMatrix44Translation(Intersection); + } + return lcMatrix44Translation(UnprojectPoint(lcVector3((float)mMouseX, (float)mMouseY, 0.9f))); }