1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include <drawinglayer/primitive3d/sdrcubeprimitive3d.hxx>
30 #include <basegfx/polygon/b3dpolypolygontools.hxx>
31 #include <basegfx/polygon/b3dpolygon.hxx>
32 #include <basegfx/matrix/b2dhommatrix.hxx>
33 #include <drawinglayer/primitive3d/sdrdecompositiontools3d.hxx>
34 #include <basegfx/tools/canvastools.hxx>
35 #include <drawinglayer/primitive3d/drawinglayer_primitivetypes3d.hxx>
36 #include <drawinglayer/attribute/sdrfillattribute.hxx>
37 #include <drawinglayer/attribute/sdrlineattribute.hxx>
38 #include <drawinglayer/attribute/sdrshadowattribute.hxx>
40 //////////////////////////////////////////////////////////////////////////////
42 using namespace com::sun::star
;
44 //////////////////////////////////////////////////////////////////////////////
46 namespace drawinglayer
50 Primitive3DSequence
SdrCubePrimitive3D::create3DDecomposition(const geometry::ViewInformation3D
& /*rViewInformation*/) const
52 const basegfx::B3DRange
aUnitRange(0.0, 0.0, 0.0, 1.0, 1.0, 1.0);
53 Primitive3DSequence aRetval
;
54 basegfx::B3DPolyPolygon
aFill(basegfx::tools::createCubeFillPolyPolygonFromB3DRange(aUnitRange
));
57 if(!getSdrLFSAttribute().getFill().isDefault())
59 if(::com::sun::star::drawing::NormalsKind_SPECIFIC
== getSdr3DObjectAttribute().getNormalsKind()
60 || ::com::sun::star::drawing::NormalsKind_SPHERE
== getSdr3DObjectAttribute().getNormalsKind())
62 // create sphere normals
63 const basegfx::B3DPoint
aCenter(basegfx::tools::getRange(aFill
).getCenter());
64 aFill
= basegfx::tools::applyDefaultNormalsSphere(aFill
, aCenter
);
67 if(getSdr3DObjectAttribute().getNormalsInvert())
70 aFill
= basegfx::tools::invertNormals(aFill
);
74 // texture coordinates
75 if(!getSdrLFSAttribute().getFill().isDefault())
77 // handle texture coordinates X
78 const bool bParallelX(::com::sun::star::drawing::TextureProjectionMode_PARALLEL
== getSdr3DObjectAttribute().getTextureProjectionX());
79 const bool bObjectSpecificX(::com::sun::star::drawing::TextureProjectionMode_OBJECTSPECIFIC
== getSdr3DObjectAttribute().getTextureProjectionX());
80 const bool bSphereX(!bParallelX
&& (::com::sun::star::drawing::TextureProjectionMode_SPHERE
== getSdr3DObjectAttribute().getTextureProjectionX()));
82 // handle texture coordinates Y
83 const bool bParallelY(::com::sun::star::drawing::TextureProjectionMode_PARALLEL
== getSdr3DObjectAttribute().getTextureProjectionY());
84 const bool bObjectSpecificY(::com::sun::star::drawing::TextureProjectionMode_OBJECTSPECIFIC
== getSdr3DObjectAttribute().getTextureProjectionY());
85 const bool bSphereY(!bParallelY
&& (::com::sun::star::drawing::TextureProjectionMode_SPHERE
== getSdr3DObjectAttribute().getTextureProjectionY()));
87 if(bParallelX
|| bParallelY
)
89 // apply parallel texture coordinates in X and/or Y
90 const basegfx::B3DRange
aRange(basegfx::tools::getRange(aFill
));
91 aFill
= basegfx::tools::applyDefaultTextureCoordinatesParallel(aFill
, aRange
, bParallelX
, bParallelY
);
94 if(bSphereX
|| bSphereY
)
96 // apply spherical texture coordinates in X and/or Y
97 const basegfx::B3DRange
aRange(basegfx::tools::getRange(aFill
));
98 const basegfx::B3DPoint
aCenter(aRange
.getCenter());
99 aFill
= basegfx::tools::applyDefaultTextureCoordinatesSphere(aFill
, aCenter
, bSphereX
, bSphereY
);
102 if(bObjectSpecificX
|| bObjectSpecificY
)
105 for(sal_uInt32
a(0L); a
< aFill
.count(); a
++)
107 basegfx::B3DPolygon
aTmpPoly(aFill
.getB3DPolygon(a
));
109 if(aTmpPoly
.count() >= 4L)
111 for(sal_uInt32
b(0L); b
< 4L; b
++)
113 basegfx::B2DPoint
aPoint(aTmpPoly
.getTextureCoordinate(b
));
117 aPoint
.setX((1L == b
|| 2L == b
) ? 1.0 : 0.0);
122 aPoint
.setY((2L == b
|| 3L == b
) ? 1.0 : 0.0);
125 aTmpPoly
.setTextureCoordinate(b
, aPoint
);
128 aFill
.setB3DPolygon(a
, aTmpPoly
);
133 // transform texture coordinates to texture size
134 basegfx::B2DHomMatrix aTexMatrix
;
135 aTexMatrix
.scale(getTextureSize().getX(), getTextureSize().getY());
136 aFill
.transformTextureCoordiantes(aTexMatrix
);
139 // build vector of PolyPolygons
140 ::std::vector
< basegfx::B3DPolyPolygon
> a3DPolyPolygonVector
;
142 for(sal_uInt32
a(0L); a
< aFill
.count(); a
++)
144 a3DPolyPolygonVector
.push_back(basegfx::B3DPolyPolygon(aFill
.getB3DPolygon(a
)));
147 if(!getSdrLFSAttribute().getFill().isDefault())
150 aRetval
= create3DPolyPolygonFillPrimitives(
151 a3DPolyPolygonVector
,
154 getSdr3DObjectAttribute(),
155 getSdrLFSAttribute().getFill(),
156 getSdrLFSAttribute().getFillFloatTransGradient());
160 // create simplified 3d hit test geometry
161 aRetval
= createHiddenGeometryPrimitives3D(
162 a3DPolyPolygonVector
,
165 getSdr3DObjectAttribute());
169 if(!getSdrLFSAttribute().getLine().isDefault())
171 basegfx::B3DPolyPolygon
aLine(basegfx::tools::createCubePolyPolygonFromB3DRange(aUnitRange
));
172 const Primitive3DSequence
aLines(create3DPolyPolygonLinePrimitives(
173 aLine
, getTransform(), getSdrLFSAttribute().getLine()));
174 appendPrimitive3DSequenceToPrimitive3DSequence(aRetval
, aLines
);
178 if(!getSdrLFSAttribute().getShadow().isDefault() && aRetval
.hasElements())
180 const Primitive3DSequence
aShadow(createShadowPrimitive3D(
181 aRetval
, getSdrLFSAttribute().getShadow(), getSdr3DObjectAttribute().getShadow3D()));
182 appendPrimitive3DSequenceToPrimitive3DSequence(aRetval
, aShadow
);
188 SdrCubePrimitive3D::SdrCubePrimitive3D(
189 const basegfx::B3DHomMatrix
& rTransform
,
190 const basegfx::B2DVector
& rTextureSize
,
191 const attribute::SdrLineFillShadowAttribute3D
& rSdrLFSAttribute
,
192 const attribute::Sdr3DObjectAttribute
& rSdr3DObjectAttribute
)
193 : SdrPrimitive3D(rTransform
, rTextureSize
, rSdrLFSAttribute
, rSdr3DObjectAttribute
)
197 bool SdrCubePrimitive3D::operator==(const BasePrimitive3D
& rPrimitive
) const
199 return SdrPrimitive3D::operator==(rPrimitive
);
202 basegfx::B3DRange
SdrCubePrimitive3D::getB3DRange(const geometry::ViewInformation3D
& /*rViewInformation*/) const
204 // use defaut from sdrPrimitive3D which uses transformation expanded by line width/2.
205 // The parent implementation which uses the ranges of the decomposition would be more
206 // corrcet, but for historical reasons it is necessary to do the old method: To get
207 // the range of the non-transformed geometry and transform it then. This leads to different
208 // ranges where the new method is more correct, but the need to keep the old behaviour
209 // has priority here.
210 return getStandard3DRange();
214 ImplPrimitrive3DIDBlock(SdrCubePrimitive3D
, PRIMITIVE3D_ID_SDRCUBEPRIMITIVE3D
)
216 } // end of namespace primitive3d
217 } // end of namespace drawinglayer
219 //////////////////////////////////////////////////////////////////////////////
222 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */