1 /*
2 This file is part of Caelum.
3 See http://www.ogre3d.org/wiki/index.php/Caelum
4 
5 Copyright (c) 2008 Caelum team. See Contributors.txt for details.
6 
7 Caelum is free software: you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published
9 by the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Caelum is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU Lesser General Public License for more details.
16 
17 You should have received a copy of the GNU Lesser General Public License
18 along with Caelum. If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 #ifndef CAELUM__SKYLIGHT_H
22 #define CAELUM__SKYLIGHT_H
23 
24 #include "CameraBoundElement.h"
25 
26 namespace Caelum
27 {
28     /** Base class for sky lights (sun and moon).
29      *  Contains a directional light which can be automatically disabled when too dim.
30      */
31     class CAELUM_EXPORT BaseSkyLight : public CameraBoundElement
32     {
33 	protected:
34 		/// The main directional light.
35 		Ogre::Light *mMainLight;
36 
37 		/// The sun scene node.
38 		Ogre::SceneNode *mNode;
39 
40 		/// Base distance of the light.
41 		float mRadius;
42 
43 		/// The latest normalised sun direction.
44 		Ogre::Vector3 mDirection;
45 
46 		/// Body sphere colour, as set by setBodyColour
47 		Ogre::ColourValue mBodyColour;
48 
49 		/// Sun light colour, as set by setLightColour
50 		Ogre::ColourValue mLightColour;
51 
52 		/// Colour multiplier for light diffuse colour.
53 		Ogre::ColourValue mDiffuseMultiplier;
54 
55 		/// Colour multiplier for light specular colour.
56 		Ogre::ColourValue mSpecularMultiplier;
57 
58 		/** Colour multiplier for ambient light colour.
59 		 *  No effect, this value is only stored here.
60 		 */
61 		Ogre::ColourValue mAmbientMultiplier;
62 
63         /// If the light is automatically disabled beneath mAutoDisableThreshold
64         bool mAutoDisableLight;
65 
66         /// Threshold beneath which the light is automatically disabled.
67         Ogre::Real mAutoDisableThreshold;
68 
69         /// If the light is always disabled. Separate from the mAutoDisable mechanism.
70         bool mForceDisableLight;
71 
72 	public:
73 		/** Constructor.
74 			@param sceneMgr The scene manager where the lights will be created.
75             @param caelumRootNode Root node to attach to. Should be bound to the camera.
76 		 */
77 		BaseSkyLight (
78                 Ogre::SceneManager *sceneMgr,
79                 Ogre::SceneNode *caelumRootNode);
80 
81 		/// Destructor.
82 		virtual ~BaseSkyLight () = 0;
83 
84 		/** Updates skylight parameters.
85 		 *  @param direction Light direction.
86 		 *  @param lightColour Color for the light source
87 		 *  @param bodyColour Color to draw the body of the light (whatever that is).
88 		 */
89         virtual void update (
90                 const Ogre::Vector3& direction,
91                 const Ogre::ColourValue &lightColour,
92                 const Ogre::ColourValue &bodyColour);
93 
94 		/// Retrieves the latest light direction.
95 		const Ogre::Vector3 getLightDirection () const;
96 
97 		/// Set the sun direction.
98 		virtual void setLightDirection (const Ogre::Vector3 &dir);
99 
100 		/// Get current body colour, as set in setBodyColour.
101 		const Ogre::ColourValue getBodyColour () const;
102 
103 		/// Sets the colour to draw the light's body with.
104 		virtual void setBodyColour (const Ogre::ColourValue &colour);
105 
106 		/// Get current light colour, as set in setLightColour.
107 		const Ogre::ColourValue getLightColour () const;
108 
109 		/// Sets the skylight colour.
110 		virtual void setLightColour (const Ogre::ColourValue &colour);
111 
112 		/// Set diffuse multiplier for light colour
113 		void setDiffuseMultiplier (const Ogre::ColourValue &diffuse);
114 
115 		/// Set diffuse multiplier for light colour
116 		const Ogre::ColourValue getDiffuseMultiplier () const;
117 
118 		/// Set specular multiplier for light colour
119 		void setSpecularMultiplier (const Ogre::ColourValue &specular);
120 
121 		/// Set specular multiplier for light colour
122 		const Ogre::ColourValue getSpecularMultiplier () const;
123 
124 		/// Set ambient multiplier for light colour
125 		/// This value is only stored here; the SceneManager is not touched
126         /// However, CaelumSystem does use this value.
127 		void setAmbientMultiplier (const Ogre::ColourValue &ambient);
128 
129 		/// Set ambient multiplier for light colour
130 		const Ogre::ColourValue getAmbientMultiplier () const;
131 
132 		/// Direct access to the Ogre::Light.
133 		Ogre::Light* getMainLight() const;
134 
135         /// Check if the light is automatically disabled.
getAutoDisable()136         inline bool getAutoDisable() const { return mAutoDisableLight; }
137 
138         /** Turn on and off auto-disabling of the light when too dim.
139          *  This is off by default. If you set it to true you probably also want to
140          *  set the autoDisableThreshold.
141          *  The "intensity" of the light for the threshold is calculated as the plain sum of r, g and b.
142          */
setAutoDisable(bool value)143         inline void setAutoDisable(bool value) { mAutoDisableLight = value; }
144 
145         /// Get the auto-disable threshold.
getAutoDisableThreshold()146         inline Ogre::Real getAutoDisableThreshold() const { return mAutoDisableThreshold; }
147 
148         /// Set the auto-disable threshold.
setAutoDisableThreshold(Ogre::Real value)149         inline void setAutoDisableThreshold(Ogre::Real value) { mAutoDisableThreshold = value; }
150 
151         static const Ogre::Real DEFAULT_AUTO_DISABLE_THRESHOLD;
152 
153         /// Disable the light by force; without taking intensity into account.
setForceDisable(bool value)154         inline void setForceDisable(bool value) { mForceDisableLight = value; }
getForceDisable()155         inline bool getForceDisable() const { return mForceDisableLight; }
156 
157         virtual void setQueryFlags (uint flags) = 0;
158         virtual uint getQueryFlags () const = 0;
159         virtual void setVisibilityFlags (uint flags) = 0;
160         virtual uint getVisibilityFlags () const = 0;
161 
162     protected:
163         /// Handle far radius.
164 	    virtual void setFarRadius (Ogre::Real radius);
165 
166 		/// Temporary change main light color
167 		void setMainLightColour(const Ogre::ColourValue &colour);
168 
169         /// If the light should be enabled for a certain value.
170         /// This functions takes AutoDisable and such into account.
171         bool shouldEnableLight(const Ogre::ColourValue &colour);
172     };
173 }
174 
175 #endif // CAELUM__SKYLIGHT_H
176