LightNode.cc 21.9 KB
Newer Older
Jan Möbius's avatar
Jan Möbius committed
1
2
3
/*===========================================================================*\
 *                                                                           *
 *                              OpenFlipper                                  *
Jan Möbius's avatar
Jan Möbius committed
4
 *      Copyright (C) 2001-2010 by Computer Graphics Group, RWTH Aachen      *
Jan Möbius's avatar
Jan Möbius committed
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
 *                           www.openflipper.org                             *
 *                                                                           *
 *---------------------------------------------------------------------------*
 *  This file is part of OpenFlipper.                                        *
 *                                                                           *
 *  OpenFlipper is free software: you can redistribute it and/or modify      *
 *  it under the terms of the GNU Lesser General Public License as           *
 *  published by the Free Software Foundation, either version 3 of           *
 *  the License, or (at your option) any later version with the              *
 *  following exceptions:                                                    *
 *                                                                           *
 *  If other files instantiate templates or use macros                       *
 *  or inline functions from this file, or you compile this file and         *
 *  link it with other files to produce an executable, this file does        *
 *  not by itself cause the resulting executable to be covered by the        *
 *  GNU Lesser General Public License. This exception does not however       *
 *  invalidate any other reasons why the executable file might be            *
 *  covered by the GNU Lesser General Public License.                        *
 *                                                                           *
 *  OpenFlipper is distributed in the hope that it will be useful,           *
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
 *  GNU Lesser General Public License for more details.                      *
 *                                                                           *
 *  You should have received a copy of the GNU LesserGeneral Public          *
 *  License along with OpenFlipper. If not,                                  *
 *  see <http://www.gnu.org/licenses/>.                                      *
 *                                                                           *
\*===========================================================================*/

/*===========================================================================*\
 *                                                                           *
 *   $Revision: 8548 $                                                       *
 *   $Author: moebius $                                                      *
 *   $Date: 2010-02-12 14:40:13 +0100 (Fr, 12. Feb 2010) $                   *
 *                                                                           *
\*===========================================================================*/




//=============================================================================
//
//  CLASS LightNode - IMPLEMENTATION
//
//=============================================================================


//== INCLUDES =================================================================


#include "LightNode.hh"

Jan Möbius's avatar
Jan Möbius committed
58
#ifndef M_PI
Mike Kremer's avatar
Mike Kremer committed
59
#define M_PI 3.14159265358979323846
Jan Möbius's avatar
Jan Möbius committed
60
#endif
Jan Möbius's avatar
Jan Möbius committed
61
62
63
64
65
66
67
68

//== NAMESPACES ===============================================================

namespace ACG {
namespace SceneGraph {

//== IMPLEMENTATION ========================================================== 

69
70
static LightSourceHandle* lightSourceHandle = 0;

Jan Möbius's avatar
Jan Möbius committed
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//default Constructor
LightSource::LightSource()
{
  // set OpenGL defaults
  enabled_              = false;
  fixedPosition_        = false;

  ambientColor_         = Vec4f(0.1,0.1,0.1,1.0);
  diffuseColor_         = Vec4f(1.0,1.0,1.0,1.0);
  specularColor_        = Vec4f(1.0,1.0,1.0,1.0);
  
  position_             = Vec4f(0.0,0.0,1.0,0.0);
  realPosition_         = Vec4f(0.0,0.0,1.0,0.0);
  
85
  spotDirection_        = Vec3d(0.0,0.0,-1.0);
Mike Kremer's avatar
Mike Kremer committed
86
87
  realSpotDirection_    = Vec3d(0.0,0.0,-1.0);
  
Jan Möbius's avatar
Jan Möbius committed
88
  spotExponent_         = 0;
89
  spotCutoff_           = 180;
Jan Möbius's avatar
Jan Möbius committed
90
91
92
93

  constantAttenuation_  = 1;
  linearAttenuation_    = 0;
  quadraticAttenuation_ = 0;
94
  
95
96
  brightness_           = 1.0f;
  
97
  radius_               = 0.1f;
Jan Möbius's avatar
Jan Möbius committed
98
99
}

100
void LightSource::position( Vec3d _pos){ 
Jan Möbius's avatar
Jan Möbius committed
101
  // Set homogeneous coordinte to 1.0 to get a positional light source
102
  position_ = Vec4d( _pos[0],_pos[1],_pos[2],1.0); 
Jan Möbius's avatar
Jan Möbius committed
103
104
}

105
106
Vec3d LightSource::position() {
  return Vec3d( position_[0], position_[1], position_[2]);
Jan Möbius's avatar
Jan Möbius committed
107
108
}

109
void LightSource::direction( Vec3d _pos) { 
Jan Möbius's avatar
Jan Möbius committed
110
111
  // Set homogeneous coordinate of position to 0.0 to tell OpenGL
  // that this is a directional light source
112
  position_ = Vec4d( _pos[0],_pos[1],_pos[2],0.0); 
Jan Möbius's avatar
Jan Möbius committed
113
114
}

115
116
Vec3d LightSource::direction() {
    return Vec3d(position_[0], position_[1], position_[2]);
117
118
}

Jan Möbius's avatar
Jan Möbius committed
119
120
121
122
123
124
125
126
127
128
129
130
131
132
bool LightSource::directional() {
  return ( position_[3] == 0.0  );
}

void LightSource::enable()
{ enabled_ = true; }

void LightSource::disable()
{ enabled_ = false; }

bool LightSource::enabled() {
  return enabled_;
}

133
void LightSource::spotDirection( Vec3d _pos)
Jan Möbius's avatar
Jan Möbius committed
134
135
{ spotDirection_ = _pos; }

136
137
Vec3d LightSource::spotDirection( ) { 
  return Vec3d(spotDirection_[0],spotDirection_[1],spotDirection_[2]); 
Jan Möbius's avatar
Jan Möbius committed
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
}  

void LightSource::ambientColor(  Vec4f _color)
{ ambientColor_ = _color; }

Vec4f LightSource::ambientColor()
{ return ambientColor_; }

void LightSource::diffuseColor(  Vec4f _color)
{ diffuseColor_ = _color; }

Vec4f LightSource::diffuseColor()
{ return diffuseColor_; }

void LightSource::specularColor(  Vec4f _color)
{ specularColor_ = _color; }

Vec4f LightSource::specularColor()
{ return specularColor_; }

158
159
160
161
162
163
void LightSource::setColor(const Vec4f& _ambient, const Vec4f& _diffuse, const Vec4f& _specular) {
    ambientColor_ = _ambient;
    diffuseColor_ = _diffuse;
    specularColor_ = _specular;
}

Jan Möbius's avatar
Jan Möbius committed
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
void LightSource::fixedPosition( bool _state)
{ fixedPosition_ = _state; }

bool LightSource::fixedPosition() {
  return fixedPosition_;   
}

void LightSource::spotExponent(float _exponent) {
    spotExponent_ = _exponent;
}

float LightSource::spotExponent() {
    return spotExponent_;
}

void LightSource::spotCutoff(float _cutoff) {
    spotCutoff_ = _cutoff;
}

float LightSource::spotCutoff() {
    return spotCutoff_;
}

void LightSource::constantAttenuation(float _constantAttenuation) {
    constantAttenuation_ = _constantAttenuation;
}

float LightSource::constantAttenuation() {
    return constantAttenuation_;
}

void LightSource::linearAttenuation(float _linearAttenuation) {
    linearAttenuation_ = _linearAttenuation;
}

float LightSource::linearAttenuation() {
    return linearAttenuation_;
}

void LightSource::quadraticAttenuation(float _quadraticAttenuation) {
    quadraticAttenuation_ = _quadraticAttenuation;
}

float LightSource::quadraticAttenuation() {
    return quadraticAttenuation_;
}

211
212
213
void LightSource::brightness(float _brightness) {
    brightness_ = _brightness;
}
Jan Möbius's avatar
Jan Möbius committed
214

215
216
217
float LightSource::brightness() const {
    return brightness_;
}
Jan Möbius's avatar
Jan Möbius committed
218

219
220
LightNode::LightNode( BaseNode* _parent, 
    const std::string&   _name) 
Jan Möbius's avatar
Jan Möbius committed
221
  : BaseNode(_parent, _name),
222
223
    visualize_(false),
    lightId_(GL_INVALID_ENUM) {
224
  
225
226
227
    if(lightSourceHandle == 0) {
        lightSourceHandle = new LightSourceHandle();
    }
Jan Möbius's avatar
Jan Möbius committed
228
229
}

230
231
232
233
//----------------------------------------------------------------------------

LightNode::~LightNode() {
}
Jan Möbius's avatar
Jan Möbius committed
234
235
236
    
//----------------------------------------------------------------------------

237
238
239
void LightNode::boundingBox(ACG::Vec3d& _bbMin, ACG::Vec3d& _bbMax) {
    
    if( visualize_ && !light_.directional() ) {
Mike Kremer's avatar
Mike Kremer committed
240
241
        _bbMin.minimize( light_.position() - Vec3d(light_.radius()*3) );
        _bbMax.maximize( light_.position() + Vec3d(light_.radius()*3) );
242
243
244
245
246
247
248
249
250
251
    }
}

//----------------------------------------------------------------------------

void LightNode::draw(GLState& _state, DrawModes::DrawMode /*_drawMode*/) {
    
    // Visualize light node
    if(visualize_ && !light_.directional()) {
        
Mike Kremer's avatar
Mike Kremer committed
252
253
254
255
256
257
258
259
260
261
262
        if(light_.fixedPosition_) {
             light_.realPosition_ = _state.inverse_modelview() * light_.position_;
             light_.realSpotDirection_ = _state.inverse_modelview().transform_vector(light_.spotDirection_);
         } else {
             light_.realPosition_ = light_.position_;
             light_.realSpotDirection_ = light_.spotDirection_;
         }
         
         ACG::Vec3f p = ACG::Vec3f(light_.realPosition_[0],
                                   light_.realPosition_[1],
                                   light_.realPosition_[2]);
263
         ACG::Vec3d spotDir = light_.realSpotDirection_;          
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
         
         ACG::Vec4f ac = light_.ambientColor();
         ACG::Vec4f dc = light_.diffuseColor();
         ACG::Vec4f sc = light_.specularColor();
         
         // Make light sources appear as bright as possible
         float max = 0;
         for(int i = 0; i < 3; ++i) {
             if(ac[i] > max) max = ac[i];
         }
         ac += ACG::Vec4f(1.0f - max);
         max = 0;
         for(int i = 0; i < 3; ++i) {
             if(dc[i] > max) max = dc[i];
         }
         dc += ACG::Vec4f(1.0f - max);
         max = 0;
         for(int i = 0; i < 3; ++i) {
             if(sc[i] > max) max = sc[i];
         }
         sc += ACG::Vec4f(1.0f - max);
285
      
286
         // Backup variables
Mike Kremer's avatar
Mike Kremer committed
287
288
289
290
291
         GLboolean lighting_backup;
 
         GLUquadricObj* quadric = gluNewQuadric();
 
         // Origin
292
         _state.push_modelview_matrix();
Mike Kremer's avatar
Mike Kremer committed
293
294
295
296
297
         // Transform to light origin and direction
         _state.translate(p[0], p[1], p[2]);
             
         // Set lighting
         glGetBooleanv(GL_LIGHTING, &lighting_backup);
298
         glEnable(GL_LIGHTING);
Mike Kremer's avatar
Mike Kremer committed
299
 
300
301
302
303
304
305
306
307
308
309
310
311
312
         // Make light directional just for the drawing
         // of itself
         bool backup_directional = light_.directional();
         ACG::Vec3d backup_position = light_.position();
         
         // Get light id
         lightId_ = lightSourceHandle->getLight(this);
    
         // Return if we don't have a valid light source
         if(lightId_ == GL_INVALID_ENUM) {
             
             // Reset all stored attributes before returning
             if(!lighting_backup) glDisable(GL_LIGHTING);
Mike Kremer's avatar
Mike Kremer committed
313
 
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
             gluDeleteQuadric(quadric);
 
             _state.pop_modelview_matrix();
             
             return;
         }
         
         glLightf(lightId_, GL_SPOT_EXPONENT, 0.0f);
         float pos[] = {backup_position[0], backup_position[1], backup_position[2], 0.0f};
         glLightfv(lightId_, GL_POSITION, pos);
         
         // Set colors
         float gl_ac[] = {ac[0], ac[1], ac[2], ac[3]};
         glLightfv(lightId_, GL_AMBIENT, gl_ac);
         float gl_dc[] = {dc[0], dc[1], dc[2], dc[3]};
         glLightfv(lightId_, GL_DIFFUSE, gl_dc);
         float gl_sc[] = {sc[0], sc[1], sc[2], sc[3]};
         glLightfv(lightId_, GL_SPECULAR, gl_sc);
         
         glEnable(lightId_);
         
         gluQuadricOrientation(quadric, GLU_OUTSIDE);
Mike Kremer's avatar
Mike Kremer committed
336
337
338
339
340
341
342
343
344
         gluSphere( quadric, light_.radius(), 10, 10 );
 
         // Visualize spot cone (or direction)
         if(light_.spotCutoff() < 180.0f) {
             // Note: if the cutoff angle is 180, the light source
             // is a point light emitting light into all directions equally
             
             // Rotate into light direction
             ACG::Vec3d z = ACG::Vec3d(0.0f, 0.0f, 1.0f);
345
             ACG::Vec3d spot = spotDir;
Mike Kremer's avatar
Mike Kremer committed
346
347
348
349
350
             float angle = acos((z | spot)/(z.norm()*spot.norm()));
             angle = angle*360/(2*M_PI);
             ACG::Vec3d rA = z % spot;
             _state.rotate(angle, rA[0], rA[1], rA[2]);
 
351
352
             // Inverse normal orientation
             gluQuadricOrientation(quadric, GLU_INSIDE);
Mike Kremer's avatar
Mike Kremer committed
353
354
355
356
357
             gluCylinder( quadric, light_.radius()/6, light_.radius()/6, light_.radius()*2, 10, 10 );
             _state.translate(0.0, 0.0, light_.radius()*2);
             // Draw arrow tip
             gluCylinder( quadric, light_.radius()/2, 0, light_.radius(), 10, 10 );
         }
358
359
360
         
         // Free light id
         lightSourceHandle->removeLight(this);
Mike Kremer's avatar
Mike Kremer committed
361
362
 
         // Undo state changes
363
364
365
366
         
         if(!backup_directional) {
             light_.position(backup_position);
         }
Mike Kremer's avatar
Mike Kremer committed
367
368
 
         // Lighting
369
         if(!lighting_backup) glDisable(GL_LIGHTING);
Mike Kremer's avatar
Mike Kremer committed
370
371
372
373
374
 
         gluDeleteQuadric(quadric);
 
         _state.pop_modelview_matrix();
     }
375

376
377
}

378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
void LightNode::pick(GLState& _state, PickTarget _target) {

    GLenum prev_depth = _state.depthFunc();
    
    if (_target == PICK_FACE ||
       _target == PICK_ANYTHING) {
        
        // Visualize light node
        if(visualize_ && !light_.directional()) {
            
            if(light_.fixedPosition_) {
                 light_.realPosition_ = _state.inverse_modelview() * light_.position_;
                 light_.realSpotDirection_ = _state.inverse_modelview().transform_vector(light_.spotDirection_);
             } else {
                 light_.realPosition_ = light_.position_;
                 light_.realSpotDirection_ = light_.spotDirection_;
             }
             
             // Enable depth test but store original status
             glPushAttrib(GL_DEPTH_BUFFER_BIT);
             glEnable(GL_DEPTH_TEST);
             glDepthFunc(GL_LEQUAL);
             
             _state.pick_set_maximum(1);
             _state.pick_set_name(0);
             
             ACG::Vec3f p = ACG::Vec3f(light_.realPosition_[0],
                                       light_.realPosition_[1],
                                       light_.realPosition_[2]);
             ACG::Vec3d spotDir = light_.realSpotDirection_;          
             ACG::Vec4f c = light_.ambientColor() * light_.brightness_;
          
             GLUquadricObj* quadric = gluNewQuadric();

             // Origin
             _state.push_modelview_matrix();
             // Transform to light origin and direction
             _state.translate(p[0], p[1], p[2]);
                 
             gluSphere( quadric, light_.radius(), 10, 10 );

             // Visualize spot cone (or direction)
             if(light_.spotCutoff() < 180.0f) {
                 // Note: if the cutoff angle is 180, the light source
                 // is a point light emitting light into all directions equally
                 
                 // Rotate into light direction
                 ACG::Vec3d z = ACG::Vec3d(0.0f, 0.0f, 1.0f);
                 ACG::Vec3d spot = spotDir;
                 float angle = acos((z | spot)/(z.norm()*spot.norm()));
                 angle = angle*360/(2*M_PI);
                 ACG::Vec3d rA = z % spot;
                 _state.rotate(angle, rA[0], rA[1], rA[2]);

                 gluCylinder( quadric, light_.radius()/6, light_.radius()/6, light_.radius()*2, 10, 10 );
                 _state.translate(0.0, 0.0, light_.radius()*2);
                 // Draw arrow tip
                 gluCylinder( quadric, light_.radius()/2, 0, light_.radius(), 10, 10 );
             }

             gluDeleteQuadric(quadric);

             _state.pop_modelview_matrix();
             
             glDepthFunc(prev_depth);
         }  
    }
}

Jan Möbius's avatar
Jan Möbius committed
447
448
void LightNode::enter(GLState& _state, DrawModes::DrawMode /* _drawmode */ ) 
{
449
450
451
452
453
454
455
456
457
458
    if(visualize_) return;
    
    // Get light id
    lightId_ = lightSourceHandle->getLight(this);
    
    // Return if we don't have a valid light source
    if(lightId_ == GL_INVALID_ENUM) return;
    
    /// transfer GL-preferences to lightSave_
    getParameters(lightId_, lightSave_);
Jan Möbius's avatar
Jan Möbius committed
459
  
460
461
462
463
464
465
466
    // save old light
    lightSave_.enabled_ = glIsEnabled(lightId_);

    if(light_.enabled_ ) {
        // correct Position for fixed Lights
        if(light_.fixedPosition_) {
            light_.realPosition_ = _state.inverse_modelview() * light_.position_;
Mike Kremer's avatar
Mike Kremer committed
467
            light_.realSpotDirection_ = _state.inverse_modelview().transform_vector(light_.spotDirection_);
468
469
470
            //std::cerr << "New Light pos :" << _state.inverse_modelview().transform_vector(light_.position) << std::endl;
        } else {
            light_.realPosition_ = light_.position_;
Mike Kremer's avatar
Mike Kremer committed
471
            light_.realSpotDirection_ = light_.spotDirection_;
472
473
474
475
476
            //std::cerr << "New Light pos :" << light_.position << std::endl;
        }

        glEnable(lightId_);
        setParameters(lightId_, light_);
Jan Möbius's avatar
Jan Möbius committed
477
    } else {
478
        glDisable(lightId_);
Jan Möbius's avatar
Jan Möbius committed
479
480
481
482
483
484
485
486
487
    }
}


//----------------------------------------------------------------------------


void LightNode::leave(GLState& /* _state */ , DrawModes::DrawMode /* _drawmode*/ )
{
488
489
490
491
    if(visualize_) return;
    
    // Return if we don't have a valid light source
    if(lightId_ == GL_INVALID_ENUM) return;
492
      
493
494
495
496
497
498
499
500
501
502
503
    // restore old enabled light
    if(lightSave_.enabled_) {
        glEnable(lightId_);
        setParameters(lightId_, lightSave_);
    }
    else {
        glDisable(lightId_);
    }
    
    // Free light id
    lightSourceHandle->removeLight(this);
Jan Möbius's avatar
Jan Möbius committed
504
505
506
507
508
509
510
}

//----------------------------------------------------------------------------

void LightNode::setParameters(GLenum _index, LightSource& _light)
{

511
512
513
514
515
516
517
518
519
520
521
522
  // Multiply colors by brightness
  Vec4f& a = _light.ambientColor_;
  GLfloat ambient[4] = {a[0]*_light.brightness_, 
                        a[1]*_light.brightness_,
                        a[2]*_light.brightness_,
                        a[3]*_light.brightness_};

  Vec4f& d = _light.diffuseColor_;
  GLfloat diffuse[4] = {d[0]*_light.brightness_,
                        d[1]*_light.brightness_,
                        d[2]*_light.brightness_,
                        d[3]*_light.brightness_};
523
                        
524
525
526
527
528
529
  Vec4f& s = _light.specularColor_;
  GLfloat specular[4] = {s[0]*_light.brightness_,
                         s[1]*_light.brightness_,
                         s[2]*_light.brightness_,
                         s[3]*_light.brightness_};
  
Jan Möbius's avatar
Jan Möbius committed
530
  // set preferences of _light for GL_LIGHT#_index
531
532
533
  glLightfv(_index, GL_AMBIENT,  ambient);
  glLightfv(_index, GL_DIFFUSE,  diffuse);
  glLightfv(_index, GL_SPECULAR, specular);
Jan Möbius's avatar
Jan Möbius committed
534

535
536
  Vec3d& sd = _light.realSpotDirection_;
  GLfloat dir[3] = {(float)sd[0], (float)sd[1], (float)sd[2]};
Mike Kremer's avatar
Mike Kremer committed
537
  
538
539
540
541
542
543
544
545
546
547
548
  bool directional = _light.directional();
  
  Vec4f& p = _light.realPosition_;
  GLfloat realPos[4] = {(float)p[0], (float)p[1], (float)p[2], (directional ? 0.0f : 1.0f)};
  
  glLightfv(_index, GL_POSITION,  realPos);
  
  if(!directional) glLightfv(_index, GL_SPOT_DIRECTION,  dir);
  if(!directional) glLightf(_index, GL_SPOT_EXPONENT,  _light.spotExponent_);
  if(!directional) glLightf(_index, GL_SPOT_CUTOFF,  _light.spotCutoff_);
  
Jan Möbius's avatar
Jan Möbius committed
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
  glLightf(_index, GL_CONSTANT_ATTENUATION,  _light.constantAttenuation_);
  glLightf(_index, GL_LINEAR_ATTENUATION,  _light.linearAttenuation_);
  glLightf(_index, GL_QUADRATIC_ATTENUATION,  _light.quadraticAttenuation_);
//   std::cerr << " set GL_AMBIENT  : " << _index << " "  << _light.ambientColor << std::endl;
//   std::cerr << " set GL_DIFFUSE  : " << _index << " "  << _light.diffuseColor << std::endl;
//   std::cerr << " set GL_SPECULAR  : " << _index << " "  << _light.specularColor << std::endl;
//   
//   std::cerr << " set GL_POSITION  : " << _index << " "  << _light.realPosition << std::endl;
//   std::cerr << " set GL_SPOT_DIRECTION  : " << _index << " "  << _light.spotDirection << std::endl;
//   
//   std::cerr << " set GL_SPOT_EXPONENT  : " << _index << " "  << _light.spotExponent << std::endl;
//   std::cerr << " set GL_SPOT_CUTOFF  : " << _index << " "  << _light.spotCutoff << std::endl;
//   std::cerr << " set GL_CONSTANT_ATTENUATION  : " << _index << " "  << _light.constantAttenuation << std::endl;
//   std::cerr << " set GL_LINEAR_ATTENUATION  : " << _index << " "  << _light.linearAttenuation << std::endl;
//   std::cerr << " set GL_QUADRATIC_ATTENUATION  : " << _index << " "  << _light.quadraticAttenuation << std::endl;
//   std::cerr << "===============================================================================" << std::endl;
}

//----------------------------------------------------------------------------

void LightNode::getParameters(GLenum _index, LightSource& _light)
{
  // get preferences of GL_LIGHT#_index and store them in _light
  glGetLightfv(_index, GL_AMBIENT,  (GLfloat *)_light.ambientColor_.data());
  glGetLightfv(_index, GL_DIFFUSE,  (GLfloat *)_light.diffuseColor_.data());
  glGetLightfv(_index, GL_SPECULAR,  (GLfloat *)_light.specularColor_.data());
  glGetLightfv(_index, GL_POSITION,  (GLfloat *)_light.position_.data());
  glGetLightfv(_index, GL_SPOT_DIRECTION,  (GLfloat *)_light.spotDirection_.data());

  glGetLightfv(_index, GL_SPOT_EXPONENT,  &_light.spotExponent_);
  glGetLightfv(_index, GL_SPOT_CUTOFF,  &_light.spotCutoff_);
  glGetLightfv(_index, GL_CONSTANT_ATTENUATION,  &_light.constantAttenuation_);
  glGetLightfv(_index, GL_LINEAR_ATTENUATION,  &_light.linearAttenuation_);
  glGetLightfv(_index, GL_QUADRATIC_ATTENUATION,  &_light.quadraticAttenuation_);
//   std::cerr << " get GL_AMBIENT  : " << _index << " "  << _light.ambientColor << std::endl;
//   std::cerr << " get GL_DIFFUSE  : " << _index << " "  << _light.diffuseColor << std::endl;
//   std::cerr << " get GL_SPECULAR  : " << _index << " "  << _light.specularColor << std::endl;
//   
//   std::cerr << " get GL_POSITION  : " << _index << " "  << _light.realPosition << std::endl;
//   std::cerr << " get GL_SPOT_DIRECTION  : " << _index << " "  << _light.spotDirection << std::endl;
//     
//   std::cerr << " get GL_SPOT_EXPONENT  : " << _index << " "  << _light.spotExponent << std::endl;
//   std::cerr << " get GL_SPOT_CUTOFF  : " << _index << " "  << _light.spotCutoff << std::endl;
//   std::cerr << " get GL_CONSTANT_ATTENUATION  : " << _index << " "  << _light.constantAttenuation << std::endl;
//   std::cerr << " get GL_LINEAR_ATTENUATION  : " << _index << " "  << _light.linearAttenuation << std::endl;
//   std::cerr << " get GL_QUADRATIC_ATTENUATION  : " << _index << " "  << _light.quadraticAttenuation << std::endl;
}
//=============================================================================
} // namespace SceneGraph
} // namespace ACG
//=============================================================================