Skip to content

Commit

Permalink
Fixed train track gizmo drawing when a rotated connection has focus.
Browse files Browse the repository at this point in the history
  • Loading branch information
leozide committed Dec 9, 2024
1 parent ff23653 commit 24b7c43
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 57 deletions.
33 changes: 23 additions & 10 deletions common/lc_viewmanipulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(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);

Expand Down
82 changes: 82 additions & 0 deletions common/piece.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<lcTrainTrackConnection>& 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<lcTrainTrackConnection>& 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)
Expand Down
49 changes: 2 additions & 47 deletions common/piece.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,53 +283,8 @@ class lcPiece : public lcObject
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()
{
Expand Down

0 comments on commit 24b7c43

Please sign in to comment.