chart2/source/controller/dialogs/tp_3D_SceneGeometry.cxx   |    4 
 chart2/source/controller/main/DragMethod_RotateDiagram.cxx |   19 
 chart2/source/inc/Diagram.hxx                              |    9 
 chart2/source/inc/ThreeDHelper.hxx                         |   16 
 chart2/source/model/main/Diagram.cxx                       |  262 ++++++++++++-
 chart2/source/tools/ThreeDHelper.cxx                       |  209 ----------
 chart2/source/view/diagram/VDiagram.cxx                    |    2 
 7 files changed, 289 insertions(+), 232 deletions(-)

New commits:
commit 5bcc7e6abfd8a0838f6f2c13b9e7040748913e28
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Tue Mar 28 09:10:59 2023 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Tue Mar 28 10:49:12 2023 +0000

    move get/setRotation from ThreeDHelper to Diagram
    
    so we can use the get/setFastPropertyValue methods
    
    Change-Id: I147ed5c092b44283bfbbf4ea5a3145736417b92c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149642
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/chart2/source/controller/dialogs/tp_3D_SceneGeometry.cxx 
b/chart2/source/controller/dialogs/tp_3D_SceneGeometry.cxx
index 12e878d237ed..fb05bfde0dbf 100644
--- a/chart2/source/controller/dialogs/tp_3D_SceneGeometry.cxx
+++ b/chart2/source/controller/dialogs/tp_3D_SceneGeometry.cxx
@@ -69,7 +69,7 @@ 
ThreeD_SceneGeometry_TabPage::ThreeD_SceneGeometry_TabPage(weld::Container* pPar
     , 
m_xMFPerspective(m_xBuilder->weld_metric_spin_button("MTR_FLD_PERSPECTIVE", 
FieldUnit::PERCENT))
 {
     double fXAngle, fYAngle, fZAngle;
-    ThreeDHelper::getRotationAngleFromDiagram( m_xDiagram, fXAngle, fYAngle, 
fZAngle );
+    m_xDiagram->getRotationAngle( fXAngle, fYAngle, fZAngle );
 
     fXAngle = basegfx::rad2deg(fXAngle);
     fYAngle = basegfx::rad2deg(fYAngle);
@@ -159,7 +159,7 @@ void ThreeD_SceneGeometry_TabPage::applyAnglesToModel()
     fYAngle = basegfx::deg2rad(fYAngle);
     fZAngle = basegfx::deg2rad(fZAngle);
 
-    ThreeDHelper::setRotationAngleToDiagram( m_xDiagram, fXAngle, fYAngle, 
fZAngle );
+    m_xDiagram->setRotationAngle( fXAngle, fYAngle, fZAngle );
 
     m_bAngleChangePending = false;
     m_aAngleTimer.Stop();
diff --git a/chart2/source/controller/main/DragMethod_RotateDiagram.cxx 
b/chart2/source/controller/main/DragMethod_RotateDiagram.cxx
index c4b2646e1fe8..1fcd94a58a2b 100644
--- a/chart2/source/controller/main/DragMethod_RotateDiagram.cxx
+++ b/chart2/source/controller/main/DragMethod_RotateDiagram.cxx
@@ -77,11 +77,11 @@ DragMethod_RotateDiagram::DragMethod_RotateDiagram( 
DrawViewWrapper& rDrawViewWr
     if( !xDiagram.is() )
         return;
 
-    ThreeDHelper::getRotationFromDiagram( xDiagram
-        , m_nInitialHorizontalAngleDegree, m_nInitialVerticalAngleDegree );
+    xDiagram->getRotation(
+        m_nInitialHorizontalAngleDegree, m_nInitialVerticalAngleDegree );
 
-    ThreeDHelper::getRotationAngleFromDiagram( xDiagram
-        , m_fInitialXAngleRad, m_fInitialYAngleRad, m_fInitialZAngleRad );
+    xDiagram->getRotationAngle(
+        m_fInitialXAngleRad, m_fInitialYAngleRad, m_fInitialZAngleRad );
 
     if( ChartTypeHelper::isSupportingRightAngledAxes(
         xDiagram->getChartTypeByIndex( 0 ) ) )
@@ -160,13 +160,16 @@ bool DragMethod_RotateDiagram::EndSdrDrag(bool /*bCopy*/)
         if(m_bRightAngledAxes)
             ThreeDHelper::adaptRadAnglesForRightAngledAxes( fResultX, fResultY 
);
 
-        ThreeDHelper::setRotationAngleToDiagram( 
ChartModelHelper::findDiagram( getChartModel() )
-            , fResultX, fResultY, fResultZ );
+        rtl::Reference<Diagram> xDiagram = ChartModelHelper::findDiagram( 
getChartModel() );
+        if (xDiagram)
+            xDiagram->setRotationAngle( fResultX, fResultY, fResultZ );
     }
     else
     {
-        ThreeDHelper::setRotationToDiagram( ChartModelHelper::findDiagram( 
getChartModel() )
-            , 
m_nInitialHorizontalAngleDegree+m_nAdditionalHorizontalAngleDegree, 
m_nInitialVerticalAngleDegree+m_nAdditionalVerticalAngleDegree );
+        rtl::Reference<Diagram> xDiagram = ChartModelHelper::findDiagram( 
getChartModel() );
+        if (xDiagram)
+            xDiagram->setRotation(
+                
m_nInitialHorizontalAngleDegree+m_nAdditionalHorizontalAngleDegree, 
m_nInitialVerticalAngleDegree+m_nAdditionalVerticalAngleDegree );
     }
 
     return true;
diff --git a/chart2/source/inc/Diagram.hxx b/chart2/source/inc/Diagram.hxx
index e39b7342e2dd..98f0e17ac82b 100644
--- a/chart2/source/inc/Diagram.hxx
+++ b/chart2/source/inc/Diagram.hxx
@@ -335,6 +335,15 @@ public:
     double getCameraDistance();
     void setCameraDistance( double fCameraDistance );
 
+    void getRotation(
+            sal_Int32& rnHorizontalAngleDegree, sal_Int32& 
rnVerticalAngleDegree );
+    void setRotation(
+            sal_Int32 nHorizontalAngleDegree, sal_Int32 nVerticalYAngleDegree 
);
+    void getRotationAngle(
+            double& rfXAngleRad, double& rfYAngleRad, double& rfZAngleRad );
+    void setRotationAngle(
+            double fXAngleRad, double fYAngleRad, double fZAngleRad );
+
 private:
     // ____ XModifyListener ____
     virtual void SAL_CALL modified(
diff --git a/chart2/source/inc/ThreeDHelper.hxx 
b/chart2/source/inc/ThreeDHelper.hxx
index 8bcb4183ebea..503679e9b56f 100644
--- a/chart2/source/inc/ThreeDHelper.hxx
+++ b/chart2/source/inc/ThreeDHelper.hxx
@@ -59,21 +59,7 @@ public:
      */
     static css::drawing::CameraGeometry getDefaultCameraGeometry( bool 
bPie=false );
 
-    static void getRotationAngleFromDiagram(
-        const css::uno::Reference< css::beans::XPropertySet >& xSceneProperties
-            , double& rfXAngleRad, double& rfYAngleRad, double& rfZAngleRad );
-    static void setRotationAngleToDiagram(
-        const rtl::Reference< ::chart::Diagram >& xSceneProperties
-            , double fXAngleRad, double fYAngleRad, double fZAngleRad );
-
-    static void getRotationFromDiagram(
-        const rtl::Reference< ::chart::Diagram >& xSceneProperties
-            , sal_Int32& rnHorizontalAngleDegree, sal_Int32& 
rnVerticalAngleDegree );
-    static void setRotationToDiagram(
-        const rtl::Reference< ::chart::Diagram >& xSceneProperties
-            , sal_Int32 nHorizontalAngleDegree, sal_Int32 
nVerticalYAngleDegree );
-
-    static void switchRightAngledAxes( const css::uno::Reference< 
css::beans::XPropertySet >& xSceneProperties
+    static void switchRightAngledAxes( const rtl::Reference< Diagram >& 
xSceneProperties
             , bool bRightAngledAxes );
 
     static void adaptRadAnglesForRightAngledAxes( double& rfXAngleRad, double& 
rfYAngleRad );
diff --git a/chart2/source/model/main/Diagram.cxx 
b/chart2/source/model/main/Diagram.cxx
index a6c07f84163e..30cb2d543990 100644
--- a/chart2/source/model/main/Diagram.cxx
+++ b/chart2/source/model/main/Diagram.cxx
@@ -60,12 +60,14 @@
 #include <comphelper/diagnose_ex.hxx>
 #include <o3tl/safeint.hxx>
 #include <rtl/math.hxx>
+#include <tools/helpers.hxx>
 
 #include <algorithm>
 #include <utility>
 
 using namespace ::com::sun::star;
 using namespace ::com::sun::star::beans::PropertyAttribute;
+using namespace ::chart::SceneProperties;
 
 using ::com::sun::star::beans::Property;
 using ::com::sun::star::uno::Sequence;
@@ -255,7 +257,7 @@ Diagram::Diagram( uno::Reference< uno::XComponentContext > 
xContext ) :
     // straight ono the scene).  These defaults have been acquired from the old
     // chart implementation.
     setFastPropertyValue_NoBroadcast(
-        SceneProperties::PROP_SCENE_CAMERA_GEOMETRY, uno::Any(
+        PROP_SCENE_CAMERA_GEOMETRY, uno::Any(
             ThreeDHelper::getDefaultCameraGeometry()));
 }
 
@@ -628,12 +630,12 @@ void SAL_CALL Diagram::setFastPropertyValue( sal_Int32 
nHandle, const Any& rValu
         if( rValue >>=nNewAngleDegree )
         {
             sal_Int32 nHorizontal, nVertical;
-            ThreeDHelper::getRotationFromDiagram( this, nHorizontal, nVertical 
);
+            getRotation( nHorizontal, nVertical );
             if( nHandle == PROP_DIAGRAM_ROTATION_HORIZONTAL )
                 nHorizontal = nNewAngleDegree;
             else
                 nVertical = nNewAngleDegree;
-            ThreeDHelper::setRotationToDiagram( this, nHorizontal, nVertical );
+            setRotation( nHorizontal, nVertical );
         }
     }
     else
@@ -653,7 +655,7 @@ void SAL_CALL Diagram::getFastPropertyValue( Any& rValue, 
sal_Int32 nHandle ) co
         || nHandle == PROP_DIAGRAM_ROTATION_VERTICAL )
     {
         sal_Int32 nHorizontal, nVertical;
-        ThreeDHelper::getRotationFromDiagram( const_cast< Diagram* >( this ), 
nHorizontal, nVertical );
+        const_cast< Diagram* >( this )->getRotation( nHorizontal, nVertical );
         sal_Int32 nAngleDegree = 0;
         if( nHandle == PROP_DIAGRAM_ROTATION_HORIZONTAL )
             nAngleDegree = nHorizontal;
@@ -1670,7 +1672,7 @@ double Diagram::getCameraDistance()
     try
     {
         drawing::CameraGeometry aCG( ThreeDHelper::getDefaultCameraGeometry() 
);
-        getFastPropertyValue( SceneProperties::PROP_SCENE_CAMERA_GEOMETRY ) 
>>= aCG;
+        getFastPropertyValue( PROP_SCENE_CAMERA_GEOMETRY ) >>= aCG;
         ::basegfx::B3DVector aVRP( BaseGFXHelper::Position3DToB3DVector( 
aCG.vrp ) );
         fCameraDistance = aVRP.getLength();
 
@@ -1691,14 +1693,14 @@ void Diagram::setCameraDistance(double fCameraDistance )
             fCameraDistance = FIXED_SIZE_FOR_3D_CHART_VOLUME;
 
         drawing::CameraGeometry aCG( ThreeDHelper::getDefaultCameraGeometry() 
);
-        getFastPropertyValue( SceneProperties::PROP_SCENE_CAMERA_GEOMETRY ) 
>>= aCG;
+        getFastPropertyValue( PROP_SCENE_CAMERA_GEOMETRY ) >>= aCG;
         ::basegfx::B3DVector aVRP( BaseGFXHelper::Position3DToB3DVector( 
aCG.vrp ) );
         if( ::basegfx::fTools::equalZero( aVRP.getLength() ) )
             aVRP = ::basegfx::B3DVector(0,0,1);
         aVRP.setLength(fCameraDistance);
         aCG.vrp = BaseGFXHelper::B3DVectorToPosition3D( aVRP );
 
-        setFastPropertyValue( SceneProperties::PROP_SCENE_CAMERA_GEOMETRY, 
uno::Any( aCG ));
+        setFastPropertyValue( PROP_SCENE_CAMERA_GEOMETRY, uno::Any( aCG ));
     }
     catch( const uno::Exception & )
     {
@@ -1706,6 +1708,252 @@ void Diagram::setCameraDistance(double fCameraDistance )
     }
 }
 
+static bool lcl_isRightAngledAxesSetAndSupported( Diagram& rDiagram )
+{
+    bool bRightAngledAxes = false;
+    rDiagram.getFastPropertyValue( PROP_DIAGRAM_RIGHT_ANGLED_AXES ) >>= 
bRightAngledAxes; // "RightAngledAxes"
+    if(bRightAngledAxes)
+    {
+        if( ChartTypeHelper::isSupportingRightAngledAxes(
+                rDiagram.getChartTypeByIndex( 0 ) ) )
+        {
+            return true;
+        }
+    }
+    return false;
+}
+
+void Diagram::getRotation( sal_Int32& rnHorizontalAngleDegree, sal_Int32& 
rnVerticalAngleDegree )
+{
+    double fXAngle, fYAngle, fZAngle;
+    getRotationAngle( fXAngle, fYAngle, fZAngle );
+
+    if( !lcl_isRightAngledAxesSetAndSupported( *this ) )
+    {
+        ThreeDHelper::convertXYZAngleRadToElevationRotationDeg(
+            rnHorizontalAngleDegree, rnVerticalAngleDegree, fXAngle, fYAngle, 
fZAngle);
+        rnVerticalAngleDegree*=-1;
+    }
+    else
+    {
+        rnHorizontalAngleDegree = basegfx::fround(basegfx::rad2deg(fXAngle));
+        rnVerticalAngleDegree = basegfx::fround(-1.0 * 
basegfx::rad2deg(fYAngle));
+        // nZRotation = basegfx::fround(-1.0 * basegfx::rad2deg(fZAngle));
+    }
+
+    rnHorizontalAngleDegree = NormAngle180(rnHorizontalAngleDegree);
+    rnVerticalAngleDegree = NormAngle180(rnVerticalAngleDegree);
+}
+
+void Diagram::setRotation( sal_Int32 nHorizontalAngleDegree, sal_Int32 
nVerticalYAngleDegree )
+{
+    //todo: x and y is not equal to horz and vert in case of 
RightAngledAxes==false
+    double fXAngle = basegfx::deg2rad(nHorizontalAngleDegree);
+    double fYAngle = basegfx::deg2rad(-1 * nVerticalYAngleDegree);
+    double fZAngle = 0.0;
+
+    if( !lcl_isRightAngledAxesSetAndSupported( *this ) )
+        ThreeDHelper::convertElevationRotationDegToXYZAngleRad(
+            nHorizontalAngleDegree, -1*nVerticalYAngleDegree, fXAngle, 
fYAngle, fZAngle );
+
+    setRotationAngle( fXAngle, fYAngle, fZAngle );
+}
+
+static ::basegfx::B3DHomMatrix lcl_getCameraMatrix( Diagram& rDiagram )
+{
+    drawing::HomogenMatrix aCameraMatrix;
+
+    drawing::CameraGeometry aCG( ThreeDHelper::getDefaultCameraGeometry() );
+    rDiagram.getFastPropertyValue( PROP_SCENE_CAMERA_GEOMETRY ) >>= aCG; // 
"D3DCameraGeometry"
+
+    ::basegfx::B3DVector aVPN( BaseGFXHelper::Direction3DToB3DVector( aCG.vpn 
) );
+    ::basegfx::B3DVector aVUP( BaseGFXHelper::Direction3DToB3DVector( aCG.vup 
) );
+
+    //normalize vectors:
+    aVPN.normalize();
+    aVUP.normalize();
+
+    ::basegfx::B3DVector aCross = ::basegfx::cross( aVUP, aVPN );
+
+    //first line is VUP x VPN
+    aCameraMatrix.Line1.Column1 = aCross[0];
+    aCameraMatrix.Line1.Column2 = aCross[1];
+    aCameraMatrix.Line1.Column3 = aCross[2];
+    aCameraMatrix.Line1.Column4 = 0.0;
+
+    //second line is VUP
+    aCameraMatrix.Line2.Column1 = aVUP[0];
+    aCameraMatrix.Line2.Column2 = aVUP[1];
+    aCameraMatrix.Line2.Column3 = aVUP[2];
+    aCameraMatrix.Line2.Column4 = 0.0;
+
+    //third line is VPN
+    aCameraMatrix.Line3.Column1 = aVPN[0];
+    aCameraMatrix.Line3.Column2 = aVPN[1];
+    aCameraMatrix.Line3.Column3 = aVPN[2];
+    aCameraMatrix.Line3.Column4 = 0.0;
+
+    //fourth line is 0 0 0 1
+    aCameraMatrix.Line4.Column1 = 0.0;
+    aCameraMatrix.Line4.Column2 = 0.0;
+    aCameraMatrix.Line4.Column3 = 0.0;
+    aCameraMatrix.Line4.Column4 = 1.0;
+
+    return BaseGFXHelper::HomogenMatrixToB3DHomMatrix( aCameraMatrix );
+}
+
+static double lcl_shiftAngleToIntervalMinusPiToPi( double fAngleRad )
+{
+    //valid range:  ]-Pi,Pi]
+    while( fAngleRad<=-M_PI )
+        fAngleRad+=(2*M_PI);
+    while( fAngleRad>M_PI )
+        fAngleRad-=(2*M_PI);
+    return fAngleRad;
+}
+
+void Diagram::getRotationAngle( double& rfXAngleRad, double& rfYAngleRad, 
double& rfZAngleRad )
+{
+    //takes the camera and the transformation matrix into account
+
+    rfXAngleRad = rfYAngleRad = rfZAngleRad = 0.0;
+
+    //get camera rotation
+    ::basegfx::B3DHomMatrix aFixCameraRotationMatrix( lcl_getCameraMatrix( 
*this ) );
+    BaseGFXHelper::ReduceToRotationMatrix( aFixCameraRotationMatrix );
+
+    //get scene rotation
+    ::basegfx::B3DHomMatrix aSceneRotation;
+    {
+        drawing::HomogenMatrix aHomMatrix;
+        // "D3DTransformMatrix"
+        if( getFastPropertyValue( PROP_SCENE_TRANSF_MATRIX ) >>= aHomMatrix )
+        {
+            aSceneRotation = BaseGFXHelper::HomogenMatrixToB3DHomMatrix( 
aHomMatrix );
+            BaseGFXHelper::ReduceToRotationMatrix( aSceneRotation );
+        }
+    }
+
+    ::basegfx::B3DHomMatrix aResultRotation = aFixCameraRotationMatrix * 
aSceneRotation;
+    ::basegfx::B3DTuple aRotation( BaseGFXHelper::GetRotationFromMatrix( 
aResultRotation ) );
+
+    rfXAngleRad = lcl_shiftAngleToIntervalMinusPiToPi(aRotation.getX());
+    rfYAngleRad = lcl_shiftAngleToIntervalMinusPiToPi(aRotation.getY());
+    rfZAngleRad = lcl_shiftAngleToIntervalMinusPiToPi(aRotation.getZ());
+
+    if(rfZAngleRad<-M_PI_2 || rfZAngleRad>M_PI_2)
+    {
+        rfZAngleRad-=M_PI;
+        rfXAngleRad-=M_PI;
+        rfYAngleRad=(M_PI-rfYAngleRad);
+
+        rfXAngleRad = lcl_shiftAngleToIntervalMinusPiToPi(rfXAngleRad);
+        rfYAngleRad = lcl_shiftAngleToIntervalMinusPiToPi(rfYAngleRad);
+        rfZAngleRad = lcl_shiftAngleToIntervalMinusPiToPi(rfZAngleRad);
+    }
+}
+
+static ::basegfx::B3DHomMatrix lcl_getInverseRotationMatrix( Diagram& rDiagram 
)
+{
+    ::basegfx::B3DHomMatrix aInverseRotation;
+    double fXAngleRad=0.0;
+    double fYAngleRad=0.0;
+    double fZAngleRad=0.0;
+    rDiagram.getRotationAngle( fXAngleRad, fYAngleRad, fZAngleRad );
+    aInverseRotation.rotate( 0.0, 0.0, -fZAngleRad );
+    aInverseRotation.rotate( 0.0, -fYAngleRad, 0.0 );
+    aInverseRotation.rotate( -fXAngleRad, 0.0, 0.0 );
+    return aInverseRotation;
+}
+
+static void lcl_RotateLightSource( Diagram& rDiagram
+                           , int nLightSourceDirectionProp
+                           , int nLightSourceOnProp
+                           , const ::basegfx::B3DHomMatrix& rRotationMatrix )
+{
+    bool bLightOn = false;
+    if( !(rDiagram.getFastPropertyValue( nLightSourceOnProp ) >>= bLightOn) )
+        return;
+
+    if( bLightOn )
+    {
+        drawing::Direction3D aLight;
+        if( rDiagram.getFastPropertyValue( nLightSourceDirectionProp ) >>= 
aLight )
+        {
+            ::basegfx::B3DVector aLightVector( 
BaseGFXHelper::Direction3DToB3DVector( aLight ) );
+            aLightVector = rRotationMatrix*aLightVector;
+
+            rDiagram.setFastPropertyValue( nLightSourceDirectionProp
+                , uno::Any( BaseGFXHelper::B3DVectorToDirection3D( 
aLightVector ) ) );
+        }
+    }
+}
+
+static void lcl_rotateLights( const ::basegfx::B3DHomMatrix& rLightRotation, 
Diagram& rDiagram )
+{
+    ::basegfx::B3DHomMatrix aLightRotation( rLightRotation );
+    BaseGFXHelper::ReduceToRotationMatrix( aLightRotation );
+
+    // "D3DSceneLightDirection1","D3DSceneLightOn1",
+    lcl_RotateLightSource( rDiagram, PROP_SCENE_LIGHT_DIRECTION_1, 
PROP_SCENE_LIGHT_ON_1, aLightRotation );
+    lcl_RotateLightSource( rDiagram, PROP_SCENE_LIGHT_DIRECTION_2, 
PROP_SCENE_LIGHT_ON_2, aLightRotation );
+    lcl_RotateLightSource( rDiagram, PROP_SCENE_LIGHT_DIRECTION_3, 
PROP_SCENE_LIGHT_ON_3, aLightRotation );
+    lcl_RotateLightSource( rDiagram, PROP_SCENE_LIGHT_DIRECTION_4, 
PROP_SCENE_LIGHT_ON_4, aLightRotation );
+    lcl_RotateLightSource( rDiagram, PROP_SCENE_LIGHT_DIRECTION_5, 
PROP_SCENE_LIGHT_ON_5, aLightRotation );
+    lcl_RotateLightSource( rDiagram, PROP_SCENE_LIGHT_DIRECTION_6, 
PROP_SCENE_LIGHT_ON_6, aLightRotation );
+    lcl_RotateLightSource( rDiagram, PROP_SCENE_LIGHT_DIRECTION_7, 
PROP_SCENE_LIGHT_ON_7, aLightRotation );
+    lcl_RotateLightSource( rDiagram, PROP_SCENE_LIGHT_DIRECTION_8, 
PROP_SCENE_LIGHT_ON_8, aLightRotation );
+}
+
+void Diagram::setRotationAngle(
+        double fXAngleRad, double fYAngleRad, double fZAngleRad )
+{
+    //the rotation of the camera is not touched but taken into account
+    //the rotation difference is applied to the transformation matrix
+
+    //the light sources will be adapted also
+
+    try
+    {
+        //remind old rotation for adaptation of light directions
+        ::basegfx::B3DHomMatrix aInverseOldRotation( 
lcl_getInverseRotationMatrix( *this ) );
+
+        ::basegfx::B3DHomMatrix aInverseCameraRotation;
+        {
+            ::basegfx::B3DTuple aR( BaseGFXHelper::GetRotationFromMatrix(
+                    lcl_getCameraMatrix( *this ) ) );
+            aInverseCameraRotation.rotate( 0.0, 0.0, -aR.getZ() );
+            aInverseCameraRotation.rotate( 0.0, -aR.getY(), 0.0 );
+            aInverseCameraRotation.rotate( -aR.getX(), 0.0, 0.0 );
+        }
+
+        ::basegfx::B3DHomMatrix aCumulatedRotation;
+        aCumulatedRotation.rotate( fXAngleRad, fYAngleRad, fZAngleRad );
+
+        //calculate new scene matrix
+        ::basegfx::B3DHomMatrix aSceneRotation = 
aInverseCameraRotation*aCumulatedRotation;
+        BaseGFXHelper::ReduceToRotationMatrix( aSceneRotation );
+
+        //set new rotation to transformation matrix ("D3DTransformMatrix")
+        setFastPropertyValue(
+            PROP_SCENE_TRANSF_MATRIX, uno::Any( 
BaseGFXHelper::B3DHomMatrixToHomogenMatrix( aSceneRotation )));
+
+        //rotate lights if RightAngledAxes are not set or not supported
+        bool bRightAngledAxes = false;
+        getFastPropertyValue( PROP_DIAGRAM_RIGHT_ANGLED_AXES ) >>= 
bRightAngledAxes;
+        if(!bRightAngledAxes || !ChartTypeHelper::isSupportingRightAngledAxes(
+                    getChartTypeByIndex( 0 ) ) )
+        {
+            ::basegfx::B3DHomMatrix aNewRotation;
+            aNewRotation.rotate( fXAngleRad, fYAngleRad, fZAngleRad );
+            lcl_rotateLights( aNewRotation*aInverseOldRotation, *this );
+        }
+    }
+    catch( const uno::Exception & )
+    {
+        DBG_UNHANDLED_EXCEPTION("chart2");
+    }
+}
 
 } //  namespace chart
 
diff --git a/chart2/source/tools/ThreeDHelper.cxx 
b/chart2/source/tools/ThreeDHelper.cxx
index bee4085f9637..fb2bc3122665 100644
--- a/chart2/source/tools/ThreeDHelper.cxx
+++ b/chart2/source/tools/ThreeDHelper.cxx
@@ -109,28 +109,28 @@ void lcl_rotateLights( const ::basegfx::B3DHomMatrix& 
rLightRottion, const Refer
     lcl_RotateLightSource( xSceneProperties, "D3DSceneLightDirection8", 
"D3DSceneLightOn8", aLightRottion );
 }
 
-::basegfx::B3DHomMatrix lcl_getInverseRotationMatrix( const Reference< 
beans::XPropertySet >& xSceneProperties )
+::basegfx::B3DHomMatrix lcl_getInverseRotationMatrix( const rtl::Reference< 
Diagram >& xSceneProperties )
 {
     ::basegfx::B3DHomMatrix aInverseRotation;
     double fXAngleRad=0.0;
     double fYAngleRad=0.0;
     double fZAngleRad=0.0;
-    ThreeDHelper::getRotationAngleFromDiagram(
-        xSceneProperties, fXAngleRad, fYAngleRad, fZAngleRad );
+    xSceneProperties->getRotationAngle(
+        fXAngleRad, fYAngleRad, fZAngleRad );
     aInverseRotation.rotate( 0.0, 0.0, -fZAngleRad );
     aInverseRotation.rotate( 0.0, -fYAngleRad, 0.0 );
     aInverseRotation.rotate( -fXAngleRad, 0.0, 0.0 );
     return aInverseRotation;
 }
 
-::basegfx::B3DHomMatrix lcl_getCompleteRotationMatrix( const Reference< 
beans::XPropertySet >& xSceneProperties )
+::basegfx::B3DHomMatrix lcl_getCompleteRotationMatrix( const rtl::Reference< 
Diagram >& xSceneProperties )
 {
     ::basegfx::B3DHomMatrix aCompleteRotation;
     double fXAngleRad=0.0;
     double fYAngleRad=0.0;
     double fZAngleRad=0.0;
-    ThreeDHelper::getRotationAngleFromDiagram(
-        xSceneProperties, fXAngleRad, fYAngleRad, fZAngleRad );
+    xSceneProperties->getRotationAngle(
+        fXAngleRad, fYAngleRad, fZAngleRad );
     aCompleteRotation.rotate( fXAngleRad, fYAngleRad, fZAngleRad );
     return aCompleteRotation;
 }
@@ -316,60 +316,6 @@ drawing::CameraGeometry 
ThreeDHelper::getDefaultCameraGeometry( bool bPie )
 
 namespace
 {
-::basegfx::B3DHomMatrix lcl_getCameraMatrix( const uno::Reference< 
beans::XPropertySet >& xSceneProperties )
-{
-    drawing::HomogenMatrix aCameraMatrix;
-
-    drawing::CameraGeometry aCG( ThreeDHelper::getDefaultCameraGeometry() );
-    if( xSceneProperties.is() )
-        xSceneProperties->getPropertyValue( "D3DCameraGeometry" ) >>= aCG;
-
-    ::basegfx::B3DVector aVPN( BaseGFXHelper::Direction3DToB3DVector( aCG.vpn 
) );
-    ::basegfx::B3DVector aVUP( BaseGFXHelper::Direction3DToB3DVector( aCG.vup 
) );
-
-    //normalize vectors:
-    aVPN.normalize();
-    aVUP.normalize();
-
-    ::basegfx::B3DVector aCross = ::basegfx::cross( aVUP, aVPN );
-
-    //first line is VUP x VPN
-    aCameraMatrix.Line1.Column1 = aCross[0];
-    aCameraMatrix.Line1.Column2 = aCross[1];
-    aCameraMatrix.Line1.Column3 = aCross[2];
-    aCameraMatrix.Line1.Column4 = 0.0;
-
-    //second line is VUP
-    aCameraMatrix.Line2.Column1 = aVUP[0];
-    aCameraMatrix.Line2.Column2 = aVUP[1];
-    aCameraMatrix.Line2.Column3 = aVUP[2];
-    aCameraMatrix.Line2.Column4 = 0.0;
-
-    //third line is VPN
-    aCameraMatrix.Line3.Column1 = aVPN[0];
-    aCameraMatrix.Line3.Column2 = aVPN[1];
-    aCameraMatrix.Line3.Column3 = aVPN[2];
-    aCameraMatrix.Line3.Column4 = 0.0;
-
-    //fourth line is 0 0 0 1
-    aCameraMatrix.Line4.Column1 = 0.0;
-    aCameraMatrix.Line4.Column2 = 0.0;
-    aCameraMatrix.Line4.Column3 = 0.0;
-    aCameraMatrix.Line4.Column4 = 1.0;
-
-    return BaseGFXHelper::HomogenMatrixToB3DHomMatrix( aCameraMatrix );
-}
-
-double lcl_shiftAngleToIntervalMinusPiToPi( double fAngleRad )
-{
-    //valid range:  ]-Pi,Pi]
-    while( fAngleRad<=-M_PI )
-        fAngleRad+=(2*M_PI);
-    while( fAngleRad>M_PI )
-        fAngleRad-=(2*M_PI);
-    return fAngleRad;
-}
-
 void lcl_ensureIntervalMinus1To1( double& rSinOrCos )
 {
     if (rSinOrCos < -1.0)
@@ -888,51 +834,8 @@ void ThreeDHelper::adaptRadAnglesForRightAngledAxes( 
double& rfXAngleRad, double
     rfYAngleRad = ThreeDHelper::getValueClippedToRange(rfYAngleRad, 
basegfx::deg2rad(ThreeDHelper::getYDegreeAngleLimitForRightAngledAxes()) );
 }
 
-void ThreeDHelper::getRotationAngleFromDiagram(
-        const Reference< beans::XPropertySet >& xSceneProperties, double& 
rfXAngleRad, double& rfYAngleRad, double& rfZAngleRad )
-{
-    //takes the camera and the transformation matrix into account
-
-    rfXAngleRad = rfYAngleRad = rfZAngleRad = 0.0;
-
-    if( !xSceneProperties.is() )
-        return;
-
-    //get camera rotation
-    ::basegfx::B3DHomMatrix aFixCameraRotationMatrix( lcl_getCameraMatrix( 
xSceneProperties ) );
-    BaseGFXHelper::ReduceToRotationMatrix( aFixCameraRotationMatrix );
-
-    //get scene rotation
-    ::basegfx::B3DHomMatrix aSceneRotation;
-    {
-        drawing::HomogenMatrix aHomMatrix;
-        if( xSceneProperties->getPropertyValue( "D3DTransformMatrix") >>= 
aHomMatrix )
-        {
-            aSceneRotation = BaseGFXHelper::HomogenMatrixToB3DHomMatrix( 
aHomMatrix );
-            BaseGFXHelper::ReduceToRotationMatrix( aSceneRotation );
-        }
-    }
-
-    ::basegfx::B3DHomMatrix aResultRotation = aFixCameraRotationMatrix * 
aSceneRotation;
-    ::basegfx::B3DTuple aRotation( BaseGFXHelper::GetRotationFromMatrix( 
aResultRotation ) );
-
-    rfXAngleRad = lcl_shiftAngleToIntervalMinusPiToPi(aRotation.getX());
-    rfYAngleRad = lcl_shiftAngleToIntervalMinusPiToPi(aRotation.getY());
-    rfZAngleRad = lcl_shiftAngleToIntervalMinusPiToPi(aRotation.getZ());
-
-    if(rfZAngleRad<-M_PI_2 || rfZAngleRad>M_PI_2)
-    {
-        rfZAngleRad-=M_PI;
-        rfXAngleRad-=M_PI;
-        rfYAngleRad=(M_PI-rfYAngleRad);
 
-        rfXAngleRad = lcl_shiftAngleToIntervalMinusPiToPi(rfXAngleRad);
-        rfYAngleRad = lcl_shiftAngleToIntervalMinusPiToPi(rfYAngleRad);
-        rfZAngleRad = lcl_shiftAngleToIntervalMinusPiToPi(rfZAngleRad);
-    }
-}
-
-void ThreeDHelper::switchRightAngledAxes( const Reference< beans::XPropertySet 
>& xSceneProperties, bool bRightAngledAxes )
+void ThreeDHelper::switchRightAngledAxes( const rtl::Reference< Diagram >& 
xSceneProperties, bool bRightAngledAxes )
 {
     try
     {
@@ -962,98 +865,6 @@ void ThreeDHelper::switchRightAngledAxes( const Reference< 
beans::XPropertySet >
     }
 }
 
-void ThreeDHelper::setRotationAngleToDiagram(
-    const rtl::Reference< Diagram >& xDiagram
-        , double fXAngleRad, double fYAngleRad, double fZAngleRad )
-{
-    //the rotation of the camera is not touched but taken into account
-    //the rotation difference is applied to the transformation matrix
-
-    //the light sources will be adapted also
-
-    if( !xDiagram.is() )
-        return;
-
-    try
-    {
-        //remind old rotation for adaptation of light directions
-        ::basegfx::B3DHomMatrix aInverseOldRotation( 
lcl_getInverseRotationMatrix( xDiagram ) );
-
-        ::basegfx::B3DHomMatrix aInverseCameraRotation;
-        {
-            ::basegfx::B3DTuple aR( BaseGFXHelper::GetRotationFromMatrix(
-                    lcl_getCameraMatrix( xDiagram ) ) );
-            aInverseCameraRotation.rotate( 0.0, 0.0, -aR.getZ() );
-            aInverseCameraRotation.rotate( 0.0, -aR.getY(), 0.0 );
-            aInverseCameraRotation.rotate( -aR.getX(), 0.0, 0.0 );
-        }
-
-        ::basegfx::B3DHomMatrix aCumulatedRotation;
-        aCumulatedRotation.rotate( fXAngleRad, fYAngleRad, fZAngleRad );
-
-        //calculate new scene matrix
-        ::basegfx::B3DHomMatrix aSceneRotation = 
aInverseCameraRotation*aCumulatedRotation;
-        BaseGFXHelper::ReduceToRotationMatrix( aSceneRotation );
-
-        //set new rotation to transformation matrix
-        xDiagram->setPropertyValue(
-            "D3DTransformMatrix", uno::Any( 
BaseGFXHelper::B3DHomMatrixToHomogenMatrix( aSceneRotation )));
-
-        //rotate lights if RightAngledAxes are not set or not supported
-        bool bRightAngledAxes = false;
-        xDiagram->getPropertyValue( "RightAngledAxes") >>= bRightAngledAxes;
-        if(!bRightAngledAxes || !ChartTypeHelper::isSupportingRightAngledAxes(
-                    xDiagram->getChartTypeByIndex( 0 ) ) )
-        {
-            ::basegfx::B3DHomMatrix aNewRotation;
-            aNewRotation.rotate( fXAngleRad, fYAngleRad, fZAngleRad );
-            lcl_rotateLights( aNewRotation*aInverseOldRotation, xDiagram );
-        }
-    }
-    catch( const uno::Exception & )
-    {
-        DBG_UNHANDLED_EXCEPTION("chart2");
-    }
-}
-
-void ThreeDHelper::getRotationFromDiagram( const rtl::Reference< Diagram >& 
xSceneProperties
-            , sal_Int32& rnHorizontalAngleDegree, sal_Int32& 
rnVerticalAngleDegree )
-{
-    double fXAngle, fYAngle, fZAngle;
-    ThreeDHelper::getRotationAngleFromDiagram( xSceneProperties, fXAngle, 
fYAngle, fZAngle );
-
-    if( !lcl_isRightAngledAxesSetAndSupported( xSceneProperties ) )
-    {
-        ThreeDHelper::convertXYZAngleRadToElevationRotationDeg(
-            rnHorizontalAngleDegree, rnVerticalAngleDegree, fXAngle, fYAngle, 
fZAngle);
-        rnVerticalAngleDegree*=-1;
-    }
-    else
-    {
-        rnHorizontalAngleDegree = basegfx::fround(basegfx::rad2deg(fXAngle));
-        rnVerticalAngleDegree = basegfx::fround(-1.0 * 
basegfx::rad2deg(fYAngle));
-        // nZRotation = basegfx::fround(-1.0 * basegfx::rad2deg(fZAngle));
-    }
-
-    rnHorizontalAngleDegree = NormAngle180(rnHorizontalAngleDegree);
-    rnVerticalAngleDegree = NormAngle180(rnVerticalAngleDegree);
-}
-
-void ThreeDHelper::setRotationToDiagram( const rtl::Reference< Diagram >& 
xDiagram
-            , sal_Int32 nHorizontalAngleDegree, sal_Int32 
nVerticalYAngleDegree )
-{
-    //todo: x and y is not equal to horz and vert in case of 
RightAngledAxes==false
-    double fXAngle = basegfx::deg2rad(nHorizontalAngleDegree);
-    double fYAngle = basegfx::deg2rad(-1 * nVerticalYAngleDegree);
-    double fZAngle = 0.0;
-
-    if( !lcl_isRightAngledAxesSetAndSupported( xDiagram ) )
-        ThreeDHelper::convertElevationRotationDegToXYZAngleRad(
-            nHorizontalAngleDegree, -1*nVerticalYAngleDegree, fXAngle, 
fYAngle, fZAngle );
-
-    ThreeDHelper::setRotationAngleToDiagram( xDiagram, fXAngle, fYAngle, 
fZAngle );
-}
-
 void ThreeDHelper::getCameraDistanceRange( double& rfMinimumDistance, double& 
rfMaximumDistance )
 {
     rfMinimumDistance = 3.0/4.0*FIXED_SIZE_FOR_3D_CHART_VOLUME;//empiric value
@@ -1358,7 +1169,7 @@ CuboidPlanePosition 
ThreeDHelper::getAutomaticCuboidPlanePositionForStandardLeft
     CuboidPlanePosition eRet(CuboidPlanePosition_Left);
 
     double fXAngleRad=0.0; double fYAngleRad=0.0; double fZAngleRad=0.0;
-    ThreeDHelper::getRotationAngleFromDiagram( xDiagram, fXAngleRad, 
fYAngleRad, fZAngleRad );
+    xDiagram->getRotationAngle( fXAngleRad, fYAngleRad, fZAngleRad );
     if( lcl_isRightAngledAxesSetAndSupported( xDiagram ) )
     {
         ThreeDHelper::adaptRadAnglesForRightAngledAxes( fXAngleRad, fYAngleRad 
);
@@ -1373,7 +1184,7 @@ CuboidPlanePosition 
ThreeDHelper::getAutomaticCuboidPlanePositionForStandardBack
     CuboidPlanePosition eRet(CuboidPlanePosition_Back);
 
     double fXAngleRad=0.0; double fYAngleRad=0.0; double fZAngleRad=0.0;
-    ThreeDHelper::getRotationAngleFromDiagram( xDiagram, fXAngleRad, 
fYAngleRad, fZAngleRad );
+    xDiagram->getRotationAngle( fXAngleRad, fYAngleRad, fZAngleRad );
     if( lcl_isRightAngledAxesSetAndSupported( xDiagram ) )
     {
         ThreeDHelper::adaptRadAnglesForRightAngledAxes( fXAngleRad, fYAngleRad 
);
@@ -1388,7 +1199,7 @@ CuboidPlanePosition 
ThreeDHelper::getAutomaticCuboidPlanePositionForStandardBott
     CuboidPlanePosition eRet(CuboidPlanePosition_Bottom);
 
     double fXAngleRad=0.0; double fYAngleRad=0.0; double fZAngleRad=0.0;
-    ThreeDHelper::getRotationAngleFromDiagram( xDiagram, fXAngleRad, 
fYAngleRad, fZAngleRad );
+    xDiagram->getRotationAngle( fXAngleRad, fYAngleRad, fZAngleRad );
     if( lcl_isRightAngledAxesSetAndSupported( xDiagram ) )
     {
         ThreeDHelper::adaptRadAnglesForRightAngledAxes( fXAngleRad, fYAngleRad 
);
diff --git a/chart2/source/view/diagram/VDiagram.cxx 
b/chart2/source/view/diagram/VDiagram.cxx
index f950561d5aab..ff660a485d04 100644
--- a/chart2/source/view/diagram/VDiagram.cxx
+++ b/chart2/source/view/diagram/VDiagram.cxx
@@ -54,7 +54,7 @@ VDiagram::VDiagram(
     if( m_nDimensionCount != 3)
         return;
 
-    ThreeDHelper::getRotationAngleFromDiagram( xDiagram, m_fXAnglePi, 
m_fYAnglePi, m_fZAnglePi );
+    xDiagram->getRotationAngle( m_fXAnglePi, m_fYAnglePi, m_fZAnglePi );
     if( ChartTypeHelper::isSupportingRightAngledAxes(
             m_xDiagram->getChartTypeByIndex( 0 ) ) )
     {

Reply via email to