mirror of
https://github.com/leozide/leocad
synced 2024-12-26 21:58:44 +01:00
Rotate track while holding left mouse button down and move left or right
This commit is contained in:
parent
511aaf7dd4
commit
f460e65856
5 changed files with 84 additions and 29 deletions
|
@ -13,41 +13,38 @@
|
||||||
// move config to json
|
// move config to json
|
||||||
// add other track types
|
// add other track types
|
||||||
|
|
||||||
std::pair<PieceInfo*, lcMatrix44> lcTrainTrackInfo::GetPieceInsertPosition(lcPiece* Piece, quint32 ConnectionIndex, lcTrainTrackType TrainTrackType) const
|
std::pair<PieceInfo*, lcMatrix44> lcTrainTrackInfo::GetPieceInsertPosition(lcPiece* Piece, quint32 fromConnectionIdx, lcTrainTrackType TrainTrackType, quint32 toConnectionIdx) const
|
||||||
{
|
{
|
||||||
if (ConnectionIndex >= mConnections.size())
|
const char* TrainTrackPieceNames[] =
|
||||||
|
{
|
||||||
|
"74746.dat",
|
||||||
|
"2861c04.dat",
|
||||||
|
"2859c04.dat",
|
||||||
|
"74747.dat",
|
||||||
|
"32087.dat"
|
||||||
|
};
|
||||||
|
|
||||||
|
if (fromConnectionIdx >= mConnections.size())
|
||||||
return { nullptr, lcMatrix44Identity() };
|
return { nullptr, lcMatrix44Identity() };
|
||||||
|
|
||||||
const char* PieceNames[] =
|
PieceInfo* Info = lcGetPiecesLibrary()->FindPiece(TrainTrackPieceNames[static_cast<int>(TrainTrackType)], nullptr, false, false);
|
||||||
{
|
|
||||||
"74746.dat",
|
|
||||||
"74747.dat",
|
|
||||||
"74747.dat",
|
|
||||||
"2861c04.dat",
|
|
||||||
"2859c04.dat"
|
|
||||||
};
|
|
||||||
|
|
||||||
PieceInfo* Info = lcGetPiecesLibrary()->FindPiece(PieceNames[static_cast<int>(TrainTrackType)], nullptr, false, false);
|
|
||||||
|
|
||||||
if (!Info)
|
if (!Info)
|
||||||
return { nullptr, lcMatrix44Identity() };
|
return { nullptr, lcMatrix44Identity() };
|
||||||
|
|
||||||
lcTrainTrackInfo* TrainTrackInfo = Info->GetTrainTrackInfo();
|
lcTrainTrackInfo* TrainTrackInfo = Info->GetTrainTrackInfo();
|
||||||
|
|
||||||
|
toConnectionIdx = toConnectionIdx % TrainTrackInfo->mConnections.size();
|
||||||
|
|
||||||
if (!TrainTrackInfo || TrainTrackInfo->mConnections.empty())
|
if (!TrainTrackInfo || TrainTrackInfo->mConnections.empty())
|
||||||
return { nullptr, lcMatrix44Identity() };
|
return { nullptr, lcMatrix44Identity() };
|
||||||
|
|
||||||
lcMatrix44 Transform;
|
lcMatrix44 Transform;
|
||||||
|
|
||||||
if (TrainTrackType != lcTrainTrackType::Left)
|
Transform = lcMatrix44AffineInverse(TrainTrackInfo->mConnections[toConnectionIdx].Transform);
|
||||||
Transform = TrainTrackInfo->mConnections[0].Transform;
|
Transform = lcMul(Transform, lcMatrix44RotationZ(LC_PI));
|
||||||
else
|
|
||||||
{
|
|
||||||
Transform = lcMatrix44AffineInverse(TrainTrackInfo->mConnections[0].Transform);
|
|
||||||
Transform = lcMul(Transform, lcMatrix44RotationZ(LC_PI));
|
|
||||||
}
|
|
||||||
|
|
||||||
Transform = lcMul(Transform, mConnections[ConnectionIndex].Transform);
|
Transform = lcMul(Transform, mConnections[fromConnectionIdx].Transform);
|
||||||
Transform = lcMul(Transform, Piece->mModelWorld);
|
Transform = lcMul(Transform, Piece->mModelWorld);
|
||||||
|
|
||||||
return { Info, Transform };
|
return { Info, Transform };
|
||||||
|
@ -108,6 +105,20 @@ void lcTrainTrackInit(lcPiecesLibrary* Library)
|
||||||
TrainTrackInfo->AddConnection({lcMatrix44(lcMatrix33RotationZ(-22.5f * LC_DTOR), lcVector3(BranchX, -BranchY, 0.0f))});
|
TrainTrackInfo->AddConnection({lcMatrix44(lcMatrix33RotationZ(-22.5f * LC_DTOR), lcVector3(BranchX, -BranchY, 0.0f))});
|
||||||
TrainTrackInfo->AddConnection({lcMatrix44(lcMatrix33RotationZ(LC_PI), lcVector3(-320.0f, 0.0f, 0.0f))});
|
TrainTrackInfo->AddConnection({lcMatrix44(lcMatrix33RotationZ(LC_PI), lcVector3(-320.0f, 0.0f, 0.0f))});
|
||||||
|
|
||||||
|
Info->SetTrainTrackInfo(TrainTrackInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
Info = Library->FindPiece("32087.dat", nullptr, false, false);
|
||||||
|
|
||||||
|
if (Info)
|
||||||
|
{
|
||||||
|
lcTrainTrackInfo* TrainTrackInfo = new lcTrainTrackInfo();
|
||||||
|
|
||||||
|
TrainTrackInfo->AddConnection({lcMatrix44(lcMatrix33RotationZ(0.0f * LC_DTOR), lcVector3(160.0f, 0.0f, 0.0f))});
|
||||||
|
TrainTrackInfo->AddConnection({lcMatrix44(lcMatrix33RotationZ(90.0f * LC_DTOR), lcVector3(0.0f, 160.0f, 0.0f))});
|
||||||
|
TrainTrackInfo->AddConnection({lcMatrix44(lcMatrix33RotationZ(180.0f * LC_DTOR), lcVector3(-160.0f, 0.0f, 0.0f))});
|
||||||
|
TrainTrackInfo->AddConnection({lcMatrix44(lcMatrix33RotationZ(-90.0f * LC_DTOR), lcVector3(0.0f, -160.0f, 0.0f))});
|
||||||
|
|
||||||
Info->SetTrainTrackInfo(TrainTrackInfo);
|
Info->SetTrainTrackInfo(TrainTrackInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,10 +13,10 @@ struct lcTrainTrackConnection
|
||||||
enum class lcTrainTrackType
|
enum class lcTrainTrackType
|
||||||
{
|
{
|
||||||
Straight,
|
Straight,
|
||||||
|
BranchLeft,
|
||||||
|
BranchRight,
|
||||||
Left,
|
Left,
|
||||||
Right,
|
Cross,
|
||||||
BranchLeft,
|
|
||||||
BranchRight,
|
|
||||||
Count
|
Count
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ class lcTrainTrackInfo
|
||||||
public:
|
public:
|
||||||
lcTrainTrackInfo() = default;
|
lcTrainTrackInfo() = default;
|
||||||
|
|
||||||
std::pair<PieceInfo*, lcMatrix44> GetPieceInsertPosition(lcPiece* Piece, quint32 ConnectionIndex, lcTrainTrackType TrainTrackType) const;
|
std::pair<PieceInfo*, lcMatrix44> GetPieceInsertPosition(lcPiece* Piece, quint32 fromConnectionIdx, lcTrainTrackType TrainTrackType, quint32 toConnectionIdx) const;
|
||||||
|
|
||||||
void AddConnection(const lcTrainTrackConnection& TrainTrackConnection)
|
void AddConnection(const lcTrainTrackConnection& TrainTrackConnection)
|
||||||
{
|
{
|
||||||
|
|
|
@ -436,8 +436,9 @@ void lcView::UpdatePiecePreview()
|
||||||
{
|
{
|
||||||
quint32 ConnectionIndex = mTrackToolSection & 0xff;
|
quint32 ConnectionIndex = mTrackToolSection & 0xff;
|
||||||
lcTrainTrackType TrainTrackType = static_cast<lcTrainTrackType>((mTrackToolSection >> 8) & 0xff);
|
lcTrainTrackType TrainTrackType = static_cast<lcTrainTrackType>((mTrackToolSection >> 8) & 0xff);
|
||||||
|
int toConnectionIdx = (mTrackToolSection >> 16) & 0xFF;
|
||||||
|
|
||||||
std::tie(PreviewInfo, mPiecePreviewTransform) = TrainTrackInfo->GetPieceInsertPosition(Piece, ConnectionIndex, TrainTrackType);
|
std::tie(PreviewInfo, mPiecePreviewTransform) = TrainTrackInfo->GetPieceInsertPosition(Piece, ConnectionIndex, TrainTrackType, toConnectionIdx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -868,7 +869,7 @@ void lcView::OnDraw()
|
||||||
|
|
||||||
mModel->GetScene(mScene.get(), mCamera, Preferences.mHighlightNewParts, Preferences.mFadeSteps);
|
mModel->GetScene(mScene.get(), mCamera, Preferences.mHighlightNewParts, Preferences.mFadeSteps);
|
||||||
|
|
||||||
if (DrawInterface && mTrackTool == lcTrackTool::Insert)
|
if (DrawInterface && mTrackTool == lcTrackTool::RotateTrack)
|
||||||
{
|
{
|
||||||
UpdatePiecePreview();
|
UpdatePiecePreview();
|
||||||
|
|
||||||
|
@ -1931,7 +1932,8 @@ lcCursor lcView::GetCursor() const
|
||||||
lcCursor::RotateY, // lcTrackTool::OrbitY
|
lcCursor::RotateY, // lcTrackTool::OrbitY
|
||||||
lcCursor::RotateView, // lcTrackTool::OrbitXY
|
lcCursor::RotateView, // lcTrackTool::OrbitXY
|
||||||
lcCursor::Roll, // lcTrackTool::Roll
|
lcCursor::Roll, // lcTrackTool::Roll
|
||||||
lcCursor::ZoomRegion // lcTrackTool::ZoomRegion
|
lcCursor::ZoomRegion, // lcTrackTool::ZoomRegion
|
||||||
|
lcCursor::Rotate // lcTrackTool::RotateTrack
|
||||||
};
|
};
|
||||||
|
|
||||||
LC_ARRAY_SIZE_CHECK(CursorFromTrackTool, lcTrackTool::Count);
|
LC_ARRAY_SIZE_CHECK(CursorFromTrackTool, lcTrackTool::Count);
|
||||||
|
@ -2040,7 +2042,8 @@ lcTool lcView::GetCurrentTool() const
|
||||||
lcTool::RotateView, // lcTrackTool::OrbitY
|
lcTool::RotateView, // lcTrackTool::OrbitY
|
||||||
lcTool::RotateView, // lcTrackTool::OrbitXY
|
lcTool::RotateView, // lcTrackTool::OrbitXY
|
||||||
lcTool::Roll, // lcTrackTool::Roll
|
lcTool::Roll, // lcTrackTool::Roll
|
||||||
lcTool::ZoomRegion // lcTrackTool::ZoomRegion
|
lcTool::ZoomRegion, // lcTrackTool::ZoomRegion
|
||||||
|
lcTool::Rotate // lcTrackTool::RotateTrack
|
||||||
};
|
};
|
||||||
|
|
||||||
LC_ARRAY_SIZE_CHECK(ToolFromTrackTool, lcTrackTool::Count);
|
LC_ARRAY_SIZE_CHECK(ToolFromTrackTool, lcTrackTool::Count);
|
||||||
|
@ -2395,6 +2398,24 @@ void lcView::StopTracking(bool Accept)
|
||||||
|
|
||||||
case lcTool::Move:
|
case lcTool::Move:
|
||||||
case lcTool::Rotate:
|
case lcTool::Rotate:
|
||||||
|
|
||||||
|
if(mTrackTool == lcTrackTool::RotateTrack) {
|
||||||
|
|
||||||
|
UpdatePiecePreview();
|
||||||
|
|
||||||
|
if (!mPiecePreviewInfo)
|
||||||
|
break;
|
||||||
|
|
||||||
|
ActiveModel->InsertPieceToolClicked(mPiecePreviewInfo, mPiecePreviewTransform);
|
||||||
|
|
||||||
|
if ((mMouseModifiers & Qt::ControlModifier) == 0)
|
||||||
|
gMainWindow->SetTool(lcTool::Select);
|
||||||
|
|
||||||
|
mToolClicked = true;
|
||||||
|
UpdateTrackTool();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
ActiveModel->EndMouseTool(Tool, Accept);
|
ActiveModel->EndMouseTool(Tool, Accept);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -2586,6 +2607,14 @@ void lcView::OnButtonDown(lcTrackButton TrackButton)
|
||||||
StartTracking(TrackButton);
|
StartTracking(TrackButton);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case lcTrackTool::RotateTrack:
|
||||||
|
{
|
||||||
|
lcObject* Focus = ActiveModel->GetFocusObject();
|
||||||
|
if (Focus && Focus->IsPiece() && ((lcPiece*)Focus)->mPieceInfo->GetTrainTrackInfo())
|
||||||
|
StartTracking(TrackButton);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case lcTrackTool::Count:
|
case lcTrackTool::Count:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -3020,6 +3049,17 @@ void lcView::OnMouseMove()
|
||||||
Redraw();
|
Redraw();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case lcTrackTool::RotateTrack:
|
||||||
|
{
|
||||||
|
int trackRotation = (float)(mMouseX - mMouseDownX) * MouseSensitivity;;
|
||||||
|
trackRotation = abs(trackRotation);
|
||||||
|
mTrackToolSection &= 0xFF00FFFF;
|
||||||
|
mTrackToolSection += (trackRotation << 16);
|
||||||
|
|
||||||
|
Redraw();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case lcTrackTool::Count:
|
case lcTrackTool::Count:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,6 +82,7 @@ enum class lcTrackTool
|
||||||
OrbitXY,
|
OrbitXY,
|
||||||
Roll,
|
Roll,
|
||||||
ZoomRegion,
|
ZoomRegion,
|
||||||
|
RotateTrack,
|
||||||
Count
|
Count
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -772,6 +772,9 @@ bool lcViewManipulator::IsTrackToolAllowed(lcTrackTool TrackTool, quint32 Allowe
|
||||||
case lcTrackTool::ZoomRegion:
|
case lcTrackTool::ZoomRegion:
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
case lcTrackTool::RotateTrack:
|
||||||
|
return true;
|
||||||
|
|
||||||
case lcTrackTool::Count:
|
case lcTrackTool::Count:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -979,7 +982,7 @@ std::pair<lcTrackTool, quint32> lcViewManipulator::UpdateSelectMove()
|
||||||
if (IntersectionDistance > ClosestIntersectionDistance)
|
if (IntersectionDistance > ClosestIntersectionDistance)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
NewTrackTool = lcTrackTool::Insert;
|
NewTrackTool = lcTrackTool::RotateTrack;
|
||||||
ClosestIntersectionDistance = IntersectionDistance;
|
ClosestIntersectionDistance = IntersectionDistance;
|
||||||
NewTrackSection = Section | (VertexIndex << 8);
|
NewTrackSection = Section | (VertexIndex << 8);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue