source: GTP/trunk/App/Demos/Geom/OgreStuff/include/OgreLight.h @ 1092

Revision 1092, 15.5 KB checked in by gumbau, 18 years ago (diff)

LodStrips? and LODTrees demos

Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2005 The OGRE Team
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23-----------------------------------------------------------------------------
24*/
25#ifndef _LIGHT_H__
26#define _LIGHT_H__
27
28#include "OgrePrerequisites.h"
29
30#include "OgreColourValue.h"
31#include "OgreVector3.h"
32#include "OgreVector4.h"
33#include "OgreString.h"
34#include "OgreMovableObject.h"
35#include "OgrePlaneBoundedVolume.h"
36
37namespace Ogre {
38
39
40    /** Representation of a dynamic light source in the scene.
41        @remarks
42            Lights are added to the scene like any other object. They contain various
43            parameters like type, position, attenuation (how light intensity fades with
44            distance), colour etc.
45        @par
46            The defaults when a light is created is pure white diffues light, with no
47            attenuation (does not decrease with distance) and a range of 1000 world units.
48        @par
49            Lights are created by using the SceneManager::createLight method. They can subsequently be
50            added to a SceneNode if required to allow them to move relative to a node in the scene. A light attached
51            to a SceneNode is assumed to havea base position of (0,0,0) and a direction of (0,0,1) before modification
52            by the SceneNode's own orientation. If not attached to a SceneNode,
53            the light's position and direction is as set using setPosition and setDirection.
54        @par
55            Remember also that dynamic lights rely on modifying the colour of vertices based on the position of
56            the light compared to an object's vertex normals. Dynamic lighting will only look good if the
57            object being lit has a fair level of tesselation and the normals are properly set. This is particularly
58            true for the spotlight which will only look right on highly tesselated models. In the future OGRE may be
59            extended for certain scene types so an alternative to the standard dynamic lighting may be used, such
60            as dynamic lightmaps.
61    */
62    class _OgreExport Light : public MovableObject
63    {
64    public:
65        /// Temp tag used for sorting
66        Real tempSquareDist;
67
68        /// Defines the type of light
69        enum LightTypes
70        {
71            /// Point light sources give off light equally in all directions, so require only position not direction
72            LT_POINT,
73            /// Directional lights simulate parallel light beams from a distant source, hence have direction but no position
74            LT_DIRECTIONAL,
75            /// Spotlights simulate a cone of light from a source so require position and direction, plus extra values for falloff
76            LT_SPOTLIGHT
77        };
78
79        /** Default constructor (for Python mainly).
80        */
81        Light();
82
83        /** Normal constructor. Should not be called directly, but rather the SceneManager::createLight method should be used.
84        */
85        Light(const String& name);
86
87        /** Standard destructor.
88        */
89        ~Light();
90
91        /** Returns the name of this light (cannot be modified).
92        */
93        const String& getName(void) const;
94
95        /** Sets the type of light - see LightTypes for more info.
96        */
97        void setType(LightTypes type);
98
99        /** Returns the light type.
100        */
101        LightTypes getType(void) const;
102
103        /** Sets the colour of the diffuse light given off by this source.
104            @remarks
105                Material objects have ambient, diffuse and specular values which indicate how much of each type of
106                light an object reflects. This value denotes the amount and colour of this type of light the light
107                exudes into the scene. The actual appearance of objects is a combination of the two.
108            @par
109                Diffuse light simulates the typical light emenating from light sources and affects the base colour
110                of objects together with ambient light.
111        */
112        void setDiffuseColour(Real red, Real green, Real blue);
113
114        /** Sets the colour of the diffuse light given off by this source.
115            @remarks
116                Material objects have ambient, diffuse and specular values which indicate how much of each type of
117                light an object reflects. This value denotes the amount and colour of this type of light the light
118                exudes into the scene. The actual appearance of objects is a combination of the two.
119            @par
120                Diffuse light simulates the typical light emenating from light sources and affects the base colour
121                of objects together with ambient light.
122        */
123        void setDiffuseColour(const ColourValue& colour);
124
125        /** Returns the colour of the diffuse light given off by this light source (see setDiffuseColour for more info).
126        */
127        const ColourValue& getDiffuseColour(void) const;
128
129        /** Sets the colour of the specular light given off by this source.
130            @remarks
131                Material objects have ambient, diffuse and specular values which indicate how much of each type of
132                light an object reflects. This value denotes the amount and colour of this type of light the light
133                exudes into the scene. The actual appearance of objects is a combination of the two.
134            @par
135                Specular light affects the appearance of shiny highlights on objects, and is also dependent on the
136                'shininess' Material value.
137        */
138        void setSpecularColour(Real red, Real green, Real blue);
139
140        /** Sets the colour of the specular light given off by this source.
141            @remarks
142                Material objects have ambient, diffuse and specular values which indicate how much of each type of
143                light an object reflects. This value denotes the amount and colour of this type of light the light
144                exudes into the scene. The actual appearance of objects is a combination of the two.
145            @par
146                Specular light affects the appearance of shiny highlights on objects, and is also dependent on the
147                'shininess' Material value.
148        */
149        void setSpecularColour(const ColourValue& colour);
150
151        /** Returns the colour of specular light given off by this light source.
152        */
153        const ColourValue& getSpecularColour(void) const;
154
155        /** Sets the attenuation parameters of the light source ie how it diminishes with distance.
156            @remarks
157                Lights normally get fainter the further they are away. Also, each light is given a maximum range
158                beyond which it cannot affect any objects.
159            @par
160                Light attentuation is not applicable to directional lights since they have an infinite range and
161                constant intensity.
162            @par
163                This follows a standard attenuation approach - see any good 3D text for the details of what they mean
164                since i don't have room here!
165            @param
166                range The absolute upper range of the light in world units
167            @param
168                constant The constant factor in the attenuation formula: 1.0 means never attenuate, 0.0 is complete attenuation
169            @param
170                linear The linear factor in the attenuation formula: 1 means attenuate evenly over the distance
171            @param
172                quadratic The quadratic factor in the attenuation formula: adds a curvature to the attenuation formula.
173        */
174        void setAttenuation(Real range, Real constant, Real linear, Real quadratic);
175
176        /** Returns the absolute upper range of the light.
177        */
178        Real getAttenuationRange(void) const;
179
180        /** Returns the constant factor in the attenuation formula.
181        */
182        Real getAttenuationConstant(void) const;
183
184        /** Returns the linear factor in the attenuation formula.
185        */
186        Real getAttenuationLinear(void) const;
187
188        /** Returns the quadric factor in the attenuation formula.
189        */
190        Real getAttenuationQuadric(void) const;
191
192        /** Sets the position of the light.
193            @remarks
194                Applicable to point lights and spotlights only.
195            @note
196                This will be overridden if the light is attached to a SceneNode.
197        */
198        void setPosition(Real x, Real y, Real z);
199
200        /** Sets the position of the light.
201            @remarks
202                Applicable to point lights and spotlights only.
203            @note
204                This will be overridden if the light is attached to a SceneNode.
205        */
206        void setPosition(const Vector3& vec);
207
208        /** Returns the position of the light.
209            @note
210                Applicable to point lights and spotlights only.
211        */
212        const Vector3& getPosition(void) const;
213
214        /** Sets the direction in which a light points.
215            @remarks
216                Applicable only to the spotlight and directional light types.
217            @note
218                This will be overridden if the light is attached to a SceneNode.
219        */
220        void setDirection(Real x, Real y, Real z);
221
222        /** Sets the direction in which a light points.
223            @remarks
224                Applicable only to the spotlight and directional light types.
225            @note
226                This will be overridden if the light is attached to a SceneNode.
227        */
228        void setDirection(const Vector3& vec);
229
230        /** Returns the light's direction.
231            @remarks
232                Applicable only to the spotlight and directional light types.
233        */
234        const Vector3& getDirection(void) const;
235
236        /** Sets the range of a spotlight, i.e. the angle of the inner and outer cones and the rate of falloff between them.
237            @param
238                innerAngle Angle covered by the bright inner cone
239            @param
240                outerAngle Angle covered by the outer cone
241            @param
242                falloff The rate of falloff between the inner and outer cones. 1.0 means a linear falloff, less means slower falloff, higher means faster falloff.
243        */
244        void setSpotlightRange(const Radian& innerAngle, const Radian& outerAngle, Real falloff = 1.0);
245#ifndef OGRE_FORCE_ANGLE_TYPES
246        inline void setSpotlightRange(Real innerAngle, Real outerAngle, Real falloff = 1.0) {
247            setSpotlightRange ( Angle(innerAngle), Angle(outerAngle), falloff );
248        }
249#endif//OGRE_FORCE_ANGLE_TYPES
250
251        /** Returns the angle covered by the spotlights inner cone.
252        */
253        const Radian& getSpotlightInnerAngle(void) const;
254
255        /** Returns the angle covered by the spotlights outer cone.
256        */
257        const Radian& getSpotlightOuterAngle(void) const;
258
259        /** Returns the falloff between the inner and outer cones of the spotlight.
260        */
261        Real getSpotlightFalloff(void) const;
262
263        /** Overridden from MovableObject */
264        void _notifyCurrentCamera(Camera* cam);
265
266        /** Overridden from MovableObject */
267        const AxisAlignedBox& getBoundingBox(void) const;
268
269        /** Overridden from MovableObject */
270        void _updateRenderQueue(RenderQueue* queue);
271
272        /** Overridden from MovableObject */
273        const String& getMovableType(void) const;
274
275        /** Retrieves the position of the light including any transform from nodes it is attached to. */
276        const Vector3& getDerivedPosition(void) const;
277
278        /** Retrieves the direction of the light including any transform from nodes it is attached to. */
279        const Vector3& getDerivedDirection(void) const;
280
281        /** Overridden from MovableObject.
282        @remarks
283            Although lights themselves are not 'visible', setting a light to invisible
284            means it no longer affects the scene.
285        */
286        void setVisible(bool visible);
287
288        /** Overridden from MovableObject */
289        Real getBoundingRadius(void) const { return 0; /* not visible */ }
290
291                /** Gets the details of this light as a 4D vector.
292                @remarks
293                        Getting details of a light as a 4D vector can be useful for
294                        doing general calculations between different light types; for
295                        example the vector can represent both position lights (w=1.0f)
296                        and directional lights (w=0.0f) and be used in the same
297                        calculations.
298                */
299                Vector4 getAs4DVector(void) const;
300
301        /** Internal method for calculating the 'near clip volume', which is
302            the volume formed between the near clip rectangle of the
303            camera and the light.
304        @remarks This volume is a pyramid for a point/spot light and
305            a cuboid for a directional light. It can used to detect whether
306            an object could be casting a shadow on the viewport. Note that
307            the reference returned is to a shared volume which will be
308            reused across calls to this method.
309        */
310        const PlaneBoundedVolume& _getNearClipVolume(const Camera* const cam) const;
311
312        /** Internal method for calculating the clip volumes outside of the
313            frustum which can be used to determine which objects are casting
314            shadow on the frustum as a whole.
315        @remarks Each of the volumes is a pyramid for a point/spot light and
316            a cuboid for a directional light.
317        */
318        const PlaneBoundedVolumeList& _getFrustumClipVolumes(const Camera* const cam) const;
319
320
321
322    private:
323        /// internal method for synchronising with parent node (if any)
324        void update(void) const;
325        String mName;
326
327        LightTypes mLightType;
328        Vector3 mPosition;
329        ColourValue mDiffuse;
330        ColourValue mSpecular;
331
332        Vector3 mDirection;
333
334        Radian mSpotOuter;
335        Radian mSpotInner;
336        Real mSpotFalloff;
337        Real mRange;
338        Real mAttenuationConst;
339        Real mAttenuationLinear;
340        Real mAttenuationQuad;
341
342        mutable Vector3 mDerivedPosition;
343        mutable Vector3 mDerivedDirection;
344        /// Stored versions of parent orientation / position
345        mutable Quaternion mLastParentOrientation;
346        mutable Vector3 mLastParentPosition;
347
348        /// Shared class-level name for Movable type
349        static String msMovableType;
350
351        mutable PlaneBoundedVolume mNearClipVolume;
352        mutable PlaneBoundedVolumeList mFrustumClipVolumes;
353        /// Is the local transform dirty?
354        mutable bool mLocalTransformDirty;
355
356
357
358    };
359} // Namespace
360#endif
Note: See TracBrowser for help on using the repository browser.