/src/libreoffice/drawinglayer/source/primitive3d/sdrsphereprimitive3d.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | |
20 | | #include <com/sun/star/drawing/NormalsKind.hpp> |
21 | | #include <drawinglayer/primitive3d/sdrsphereprimitive3d.hxx> |
22 | | #include <basegfx/polygon/b3dpolypolygontools.hxx> |
23 | | #include <basegfx/range/b3drange.hxx> |
24 | | #include <basegfx/matrix/b2dhommatrix.hxx> |
25 | | #include <primitive3d/sdrdecompositiontools3d.hxx> |
26 | | #include <drawinglayer/primitive3d/drawinglayer_primitivetypes3d.hxx> |
27 | | #include <drawinglayer/attribute/sdrfillattribute.hxx> |
28 | | #include <drawinglayer/attribute/sdrlineattribute.hxx> |
29 | | #include <drawinglayer/attribute/sdrshadowattribute.hxx> |
30 | | |
31 | | |
32 | | using namespace com::sun::star; |
33 | | |
34 | | |
35 | | namespace drawinglayer::primitive3d |
36 | | { |
37 | | Primitive3DContainer SdrSpherePrimitive3D::create3DDecomposition(const geometry::ViewInformation3D& /*rViewInformation*/) const |
38 | 0 | { |
39 | 0 | Primitive3DContainer aRetval; |
40 | 0 | const basegfx::B3DRange aUnitRange(0.0, 0.0, 0.0, 1.0, 1.0, 1.0); |
41 | 0 | const bool bCreateNormals(css::drawing::NormalsKind_SPECIFIC == getSdr3DObjectAttribute().getNormalsKind() |
42 | 0 | || css::drawing::NormalsKind_SPHERE == getSdr3DObjectAttribute().getNormalsKind()); |
43 | | |
44 | | // create unit geometry |
45 | 0 | basegfx::B3DPolyPolygon aFill(basegfx::utils::createSphereFillPolyPolygonFromB3DRange(aUnitRange, |
46 | 0 | getHorizontalSegments(), getVerticalSegments(), bCreateNormals)); |
47 | | |
48 | | // normal inversion |
49 | 0 | if(!getSdrLFSAttribute().getFill().isDefault() |
50 | 0 | && bCreateNormals |
51 | 0 | && getSdr3DObjectAttribute().getNormalsInvert() |
52 | 0 | && aFill.areNormalsUsed()) |
53 | 0 | { |
54 | | // invert normals |
55 | 0 | aFill = basegfx::utils::invertNormals(aFill); |
56 | 0 | } |
57 | | |
58 | | // texture coordinates |
59 | 0 | if(!getSdrLFSAttribute().getFill().isDefault()) |
60 | 0 | { |
61 | | // handle texture coordinates X |
62 | 0 | const bool bParallelX(css::drawing::TextureProjectionMode_PARALLEL == getSdr3DObjectAttribute().getTextureProjectionX()); |
63 | 0 | const bool bObjectSpecificX(css::drawing::TextureProjectionMode_OBJECTSPECIFIC == getSdr3DObjectAttribute().getTextureProjectionX()); |
64 | 0 | const bool bSphereX(css::drawing::TextureProjectionMode_SPHERE == getSdr3DObjectAttribute().getTextureProjectionX()); |
65 | | |
66 | | // handle texture coordinates Y |
67 | 0 | const bool bParallelY(css::drawing::TextureProjectionMode_PARALLEL == getSdr3DObjectAttribute().getTextureProjectionY()); |
68 | 0 | const bool bObjectSpecificY(css::drawing::TextureProjectionMode_OBJECTSPECIFIC == getSdr3DObjectAttribute().getTextureProjectionY()); |
69 | 0 | const bool bSphereY(css::drawing::TextureProjectionMode_SPHERE == getSdr3DObjectAttribute().getTextureProjectionY()); |
70 | |
|
71 | 0 | if(bParallelX || bParallelY) |
72 | 0 | { |
73 | | // apply parallel texture coordinates in X and/or Y |
74 | 0 | const basegfx::B3DRange aRange(basegfx::utils::getRange(aFill)); |
75 | 0 | aFill = basegfx::utils::applyDefaultTextureCoordinatesParallel(aFill, aRange, bParallelX, bParallelY); |
76 | 0 | } |
77 | |
|
78 | 0 | if(bSphereX || bObjectSpecificX || bSphereY || bObjectSpecificY) |
79 | 0 | { |
80 | 0 | double fRelativeAngle(0.0); |
81 | |
|
82 | 0 | if(bObjectSpecificX) |
83 | 0 | { |
84 | | // Since the texture coordinates are (for historical reasons) |
85 | | // different from forced to sphere texture coordinates, |
86 | | // create a old version from it by rotating to old state before applying |
87 | | // the texture coordinates to emulate old behaviour |
88 | 0 | fRelativeAngle = 2 * M_PI * (static_cast<double>((getHorizontalSegments() >> 1) - 1) / static_cast<double>(getHorizontalSegments())); |
89 | 0 | basegfx::B3DHomMatrix aRot; |
90 | 0 | aRot.rotate(0.0, fRelativeAngle, 0.0); |
91 | 0 | aFill.transform(aRot); |
92 | 0 | } |
93 | | |
94 | | // apply spherical texture coordinates in X and/or Y |
95 | 0 | const basegfx::B3DRange aRange(basegfx::utils::getRange(aFill)); |
96 | 0 | const basegfx::B3DPoint aCenter(aRange.getCenter()); |
97 | 0 | aFill = basegfx::utils::applyDefaultTextureCoordinatesSphere(aFill, aCenter, |
98 | 0 | bSphereX || bObjectSpecificX, bSphereY || bObjectSpecificY); |
99 | |
|
100 | 0 | if(bObjectSpecificX) |
101 | 0 | { |
102 | | // rotate back again |
103 | 0 | basegfx::B3DHomMatrix aRot; |
104 | 0 | aRot.rotate(0.0, -fRelativeAngle, 0.0); |
105 | 0 | aFill.transform(aRot); |
106 | 0 | } |
107 | 0 | } |
108 | | |
109 | | // transform texture coordinates to texture size |
110 | 0 | basegfx::B2DHomMatrix aTexMatrix; |
111 | 0 | aTexMatrix.scale(getTextureSize().getX(), getTextureSize().getY()); |
112 | 0 | aFill.transformTextureCoordinates(aTexMatrix); |
113 | 0 | } |
114 | | |
115 | | // build vector of PolyPolygons |
116 | 0 | std::vector< basegfx::B3DPolyPolygon > a3DPolyPolygonVector; |
117 | |
|
118 | 0 | for(sal_uInt32 a(0); a < aFill.count(); a++) |
119 | 0 | { |
120 | 0 | a3DPolyPolygonVector.emplace_back(aFill.getB3DPolygon(a)); |
121 | 0 | } |
122 | |
|
123 | 0 | if(!getSdrLFSAttribute().getFill().isDefault()) |
124 | 0 | { |
125 | | // add fill |
126 | 0 | aRetval = create3DPolyPolygonFillPrimitives( |
127 | 0 | a3DPolyPolygonVector, |
128 | 0 | getTransform(), |
129 | 0 | getTextureSize(), |
130 | 0 | getSdr3DObjectAttribute(), |
131 | 0 | getSdrLFSAttribute().getFill(), |
132 | 0 | getSdrLFSAttribute().getFillFloatTransGradient()); |
133 | 0 | } |
134 | 0 | else |
135 | 0 | { |
136 | | // create simplified 3d hit test geometry |
137 | 0 | aRetval = createHiddenGeometryPrimitives3D( |
138 | 0 | a3DPolyPolygonVector, |
139 | 0 | getTransform(), |
140 | 0 | getTextureSize(), |
141 | 0 | getSdr3DObjectAttribute()); |
142 | 0 | } |
143 | | |
144 | | // add line |
145 | 0 | if(!getSdrLFSAttribute().getLine().isDefault()) |
146 | 0 | { |
147 | 0 | basegfx::B3DPolyPolygon aSphere(basegfx::utils::createSpherePolyPolygonFromB3DRange(aUnitRange, getHorizontalSegments(), getVerticalSegments())); |
148 | 0 | const Primitive3DContainer aLines(create3DPolyPolygonLinePrimitives( |
149 | 0 | aSphere, getTransform(), getSdrLFSAttribute().getLine())); |
150 | 0 | aRetval.append(aLines); |
151 | 0 | } |
152 | | |
153 | | // add shadow |
154 | 0 | if(!getSdrLFSAttribute().getShadow().isDefault() |
155 | 0 | && !aRetval.empty()) |
156 | 0 | { |
157 | 0 | const Primitive3DContainer aShadow(createShadowPrimitive3D( |
158 | 0 | aRetval, getSdrLFSAttribute().getShadow(), getSdr3DObjectAttribute().getShadow3D())); |
159 | 0 | aRetval.append(aShadow); |
160 | 0 | } |
161 | |
|
162 | 0 | return aRetval; |
163 | 0 | } |
164 | | |
165 | | SdrSpherePrimitive3D::SdrSpherePrimitive3D( |
166 | | const basegfx::B3DHomMatrix& rTransform, |
167 | | const basegfx::B2DVector& rTextureSize, |
168 | | const attribute::SdrLineFillShadowAttribute3D& rSdrLFSAttribute, |
169 | | const attribute::Sdr3DObjectAttribute& rSdr3DObjectAttribute, |
170 | | sal_uInt32 nHorizontalSegments, |
171 | | sal_uInt32 nVerticalSegments) |
172 | 0 | : SdrPrimitive3D(rTransform, rTextureSize, rSdrLFSAttribute, rSdr3DObjectAttribute), |
173 | 0 | mnHorizontalSegments(nHorizontalSegments), |
174 | 0 | mnVerticalSegments(nVerticalSegments) |
175 | 0 | { |
176 | 0 | } Unexecuted instantiation: drawinglayer::primitive3d::SdrSpherePrimitive3D::SdrSpherePrimitive3D(basegfx::B3DHomMatrix const&, basegfx::B2DVector const&, drawinglayer::attribute::SdrLineFillShadowAttribute3D const&, drawinglayer::attribute::Sdr3DObjectAttribute const&, unsigned int, unsigned int) Unexecuted instantiation: drawinglayer::primitive3d::SdrSpherePrimitive3D::SdrSpherePrimitive3D(basegfx::B3DHomMatrix const&, basegfx::B2DVector const&, drawinglayer::attribute::SdrLineFillShadowAttribute3D const&, drawinglayer::attribute::Sdr3DObjectAttribute const&, unsigned int, unsigned int) |
177 | | |
178 | | bool SdrSpherePrimitive3D::operator==(const BasePrimitive3D& rPrimitive) const |
179 | 0 | { |
180 | 0 | if(SdrPrimitive3D::operator==(rPrimitive)) |
181 | 0 | { |
182 | 0 | const SdrSpherePrimitive3D& rCompare = static_cast< const SdrSpherePrimitive3D& >(rPrimitive); |
183 | |
|
184 | 0 | return (getHorizontalSegments() == rCompare.getHorizontalSegments() |
185 | 0 | && getVerticalSegments() == rCompare.getVerticalSegments()); |
186 | 0 | } |
187 | | |
188 | 0 | return false; |
189 | 0 | } |
190 | | |
191 | | basegfx::B3DRange SdrSpherePrimitive3D::getB3DRange(const geometry::ViewInformation3D& /*rViewInformation*/) const |
192 | 0 | { |
193 | | // use default from sdrPrimitive3D which uses transformation expanded by line width/2 |
194 | | // The parent implementation which uses the ranges of the decomposition would be more |
195 | | // correct, but for historical reasons it is necessary to do the old method: To get |
196 | | // the range of the non-transformed geometry and transform it then. This leads to different |
197 | | // ranges where the new method is more correct, but the need to keep the old behaviour |
198 | | // has priority here. |
199 | 0 | return getStandard3DRange(); |
200 | 0 | } |
201 | | |
202 | | // provide unique ID |
203 | | ImplPrimitive3DIDBlock(SdrSpherePrimitive3D, PRIMITIVE3D_ID_SDRSPHEREPRIMITIVE3D) |
204 | | |
205 | | } // end of namespace |
206 | | |
207 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |