fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / svx / source / sdr / contact / viewcontactofe3dlathe.cxx
blobef8425c5282d439a7fd225592ac89b68d150936b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <svx/sdr/contact/viewcontactofe3dlathe.hxx>
22 #include <svx/lathe3d.hxx>
23 #include <drawinglayer/primitive3d/sdrlatheprimitive3d.hxx>
24 #include <svx/sdr/primitive2d/sdrattributecreator.hxx>
25 #include <svx/sdr/primitive3d/sdrattributecreator3d.hxx>
26 #include <basegfx/polygon/b2dpolygontools.hxx>
28 //////////////////////////////////////////////////////////////////////////////
30 namespace sdr
32 namespace contact
34 ViewContactOfE3dLathe::ViewContactOfE3dLathe(E3dLatheObj& rLathe)
35 : ViewContactOfE3d(rLathe)
39 ViewContactOfE3dLathe::~ViewContactOfE3dLathe()
43 drawinglayer::primitive3d::Primitive3DSequence ViewContactOfE3dLathe::createViewIndependentPrimitive3DSequence() const
45 drawinglayer::primitive3d::Primitive3DSequence xRetval;
46 const SfxItemSet& rItemSet = GetE3dLatheObj().GetMergedItemSet();
47 const drawinglayer::attribute::SdrLineFillShadowAttribute3D aAttribute(
48 drawinglayer::primitive2d::createNewSdrLineFillShadowAttribute(rItemSet, false));
50 // get extrude geometry
51 const basegfx::B2DPolyPolygon aPolyPolygon(GetE3dLatheObj().GetPolyPoly2D());
53 // get 3D Object Attributes
54 drawinglayer::attribute::Sdr3DObjectAttribute* pSdr3DObjectAttribute = drawinglayer::primitive2d::createNewSdr3DObjectAttribute(rItemSet);
56 // calculate texture size. Use the polygon length of the longest polygon for
57 // height and the rotated radius for width (using polygon center) to get a good
58 // texture mapping
59 const sal_uInt32 nPolygonCount(aPolyPolygon.count());
60 double fPolygonMaxLength(0.0);
62 for(sal_uInt32 a(0); a < nPolygonCount; a++)
64 const basegfx::B2DPolygon aCandidate(aPolyPolygon.getB2DPolygon(a));
65 const double fPolygonLength(basegfx::tools::getLength(aCandidate));
66 fPolygonMaxLength = std::max(fPolygonMaxLength, fPolygonLength);
69 const basegfx::B2DRange aPolyPolygonRange(basegfx::tools::getRange(aPolyPolygon));
70 const basegfx::B2DVector aTextureSize(
71 F_PI * fabs(aPolyPolygonRange.getCenter().getX()), // PI * d
72 fPolygonMaxLength);
74 // get more data
75 const sal_uInt32 nHorizontalSegments(GetE3dLatheObj().GetHorizontalSegments());
76 const sal_uInt32 nVerticalSegments(GetE3dLatheObj().GetVerticalSegments());
77 const double fDiagonal((double)GetE3dLatheObj().GetPercentDiagonal() / 100.0);
78 const double fBackScale((double)GetE3dLatheObj().GetBackScale() / 100.0);
79 const double fRotation(((double)GetE3dLatheObj().GetEndAngle() / 1800.0) * F_PI);
80 const bool bSmoothNormals(GetE3dLatheObj().GetSmoothNormals()); // Plane itself
81 const bool bSmoothLids(GetE3dLatheObj().GetSmoothLids()); // Front/back
82 const bool bCharacterMode(GetE3dLatheObj().GetCharacterMode());
83 const bool bCloseFront(GetE3dLatheObj().GetCloseFront());
84 const bool bCloseBack(GetE3dLatheObj().GetCloseBack());
86 // create primitive and add
87 const basegfx::B3DHomMatrix aWorldTransform;
88 const drawinglayer::primitive3d::Primitive3DReference xReference(
89 new drawinglayer::primitive3d::SdrLathePrimitive3D(
90 aWorldTransform, aTextureSize, aAttribute, *pSdr3DObjectAttribute,
91 aPolyPolygon, nHorizontalSegments, nVerticalSegments,
92 fDiagonal, fBackScale, fRotation,
93 bSmoothNormals, true, bSmoothLids, bCharacterMode, bCloseFront, bCloseBack));
94 xRetval = drawinglayer::primitive3d::Primitive3DSequence(&xReference, 1);
96 // delete 3D Object Attributes
97 delete pSdr3DObjectAttribute;
99 return xRetval;
101 } // end of namespace contact
102 } // end of namespace sdr
104 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */