tdf#130988 add y-axis up<->down in create 3D obj

Creating the matrix aLatheMat uses a coordinate system with y-axis
pointing up, but aPolyPoly2D and ctor of E3dLatheObj uses y-axis
pointing down. Converting was missing. The error was inherited
from OOo2.

Change-Id: Id5b2f769b8f940bd0028d0386d7ce8b80bf17b97
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/89730
Tested-by: Jenkins
Reviewed-by: Regina Henschel <rb.henschel@t-online.de>
diff --git a/sd/qa/unit/data/tdf130988_3D_create_lathe.odg b/sd/qa/unit/data/tdf130988_3D_create_lathe.odg
new file mode 100644
index 0000000..e2b37ef
--- /dev/null
+++ b/sd/qa/unit/data/tdf130988_3D_create_lathe.odg
Binary files differ
diff --git a/sd/qa/unit/misc-tests.cxx b/sd/qa/unit/misc-tests.cxx
index 852cdc0..6871b2d 100644
--- a/sd/qa/unit/misc-tests.cxx
+++ b/sd/qa/unit/misc-tests.cxx
@@ -55,6 +55,8 @@
#include <vcl/keycodes.hxx>
#include <svx/svdoashp.hxx>
#include <tools/gen.hxx>
#include <svx/view3d.hxx>
#include <svx/scene3d.hxx>

using namespace ::com::sun::star;

@@ -78,6 +80,7 @@ public:
    void testTdf119956();
    void testTdf120527();
    void testTdf98839_ShearVFlipH();
    void testTdf130988();

    CPPUNIT_TEST_SUITE(SdMiscTest);
    CPPUNIT_TEST(testTdf96206);
@@ -96,6 +99,7 @@ public:
    CPPUNIT_TEST(testTdf119956);
    CPPUNIT_TEST(testTdf120527);
    CPPUNIT_TEST(testTdf98839_ShearVFlipH);
    CPPUNIT_TEST(testTdf130988);
    CPPUNIT_TEST_SUITE_END();

virtual void registerNamespaces(xmlXPathContextPtr& pXmlXPathCtx) override
@@ -802,6 +806,28 @@ void SdMiscTest::testTdf98839_ShearVFlipH()
    xDocShRef->DoClose();
}

void SdMiscTest::testTdf130988()
{
    const OUString sURL("sd/qa/unit/data/tdf130988_3D_create_lathe.odg");
    sd::DrawDocShellRef xDocShRef = Load(m_directories.getURLFromSrc(sURL), ODG);

    //emulate command .uno:ConvertInto3DLathe
    sd::ViewShell* pViewShell = xDocShRef->GetViewShell();
    E3dView* pView = dynamic_cast<E3dView*>(pViewShell->GetView());
    pView->MarkNextObj();
    pView->ConvertMarkedObjTo3D(false, basegfx::B2DPoint(8000.0, -3000.0), basegfx::B2DPoint(3000.0, -8000.0));
    E3dScene* pObj = dynamic_cast<E3dScene*>(pView->GetMarkedObjectByIndex(0));
    CPPUNIT_ASSERT(pObj);

    // Error was, that the created 3D object had a wrong path. Instead examining
    // the path directly, I use the scene distance, because that is easier. The
    // scene distance is calculated from the object while creating.
    const double fDistance = pObj->GetDistance();
    CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("D3DSceneDistance", 7071.0, fDistance, 0.5);

    xDocShRef->DoClose();
}

CPPUNIT_TEST_SUITE_REGISTRATION(SdMiscTest);

CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/svx/source/engine3d/view3d.cxx b/svx/source/engine3d/view3d.cxx
index 4d7e138..c756c90 100644
--- a/svx/source/engine3d/view3d.cxx
+++ b/svx/source/engine3d/view3d.cxx
@@ -737,8 +737,13 @@ void E3dView::ImpCreateSingle3DObjectFlat(E3dScene* pScene, SdrObject* pObj, boo
        }
        else
        {
            // rLatheMat expects coordinates with y-axis up, pPath uses y-axis down
            basegfx::B2DHomMatrix aFlipVerticalMat(1.0, 0.0, 0.0, 0.0, -1.0, 0.0);
            basegfx::B2DPolyPolygon aPolyPoly2D(pPath->GetPathPoly());
            aPolyPoly2D.transform(aFlipVerticalMat);
            aPolyPoly2D.transform(rLatheMat);
            // ctor E3dLatheObj expects coordinates with y-axis down
            aPolyPoly2D.transform(aFlipVerticalMat);
            p3DObj = new E3dLatheObj(pObj->getSdrModelFromSdrObject(), aDefault, aPolyPoly2D);
        }