Visualization LibraryA lightweight C++ OpenGL middleware for 2D/3D graphics |
[Home] [Tutorials] [All Classes] [Grouped Classes] |
00001 /**************************************************************************************/ 00002 /* */ 00003 /* Visualization Library */ 00004 /* http://www.visualizationlibrary.com */ 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 <vlCore/Vector4.hpp> 00036 #include <vlCore/Transform.hpp> 00037 #include <vlGraphics/link_config.hpp> 00038 #include <vlGraphics/RenderState.hpp> 00039 00040 namespace vl 00041 { 00042 //------------------------------------------------------------------------------ 00043 // Light 00044 //------------------------------------------------------------------------------ 00051 class VLGRAPHICS_EXPORT Light: public RenderState 00052 { 00053 public: 00054 Light(int light_index); 00055 00056 virtual const char* className() { return "vl::Light"; } 00057 00058 virtual ERenderState type() const { return (ERenderState)(RS_Light0 + lightIndex()); } 00059 00060 virtual void apply(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 00110 void setLightIndex(int light_index); 00111 int lightIndex() const { return mLightIndex; } 00112 00114 void followTransform(Transform* transform); 00115 Transform* followedTransform(); 00116 const Transform* followedTransform() const; 00117 00118 protected: 00119 fvec4 mAmbient; 00120 fvec4 mDiffuse; 00121 fvec4 mSpecular; 00122 fvec4 mPosition; 00123 fvec3 mSpotDirection; 00124 float mSpotExponent; 00125 float mSpotCutoff; 00126 float mConstantAttenuation; 00127 float mLinearAttenuation; 00128 float mQuadraticAttenuation; 00129 ref<Transform> mFollowedTransform; 00130 int mLightIndex; 00131 }; 00132 } 00133 00134 #endif