H3D API  2.4.1
X3DLightNode.h
Go to the documentation of this file.
1 // Copyright 2004-2019, SenseGraphics AB
3 //
4 // This file is part of H3D API.
5 //
6 // H3D API is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // H3D API is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with H3D API; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 //
20 // A commercial license is also available. Please contact us at
21 // www.sensegraphics.com for more information.
22 //
23 //
27 //
29 #ifndef __X3DLIGHTNODE_H__
30 #define __X3DLIGHTNODE_H__
31 
32 #include <H3D/X3DChildNode.h>
35 #include <H3D/SFFloat.h>
36 #include <H3D/SFColor.h>
37 
38 namespace H3D {
39 
67  class H3DAPI_API X3DLightNode :
68  public X3DChildNode,
69  public H3DDisplayListObject,
70  public H3DRenderStateObject {
71  public:
72 
75  struct GLLightInfo {
76  GLLightInfo (
77  RGBA _ambient = RGBA(0.0f,0.0f,0.0f, 1.0f),
78  RGBA _diffuse = RGBA(0.0f,0.0f,0.0f,1.0f),
79  RGBA _specular = RGBA(0.0f,0.0f,0.0f,1.0f),
80  Vec4f _position = Vec4f(0.0f,0.0f,0.0f,0.0f),
81  Vec3f _spotDirection= Vec3f(),
82  H3DFloat _spotExponent= 0,
83  H3DFloat _spotCutoff= 180.0f,
84  H3DFloat _constantAttenuation= 0.0f,
85  H3DFloat _linearAttenuation= 0.0f,
86  H3DFloat _quadraticAttenuation= 0.0f ) :
87  ambient ( _ambient ),
88  diffuse ( _diffuse ),
89  specular ( _specular ),
90  position ( _position ),
91  spotDirection ( _spotDirection ),
92  spotExponent( _spotExponent ),
93  spotCutoff ( _spotCutoff ),
94  linearAttenuation ( _linearAttenuation ),
95  constantAttenuation( _constantAttenuation ),
96  quadraticAttenuation ( _quadraticAttenuation ) {}
97 
98  RGBA ambient;
99  RGBA diffuse;
100  RGBA specular;
101  Vec4f position;
102  Vec3f spotDirection;
103  H3DFloat spotExponent;
104  H3DFloat spotCutoff; // (range: [0.0,90.0], 180.0)
105  H3DFloat linearAttenuation;
106  H3DFloat constantAttenuation;
107  H3DFloat quadraticAttenuation;
108 
109  bool isDirectionalLight() {
110  return position.w == 0;
111  }
112 
113  bool isPointLight() {
114  return !isDirectionalLight() && spotCutoff == 180;
115  }
116 
117  bool isSpotLight() {
118  return !isDirectionalLight() && !isPointLight();
119  }
120 
121  };
122 
124  X3DLightNode( Inst< SFNode > _metadata = 0,
125  Inst< SFFloat> _ambientIntensity = 0,
126  Inst< SFColor> _color = 0,
127  Inst< SFBool > _global = 0,
128  Inst< SFFloat> _intensity = 0,
129  Inst< SFBool > _on = 0,
130  Inst< SFBool > _shadows = 0 );
131 
133  virtual void enableGraphicsState();
134 
136  virtual void disableGraphicsState();
137 
138  virtual GLLightInfo getGLLightInfo()
139 #ifndef H3D_GENERATE_DOTROUTE_FILES
140  = 0;
141 #else
142  { return GLLightInfo (RGBA(0.0f,0.0f,0.0f, 1.0f), RGBA(0.0f,0.0f,0.0f,1.0f),
143  RGBA(0.0f,0.0f,0.0f,1.0f), Vec4f(0.0f,0.0f,0.0f,0.0f), Vec3f(), 0,
144  180.0f, 0.0f, 0.0f, 0.0f ); }
145 #endif
146 
148  virtual void enableHapticsState( TraverseInfo &ti );
149 
151  virtual void disableHapticsState( TraverseInfo &ti );
152 
157  virtual void traverseSG( TraverseInfo &ti );
158 
162  static GLuint getLightIndex( string name_for_error );
163 
166  static void decreaseLightIndex() { --global_light_index; }
167 
175  H3DUniquePtr< SFFloat > ambientIntensity;
176 
185  H3DUniquePtr< SFColor > color;
186 
195  H3DUniquePtr< SFBool > global;
196 
205  H3DUniquePtr< SFFloat > intensity;
206 
215  H3DUniquePtr< SFBool > on;
216 
224  H3DUniquePtr< SFBool > shadows;
225 
228 
229  protected:
231  GLuint light_index;
232  static GLint max_lights;
233  static GLint global_light_index;
234 
237 
243 
244  vector< Matrix4f > global_light_transforms;
245 
248 
251  list< bool > had_light_index;
252  };
253 }
254 
255 #endif
Header file for H3DDisplayListObject.
Header file for H3DRenderStateObject.
Contains the SFColor field class.
Contains the SFFloat field class.
Header file for X3DChildNode, X3D scene-graph node.
This abstract interface class is the base class for all node types that wants to create an OpenGL dis...
Definition: H3DDisplayListObject.h:54
This abstract class is the base class for node types that want to change the rendering state temporar...
Definition: H3DRenderStateObject.h:45
TraverseInfo is a structure that is passed along when traversing the scene graph.
Definition: TraverseInfo.h:57
This abstract node type indicates that the concrete nodes which are instantiated based on it may be u...
Definition: X3DChildNode.h:42
The X3DLightNode abstract node type is the base type from which all node types that serve as light so...
Definition: X3DLightNode.h:70
H3DInt32 traverse_sg_counter
count how many times this X3DLightNodes traverseSG function is called.
Definition: X3DLightNode.h:240
static H3DNodeDatabase database
The H3DNodeDatabase for this node.
Definition: X3DLightNode.h:227
H3DUniquePtr< SFBool > global
The global field specifies whether the X3DLightNode affects all geometries in the scene or only those...
Definition: X3DLightNode.h:195
static void decreaseLightIndex()
must be called if getLightIndex have been called outside X3DLightNode.
Definition: X3DLightNode.h:166
TraverseInfo * last_ti_ptr
only interested in adress, what it points to will be invalid
Definition: X3DLightNode.h:236
list< bool > had_light_index
true if a light index was created for each call to enableGraphicsState for this X3DLightNode
Definition: X3DLightNode.h:251
GLuint light_index
Light index for this node, used to enable light.
Definition: X3DLightNode.h:231
H3DUniquePtr< SFBool > on
The on field specifies whether the light is enabled or disabled.
Definition: X3DLightNode.h:215
H3DUniquePtr< SFFloat > intensity
The intensity field specifies the brightness of the direct emission from the light.
Definition: X3DLightNode.h:205
H3DInt32 graphics_state_counter
count nr of times enableGraphicsState is called.
Definition: X3DLightNode.h:242
H3DUniquePtr< SFColor > color
The color field specifies the spectral colour properties of both the direct and ambient light emissio...
Definition: X3DLightNode.h:185
H3DUniquePtr< SFBool > shadows
The shadows field will determine if this light will be part of the shadow calculations of the scene.
Definition: X3DLightNode.h:224
H3DUniquePtr< SFFloat > ambientIntensity
Specifies the intensity of the ambient emission from the light.
Definition: X3DLightNode.h:175
bool act_global
used if the light should act as a global light.
Definition: X3DLightNode.h:247
Vec4f()
int H3DInt32
float H3DFloat
H3D API namespace.
Definition: Anchor.h:38
The H3DNodeDatabase contains a mapping between a name of a Node and the constructor for the Node with...
Definition: H3DNodeDatabase.h:194
A structure representing a the OpenGL representation of the specified light source.
Definition: X3DLightNode.h:75