diff --git a/common/lc_model.cpp b/common/lc_model.cpp index 5836591f..7db5401e 100644 --- a/common/lc_model.cpp +++ b/common/lc_model.cpp @@ -2521,17 +2521,26 @@ bool lcModel::GetPieceFocusOrSelectionCenter(lcVector3& Center) const return Selected; } +bool lcModel::GetFocusOrSelectionCenter(lcVector3& Center) const +{ + if (GetFocusPosition(Center)) + return true; + + if (GetSelectionCenter(Center)) + return true; + + Center = lcVector3(0.0f, 0.0f, 0.0f); + + return false; +} + lcVector3 lcModel::GetFocusOrSelectionCenter() const { lcVector3 Center; - if (GetFocusPosition(Center)) - return Center; + GetFocusOrSelectionCenter(Center); - if (GetSelectionCenter(Center)) - return Center; - - return lcVector3(0.0f, 0.0f, 0.0f); + return Center; } bool lcModel::GetFocusPosition(lcVector3& Position) const diff --git a/common/lc_model.h b/common/lc_model.h index dbd07414..67d9697f 100644 --- a/common/lc_model.h +++ b/common/lc_model.h @@ -231,6 +231,7 @@ public: bool AnyPiecesSelected() const; bool AnyObjectsSelected() const; bool GetPieceFocusOrSelectionCenter(lcVector3& Center) const; + bool GetFocusOrSelectionCenter(lcVector3& Center) const; lcVector3 GetFocusOrSelectionCenter() const; bool GetFocusPosition(lcVector3& Position) const; lcObject* GetFocusObject() const; diff --git a/common/view.cpp b/common/view.cpp index 14e14f9d..a4c7ca0a 100644 --- a/common/view.cpp +++ b/common/view.cpp @@ -1471,6 +1471,12 @@ void View::UpdateTrackTool() const float OverlayRotateArrowStart = 1.0f * OverlayScale; const float OverlayRotateArrowEnd = 1.5f * OverlayScale; + NewTrackTool = (CurrentTool == LC_TOOL_MOVE) ? LC_TRACKTOOL_MOVE_XYZ : LC_TRACKTOOL_SELECT; + + lcVector3 OverlayCenter; + if (!mModel->GetFocusOrSelectionCenter(OverlayCenter)) + break; + // Intersect the mouse with the 3 planes. lcVector3 PlaneNormals[3] = { @@ -1480,12 +1486,10 @@ void View::UpdateTrackTool() }; lcMatrix44 RelativeRotation = mModel->GetRelativeRotation(); - lcVector3 OverlayCenter = mModel->GetFocusOrSelectionCenter(); for (int i = 0; i < 3; i++) PlaneNormals[i] = lcMul30(PlaneNormals[i], RelativeRotation); - NewTrackTool = (CurrentTool == LC_TOOL_MOVE) ? LC_TRACKTOOL_MOVE_XYZ : LC_TRACKTOOL_SELECT; lcVector3 StartEnd[2] = { lcVector3((float)x, (float)y, 0.0f), lcVector3((float)x, (float)y, 1.0f) }; UnprojectPoints(StartEnd, 2); const lcVector3& Start = StartEnd[0]; @@ -1556,14 +1560,18 @@ void View::UpdateTrackTool() const float OverlayScale = GetOverlayScale(); const float OverlayRotateRadius = 2.0f; + NewTrackTool = LC_TRACKTOOL_ROTATE_XYZ; + + lcVector3 OverlayCenter; + if (!mModel->GetFocusOrSelectionCenter(OverlayCenter)) + break; + // Calculate the distance from the mouse pointer to the center of the sphere. lcVector3 StartEnd[2] = { lcVector3((float)x, (float)y, 0.0f), lcVector3((float)x, (float)y, 1.0f) }; UnprojectPoints(StartEnd, 2); const lcVector3& SegStart = StartEnd[0]; const lcVector3& SegEnd = StartEnd[1]; - NewTrackTool = LC_TRACKTOOL_ROTATE_XYZ; - lcVector3 OverlayCenter = mModel->GetFocusOrSelectionCenter(); lcVector3 Line = SegEnd - SegStart; lcVector3 Vec = OverlayCenter - SegStart;