diff --git a/common/lc_viewmanipulator.cpp b/common/lc_viewmanipulator.cpp index 85e0bfde..4f2b436d 100644 --- a/common/lc_viewmanipulator.cpp +++ b/common/lc_viewmanipulator.cpp @@ -379,24 +379,37 @@ void lcViewManipulator::DrawTrainTrack(lcPiece* Piece, lcContext* Context, float continue; const lcMatrix44& Transform = Connections[ConnectionIndex].Transform; + lcVector3 Start = Transform.GetTranslation(); + lcVector3 Direction = lcVector3(Transform[0]) * 100; + + if (Piece->GetFocusSection() >= LC_PIECE_SECTION_TRAIN_TRACK_CONNECTION_FIRST) + { + quint32 FocusIndex = Piece->GetFocusSection() - LC_PIECE_SECTION_TRAIN_TRACK_CONNECTION_FIRST; + + if (FocusIndex != ConnectionIndex) + continue; + + Start = lcVector3(0.0f, 0.0f, 0.0f); + Direction = lcVector3(100.0f, 0.0f, 0.0f); + } lcVector3 Verts[static_cast(lcTrainTrackType::Count) * 2]; int NumVerts = 0; - Verts[NumVerts++] = Transform.GetTranslation() / OverlayScale; - Verts[NumVerts++] = (Transform.GetTranslation() + lcVector3(Transform[0]) * 100) / OverlayScale; + Verts[NumVerts++] = Start / OverlayScale; + Verts[NumVerts++] = (Start + Direction) / OverlayScale; - Verts[NumVerts++] = Transform.GetTranslation() / OverlayScale; - Verts[NumVerts++] = (Transform.GetTranslation() + lcMul31(lcVector3(Transform[0]), lcMatrix44RotationZ(LC_DTOR * 60)) * 100) / OverlayScale; + Verts[NumVerts++] = Verts[0]; + Verts[NumVerts++] = (Start + lcMul31(Direction, lcMatrix44RotationZ(LC_DTOR * 60))) / OverlayScale; - Verts[NumVerts++] = Transform.GetTranslation() / OverlayScale; - Verts[NumVerts++] = (Transform.GetTranslation() + lcMul31(lcVector3(Transform[0]), lcMatrix44RotationZ(LC_DTOR * -60)) * 100) / OverlayScale; + Verts[NumVerts++] = Verts[0]; + Verts[NumVerts++] = (Start + lcMul31(Direction, lcMatrix44RotationZ(LC_DTOR * -60))) / OverlayScale; - Verts[NumVerts++] = Transform.GetTranslation() / OverlayScale; - Verts[NumVerts++] = (Transform.GetTranslation() + lcMul31(lcVector3(Transform[0]), lcMatrix44RotationZ(LC_DTOR * 30)) * 100) / OverlayScale; + Verts[NumVerts++] = Verts[0]; + Verts[NumVerts++] = (Start + lcMul31(Direction, lcMatrix44RotationZ(LC_DTOR * 30))) / OverlayScale; - Verts[NumVerts++] = Transform.GetTranslation() / OverlayScale; - Verts[NumVerts++] = (Transform.GetTranslation() + lcMul31(lcVector3(Transform[0]), lcMatrix44RotationZ(LC_DTOR * -30)) * 100) / OverlayScale; + Verts[NumVerts++] = Verts[0]; + Verts[NumVerts++] = (Start + lcMul31(Direction, lcMatrix44RotationZ(LC_DTOR * -30))) / OverlayScale; Context->SetColor(1.0f, 1.0f, 1.0f, 1.0f); diff --git a/common/piece.cpp b/common/piece.cpp index 91186ffd..1abf5c04 100644 --- a/common/piece.cpp +++ b/common/piece.cpp @@ -1268,6 +1268,88 @@ lcVector3 lcPiece::GetSectionPosition(quint32 Section) const return lcVector3(0.0f, 0.0f, 0.0f); } +lcVector3 lcPiece::GetRotationCenter() const +{ + const quint32 Section = GetFocusSection(); + + if (Section == LC_PIECE_SECTION_POSITION || Section == LC_PIECE_SECTION_INVALID) + { + if (mPivotPointValid) + return lcMul31(mPivotMatrix.GetTranslation(), mModelWorld); + } + else if (mPieceInfo->GetSynthInfo()) + { + if (Section >= LC_PIECE_SECTION_CONTROL_POINT_FIRST) + { + const quint32 ControlPointIndex = Section - LC_PIECE_SECTION_CONTROL_POINT_FIRST; + + if (ControlPointIndex < mControlPoints.size()) + { + const lcMatrix44& Transform = mControlPoints[ControlPointIndex].Transform; + return lcMul31(Transform.GetTranslation(), mModelWorld); + } + } + } + else if (mPieceInfo->GetTrainTrackInfo()) + { + if (Section >= LC_PIECE_SECTION_TRAIN_TRACK_CONNECTION_FIRST) + { + const quint32 ConnectionIndex = Section - LC_PIECE_SECTION_TRAIN_TRACK_CONNECTION_FIRST; + const std::vector& Connections = mPieceInfo->GetTrainTrackInfo()->GetConnections(); + + if (ConnectionIndex < Connections.size()) + { + const lcMatrix44& Transform = Connections[ConnectionIndex].Transform; + return lcMul(Transform, mModelWorld).GetTranslation(); + } + } + } + + return mModelWorld.GetTranslation(); +} + +lcMatrix33 lcPiece::GetRelativeRotation() const +{ + const quint32 Section = GetFocusSection(); + + if (Section == LC_PIECE_SECTION_POSITION || Section == LC_PIECE_SECTION_INVALID) + { + if (mPivotPointValid) + return lcMatrix33(lcMul(mModelWorld, mPivotMatrix)); + else + return lcMatrix33(mModelWorld); + } + else if (mPieceInfo->GetSynthInfo()) + { + if (Section >= LC_PIECE_SECTION_CONTROL_POINT_FIRST) + { + const quint32 ControlPointIndex = Section - LC_PIECE_SECTION_CONTROL_POINT_FIRST; + + if (ControlPointIndex < mControlPoints.size()) + { + const lcMatrix44& Transform = mControlPoints[ControlPointIndex].Transform; + return lcMatrix33(lcMul(Transform, mModelWorld)); + } + } + } + else if (mPieceInfo->GetTrainTrackInfo()) + { + if (Section >= LC_PIECE_SECTION_TRAIN_TRACK_CONNECTION_FIRST) + { + const quint32 ConnectionIndex = Section - LC_PIECE_SECTION_TRAIN_TRACK_CONNECTION_FIRST; + const std::vector& Connections = mPieceInfo->GetTrainTrackInfo()->GetConnections(); + + if (ConnectionIndex < Connections.size()) + { + const lcMatrix44& Transform = Connections[ConnectionIndex].Transform; + return lcMatrix33(lcMul(Transform, mModelWorld)); + } + } + } + + return lcMatrix33Identity(); +} + bool lcPiece::CanAddControlPoint() const { if (mControlPoints.size() >= LC_MAX_CONTROL_POINTS) diff --git a/common/piece.h b/common/piece.h index 85019a3a..cb7668b3 100644 --- a/common/piece.h +++ b/common/piece.h @@ -283,53 +283,8 @@ public: mRotation.ChangeKey(Rotation, Step, AddKey); } - lcVector3 GetRotationCenter() const - { - const quint32 Section = GetFocusSection(); - - if (Section == LC_PIECE_SECTION_POSITION || Section == LC_PIECE_SECTION_INVALID) - { - if (mPivotPointValid) - return lcMul31(mPivotMatrix.GetTranslation(), mModelWorld); - } - else if (Section >= LC_PIECE_SECTION_CONTROL_POINT_FIRST) - { - const quint32 ControlPointIndex = Section - LC_PIECE_SECTION_CONTROL_POINT_FIRST; - - if (ControlPointIndex < mControlPoints.size()) - { - const lcMatrix44& Transform = mControlPoints[ControlPointIndex].Transform; - return lcMul31(Transform.GetTranslation(), mModelWorld); - } - } - - return mModelWorld.GetTranslation(); - } - - lcMatrix33 GetRelativeRotation() const - { - const quint32 Section = GetFocusSection(); - - if (Section == LC_PIECE_SECTION_POSITION || Section == LC_PIECE_SECTION_INVALID) - { - if (mPivotPointValid) - return lcMatrix33(lcMul(mModelWorld, mPivotMatrix)); - else - return lcMatrix33(mModelWorld); - } - else if (Section >= LC_PIECE_SECTION_CONTROL_POINT_FIRST) - { - const quint32 ControlPointIndex = Section - LC_PIECE_SECTION_CONTROL_POINT_FIRST; - - if (ControlPointIndex < mControlPoints.size()) - { - const lcMatrix44& Transform = mControlPoints[ControlPointIndex].Transform; - return lcMatrix33(lcMul(Transform, mModelWorld)); - } - } - - return lcMatrix33Identity(); - } + lcVector3 GetRotationCenter() const; + lcMatrix33 GetRelativeRotation() const; void ResetPivotPoint() {