Added helper functions to encode/decode mTrackToolSection.

This commit is contained in:
Leonardo Zide 2024-12-17 12:37:00 -08:00
parent 24b7c43a09
commit 5e0df56351
4 changed files with 19 additions and 8 deletions

View file

@ -9,12 +9,11 @@
// auto replace cross when going over a straight section // auto replace cross when going over a straight section
// redo gizmo // redo gizmo
// add cross to gizmo // add cross to gizmo
// new rotate connection gizmo
// rotate around connections shortcut // rotate around connections shortcut
// shortcuts for changing active connection // shortcuts for changing active connection
// move config to json // move config to json
// add other track types // add other track types
// macros to encode/decode mTrackToolSection
// better transform and connection selection when adding with the keyboard, keep the same curve direction and use straight for branches
// set focus connection after adding // set focus connection after adding
void lcTrainTrackInit(lcPiecesLibrary* Library) void lcTrainTrackInit(lcPiecesLibrary* Library)
@ -55,8 +54,8 @@ void lcTrainTrackInit(lcPiecesLibrary* Library)
{ {
lcTrainTrackInfo* TrainTrackInfo = new lcTrainTrackInfo(); lcTrainTrackInfo* TrainTrackInfo = new lcTrainTrackInfo();
TrainTrackInfo->AddConnection({lcMatrix44(lcMatrix33RotationZ(LC_PI), lcVector3(-320.0f, 0.0f, 0.0f))});
TrainTrackInfo->AddConnection({lcMatrix44Translation(lcVector3(320.0f, 0.0f, 0.0f))}); TrainTrackInfo->AddConnection({lcMatrix44Translation(lcVector3(320.0f, 0.0f, 0.0f))});
TrainTrackInfo->AddConnection({lcMatrix44(lcMatrix33RotationZ(LC_PI), lcVector3(-320.0f, 0.0f, 0.0f))});
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))});
Info->SetTrainTrackInfo(TrainTrackInfo); Info->SetTrainTrackInfo(TrainTrackInfo);
@ -68,8 +67,8 @@ void lcTrainTrackInit(lcPiecesLibrary* Library)
{ {
lcTrainTrackInfo* TrainTrackInfo = new lcTrainTrackInfo(); lcTrainTrackInfo* TrainTrackInfo = new lcTrainTrackInfo();
TrainTrackInfo->AddConnection({lcMatrix44(lcMatrix33RotationZ(LC_PI), lcVector3(-320.0f, 0.0f, 0.0f))});
TrainTrackInfo->AddConnection({lcMatrix44Translation(lcVector3(320.0f, 0.0f, 0.0f))}); TrainTrackInfo->AddConnection({lcMatrix44Translation(lcVector3(320.0f, 0.0f, 0.0f))});
TrainTrackInfo->AddConnection({lcMatrix44(lcMatrix33RotationZ(LC_PI), lcVector3(-320.0f, 0.0f, 0.0f))});
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))});
Info->SetTrainTrackInfo(TrainTrackInfo); Info->SetTrainTrackInfo(TrainTrackInfo);

View file

@ -31,6 +31,19 @@ public:
static std::optional<lcMatrix44> CalculateTransformToConnection(const lcMatrix44& ConnectionTransform, PieceInfo* Info, quint32 ConnectionIndex); static std::optional<lcMatrix44> CalculateTransformToConnection(const lcMatrix44& ConnectionTransform, PieceInfo* Info, quint32 ConnectionIndex);
static int GetPieceConnectionIndex(const lcPiece* Piece1, int ConnectionIndex1, const lcPiece* Piece2); static int GetPieceConnectionIndex(const lcPiece* Piece1, int ConnectionIndex1, const lcPiece* Piece2);
static quint32 EncodeTrackToolSection(quint32 ConnectionIndex, lcTrainTrackType TrainTrackType)
{
return ConnectionIndex | (static_cast<quint32>(TrainTrackType) << 8);
}
static std::pair<quint32, lcTrainTrackType> DecodeTrackToolSection(quint32 TrackToolSection)
{
quint32 ConnectionIndex = TrackToolSection & 0xff;
lcTrainTrackType TrainTrackType = static_cast<lcTrainTrackType>((TrackToolSection >> 8) & 0xff);
return { ConnectionIndex, TrainTrackType };
}
void AddConnection(const lcTrainTrackConnection& TrainTrackConnection) void AddConnection(const lcTrainTrackConnection& TrainTrackConnection)
{ {
mConnections.emplace_back(TrainTrackConnection); mConnections.emplace_back(TrainTrackConnection);

View file

@ -434,8 +434,7 @@ void lcView::UpdatePiecePreview()
if (TrainTrackInfo) if (TrainTrackInfo)
{ {
quint32 ConnectionIndex = mTrackToolSection & 0xff; auto [ConnectionIndex, TrainTrackType] = lcTrainTrackInfo::DecodeTrackToolSection(mTrackToolSection);
lcTrainTrackType TrainTrackType = static_cast<lcTrainTrackType>((mTrackToolSection >> 8) & 0xff);
std::tie(PreviewInfo, mPiecePreviewTransform) = TrainTrackInfo->GetPieceInsertTransform(Piece, ConnectionIndex, TrainTrackType); std::tie(PreviewInfo, mPiecePreviewTransform) = TrainTrackInfo->GetPieceInsertTransform(Piece, ConnectionIndex, TrainTrackType);
@ -2570,7 +2569,7 @@ void lcView::OnButtonDown(lcTrackButton TrackButton)
case lcTrackTool::RotateTrainTrack: case lcTrackTool::RotateTrainTrack:
{ {
quint32 ConnectionIndex = mTrackToolSection & 0xff; auto [ConnectionIndex, TrainTrackType] = lcTrainTrackInfo::DecodeTrackToolSection(mTrackToolSection);
ActiveModel->RotateTrainTrackToolClicked(ConnectionIndex); ActiveModel->RotateTrainTrackToolClicked(ConnectionIndex);

View file

@ -1010,7 +1010,7 @@ std::pair<lcTrackTool, quint32> lcViewManipulator::UpdateSelectMove()
NewTrackTool = lcTrackTool::Insert; NewTrackTool = lcTrackTool::Insert;
ClosestIntersectionDistance = IntersectionDistance; ClosestIntersectionDistance = IntersectionDistance;
NewTrackSection = ConnectionIndex | (VertexIndex << 8); NewTrackSection = lcTrainTrackInfo::EncodeTrackToolSection(ConnectionIndex, static_cast<lcTrainTrackType>(VertexIndex));
} }
} }
} }