Cinder  0.8.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Light.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2010, The Barbarian Group
3  All rights reserved.
4 
5  Redistribution and use in source and binary forms, with or without modification, are permitted provided that
6  the following conditions are met:
7 
8  * Redistributions of source code must retain the above copyright notice, this list of conditions and
9  the following disclaimer.
10  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
11  the following disclaimer in the documentation and/or other materials provided with the distribution.
12 
13  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
14  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
15  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
16  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
17  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
18  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
19  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
20  POSSIBILITY OF SUCH DAMAGE.
21 */
22 
23 #pragma once
24 
25 #include "cinder/Color.h"
26 #include "cinder/gl/gl.h"
27 #include "cinder/Vector.h"
28 #include "cinder/Camera.h"
29 
30 namespace cinder {
31 namespace gl {
32 
33 class Light {
34  public:
35  Light( int aType, int aID ) : mType( aType ), mID( aID ), mEnabled( false ) { setDefaults(); }
36 
37  void setAmbient( const Color &aAmbient );
38  void setDiffuse( const Color &aDiffuse );
39  void setSpecular( const Color &aSpecular );
40 
41  void lookAt( const Vec3f &eye, const Vec3f &target );
42  void setDirection( const Vec3f &aDirection );
43  Vec3f getPosition() const { return mPosition; }
44  void setPosition( const Vec3f &aPosition );
45 
46  void setAttenuation( float aConstantAttenuation, float aLinearAttenuation = 1.0f, float aQuadraticAttenuation = 1.0f );
47  void setConstantAttenuation( float aConstantAttenuation );
48  void setLinearAttenuation( float aLinearAttenuation );
49  void setQuadraticAttenuation( float aQuadraticAttenuation );
50 
51  void setSpotExponent( float aSpotExponent );
52  void setSpotCutoff( float aSpotCutoff );
53 
54  void enable();
55  void disable();
56  void update( const Camera &relativeCamera ) const;
57 
58  void setShadowParams( float aShadowFOV, float aShadowNear, float aShadowFar );
59  void setShadowRenderMatrices() const;
60  Matrix44f getShadowTransformationMatrix( const Camera &camera ) const;
61  const CameraPersp& getShadowCamera() const { return mShadowCam; }
62 
64 
65  protected:
66  void setDefaults();
67 
68  int mType;
69  int mID;
70  bool mEnabled;
75 
78 };
79 
80 } // namespace gl
81 } // namespace cinder
float mQuadraticAttenuation
Definition: Light.h:74
void setDefaults()
Definition: Light.cpp:180
void setShadowRenderMatrices() const
Definition: Light.cpp:162
CameraPersp mShadowCam
Definition: Light.h:76
float mLinearAttenuation
Definition: Light.h:74
void lookAt(const Vec3f &eye, const Vec3f &target)
Definition: Light.cpp:53
Vec3f mDirection
Definition: Light.h:72
void setSpecular(const Color &aSpecular)
Definition: Light.cpp:47
Definition: Light.h:63
float mShadowNear
Definition: Light.h:77
Definition: Light.h:33
GLenum target
Definition: GLee.h:13607
Definition: Light.h:63
int mID
Definition: Light.h:69
void setQuadraticAttenuation(float aQuadraticAttenuation)
Definition: Light.cpp:87
Color mDiffuse
Definition: Light.h:71
Vec3f mPosition
Definition: Light.h:72
Definition: Camera.h:36
Color mSpecular
Definition: Light.h:71
float mSpotCutoff
Definition: Light.h:73
float mShadowFOV
Definition: Light.h:77
void setDirection(const Vec3f &aDirection)
Definition: Light.cpp:59
void setSpotCutoff(float aSpotCutoff)
Definition: Light.cpp:99
void enable()
Definition: Light.cpp:105
void setLinearAttenuation(float aLinearAttenuation)
Definition: Light.cpp:81
Type
Definition: Light.h:63
const CameraPersp & getShadowCamera() const
Definition: Light.h:61
bool mEnabled
Definition: Light.h:70
void setShadowParams(float aShadowFOV, float aShadowNear, float aShadowFar)
Definition: Light.cpp:154
Definition: Camera.h:133
void setSpotExponent(float aSpotExponent)
Definition: Light.cpp:93
void update(const Camera &relativeCamera) const
Definition: Light.cpp:134
Matrix44f getShadowTransformationMatrix(const Camera &camera) const
Definition: Light.cpp:167
Color mAmbient
Definition: Light.h:71
Light(int aType, int aID)
Definition: Light.h:35
int mType
Definition: Light.h:68
void setAmbient(const Color &aAmbient)
Definition: Light.cpp:35
void setPosition(const Vec3f &aPosition)
Definition: Light.cpp:67
float mShadowFar
Definition: Light.h:77
float mSpotExponent
Definition: Light.h:73
void setAttenuation(float aConstantAttenuation, float aLinearAttenuation=1.0f, float aQuadraticAttenuation=1.0f)
Definition: Light.cpp:28
Definition: Light.h:63
Vec3f getPosition() const
Definition: Light.h:43
void disable()
Definition: Light.cpp:128
GLclampf f
Definition: GLee.h:15307
float mConstantAttenuation
Definition: Light.h:74
void setConstantAttenuation(float aConstantAttenuation)
Definition: Light.cpp:75
void setDiffuse(const Color &aDiffuse)
Definition: Light.cpp:41