Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/archive/tutorialFS09/src/orxonox/objects/worldentities/Light.h @ 10022

Last change on this file since 10022 was 2662, checked in by rgrieder, 16 years ago

Merged presentation branch back to trunk.

  • Property svn:eol-style set to native
File size: 5.9 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Fabian 'x3n' Landau
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#ifndef _Light_H__
30#define _Light_H__
31
32#include "OrxonoxPrereqs.h"
33#include "StaticEntity.h"
34
35#include <string>
36#include <OgreLight.h>
37
38#include "util/Math.h"
39
40namespace orxonox
41{
42    class _OrxonoxExport Light : public StaticEntity
43    {
44        public:
45            Light(BaseObject* creator);
46            virtual ~Light();
47
48            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
49            void registerVariables();
50
51            virtual void changedVisibility();
52
53            inline Ogre::Light* getLight()
54                { return this->light_; }
55
56            inline void setType(Ogre::Light::LightTypes type)
57                { this->type_ = type; this->updateType(); }
58            inline Ogre::Light::LightTypes getType() const
59                { return this->type_; }
60
61            inline void setDiffuseColour(const ColourValue& colour)
62                { this->diffuse_ = colour; this->updateDiffuseColour(); }
63            inline const ColourValue& getDiffuseColour() const
64                { return this->diffuse_; }
65
66            inline void setSpecularColour(const ColourValue& colour)
67                { this->specular_ = colour; this->updateSpecularColour(); }
68            inline const ColourValue& getSpecularColour() const
69                { return this->specular_; }
70
71            /**
72                @brief Sets the attenuation parameters of the light source i.e. how it diminishes with distance.
73
74                @param attenuation.x range (The absolute upper range of the light in world units)
75                @param attenuation.y constant (The constant factor in the attenuation formula: 1.0 means never attenuate, 0.0 is complete attenuation)
76                @param attenuation.z linear (The linear factor in the attenuation formula: 1 means attenuate evenly over the distance)
77                @param attenuation.w quadratic (The quadratic factor in the attenuation formula: adds a curvature to the attenuation formula)
78
79                Quote from the Ogre API:
80                Lights normally get fainter the further they are away. Also, each light is given a maximum range beyond which it cannot affect any objects.
81                Light attenuation is not applicable to directional lights since they have an infinite range and constant intensity.
82                This follows a standard attenuation approach - see any good 3D text for the details of what they mean since i don't have room here!
83
84                Quote from the Ogre wiki:
85                "Using these numbers, the light has 100% intensity at 0 distance, and
86                trails off to near black at a distance equal to the Range. Keep in mind
87                that most of the light falls in the first 20% of the range."
88
89                Range   Constant   Linear     Quadratic
90                3250,     1.0,     0.0014,    0.000007
91                600,      1.0,     0.007,     0.0002
92                325,      1.0,     0.014,     0.0007
93                200,      1.0,     0.022,     0.0019
94                160,      1.0,     0.027,     0.0028
95                100,      1.0,     0.045,     0.0075
96                65,       1.0,     0.07,      0.017
97                50,       1.0,     0.09,      0.032
98                32,       1.0,     0.14,      0.07
99                20,       1.0,     0.22,      0.20
100                13,       1.0,     0.35,      0.44
101                7,        1.0,     0.7,       1.8
102            */
103            inline void setAttenuation(const Vector4& attenuation)
104                { this->attenuation_ = attenuation; this->updateAttenuation(); }
105            inline const Vector4& getAttenuation() const
106                { return this->attenuation_; }
107
108            /**
109                @brief Sets the range of a spotlight, i.e. the angle of the inner and outer cones and the rate of falloff between them.
110
111                @param spotlightRange.x innerAngle (The angle covered by the bright inner cone)
112                @param spotlightRange.x outerAngle (The angle covered by the outer cone)
113                @param spotlightRange.x 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.)
114            */
115            inline void setSpotlightRange(const Vector3& spotlightRange)
116                { this->spotlightRange_ = spotlightRange; this->updateSpotlightRange(); }
117            inline const Vector3& getSpotlightRange() const
118                { return this->spotlightRange_; }
119
120        private:
121            void setTypeString(const std::string& type);
122            std::string getTypeString() const;
123
124            void updateType();
125            void updateDiffuseColour();
126            void updateSpecularColour();
127            void updateAttenuation();
128            void updateSpotlightRange();
129
130            Ogre::Light* light_;
131            Ogre::Light::LightTypes type_;
132            ColourValue diffuse_;
133            ColourValue specular_;
134            Vector4 attenuation_;
135            Vector3 spotlightRange_;
136    };
137}
138
139#endif /* _Light_H__ */
Note: See TracBrowser for help on using the repository browser.