Developer documentation | Axl-2.5.1

axlLight.cpp
Go to the documentation of this file.
1 /* axlLight.cpp ---
2  *
3  * Author: Meriadeg Perrinel
4  * Copyright (C) 2008 - Meriadeg Perrinel, Inria.
5  * Created: Tue Nov 9 16:58:59 2010 (+0100)
6  * Version: $Id$
7  * Last-Updated: Tue Nov 9 17:09:38 2010 (+0100)
8  * By: Meriadeg Perrinel
9  * Update #: 19
10  */
11 
12 /* Commentary:
13  *
14  */
15 
16 /* Change log:
17  *
18  */
19 
20 #include "axlLight.h"
21 
22 #include "axlPoint.h"
23 
24 #include <dtkCoreSupport/dtkGlobal.h>
25 
26 #include <QtGui>
27 
28 // /////////////////////////////////////////////////////////////////
29 // axlLightPrivate
30 // /////////////////////////////////////////////////////////////////
31 
32 class axlLightPrivate
33 {
34 public:
35  double position[3];
36  double ambiant[3];
37  double diffuse[3];
38  double specular[3];
39  double exponent;
40 
41 
42 public:
43  QColor color;
44  double opacity;
45  QString shader;
46 };
47 
48 // /////////////////////////////////////////////////////////////////
49 // axlLight implementation
50 // /////////////////////////////////////////////////////////////////
51 
53 
58 axlLight::axlLight(QObject *parent) : dtkAbstractData(), d(new axlLightPrivate)
59 {
60  this->setObjectName(this->description());
61  d->position[0] = 0.0;
62  d->position[1] = 0.0;
63  d->position[2] = 0.0;
64 
65  d->ambiant[0] = 1.0;
66  d->ambiant[1] = 1.0;
67  d->ambiant[2] = 1.0;
68 
69  d->diffuse[0] = 1.0;
70  d->diffuse[1] = 1.0;
71  d->diffuse[2] = 1.0;
72 
73  d->specular[0] = 1.0;
74  d->specular[1] = 1.0;
75  d->specular[2] = 1.0;
76 
77  d->exponent = 50;
78 
79 }
80 
82 
87 axlLight::axlLight(double x, double y, double z, QObject *parent) : dtkAbstractData(), d(new axlLightPrivate)
88 {
89  this->setObjectName(this->description());
90  d->position[0] = x;
91  d->position[1] = y;
92  d->position[2] = z;
93 
94  d->ambiant[0] = 1.0;
95  d->ambiant[1] = 1.0;
96  d->ambiant[2] = 1.0;
97 
98  d->diffuse[0] = 1.0;
99  d->diffuse[1] = 1.0;
100  d->diffuse[2] = 1.0;
101 
102  d->specular[0] = 1.0;
103  d->specular[1] = 1.0;
104  d->specular[2] = 1.0;
105 
106  d->exponent = 50;
107 }
108 
109 axlLight::axlLight(double *position, double *ambiant, double *diffuse, double *specular, double exponent, QObject *parent)
110 {
111  this->setObjectName(this->description());
112 
113  for(int i = 0; i < 3; i++)
114  {
115  d->position[i] = position[i];
116  d->ambiant[i] = ambiant[i];
117  d->diffuse[i] = diffuse[i];
118  d->specular[i] = specular[i];
119  }
120 
121  d->exponent = exponent;
122 }
123 
125 
128 axlLight::axlLight(const axlLight& other) : dtkAbstractData(), d(new axlLightPrivate)
129 {
130  this->setObjectName(this->description());
131  this->setParent(other.parent());
132  d->position[0] = other.d->position[0];
133  d->position[1] = other.d->position[1];
134  d->position[2] = other.d->position[2];
135 
136  d->ambiant[0] = other.d->ambiant[0];
137  d->ambiant[1] = other.d->ambiant[1];
138  d->ambiant[2] = other.d->ambiant[2];
139 
140  d->diffuse[0] = other.d->diffuse[0];
141  d->diffuse[1] = other.d->diffuse[1];
142  d->diffuse[2] = other.d->diffuse[2];
143 
144  d->specular[0] = other.d->specular[0];
145  d->specular[1] = other.d->specular[1];
146  d->specular[2] = other.d->specular[2];
147 
148  d->exponent = other.d->exponent;
149 }
150 
152 
156 {
157  delete d;
158 
159  d = NULL;
160 }
161 
162 
163 
165 
168 double axlLight::x(void) const
169 {
170  return d->position[0];
171 }
172 
174 
177 double axlLight::y(void) const
178 {
179  return d->position[1];
180 }
181 
183 
186 double axlLight::z(void) const
187 {
188  return d->position[2];
189 }
190 
192 
195 double *axlLight::position(void) const
196 {
197  return d->position ;
198 }
199 
200 double *axlLight::ambiant(void) const
201 {
202  return d->ambiant ;
203 }
204 
205 double *axlLight::diffuse(void) const
206 {
207  return d->diffuse ;
208 }
209 
210 double *axlLight::specular(void) const
211 {
212  return d->specular ;
213 }
214 
215 double axlLight::exponent(void) const
216 {
217  return d->exponent ;
218 }
219 
221 {
222  for (int i =0; i < 3 ; i ++)
223  d->position[i] = position->coordinates()[i];
224 }
225 
227 {
228  for (int i =0; i < 3 ; i ++)
229  d->ambiant[i] = ambiant->coordinates()[i];
230 }
231 
233 {
234  for (int i =0; i < 3 ; i ++)
235  d->diffuse[i] = diffuse->coordinates()[i];
236 }
237 
239 {
240  for (int i =0; i < 3 ; i ++)
241  d->specular[i] = specular->coordinates()[i];
242 }
243 
244 void axlLight::setExponent(double position)
245 {
246  d->exponent = position;
247 }
248 
249 //SLOTS
250 
252 {
253  this->setPosition(position);
254 }
255 
256 
257 //Property Method
258 
259 const QColor& axlLight::color(void) const
260 {
261  return d->color;
262 }
263 
264 void axlLight::setColor(const QColor& color)
265 {
266  d->color = color;
267 }
268 
269 const double& axlLight::opacity(void) const
270 {
271  return d->opacity;
272 }
273 
274 void axlLight::setOpacity(const double& opacity)
275 {
276  d->opacity = opacity;
277 }
278 
279 const QString& axlLight::shader(void) const
280 {
281  return d->shader;
282 }
283 
284 
285 void axlLight::setShader(const QString& shader)
286 {
287  d->shader = shader;
288 }
289 
290 
291 // /////////////////////////////////////////////////////////////////
292 // Debug operators
293 // /////////////////////////////////////////////////////////////////
294 
295 QDebug operator<<(QDebug dbg, axlLight light)
296 {
297 
298  QString position(QString("position: (%1, %2, %3)\n").arg(light.position()[0]).arg(light.position()[1]).arg(light.position()[2]));
299  QString ambiant(QString("ambiant: (%1, %2, %3)\n").arg(light.ambiant()[0]).arg(light.ambiant()[1]).arg(light.ambiant()[2]));
300  QString diffuse(QString("diffuse: (%1, %2, %3)\n").arg(light.diffuse()[0]).arg(light.diffuse()[1]).arg(light.diffuse()[2]));
301  QString specular(QString("specular: (%1, %2, %3)\n").arg(light.specular()[0]).arg(light.specular()[1]).arg(light.specular()[2]));
302  QString exponent(QString("exponent: (%1)").arg(light.exponent()));
303 
304  dbg.nospace() << QString("axlLight:\n") << position << ambiant << diffuse << specular<<exponent;
305 
306  return dbg.space();
307 }
308 
309 QDebug operator<<(QDebug dbg, axlLight& light)
310 {
311  QString position(QString("position: (%1, %2, %3)\n").arg(light.position()[0]).arg(light.position()[1]).arg(light.position()[2]));
312  QString ambiant(QString("ambiant: (%1, %2, %3)\n").arg(light.ambiant()[0]).arg(light.ambiant()[1]).arg(light.ambiant()[2]));
313  QString diffuse(QString("diffuse: (%1, %2, %3)\n").arg(light.diffuse()[0]).arg(light.diffuse()[1]).arg(light.diffuse()[2]));
314  QString specular(QString("specular: (%1, %2, %3)\n").arg(light.specular()[0]).arg(light.specular()[1]).arg(light.specular()[2]));
315  QString exponent(QString("exponent: (%1)").arg(light.exponent()));
316 
317  dbg.nospace() << QString("axlLight:\n") << position << ambiant << diffuse << specular<<exponent;
318 
319  return dbg.space();
320 }
321 
322 QDebug operator<<(QDebug dbg, axlLight *light)
323 {
324  QString position(QString("position: (%1, %2, %3)\n").arg(light->position()[0]).arg(light->position()[1]).arg(light->position()[2]));
325  QString ambiant(QString("ambiant: (%1, %2, %3)\n").arg(light->ambiant()[0]).arg(light->ambiant()[1]).arg(light->ambiant()[2]));
326  QString diffuse(QString("diffuse: (%1, %2, %3)\n").arg(light->diffuse()[0]).arg(light->diffuse()[1]).arg(light->diffuse()[2]));
327  QString specular(QString("specular: (%1, %2, %3)\n").arg(light->specular()[0]).arg(light->specular()[1]).arg(light->specular()[2]));
328  QString exponent(QString("exponent: (%1)").arg(light->exponent()));
329 
330  dbg.nospace() << QString("axlLight:\n") << position << ambiant << diffuse << specular<<exponent;
331  return dbg.space();
332 }
333 
334 QString axlLight::description(void) const
335 {
336  return "axlLight";
337 }
338 
339 // /////////////////////////////////////////////////////////////////
340 // axlLight documentation
341 // /////////////////////////////////////////////////////////////////
342 
Class axlPoint defines 3D points.
Definition: axlPoint.h:34
void setOpacity(const double &opacity)
Definition: axlLight.cpp:274
axlLight(QObject *parent=0)
Constructs a axel light of zero position with parent parent of QObject type.
Definition: axlLight.cpp:58
double x(void) const
Returns x-coordinate of this light.
Definition: axlLight.cpp:168
double * coordinates(void) const
Returns coordinates of this point.
Definition: axlPoint.cpp:445
void onPositionChanged(axlPoint *position)
Definition: axlLight.cpp:251
void setDiffuse(axlPoint *diffuse)
Definition: axlLight.cpp:232
double y(void) const
Returns y-coordinate of this light.
Definition: axlLight.cpp:177
void setShader(const QString &shader)
Definition: axlLight.cpp:285
virtual QString description(void) const
Definition: axlLight.cpp:334
~axlLight(void)
Destroys the axel light.
Definition: axlLight.cpp:155
double z(void) const
Returns z-coordinate of this light.
Definition: axlLight.cpp:186
void setPosition(axlPoint *position)
Definition: axlLight.cpp:220
double * position(void) const
Returns position of this light.
Definition: axlLight.cpp:195
double * diffuse(void) const
Definition: axlLight.cpp:205
void setExponent(double position)
Definition: axlLight.cpp:244
const QColor & color(void) const
Definition: axlLight.cpp:259
void setColor(const QColor &color)
Definition: axlLight.cpp:264
const QString & shader(void) const
Definition: axlLight.cpp:279
Class axlLight defines 3D lights.
Definition: axlLight.h:33
double exponent(void) const
Definition: axlLight.cpp:215
QDebug operator<<(QDebug dbg, axlLight light)
Definition: axlLight.cpp:295
void setAmbiant(axlPoint *ambiant)
Definition: axlLight.cpp:226
double * ambiant(void) const
Definition: axlLight.cpp:200
double * specular(void) const
Definition: axlLight.cpp:210
const double & opacity(void) const
Definition: axlLight.cpp:269
void setSpecular(axlPoint *specular)
Definition: axlLight.cpp:238