V-ART
light.cpp
Go to the documentation of this file.
1 #include "vart/light.h"
5 
6 #ifdef WIN32
7 #include <windows.h>
8 #endif
9 #ifdef VART_OGL
10 #include <GL/gl.h>
11 #endif
12 
13 using namespace std;
14 
16  // FixMe: As with most V-ART default constructors, an unitilized object could be
17  // created here.
18  color.SetRGBA(255,255,255,255);
19  intensity = 1;
20  ambientIntensity = 1;
21  on = true;
22 
23  transform = new VART::Transform();
24  transform->MakeIdentity();
25 }
26 
27 VART::Light::Light (float i, float ai, VART::Color c, bool o) {
28  intensity=i;
29  ambientIntensity=ai;
30  color=c;
31  on=o;
32 
33  transform = new VART::Transform();
34  transform->MakeIdentity();
35 }
36 
37 VART::Light::Light(const string& newDescription, float newIntensity,
38  float newAmbientIntensity, const VART::Color& newColor,
39  const VART::Point4D& newLocation)
40 {
41  description = newDescription;
42  intensity = newIntensity;
43  ambientIntensity = newAmbientIntensity;
44  color = newColor;
45  location = newLocation;
46  on = true;
47 
48  transform = new VART::Transform();
49  transform->MakeIdentity();
50 }
51 
53  description = light.description;
54  intensity = light.intensity;
55  ambientIntensity = light.ambientIntensity;
56  color = light.color;
57  location = light.location;
58  on = light.on;
59 
60  transform = new VART::Transform(*light.transform);
61 }
62 
64 {
65  return new VART::Light(*this);
66 }
67 
69  delete transform;
70 }
71 
73  description = light.description;
74  intensity = light.intensity;
75  ambientIntensity = light.ambientIntensity;
76  color = light.color;
77  location = light.location;
78  on = light.on;
79  return (*this);
80 }
81 
83  static const VART::Light sun("TheSun", 0.7f, 0.7f, VART::Color::WHITE(), VART::Point4D(0,-1,0,0));
84  return sun;
85 }
87  static const VART::Light ba("BrightAmbient", 0.3f, 0.7f, VART::Color::WHITE(), VART::Point4D::ORIGIN());
88  return ba;
89 }
90 
92  intensity = i;
93 }
94 
96  return(intensity);
97 }
98 
100  ambientIntensity = ai;
101 }
102 
104  return(ambientIntensity);
105 }
106 
108  color = c;
109 }
110 
112  return(color);
113 }
114 
115 void VART::Light::Turn(bool on_off){
116  on=on_off;
117 }
118 
119 bool VART::Light::IsOn() const {
120  return on;
121 }
122 
123 void VART::Light::SetLocation(const VART::Point4D& newLocation){
124  location = newLocation;
125 }
126 
127 bool VART::Light::DrawOGL(unsigned int oglLightID) const {
128 // The ID is needed because OpenGL calls require it.
129 #ifdef VART_OGL
130  if (on) { // Is light enabled?
131  float weightedColor[4];
132  GLenum realID = getOpenGLID(oglLightID);
133 
134  //switch (oglLightID) {
135  // case 0:
136  // realID = GL_LIGHT0;
137  // break;
138  // case 1:
139  // realID = GL_LIGHT1;
140  // break;
141  // case 2:
142  // realID = GL_LIGHT2;
143  // break;
144  // case 3:
145  // realID = GL_LIGHT3;
146  // break;
147  // case 4:
148  // realID = GL_LIGHT4;
149  // break;
150  // case 5:
151  // realID = GL_LIGHT5;
152  // break;
153  // case 6:
154  // realID = GL_LIGHT6;
155  // break;
156  // default:
157  // realID = GL_LIGHT7;
158  // break;
159  // }
160 
161  color.GetScaled(ambientIntensity, weightedColor);
162  glLightfv(realID, GL_AMBIENT, weightedColor);
163  color.GetScaled(intensity, weightedColor);
164  glLightfv(realID, GL_DIFFUSE, weightedColor);
165 
166  glEnable(realID);
167  }
168  // FixMe: if light is turned off, it seems that glDisable should be called.
169  return true;
170 #else
171  return false;
172 #endif
173 }
174 
176 // virtual method
177  return false;
178 }
179 
180 unsigned int VART::Light::getOpenGLID(unsigned int lightID) const {
181  switch (lightID) {
182  case 0:
183  return GL_LIGHT0;
184  case 1:
185  return GL_LIGHT1;
186  case 2:
187  return GL_LIGHT2;
188  case 3:
189  return GL_LIGHT3;
190  case 4:
191  return GL_LIGHT4;
192  case 5:
193  return GL_LIGHT5;
194  case 6:
195  return GL_LIGHT6;
196  default:
197  return GL_LIGHT7;
198  }
199 }
200 
virtual SceneNode * Copy()
Returns a copy of an Light. Every derived class must reimplements this method, to avoid errors with V...
Definition: light.cpp:63
Base class for objects that compose a scene graph.
Definition: scenenode.h:25
void SetColor(const Color &c)
Definition: light.cpp:107
Point4D location
Definition: light.h:87
Points and vectors using homogeneous coordinates.
Definition: point4d.h:22
unsigned int getOpenGLID(unsigned int lightID) const
Definition: light.cpp:180
std::string description
Textual identification.
Definition: scenenode.h:162
RGBA color representation.
Definition: color.h:24
void SetLocation(const Point4D &newLocation)
Sets the location of the light.
Definition: light.cpp:123
Axis aligned bounding box.
Definition: boundingbox.h:23
Transform * transform
Definition: light.h:86
bool IsOn() const
Definition: light.cpp:119
Header file for V-ART class "Light".
Geometric transformations.
Definition: transform.h:24
Light & operator=(const Light &light)
Definition: light.cpp:72
virtual bool RecursiveBoundingBox(BoundingBox *bBox)
Always returns false, therefore recursive bbox does not exist.
Definition: light.cpp:175
void SetIntensity(float i)
Definition: light.cpp:91
virtual ~Light()
Definition: light.cpp:68
void SetAmbientIntensity(float ai)
Definition: light.cpp:99
float GetAmbientIntensity() const
Definition: light.cpp:103
float GetIntensity() const
Definition: light.cpp:95
static const Light & BRIGHT_AMBIENT()
Strong, white ambient light.
Definition: light.cpp:86
void Turn(bool on_off)
Turns a light on or off.
Definition: light.cpp:115
virtual bool DrawOGL() const
Recursive drawing using OpenGL commands.
Definition: scenenode.cpp:76
static const Point4D & ORIGIN()
The (0,0,0,1) point.
Definition: point4d.cpp:61
static const Color & WHITE()
White opaque color.
Definition: color.cpp:105
Color GetColor() const
Definition: light.cpp:111
static const Light & SUN()
White directional light towards negative Y. Small ambient intensity.
Definition: light.cpp:82
Represents a light source.
Definition: light.h:22