Project

General

Profile

SO3Engine
SO3Light.cpp
Go to the documentation of this file.
1
11
12namespace SO3
13{
14
15 SLight::SLight(SScene* parent, const std::string& lightName) : SNode(parent, lightName, SNode::LIGHT_TYPE_ID)
16 {
17 mShadowFarDistance = 0;
18 O3Light = currentScene->GetOgreScenePointer()->createLight(lightName);
19 UpdateShadowFarDistance(currentScene->O3SceneManager->getShadowFarDistance());
20 UpdateShadowFarClipDistance(currentScene->O3SceneManager->getShadowDirectionalLightExtrusionDistance());
21
22 mLightShaft = 0;
23 mVolumetric = false;
24 mRange = 1000.0f;
25
26 ogreMovableObject = O3Light;
27 O3SceneNode->attachObject(O3Light);
28 SetAttenuation(mRange);
29 }
30
31 SLight::SLight() : SNode(0, "", SNode::LIGHT_TYPE_ID)
32 {
33 // Forbiden (private);
34 }
35
37 {
38 SAFE_DELETE(mLightShaft);
39 O3SceneNode->detachObject(O3Light);
40 currentScene->GetOgreScenePointer()->destroyLight(O3Light);
41 O3Light = 0;
43 }
44
46 {
47 return O3Light;
48 }
49
50 void SLight::UpdateVolumetric(bool force)
51 {
52 float nrange = mRange;
53 Ogre::Radian fov = Ogre::Degree(120.0f);
54 switch (GetType())
55 {
56 case SO3_POINT_LIGHT:
57 fov = Ogre::Degree(160.0f);
58 break;
59
61 fov = Ogre::Degree(120.0f);
62 nrange = 100000.0f;
63 break;
64
65 case SO3_SPOT_LIGHT:
66 case SO3_RECT_LIGHT:
67 fov = O3Light->getSpotlightOuterAngle();
68 nrange *= 10.0f;
69 break;
70 }
71
72 if (force && mVolumetric && O3Light->isVisible())
73 {
74 SAFE_DELETE(mLightShaft);
75 mLightShaft = new SLightShaft(this, 0.0001f, nrange * 0.01f, nrange, fov);
76 }
77 else
78 {
79 if (mVolumetric && O3Light->isVisible() && !mLightShaft)
80 mLightShaft = new SLightShaft(this, 0.0001f, nrange * 0.01f, nrange, fov);
81 else if ((!O3Light->isVisible() || !mVolumetric) && mLightShaft)
82 SAFE_DELETE(mLightShaft);
83 }
84
85 if (mLightShaft)
86 {
87 mLightShaft->SetColor(O3Light->getDiffuseColour() * O3Light->getPowerScale());
88 mLightShaft->SetLightFov(fov);
89 mLightShaft->SetLightClipping(nrange * 0.01f, nrange);
90 mLightShaft->SetAttenuation(Ogre::Vector4(mRange, 0.1, 4.5f / mRange, 7.5f / (mRange*mRange)));
91 }
92 }
93
94 void SLight::SetVolumetric(bool state)
95 {
96 mVolumetric = state;
97 UpdateVolumetric();
98 }
99
101 {
102 return mVolumetric;
103 }
104
105 void SLight::SetDiffuseColour(Ogre::ColourValue color)
106 {
107 O3Light->setDiffuseColour(color);
108 UpdateVolumetric();
109 }
110
111 void SLight::SetSpecularColour(Ogre::ColourValue color)
112 {
113 O3Light->setSpecularColour(color);
114 }
115
116 void SLight::SetDiffuseColour(const int& diffuseColor)
117 {
118 O3Light->setDiffuseColour(ConversionTools::ScolToOgreColorRGBA(diffuseColor));
119 UpdateVolumetric();
120 }
121
123 {
124 return ConversionTools::OgreToScolColorRGBA(O3Light->getDiffuseColour());
125 }
126
127 void SLight::SetSpecularColour(const int& specularColor)
128 {
129 O3Light->setSpecularColour(ConversionTools::ScolToOgreColorRGBA(specularColor));
130 }
131
133 {
134 return ConversionTools::OgreToScolColorRGBA(O3Light->getSpecularColour());
135 }
136
137 void SLight::SetPowerScale(const float& powerScale)
138 {
139 float power = std::max(0.01f, powerScale);
140 O3Light->setPowerScale(power);
141 UpdateVolumetric();
142 }
143
145 {
146 return static_cast <float> (O3Light->getPowerScale());
147 }
148
149 void SLight::SetVisible(const bool& isVisible)
150 {
151 O3Light->setVisible(isVisible);
152
153 if (mVolumetric)
154 {
155 if (isVisible)
156 UpdateVolumetric();
157 else
158 SAFE_DELETE(mLightShaft);
159 }
160
161 //hack to force shadow texture destruction
165 }
166
168 {
169 return O3Light->isVisible();
170 }
171
172 void SLight::SetAttenuation(const float& range, const float& constant, const float& linear, const float& quadratic)
173 {
174 mRange = std::max(0.01f, range);
175 if (O3Light->getType() == Ogre::Light::LT_DIRECTIONAL)
176 O3Light->setAttenuation(100000.0f, constant, 0.0f, 0.0f);
177 else
178 O3Light->setAttenuation(range, constant, linear, quadratic);
179 }
180
181 void SLight::SetAttenuation(const float& range)
182 {
183 SetAttenuation(range, 1.0, 0.45f / range, 7.5f / (range*range));
184 UpdateVolumetric();
185 }
186
188 {
189 return Ogre::Vector4(O3Light->getAttenuationRange(),
190 O3Light->getAttenuationConstant(),
191 O3Light->getAttenuationLinear(),
192 O3Light->getAttenuationQuadric());
193 }
194
195 void SLight::SetShadowFarDistance(const float& distance)
196 {
197 O3Light->setShadowFarDistance(distance);
198 mShadowFarDistance = distance;
199 }
200
201 void SLight::UpdateShadowFarDistance(const float& distance)
202 {
203 if (mShadowFarDistance == 0)
204 O3Light->setShadowFarDistance(distance);
205 }
206
207 void SLight::UpdateShadowFarClipDistance(const float& distance)
208 {
209 O3Light->setShadowNearClipDistance(0.1f);
210 O3Light->setShadowFarClipDistance(distance);
211 }
212
214 {
215 return O3Light->getShadowFarDistance();
216 }
217
218 void SLight::SetType(const LightType& type)
219 {
220 O3Light->setType(static_cast <Ogre::Light::LightTypes> (type));
221 SetAttenuation(mRange);
222 UpdateVolumetric(true);
223 }
224
226 {
227 return static_cast <SLight::LightType> (O3Light->getType());
228 }
229
230 void SLight::SetSpotlightInnerAngle(const float& radianAngle)
231 {
232 O3Light->setSpotlightInnerAngle(Ogre::Radian(radianAngle));
233 }
234
236 {
237 return static_cast <float> (O3Light->getSpotlightInnerAngle().valueRadians());
238 }
239
240 void SLight::SetSpotlightOuterAngle(const float& radianAngle)
241 {
242 O3Light->setSpotlightOuterAngle(Ogre::Radian(radianAngle));
243 UpdateVolumetric();
244 }
245
247 {
248 return static_cast <float> (O3Light->getSpotlightOuterAngle().valueRadians());
249 }
250
251 void SLight::SetSpotlightFalloff(const float& value)
252 {
253 O3Light->setSpotlightFalloff(value);
254 }
255
257 {
258 return O3Light->getSpotlightFalloff();
259 }
260
261 void SLight::SetSourceSize(float x, float y)
262 {
263 O3Light->setSourceSize(x, y);
264 UpdateVolumetric();
265 }
266
267 Ogre::Vector2f SLight::GetSourceSize()
268 {
269 return O3Light->getSourceSize();
270 }
271
272 void SLight::SetCastShadows(const bool& castShadows)
273 {
274 O3Light->setCastShadows(castShadows);
275 //hack to force shadow texture destruction
279 }
280
282 {
283 return O3Light->getCastShadows();
284 }
285
286 void SLight::SetRenderingDistance(const float& distance)
287 {
288 return O3Light->setRenderingDistance(distance);
289 }
290
292 {
293 return O3Light->getRenderingDistance();
294 }
295
296 Ogre::Vector3 SLight::GetBoundingBoxSize(const bool& childs)
297 {
298 if (childs)
299 return GetSonsBoundingBox();
300
301 return O3Light->getBoundingBox().getSize();
302 }
303
304 Ogre::Vector3 SLight::GetBoundingBoxCenter(const bool& childs)
305 {
306 return O3Light->getBoundingBox().getCenter();
307 }
308
309 Ogre::Vector3 SLight::GetWorldBoundingBoxSize(const bool& childs)
310 {
311 if (childs)
313
314 return O3Light->getWorldBoundingBox(true).getSize();
315 }
316
317 Ogre::Vector3 SLight::GetWorldBoundingBoxCenter(const bool& childs)
318 {
319 return O3Light->getWorldBoundingBox(true).getCenter();
320 }
321}
static Ogre::ColourValue ScolToOgreColorRGBA(const int &scolColor)
static int OgreToScolColorRGBA(const Ogre::ColourValue &ogreColor)
virtual void SetRenderingDistance(const float &distance)
Definition SO3Light.cpp:286
void SetAttenuation(const float &range, const float &constant, const float &linear, const float &quadratic)
Definition SO3Light.cpp:172
bool GetVolumetric()
Definition SO3Light.cpp:100
virtual float GetRenderingDistance()
Definition SO3Light.cpp:291
void SetSpotlightInnerAngle(const float &radianAngle)
Definition SO3Light.cpp:230
virtual bool GetCastShadows()
Definition SO3Light.cpp:281
Ogre::Vector2f GetSourceSize()
Definition SO3Light.cpp:267
virtual void SetCastShadows(const bool &castShadows)
Definition SO3Light.cpp:272
void SetDiffuseColour(const int &diffuseColor)
Definition SO3Light.cpp:116
Ogre::Light * GetOgreLightPointer()
Definition SO3Light.cpp:45
bool GetVisible()
Definition SO3Light.cpp:167
void SetPowerScale(const float &powerScale)
Definition SO3Light.cpp:137
float GetSpotlightInnerAngle()
Definition SO3Light.cpp:235
Ogre::Vector4 GetAttenuation()
Definition SO3Light.cpp:187
void SetSpotlightOuterAngle(const float &radianAngle)
Definition SO3Light.cpp:240
float GetPowerScale()
Definition SO3Light.cpp:144
void SetShadowFarDistance(const float &distance)
Definition SO3Light.cpp:195
virtual Ogre::Vector3 GetBoundingBoxCenter(const bool &childs=false)
Definition SO3Light.cpp:304
virtual Ogre::Vector3 GetWorldBoundingBoxSize(const bool &childs=false)
Definition SO3Light.cpp:309
void SetSpotlightFalloff(const float &value)
Definition SO3Light.cpp:251
void SetVisible(const bool &isVisible)
Definition SO3Light.cpp:149
void SetType(const LightType &type)
Definition SO3Light.cpp:218
void SetSourceSize(float x, float y)
Definition SO3Light.cpp:261
@ SO3_RECT_LIGHT
Definition SO3Light.h:51
@ SO3_SPOT_LIGHT
Definition SO3Light.h:50
@ SO3_POINT_LIGHT
Definition SO3Light.h:48
@ SO3_DIRECTIONAL_LIGHT
Definition SO3Light.h:49
void UpdateShadowFarDistance(const float &distance)
Definition SO3Light.cpp:201
LightType GetType()
Definition SO3Light.cpp:225
float GetSpotlightOuterAngle()
Definition SO3Light.cpp:246
void SetSpecularColour(const int &specularColor)
Definition SO3Light.cpp:127
int GetDiffuseColour()
Definition SO3Light.cpp:122
void SetVolumetric(bool state)
Definition SO3Light.cpp:94
virtual Ogre::Vector3 GetBoundingBoxSize(const bool &childs=false)
Definition SO3Light.cpp:296
float GetSpotlightFalloff()
Definition SO3Light.cpp:256
int GetSpecularColour()
Definition SO3Light.cpp:132
float GetShadowFarDistance()
Definition SO3Light.cpp:213
void UpdateShadowFarClipDistance(const float &distance)
Definition SO3Light.cpp:207
virtual Ogre::Vector3 GetWorldBoundingBoxCenter(const bool &childs=false)
Definition SO3Light.cpp:317
void SetLightClipping(float nearClip, float farClip)
void SetColor(Ogre::ColourValue col)
void SetAttenuation(Ogre::Vector4 attenuation)
void SetLightFov(Ogre::Radian fov)
Ogre::Vector3 GetSonsWorldBoundingBox()
SScene * currentScene
Definition SO3NodeScol.h:68
Ogre::SceneNode * O3SceneNode
Definition SO3NodeScol.h:69
Ogre::MovableObject * ogreMovableObject
Definition SO3NodeScol.h:70
Ogre::Vector3 GetSonsBoundingBox()
Ogre::SceneManager * O3SceneManager
Definition SO3Scene.h:127
void SetShadowType(const SShadowManager::ShadowType &shadowType)
SShadowManager::ShadowType GetShadowType()
Ogre::SceneManager * GetOgreScenePointer()
Definition SO3Scene.cpp:449