Cinder  0.8.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DxLight.h
Go to the documentation of this file.
1 // The copyright in this software is being made available under the BSD License, included below.
2 // This software may be subject to other third party and contributor rights, including patent rights,
3 // and no such rights are granted under this license.
4 //
5 // Copyright (c) 2013, Microsoft Open Technologies, Inc.
6 // All rights reserved.
7 //
8 // Redistribution and use in source and binary forms, with or without modification,
9 // are permitted provided that the following conditions are met:
10 //
11 // - Redistributions of source code must retain the above copyright notice,
12 // this list of conditions and the following disclaimer.
13 // - Redistributions in binary form must reproduce the above copyright notice,
14 // this list of conditions and the following disclaimer in the documentation
15 // and/or other materials provided with the distribution.
16 // - Neither the name of Microsoft Open Technologies, Inc. nor the names of its contributors
17 // may be used to endorse or promote products derived from this software
18 // without specific prior written permission.
19 //
20 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES,
21 // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23 // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27 // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 
29 
30 #pragma once
31 
32 #include "cinder/Color.h"
33 #include "cinder/dx/dx.h"
34 #include "cinder/Vector.h"
35 #include "cinder/Camera.h"
36 
37 namespace cinder {
38 namespace dx {
39 
40 class Light {
41  public:
42  Light( int aType, int aID ) : mType( aType ), mID( aID ), mEnabled( false ) { setDefaults(); }
43 
44  void setAmbient( const Color &aAmbient );
45  void setDiffuse( const Color &aDiffuse );
46  void setSpecular( const Color &aSpecular );
47 
48  void lookAt( const Vec3f &eye, const Vec3f &target );
49  void setDirection( const Vec3f &aDirection );
50  Vec3f getPosition() const { return mPosition; }
51  void setPosition( const Vec3f &aPosition );
52 
53  void setAttenuation( float aConstantAttenuation, float aLinearAttenuation = 1.0f, float aQuadraticAttenuation = 1.0f );
54  void setConstantAttenuation( float aConstantAttenuation );
55  void setLinearAttenuation( float aLinearAttenuation );
56  void setQuadraticAttenuation( float aQuadraticAttenuation );
57 
58  void setSpotExponent( float aSpotExponent );
59  void setSpotCutoff( float aSpotCutoff );
60 
61  int getType() const { return mType; }
62  int getId() const { return mID; }
63  bool enabled() const { return mEnabled; }
64  const Color &getAmbient() const { return mAmbient; }
65  const Color &getDiffuse() const { return mDiffuse; }
66  const Color &getSpecular() const { return mSpecular; }
67  const Vec3f &getRelativePosition() const { return mRelativePos; }
68  const Vec3f &getRelativeDirection() const { return mRelativeDir; }
69  float getSpotExponent() const { return mSpotExponent; }
70  float getSpotCutoff() const { return mSpotCutoff; }
71  float getConstantAtt() const { return mConstantAttenuation; }
72  float getLinearAtt() const { return mLinearAttenuation; }
73  float getQuadraticAtt() const { return mQuadraticAttenuation; }
74 
75  void enable();
76  void disable();
77  void update( const Camera &relativeCamera );
78 
79  void setShadowParams( float aShadowFOV, float aShadowNear, float aShadowFar );
80  void setShadowRenderMatrices() const;
81  Matrix44f getShadowTransformationMatrix( const Camera &camera ) const;
82  const CameraPersp& getShadowCamera() const { return mShadowCam; }
83 
85 
86  protected:
87  void setDefaults();
88 
89  int mType;
90  int mID;
91  bool mEnabled;
97 
100 };
101 
102 } // namespace dx
103 } // namespace cinder
void setPosition(const Vec3f &aPosition)
Definition: DxLight.cpp:69
int getType() const
Definition: DxLight.h:61
void setDiffuse(const Color &aDiffuse)
Definition: DxLight.cpp:47
void lookAt(const Vec3f &eye, const Vec3f &target)
Definition: DxLight.cpp:57
void setSpecular(const Color &aSpecular)
Definition: DxLight.cpp:52
float mShadowFar
Definition: DxLight.h:99
void setSpotExponent(float aSpotExponent)
Definition: DxLight.cpp:90
Definition: DxLight.h:84
void setAttenuation(float aConstantAttenuation, float aLinearAttenuation=1.0f, float aQuadraticAttenuation=1.0f)
Definition: DxLight.cpp:35
Definition: DxLight.h:84
int mType
Definition: DxLight.h:89
void setDirection(const Vec3f &aDirection)
Definition: DxLight.cpp:63
float mShadowNear
Definition: DxLight.h:99
float mQuadraticAttenuation
Definition: DxLight.h:96
float mShadowFOV
Definition: DxLight.h:99
float mSpotExponent
Definition: DxLight.h:95
Light(int aType, int aID)
Definition: DxLight.h:42
GLenum target
Definition: GLee.h:13607
int mID
Definition: DxLight.h:90
Definition: Camera.h:36
int getId() const
Definition: DxLight.h:62
bool mEnabled
Definition: DxLight.h:91
Color mAmbient
Definition: DxLight.h:92
void update(const Camera &relativeCamera)
Definition: DxLight.cpp:113
const Color & getAmbient() const
Definition: DxLight.h:64
const Color & getSpecular() const
Definition: DxLight.h:66
const Vec3f & getRelativeDirection() const
Definition: DxLight.h:68
Vec3f getPosition() const
Definition: DxLight.h:50
float getQuadraticAtt() const
Definition: DxLight.h:73
void setShadowRenderMatrices() const
Definition: DxLight.cpp:136
float getSpotExponent() const
Definition: DxLight.h:69
Vec3f mPosition
Definition: DxLight.h:93
float mLinearAttenuation
Definition: DxLight.h:96
Definition: DxLight.h:40
float getConstantAtt() const
Definition: DxLight.h:71
Type
Definition: DxLight.h:84
Color mDiffuse
Definition: DxLight.h:92
float mConstantAttenuation
Definition: DxLight.h:96
float getLinearAtt() const
Definition: DxLight.h:72
CameraPersp mShadowCam
Definition: DxLight.h:98
void setShadowParams(float aShadowFOV, float aShadowNear, float aShadowFar)
Definition: DxLight.cpp:128
Vec3f mDirection
Definition: DxLight.h:93
void enable()
Definition: DxLight.cpp:100
Vec3f mRelativePos
Definition: DxLight.h:94
const CameraPersp & getShadowCamera() const
Definition: DxLight.h:82
float getSpotCutoff() const
Definition: DxLight.h:70
void setAmbient(const Color &aAmbient)
Definition: DxLight.cpp:42
Definition: Camera.h:133
void setLinearAttenuation(float aLinearAttenuation)
Definition: DxLight.cpp:80
const Vec3f & getRelativePosition() const
Definition: DxLight.h:67
void setConstantAttenuation(float aConstantAttenuation)
Definition: DxLight.cpp:75
int int int * dx
Definition: GLee.h:17162
Color mSpecular
Definition: DxLight.h:92
void setSpotCutoff(float aSpotCutoff)
Definition: DxLight.cpp:95
Matrix44f getShadowTransformationMatrix(const Camera &camera) const
Definition: DxLight.cpp:141
bool enabled() const
Definition: DxLight.h:63
void setDefaults()
Definition: DxLight.cpp:154
float mSpotCutoff
Definition: DxLight.h:95
void setQuadraticAttenuation(float aQuadraticAttenuation)
Definition: DxLight.cpp:85
GLclampf f
Definition: GLee.h:15307
const Color & getDiffuse() const
Definition: DxLight.h:65
void disable()
Definition: DxLight.cpp:108
Vec3f mRelativeDir
Definition: DxLight.h:94
Definition: DxLight.h:84