Try to place new pieces near existing parts or the origin #548.

This commit is contained in:
Leonardo Zide 2020-12-18 19:13:03 -08:00
parent 1925c476d6
commit e5a8eebdb8

View file

@ -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)));
}