Developer Documentation
LightSourceNode.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  * $Author$ *
46  * $Date$ *
47  * *
48 \*===========================================================================*/
49 
50 
51 
52 
53 //=============================================================================
54 //
55 // CLASS LightSourceNode
56 //
57 //=============================================================================
58 
59 #ifndef ACG_LIGHTSOURCE_NODE_HH
60 #define ACG_LIGHTSOURCE_NODE_HH
61 
62 
63 //== INCLUDES =================================================================
64 
65 #include "BaseNode.hh"
66 #include "../GL/gl.hh"
67 #include <string>
68 #include <vector>
69 
70 
71 //== NAMESPACES ===============================================================
72 
73 namespace ACG {
74 namespace SceneGraph {
75 
76 
77 //== CLASS DEFINITION =========================================================
78 
79 
91 class ACGDLLEXPORT LightSourceNode : public BaseNode
92 {
93 
95  struct LightSource
96  {
97  //default Constructor
98  LightSource()
99  {
100  // set OpenGL defaults
101  enabled = false;
102  fixedPosition = false;
103 
104  ambientColor = Vec4f(0.1f,0.1f,0.1f,1.0f);
105  diffuseColor = Vec4f(1.0f,1.0f,1.0f,1.0f);
106  specularColor = Vec4f(1.0f,1.0f,1.0f,1.0f);
107  position = Vec4f(0.0f,0.0f,1.0f,0.0f);
108  realPosition = Vec4f(0.0f,0.0f,1.0f,0.0f);
109  spotDirection = Vec3f(0.0f,0.0f,-1.0f);
110  spotExponent = 0;
111  spotCutoff = 180;
112 
113  constantAttenuation = 1;
114  linearAttenuation = 0;
115  quadraticAttenuation = 0;
116  }
117 
118  bool enabled;
119  bool fixedPosition;
120  Vec4f ambientColor;
121  Vec4f diffuseColor;
122  Vec4f specularColor;
123  Vec4f position;
124  Vec4f realPosition;
125  Vec3f spotDirection;
126  float spotExponent;
127  float spotCutoff;
128  float constantAttenuation;
129  float linearAttenuation;
130  float quadraticAttenuation;
131  };
132 
133 
134 public:
135 
137  LightSourceNode( BaseNode* _parent = 0,
138  const std::string& _name = "<LightSourceNode>");
139 
141  virtual ~LightSourceNode() {}
142 
143 
144  ACG_CLASSNAME(LightSourceNode);
145 
147  void enter(GLState& _state, const DrawModes::DrawMode& _drawmode);
149  void leave(GLState& _state, const DrawModes::DrawMode& _drawmode);
150 
152  void enable(GLenum _nr)
153  { lights_[gl2index(_nr)].enabled = true; }
154 
156  void disable(GLenum _nr)
157  { lights_[gl2index(_nr)].enabled = false; }
158 
160  void set_position(GLenum _nr, Vec4f _pos)
161  { lights_[gl2index(_nr)].position = _pos; }
162 
164  void set_position(GLenum _nr, Vec3f _pos)
165  { set_position(_nr, Vec4f(_pos[0], _pos[1], _pos[2], 1)); }
166 
168  void set_direction(GLenum _nr, Vec3f _pos)
169  { set_position(_nr, Vec4f(_pos[0], _pos[1], _pos[2], 0)); }
170 
172  void set_ambient_color( GLenum _nr, Vec4f _color)
173  { lights_[gl2index(_nr)].ambientColor = _color; }
174 
176  void set_diffuse_color( GLenum _nr, Vec4f _color)
177  { lights_[gl2index(_nr)].diffuseColor = _color; }
178 
180  void set_specular_color( GLenum _nr, Vec4f _color)
181  { lights_[gl2index(_nr)].specularColor = _color; }
182 
184  void fixed_position(GLenum _nr, bool _state)
185  { lights_[gl2index(_nr)].fixedPosition = _state; }
186 
187 private:
188 
190  int gl2index( GLenum _nr)
191  { return( _nr - GL_LIGHT0); }
192 
194  GLenum index2gl( int _nr)
195  { return( _nr + GL_LIGHT0); }
196 
198  void set_parameters(GLenum _index, LightSource& _light);
199 
201  void get_parameters(GLenum _index, LightSource& _light);
202 
203 private:
204 
206  std::vector<LightSource> lights_;
207 
209  std::vector<LightSource> lightsSave_;
210 };
211 
212 
213 //=============================================================================
214 } // namespace SceneGraph
215 } // namespace ACG
216 //=============================================================================
217 #endif // ACG_LIGHTSOURCE_NODE_HH defined
218 //=============================================================================
219 
GLenum index2gl(int _nr)
return GL_LIGHT* for light _nr
void set_diffuse_color(GLenum _nr, Vec4f _color)
set Diffuse color for LightSource _nr
std::vector< LightSource > lightsSave_
save old LightSources
void enable(GLenum _nr)
enable LightSource _nr
VectorT< float, 4 > Vec4f
Definition: VectorT.hh:144
void set_direction(GLenum _nr, Vec3f _pos)
set direction for directional LightSource
Structure to hold options for one LightSource.
void fixed_position(GLenum _nr, bool _state)
make LightSource fixed or moveable with ModelViewMatrix
VectorT< float, 3 > Vec3f
Definition: VectorT.hh:125
void set_position(GLenum _nr, Vec3f _pos)
set position for Point-LightSource
std::vector< LightSource > lights_
store LightSources of this node
virtual ~LightSourceNode()
Destructor.
ACG::SceneGraph::LightSource LightSource
Simple Name for the LightSource.
Definition: LightTypes.hh:72
Namespace providing different geometric functions concerning angles.
Definition: DBSCANT.cc:51
void set_ambient_color(GLenum _nr, Vec4f _color)
set Ambient color for LightSource _nr
void set_specular_color(GLenum _nr, Vec4f _color)
set Specular color for LightSource _nr
void disable(GLenum _nr)
disable LightSource _nr
void set_position(GLenum _nr, Vec4f _pos)
set position ( _pos = 1) or direction ( _pos = 0) of LightSource
int gl2index(GLenum _nr)
return index in vector for GL_LIGHT*