MercuryLight.h

Go to the documentation of this file.
00001 #ifndef MERCURYLIGHT_H
00002 #define MERCURYLIGHT_H
00003 
00004 //#include "global.h"
00005 #include "MercuryObject.h"
00006 
00008 struct Attenuation
00009 {
00010     enum Type
00011     {
00012         CONSTANT = 0,
00013         LINEAR,
00014         QUADRATIC
00015     };
00016 
00017     //0 is default for most types of attenuations
00018     //except const where 1 is.
00019     Attenuation()
00020         :type(CONSTANT), value(0)
00021     {}
00022 
00023     Type type;
00024     float value;
00025 };
00026 
00027 enum LightType
00028 {
00029     LT_DIRECTIONAL = 0,
00030     LT_POINT = 1,
00031 };
00032 
00034 class MercuryLight : public MercuryObject
00035 {
00036 public:
00037     MercuryLight();
00038     virtual ~MercuryLight();
00039 
00040     virtual void Init();
00041 
00042     //Attenuations
00043     void SetAttenuation(float value, Attenuation::Type type = Attenuation::CONSTANT);
00044     inline const Attenuation& GetAttenuation(Attenuation::Type type) const { return m_attenuation[type]; }
00045 
00046     inline void SetStatic(bool toggle) { m_static = toggle; }
00047     inline bool IsStatic() const { return m_static; }
00048 
00049     inline void SetLightType( LightType pLT ) { m_pLT = pLT; }
00050     inline LightType GetLightType() const { return m_pLT; } 
00051 
00052     inline void SetColors(const MercuryMaterial& c) { m_colors = c; }
00053     virtual void Draw() {};
00054     virtual void Render() {};
00055 
00056     CLASS_RTTI( MercuryLight, MercuryObject );
00057 
00058     float ComputeBrightnessFromDistance(const MercuryPoint& objectPos) const;
00059     void ComputeRadius();
00060     inline float GetRadius() const { return m_radius; }
00061 private:
00062     //Lights use ambient diffuse and specular colors.
00063 
00064     LightType   m_pLT;
00065 
00066     MercuryMaterial m_colors;
00067 
00068     //supports multiple attenuations
00069     Attenuation m_attenuation[3];
00070     bool m_static;
00071 
00072     float m_radius;
00073 };
00074 
00075 #endif
00076 
00077 /* 
00078  * Copyright (c) 2005-2006, Joshua Allen
00079  * All rights reserved.
00080  *
00081  * Redistribution and use in source and binary forms, with or
00082  * without modification, are permitted provided that the following
00083  * conditions are met:
00084  *  -   Redistributions of source code must retain the above
00085  *      copyright notice, this list of conditions and the following disclaimer.
00086  *  -   Redistributions in binary form must reproduce the above copyright
00087  *      notice, this list of conditions and the following disclaimer in
00088  *      the documentation and/or other materials provided with the distribution.
00089  *  -   Neither the name of the Mercury Engine nor the names of its
00090  *      contributors may be used to endorse or promote products derived from
00091  *      this software without specific prior written permission.
00092  *
00093  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00094  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00095  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00096  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
00097  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00098  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00099  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00100  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00101  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00102  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00103  */

Hosted by SourceForge.net Logo