1 /**************************************************************************\
2 * Copyright (c) Kongsberg Oil & Gas Technologies AS
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 * Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 *
12 * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * Neither the name of the copyright holder nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 \**************************************************************************/
32
33 /*!
34 \class SoEnvironmentElement Inventor/elements/SoEnvironmentElement.h
35 \brief The SoEnvironmentElement class is yet to be documented.
36
37 \ingroup elements
38
39 FIXME: write doc.
40 */
41
42 #include <Inventor/elements/SoEnvironmentElement.h>
43
44
45 #include <cassert>
46
47 #include "SbBasicP.h"
48
49 /*!
50 \fn SoEnvironmentElement::FogType
51
52 FIXME: write doc.
53 */
54
55 /*!
56 \fn SoEnvironmentElement::ambientIntensity
57
58 FIXME: write doc.
59 */
60
61 /*!
62 \fn SoEnvironmentElement::ambientColor
63
64 FIXME: write doc.
65 */
66
67 /*!
68 \fn SoEnvironmentElement::attenuation
69
70 FIXME: write doc.
71 */
72
73 /*!
74 \fn SoEnvironmentElement::fogType
75
76 FIXME: write doc.
77 */
78
79 /*!
80 \fn SoEnvironmentElement::fogColor
81
82 FIXME: write doc.
83 */
84
85 /*!
86 \fn SoEnvironmentElement::fogVisibility
87
88 FIXME: write doc.
89 */
90
91 /*!
92 \fn SoEnvironmentElement::fogStart
93
94 FIXME: write doc.
95 */
96
97 SO_ELEMENT_SOURCE(SoEnvironmentElement);
98
99 /*!
100 This static method initializes static data for the
101 SoEnvironmentElement class.
102 */
103
104 void
initClass(void)105 SoEnvironmentElement::initClass(void)
106 {
107 SO_ELEMENT_INIT_CLASS(SoEnvironmentElement, inherited);
108 }
109
110 /*!
111 The destructor.
112 */
113
~SoEnvironmentElement(void)114 SoEnvironmentElement::~SoEnvironmentElement(void)
115 {
116 }
117
118 //! FIXME: write doc.
119
120 void
set(SoState * const state,SoNode * const node,const float ambientIntensity,const SbColor & ambientColor,const SbVec3f & attenuation,const int32_t fogType,const SbColor & fogColor,const float fogVisibility,const float fogStart)121 SoEnvironmentElement::set(SoState * const state,
122 SoNode * const node,
123 const float ambientIntensity,
124 const SbColor & ambientColor,
125 const SbVec3f & attenuation,
126 const int32_t fogType,
127 const SbColor & fogColor,
128 const float fogVisibility,
129 const float fogStart)
130 {
131 SoEnvironmentElement * element =
132 coin_safe_cast<SoEnvironmentElement *>
133 (
134 SoReplacedElement::getElement(state, classStackIndex, node)
135 );
136 if (element) {
137 element->setElt(state, ambientIntensity, ambientColor, attenuation,
138 fogType, fogColor, fogVisibility, fogStart);
139 }
140 }
141
142 //! FIXME: write doc.
143
144 void
get(SoState * const state,float & ambientIntensity,SbColor & ambientColor,SbVec3f & attenuation,int32_t & fogType,SbColor & fogColor,float & fogVisibility,float & fogStart)145 SoEnvironmentElement::get(SoState * const state,
146 float & ambientIntensity,
147 SbColor & ambientColor,
148 SbVec3f & attenuation,
149 int32_t & fogType,
150 SbColor & fogColor,
151 float & fogVisibility,
152 float & fogStart)
153 {
154 const SoEnvironmentElement * element = coin_assert_cast<const SoEnvironmentElement *>
155 (
156 SoElement::getConstElement(state, classStackIndex)
157 );
158
159 ambientIntensity = element->ambientIntensity;
160 ambientColor = element->ambientColor;
161 attenuation = element->attenuation;
162 fogType = element->fogType;
163 fogColor = element->fogColor;
164 fogVisibility = element->fogVisibility;
165 fogStart = element->fogStart;
166 }
167
168 //! FIXME: write doc.
169
170 void
getDefault(float & ambientIntensity,SbColor & ambientColor,SbVec3f & attenuation,int32_t & fogType,SbColor & fogColor,float & fogVisibility,float & fogStart)171 SoEnvironmentElement::getDefault(float & ambientIntensity,
172 SbColor & ambientColor,
173 SbVec3f & attenuation,
174 int32_t & fogType,
175 SbColor & fogColor,
176 float & fogVisibility,
177 float & fogStart)
178 {
179 ambientIntensity = 0.2f;
180 ambientColor = SbColor(1.0f, 1.0f, 1.0f);
181 attenuation = SbVec3f(0.0f, 0.0f, 1.0f);
182 fogType = NONE;
183 fogColor = SbColor(1.0f, 1.0f, 1.0f);
184 fogVisibility = 0.0f;
185 fogStart = 0.0f;
186 }
187
188 //! FIXME: write doc.
189
190 float
getAmbientIntensity(SoState * const state)191 SoEnvironmentElement::getAmbientIntensity(SoState * const state)
192 {
193 const SoEnvironmentElement * element = coin_assert_cast<const SoEnvironmentElement *>
194 (
195 SoElement::getConstElement(state, classStackIndex)
196 );
197 return element->ambientIntensity;
198 }
199
200 //! FIXME: write doc.
201
202 float
getFogVisibility(SoState * const state)203 SoEnvironmentElement::getFogVisibility(SoState * const state)
204 {
205 const SoEnvironmentElement * element = coin_assert_cast<const SoEnvironmentElement *>
206 (
207 SoElement::getConstElement(state, classStackIndex)
208 );
209 return element->fogVisibility;
210 }
211
212 //! FIXME: write doc.
213
214 const SbVec3f &
getLightAttenuation(SoState * const state)215 SoEnvironmentElement::getLightAttenuation(SoState * const state)
216 {
217 const SoEnvironmentElement * element = coin_assert_cast<const SoEnvironmentElement *>
218 (
219 SoElement::getConstElement(state, classStackIndex)
220 );
221 return element->attenuation;
222 }
223
224 //! FIXME: write doc.
225
226 const SbColor &
getAmbientColor(SoState * const state)227 SoEnvironmentElement::getAmbientColor(SoState * const state)
228 {
229 const SoEnvironmentElement * element = coin_assert_cast<const SoEnvironmentElement *>
230 (
231 SoElement::getConstElement(state, classStackIndex)
232 );
233 return element->ambientColor;
234 }
235
236 //! FIXME: write doc.
237
238 const SbColor &
getFogColor(SoState * const state)239 SoEnvironmentElement::getFogColor(SoState * const state)
240 {
241 const SoEnvironmentElement * element = coin_assert_cast<const SoEnvironmentElement *>
242 (
243 SoElement::getConstElement(state, classStackIndex)
244 );
245 return element->fogColor;
246 }
247
248 //! FIXME: write doc.
249
250 int32_t
getFogType(SoState * const state)251 SoEnvironmentElement::getFogType(SoState * const state)
252 {
253 const SoEnvironmentElement * element = coin_assert_cast<const SoEnvironmentElement *>
254 (
255 SoElement::getConstElement(state, classStackIndex)
256 );
257 return element->fogType;
258 }
259
260 //! FIXME: write doc.
261
262 void
print(FILE * file) const263 SoEnvironmentElement::print(FILE * file) const
264 {
265 fprintf(file, "SoEnvironmentElement[%p]\n", this);
266 }
267
268 //! FIXME: write doc.
269
270 void
init(SoState * state)271 SoEnvironmentElement::init(SoState * state)
272 {
273 inherited::init(state);
274 this->getDefault(this->ambientIntensity, this->ambientColor, this->attenuation,
275 fogType, fogColor, fogVisibility, fogStart);
276 }
277
278 //! FIXME: doc
279 void
setElt(SoState * const,const float ambientIntensityarg,const SbColor & ambientColorarg,const SbVec3f & attenuationarg,const int32_t fogTypearg,const SbColor & fogColorarg,const float fogVisibilityarg,const float fogStartarg)280 SoEnvironmentElement::setElt(SoState * const,
281 const float ambientIntensityarg,
282 const SbColor & ambientColorarg,
283 const SbVec3f & attenuationarg,
284 const int32_t fogTypearg,
285 const SbColor & fogColorarg,
286 const float fogVisibilityarg,
287 const float fogStartarg)
288 {
289 this->ambientIntensity = ambientIntensityarg;
290 this->ambientColor = ambientColorarg;
291 this->attenuation = attenuationarg;
292 this->fogType = fogTypearg;
293 this->fogColor = fogColorarg;
294 this->fogVisibility = fogVisibilityarg;
295 this->fogStart = fogStartarg;
296 }
297