LibreOffice Module drawinglayer (master) 1
sdrsphereprimitive3d.cxx
Go to the documentation of this file.
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
28
29
30using namespace com::sun::star;
31
32
34{
36 {
38 const basegfx::B3DRange aUnitRange(0.0, 0.0, 0.0, 1.0, 1.0, 1.0);
39 const bool bCreateNormals(css::drawing::NormalsKind_SPECIFIC == getSdr3DObjectAttribute().getNormalsKind()
40 || css::drawing::NormalsKind_SPHERE == getSdr3DObjectAttribute().getNormalsKind());
41
42 // create unit geometry
44 getHorizontalSegments(), getVerticalSegments(), bCreateNormals));
45
46 // normal inversion
47 if(!getSdrLFSAttribute().getFill().isDefault()
48 && bCreateNormals
49 && getSdr3DObjectAttribute().getNormalsInvert()
50 && aFill.areNormalsUsed())
51 {
52 // invert normals
53 aFill = basegfx::utils::invertNormals(aFill);
54 }
55
56 // texture coordinates
57 if(!getSdrLFSAttribute().getFill().isDefault())
58 {
59 // handle texture coordinates X
60 const bool bParallelX(css::drawing::TextureProjectionMode_PARALLEL == getSdr3DObjectAttribute().getTextureProjectionX());
61 const bool bObjectSpecificX(css::drawing::TextureProjectionMode_OBJECTSPECIFIC == getSdr3DObjectAttribute().getTextureProjectionX());
62 const bool bSphereX(css::drawing::TextureProjectionMode_SPHERE == getSdr3DObjectAttribute().getTextureProjectionX());
63
64 // handle texture coordinates Y
65 const bool bParallelY(css::drawing::TextureProjectionMode_PARALLEL == getSdr3DObjectAttribute().getTextureProjectionY());
66 const bool bObjectSpecificY(css::drawing::TextureProjectionMode_OBJECTSPECIFIC == getSdr3DObjectAttribute().getTextureProjectionY());
67 const bool bSphereY(css::drawing::TextureProjectionMode_SPHERE == getSdr3DObjectAttribute().getTextureProjectionY());
68
69 if(bParallelX || bParallelY)
70 {
71 // apply parallel texture coordinates in X and/or Y
73 aFill = basegfx::utils::applyDefaultTextureCoordinatesParallel(aFill, aRange, bParallelX, bParallelY);
74 }
75
76 if(bSphereX || bObjectSpecificX || bSphereY || bObjectSpecificY)
77 {
78 double fRelativeAngle(0.0);
79
80 if(bObjectSpecificX)
81 {
82 // Since the texture coordinates are (for historical reasons)
83 // different from forced to sphere texture coordinates,
84 // create a old version from it by rotating to old state before applying
85 // the texture coordinates to emulate old behaviour
86 fRelativeAngle = 2 * M_PI * (static_cast<double>((getHorizontalSegments() >> 1) - 1) / static_cast<double>(getHorizontalSegments()));
88 aRot.rotate(0.0, fRelativeAngle, 0.0);
89 aFill.transform(aRot);
90 }
91
92 // apply spherical texture coordinates in X and/or Y
94 const basegfx::B3DPoint aCenter(aRange.getCenter());
96 bSphereX || bObjectSpecificX, bSphereY || bObjectSpecificY);
97
98 if(bObjectSpecificX)
99 {
100 // rotate back again
102 aRot.rotate(0.0, -fRelativeAngle, 0.0);
103 aFill.transform(aRot);
104 }
105 }
106
107 // transform texture coordinates to texture size
108 basegfx::B2DHomMatrix aTexMatrix;
109 aTexMatrix.scale(getTextureSize().getX(), getTextureSize().getY());
110 aFill.transformTextureCoordinates(aTexMatrix);
111 }
112
113 // build vector of PolyPolygons
114 std::vector< basegfx::B3DPolyPolygon > a3DPolyPolygonVector;
115
116 for(sal_uInt32 a(0); a < aFill.count(); a++)
117 {
118 a3DPolyPolygonVector.emplace_back(aFill.getB3DPolygon(a));
119 }
120
121 if(!getSdrLFSAttribute().getFill().isDefault())
122 {
123 // add fill
125 a3DPolyPolygonVector,
126 getTransform(),
129 getSdrLFSAttribute().getFill(),
130 getSdrLFSAttribute().getFillFloatTransGradient());
131 }
132 else
133 {
134 // create simplified 3d hit test geometry
136 a3DPolyPolygonVector,
137 getTransform(),
140 }
141
142 // add line
143 if(!getSdrLFSAttribute().getLine().isDefault())
144 {
147 aSphere, getTransform(), getSdrLFSAttribute().getLine()));
148 aRetval.append(aLines);
149 }
150
151 // add shadow
152 if(!getSdrLFSAttribute().getShadow().isDefault()
153 && !aRetval.empty())
154 {
156 aRetval, getSdrLFSAttribute().getShadow(), getSdr3DObjectAttribute().getShadow3D()));
157 aRetval.append(aShadow);
158 }
159
160 return aRetval;
161 }
162
164 const basegfx::B3DHomMatrix& rTransform,
165 const basegfx::B2DVector& rTextureSize,
166 const attribute::SdrLineFillShadowAttribute3D& rSdrLFSAttribute,
167 const attribute::Sdr3DObjectAttribute& rSdr3DObjectAttribute,
168 sal_uInt32 nHorizontalSegments,
169 sal_uInt32 nVerticalSegments)
170 : SdrPrimitive3D(rTransform, rTextureSize, rSdrLFSAttribute, rSdr3DObjectAttribute),
171 mnHorizontalSegments(nHorizontalSegments),
172 mnVerticalSegments(nVerticalSegments)
173 {
174 }
175
177 {
178 if(SdrPrimitive3D::operator==(rPrimitive))
179 {
180 const SdrSpherePrimitive3D& rCompare = static_cast< const SdrSpherePrimitive3D& >(rPrimitive);
181
182 return (getHorizontalSegments() == rCompare.getHorizontalSegments()
183 && getVerticalSegments() == rCompare.getVerticalSegments());
184 }
185
186 return false;
187 }
188
190 {
191 // use default from sdrPrimitive3D which uses transformation expanded by line width/2
192 // The parent implementation which uses the ranges of the decomposition would be more
193 // correct, but for historical reasons it is necessary to do the old method: To get
194 // the range of the non-transformed geometry and transform it then. This leads to different
195 // ranges where the new method is more correct, but the need to keep the old behaviour
196 // has priority here.
197 return getStandard3DRange();
198 }
199
200 // provide unique ID
202
203} // end of namespace
204
205/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void scale(double fX, double fY)
void rotate(double fAngleX, double fAngleY, double fAngleZ)
void transformTextureCoordinates(const B2DHomMatrix &rMatrix)
sal_uInt32 count() const
void transform(const basegfx::B3DHomMatrix &rMatrix)
bool areNormalsUsed() const
B3DPolygon const & getB3DPolygon(sal_uInt32 nIndex) const
B3DPoint getCenter() const
void append(const Primitive3DContainer &rSource)
const basegfx::B3DHomMatrix & getTransform() const
data read access
const basegfx::B2DVector & getTextureSize() const
const attribute::Sdr3DObjectAttribute & getSdr3DObjectAttribute() const
basegfx::B3DRange getStandard3DRange() const
Standard implementation for primitive3D which will use maTransform as range and expand by evtl.
const attribute::SdrLineFillShadowAttribute3D & getSdrLFSAttribute() const
SdrSpherePrimitive3D(const basegfx::B3DHomMatrix &rTransform, const basegfx::B2DVector &rTextureSize, const attribute::SdrLineFillShadowAttribute3D &rSdrLFSAttribute, const attribute::Sdr3DObjectAttribute &rSdr3DObjectAttribute, sal_uInt32 nHorizontalSegments, sal_uInt32 nVerticalSegments)
constructor
virtual Primitive3DContainer create3DDecomposition(const geometry::ViewInformation3D &rViewInformation) const override
local decomposition.
sal_uInt32 getHorizontalSegments() const
data read access
virtual bool operator==(const BasePrimitive3D &rPrimitive) const override
compare operator
virtual basegfx::B3DRange getB3DRange(const geometry::ViewInformation3D &rViewInformation) const override
get range
#define PRIMITIVE3D_ID_SDRSPHEREPRIMITIVE3D
uno_Any a
B3DPolygon applyDefaultTextureCoordinatesSphere(const B3DPolygon &rCandidate, const B3DPoint &rCenter, bool bChangeX, bool bChangeY)
B3DPolyPolygon createSphereFillPolyPolygonFromB3DRange(const B3DRange &rRange, sal_uInt32 nHorSeg, sal_uInt32 nVerSeg, bool bNormals=false, double fVerStart=M_PI_2, double fVerStop=-M_PI_2, double fHorStart=0.0, double fHorStop=2 *M_PI)
B3DPolyPolygon createSpherePolyPolygonFromB3DRange(const B3DRange &rRange, sal_uInt32 nHorSeg, sal_uInt32 nVerSeg, double fVerStart=M_PI_2, double fVerStop=-M_PI_2, double fHorStart=0.0, double fHorStop=2 *M_PI)
B3DPolygon invertNormals(const B3DPolygon &rCandidate)
B3DPolygon applyDefaultTextureCoordinatesParallel(const B3DPolygon &rCandidate, const B3DRange &rRange, bool bChangeX, bool bChangeY)
B2DRange getRange(const B2DPolygon &rCandidate)
SdrPrimitive3D class.
ImplPrimitive3DIDBlock(PolygonHairlinePrimitive3D, PRIMITIVE3D_ID_POLYGONHAIRLINEPRIMITIVE3D) Primitive3DContainer PolygonStrokePrimitive3D
Primitive3DContainer create3DPolyPolygonFillPrimitives(const std::vector< basegfx::B3DPolyPolygon > &r3DPolyPolygonVector, const basegfx::B3DHomMatrix &rObjectTransform, const basegfx::B2DVector &rTextureSize, const attribute::Sdr3DObjectAttribute &aSdr3DObjectAttribute, const attribute::SdrFillAttribute &rFill, const attribute::FillGradientAttribute &rFillGradient)
Primitive3DContainer createHiddenGeometryPrimitives3D(const std::vector< basegfx::B3DPolyPolygon > &r3DPolyPolygonVector, const basegfx::B3DHomMatrix &rObjectTransform, const basegfx::B2DVector &rTextureSize, const attribute::Sdr3DObjectAttribute &aSdr3DObjectAttribute)
Primitive3DContainer createShadowPrimitive3D(const Primitive3DContainer &rSource, const attribute::SdrShadowAttribute &rShadow, bool bShadow3D)
Primitive3DContainer create3DPolyPolygonLinePrimitives(const basegfx::B3DPolyPolygon &rUnitPolyPolygon, const basegfx::B3DHomMatrix &rObjectTransform, const attribute::SdrLineAttribute &rLine)