From f891937306dd21a0effb13a9c595bebfb58f3bb6 Mon Sep 17 00:00:00 2001
From: mzernova <mzernova@opencascade.com>
Date: Tue, 4 Feb 2025 16:46:26 +0000
Subject: [PATCH] Fix: don't move grid during panning

---
 src/AIS/AIS_ViewController.cxx     |  4 ++++
 src/Graphic3d/Graphic3d_Camera.hxx | 12 ++++++++++++
 src/OpenGl/OpenGl_View.cxx         |  3 +++
 3 files changed, 19 insertions(+)

diff --git a/src/AIS/AIS_ViewController.cxx b/src/AIS/AIS_ViewController.cxx
index 9a463779af..2ab3858d52 100644
--- a/src/AIS/AIS_ViewController.cxx
+++ b/src/AIS/AIS_ViewController.cxx
@@ -1510,6 +1510,10 @@ void AIS_ViewController::handlePanning (const Handle(V3d_View)& theView)
   AbortViewAnimation();
 
   const Handle(Graphic3d_Camera)& aCam = theView->Camera();
+  aCam->SetPanningVector(aCam->PanningVector() +
+                         gp_Vec2d(theView->Convert(myGL.Panning.Delta.x()),
+                                  theView->Convert(myGL.Panning.Delta.y())));
+
   if (aCam->IsOrthographic()
   || !hasPanningAnchorPoint())
   {
diff --git a/src/Graphic3d/Graphic3d_Camera.hxx b/src/Graphic3d/Graphic3d_Camera.hxx
index 17875b5c74..2d93ecd9f7 100644
--- a/src/Graphic3d/Graphic3d_Camera.hxx
+++ b/src/Graphic3d/Graphic3d_Camera.hxx
@@ -289,6 +289,17 @@ public:
     myRotationPoint = theRotationPoint;
   };
 
+  //! Get panning translation.
+  //! @return the panning translation.
+  gp_Vec2d PanningVector() const { return myPanningVector; }
+
+  //! Sets panning translation.
+  //! @param thePanningVector [in] the panning translation.
+  void SetPanningVector(const gp_Vec2d &thePanningVector)
+  {
+    myPanningVector = thePanningVector;
+  };
+
   //! Get distance of Eye from camera Center.
   //! @return the distance.
   Standard_Real Distance() const { return myDistance; }
@@ -854,6 +865,7 @@ private:
   gp_Dir        myDirection;//!< Camera view direction (from eye)
   gp_Pnt        myEye;      //!< Camera eye position
   gp_Pnt        myRotationPoint;
+  gp_Vec2d      myPanningVector;
   Standard_Real myDistance; //!< distance from Eye to Center
 
   gp_XYZ myAxialScale; //!< World axial scale.
diff --git a/src/OpenGl/OpenGl_View.cxx b/src/OpenGl/OpenGl_View.cxx
index d6b9b776a9..6def227cf8 100644
--- a/src/OpenGl/OpenGl_View.cxx
+++ b/src/OpenGl/OpenGl_View.cxx
@@ -2599,6 +2599,9 @@ void OpenGl_View::renderGrid()
     aTranslationInv.SetColumn (3, -aRotationVec);
     OpenGl_Mat4 aWorldViewStateCorrected = aTranslationInv * aWorldViewCurrent * aTranslation;
     aPosition.ChangeCoord() += gp_XYZ (aWorldViewStateCorrected (0, 3), aWorldViewStateCorrected (1, 3), -aZFar);
+
+    gp_XYZ aPanningVector (aCamera->PanningVector().X(), aCamera->PanningVector().Y(), 0.0);
+    aPosition.ChangeCoord() -= aPanningVector;
   }
   OpenGl_Mat4 aTranslation;
   aTranslation.SetColumn (3, Graphic3d_Vec4 ((float)aPosition.X(), (float)aPosition.Y(), (float)aPosition.Z(), 1.0));