CSpotLight.h
Go to the documentation of this file.
1 //==============================================================================
2 /*
3  Software License Agreement (BSD License)
4  Copyright (c) 2003-2016, CHAI3D.
5  (www.chai3d.org)
6 
7  All rights reserved.
8 
9  Redistribution and use in source and binary forms, with or without
10  modification, are permitted provided that the following conditions
11  are met:
12 
13  * Redistributions of source code must retain the above copyright
14  notice, this list of conditions and the following disclaimer.
15 
16  * Redistributions in binary form must reproduce the above
17  copyright notice, this list of conditions and the following
18  disclaimer in the documentation and/or other materials provided
19  with the distribution.
20 
21  * Neither the name of CHAI3D nor the names of its contributors may
22  be used to endorse or promote products derived from this software
23  without specific prior written permission.
24 
25  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
28  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
29  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
30  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
31  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  POSSIBILITY OF SUCH DAMAGE.
37 
38  \author <http://www.chai3d.org>
39  \author Francois Conti
40  \version 3.1.1 $Rev: 1869 $
41 */
42 //==============================================================================
43 
44 //------------------------------------------------------------------------------
45 #ifndef CSpotLightH
46 #define CSpotLightH
47 //------------------------------------------------------------------------------
50 //------------------------------------------------------------------------------
51 
52 //------------------------------------------------------------------------------
53 namespace chai3d {
54 //------------------------------------------------------------------------------
55 
56 //==============================================================================
63 //==============================================================================
64 
65 //==============================================================================
76 //==============================================================================
78 {
79  //--------------------------------------------------------------------------
80  // CONSTRUCTOR & DESTRUCTOR:
81  //--------------------------------------------------------------------------
82 
83 public:
84 
86  cSpotLight(cWorld* a_world);
87 
89  virtual ~cSpotLight();
90 
91 
92  //-----------------------------------------------------------------------
93  // PUBLIC METHODS - SHADOW CASTING:
94  //-----------------------------------------------------------------------
95 
96 public:
97 
99  bool updateShadowMap(const double a_mirrorH = 1.0,
100  const double a_mirrorV = 1.0,
101  const int a_displayContext = 0);
102 
104  void setShadowMapProperties(const double& a_nearClippingPlane,
105  const double& a_farClippingPlane);
106 
108  void setShadowMapEnabled(const bool a_enabled);
109 
111  bool getShadowMapEnabled() const;
112 
113 
114  //-----------------------------------------------------------------------
115  // PUBLIC MEMBERS - SHADOW CASTING:
116  //-----------------------------------------------------------------------
117 
118 public:
119 
122 
123 
124  //-----------------------------------------------------------------------
125  // PUBLIC METHODS - LIGHTING PROPERTIES:
126  //-----------------------------------------------------------------------
127 
128 public:
129 
131  void setSpotExponent(const GLfloat& a_value) { m_spotExponent = cClamp(a_value, 0.0f, 100.0f); }
132 
134  GLfloat getSpotExponent() const { return (m_spotExponent); }
135 
137  void setCutOffAngleDeg(const GLfloat& a_angleDeg);
138 
140  GLfloat getCutOffAngleDeg() const { return (m_cutOffAngleDeg); }
141 
142 
143  //-----------------------------------------------------------------------
144  // PUBLIC METHODS - DISPLAY MODEL:
145  //-----------------------------------------------------------------------
146 
147 public:
148 
150  void setDisplaySettings(const double& a_sourceRadius = 0.02,
151  const double& a_coneLength = 1.0,
152  const bool a_displayEnabled = true);
153 
154 
155  //-----------------------------------------------------------------------
156  // PUBLIC MEMBERS - DISPLAY MODEL:
157  //-----------------------------------------------------------------------
158 
159 public:
160 
163 
164 
165  //-----------------------------------------------------------------------
166  // PROTECTED MEMBERS - LIGHTING PROPERTIES
167  //-----------------------------------------------------------------------
168 
169 protected:
170 
172  GLfloat m_spotExponent;
173 
176 
177 
178  //--------------------------------------------------------------------------
179  // PROTECTED MEMBERS - SHADOW CASTING
180  //--------------------------------------------------------------------------
181 
182 protected:
183 
186 
189 
190 
191  //-----------------------------------------------------------------------
192  // PROTECTED MEMBERS - DISPLAY MODEL:
193  //-----------------------------------------------------------------------
194 
195 protected:
196 
199 
200 
201  //-----------------------------------------------------------------------
202  // PROTECTED VIRTUAL METHODS:
203  //-----------------------------------------------------------------------
204 
205 protected:
206 
208  virtual void renderLightSource(cRenderOptions& a_options);
209 
211  virtual void render(cRenderOptions& a_options);
212 };
213 
214 //------------------------------------------------------------------------------
215 } // namespace chai3d
216 //------------------------------------------------------------------------------
217 
218 //------------------------------------------------------------------------------
219 #endif
220 //------------------------------------------------------------------------------
221 
This structures provide a containers for storing rendering options that are passed through the sceneg...
Definition: CRenderOptions.h:82
GLfloat m_cutOffAngleDeg
Cut off angle (for spot lights only). Only values in the range 0 to 90 degrees.
Definition: CSpotLight.h:175
double m_shadowNearClippingPlane
Shadow map near clipping plane.
Definition: CSpotLight.h:185
Implements a directional light source.
void setShadowMapProperties(const double &a_nearClippingPlane, const double &a_farClippingPlane)
This method define the near and far clipping planes of the shadow map.
Definition: CSpotLight.cpp:333
cShadowMap * m_shadowMap
Shadow map.
Definition: CSpotLight.h:121
void setDisplaySettings(const double &a_sourceRadius=0.02, const double &a_coneLength=1.0, const bool a_displayEnabled=true)
This method sets the display settings of light source. To be used for debugging purposes to display l...
Definition: CSpotLight.cpp:198
bool updateShadowMap(const double a_mirrorH=1.0, const double a_mirrorV=1.0, const int a_displayContext=0)
This method updates the shadow map.
Definition: CSpotLight.cpp:296
cColorf m_displayConeColor
Color used for rendering the light cone of the display model.
Definition: CSpotLight.h:162
GLfloat getCutOffAngleDeg() const
This method returns the cut off angle.
Definition: CSpotLight.h:140
Implements a positional light source.
void setCutOffAngleDeg(const GLfloat &a_angleDeg)
This method sets the cutoff angle in degrees (only affects spotlights) (positional lights with angula...
Definition: CSpotLight.cpp:109
This class implements a virtual world.
Definition: CWorld.h:92
This class implements a spot light source.
Definition: CSpotLight.h:77
bool getShadowMapEnabled() const
This method returns true if the shadow map is enabled, false otherwise.
Definition: CSpotLight.cpp:364
This class implements a positional light source.
Definition: CPositionalLight.h:76
virtual void render(cRenderOptions &a_options)
This method renders a graphical representation (display model) of the light source. (used for debuging purposes typically).
Definition: CSpotLight.cpp:217
void setSpotExponent(const GLfloat &a_value)
This method sets the concentration level of the light (0.0 - 100.0).
Definition: CSpotLight.h:131
GLfloat getSpotExponent() const
This method returns the concentration level of the light.
Definition: CSpotLight.h:134
This class implements a shadow map for spot lights (cSpotLight).
Definition: CShadowMap.h:76
This class defines a color using a GLfloat representation for each component.
Definition: CColor.h:138
virtual void renderLightSource(cRenderOptions &a_options)
This method renders the lighting properties of this light source in OpenGL.
Definition: CSpotLight.cpp:123
virtual ~cSpotLight()
Destructor of cSpotLight.
Definition: CSpotLight.cpp:94
T cClamp(const T &a_value, const T &a_low, const T &a_high)
This function clamps a value to a specified range.
Definition: CMaths.h:362
Definition: CAudioBuffer.cpp:56
cSpotLight(cWorld *a_world)
Constructor of cSpotLight.
Definition: CSpotLight.cpp:67
This class implements a directional light source.
Definition: CDirectionalLight.h:81
void setShadowMapEnabled(const bool a_enabled)
This method enables of disables the shadow map.
Definition: CSpotLight.cpp:348
double m_shadowFarClippingPlane
Shadow map far clipping plane.
Definition: CSpotLight.h:188
double m_displayConeLength
Length of light cone for display model.
Definition: CSpotLight.h:198
GLfloat m_spotExponent
Concentration of the light.
Definition: CSpotLight.h:172