LibreOffice Module drawinglayer (master) 1
sdrlightingattribute3d.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
24
25
27{
29 {
30 public:
31 // 3D light attribute definitions
33 std::vector< Sdr3DLightAttribute > maLightVector;
34
36 const basegfx::BColor& rAmbientLight,
37 std::vector< Sdr3DLightAttribute >&& rLightVector)
38 : maAmbientLight(rAmbientLight),
39 maLightVector(std::move(rLightVector))
40 {
41 }
42
44 {
45 }
46
47 // data read access
49 const std::vector< Sdr3DLightAttribute >& getLightVector() const { return maLightVector; }
50
51 bool operator==(const ImpSdrLightingAttribute& rCandidate) const
52 {
53 return (getAmbientLight() == rCandidate.getAmbientLight()
54 && getLightVector() == rCandidate.getLightVector());
55 }
56 };
57
58 namespace
59 {
60 SdrLightingAttribute::ImplType& theGlobalDefault()
61 {
62 static SdrLightingAttribute::ImplType SINGLETON;
63 return SINGLETON;
64 }
65 }
66
68 const basegfx::BColor& rAmbientLight,
69 std::vector< Sdr3DLightAttribute >&& rLightVector)
70 : mpSdrLightingAttribute(ImpSdrLightingAttribute(
71 rAmbientLight, std::move(rLightVector)))
72 {
73 }
74
76 : mpSdrLightingAttribute(theGlobalDefault())
77 {
78 }
79
81
83
85
86
88 {
89 return mpSdrLightingAttribute.same_object(theGlobalDefault());
90 }
91
93
95
97 {
98 // tdf#87509 default attr is always != non-default attr, even with same values
99 if(rCandidate.isDefault() != isDefault())
100 return false;
101
103 }
104
105 const std::vector< Sdr3DLightAttribute >& SdrLightingAttribute::getLightVector() const
106 {
107 return mpSdrLightingAttribute->getLightVector();
108 }
109
111 {
112 return mpSdrLightingAttribute->maAmbientLight;
113 }
114
115 // color model solver
117 const basegfx::B3DVector& rNormalInEyeCoordinates,
118 const basegfx::BColor& rColor, const basegfx::BColor& rSpecular,
119 const basegfx::BColor& rEmission, sal_uInt16 nSpecularIntensity) const
120 {
121 // initialize with emissive color
122 basegfx::BColor aRetval(rEmission);
123
124 // take care of global ambient light
125 aRetval += mpSdrLightingAttribute->getAmbientLight() * rColor;
126
127 const std::vector<Sdr3DLightAttribute>& rLightVector = mpSdrLightingAttribute->getLightVector();
128
129 // prepare light access. Is there a light?
130 const sal_uInt32 nLightCount(rLightVector.size());
131
132 if(nLightCount && !rNormalInEyeCoordinates.equalZero())
133 {
134 // prepare normal
135 basegfx::B3DVector aEyeNormal(rNormalInEyeCoordinates);
136 aEyeNormal.normalize();
137
138 for(sal_uInt32 a(0); a < nLightCount; a++)
139 {
140 const Sdr3DLightAttribute& rLight(rLightVector[a]);
141 const double fCosFac(rLight.getDirection().scalar(aEyeNormal));
142
143 if(basegfx::fTools::more(fCosFac, 0.0))
144 {
145 aRetval += (rLight.getColor() * rColor) * fCosFac;
146
147 if(rLight.getSpecular())
148 {
149 // expand by (0.0, 0.0, 1.0) in Z
150 basegfx::B3DVector aSpecularNormal(rLight.getDirection().getX(), rLight.getDirection().getY(), rLight.getDirection().getZ() + 1.0);
151 aSpecularNormal.normalize();
152 double fCosFac2(aSpecularNormal.scalar(aEyeNormal));
153
154 if(basegfx::fTools::more(fCosFac2, 0.0))
155 {
156 fCosFac2 = pow(fCosFac2, static_cast<double>(nSpecularIntensity));
157 aRetval += rSpecular * fCosFac2;
158 }
159 }
160 }
161 }
162 }
163
164 // clamp to color space before usage
165 aRetval.clamp();
166
167 return aRetval;
168 }
169
170} // end of namespace
171
172/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool equalZero() const
B3DVector & normalize()
double scalar(const B3DVector &rVec) const
BColor & clamp()
TYPE getX() const
TYPE getZ() const
TYPE getY() const
const std::vector< Sdr3DLightAttribute > & getLightVector() const
bool operator==(const ImpSdrLightingAttribute &rCandidate) const
ImpSdrLightingAttribute(const basegfx::BColor &rAmbientLight, std::vector< Sdr3DLightAttribute > &&rLightVector)
const basegfx::B3DVector & getDirection() const
basegfx::BColor solveColorModel(const basegfx::B3DVector &rNormalInEyeCoordinates, const basegfx::BColor &rColor, const basegfx::BColor &rSpecular, const basegfx::BColor &rEmission, sal_uInt16 nSpecularIntensity) const
SdrLightingAttribute & operator=(const SdrLightingAttribute &rCandidate)
o3tl::cow_wrapper< ImpSdrLightingAttribute > ImplType
const ::std::vector< Sdr3DLightAttribute > & getLightVector() const
bool operator==(const SdrLightingAttribute &rCandidate) const
bool same_object(const cow_wrapper &rOther) const
uno_Any a
bool more(const T &rfValA, const T &rfValB)