Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 * $Revision$ *
45 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49 
50 
51 
52 
53 //=============================================================================
54 //
55 // CLASS LightNode
56 //
57 //=============================================================================
58 
59 #ifndef ACG_LIGHT_NODE_HH
60 #define ACG_LIGHT_NODE_HH
61 
62 
63 //== INCLUDES =================================================================
64 
65 #include <ACG/Scenegraph/BaseNode.hh>
68 #include <ACG/GL/gl.hh>
69 #include <ACG/GL/GLPrimitives.hh>
71 #include <string>
72 #include <vector>
73 
74 
75 //== NAMESPACES ===============================================================
76 
77 namespace ACG {
78 namespace SceneGraph {
79 
80 
81 //== CLASS DEFINITION =========================================================
82 
92 {
93  // Declare Node as friend for direct access to memberss
94  friend class LightNode;
95 
96 public:
97 
99  LightSource();
100 
108  void position( Vec3d _pos);
109 
115  Vec3d position() const;
116 
122  bool directional() const;
123 
128  Vec3d direction() const;
129 
135  void direction( Vec3d _pos);
136 
138  void enable();
139 
141  void disable();
142 
144  bool enabled() const;
145 
150  void spotDirection(Vec3d _pos);
151 
156  Vec3d spotDirection( ) const;
157 
159  void ambientColor( Vec4f _color);
160 
162  Vec4f ambientColor() const;
163 
165  void diffuseColor( Vec4f _color);
166 
168  Vec4f diffuseColor() const;
169 
171  void specularColor( Vec4f _color);
172 
174  Vec4f specularColor() const;
175 
176  void setColor(const Vec4f& _ambient, const Vec4f& _diffuse, const Vec4f& _specular);
177 
179  void fixedPosition( bool _state);
180 
181  bool fixedPosition() const;
182 
183  void spotExponent(float _exponent);
184 
185  float spotExponent() const;
186 
187  void spotCutoff(float _cutoff);
188 
189  float spotCutoff() const;
190 
191  void constantAttenuation(float _constantAttenuation);
192 
193  float constantAttenuation() const;
194 
195  void linearAttenuation(float _linearAttenuation);
196 
197  float linearAttenuation() const;
198 
199  void quadraticAttenuation(float _quadraticAttenuation);
200 
201  float quadraticAttenuation() const;
202 
203  void brightness(const float _brightness);
204 
205  float brightness() const;
206 
212  float radius() const { return radius_; }
213 
219  void radius(const float _radius) { radius_ = _radius; }
220 
221 protected:
222 
223  Vec4f position_;
224  Vec4f realPosition_;
225 
226  bool enabled_;
227  bool fixedPosition_;
228  Vec4f ambientColor_;
229  Vec4f diffuseColor_;
230  Vec4f specularColor_;
231 
232  Vec3d spotDirection_;
233  Vec3d realSpotDirection_;
234 
235  // Only if in fixed mode
236  Vec4f initialPosition_;
237  Vec3d initialSpotDirection_;
238  bool initialPositionInit_;
239 
240  float spotExponent_;
241  float spotCutoff_;
242  float constantAttenuation_;
243  float linearAttenuation_;
244  float quadraticAttenuation_;
245 
246  float brightness_;
247 
251  float radius_;
252 };
253 
254 
256 {
257 
258 public:
259 
261  LightNode( BaseNode* _parent = 0,
262  const std::string& _name = "<LightNode>");
263 
265  virtual ~LightNode();
266 
268  void setLightSource(LightSource _light ) { light_ = _light; };
269 
271  void getLightSource(LightSource* _light) const;
272 
275  void getLightSourceViewSpace(LightSource* _light) const;
276 
277 
278  ACG_CLASSNAME(LightNode);
279 
281  void boundingBox(ACG::Vec3d& /* _bbMin */, ACG::Vec3d& /*_bbMax*/ );
282 
284  void enter(GLState& _state, const DrawModes::DrawMode& _drawmode);
285 
287  void leave(GLState& _state, const DrawModes::DrawMode& _drawmode);
288 
290  void draw(GLState& _state, const DrawModes::DrawMode& _drawMode);
291 
293  void pick(GLState& _state, PickTarget _target);
294 
296  bool visualize() { return visualize_; }
297 
299  void visualize(bool _visualize) { visualize_ = _visualize; }
300 
301 
303  void getRenderObjects(IRenderer* _renderer, GLState& _state , const DrawModes::DrawMode& _drawMode , const Material* _mat);
304 
305 
306 private:
307 
309  void setParameters(GLenum _index, LightSource& _light);
310 
312  void getParameters(GLenum _index, LightSource& _light);
313 
314 private:
315 
318 
321 
324 
327 
329  GLenum lightId_;
330 
331  ACG::GLCone* cone_;
332  ACG::GLSphere* sphere_;
333 };
334 
344  public:
346  GLint maxLights;
347 
348  // Get max number of lights
349  if (OpenFlipper::Options::gui())
350  glGetIntegerv(GL_MAX_LIGHTS, &maxLights);
351  else
352  maxLights = 50;
353 
354  for(int i = 0; i < maxLights; ++i) {
355  lights_.insert(std::pair<GLenum, LightNode*>(GL_LIGHT0 + i, (LightNode*)0 ));
356  }
357  };
358 
359  GLenum getLight(LightNode* _node) {
360  GLenum light = GL_INVALID_ENUM;
361  for(std::map<GLenum, LightNode*>::iterator it = lights_.begin();
362  it != lights_.end(); ++it) {
363 
364  if(it->second == 0) {
365  lights_[it->first] = _node;
366  light = it->first;
367  break;
368  }
369  }
370  return light;
371  };
372 
373  void removeLight(LightNode* _node) {
374  for(std::map<GLenum, LightNode*>::iterator it = lights_.begin();
375  it != lights_.end(); ++it) {
376 
377  if(it->second == _node) {
378  lights_[it->first] = 0;
379  break;
380  }
381  }
382  };
383 
384  private:
385  std::map<GLenum, LightNode*> lights_;
386 };
387 
388 //=============================================================================
389 } // namespace SceneGraph
390 } // namespace ACG
391 //=============================================================================
392 #endif // ACG_LIGHT_NODE_HH defined
393 //=============================================================================
bool visualize()
Should node be visualized?
Definition: LightNode.hh:296
LightSource lightSave_
save old LightSources
Definition: LightNode.hh:323
Namespace providing different geometric functions concerning angles.
Definition: DBSCANT.cc:51
PickTarget
What target to use for picking.
Definition: BaseNode.hh:99
void setLightSource(LightSource _light)
Set the light source parameters.
Definition: LightNode.hh:268
ACG::SceneGraph::LightNode LightNode
Simple Name for PlaneNode.
Definition: LightTypes.hh:75
LightSource transformedLight_
pretransformed light position and direction in view space
Definition: LightNode.hh:320
LightSource light_
store LightSources of this node
Definition: LightNode.hh:317
#define DLLEXPORT
bool visualize_
Indicates whether light node should be visualized or not.
Definition: LightNode.hh:326
Structure to hold options for one LightSource.
Definition: LightNode.hh:91
GLenum lightId_
Internal light id.
Definition: LightNode.hh:329
void radius(const float _radius)
Set light source radius.
Definition: LightNode.hh:219
void visualize(bool _visualize)
Set whether node should be visualized.
Definition: LightNode.hh:299
float radius() const
Get light source radius.
Definition: LightNode.hh:212
ACG::SceneGraph::LightSource LightSource
Simple Name for the LightSource.
Definition: LightTypes.hh:72