Visualization Library v1.0.3A lightweight C++ OpenGL middleware for 2D/3D graphics |
[Download] [Tutorials] [All Classes] [Grouped Classes] |
00001 /**************************************************************************************/ 00002 /* */ 00003 /* Visualization Library */ 00004 /* http://visualizationlibrary.org */ 00005 /* */ 00006 /* Copyright (c) 2005-2010, Michele Bosi */ 00007 /* All rights reserved. */ 00008 /* */ 00009 /* Redistribution and use in source and binary forms, with or without modification, */ 00010 /* are permitted provided that the following conditions are met: */ 00011 /* */ 00012 /* - Redistributions of source code must retain the above copyright notice, this */ 00013 /* list of conditions and the following disclaimer. */ 00014 /* */ 00015 /* - Redistributions in binary form must reproduce the above copyright notice, this */ 00016 /* list of conditions and the following disclaimer in the documentation and/or */ 00017 /* other materials provided with the distribution. */ 00018 /* */ 00019 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND */ 00020 /* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ 00021 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */ 00022 /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR */ 00023 /* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */ 00024 /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */ 00025 /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */ 00026 /* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */ 00027 /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */ 00028 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 00029 /* */ 00030 /**************************************************************************************/ 00031 00032 #ifndef Light_INCLUDE_ONCE 00033 #define Light_INCLUDE_ONCE 00034 00035 #include <vlGraphics/link_config.hpp> 00036 #include <vlCore/Vector4.hpp> 00037 #include <vlCore/Transform.hpp> 00038 #include <vlGraphics/RenderState.hpp> 00039 00040 namespace vl 00041 { 00042 //------------------------------------------------------------------------------ 00043 // Light 00044 //------------------------------------------------------------------------------ 00051 class VLGRAPHICS_EXPORT Light: public RenderStateIndexed 00052 { 00053 VL_INSTRUMENT_CLASS(vl::Light, RenderStateIndexed) 00054 00055 public: 00056 Light(); 00057 00058 virtual ERenderState type() const { return RS_Light; } 00059 00060 virtual void apply(int index, const Camera*, OpenGLContext* ctx) const; 00061 00062 void setAmbient(const fvec4& ambientcolor) { mAmbient = ambientcolor; } 00063 const fvec4& ambient() const { return mAmbient; } 00064 00065 void setDiffuse(const fvec4& diffusecolor) { mDiffuse = diffusecolor; } 00066 const fvec4& diffuse() const { return mDiffuse; } 00067 00068 void setSpecular(const fvec4& specularcolor) { mSpecular = specularcolor; } 00069 const fvec4& specular() const { return mSpecular; } 00070 00077 void setPosition(const fvec4& position) { mPosition = position; } 00079 const fvec4& position() const { return mPosition; } 00080 00081 void setSpotDirection(const fvec3& spotdirection) { mSpotDirection = spotdirection; } 00082 const fvec3& spotDirection() const { return mSpotDirection; } 00083 00084 void setSpotExponent(float spotexponent) { mSpotExponent = spotexponent; } 00085 float spotExponent() const { return mSpotExponent; } 00086 00088 void setSpotCutoff(float spotcutoff) { mSpotCutoff = spotcutoff; } 00090 float spotCutoff() const { return mSpotCutoff; } 00091 00095 void setLinearAttenuation(float linearattenuation) { mLinearAttenuation = linearattenuation; } 00096 float linearAttenuation() const { return mLinearAttenuation; } 00097 00101 void setQuadraticAttenuation(float quadraticattenuation) { mQuadraticAttenuation = quadraticattenuation; } 00102 float quadraticAttenuation() const { return mQuadraticAttenuation; } 00103 00107 void setConstantAttenuation(float constantattenuation) { mConstantAttenuation = constantattenuation; } 00108 float constantAttenuation() const { return mConstantAttenuation; } 00109 00111 void bindTransform(Transform* transform); 00112 00113 Transform* boundTransform(); 00114 00115 const Transform* boundTransform() const; 00116 00117 virtual ref<RenderState> clone() const 00118 { 00119 ref<Light> rs = new Light; 00120 *rs = *this; 00121 return rs; 00122 } 00123 00124 void setEnabled(bool enabled) { mEnabled = enabled; } 00125 00126 bool enabled() const { return mEnabled; } 00127 00128 protected: 00129 fvec4 mAmbient; 00130 fvec4 mDiffuse; 00131 fvec4 mSpecular; 00132 fvec4 mPosition; 00133 fvec3 mSpotDirection; 00134 float mSpotExponent; 00135 float mSpotCutoff; 00136 float mConstantAttenuation; 00137 float mLinearAttenuation; 00138 float mQuadraticAttenuation; 00139 ref<Transform> mBoundTransform; 00140 bool mEnabled; 00141 }; 00142 } 00143 00144 #endif