diff --git a/common/camera.cpp b/common/camera.cpp index b261a84e..b28479e2 100644 --- a/common/camera.cpp +++ b/common/camera.cpp @@ -488,8 +488,9 @@ void lcCamera::CopyPosition(const lcCamera* camera) mState |= (camera->mState&LC_CAMERA_ORTHO); } -void lcCamera::DrawInterface(lcContext* Context) const +void lcCamera::DrawInterface(lcContext* Context, const lcScene& Scene) const { + Q_UNUSED(Scene); Context->SetMaterial(LC_MATERIAL_UNLIT_COLOR); lcMatrix44 ViewWorldMatrix = lcMatrix44AffineInverse(mWorldView); diff --git a/common/camera.h b/common/camera.h index 9ffe03c0..513278b7 100644 --- a/common/camera.h +++ b/common/camera.h @@ -261,7 +261,7 @@ public: public: virtual void RayTest(lcObjectRayTest& ObjectRayTest) const override; virtual void BoxTest(lcObjectBoxTest& ObjectBoxTest) const override; - virtual void DrawInterface(lcContext* Context) const override; + virtual void DrawInterface(lcContext* Context, const lcScene& Scene) const override; virtual void RemoveKeyFrames() override; void InsertTime(lcStep Start, lcStep Time); diff --git a/common/lc_model.cpp b/common/lc_model.cpp index 81f328b1..b4543f80 100644 --- a/common/lc_model.cpp +++ b/common/lc_model.cpp @@ -1251,10 +1251,10 @@ void lcModel::DuplicateSelectedPieces() SaveCheckpoint(tr("Duplicating Pieces")); } -void lcModel::GetScene(lcScene& Scene, lcCamera* ViewCamera, bool DrawInterface, bool Highlight, lcPiece* ActiveSubmodelInstance) const +void lcModel::GetScene(lcScene& Scene, lcCamera* ViewCamera, bool DrawInterface, bool Highlight, lcPiece* ActiveSubmodelInstance, const lcMatrix44& ActiveSubmodelTransform) const { Scene.Begin(ViewCamera->mWorldView); - Scene.SetActiveSubmodelInstance(ActiveSubmodelInstance); + Scene.SetActiveSubmodelInstance(ActiveSubmodelInstance, ActiveSubmodelTransform); Scene.SetDrawInterface(DrawInterface); mPieceInfo->AddRenderMesh(Scene); diff --git a/common/lc_model.h b/common/lc_model.h index cefa7f0f..1f60d9c5 100644 --- a/common/lc_model.h +++ b/common/lc_model.h @@ -233,7 +233,7 @@ public: void Paste(); void DuplicateSelectedPieces(); - void GetScene(lcScene& Scene, lcCamera* ViewCamera, bool DrawInterface, bool Highlight, lcPiece* ActiveSubmodelInstance) const; + void GetScene(lcScene& Scene, lcCamera* ViewCamera, bool DrawInterface, bool Highlight, lcPiece* ActiveSubmodelInstance, const lcMatrix44& ActiveSubmodelTransform) const; void AddSubModelRenderMeshes(lcScene& Scene, const lcMatrix44& WorldMatrix, int DefaultColorIndex, lcRenderMeshState RenderMeshState, bool ParentActive) const; void DrawBackground(lcGLWidget* Widget); void SaveStepImages(const QString& BaseName, bool AddStepSuffix, bool Zoom, bool Highlight, int Width, int Height, lcStep Start, lcStep End); diff --git a/common/lc_scene.cpp b/common/lc_scene.cpp index 90b8321f..93e4217e 100644 --- a/common/lc_scene.cpp +++ b/common/lc_scene.cpp @@ -378,5 +378,5 @@ void lcScene::Draw(lcContext* Context) const void lcScene::DrawInterfaceObjects(lcContext* Context) const { for (const lcObject* Object : mInterfaceObjects) - Object->DrawInterface(Context); + Object->DrawInterface(Context, *this); } diff --git a/common/lc_scene.h b/common/lc_scene.h index 5c02d909..b2396e08 100644 --- a/common/lc_scene.h +++ b/common/lc_scene.h @@ -8,9 +8,10 @@ class lcScene public: lcScene(); - void SetActiveSubmodelInstance(lcPiece* ActiveSubmodelInstance) + void SetActiveSubmodelInstance(lcPiece* ActiveSubmodelInstance, const lcMatrix44& ActiveSubmodelTransform) { mActiveSubmodelInstance = ActiveSubmodelInstance; + mActiveSubmodelTransform = ActiveSubmodelTransform; } lcPiece* GetActiveSubmodelInstance() const @@ -33,6 +34,11 @@ public: mAllowWireframe = AllowWireframe; } + lcMatrix44 ApplyActiveSubmodelTransform(const lcMatrix44& WorldMatrix) const + { + return !mActiveSubmodelInstance ? WorldMatrix : lcMul(WorldMatrix, mActiveSubmodelTransform); + } + void Begin(const lcMatrix44& ViewMatrix); void End(); void AddMesh(lcMesh* Mesh, const lcMatrix44& WorldMatrix, int ColorIndex, lcRenderMeshState State, int Flags); @@ -49,6 +55,7 @@ protected: void DrawRenderMeshes(lcContext* Context, int PrimitiveTypes, bool EnableNormals, bool DrawTranslucent, bool DrawTextured) const; lcMatrix44 mViewMatrix; + lcMatrix44 mActiveSubmodelTransform; lcPiece* mActiveSubmodelInstance; bool mDrawInterface; bool mAllowWireframe; diff --git a/common/light.cpp b/common/light.cpp index 44dd78db..742f5025 100644 --- a/common/light.cpp +++ b/common/light.cpp @@ -282,8 +282,9 @@ void lcLight::UpdatePosition(lcStep Step) } } -void lcLight::DrawInterface(lcContext* Context) const +void lcLight::DrawInterface(lcContext* Context, const lcScene& Scene) const { + Q_UNUSED(Scene); Context->SetMaterial(LC_MATERIAL_UNLIT_COLOR); if (IsPointLight()) diff --git a/common/light.h b/common/light.h index ccda1b42..fd06dd4c 100644 --- a/common/light.h +++ b/common/light.h @@ -177,7 +177,7 @@ public: public: virtual void RayTest(lcObjectRayTest& ObjectRayTest) const override; virtual void BoxTest(lcObjectBoxTest& ObjectBoxTest) const override; - virtual void DrawInterface(lcContext* Context) const override; + virtual void DrawInterface(lcContext* Context, const lcScene& Scene) const override; virtual void RemoveKeyFrames() override; void InsertTime(lcStep Start, lcStep Time); diff --git a/common/object.h b/common/object.h index 702c4f73..6f9d5e1c 100644 --- a/common/object.h +++ b/common/object.h @@ -94,7 +94,7 @@ public: virtual lcVector3 GetSectionPosition(quint32 Section) const = 0; virtual void RayTest(lcObjectRayTest& ObjectRayTest) const = 0; virtual void BoxTest(lcObjectBoxTest& ObjectBoxTest) const = 0; - virtual void DrawInterface(lcContext* Context) const = 0; + virtual void DrawInterface(lcContext* Context, const lcScene& Scene) const = 0; virtual void RemoveKeyFrames() = 0; virtual const char* GetName() const = 0; diff --git a/common/piece.cpp b/common/piece.cpp index 755119eb..3d122fe5 100644 --- a/common/piece.cpp +++ b/common/piece.cpp @@ -509,7 +509,7 @@ void lcPiece::BoxTest(lcObjectBoxTest& ObjectBoxTest) const ObjectBoxTest.Objects.Add(const_cast(this)); } -void lcPiece::DrawInterface(lcContext* Context) const +void lcPiece::DrawInterface(lcContext* Context, const lcScene& Scene) const { float LineWidth = lcGetPreferences().mLineWidth; Context->SetLineWidth(2.0f * LineWidth); @@ -554,8 +554,9 @@ void lcPiece::DrawInterface(lcContext* Context) const { Min[0], Min[1], Min[2] }, { Min[0], Min[1], Min[2] + Edge[2] }, }; + lcMatrix44 WorldMatrix = Scene.ApplyActiveSubmodelTransform(mModelWorld); Context->SetMaterial(LC_MATERIAL_UNLIT_COLOR); - Context->SetWorldMatrix(mModelWorld); + Context->SetWorldMatrix(WorldMatrix); if (IsFocused(LC_PIECE_SECTION_POSITION)) Context->SetInterfaceColor(LC_COLOR_FOCUSED); @@ -581,7 +582,7 @@ void lcPiece::DrawInterface(lcContext* Context) const 0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 4, 1, 5, 2, 6, 3, 7 }; - Context->SetWorldMatrix(lcMul(mPivotMatrix, mModelWorld)); + Context->SetWorldMatrix(lcMul(mPivotMatrix, WorldMatrix)); Context->SetVertexBufferPointer(Verts); Context->SetVertexFormatPosition(3); @@ -618,7 +619,7 @@ void lcPiece::DrawInterface(lcContext* Context) const for (int ControlPointIdx = 0; ControlPointIdx < mControlPoints.GetSize(); ControlPointIdx++) { - Context->SetWorldMatrix(lcMul(mControlPoints[ControlPointIdx].Transform, mModelWorld)); + Context->SetWorldMatrix(lcMul(mControlPoints[ControlPointIdx].Transform, WorldMatrix)); Context->SetVertexBufferPointer(Verts); Context->SetVertexFormatPosition(3); diff --git a/common/piece.h b/common/piece.h index 8aa2b465..e80ea011 100644 --- a/common/piece.h +++ b/common/piece.h @@ -344,7 +344,7 @@ public: virtual void RayTest(lcObjectRayTest& ObjectRayTest) const override; virtual void BoxTest(lcObjectBoxTest& ObjectBoxTest) const override; - virtual void DrawInterface(lcContext* Context) const override; + virtual void DrawInterface(lcContext* Context, const lcScene& Scene) const override; virtual void RemoveKeyFrames() override; void AddMainModelRenderMeshes(lcScene& Scene, bool Highlight) const; diff --git a/common/view.cpp b/common/view.cpp index b0efd3c7..4fd3a61e 100644 --- a/common/view.cpp +++ b/common/view.cpp @@ -66,8 +66,8 @@ void View::SetSelectedSubmodelActive() if (Piece->mPieceInfo->IsModel()) { - mActiveSubmodelMatrix = lcMatrix44Identity(); - mModel->GetPieceWorldMatrix(Piece, mActiveSubmodelMatrix); + mActiveSubmodelTransform = lcMatrix44Identity(); + mModel->GetPieceWorldMatrix(Piece, mActiveSubmodelTransform); mActiveSubmodelInstance = Piece; lcModel* Model = mActiveSubmodelInstance->mPieceInfo->GetModel(); Model->SetActive(true); @@ -606,7 +606,7 @@ lcObjectSection View::FindObjectUnderPointer(bool PiecesOnly, bool IgnoreSelecte if (ActiveModel != mModel) { - lcMatrix44 InverseMatrix = lcMatrix44AffineInverse(mActiveSubmodelMatrix); + lcMatrix44 InverseMatrix = lcMatrix44AffineInverse(mActiveSubmodelTransform); ObjectRayTest.Start = lcMul31(ObjectRayTest.Start, InverseMatrix); ObjectRayTest.End = lcMul31(ObjectRayTest.End, InverseMatrix); @@ -712,7 +712,7 @@ void View::OnDraw() bool DrawInterface = mWidget != nullptr; - mModel->GetScene(mScene, mCamera, DrawInterface, mHighlight, mActiveSubmodelInstance); + mModel->GetScene(mScene, mCamera, DrawInterface, mHighlight, mActiveSubmodelInstance, mActiveSubmodelTransform); if (DrawInterface && mTrackTool == LC_TRACKTOOL_INSERT) { @@ -853,7 +853,7 @@ void View::DrawSelectMoveOverlay() lcMatrix44 WorldMatrix = lcMatrix44(RelativeRotation, OverlayCenter); if (ActiveModel != mModel) - WorldMatrix = lcMul(WorldMatrix, mActiveSubmodelMatrix); + WorldMatrix = lcMul(WorldMatrix, mActiveSubmodelTransform); const float OverlayScale = GetOverlayScale(); WorldMatrix = lcMul(lcMatrix44Scale(lcVector3(OverlayScale, OverlayScale, OverlayScale)), WorldMatrix); diff --git a/common/view.h b/common/view.h index 7a20decc..a029021e 100644 --- a/common/view.h +++ b/common/view.h @@ -172,7 +172,7 @@ protected: lcModel* mModel; lcPiece* mActiveSubmodelInstance; - lcMatrix44 mActiveSubmodelMatrix; + lcMatrix44 mActiveSubmodelTransform; lcScene mScene; lcDragState mDragState;