xref: /trunk/main/drawinglayer/source/primitive3d/sdrcubeprimitive3d.cxx (revision 6e2947abcd32c68d8b41a6b46ee7d63b91c825fe)
1464702f4SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3464702f4SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4464702f4SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5464702f4SAndrew Rist  * distributed with this work for additional information
6464702f4SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7464702f4SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8464702f4SAndrew Rist  * "License"); you may not use this file except in compliance
9464702f4SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11464702f4SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13464702f4SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14464702f4SAndrew Rist  * software distributed under the License is distributed on an
15464702f4SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16464702f4SAndrew Rist  * KIND, either express or implied.  See the License for the
17464702f4SAndrew Rist  * specific language governing permissions and limitations
18464702f4SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20464702f4SAndrew Rist  *************************************************************/
21464702f4SAndrew Rist 
22464702f4SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_drawinglayer.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <drawinglayer/primitive3d/sdrcubeprimitive3d.hxx>
28cdf0e10cSrcweir #include <basegfx/polygon/b3dpolypolygontools.hxx>
29cdf0e10cSrcweir #include <basegfx/polygon/b3dpolygon.hxx>
30cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrix.hxx>
31cdf0e10cSrcweir #include <drawinglayer/primitive3d/sdrdecompositiontools3d.hxx>
32cdf0e10cSrcweir #include <basegfx/tools/canvastools.hxx>
33cdf0e10cSrcweir #include <drawinglayer/primitive3d/drawinglayer_primitivetypes3d.hxx>
34cdf0e10cSrcweir #include <drawinglayer/attribute/sdrfillattribute.hxx>
35cdf0e10cSrcweir #include <drawinglayer/attribute/sdrlineattribute.hxx>
36cdf0e10cSrcweir #include <drawinglayer/attribute/sdrshadowattribute.hxx>
37cdf0e10cSrcweir 
38cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
39cdf0e10cSrcweir 
40cdf0e10cSrcweir using namespace com::sun::star;
41cdf0e10cSrcweir 
42cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
43cdf0e10cSrcweir 
44cdf0e10cSrcweir namespace drawinglayer
45cdf0e10cSrcweir {
46cdf0e10cSrcweir     namespace primitive3d
47cdf0e10cSrcweir     {
create3DDecomposition(const geometry::ViewInformation3D &) const48cdf0e10cSrcweir         Primitive3DSequence SdrCubePrimitive3D::create3DDecomposition(const geometry::ViewInformation3D& /*rViewInformation*/) const
49cdf0e10cSrcweir         {
50cdf0e10cSrcweir             const basegfx::B3DRange aUnitRange(0.0, 0.0, 0.0, 1.0, 1.0, 1.0);
51cdf0e10cSrcweir             Primitive3DSequence aRetval;
52cdf0e10cSrcweir             basegfx::B3DPolyPolygon aFill(basegfx::tools::createCubeFillPolyPolygonFromB3DRange(aUnitRange));
53cdf0e10cSrcweir 
54cdf0e10cSrcweir             // normal creation
55cdf0e10cSrcweir             if(!getSdrLFSAttribute().getFill().isDefault())
56cdf0e10cSrcweir             {
57cdf0e10cSrcweir                 if(::com::sun::star::drawing::NormalsKind_SPECIFIC == getSdr3DObjectAttribute().getNormalsKind()
58cdf0e10cSrcweir                     || ::com::sun::star::drawing::NormalsKind_SPHERE == getSdr3DObjectAttribute().getNormalsKind())
59cdf0e10cSrcweir                 {
60cdf0e10cSrcweir                     // create sphere normals
61cdf0e10cSrcweir                     const basegfx::B3DPoint aCenter(basegfx::tools::getRange(aFill).getCenter());
62cdf0e10cSrcweir                     aFill = basegfx::tools::applyDefaultNormalsSphere(aFill, aCenter);
63cdf0e10cSrcweir                 }
64cdf0e10cSrcweir 
65cdf0e10cSrcweir                 if(getSdr3DObjectAttribute().getNormalsInvert())
66cdf0e10cSrcweir                 {
67cdf0e10cSrcweir                     // invert normals
68cdf0e10cSrcweir                     aFill = basegfx::tools::invertNormals(aFill);
69cdf0e10cSrcweir                 }
70cdf0e10cSrcweir             }
71cdf0e10cSrcweir 
72cdf0e10cSrcweir             // texture coordinates
73cdf0e10cSrcweir             if(!getSdrLFSAttribute().getFill().isDefault())
74cdf0e10cSrcweir             {
75cdf0e10cSrcweir                 // handle texture coordinates X
76cdf0e10cSrcweir                 const bool bParallelX(::com::sun::star::drawing::TextureProjectionMode_PARALLEL == getSdr3DObjectAttribute().getTextureProjectionX());
77cdf0e10cSrcweir                 const bool bObjectSpecificX(::com::sun::star::drawing::TextureProjectionMode_OBJECTSPECIFIC == getSdr3DObjectAttribute().getTextureProjectionX());
78cdf0e10cSrcweir                 const bool bSphereX(!bParallelX && (::com::sun::star::drawing::TextureProjectionMode_SPHERE == getSdr3DObjectAttribute().getTextureProjectionX()));
79cdf0e10cSrcweir 
80cdf0e10cSrcweir                 // handle texture coordinates Y
81cdf0e10cSrcweir                 const bool bParallelY(::com::sun::star::drawing::TextureProjectionMode_PARALLEL == getSdr3DObjectAttribute().getTextureProjectionY());
82cdf0e10cSrcweir                 const bool bObjectSpecificY(::com::sun::star::drawing::TextureProjectionMode_OBJECTSPECIFIC == getSdr3DObjectAttribute().getTextureProjectionY());
83cdf0e10cSrcweir                 const bool bSphereY(!bParallelY && (::com::sun::star::drawing::TextureProjectionMode_SPHERE == getSdr3DObjectAttribute().getTextureProjectionY()));
84cdf0e10cSrcweir 
85cdf0e10cSrcweir                 if(bParallelX || bParallelY)
86cdf0e10cSrcweir                 {
87cdf0e10cSrcweir                     // apply parallel texture coordinates in X and/or Y
88cdf0e10cSrcweir                     const basegfx::B3DRange aRange(basegfx::tools::getRange(aFill));
89cdf0e10cSrcweir                     aFill = basegfx::tools::applyDefaultTextureCoordinatesParallel(aFill, aRange, bParallelX, bParallelY);
90cdf0e10cSrcweir                 }
91cdf0e10cSrcweir 
92cdf0e10cSrcweir                 if(bSphereX || bSphereY)
93cdf0e10cSrcweir                 {
94cdf0e10cSrcweir                     // apply spherical texture coordinates in X and/or Y
95cdf0e10cSrcweir                     const basegfx::B3DRange aRange(basegfx::tools::getRange(aFill));
96cdf0e10cSrcweir                     const basegfx::B3DPoint aCenter(aRange.getCenter());
97cdf0e10cSrcweir                     aFill = basegfx::tools::applyDefaultTextureCoordinatesSphere(aFill, aCenter, bSphereX, bSphereY);
98cdf0e10cSrcweir                 }
99cdf0e10cSrcweir 
100cdf0e10cSrcweir                 if(bObjectSpecificX || bObjectSpecificY)
101cdf0e10cSrcweir                 {
102cdf0e10cSrcweir                     // object-specific
103cdf0e10cSrcweir                     for(sal_uInt32 a(0L); a < aFill.count(); a++)
104cdf0e10cSrcweir                     {
105cdf0e10cSrcweir                         basegfx::B3DPolygon aTmpPoly(aFill.getB3DPolygon(a));
106cdf0e10cSrcweir 
107cdf0e10cSrcweir                         if(aTmpPoly.count() >= 4L)
108cdf0e10cSrcweir                         {
109cdf0e10cSrcweir                             for(sal_uInt32 b(0L); b < 4L; b++)
110cdf0e10cSrcweir                             {
111cdf0e10cSrcweir                                 basegfx::B2DPoint aPoint(aTmpPoly.getTextureCoordinate(b));
112cdf0e10cSrcweir 
113cdf0e10cSrcweir                                 if(bObjectSpecificX)
114cdf0e10cSrcweir                                 {
115cdf0e10cSrcweir                                     aPoint.setX((1L == b || 2L == b) ? 1.0 : 0.0);
116cdf0e10cSrcweir                                 }
117cdf0e10cSrcweir 
118cdf0e10cSrcweir                                 if(bObjectSpecificY)
119cdf0e10cSrcweir                                 {
120cdf0e10cSrcweir                                     aPoint.setY((2L == b || 3L == b) ? 1.0 : 0.0);
121cdf0e10cSrcweir                                 }
122cdf0e10cSrcweir 
123cdf0e10cSrcweir                                 aTmpPoly.setTextureCoordinate(b, aPoint);
124cdf0e10cSrcweir                             }
125cdf0e10cSrcweir 
126cdf0e10cSrcweir                             aFill.setB3DPolygon(a, aTmpPoly);
127cdf0e10cSrcweir                         }
128cdf0e10cSrcweir                     }
129cdf0e10cSrcweir                 }
130cdf0e10cSrcweir 
131cdf0e10cSrcweir                 // transform texture coordinates to texture size
132cdf0e10cSrcweir                 basegfx::B2DHomMatrix aTexMatrix;
133cdf0e10cSrcweir                 aTexMatrix.scale(getTextureSize().getX(), getTextureSize().getY());
134cdf0e10cSrcweir                 aFill.transformTextureCoordiantes(aTexMatrix);
135cdf0e10cSrcweir             }
136cdf0e10cSrcweir 
137cdf0e10cSrcweir             // build vector of PolyPolygons
138cdf0e10cSrcweir             ::std::vector< basegfx::B3DPolyPolygon > a3DPolyPolygonVector;
139cdf0e10cSrcweir 
140cdf0e10cSrcweir             for(sal_uInt32 a(0L); a < aFill.count(); a++)
141cdf0e10cSrcweir             {
142cdf0e10cSrcweir                 a3DPolyPolygonVector.push_back(basegfx::B3DPolyPolygon(aFill.getB3DPolygon(a)));
143cdf0e10cSrcweir             }
144cdf0e10cSrcweir 
145cdf0e10cSrcweir             if(!getSdrLFSAttribute().getFill().isDefault())
146cdf0e10cSrcweir             {
147cdf0e10cSrcweir                 // add fill
148cdf0e10cSrcweir                 aRetval = create3DPolyPolygonFillPrimitives(
149cdf0e10cSrcweir                     a3DPolyPolygonVector,
150cdf0e10cSrcweir                     getTransform(),
151cdf0e10cSrcweir                     getTextureSize(),
152cdf0e10cSrcweir                     getSdr3DObjectAttribute(),
153cdf0e10cSrcweir                     getSdrLFSAttribute().getFill(),
154cdf0e10cSrcweir                     getSdrLFSAttribute().getFillFloatTransGradient());
155cdf0e10cSrcweir             }
156cdf0e10cSrcweir             else
157cdf0e10cSrcweir             {
158cdf0e10cSrcweir                 // create simplified 3d hit test geometry
159cdf0e10cSrcweir                 aRetval = createHiddenGeometryPrimitives3D(
160cdf0e10cSrcweir                     a3DPolyPolygonVector,
161cdf0e10cSrcweir                     getTransform(),
162cdf0e10cSrcweir                     getTextureSize(),
163cdf0e10cSrcweir                     getSdr3DObjectAttribute());
164cdf0e10cSrcweir             }
165cdf0e10cSrcweir 
166cdf0e10cSrcweir             // add line
167cdf0e10cSrcweir             if(!getSdrLFSAttribute().getLine().isDefault())
168cdf0e10cSrcweir             {
169cdf0e10cSrcweir                 basegfx::B3DPolyPolygon aLine(basegfx::tools::createCubePolyPolygonFromB3DRange(aUnitRange));
170cdf0e10cSrcweir                 const Primitive3DSequence aLines(create3DPolyPolygonLinePrimitives(
171cdf0e10cSrcweir                     aLine, getTransform(), getSdrLFSAttribute().getLine()));
172cdf0e10cSrcweir                 appendPrimitive3DSequenceToPrimitive3DSequence(aRetval, aLines);
173cdf0e10cSrcweir             }
174cdf0e10cSrcweir 
175cdf0e10cSrcweir             // add shadow
176cdf0e10cSrcweir             if(!getSdrLFSAttribute().getShadow().isDefault() && aRetval.hasElements())
177cdf0e10cSrcweir             {
178cdf0e10cSrcweir                 const Primitive3DSequence aShadow(createShadowPrimitive3D(
179cdf0e10cSrcweir                     aRetval, getSdrLFSAttribute().getShadow(), getSdr3DObjectAttribute().getShadow3D()));
180cdf0e10cSrcweir                 appendPrimitive3DSequenceToPrimitive3DSequence(aRetval, aShadow);
181cdf0e10cSrcweir             }
182cdf0e10cSrcweir 
183cdf0e10cSrcweir             return aRetval;
184cdf0e10cSrcweir         }
185cdf0e10cSrcweir 
SdrCubePrimitive3D(const basegfx::B3DHomMatrix & rTransform,const basegfx::B2DVector & rTextureSize,const attribute::SdrLineFillShadowAttribute3D & rSdrLFSAttribute,const attribute::Sdr3DObjectAttribute & rSdr3DObjectAttribute)186cdf0e10cSrcweir         SdrCubePrimitive3D::SdrCubePrimitive3D(
187cdf0e10cSrcweir             const basegfx::B3DHomMatrix& rTransform,
188cdf0e10cSrcweir             const basegfx::B2DVector& rTextureSize,
189cdf0e10cSrcweir             const attribute::SdrLineFillShadowAttribute3D& rSdrLFSAttribute,
190cdf0e10cSrcweir             const attribute::Sdr3DObjectAttribute& rSdr3DObjectAttribute)
191cdf0e10cSrcweir         :   SdrPrimitive3D(rTransform, rTextureSize, rSdrLFSAttribute, rSdr3DObjectAttribute)
192cdf0e10cSrcweir         {
193cdf0e10cSrcweir         }
194cdf0e10cSrcweir 
operator ==(const BasePrimitive3D & rPrimitive) const195cdf0e10cSrcweir         bool SdrCubePrimitive3D::operator==(const BasePrimitive3D& rPrimitive) const
196cdf0e10cSrcweir         {
197cdf0e10cSrcweir             return SdrPrimitive3D::operator==(rPrimitive);
198cdf0e10cSrcweir         }
199cdf0e10cSrcweir 
getB3DRange(const geometry::ViewInformation3D &) const200cdf0e10cSrcweir         basegfx::B3DRange SdrCubePrimitive3D::getB3DRange(const geometry::ViewInformation3D& /*rViewInformation*/) const
201cdf0e10cSrcweir         {
202*6e2947abSJohn Bampton             // use default from sdrPrimitive3D which uses transformation expanded by line width/2.
203cdf0e10cSrcweir             // The parent implementation which uses the ranges of the decomposition would be more
204*6e2947abSJohn Bampton             // correct, but for historical reasons it is necessary to do the old method: To get
205cdf0e10cSrcweir             // the range of the non-transformed geometry and transform it then. This leads to different
206cdf0e10cSrcweir             // ranges where the new method is more correct, but the need to keep the old behaviour
207cdf0e10cSrcweir             // has priority here.
208cdf0e10cSrcweir             return getStandard3DRange();
209cdf0e10cSrcweir         }
210cdf0e10cSrcweir 
211cdf0e10cSrcweir         // provide unique ID
212cdf0e10cSrcweir         ImplPrimitrive3DIDBlock(SdrCubePrimitive3D, PRIMITIVE3D_ID_SDRCUBEPRIMITIVE3D)
213cdf0e10cSrcweir 
214cdf0e10cSrcweir     } // end of namespace primitive3d
215cdf0e10cSrcweir } // end of namespace drawinglayer
216cdf0e10cSrcweir 
217cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
218cdf0e10cSrcweir // eof
219