Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ScenePointLight.cpp
1 #include <GLviewer/Scenes/ScenePointLight.hh>
2 #include <GLviewer/GLProjectionParametersBase.hh>
3 
4 #include <Gui/biasgl.h>
5 #include <Base/Math/Vector3.hh>
6 
7 
8 using namespace BIAS;
9 using namespace BIAS;
10 using namespace std;
11 
14 {
15  lightPos_.SetZero();
16  drawLight_ = false;
17  lightAsHeadALight_ = false;
18 
19  diffuse_[0] = diffuse_[1] = diffuse_[2] = diffuse_[3] = 1.0;
20  specular_[0] = specular_[1] = specular_[2] = specular_[3] = 1.0;
21  ambient_[0] = ambient_[1] = ambient_[2] = 0.4; ambient_[3] = 1.0;
22 
23  useAttenuation_ = false;
24  attenuationFactors_[0] = 1.0f;
25  attenuationFactors_[1] = 0.2f;
26  attenuationFactors_[2] = 0.08f;
27 }
28 
29 
31 Draw()
32 {
33  glEnable(GL_LIGHTING);
34  glEnable(GL_LIGHT0);
35 
36  if( lightAsHeadALight_ && camera_ != NULL) {
37  lightPos_ = camera_->GetMyselfAsProjectionParameterBase()->GetC();
38  }
39 
40  float c[4] = { (float)lightPos_[0], (float)lightPos_[1], (float)lightPos_[2], 1.0 };
41  glLightfv(GL_LIGHT0, GL_POSITION, c);
42  glLightfv(GL_LIGHT0, GL_AMBIENT, ambient_);
43  glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse_);
44  glLightfv(GL_LIGHT0, GL_SPECULAR, specular_);
45 
46  if (useAttenuation_) {
47  glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, attenuationFactors_[0]);
48  glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, attenuationFactors_[1]);
49  glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, attenuationFactors_[2]);
50  }
51 
52  if (drawLight_) DrawLightPosition_();
53 }
54 
57 {
58  glDisable(GL_LIGHTING);
59 
60  GLint ps[1];
61  glGetIntegerv(GL_POINT_SIZE,ps);
62 
63  glPointSize(20);
64  glColor3f(1.0, 1.0, 0.0);
65  float c[4] = {(float)lightPos_[0], (float)lightPos_[1], (float)lightPos_[2], 1.0};
66  glBegin(GL_POINTS);
67  glVertex4fv(c);
68  glEnd();
69 
70  glPointSize(ps[0]);
71 
72  glEnable(GL_LIGHTING);
73 }
virtual void Draw()
To do anything usefull, overload this method, assume context is ready and draw.