1 /*************************************************************************
3 * OpenOffice.org - a multi-platform office productivity suite
5 * $RCSfile: sdrcubeprimitive3d.cxx,v $
9 * last change: $Author: aw $ $Date: 2008-06-10 09:29:33 $
11 * The Contents of this file are made available subject to
12 * the terms of GNU Lesser General Public License Version 2.1.
15 * GNU Lesser General Public License Version 2.1
16 * =============================================
17 * Copyright 2005 by Sun Microsystems, Inc.
18 * 901 San Antonio Road, Palo Alto, CA 94303, USA
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Lesser General Public
22 * License version 2.1, as published by the Free Software Foundation.
24 * This library is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 * Lesser General Public License for more details.
29 * You should have received a copy of the GNU Lesser General Public
30 * License along with this library; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
34 ************************************************************************/
36 // MARKER(update_precomp.py): autogen include statement, do not remove
37 #include "precompiled_drawinglayer.hxx"
39 #include <drawinglayer/primitive3d/sdrcubeprimitive3d.hxx>
40 #include <basegfx/polygon/b3dpolypolygontools.hxx>
41 #include <basegfx/polygon/b3dpolygon.hxx>
42 #include <basegfx/matrix/b2dhommatrix.hxx>
43 #include <drawinglayer/primitive3d/sdrdecompositiontools3d.hxx>
44 #include <basegfx/tools/canvastools.hxx>
45 #include <drawinglayer/primitive3d/drawinglayer_primitivetypes3d.hxx>
46 #include <drawinglayer/primitive3d/hittestprimitive3d.hxx>
47 #include <drawinglayer/attribute/sdrattribute.hxx>
49 //////////////////////////////////////////////////////////////////////////////
51 using namespace com::sun::star
;
53 //////////////////////////////////////////////////////////////////////////////
55 namespace drawinglayer
59 Primitive3DSequence
SdrCubePrimitive3D::createLocalDecomposition(const geometry::ViewInformation3D
& /*rViewInformation*/) const
61 const basegfx::B3DRange
aUnitRange(0.0, 0.0, 0.0, 1.0, 1.0, 1.0);
62 Primitive3DSequence aRetval
;
63 basegfx::B3DPolyPolygon
aFill(basegfx::tools::createCubeFillPolyPolygonFromB3DRange(aUnitRange
));
66 if(getSdrLFSAttribute().getFill())
68 if(::com::sun::star::drawing::NormalsKind_SPECIFIC
== getSdr3DObjectAttribute().getNormalsKind()
69 || ::com::sun::star::drawing::NormalsKind_SPHERE
== getSdr3DObjectAttribute().getNormalsKind())
71 // create sphere normals
72 const basegfx::B3DPoint
aCenter(basegfx::tools::getRange(aFill
).getCenter());
73 aFill
= basegfx::tools::applyDefaultNormalsSphere(aFill
, aCenter
);
76 if(getSdr3DObjectAttribute().getNormalsInvert())
79 aFill
= basegfx::tools::invertNormals(aFill
);
83 // texture coordinates
84 if(getSdrLFSAttribute().getFill())
86 // handle texture coordinates X
87 const bool bParallelX(::com::sun::star::drawing::TextureProjectionMode_PARALLEL
== getSdr3DObjectAttribute().getTextureProjectionX());
88 const bool bObjectSpecificX(::com::sun::star::drawing::TextureProjectionMode_OBJECTSPECIFIC
== getSdr3DObjectAttribute().getTextureProjectionX());
89 const bool bSphereX(!bParallelX
&& (::com::sun::star::drawing::TextureProjectionMode_SPHERE
== getSdr3DObjectAttribute().getTextureProjectionX()));
91 // handle texture coordinates Y
92 const bool bParallelY(::com::sun::star::drawing::TextureProjectionMode_PARALLEL
== getSdr3DObjectAttribute().getTextureProjectionY());
93 const bool bObjectSpecificY(::com::sun::star::drawing::TextureProjectionMode_OBJECTSPECIFIC
== getSdr3DObjectAttribute().getTextureProjectionY());
94 const bool bSphereY(!bParallelY
&& (::com::sun::star::drawing::TextureProjectionMode_SPHERE
== getSdr3DObjectAttribute().getTextureProjectionY()));
96 if(bParallelX
|| bParallelY
)
98 // apply parallel texture coordinates in X and/or Y
99 const basegfx::B3DRange
aRange(basegfx::tools::getRange(aFill
));
100 aFill
= basegfx::tools::applyDefaultTextureCoordinatesParallel(aFill
, aRange
, bParallelX
, bParallelY
);
103 if(bSphereX
|| bSphereY
)
105 // apply spherical texture coordinates in X and/or Y
106 const basegfx::B3DRange
aRange(basegfx::tools::getRange(aFill
));
107 const basegfx::B3DPoint
aCenter(aRange
.getCenter());
108 aFill
= basegfx::tools::applyDefaultTextureCoordinatesSphere(aFill
, aCenter
, bSphereX
, bSphereY
);
111 if(bObjectSpecificX
|| bObjectSpecificY
)
114 for(sal_uInt32
a(0L); a
< aFill
.count(); a
++)
116 basegfx::B3DPolygon
aTmpPoly(aFill
.getB3DPolygon(a
));
118 if(aTmpPoly
.count() >= 4L)
120 for(sal_uInt32
b(0L); b
< 4L; b
++)
122 basegfx::B2DPoint
aPoint(aTmpPoly
.getTextureCoordinate(b
));
126 aPoint
.setX((1L == b
|| 2L == b
) ? 1.0 : 0.0);
131 aPoint
.setY((2L == b
|| 3L == b
) ? 1.0 : 0.0);
134 aTmpPoly
.setTextureCoordinate(b
, aPoint
);
137 aFill
.setB3DPolygon(a
, aTmpPoly
);
142 // transform texture coordinates to texture size
143 basegfx::B2DHomMatrix aTexMatrix
;
144 aTexMatrix
.scale(getTextureSize().getX(), getTextureSize().getY());
145 aFill
.transformTextureCoordiantes(aTexMatrix
);
148 // build vector of PolyPolygons
149 ::std::vector
< basegfx::B3DPolyPolygon
> a3DPolyPolygonVector
;
151 for(sal_uInt32
a(0L); a
< aFill
.count(); a
++)
153 a3DPolyPolygonVector
.push_back(basegfx::B3DPolyPolygon(aFill
.getB3DPolygon(a
)));
156 if(getSdrLFSAttribute().getFill())
159 aRetval
= create3DPolyPolygonFillPrimitives(
160 a3DPolyPolygonVector
,
163 getSdr3DObjectAttribute(),
164 *getSdrLFSAttribute().getFill(),
165 getSdrLFSAttribute().getFillFloatTransGradient());
169 // create simplified 3d hit test geometry
170 const attribute::SdrFillAttribute
aSimplifiedFillAttribute(0.0, basegfx::BColor(), 0, 0, 0);
172 aRetval
= create3DPolyPolygonFillPrimitives(
173 a3DPolyPolygonVector
,
176 getSdr3DObjectAttribute(),
177 aSimplifiedFillAttribute
,
180 // encapsulate in HitTestPrimitive3D and add
181 const Primitive3DReference
xRef(new HitTestPrimitive3D(aRetval
));
182 aRetval
= Primitive3DSequence(&xRef
, 1L);
186 if(getSdrLFSAttribute().getLine())
188 basegfx::B3DPolyPolygon
aLine(basegfx::tools::createCubePolyPolygonFromB3DRange(aUnitRange
));
189 const Primitive3DSequence
aLines(create3DPolyPolygonLinePrimitives(aLine
, getTransform(), *getSdrLFSAttribute().getLine()));
190 appendPrimitive3DSequenceToPrimitive3DSequence(aRetval
, aLines
);
194 if(getSdrLFSAttribute().getShadow() && aRetval
.hasElements())
196 const Primitive3DSequence
aShadow(createShadowPrimitive3D(aRetval
, *getSdrLFSAttribute().getShadow(), getSdr3DObjectAttribute().getShadow3D()));
197 appendPrimitive3DSequenceToPrimitive3DSequence(aRetval
, aShadow
);
203 SdrCubePrimitive3D::SdrCubePrimitive3D(
204 const basegfx::B3DHomMatrix
& rTransform
,
205 const basegfx::B2DVector
& rTextureSize
,
206 const attribute::SdrLineFillShadowAttribute
& rSdrLFSAttribute
,
207 const attribute::Sdr3DObjectAttribute
& rSdr3DObjectAttribute
)
208 : SdrPrimitive3D(rTransform
, rTextureSize
, rSdrLFSAttribute
, rSdr3DObjectAttribute
)
212 bool SdrCubePrimitive3D::operator==(const BasePrimitive3D
& rPrimitive
) const
214 return SdrPrimitive3D::operator==(rPrimitive
);
217 basegfx::B3DRange
SdrCubePrimitive3D::getB3DRange(const geometry::ViewInformation3D
& /*rViewInformation*/) const
219 // use defaut from sdrPrimitive3D which uses transformation expanded by line width/2.
220 // The parent implementation which uses the ranges of the decomposition would be more
221 // corrcet, but for historical reasons it is necessary to do the old method: To get
222 // the range of the non-transformed geometry and transform it then. This leads to different
223 // ranges where the new method is more correct, but the need to keep the old behaviour
224 // has priority here.
225 return getStandard3DRange();
229 ImplPrimitrive3DIDBlock(SdrCubePrimitive3D
, PRIMITIVE3D_ID_SDRCUBEPRIMITIVE3D
)
231 } // end of namespace primitive3d
232 } // end of namespace drawinglayer
234 //////////////////////////////////////////////////////////////////////////////