CPositionalLight.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.2.0 $Rev: 1869 $
41 */
42 //==============================================================================
43 
44 //------------------------------------------------------------------------------
45 #ifndef CPositionalLightH
46 #define CPositionalLightH
47 //------------------------------------------------------------------------------
48 #include "lighting/CGenericLight.h"
49 //--------------------------------------------------------------------------
50 
51 //------------------------------------------------------------------------------
52 namespace chai3d {
53 //------------------------------------------------------------------------------
54 
55 //==============================================================================
62 //==============================================================================
63 
64 //==============================================================================
75 //==============================================================================
76 class cPositionalLight : public virtual cGenericLight
77 {
78  //--------------------------------------------------------------------------
79  // CONSTRUCTOR & DESTRUCTOR:
80  //--------------------------------------------------------------------------
81 
82 public:
83 
85  cPositionalLight(cWorld* a_world);
86 
88  virtual ~cPositionalLight();
89 
90 
91  //-----------------------------------------------------------------------
92  // PUBLIC METHODS - LIGHTING PROPERTIES:
93  //-----------------------------------------------------------------------
94 
95 public:
96 
98  void setAttConstant(const GLfloat& a_value) { m_attConstant = cClamp(a_value, 0.0f, 1.0f); }
99 
101  GLfloat getAttConstant() const { return (m_attConstant); }
102 
104  void setAttLinear(const GLfloat& a_value) { m_attLinear = cClamp(a_value, 0.0f, 1.0f); }
105 
107  GLfloat getAttLinear() const { return (m_attLinear); }
108 
110  void setAttQuadratic(const GLfloat& a_value) { m_attQuadratic = cClamp(a_value, 0.0f, 1.0f); }
111 
113  GLfloat getAttQuadratic() const { return (m_attQuadratic); }
114 
115 
116  //-----------------------------------------------------------------------
117  // METHODS - DISPLAY MODEL:
118  //-----------------------------------------------------------------------
119 
120 public:
121 
123  void setDisplaySettings(const double& a_sourceRadius = 0.02,
124  const bool a_displayEnabled = true);
125 
126 
127  //-----------------------------------------------------------------------
128  // PUBLIC MEMBERS - DISPLAY MODEL
129  //-----------------------------------------------------------------------
130 
131 public:
132 
135 
136 
137  //-----------------------------------------------------------------------
138  // PROTECTED MEMBERS - LIGHTING PROPERTIES:
139  //-----------------------------------------------------------------------
140 
141 protected:
142 
144  GLfloat m_attConstant;
145 
147  GLfloat m_attLinear;
148 
150  GLfloat m_attQuadratic;
151 
152 
153  //-----------------------------------------------------------------------
154  // PROTECTED MEMBERS - DISPLAY MODEL:
155  //-----------------------------------------------------------------------
156 
157 protected:
158 
161 
162 
163  //-----------------------------------------------------------------------
164  // VIRTUAL PROTECTED METHODS:
165  //-----------------------------------------------------------------------
166 
167 protected:
168 
170  virtual void renderLightSource(cRenderOptions& a_options);
171 
173  virtual void render(cRenderOptions& a_options);
174 };
175 
176 
177 //------------------------------------------------------------------------------
178 } // namespace chai3d
179 //------------------------------------------------------------------------------
180 
181 //------------------------------------------------------------------------------
182 #endif
183 //------------------------------------------------------------------------------
184 
Implements a base class for light sources.
This structures provide a containers for storing rendering options that are passed through the sceneg...
Definition: CRenderOptions.h:82
GLfloat getAttLinear() const
This method returns the linear attenuation parameter.
Definition: CPositionalLight.h:107
void setAttQuadratic(const GLfloat &a_value)
This method set the quadratic attenuation parameter.
Definition: CPositionalLight.h:110
void setAttConstant(const GLfloat &a_value)
This method sets the constant attenuation parameter.
Definition: CPositionalLight.h:98
GLfloat getAttConstant() const
This method returns the constant attenuation parameter.
Definition: CPositionalLight.h:101
virtual void render(cRenderOptions &a_options)
This method renders a graphical representation (display model) of the light source. (used for debugging purposes typically).
Definition: CPositionalLight.cpp:111
GLfloat getAttQuadratic() const
This method returns the quadratic attenuation parameter.
Definition: CPositionalLight.h:113
This class implements a base class for modeling light sources.
Definition: CGenericLight.h:79
double m_displaySourceRadius
Radius of display model representing light source.
Definition: CPositionalLight.h:160
This class implements a virtual world.
Definition: CWorld.h:92
void setDisplaySettings(const double &a_sourceRadius=0.02, const bool a_displayEnabled=true)
This method sets the display settings of this light source. (To be used for debugging purposes to dis...
Definition: CPositionalLight.cpp:95
This class implements a positional light source.
Definition: CPositionalLight.h:76
cPositionalLight(cWorld *a_world)
Constructor of cPositionalLight.
Definition: CPositionalLight.cpp:59
GLfloat m_attLinear
Linear attenuation parameter.
Definition: CPositionalLight.h:147
virtual void renderLightSource(cRenderOptions &a_options)
This method renders the lighting properties of this light source in OpenGL.
Definition: CPositionalLight.cpp:145
This class defines a color using a GLfloat representation for each component.
Definition: CColor.h:138
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
cColorf m_displaySourceColor
Color used for rendering the display model of the light source.
Definition: CPositionalLight.h:134
Definition: CAudioBuffer.cpp:56
void setAttLinear(const GLfloat &a_value)
This method sets the linear attenuation parameter.
Definition: CPositionalLight.h:104
GLfloat m_attQuadratic
Quadratic attenuation parameter.
Definition: CPositionalLight.h:150
virtual ~cPositionalLight()
Destructor of cPositionalLight.
Definition: CPositionalLight.cpp:80
GLfloat m_attConstant
Constant attenuation parameter.
Definition: CPositionalLight.h:144