1 /*************************************************************************
3 * OpenOffice.org - a multi-platform office productivity suite
5 * $RCSfile: sdrattribute3d.cxx,v $
9 * last change: $Author: aw $ $Date: 2008-05-27 14:11:19 $
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/attribute/sdrattribute3d.hxx>
41 //////////////////////////////////////////////////////////////////////////////
43 namespace drawinglayer
47 Sdr3DObjectAttribute::Sdr3DObjectAttribute(
48 ::com::sun::star::drawing::NormalsKind aNormalsKind
,
49 ::com::sun::star::drawing::TextureProjectionMode aTextureProjectionX
,
50 ::com::sun::star::drawing::TextureProjectionMode aTextureProjectionY
,
51 ::com::sun::star::drawing::TextureKind2 aTextureKind
,
52 ::com::sun::star::drawing::TextureMode aTextureMode
,
53 const MaterialAttribute3D
& rMaterial
,
58 bool bReducedLineGeometry
)
59 : maNormalsKind(aNormalsKind
),
60 maTextureProjectionX(aTextureProjectionX
),
61 maTextureProjectionY(aTextureProjectionY
),
62 maTextureKind(aTextureKind
),
63 maTextureMode(aTextureMode
),
64 maMaterial(rMaterial
),
65 mbNormalsInvert(bNormalsInvert
),
66 mbDoubleSided(bDoubleSided
),
67 mbShadow3D(bShadow3D
),
68 mbTextureFilter(bTextureFilter
),
69 mbReducedLineGeometry(bReducedLineGeometry
)
73 bool Sdr3DObjectAttribute::operator==(const Sdr3DObjectAttribute
& rCandidate
) const
75 return (maNormalsKind
== rCandidate
.maNormalsKind
76 && maTextureProjectionX
== rCandidate
.maTextureProjectionX
77 && maTextureProjectionY
== rCandidate
.maTextureProjectionY
78 && maTextureKind
== rCandidate
.maTextureKind
79 && maTextureMode
== rCandidate
.maTextureMode
80 && maMaterial
== rCandidate
.maMaterial
81 && mbNormalsInvert
== rCandidate
.mbNormalsInvert
82 && mbDoubleSided
== rCandidate
.mbDoubleSided
83 && mbShadow3D
== rCandidate
.mbShadow3D
84 && mbTextureFilter
== rCandidate
.mbTextureFilter
85 && mbReducedLineGeometry
== rCandidate
.mbReducedLineGeometry
);
87 } // end of namespace attribute
88 } // end of namespace drawinglayer
90 //////////////////////////////////////////////////////////////////////////////
92 namespace drawinglayer
96 Sdr3DLightAttribute::Sdr3DLightAttribute(const basegfx::BColor
& rColor
, const basegfx::B3DVector
& rDirection
, bool bSpecular
)
98 maDirection(rDirection
),
103 bool Sdr3DLightAttribute::operator==(const Sdr3DLightAttribute
& rCandidate
) const
105 return (maColor
== rCandidate
.maColor
106 && maDirection
== rCandidate
.maDirection
107 && mbSpecular
== rCandidate
.mbSpecular
);
109 } // end of namespace attribute
110 } // end of namespace drawinglayer
112 //////////////////////////////////////////////////////////////////////////////
114 namespace drawinglayer
118 SdrLightingAttribute::SdrLightingAttribute(
119 const basegfx::BColor
& rAmbientLight
,
120 const ::std::vector
< Sdr3DLightAttribute
>& rLightVector
)
121 : maAmbientLight(rAmbientLight
),
122 maLightVector(rLightVector
)
126 bool SdrLightingAttribute::operator==(const SdrLightingAttribute
& rCandidate
) const
128 return (maAmbientLight
== rCandidate
.maAmbientLight
129 && maLightVector
== rCandidate
.maLightVector
);
132 // color model solver
133 basegfx::BColor
SdrLightingAttribute::solveColorModel(
134 const basegfx::B3DVector
& rNormalInEyeCoordinates
,
135 const basegfx::BColor
& rColor
, const basegfx::BColor
& rSpecular
,
136 const basegfx::BColor
& rEmission
, sal_uInt16 nSpecularIntensity
) const
138 // initialize with emissive color
139 basegfx::BColor
aRetval(rEmission
);
141 // take care of global ambient light
142 aRetval
+= getAmbientLight() * rColor
;
144 // prepare light access. Is there a light?
145 const sal_uInt32
nLightCount(maLightVector
.size());
147 if(nLightCount
&& !rNormalInEyeCoordinates
.equalZero())
150 basegfx::B3DVector
aEyeNormal(rNormalInEyeCoordinates
);
151 aEyeNormal
.normalize();
153 for(sal_uInt32
a(0L); a
< nLightCount
; a
++)
155 const Sdr3DLightAttribute
& rLight(maLightVector
[a
]);
156 const double fCosFac(rLight
.getDirection().scalar(aEyeNormal
));
158 if(basegfx::fTools::more(fCosFac
, 0.0))
160 aRetval
+= ((rLight
.getColor() * rColor
) * fCosFac
);
162 if(rLight
.getSpecular())
164 // expand by (0.0, 0.0, 1.0) in Z
165 basegfx::B3DVector
aSpecularNormal(rLight
.getDirection().getX(), rLight
.getDirection().getY(), rLight
.getDirection().getZ() + 1.0);
166 aSpecularNormal
.normalize();
167 double fCosFac2(aSpecularNormal
.scalar(aEyeNormal
));
169 if(basegfx::fTools::more(fCosFac2
, 0.0))
171 fCosFac2
= pow(fCosFac2
, (double)nSpecularIntensity
);
172 aRetval
+= (rSpecular
* fCosFac2
);
179 // clamp to color space before usage
184 } // end of namespace attribute
185 } // end of namespace drawinglayer
187 //////////////////////////////////////////////////////////////////////////////
189 namespace drawinglayer
193 SdrSceneAttribute::SdrSceneAttribute(
196 ::com::sun::star::drawing::ProjectionMode aProjectionMode
,
197 ::com::sun::star::drawing::ShadeMode aShadeMode
,
198 bool bTwoSidedLighting
)
199 : mfDistance(fDistance
),
200 mfShadowSlant(fShadowSlant
),
201 maProjectionMode(aProjectionMode
),
202 maShadeMode(aShadeMode
),
203 mbTwoSidedLighting(bTwoSidedLighting
)
207 bool SdrSceneAttribute::operator==(const SdrSceneAttribute
& rCandidate
) const
209 return (mfDistance
== rCandidate
.mfDistance
210 && mfShadowSlant
== rCandidate
.mfShadowSlant
211 && maProjectionMode
== rCandidate
.maProjectionMode
212 && maShadeMode
== rCandidate
.maShadeMode
213 && mbTwoSidedLighting
== rCandidate
.mbTwoSidedLighting
);
215 } // end of namespace attribute
216 } // end of namespace drawinglayer
218 //////////////////////////////////////////////////////////////////////////////