Sirikata
libmesh/include/sirikata/mesh/LightInfo.hpp
Go to the documentation of this file.
00001 /*  Sirikata Utilities -- Sirikata Listener Pattern
00002  *  LightInfo.hpp
00003  *
00004  *  Copyright (c) 2009, Patrick Reiter Horn
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions are
00009  *  met:
00010  *  * Redistributions of source code must retain the above copyright
00011  *    notice, this list of conditions and the following disclaimer.
00012  *  * Redistributions in binary form must reproduce the above copyright
00013  *    notice, this list of conditions and the following disclaimer in
00014  *    the documentation and/or other materials provided with the
00015  *    distribution.
00016  *  * Neither the name of Sirikata nor the names of its contributors may
00017  *    be used to endorse or promote products derived from this software
00018  *    without specific prior written permission.
00019  *
00020  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
00021  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
00022  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
00023  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
00024  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00025  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00026  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00027  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00028  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00029  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00030  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00031  */
00032 
00033 #ifndef _SIRIKATA_LIGHT_INFO_HPP_
00034 #define _SIRIKATA_LIGHT_INFO_HPP_
00035 
00036 #include <sirikata/mesh/Platform.hpp>
00037 
00038 namespace Sirikata {
00039 typedef Vector3f Color;
00040 
00041 struct SIRIKATA_MESH_EXPORT LightInfo {
00042     enum LightTypes {
00043         POINT,SPOTLIGHT,DIRECTIONAL,NUM_TYPES//defaults to point=0?
00044     };
00045     enum Fields {
00046         NONE=0,
00047         DIFFUSE_COLOR=1,
00048         SPECULAR_COLOR=2,
00049         POWER=8,
00050         AMBIENT_COLOR=16,
00051         SHADOW_COLOR=32,
00052         LIGHT_RANGE=64,
00053         FALLOFF=128,
00054         CONE=256,
00055         TYPE=512,
00056         CAST_SHADOW=1024,
00057         ALL=2047
00058     };
00059     int32 mWhichFields;
00060     LightInfo() :
00061         mWhichFields(0),
00062         mDiffuseColor(1.0f,1.0f,1.0f),
00063         mSpecularColor(1.0f,1.0f,1.0f),
00064         mPower(1000.0f),
00065         mAmbientColor(.05f,.05f,.05f),
00066         mShadowColor(.02f,.02f,.02f),
00067         mLightRange(1000.0f),
00068         mConstantFalloff(0.0f),
00069         mLinearFalloff(0.0f),
00070         mQuadraticFalloff(0.0f),
00071         mConeInnerRadians(0.0f),
00072         mConeOuterRadians(3.1415926536f),
00073         mConeFalloff(0.0f),
00074         mType(POINT),
00075         mCastsShadow(true) {
00076     }
00077     Color mDiffuseColor;
00078     Color mSpecularColor;
00079     float32 mPower;
00080     Color mAmbientColor;
00081     Color mShadowColor;
00082     float64 mLightRange;
00083     float32 mConstantFalloff;
00084     float32 mLinearFalloff;
00085     float32 mQuadraticFalloff;
00086     float32 mConeInnerRadians;
00087     float32 mConeOuterRadians;
00088     float32 mConeFalloff;
00089     LightTypes mType;
00090     bool mCastsShadow;
00091     LightInfo& setLightDiffuseColor(const Color&c){
00092         mWhichFields|=DIFFUSE_COLOR;
00093         mDiffuseColor=c;
00094         return *this;
00095     }
00096     LightInfo& setLightSpecularColor(const Color&c) {
00097         mWhichFields|=SPECULAR_COLOR;
00098         mSpecularColor=c;
00099         return *this;
00100     }
00101     LightInfo& setLightPower(float32 c){
00102         mWhichFields|=POWER;
00103         mPower=c;
00104         return *this;
00105     }
00107     LightInfo& setLightAmbientColor(const Color&c){
00108         mWhichFields|=AMBIENT_COLOR;
00109         mAmbientColor=c;
00110         return *this;
00111     }
00113     LightInfo& setLightShadowColor(const Color&c){
00114         mWhichFields|=SHADOW_COLOR;
00115         mShadowColor=c;
00116         return *this;
00117     }
00118     LightInfo& setLightRange(float64 maxRange){
00119         mWhichFields|=LIGHT_RANGE;
00120         mLightRange=maxRange;
00121         return *this;
00122     }
00123     LightInfo& setLightFalloff(float32 constant, float32 linear,float32 quadratic){
00124         mWhichFields|=FALLOFF;
00125         mConstantFalloff=constant;
00126         mLinearFalloff=linear;
00127         mQuadraticFalloff=quadratic;
00128         return *this;
00129     }
00130     LightInfo& setLightSpotlightCone(float32 innerRadians, float32 outerRadians,float32 coneFalloff){
00131         mWhichFields|=CONE;
00132         mConeInnerRadians=innerRadians;
00133         mConeOuterRadians=outerRadians;
00134         mConeFalloff=coneFalloff;
00135         return *this;
00136     }
00137     LightInfo& setLightType(LightTypes type){
00138         mWhichFields|=TYPE;
00139         mType=type;
00140         return *this;
00141     }
00142     LightInfo& setCastsShadow(bool shouldCastShadow){
00143         mWhichFields|=CAST_SHADOW;
00144         mCastsShadow=shouldCastShadow;
00145         return *this;
00146     }
00147 
00148     LightInfo& operator=(const LightInfo&other) {
00149         if (other.mWhichFields&DIFFUSE_COLOR) {
00150             mDiffuseColor=other.mDiffuseColor;
00151             mWhichFields|=DIFFUSE_COLOR;
00152         }
00153         if (other.mWhichFields&SPECULAR_COLOR) {
00154             mSpecularColor=other.mSpecularColor;
00155             mWhichFields|=SPECULAR_COLOR;
00156         }
00157         if (other.mWhichFields&POWER) {
00158             mPower=other.mPower;
00159             mWhichFields|=POWER;
00160         }
00161         if (other.mWhichFields&AMBIENT_COLOR) {
00162             mAmbientColor=other.mAmbientColor;
00163             mWhichFields|=AMBIENT_COLOR;
00164         }
00165         if (other.mWhichFields&SHADOW_COLOR) {
00166             mShadowColor=other.mShadowColor;
00167             mWhichFields|=SHADOW_COLOR;
00168         }
00169         if (other.mWhichFields&LIGHT_RANGE) {
00170             mLightRange=other.mLightRange;
00171             mWhichFields|=LIGHT_RANGE;
00172         }
00173         if (other.mWhichFields&FALLOFF) {
00174             mConstantFalloff=other.mConstantFalloff;
00175             mLinearFalloff=other.mLinearFalloff;
00176             mQuadraticFalloff=other.mQuadraticFalloff;
00177             mWhichFields|=FALLOFF;
00178         }
00179         if (other.mWhichFields&CONE) {
00180             mConeInnerRadians=other.mConeInnerRadians;
00181             mConeOuterRadians=other.mConeOuterRadians;
00182             mConeFalloff=other.mConeFalloff;
00183             mWhichFields|=CONE;
00184         }
00185         if (other.mWhichFields&TYPE) {
00186             mType=other.mType;
00187             mWhichFields|=TYPE;
00188         }
00189         if (other.mWhichFields&CAST_SHADOW) {
00190             mCastsShadow=other.mCastsShadow;
00191             mWhichFields|=CAST_SHADOW;
00192         }
00193         return *this;
00194     }
00195 };
00196 }
00197 
00198 #endif