Skip to content

Commit

Permalink
Zoom Extents now takes into account the current submodel transform. F…
Browse files Browse the repository at this point in the history
…ixes #953.
  • Loading branch information
leozide committed Nov 14, 2024
1 parent 0829365 commit a4f63fc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
8 changes: 5 additions & 3 deletions common/lc_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1363,7 +1363,7 @@ QImage lcModel::GetStepImage(bool Zoom, int Width, int Height, lcStep Step)
SetTemporaryStep(Step);

if (Zoom)
ZoomExtents(Camera, (float)Width / (float)Height);
ZoomExtents(Camera, (float)Width / (float)Height, lcMatrix44Identity());

View.OnDraw();

Expand Down Expand Up @@ -4504,7 +4504,7 @@ void lcModel::MoveCamera(lcCamera* Camera, const lcVector3& Direction)
SaveCheckpoint(tr("Moving Camera"));
}

void lcModel::ZoomExtents(lcCamera* Camera, float Aspect)
void lcModel::ZoomExtents(lcCamera* Camera, float Aspect, const lcMatrix44& WorldMatrix)
{
std::vector<lcVector3> Points = GetPiecesBoundingBoxPoints();

Expand All @@ -4513,8 +4513,10 @@ void lcModel::ZoomExtents(lcCamera* Camera, float Aspect)

lcVector3 Min(FLT_MAX, FLT_MAX, FLT_MAX), Max(-FLT_MAX, -FLT_MAX, -FLT_MAX);

for (const lcVector3& Point : Points)
for (lcVector3& Point : Points)
{
Point = lcMul31(Point, WorldMatrix);

Min = lcMin(Point, Min);
Max = lcMax(Point, Max);
}
Expand Down
2 changes: 1 addition & 1 deletion common/lc_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ class lcModel
void ZoomRegionToolClicked(lcCamera* Camera, float AspectRatio, const lcVector3& Position, const lcVector3& TargetPosition, const lcVector3* Corners);
void LookAt(lcCamera* Camera);
void MoveCamera(lcCamera* Camera, const lcVector3& Direction);
void ZoomExtents(lcCamera* Camera, float Aspect);
void ZoomExtents(lcCamera* Camera, float Aspect, const lcMatrix44& WorldMatrix);
void Zoom(lcCamera* Camera, float Amount);

void MoveSelectedObjects(const lcVector3& Distance, bool AllowRelative, bool AlternateButtonDrag, bool Update, bool Checkpoint, bool FirstMove)
Expand Down
7 changes: 6 additions & 1 deletion common/lc_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1880,8 +1880,13 @@ void lcView::Zoom(float Amount)
void lcView::ZoomExtents()
{
lcModel* ActiveModel = GetActiveModel();

if (ActiveModel)
ActiveModel->ZoomExtents(mCamera, (float)mWidth / (float)mHeight);
{
const lcMatrix44 WorldMatrix = mActiveSubmodelInstance ? mActiveSubmodelTransform : lcMatrix44Identity();

ActiveModel->ZoomExtents(mCamera, (float)mWidth / (float)mHeight, WorldMatrix);
}
}

lcCursor lcView::GetCursor() const
Expand Down

0 comments on commit a4f63fc

Please sign in to comment.