Fixed wrong mouse cursor when nothing is selected.

This commit is contained in:
leo 2015-01-18 04:41:06 +00:00
parent 876a2d9bcc
commit e1e2fcc26a
3 changed files with 28 additions and 10 deletions

View file

@ -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

View file

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

View file

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