Visualization Library 2.1.0

A lightweight C++ OpenGL middleware for 2D/3D graphics

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
Light.hpp
Go to the documentation of this file.
1 /**************************************************************************************/
2 /* */
3 /* Visualization Library */
4 /* http://visualizationlibrary.org */
5 /* */
6 /* Copyright (c) 2005-2020, Michele Bosi */
7 /* All rights reserved. */
8 /* */
9 /* Redistribution and use in source and binary forms, with or without modification, */
10 /* are permitted provided that the following conditions are met: */
11 /* */
12 /* - Redistributions of source code must retain the above copyright notice, this */
13 /* list of conditions and the following disclaimer. */
14 /* */
15 /* - Redistributions in binary form must reproduce the above copyright notice, this */
16 /* list of conditions and the following disclaimer in the documentation and/or */
17 /* other materials provided with the distribution. */
18 /* */
19 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND */
20 /* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */
21 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
22 /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR */
23 /* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
24 /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
25 /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
26 /* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
27 /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
28 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
29 /* */
30 /**************************************************************************************/
31 
32 #ifndef Light_INCLUDE_ONCE
33 #define Light_INCLUDE_ONCE
34 
36 #include <vlCore/Vector4.hpp>
37 #include <vlCore/Transform.hpp>
39 
40 namespace vl
41 {
42  //------------------------------------------------------------------------------
43  // Light
44  //------------------------------------------------------------------------------
52  {
54 
55  public:
56  Light();
57 
58  virtual ERenderState type() const { return RS_Light; }
59 
60  virtual void apply(int index, const Camera*, OpenGLContext* ctx) const;
61 
62  void setAmbient(const fvec4& ambientcolor) { mAmbient = ambientcolor; }
63  const fvec4& ambient() const { return mAmbient; }
64 
65  void setDiffuse(const fvec4& diffusecolor) { mDiffuse = diffusecolor; }
66  const fvec4& diffuse() const { return mDiffuse; }
67 
68  void setSpecular(const fvec4& specularcolor) { mSpecular = specularcolor; }
69  const fvec4& specular() const { return mSpecular; }
70 
77  void setPosition(const fvec4& position) { mPosition = position; }
79  const fvec4& position() const { return mPosition; }
80 
81  void setSpotDirection(const fvec3& spotdirection) { mSpotDirection = spotdirection; }
82  const fvec3& spotDirection() const { return mSpotDirection; }
83 
84  void setSpotExponent(float spotexponent) { mSpotExponent = spotexponent; }
85  float spotExponent() const { return mSpotExponent; }
86 
88  void setSpotCutoff(float spotcutoff) { mSpotCutoff = spotcutoff; }
90  float spotCutoff() const { return mSpotCutoff; }
91 
95  void setLinearAttenuation(float linearattenuation) { mLinearAttenuation = linearattenuation; }
96  float linearAttenuation() const { return mLinearAttenuation; }
97 
101  void setQuadraticAttenuation(float quadraticattenuation) { mQuadraticAttenuation = quadraticattenuation; }
102  float quadraticAttenuation() const { return mQuadraticAttenuation; }
103 
107  void setConstantAttenuation(float constantattenuation) { mConstantAttenuation = constantattenuation; }
108  float constantAttenuation() const { return mConstantAttenuation; }
109 
111  void bindTransform(Transform* transform);
112 
113  Transform* boundTransform();
114 
115  const Transform* boundTransform() const;
116 
117  virtual ref<RenderState> clone() const
118  {
119  ref<Light> rs = new Light;
120  *rs = *this;
121  return rs;
122  }
123 
124  void setEnabled(bool enabled) { mEnabled = enabled; }
125 
126  bool enabled() const { return mEnabled; }
127 
128  protected:
135  float mSpotCutoff;
140  bool mEnabled;
141  };
142 }
143 
144 #endif
float mConstantAttenuation
Definition: Light.hpp:136
Implements a 4x4 matrix transform used to define the position and orientation of an Actor...
Definition: Transform.hpp:72
ERenderState
float spotCutoff() const
Valid values are from 0.0f to 90.0f plus the special value 180.0f (default) which disables the spot l...
Definition: Light.hpp:90
float mLinearAttenuation
Definition: Light.hpp:137
Represents an OpenGL context, possibly a widget or a pbuffer, which can also respond to keyboard...
Base class for those render states which have more than one binding points like lights, clipping planes and texture unit states.
Definition: RenderState.hpp:70
float linearAttenuation() const
Definition: Light.hpp:96
void setPosition(const fvec4 &position)
The position or direction of a light.
Definition: Light.hpp:77
float constantAttenuation() const
Definition: Light.hpp:108
void setSpecular(const fvec4 &specularcolor)
Definition: Light.hpp:68
void setLinearAttenuation(float linearattenuation)
If the light is positional, rather than directional, its intensity is attenuated by the reciprocal of...
Definition: Light.hpp:95
void setDiffuse(const fvec4 &diffusecolor)
Definition: Light.hpp:65
#define VL_INSTRUMENT_CLASS(ClassName, BaseClass)
Definition: TypeInfo.hpp:122
void setSpotCutoff(float spotcutoff)
Valid values are from 0.0f to 90.0f plus the special value 180.0f (default) which disables the spot l...
Definition: Light.hpp:88
float mSpotCutoff
Definition: Light.hpp:135
const fvec3 & spotDirection() const
Definition: Light.hpp:82
Visualization Library main namespace.
const fvec4 & diffuse() const
Definition: Light.hpp:66
fvec4 mSpecular
Definition: Light.hpp:131
float quadraticAttenuation() const
Definition: Light.hpp:102
float mSpotExponent
Definition: Light.hpp:134
fvec4 mPosition
Definition: Light.hpp:132
void setConstantAttenuation(float constantattenuation)
If the light is positional, rather than directional, its intensity is attenuated by the reciprocal of...
Definition: Light.hpp:107
fvec4 mDiffuse
Definition: Light.hpp:130
fvec3 mSpotDirection
Definition: Light.hpp:133
bool enabled() const
Definition: Light.hpp:126
ref< Transform > mBoundTransform
Definition: Light.hpp:139
virtual ERenderState type() const
Definition: Light.hpp:58
void setQuadraticAttenuation(float quadraticattenuation)
If the light is positional, rather than directional, its intensity is attenuated by the reciprocal of...
Definition: Light.hpp:101
void setSpotExponent(float spotexponent)
Definition: Light.hpp:84
void setEnabled(bool enabled)
Definition: Light.hpp:124
void setSpotDirection(const fvec3 &spotdirection)
Definition: Light.hpp:81
const fvec4 & specular() const
Definition: Light.hpp:69
const fvec4 & position() const
The position or direction of a light.
Definition: Light.hpp:79
fvec4 mAmbient
Definition: Light.hpp:129
Wraps the OpenGL function glLight().
Definition: Light.hpp:51
bool mEnabled
Definition: Light.hpp:140
The ref<> class is used to reference-count an Object.
Definition: Object.hpp:55
float spotExponent() const
Definition: Light.hpp:85
Represents a virtual camera defining, among other things, the point of view from which scenes can be ...
Definition: Camera.hpp:49
virtual ref< RenderState > clone() const
Definition: Light.hpp:117
float mQuadraticAttenuation
Definition: Light.hpp:138
const fvec4 & ambient() const
Definition: Light.hpp:63
void setAmbient(const fvec4 &ambientcolor)
Definition: Light.hpp:62