[2072] | 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 | |
---|
| 34 | #include <string> |
---|
| 35 | #include "util/Math.h" |
---|
[3196] | 36 | #include "interfaces/TeamColourable.h" |
---|
| 37 | #include "StaticEntity.h" |
---|
[2072] | 38 | |
---|
| 39 | namespace orxonox |
---|
| 40 | { |
---|
[3196] | 41 | class _OrxonoxExport Light : public StaticEntity, public TeamColourable |
---|
[2072] | 42 | { |
---|
| 43 | public: |
---|
[3196] | 44 | enum LightTypes // Copy from the Ogre enum |
---|
| 45 | { |
---|
| 46 | /// Point light sources give off light equally in all directions, so require only position not direction |
---|
| 47 | LT_POINT, |
---|
| 48 | /// Directional lights simulate parallel light beams from a distant source, hence have direction but no position |
---|
| 49 | LT_DIRECTIONAL, |
---|
| 50 | /// Spotlights simulate a cone of light from a source so require position and direction, plus extra values for falloff |
---|
| 51 | LT_SPOTLIGHT |
---|
| 52 | }; |
---|
| 53 | |
---|
| 54 | public: |
---|
[2072] | 55 | Light(BaseObject* creator); |
---|
| 56 | virtual ~Light(); |
---|
| 57 | |
---|
| 58 | virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); |
---|
| 59 | void registerVariables(); |
---|
| 60 | |
---|
| 61 | virtual void changedVisibility(); |
---|
| 62 | |
---|
| 63 | inline Ogre::Light* getLight() |
---|
| 64 | { return this->light_; } |
---|
| 65 | |
---|
[3196] | 66 | inline void setType(Light::LightTypes type) |
---|
[2662] | 67 | { this->type_ = type; this->updateType(); } |
---|
[3196] | 68 | inline Light::LightTypes getType() const |
---|
[2072] | 69 | { return this->type_; } |
---|
| 70 | |
---|
[2662] | 71 | inline void setDiffuseColour(const ColourValue& colour) |
---|
| 72 | { this->diffuse_ = colour; this->updateDiffuseColour(); } |
---|
| 73 | inline const ColourValue& getDiffuseColour() const |
---|
| 74 | { return this->diffuse_; } |
---|
[2072] | 75 | |
---|
[2662] | 76 | inline void setSpecularColour(const ColourValue& colour) |
---|
| 77 | { this->specular_ = colour; this->updateSpecularColour(); } |
---|
| 78 | inline const ColourValue& getSpecularColour() const |
---|
| 79 | { return this->specular_; } |
---|
[2072] | 80 | |
---|
[2826] | 81 | virtual void setTeamColour(const ColourValue& colour) |
---|
| 82 | { this->setDiffuseColour(colour); this->setSpecularColour(colour); } |
---|
| 83 | |
---|
[2662] | 84 | /** |
---|
| 85 | @brief Sets the attenuation parameters of the light source i.e. how it diminishes with distance. |
---|
[2072] | 86 | |
---|
[2662] | 87 | @param attenuation.x range (The absolute upper range of the light in world units) |
---|
| 88 | @param attenuation.y constant (The constant factor in the attenuation formula: 1.0 means never attenuate, 0.0 is complete attenuation) |
---|
| 89 | @param attenuation.z linear (The linear factor in the attenuation formula: 1 means attenuate evenly over the distance) |
---|
| 90 | @param attenuation.w quadratic (The quadratic factor in the attenuation formula: adds a curvature to the attenuation formula) |
---|
| 91 | |
---|
| 92 | Quote from the Ogre API: |
---|
| 93 | Lights normally get fainter the further they are away. Also, each light is given a maximum range beyond which it cannot affect any objects. |
---|
| 94 | Light attenuation is not applicable to directional lights since they have an infinite range and constant intensity. |
---|
| 95 | 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! |
---|
| 96 | |
---|
| 97 | Quote from the Ogre wiki: |
---|
| 98 | "Using these numbers, the light has 100% intensity at 0 distance, and |
---|
| 99 | trails off to near black at a distance equal to the Range. Keep in mind |
---|
| 100 | that most of the light falls in the first 20% of the range." |
---|
| 101 | |
---|
| 102 | Range Constant Linear Quadratic |
---|
| 103 | 3250, 1.0, 0.0014, 0.000007 |
---|
| 104 | 600, 1.0, 0.007, 0.0002 |
---|
| 105 | 325, 1.0, 0.014, 0.0007 |
---|
| 106 | 200, 1.0, 0.022, 0.0019 |
---|
| 107 | 160, 1.0, 0.027, 0.0028 |
---|
| 108 | 100, 1.0, 0.045, 0.0075 |
---|
| 109 | 65, 1.0, 0.07, 0.017 |
---|
| 110 | 50, 1.0, 0.09, 0.032 |
---|
| 111 | 32, 1.0, 0.14, 0.07 |
---|
| 112 | 20, 1.0, 0.22, 0.20 |
---|
| 113 | 13, 1.0, 0.35, 0.44 |
---|
| 114 | 7, 1.0, 0.7, 1.8 |
---|
| 115 | */ |
---|
| 116 | inline void setAttenuation(const Vector4& attenuation) |
---|
| 117 | { this->attenuation_ = attenuation; this->updateAttenuation(); } |
---|
| 118 | inline const Vector4& getAttenuation() const |
---|
| 119 | { return this->attenuation_; } |
---|
| 120 | |
---|
| 121 | /** |
---|
| 122 | @brief Sets the range of a spotlight, i.e. the angle of the inner and outer cones and the rate of falloff between them. |
---|
| 123 | |
---|
| 124 | @param spotlightRange.x innerAngle (The angle covered by the bright inner cone) |
---|
| 125 | @param spotlightRange.x outerAngle (The angle covered by the outer cone) |
---|
| 126 | @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.) |
---|
| 127 | */ |
---|
| 128 | inline void setSpotlightRange(const Vector3& spotlightRange) |
---|
| 129 | { this->spotlightRange_ = spotlightRange; this->updateSpotlightRange(); } |
---|
| 130 | inline const Vector3& getSpotlightRange() const |
---|
| 131 | { return this->spotlightRange_; } |
---|
| 132 | |
---|
[2072] | 133 | private: |
---|
| 134 | void setTypeString(const std::string& type); |
---|
| 135 | std::string getTypeString() const; |
---|
| 136 | |
---|
[2662] | 137 | void updateType(); |
---|
| 138 | void updateDiffuseColour(); |
---|
| 139 | void updateSpecularColour(); |
---|
| 140 | void updateAttenuation(); |
---|
| 141 | void updateSpotlightRange(); |
---|
[2072] | 142 | |
---|
| 143 | Ogre::Light* light_; |
---|
[3196] | 144 | LightTypes type_; |
---|
[2662] | 145 | ColourValue diffuse_; |
---|
| 146 | ColourValue specular_; |
---|
| 147 | Vector4 attenuation_; |
---|
| 148 | Vector3 spotlightRange_; |
---|
[2072] | 149 | }; |
---|
| 150 | } |
---|
| 151 | |
---|
| 152 | #endif /* _Light_H__ */ |
---|