diff --git a/common/lc_model.cpp b/common/lc_model.cpp index c171e6bf..2793e42e 100644 --- a/common/lc_model.cpp +++ b/common/lc_model.cpp @@ -1080,6 +1080,29 @@ bool lcModel::GetSelectionCenter(lcVector3& Center) const return Selected; } +bool lcModel::GetPiecesBoundingBox(float BoundingBox[6]) const +{ + if (mPieces.IsEmpty()) + return false; + + BoundingBox[0] = FLT_MAX; + BoundingBox[1] = FLT_MAX; + BoundingBox[2] = FLT_MAX; + BoundingBox[3] = -FLT_MAX; + BoundingBox[4] = -FLT_MAX; + BoundingBox[5] = -FLT_MAX; + + for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++) + { + lcPiece* Piece = mPieces[PieceIdx]; + + if (Piece->IsVisible(mCurrentStep)) + Piece->CompareBoundingBox(BoundingBox); + } + + return true; +} + void lcModel::UpdateSelection() const { int Flags = 0; diff --git a/common/lc_model.h b/common/lc_model.h index 52fa1d05..152579bd 100644 --- a/common/lc_model.h +++ b/common/lc_model.h @@ -152,6 +152,8 @@ public: bool GetFocusPosition(lcVector3& Position) const; lcObject* GetFocusObject() const; bool GetSelectionCenter(lcVector3& Center) const; + bool GetPiecesBoundingBox(float BoundingBox[6]) const; + void FocusOrDeselectObject(const lcObjectSection& ObjectSection); void ClearSelectionAndSetFocus(lcObject* Object, lcuint32 Section); void ClearSelectionAndSetFocus(const lcObjectSection& ObjectSection); diff --git a/common/project.cpp b/common/project.cpp index 09cabd26..ff9c8f0c 100644 --- a/common/project.cpp +++ b/common/project.cpp @@ -1257,91 +1257,25 @@ void Project::RenderSceneObjects(View* view) Context->SetLineWidth(Preferences.mLineWidth); // context remove } -bool Project::GetPiecesBoundingBox(View* view, float BoundingBox[6]) -{ - if (mPieces.IsEmpty() && view->mTrackTool != LC_TRACKTOOL_INSERT) - return false; - - BoundingBox[0] = FLT_MAX; - BoundingBox[1] = FLT_MAX; - BoundingBox[2] = FLT_MAX; - BoundingBox[3] = -FLT_MAX; - BoundingBox[4] = -FLT_MAX; - BoundingBox[5] = -FLT_MAX; - - for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++) - { - lcPiece* Piece = mPieces[PieceIdx]; - - if (Piece->IsVisible(mCurrentStep)) - Piece->CompareBoundingBox(BoundingBox); - } - - if (view->mTrackTool == LC_TRACKTOOL_INSERT) - { - lcVector3 Position; - lcVector4 Rotation; - GetPieceInsertPosition(view, Position, Rotation); - PieceInfo* CurPiece = gMainWindow->mPreviewWidget->GetCurrentPiece(); - - lcVector3 Points[8] = - { - lcVector3(CurPiece->m_fDimensions[0], CurPiece->m_fDimensions[1], CurPiece->m_fDimensions[5]), - lcVector3(CurPiece->m_fDimensions[3], CurPiece->m_fDimensions[1], CurPiece->m_fDimensions[5]), - lcVector3(CurPiece->m_fDimensions[0], CurPiece->m_fDimensions[1], CurPiece->m_fDimensions[2]), - lcVector3(CurPiece->m_fDimensions[3], CurPiece->m_fDimensions[4], CurPiece->m_fDimensions[5]), - lcVector3(CurPiece->m_fDimensions[3], CurPiece->m_fDimensions[4], CurPiece->m_fDimensions[2]), - lcVector3(CurPiece->m_fDimensions[0], CurPiece->m_fDimensions[4], CurPiece->m_fDimensions[2]), - lcVector3(CurPiece->m_fDimensions[0], CurPiece->m_fDimensions[4], CurPiece->m_fDimensions[5]), - lcVector3(CurPiece->m_fDimensions[3], CurPiece->m_fDimensions[1], CurPiece->m_fDimensions[2]) - }; - - lcMatrix44 ModelWorld = lcMatrix44FromAxisAngle(lcVector3(Rotation[0], Rotation[1], Rotation[2]), Rotation[3] * LC_DTOR); - ModelWorld.SetTranslation(Position); - - for (int i = 0; i < 8; i++) - { - lcVector3 Point = lcMul31(Points[i], ModelWorld); - - if (Point[0] < BoundingBox[0]) BoundingBox[0] = Point[0]; - if (Point[1] < BoundingBox[1]) BoundingBox[1] = Point[1]; - if (Point[2] < BoundingBox[2]) BoundingBox[2] = Point[2]; - if (Point[0] > BoundingBox[3]) BoundingBox[3] = Point[0]; - if (Point[1] > BoundingBox[4]) BoundingBox[4] = Point[1]; - if (Point[2] > BoundingBox[5]) BoundingBox[5] = Point[2]; - } - } - - return true; -} - void Project::ZoomExtents(int FirstView, int LastView) { - if (mPieces.IsEmpty()) + float BoundingBox[6]; + + if (!GetPiecesBoundingBox(BoundingBox)) return; - float bs[6] = { 10000, 10000, 10000, -10000, -10000, -10000 }; - - for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++) - { - lcPiece* Piece = mPieces[PieceIdx]; - - if (Piece->IsVisible(mCurrentStep)) - Piece->CompareBoundingBox(bs); - } - - lcVector3 Center((bs[0] + bs[3]) / 2, (bs[1] + bs[4]) / 2, (bs[2] + bs[5]) / 2); + lcVector3 Center((BoundingBox[0] + BoundingBox[3]) / 2, (BoundingBox[1] + BoundingBox[4]) / 2, (BoundingBox[2] + BoundingBox[5]) / 2); lcVector3 Points[8] = { - lcVector3(bs[0], bs[1], bs[5]), - lcVector3(bs[3], bs[1], bs[5]), - lcVector3(bs[0], bs[1], bs[2]), - lcVector3(bs[3], bs[4], bs[5]), - lcVector3(bs[3], bs[4], bs[2]), - lcVector3(bs[0], bs[4], bs[2]), - lcVector3(bs[0], bs[4], bs[5]), - lcVector3(bs[3], bs[1], bs[2]) + lcVector3(BoundingBox[0], BoundingBox[1], BoundingBox[5]), + lcVector3(BoundingBox[3], BoundingBox[1], BoundingBox[5]), + lcVector3(BoundingBox[0], BoundingBox[1], BoundingBox[2]), + lcVector3(BoundingBox[3], BoundingBox[4], BoundingBox[5]), + lcVector3(BoundingBox[3], BoundingBox[4], BoundingBox[2]), + lcVector3(BoundingBox[0], BoundingBox[4], BoundingBox[2]), + lcVector3(BoundingBox[0], BoundingBox[4], BoundingBox[5]), + lcVector3(BoundingBox[3], BoundingBox[1], BoundingBox[2]) }; const lcArray Views = gMainWindow->GetViews(); @@ -4031,12 +3965,12 @@ void Project::HandleCommand(LC_COMMANDS id) if (!GetSelectionCenter(Center)) { - float bs[6] = { 10000, 10000, 10000, -10000, -10000, -10000 }; + float BoundingBox[6]; - for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++) - mPieces[PieceIdx]->CompareBoundingBox(bs); - - Center = lcVector3((bs[0] + bs[3]) * 0.5f, (bs[1] + bs[4]) * 0.5f, (bs[2] + bs[5]) * 0.5f); + if (GetPiecesBoundingBox(BoundingBox)) + Center = lcVector3((BoundingBox[0] + BoundingBox[3]) / 2, (BoundingBox[1] + BoundingBox[4]) / 2, (BoundingBox[2] + BoundingBox[5]) / 2); + else + Center = lcVector3(0.0f, 0.0f, 0.0f); } gMainWindow->GetActiveView()->mCamera->Center(Center, mCurrentStep, gMainWindow->GetAddKeys()); diff --git a/common/project.h b/common/project.h index 90569cdf..bdcfb526 100644 --- a/common/project.h +++ b/common/project.h @@ -96,7 +96,6 @@ public: public: void LoadDefaults(); - bool GetPiecesBoundingBox(View* view, float BoundingBox[6]); void GetPiecesUsed(lcArray& PiecesUsed) const; void CreateImages(Image* images, int width, int height, lcStep from, lcStep to, bool hilite); void Render(View* view, bool bToMemory); diff --git a/common/view.cpp b/common/view.cpp index 84402341..4a981ae4 100644 --- a/common/view.cpp +++ b/common/view.cpp @@ -8,6 +8,8 @@ #include "tr.h" #include "texfont.h" #include "lc_texture.h" +#include "preview.h" +#include "pieceinf.h" View::View(Project *project) { @@ -879,7 +881,46 @@ void View::DrawGrid() int MinX, MaxX, MinY, MaxY; float BoundingBox[6]; - if (mProject->GetPiecesBoundingBox(this, BoundingBox)) + bool GridSizeValid = mProject->GetPiecesBoundingBox(BoundingBox); + + if (mTrackTool == LC_TRACKTOOL_INSERT) + { + lcVector3 Position; + lcVector4 Rotation; + mProject->GetPieceInsertPosition(this, Position, Rotation); + PieceInfo* CurPiece = gMainWindow->mPreviewWidget->GetCurrentPiece(); + + lcVector3 Points[8] = + { + lcVector3(CurPiece->m_fDimensions[0], CurPiece->m_fDimensions[1], CurPiece->m_fDimensions[5]), + lcVector3(CurPiece->m_fDimensions[3], CurPiece->m_fDimensions[1], CurPiece->m_fDimensions[5]), + lcVector3(CurPiece->m_fDimensions[0], CurPiece->m_fDimensions[1], CurPiece->m_fDimensions[2]), + lcVector3(CurPiece->m_fDimensions[3], CurPiece->m_fDimensions[4], CurPiece->m_fDimensions[5]), + lcVector3(CurPiece->m_fDimensions[3], CurPiece->m_fDimensions[4], CurPiece->m_fDimensions[2]), + lcVector3(CurPiece->m_fDimensions[0], CurPiece->m_fDimensions[4], CurPiece->m_fDimensions[2]), + lcVector3(CurPiece->m_fDimensions[0], CurPiece->m_fDimensions[4], CurPiece->m_fDimensions[5]), + lcVector3(CurPiece->m_fDimensions[3], CurPiece->m_fDimensions[1], CurPiece->m_fDimensions[2]) + }; + + lcMatrix44 ModelWorld = lcMatrix44FromAxisAngle(lcVector3(Rotation[0], Rotation[1], Rotation[2]), Rotation[3] * LC_DTOR); + ModelWorld.SetTranslation(Position); + + for (int i = 0; i < 8; i++) + { + lcVector3 Point = lcMul31(Points[i], ModelWorld); + + if (Point[0] < BoundingBox[0]) BoundingBox[0] = Point[0]; + if (Point[1] < BoundingBox[1]) BoundingBox[1] = Point[1]; + if (Point[2] < BoundingBox[2]) BoundingBox[2] = Point[2]; + if (Point[0] > BoundingBox[3]) BoundingBox[3] = Point[0]; + if (Point[1] > BoundingBox[4]) BoundingBox[4] = Point[1]; + if (Point[2] > BoundingBox[5]) BoundingBox[5] = Point[2]; + } + + GridSizeValid = true; + } + + if (GridSizeValid) { MinX = (int)(floorf(BoundingBox[0] / (20.0f * Spacing))) - 1; MinY = (int)(floorf(BoundingBox[1] / (20.0f * Spacing))) - 1; diff --git a/qt/lc_qmainwindow.cpp b/qt/lc_qmainwindow.cpp index 7b2265e0..9aa7316b 100644 --- a/qt/lc_qmainwindow.cpp +++ b/qt/lc_qmainwindow.cpp @@ -373,7 +373,7 @@ void lcQMainWindow::createToolBars() QAction* angleAction = new QAction(tr("Snap Rotate"), this); angleAction->setStatusTip(tr("Snap rotations to fixed intervals")); angleAction->setIcon(QIcon(":/resources/edit_snap_angle.png")); - angleAction->setMenu(snapMenu); + angleAction->setMenu(snapAngleMenu); standardToolBar = addToolBar(tr("Standard")); standardToolBar->setObjectName("StandardToolbar");