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
|
||||
// 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())
|
||||
return { nullptr, lcMatrix44Identity() };
|
||||
|
||||
const char* PieceNames[] =
|
||||
const char* TrainTrackPieceNames[] =
|
||||
{
|
||||
"74746.dat",
|
||||
"74747.dat",
|
||||
"74747.dat",
|
||||
"2861c04.dat",
|
||||
"2859c04.dat"
|
||||
"2859c04.dat",
|
||||
"74747.dat",
|
||||
"32087.dat"
|
||||
};
|
||||
|
||||
PieceInfo* Info = lcGetPiecesLibrary()->FindPiece(PieceNames[static_cast<int>(TrainTrackType)], nullptr, false, false);
|
||||
if (fromConnectionIdx >= mConnections.size())
|
||||
return { nullptr, lcMatrix44Identity() };
|
||||
|
||||
PieceInfo* Info = lcGetPiecesLibrary()->FindPiece(TrainTrackPieceNames[static_cast<int>(TrainTrackType)], nullptr, false, false);
|
||||
|
||||
if (!Info)
|
||||
return { nullptr, lcMatrix44Identity() };
|
||||
|
||||
lcTrainTrackInfo* TrainTrackInfo = Info->GetTrainTrackInfo();
|
||||
|
||||
toConnectionIdx = toConnectionIdx % TrainTrackInfo->mConnections.size();
|
||||
|
||||
if (!TrainTrackInfo || TrainTrackInfo->mConnections.empty())
|
||||
return { nullptr, lcMatrix44Identity() };
|
||||
|
||||
lcMatrix44 Transform;
|
||||
|
||||
if (TrainTrackType != lcTrainTrackType::Left)
|
||||
Transform = TrainTrackInfo->mConnections[0].Transform;
|
||||
else
|
||||
{
|
||||
Transform = lcMatrix44AffineInverse(TrainTrackInfo->mConnections[0].Transform);
|
||||
Transform = lcMatrix44AffineInverse(TrainTrackInfo->mConnections[toConnectionIdx].Transform);
|
||||
Transform = lcMul(Transform, lcMatrix44RotationZ(LC_PI));
|
||||
}
|
||||
|
||||
Transform = lcMul(Transform, mConnections[ConnectionIndex].Transform);
|
||||
Transform = lcMul(Transform, mConnections[fromConnectionIdx].Transform);
|
||||
Transform = lcMul(Transform, Piece->mModelWorld);
|
||||
|
||||
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(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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,10 +13,10 @@ struct lcTrainTrackConnection
|
|||
enum class lcTrainTrackType
|
||||
{
|
||||
Straight,
|
||||
Left,
|
||||
Right,
|
||||
BranchLeft,
|
||||
BranchRight,
|
||||
Left,
|
||||
Cross,
|
||||
Count
|
||||
};
|
||||
|
||||
|
@ -25,7 +25,7 @@ class lcTrainTrackInfo
|
|||
public:
|
||||
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)
|
||||
{
|
||||
|
|
|
@ -436,8 +436,9 @@ void lcView::UpdatePiecePreview()
|
|||
{
|
||||
quint32 ConnectionIndex = mTrackToolSection & 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);
|
||||
|
||||
if (DrawInterface && mTrackTool == lcTrackTool::Insert)
|
||||
if (DrawInterface && mTrackTool == lcTrackTool::RotateTrack)
|
||||
{
|
||||
UpdatePiecePreview();
|
||||
|
||||
|
@ -1931,7 +1932,8 @@ lcCursor lcView::GetCursor() const
|
|||
lcCursor::RotateY, // lcTrackTool::OrbitY
|
||||
lcCursor::RotateView, // lcTrackTool::OrbitXY
|
||||
lcCursor::Roll, // lcTrackTool::Roll
|
||||
lcCursor::ZoomRegion // lcTrackTool::ZoomRegion
|
||||
lcCursor::ZoomRegion, // lcTrackTool::ZoomRegion
|
||||
lcCursor::Rotate // lcTrackTool::RotateTrack
|
||||
};
|
||||
|
||||
LC_ARRAY_SIZE_CHECK(CursorFromTrackTool, lcTrackTool::Count);
|
||||
|
@ -2040,7 +2042,8 @@ lcTool lcView::GetCurrentTool() const
|
|||
lcTool::RotateView, // lcTrackTool::OrbitY
|
||||
lcTool::RotateView, // lcTrackTool::OrbitXY
|
||||
lcTool::Roll, // lcTrackTool::Roll
|
||||
lcTool::ZoomRegion // lcTrackTool::ZoomRegion
|
||||
lcTool::ZoomRegion, // lcTrackTool::ZoomRegion
|
||||
lcTool::Rotate // lcTrackTool::RotateTrack
|
||||
};
|
||||
|
||||
LC_ARRAY_SIZE_CHECK(ToolFromTrackTool, lcTrackTool::Count);
|
||||
|
@ -2395,6 +2398,24 @@ void lcView::StopTracking(bool Accept)
|
|||
|
||||
case lcTool::Move:
|
||||
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);
|
||||
break;
|
||||
|
||||
|
@ -2586,6 +2607,14 @@ void lcView::OnButtonDown(lcTrackButton TrackButton)
|
|||
StartTracking(TrackButton);
|
||||
break;
|
||||
|
||||
case lcTrackTool::RotateTrack:
|
||||
{
|
||||
lcObject* Focus = ActiveModel->GetFocusObject();
|
||||
if (Focus && Focus->IsPiece() && ((lcPiece*)Focus)->mPieceInfo->GetTrainTrackInfo())
|
||||
StartTracking(TrackButton);
|
||||
}
|
||||
break;
|
||||
|
||||
case lcTrackTool::Count:
|
||||
break;
|
||||
}
|
||||
|
@ -3020,6 +3049,17 @@ void lcView::OnMouseMove()
|
|||
Redraw();
|
||||
break;
|
||||
|
||||
case lcTrackTool::RotateTrack:
|
||||
{
|
||||
int trackRotation = (float)(mMouseX - mMouseDownX) * MouseSensitivity;;
|
||||
trackRotation = abs(trackRotation);
|
||||
mTrackToolSection &= 0xFF00FFFF;
|
||||
mTrackToolSection += (trackRotation << 16);
|
||||
|
||||
Redraw();
|
||||
}
|
||||
break;
|
||||
|
||||
case lcTrackTool::Count:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -82,6 +82,7 @@ enum class lcTrackTool
|
|||
OrbitXY,
|
||||
Roll,
|
||||
ZoomRegion,
|
||||
RotateTrack,
|
||||
Count
|
||||
};
|
||||
|
||||
|
|
|
@ -772,6 +772,9 @@ bool lcViewManipulator::IsTrackToolAllowed(lcTrackTool TrackTool, quint32 Allowe
|
|||
case lcTrackTool::ZoomRegion:
|
||||
return true;
|
||||
|
||||
case lcTrackTool::RotateTrack:
|
||||
return true;
|
||||
|
||||
case lcTrackTool::Count:
|
||||
return false;
|
||||
}
|
||||
|
@ -979,7 +982,7 @@ std::pair<lcTrackTool, quint32> lcViewManipulator::UpdateSelectMove()
|
|||
if (IntersectionDistance > ClosestIntersectionDistance)
|
||||
continue;
|
||||
|
||||
NewTrackTool = lcTrackTool::Insert;
|
||||
NewTrackTool = lcTrackTool::RotateTrack;
|
||||
ClosestIntersectionDistance = IntersectionDistance;
|
||||
NewTrackSection = Section | (VertexIndex << 8);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue