Developer Documentation
LightNode.hh
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 
45 
46 
47 //=============================================================================
48 //
49 // CLASS LightNode
50 //
51 //=============================================================================
52 
53 #ifndef ACG_LIGHT_NODE_HH
54 #define ACG_LIGHT_NODE_HH
55 
56 
57 //== INCLUDES =================================================================
58 
59 #include <ACG/Scenegraph/BaseNode.hh>
62 #include <ACG/GL/gl.hh>
63 #include <ACG/GL/GLPrimitives.hh>
65 #include <string>
66 #include <vector>
67 
68 
69 //== NAMESPACES ===============================================================
70 
71 namespace ACG {
72 namespace SceneGraph {
73 
74 
75 //== CLASS DEFINITION =========================================================
76 
84 class OBJECTTYPEDLLEXPORT LightSource
86 {
87  // Declare Node as friend for direct access to memberss
88  friend class LightNode;
89 
90 public:
91 
93  LightSource();
94 
102  void position( Vec3d _pos);
103 
109  Vec3d position() const;
110 
116  bool directional() const;
117 
122  Vec3d direction() const;
123 
129  void direction( Vec3d _pos);
130 
132  void enable();
133 
135  void disable();
136 
138  bool enabled() const;
139 
144  void spotDirection(Vec3d _pos);
145 
150  Vec3d spotDirection( ) const;
151 
153  void ambientColor( Vec4f _color);
154 
156  Vec4f ambientColor() const;
157 
159  void diffuseColor( Vec4f _color);
160 
162  Vec4f diffuseColor() const;
163 
165  void specularColor( Vec4f _color);
166 
168  Vec4f specularColor() const;
169 
170  void setColor(const Vec4f& _ambient, const Vec4f& _diffuse, const Vec4f& _specular);
171 
173  void fixedPosition( bool _state);
174 
175  bool fixedPosition() const;
176 
177  void spotExponent(float _exponent);
178 
179  float spotExponent() const;
180 
181  void spotCutoff(float _cutoff);
182 
183  float spotCutoff() const;
184 
185  void constantAttenuation(float _constantAttenuation);
186 
187  float constantAttenuation() const;
188 
189  void linearAttenuation(float _linearAttenuation);
190 
191  float linearAttenuation() const;
192 
193  void quadraticAttenuation(float _quadraticAttenuation);
194 
195  float quadraticAttenuation() const;
196 
197  void brightness(const float _brightness);
198 
199  float brightness() const;
200 
206  float radius() const { return radius_; }
207 
213  void radius(const float _radius) { radius_ = _radius; }
214 
215 protected:
216 
217  Vec4f position_;
218  Vec4f realPosition_;
219 
220  bool enabled_;
221  bool fixedPosition_;
222  Vec4f ambientColor_;
223  Vec4f diffuseColor_;
224  Vec4f specularColor_;
225 
226  Vec3d spotDirection_;
227  Vec3d realSpotDirection_;
228 
229  // Only if in fixed mode
230  Vec4f initialPosition_;
231  Vec3d initialSpotDirection_;
232  bool initialPositionInit_;
233 
234  float spotExponent_;
235  float spotCutoff_;
236  float constantAttenuation_;
237  float linearAttenuation_;
238  float quadraticAttenuation_;
239 
240  float brightness_;
241 
245  float radius_;
246 };
247 
248 
249 class OBJECTTYPEDLLEXPORT LightNode : public BaseNode
250 {
251 
252 public:
253 
255  LightNode( BaseNode* _parent = 0,
256  const std::string& _name = "<LightNode>");
257 
259  virtual ~LightNode();
260 
262  void setLightSource(LightSource _light ) { light_ = _light; };
263 
265  void getLightSource(LightSource* _light) const;
266 
269  void getLightSourceViewSpace(LightSource* _light) const;
270 
271 
272  ACG_CLASSNAME(LightNode);
273 
275  void boundingBox(ACG::Vec3d& /* _bbMin */, ACG::Vec3d& /*_bbMax*/ );
276 
278  void enter(GLState& _state, const DrawModes::DrawMode& _drawmode);
279 
281  void leave(GLState& _state, const DrawModes::DrawMode& _drawmode);
282 
284  void draw(GLState& _state, const DrawModes::DrawMode& _drawMode);
285 
287  void pick(GLState& _state, PickTarget _target);
288 
290  bool visualize() { return visualize_; }
291 
293  void visualize(bool _visualize) { visualize_ = _visualize; }
294 
295 
297  void getRenderObjects(IRenderer* _renderer, GLState& _state , const DrawModes::DrawMode& _drawMode , const Material* _mat);
298 
299 
300 private:
301 
303  void setParameters(GLState& _state, GLenum _index, LightSource& _light);
304 
306  void getParameters(GLState& _state, GLenum _index, LightSource& _light);
307 
308 private:
309 
312 
315 
318 
321 
323  GLenum lightId_;
324 
325  ACG::GLCone* cone_;
326  ACG::GLSphere* sphere_;
327 };
328 
337 class OBJECTTYPEDLLEXPORT LightSourceHandle {
338  public:
340  GLint maxLights;
341 
342  // Get max number of lights
343  if (OpenFlipper::Options::gui() && !OpenFlipper::Options::coreProfile())
344  glGetIntegerv(GL_MAX_LIGHTS, &maxLights);
345  else
346  maxLights = 50;
347 
348  for(int i = 0; i < maxLights; ++i) {
349  lights_.insert(std::pair<GLenum, LightNode*>(GL_LIGHT0 + i, (LightNode*)0 ));
350  }
351  };
352 
353  GLenum getLight(LightNode* _node) {
354  GLenum light = GL_INVALID_ENUM;
355  for(std::map<GLenum, LightNode*>::iterator it = lights_.begin();
356  it != lights_.end(); ++it) {
357 
358  if(it->second == 0) {
359  lights_[it->first] = _node;
360  light = it->first;
361  break;
362  }
363  }
364  return light;
365  };
366 
367  void removeLight(LightNode* _node) {
368  for(std::map<GLenum, LightNode*>::iterator it = lights_.begin();
369  it != lights_.end(); ++it) {
370 
371  if(it->second == _node) {
372  lights_[it->first] = 0;
373  break;
374  }
375  }
376  };
377 
378  private:
379  std::map<GLenum, LightNode*> lights_;
380 };
381 
382 //=============================================================================
383 } // namespace SceneGraph
384 } // namespace ACG
385 //=============================================================================
386 #endif // ACG_LIGHT_NODE_HH defined
387 //=============================================================================
Namespace providing different geometric functions concerning angles.
LightSource light_
store LightSources of this node
Definition: LightNode.hh:311
bool visualize()
Should node be visualized?
Definition: LightNode.hh:290
LightSource transformedLight_
pretransformed light position and direction in view space
Definition: LightNode.hh:314
void visualize(bool _visualize)
Set whether node should be visualized.
Definition: LightNode.hh:293
LightSource lightSave_
save old LightSources
Definition: LightNode.hh:317
Structure to hold options for one LightSource.
Definition: LightNode.hh:85
GLenum lightId_
Internal light id.
Definition: LightNode.hh:323
bool visualize_
Indicates whether light node should be visualized or not.
Definition: LightNode.hh:320
PickTarget
What target to use for picking.
Definition: PickTarget.hh:73
ACG::SceneGraph::LightSource LightSource
Simple Name for the LightSource.
Definition: LightTypes.hh:66
ACG::SceneGraph::LightNode LightNode
Simple Name for PlaneNode.
Definition: LightTypes.hh:69
void radius(const float _radius)
Set light source radius.
Definition: LightNode.hh:213
void setLightSource(LightSource _light)
Set the light source parameters.
Definition: LightNode.hh:262
float radius() const
Get light source radius.
Definition: LightNode.hh:206