|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt3D module of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:BSD$ |
|
10 ** You may use this file under the terms of the BSD license as follows: |
|
11 ** |
|
12 ** "Redistribution and use in source and binary forms, with or without |
|
13 ** modification, are permitted provided that the following conditions are |
|
14 ** met: |
|
15 ** * Redistributions of source code must retain the above copyright |
|
16 ** notice, this list of conditions and the following disclaimer. |
|
17 ** * Redistributions in binary form must reproduce the above copyright |
|
18 ** notice, this list of conditions and the following disclaimer in |
|
19 ** the documentation and/or other materials provided with the |
|
20 ** distribution. |
|
21 ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor |
|
22 ** the names of its contributors may be used to endorse or promote |
|
23 ** products derived from this software without specific prior written |
|
24 ** permission. |
|
25 ** |
|
26 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
27 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
28 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
29 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
30 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
31 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
32 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
33 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
34 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
35 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
36 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." |
|
37 ** $QT_END_LICENSE$ |
|
38 ** |
|
39 ****************************************************************************/ |
|
40 |
|
41 #include "lightmodel.h" |
|
42 |
|
43 /*! |
|
44 \class LightModel |
|
45 \brief The LightModel class defines the lighting model to use for the scene. |
|
46 \since 4.7 |
|
47 \ingroup qt3d |
|
48 \ingroup qt3d::painting |
|
49 */ |
|
50 |
|
51 /*! |
|
52 \enum LightModel::Model |
|
53 This enum defines the type of lighting model to use: one-sided or two-sided. |
|
54 |
|
55 \value OneSided One-sided lighting, with the front face material used for both front and back faces. |
|
56 \value TwoSided Two-sided lighting, with separate front and back face materials. |
|
57 */ |
|
58 |
|
59 /*! |
|
60 \enum LightModel::ColorControl |
|
61 This enum controls the number of colors to be generated by the lighting computation. |
|
62 |
|
63 \value SingleColor A single color is generated by the lighting computation. |
|
64 \value SeparateSpecularColor A separate specular color computation is |
|
65 performed and then summed into the pixel color after texture mapping. |
|
66 */ |
|
67 |
|
68 /*! |
|
69 \enum LightModel::ViewerPosition |
|
70 This enum defines the position of the viewer for the purposes of lighting calculations. |
|
71 |
|
72 \value ViewerAtInfinity The viewer is at infinity along the -z axis. |
|
73 \value LocalViewer The viewer is at the local origin in eye coordinates. |
|
74 */ |
|
75 |
|
76 class LightModelPrivate |
|
77 { |
|
78 public: |
|
79 LightModelPrivate() |
|
80 : model(LightModel::OneSided), |
|
81 colorControl(LightModel::SingleColor), |
|
82 viewerPosition(LightModel::ViewerAtInfinity) |
|
83 { |
|
84 ambientSceneColor.setRgbF(0.2, 0.2, 0.2, 1.0); |
|
85 } |
|
86 |
|
87 LightModel::Model model; |
|
88 LightModel::ColorControl colorControl; |
|
89 LightModel::ViewerPosition viewerPosition; |
|
90 QColor ambientSceneColor; |
|
91 }; |
|
92 |
|
93 /*! |
|
94 Constructs a light model object with default values and attach |
|
95 it to \a parent. |
|
96 */ |
|
97 LightModel::LightModel(QObject *parent) |
|
98 : QObject(parent), d_ptr(new LightModelPrivate) |
|
99 { |
|
100 } |
|
101 |
|
102 /*! |
|
103 Destroys this light model. |
|
104 */ |
|
105 LightModel::~LightModel() |
|
106 { |
|
107 } |
|
108 |
|
109 /*! |
|
110 \property LightModel::model |
|
111 \brief the lighting model to use, either OneSided or TwoSided. |
|
112 The default is OneSided. |
|
113 |
|
114 \sa modelChanged() |
|
115 */ |
|
116 LightModel::Model LightModel::model() const |
|
117 { |
|
118 Q_D(const LightModel); |
|
119 return d->model; |
|
120 } |
|
121 |
|
122 void LightModel::setModel(LightModel::Model value) |
|
123 { |
|
124 Q_D(LightModel); |
|
125 if (d->model != value) { |
|
126 d->model = value; |
|
127 emit modelChanged(); |
|
128 emit lightModelChanged(); |
|
129 } |
|
130 } |
|
131 |
|
132 /*! |
|
133 \property LightModel::colorControl |
|
134 \brief the color control mode, either SingleColor or |
|
135 SeparateSpecularColor. The default value is SingleColor. |
|
136 |
|
137 If SingleColor is specified, then a single color is calculated |
|
138 by the lighting computation for a vertex. If SeparateSpecularColor |
|
139 is specified, then a separate specular color computation is |
|
140 performed and then summed into the pixel color after texture mapping. |
|
141 |
|
142 \sa colorControlChanged() |
|
143 */ |
|
144 LightModel::ColorControl LightModel::colorControl() const |
|
145 { |
|
146 Q_D(const LightModel); |
|
147 return d->colorControl; |
|
148 } |
|
149 |
|
150 void LightModel::setColorControl(LightModel::ColorControl value) |
|
151 { |
|
152 Q_D(LightModel); |
|
153 if (d->colorControl != value) { |
|
154 d->colorControl = value; |
|
155 emit colorControlChanged(); |
|
156 emit lightModelChanged(); |
|
157 } |
|
158 } |
|
159 |
|
160 /*! |
|
161 \property LightModel::viewerPosition |
|
162 \brief the viewer position, either ViewerAtInfinity or LocalViewer. |
|
163 The default value is ViewerAtInfinity. |
|
164 |
|
165 \sa viewerPositionChanged() |
|
166 */ |
|
167 LightModel::ViewerPosition LightModel::viewerPosition() const |
|
168 { |
|
169 Q_D(const LightModel); |
|
170 return d->viewerPosition; |
|
171 } |
|
172 |
|
173 void LightModel::setViewerPosition(LightModel::ViewerPosition value) |
|
174 { |
|
175 Q_D(LightModel); |
|
176 if (d->viewerPosition != value) { |
|
177 d->viewerPosition = value; |
|
178 emit viewerPositionChanged(); |
|
179 emit lightModelChanged(); |
|
180 } |
|
181 } |
|
182 |
|
183 /*! |
|
184 \property LightModel::ambientSceneColor |
|
185 \brief the ambient color of the entire scene. The default value |
|
186 is (0.2, 0.2, 0.2, 1.0). |
|
187 |
|
188 \sa ambientSceneColorChanged() |
|
189 */ |
|
190 QColor LightModel::ambientSceneColor() const |
|
191 { |
|
192 Q_D(const LightModel); |
|
193 return d->ambientSceneColor; |
|
194 } |
|
195 |
|
196 void LightModel::setAmbientSceneColor(const QColor& value) |
|
197 { |
|
198 Q_D(LightModel); |
|
199 if (d->ambientSceneColor != value) { |
|
200 d->ambientSceneColor = value; |
|
201 emit ambientSceneColorChanged(); |
|
202 emit lightModelChanged(); |
|
203 } |
|
204 } |
|
205 |
|
206 /*! |
|
207 \fn void LightModel::modelChanged() |
|
208 |
|
209 This signal is emitted when model() changes. |
|
210 |
|
211 \sa model(), lightModelChanged() |
|
212 */ |
|
213 |
|
214 /*! |
|
215 \fn void LightModel::colorControlChanged() |
|
216 |
|
217 This signal is emitted when colorControl() changes. |
|
218 |
|
219 \sa colorControl(), lightModelChanged() |
|
220 */ |
|
221 |
|
222 /*! |
|
223 \fn void LightModel::viewerPositionChanged() |
|
224 |
|
225 This signal is emitted when viewerPosition() changes. |
|
226 |
|
227 \sa viewerPosition(), lightModelChanged() |
|
228 */ |
|
229 |
|
230 /*! |
|
231 \fn void LightModel::ambientSceneColorChanged() |
|
232 |
|
233 This signal is emitted when ambientSceneColor() changes. |
|
234 |
|
235 \sa ambientSceneColor(), lightModelChanged() |
|
236 */ |
|
237 |
|
238 /*! |
|
239 \fn void LightModel::lightModelChanged() |
|
240 |
|
241 This signal is emitted when one of model(), colorControl(), |
|
242 viewerPosition(), or ambientSceneColor() changes. |
|
243 */ |