Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
LightNode.cc
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41 
42 /*===========================================================================*\
43 * *
44 * $Revision$ *
45 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49 
50 
51 
52 
53 //=============================================================================
54 //
55 // CLASS LightNode - IMPLEMENTATION
56 //
57 //=============================================================================
58 
59 
60 //== INCLUDES =================================================================
61 
62 
63 #include "LightNode.hh"
64 #include <ACG/GL/IRenderer.hh>
65 
66 #ifndef M_PI
67 #define M_PI 3.14159265358979323846
68 #endif
69 
70 //== NAMESPACES ===============================================================
71 
72 namespace ACG {
73 namespace SceneGraph {
74 
75 //== IMPLEMENTATION ==========================================================
76 
77 static LightSourceHandle* lightSourceHandle = 0;
78 
79 //default Constructor
81 {
82  // set OpenGL defaults
83  enabled_ = false;
84  fixedPosition_ = false;
85 
86  ambientColor_ = Vec4f(0.1f,0.1f,0.1f,1.f);
87  diffuseColor_ = Vec4f(1.f,1.f,1.f,1.f);
88  specularColor_ = Vec4f(1.f,1.f,1.f,1.f);
89 
90  position_ = Vec4f(0.f,0.f,1.f,0.f);
91  realPosition_ = Vec4f(0.f,0.f,1.f,0.f);
92 
93  spotDirection_ = Vec3d(0.0,0.0,-1.0);
94  realSpotDirection_ = Vec3d(0.0,0.0,-1.0);
95 
96  // Holds initial light source position
97  // converted to camera coordinates
98  initialPosition_ = Vec4f(0.f, 0.f, 0.f, 0.f);
99  initialSpotDirection_ = Vec3d(0.0, 0.0, -1.0);
100  initialPositionInit_ = false;
101 
102  spotExponent_ = 0;
103  spotCutoff_ = 180;
104 
105  constantAttenuation_ = 1;
106  linearAttenuation_ = 0;
107  quadraticAttenuation_ = 0;
108 
109  brightness_ = 1.0f;
110 
111  radius_ = 0.1f;
112 }
113 
115  // Set homogeneous coordinte to 1.0 to get a positional light source
116  position_ = Vec4d( _pos[0],_pos[1],_pos[2],1.0);
117 }
118 
120  return Vec3d( position_[0], position_[1], position_[2]);
121 }
122 
124  // Set homogeneous coordinate of position to 0.0 to tell OpenGL
125  // that this is a directional light source
126  position_ = Vec4d( _pos[0],_pos[1],_pos[2],0.0);
127 }
128 
130  return Vec3d(position_[0], position_[1], position_[2]);
131 }
132 
134  return ( position_[3] == 0.0 );
135 }
136 
138 { enabled_ = true; }
139 
141 { enabled_ = false; }
142 
143 bool LightSource::enabled() const {
144  return enabled_;
145 }
146 
148 { spotDirection_ = _pos; }
149 
151  return Vec3d(spotDirection_[0],spotDirection_[1],spotDirection_[2]);
152 }
153 
155 { ambientColor_ = _color; }
156 
158 { return ambientColor_; }
159 
161 { diffuseColor_ = _color; }
162 
164 { return diffuseColor_; }
165 
167 { specularColor_ = _color; }
168 
170 { return specularColor_; }
171 
172 void LightSource::setColor(const Vec4f& _ambient, const Vec4f& _diffuse, const Vec4f& _specular) {
173  ambientColor_ = _ambient;
174  diffuseColor_ = _diffuse;
175  specularColor_ = _specular;
176 }
177 
178 void LightSource::fixedPosition( bool _state)
179 { fixedPosition_ = _state; }
180 
181 bool LightSource::fixedPosition() const {
182  return fixedPosition_;
183 }
184 
185 void LightSource::spotExponent(float _exponent) {
186  spotExponent_ = _exponent;
187 }
188 
189 float LightSource::spotExponent() const {
190  return spotExponent_;
191 }
192 
193 void LightSource::spotCutoff(float _cutoff) {
194  spotCutoff_ = _cutoff;
195 }
196 
197 float LightSource::spotCutoff() const {
198  return spotCutoff_;
199 }
200 
201 void LightSource::constantAttenuation(float _constantAttenuation) {
202  constantAttenuation_ = _constantAttenuation;
203 }
204 
205 float LightSource::constantAttenuation() const {
206  return constantAttenuation_;
207 }
208 
209 void LightSource::linearAttenuation(float _linearAttenuation) {
210  linearAttenuation_ = _linearAttenuation;
211 }
212 
213 float LightSource::linearAttenuation() const {
214  return linearAttenuation_;
215 }
216 
217 void LightSource::quadraticAttenuation(float _quadraticAttenuation) {
218  quadraticAttenuation_ = _quadraticAttenuation;
219 }
220 
221 float LightSource::quadraticAttenuation() const {
222  return quadraticAttenuation_;
223 }
224 
225 void LightSource::brightness(float _brightness) {
226  brightness_ = _brightness;
227 }
228 
229 float LightSource::brightness() const {
230  return brightness_;
231 }
232 
234  const std::string& _name)
235  : BaseNode(_parent, _name),
236  visualize_(false),
237  lightId_(GL_INVALID_ENUM) {
238 
239  if(lightSourceHandle == 0) {
240  lightSourceHandle = new LightSourceHandle();
241  }
242 
243  sphere_ = new ACG::GLSphere(10, 10);
244  cone_ = new ACG::GLCone(10, 10, 1.0f, 1.0f, false, true);
245 }
246 
247 //----------------------------------------------------------------------------
248 
250  if (sphere_)
251  delete sphere_;
252 
253  if (cone_)
254  delete cone_;
255 }
256 
257 //----------------------------------------------------------------------------
258 
260 {
261  memcpy(_light, &light_, sizeof(LightSource));
262 }
263 
264 //----------------------------------------------------------------------------
265 
267 {
268  memcpy(_light, &transformedLight_, sizeof(LightSource));
269 }
270 
271 //----------------------------------------------------------------------------
272 
274 
275  if( visualize_ && !light_.directional() ) {
276  ACG::Vec3d r;
277  if(light_.fixedPosition())
278  r = ACG::Vec3d((double)light_.realPosition_[0],
279  (double)light_.realPosition_[1],
280  (double)light_.realPosition_[2]);
281  else
282  r = light_.position();
283  _bbMin.minimize( r - Vec3d(light_.radius()*3) );
284  _bbMax.maximize( r + Vec3d(light_.radius()*3) );
285  }
286 }
287 
288 //----------------------------------------------------------------------------
289 
290 void LightNode::draw(GLState& _state, const DrawModes::DrawMode& /*_drawMode*/) {
291 
292  // Visualize light node
293  if(visualize_ && !light_.directional()) {
294 
295  // Get initial camera coords of light if in fixed
296  // mode and if they haven't been computed yet
297  if(light_.fixedPosition_ && !light_.initialPositionInit_) {
298  light_.initialPosition_ = _state.modelview() * light_.position_;
299  light_.initialSpotDirection_ = _state.modelview().transform_vector(light_.spotDirection());
300  light_.initialPositionInit_ = true;
301  }
302 
303  if(light_.fixedPosition_) {
304  light_.realPosition_ = _state.inverse_modelview() * light_.initialPosition_;
305  light_.realSpotDirection_ = _state.inverse_modelview().transform_vector(light_.initialSpotDirection_);
306  } else {
307  light_.realPosition_ = light_.position_;
308  light_.realSpotDirection_ = light_.spotDirection_;
309  }
310 
311  ACG::Vec3f p = ACG::Vec3f(light_.realPosition_[0],
312  light_.realPosition_[1],
313  light_.realPosition_[2]);
314  ACG::Vec3d spotDir = light_.realSpotDirection_;
315 
319 
320  // Make light sources appear as bright as possible
321  float max = 0;
322  for(int i = 0; i < 3; ++i) {
323  if(ac[i] > max) max = ac[i];
324  }
325  ac += ACG::Vec4f(1.0f - max);
326  max = 0;
327  for(int i = 0; i < 3; ++i) {
328  if(dc[i] > max) max = dc[i];
329  }
330  dc += ACG::Vec4f(1.0f - max);
331  max = 0;
332  for(int i = 0; i < 3; ++i) {
333  if(sc[i] > max) max = sc[i];
334  }
335  sc += ACG::Vec4f(1.0f - max);
336 
337  // Backup variables
338  GLboolean lighting_backup;
339 
340  // Origin
341  _state.push_modelview_matrix();
342  // Transform to light origin and direction
343  _state.translate(p[0], p[1], p[2]);
344 
345  // Set lighting
346  glGetBooleanv(GL_LIGHTING, &lighting_backup);
347  ACG::GLState::enable(GL_LIGHTING);
348 
349  // Make light directional just for the drawing
350  // of itself
351  bool backup_directional = light_.directional();
352  ACG::Vec3d backup_position = light_.position();
353 
354  // Get light id
355  lightId_ = lightSourceHandle->getLight(this);
356 
357  // Return if we don't have a valid light source
358  if(lightId_ == GL_INVALID_ENUM) {
359 
360  // Reset all stored attributes before returning
361  if(!lighting_backup) ACG::GLState::disable(GL_LIGHTING);
362 
363  _state.pop_modelview_matrix();
364 
365  return;
366  }
367 
368  glLightf(lightId_, GL_SPOT_EXPONENT, 0.0f);
369  float pos[4];
370  pos [0] = backup_position[0];
371  pos [1] = backup_position[1];
372  pos [2] = backup_position[2];
373  pos [3] = 0.0f;
374 
375  glLightfv(lightId_, GL_POSITION, pos);
376 
377  // Set colors
378  float gl_ac[] = {ac[0], ac[1], ac[2], ac[3]};
379  glLightfv(lightId_, GL_AMBIENT, gl_ac);
380  float gl_dc[] = {dc[0], dc[1], dc[2], dc[3]};
381  glLightfv(lightId_, GL_DIFFUSE, gl_dc);
382  float gl_sc[] = {sc[0], sc[1], sc[2], sc[3]};
383  glLightfv(lightId_, GL_SPECULAR, gl_sc);
384 
386 
387  sphere_->draw(_state, light_.radius());
388 
389  // Visualize spot cone (or direction)
390  if(light_.spotCutoff() < 180.0f) {
391  // Note: if the cutoff angle is 180, the light source
392  // is a point light emitting light into all directions equally
393 
394  // Rotate into light direction
395  ACG::Vec3d z = ACG::Vec3d(0.0f, 0.0f, 1.0f);
396  ACG::Vec3d spot = spotDir;
397  float angle = acos((z | spot)/(z.norm()*spot.norm()));
398  angle = angle*360/(2*M_PI);
399  ACG::Vec3d rA = z % spot;
400  _state.rotate(angle, rA[0], rA[1], rA[2]);
401 
402  // Inverse normal orientation
403  cone_->setNormalOrientation(ACG::GLPrimitive::INSIDE);
404  cone_->setBottomRadius(light_.radius()/6.0f);
405  cone_->setTopRadius(light_.radius()/6.0f);
406  cone_->draw(_state, light_.radius()*2.0f);
407  _state.translate(0.0, 0.0, light_.radius()*2);
408  // Draw arrow tip
409  cone_->setBottomRadius(light_.radius()/2.0f);
410  cone_->setTopRadius(0.0f);
411  cone_->draw(_state, light_.radius());
412  }
413 
414  // Free light id
415  lightSourceHandle->removeLight(this);
416 
417  // Undo state changes
418 
419  if(!backup_directional) {
420  light_.position(backup_position);
421  }
422 
423  // Lighting
424  if(!lighting_backup) ACG::GLState::disable(GL_LIGHTING);
425 
426  _state.pop_modelview_matrix();
427  }
428 
429 }
430 
431 void LightNode::pick(GLState& _state, PickTarget _target) {
432 
433  GLenum prev_depth = _state.depthFunc();
434 
435  if (_target == PICK_FACE ||
436  _target == PICK_ANYTHING) {
437 
438  // Visualize light node
439  if(visualize_ && !light_.directional()) {
440 
441  // Get initial camera coords of light if in fixed
442  // mode and if they haven't been computed yet
443  if(light_.fixedPosition_ && !light_.initialPositionInit_) {
444  light_.initialPosition_ = _state.modelview() * light_.position_;
445  light_.initialSpotDirection_ = _state.modelview().transform_vector(light_.spotDirection());
446  light_.initialPositionInit_ = true;
447  }
448 
449  if(light_.fixedPosition_) {
450  light_.realPosition_ = _state.inverse_modelview() * light_.initialPosition_;
451  light_.realSpotDirection_ = _state.inverse_modelview().transform_vector(light_.initialSpotDirection_);
452  } else {
453  light_.realPosition_ = light_.position_;
454  light_.realSpotDirection_ = light_.spotDirection_;
455  }
456 
457  // Enable depth test but store original status
458  glPushAttrib(GL_DEPTH_BUFFER_BIT);
459  ACG::GLState::enable(GL_DEPTH_TEST);
460  ACG::GLState::depthFunc(GL_LEQUAL);
461 
462  _state.pick_set_maximum(1);
463  _state.pick_set_name(0);
464 
465  ACG::Vec3f p = ACG::Vec3f(light_.realPosition_[0],
466  light_.realPosition_[1],
467  light_.realPosition_[2]);
468  ACG::Vec3d spotDir = light_.realSpotDirection_;
469 
470  // Origin
471  _state.push_modelview_matrix();
472  // Transform to light origin and direction
473  _state.translate(p[0], p[1], p[2]);
474 
475  sphere_->draw(_state, light_.radius());
476 
477  // Visualize spot cone (or direction)
478  if(light_.spotCutoff() < 180.0f) {
479  // Note: if the cutoff angle is 180, the light source
480  // is a point light emitting light into all directions equally
481 
482  // Rotate into light direction
483  ACG::Vec3d z = ACG::Vec3d(0.0f, 0.0f, 1.0f);
484  ACG::Vec3d spot = spotDir;
485  float angle = acos((z | spot)/(z.norm()*spot.norm()));
486  angle = angle*360/(2*M_PI);
487  ACG::Vec3d rA = z % spot;
488  _state.rotate(angle, rA[0], rA[1], rA[2]);
489 
490  cone_->setNormalOrientation(ACG::GLPrimitive::OUTSIDE);
491  cone_->setBottomRadius(light_.radius()/6.0f);
492  cone_->setTopRadius(light_.radius()/6.0f);
493  cone_->draw(_state, light_.radius()*2.0f);
494  _state.translate(0.0, 0.0, light_.radius()*2);
495  // Draw arrow tip
496  cone_->setBottomRadius(light_.radius()/2.0f);
497  cone_->setTopRadius(0.0f);
498  cone_->draw(_state, light_.radius());
499  }
500 
501  _state.pop_modelview_matrix();
502 
503  ACG::GLState::depthFunc(prev_depth);
504  }
505  }
506 }
507 
508 void LightNode::enter(GLState& _state, const DrawModes::DrawMode& /* _drawmode */ )
509 {
510  if(visualize_) return;
511 
512  // Get initial camera coords of light if in fixed
513  // mode and if they haven't been computed yet
514  if(light_.fixedPosition_ && !light_.initialPositionInit_) {
515  light_.initialPosition_ = _state.modelview() * light_.position_;
516  light_.initialSpotDirection_ = _state.modelview().transform_vector(light_.spotDirection());
517  light_.initialPositionInit_ = true;
518  }
519 
520  // Get light id
521  lightId_ = lightSourceHandle->getLight(this);
522 
523  // Return if we don't have a valid light source
524  if(lightId_ == GL_INVALID_ENUM) return;
525 
528 
529  // save old light
530  lightSave_.enabled_ = glIsEnabled(lightId_);
531 
532  if(light_.enabled_ ) {
533  // correct Position for fixed Lights
534  if(light_.fixedPosition_) {
535  light_.realPosition_ = _state.inverse_modelview() * light_.initialPosition_;
536  light_.realSpotDirection_ = _state.inverse_modelview().transform_vector(light_.initialSpotDirection_);
537  //std::cerr << "New Light pos :" << _state.inverse_modelview().transform_vector(light_.position) << std::endl;
538  } else {
539  light_.realPosition_ = light_.position_;
540  light_.realSpotDirection_ = light_.spotDirection_;
541  //std::cerr << "New Light pos :" << light_.position << std::endl;
542  }
543 
544  // transform to view space for shader pipeline
546  transformedLight_.position_ = _state.modelview() * light_.realPosition_;
547  transformedLight_.spotDirection_ = _state.modelview().transform_vector(light_.realSpotDirection_);
548 
551  } else {
553  }
554 }
555 
556 
557 //----------------------------------------------------------------------------
558 
559 
560 void LightNode::leave(GLState& /* _state */ , const DrawModes::DrawMode& /* _drawmode*/ )
561 {
562  if(visualize_) return;
563 
564  // Return if we don't have a valid light source
565  if(lightId_ == GL_INVALID_ENUM) return;
566 
567  // restore old enabled light
568  if(lightSave_.enabled_) {
571  }
572  else {
574  }
575 
576  // Free light id
577  lightSourceHandle->removeLight(this);
578 }
579 
580 //----------------------------------------------------------------------------
581 
582 void LightNode::setParameters(GLenum _index, LightSource& _light)
583 {
584 
585  // Multiply colors by brightness
586  Vec4f& a = _light.ambientColor_;
587  GLfloat ambient[4] = {a[0]*_light.brightness_,
588  a[1]*_light.brightness_,
589  a[2]*_light.brightness_,
590  a[3]*_light.brightness_};
591 
592  Vec4f& d = _light.diffuseColor_;
593  GLfloat diffuse[4] = {d[0]*_light.brightness_,
594  d[1]*_light.brightness_,
595  d[2]*_light.brightness_,
596  d[3]*_light.brightness_};
597 
598  Vec4f& s = _light.specularColor_;
599  GLfloat specular[4] = {s[0]*_light.brightness_,
600  s[1]*_light.brightness_,
601  s[2]*_light.brightness_,
602  s[3]*_light.brightness_};
603 
604  // set preferences of _light for GL_LIGHT#_index
605  glLightfv(_index, GL_AMBIENT, ambient);
606  glLightfv(_index, GL_DIFFUSE, diffuse);
607  glLightfv(_index, GL_SPECULAR, specular);
608 
609  Vec3d& sd = _light.realSpotDirection_;
610 
611  bool directional = _light.directional();
612 
613  Vec4f& p = _light.realPosition_;
614  GLfloat realPos[4] = {(float)p[0], (float)p[1], (float)p[2], (directional ? 0.0f : 1.0f)};
615 
616  glLightfv(_index, GL_POSITION, realPos);
617 
618  if(!directional) {
619  GLfloat dir[3] = {(float)sd[0], (float)sd[1], (float)sd[2]};
620  glLightfv(_index, GL_SPOT_DIRECTION, dir);
621  }
622 
623  if(!directional) glLightf(_index, GL_SPOT_EXPONENT, _light.spotExponent_);
624  if(!directional) glLightf(_index, GL_SPOT_CUTOFF, _light.spotCutoff_);
625 
626  glLightf(_index, GL_CONSTANT_ATTENUATION, _light.constantAttenuation_);
627  glLightf(_index, GL_LINEAR_ATTENUATION, _light.linearAttenuation_);
628  glLightf(_index, GL_QUADRATIC_ATTENUATION, _light.quadraticAttenuation_);
629 }
630 
631 //----------------------------------------------------------------------------
632 
633 void LightNode::getParameters(GLenum _index, LightSource& _light)
634 {
635  // get preferences of GL_LIGHT#_index and store them in _light
636  glGetLightfv(_index, GL_AMBIENT, (GLfloat *)_light.ambientColor_.data());
637  glGetLightfv(_index, GL_DIFFUSE, (GLfloat *)_light.diffuseColor_.data());
638  glGetLightfv(_index, GL_SPECULAR, (GLfloat *)_light.specularColor_.data());
639  glGetLightfv(_index, GL_POSITION, (GLfloat *)_light.position_.data());
640  glGetLightfv(_index, GL_SPOT_DIRECTION, (GLfloat *)_light.spotDirection_.data());
641 
642  glGetLightfv(_index, GL_SPOT_EXPONENT, &_light.spotExponent_);
643  glGetLightfv(_index, GL_SPOT_CUTOFF, &_light.spotCutoff_);
644  glGetLightfv(_index, GL_CONSTANT_ATTENUATION, &_light.constantAttenuation_);
645  glGetLightfv(_index, GL_LINEAR_ATTENUATION, &_light.linearAttenuation_);
646  glGetLightfv(_index, GL_QUADRATIC_ATTENUATION, &_light.quadraticAttenuation_);
647 }
648 
649 
650 void LightNode::getRenderObjects( IRenderer* _renderer, GLState& _state , const DrawModes::DrawMode& _drawMode , const Material* _mat )
651 {
652 
653  // fill IRenderer light struct with light data in view-space
654  IRenderer::LightData light;
655 
657  light.ltype = ACG::SG_LIGHT_DIRECTIONAL;
658  else if (transformedLight_.spotCutoff() > 179.5f)
659  light.ltype = ACG::SG_LIGHT_POINT;
660  else
661  light.ltype = ACG::SG_LIGHT_SPOT;
662 
663 #define V4toV3(v) (ACG::Vec3f(v[0], v[1], v[2]))
664 
665  light.diffuse = V4toV3(transformedLight_.diffuseColor());
666  light.ambient = V4toV3(transformedLight_.ambientColor());
667  light.specular = V4toV3(transformedLight_.specularColor());
668 
669  light.pos = V4toV3(transformedLight_.position());
670  light.dir = V4toV3(transformedLight_.direction());
671 
672  light.atten[0] = transformedLight_.constantAttenuation();
673  light.atten[1] = transformedLight_.linearAttenuation();
674  light.atten[2] = transformedLight_.quadraticAttenuation();
675 
676  light.spotCutoffExponent[0] = transformedLight_.spotCutoff();
677  light.spotCutoffExponent[1] = transformedLight_.spotExponent();
678 
679  _renderer->addLight(light);
680 
681 }
682 
683 //=============================================================================
684 } // namespace SceneGraph
685 } // namespace ACG
686 //=============================================================================
Vec4f specularColor() const
get Specular color for LightSource
Definition: LightNode.cc:169
bool enabled() const
Get light source status.
Definition: LightNode.cc:143
void disable()
disable LightSource
Definition: LightNode.cc:140
LightSource lightSave_
save old LightSources
Definition: LightNode.hh:323
Namespace providing different geometric functions concerning angles.
Definition: DBSCANT.cc:51
static void enable(GLenum _cap)
replaces glEnable, but supports locking
void pick_set_name(unsigned int _idx)
sets the current name/color (like glLoadName(_idx))
Definition: GLState.cc:1057
PickTarget
What target to use for picking.
Definition: BaseNode.hh:99
void draw(GLState &_state, const DrawModes::DrawMode &_drawMode)
Draw light source node.
Definition: LightNode.cc:290
static void disable(GLenum _cap)
replaces glDisable, but supports locking
bool pick_set_maximum(unsigned int _idx)
Set the maximal number of primitives/components of your object.
Definition: GLState.cc:1047
picks faces (should be implemented for all nodes)
Definition: BaseNode.hh:104
pick any of the prior targets (should be implemented for all nodes)
Definition: BaseNode.hh:110
void translate(double _x, double _y, double _z, MultiplyFrom _mult_from=MULT_FROM_RIGHT)
translate by (_x, _y, _z)
Definition: GLState.cc:531
LightSource()
Default Constructor.
Definition: LightNode.cc:80
void rotate(double _angle, double _x, double _y, double _z, MultiplyFrom _mult_from=MULT_FROM_RIGHT)
rotate around axis (_x, _y, _z) by _angle
Definition: GLState.cc:562
void diffuseColor(Vec4f _color)
set Diffuse color for LightSource
Definition: LightNode.cc:160
virtual void addLight(const LightData &_light)
Callback for the scenegraph nodes, which send new lights to the renderer via this function...
Definition: IRenderer.cc:1030
VectorT< float, 4 > Vec4f
Definition: VectorT.hh:144
void fixedPosition(bool _state)
make LightSource fixed or moveable with ModelViewMatrix
Definition: LightNode.cc:178
VectorT< double, 3 > Vec3d
Definition: VectorT.hh:127
const GLMatrixd & modelview() const
get modelview matrix
Definition: GLState.hh:794
VectorT< T, 3 > transform_vector(const VectorT< T, 3 > &_v) const
transform vector (x',y',z',0) = A * (x,y,z,0)
Definition: Matrix4x4T.cc:225
void getRenderObjects(IRenderer *_renderer, GLState &_state, const DrawModes::DrawMode &_drawMode, const Material *_mat)
Add this light to shader render interface.
Definition: LightNode.cc:650
void leave(GLState &_state, const DrawModes::DrawMode &_drawmode)
restores original Light Sources
Definition: LightNode.cc:560
virtual ~LightNode()
Destructor.
Definition: LightNode.cc:249
void push_modelview_matrix()
push modelview matrix
Definition: GLState.cc:1006
Vec3d position() const
Get the position of the LightSource.
Definition: LightNode.cc:119
const GLenum & depthFunc() const
get glDepthFunc() that is supposed to be active
const GLMatrixd & inverse_modelview() const
get inverse modelview matrix
Definition: GLState.hh:814
VectorT< float, 3 > Vec3f
Definition: VectorT.hh:125
Vec3d direction() const
Get direction of the light source.
Definition: LightNode.cc:129
void getLightSource(LightSource *_light) const
Get the light source parameters.
Definition: LightNode.cc:259
Vec4f ambientColor() const
get Ambient color for LightSource
Definition: LightNode.cc:157
void pop_modelview_matrix()
pop modelview matrix
Definition: GLState.cc:1022
LightSource transformedLight_
pretransformed light position and direction in view space
Definition: LightNode.hh:320
void setParameters(GLenum _index, LightSource &_light)
set _light Options in OpenGL for GL_LIGHT::_index
Definition: LightNode.cc:582
LightNode(BaseNode *_parent=0, const std::string &_name="<LightNode>")
Default constructor. Applies all properties.
Definition: LightNode.cc:233
LightSource light_
store LightSources of this node
Definition: LightNode.hh:317
void getParameters(GLenum _index, LightSource &_light)
get _light Options in OpenGL for GL_LIGHT::_index
Definition: LightNode.cc:633
VectorT< double, 4 > Vec4d
Definition: VectorT.hh:146
bool visualize_
Indicates whether light node should be visualized or not.
Definition: LightNode.hh:326
void pick(GLState &_state, PickTarget _target)
Picking.
Definition: LightNode.cc:431
Structure to hold options for one LightSource.
Definition: LightNode.hh:91
bool directional() const
Check if the light source is a directional light source.
Definition: LightNode.cc:133
void specularColor(Vec4f _color)
set Specular color for LightSource
Definition: LightNode.cc:166
GLenum lightId_
Internal light id.
Definition: LightNode.hh:329
void enable()
enable LightSource
Definition: LightNode.cc:137
Vec4f diffuseColor() const
get Diffuse color for LightSource
Definition: LightNode.cc:163
const GLenum & depthFunc() const
get glDepthFunc() that is supposed to be active
Definition: GLState.cc:937
void enter(GLState &_state, const DrawModes::DrawMode &_drawmode)
set current Light Sources
Definition: LightNode.cc:508
void boundingBox(ACG::Vec3d &, ACG::Vec3d &)
Get bounding box (for visualization purposes)
Definition: LightNode.cc:273
float radius() const
Get light source radius.
Definition: LightNode.hh:212
void ambientColor(Vec4f _color)
set Ambient color for LightSource
Definition: LightNode.cc:154
Vec3d spotDirection() const
get spot direction
Definition: LightNode.cc:150
void position(Vec3d _pos)
Set position for LightSource.
Definition: LightNode.cc:114
void spotDirection(Vec3d _pos)
Set spot direction.
Definition: LightNode.cc:147
void getLightSourceViewSpace(LightSource *_light) const
Definition: LightNode.cc:266