]> OCCT Git - occt.git/commitdiff
0033521: Visualization - possibility to redefine rotation persistence in Graphic3d_Tr... CR0-WEEK-48 IR-2023-11-30
authorrodrlyra <rodrlyra@opencascade.com>
Fri, 3 Nov 2023 15:25:49 +0000 (15:25 +0000)
committerrodrlyra <rodrlyra@opencascade.com>
Tue, 28 Nov 2023 13:33:19 +0000 (13:33 +0000)
Added virtual function to Graphic3d_TransformPers that allows overriding rotation persistence behavior on application level.

src/Graphic3d/Graphic3d_TransformPers.hxx

index e0db73b4e8f59ccbff1d5027731a63bf1937a0d5..f9d9b60940b452d8ae38d30fbe3fce725742a92f 100644 (file)
@@ -241,6 +241,24 @@ public:
     return Abs(aViewDim.Y()) / Standard_Real(aVPSizeY);
   }
 
+  //! Create orientation matrix based on camera and view dimensions.
+  //! Default implementation locks rotation by nullifying rotation component.
+  //! Camera and view dimensions are not used, by default.
+  //! @param theCamera [in] camera definition
+  //! @param theViewportWidth [in] the width of viewport
+  //! @param theViewportHeight [in] the height of viewport
+  virtual NCollection_Mat3<Standard_Real> persistentRotationMatrix (const Handle(Graphic3d_Camera)& theCamera,
+                                                                    const Standard_Integer theViewportWidth,
+                                                                    const Standard_Integer theViewportHeight) const
+  {
+    (void )theCamera;
+    (void )theViewportWidth;
+    (void )theViewportHeight;
+
+    NCollection_Mat3<Standard_Real> aRotMat;
+    return aRotMat;
+  }
+
   //! Apply transformation to bounding box of presentation.
   //! @param theCamera [in] camera definition
   //! @param theProjection [in] the projection transformation matrix.
@@ -467,18 +485,19 @@ void Graphic3d_TransformPers::Apply (const Handle(Graphic3d_Camera)& theCamera,
 
     if ((myMode & Graphic3d_TMF_RotatePers) != 0)
     {
-      // lock rotation by nullifying rotation component
-      aWorldView.SetValue (0, 0, 1.0);
-      aWorldView.SetValue (1, 0, 0.0);
-      aWorldView.SetValue (2, 0, 0.0);
-
-      aWorldView.SetValue (0, 1, 0.0);
-      aWorldView.SetValue (1, 1, 1.0);
-      aWorldView.SetValue (2, 1, 0.0);
-
-      aWorldView.SetValue (0, 2, 0.0);
-      aWorldView.SetValue (1, 2, 0.0);
-      aWorldView.SetValue (2, 2, 1.0);
+      NCollection_Mat3<Standard_Real> aRotMat = persistentRotationMatrix (theCamera, theViewportWidth, theViewportHeight);
+
+      aWorldView.SetValue (0, 0, aRotMat.GetColumn (0).x());
+      aWorldView.SetValue (1, 0, aRotMat.GetColumn (0).y());
+      aWorldView.SetValue (2, 0, aRotMat.GetColumn (0).z());
+
+      aWorldView.SetValue (0, 1, aRotMat.GetColumn (1).x());
+      aWorldView.SetValue (1, 1, aRotMat.GetColumn (1).y());
+      aWorldView.SetValue (2, 1, aRotMat.GetColumn (1).z());
+
+      aWorldView.SetValue (0, 2, aRotMat.GetColumn (2).x());
+      aWorldView.SetValue (1, 2, aRotMat.GetColumn (2).y());
+      aWorldView.SetValue (2, 2, aRotMat.GetColumn (2).z());
     }
 
     if ((myMode & Graphic3d_TMF_ZoomPers) != 0)