SO3Engine
SO3Water.cpp
Go to the documentation of this file.
1/*
2-----------------------------------------------------------------------------
3This source file is part of OpenSpace3D
4For the latest info, see http://www.openspace3d.com
5
6Copyright (c) 2012 I-maginer
7
8This program is free software; you can redistribute it and/or modify it under
9the terms of the GNU Lesser General Public License as published by the Free Software
10Foundation; either version 2 of the License, or (at your option) any later
11version.
12
13This program is distributed in the hope that it will be useful, but WITHOUT
14ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public License along with
18this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19Place - Suite 330, Boston, MA 02111-1307, USA, or go to
20http://www.gnu.org/copyleft/lesser.txt
21
22-----------------------------------------------------------------------------
23*/
24
32#include "SO3Renderer/SO3Root.h"
39
40namespace SO3
41{
42
43SWater::SWater(SEnvironment* parent, const std::string& waterName) : SEnvironmentComponent(parent, waterName)
44{
45 CommonConstructorsSequence(SO3_WATER_GEOM_INFINITE_PLANE);
46}
47
48SWater::SWater(SEnvironment* parent, const std::string& waterName, const int& planeSizeX, const int& planeSizeY) : SEnvironmentComponent(parent, waterName)
49{
50 CommonConstructorsSequence(SO3_WATER_GEOM_FINITE_PLANE);
51 finitePlaneWaterSizeX = planeSizeX;
52 finitePlaneWaterSizeY = planeSizeY;
53}
54
55SWater::SWater(SEnvironment* parent, const std::string& waterName, const float& waterRadius) : SEnvironmentComponent(parent, waterName)
56{
57 CommonConstructorsSequence(SO3_WATER_GEOM_RADIAL);
58 radialWaterRadius = waterRadius;
59}
60
61SWater::SWater() : SEnvironmentComponent(0, "")
62{
63 // Forbiden (private)
64}
65
66void SWater::CommonConstructorsSequence(const WaterGeometryType& selectedWaterGeometryType)
67{
68 // Usefull pointers initialisation
69 parentScene = parentEnvironment->GetScene();
70 hydraxManager = 0;
71 hydraxGeometry = 0;
72 hydraxNoise = 0;
73 renderingViewport = 0;
74
75 IslastUnderWater = false;
76
77 // Store geometry type for further usage
78 actualGeometryType = selectedWaterGeometryType;
79 finitePlaneWaterSizeX = 0;
80 finitePlaneWaterSizeY = 0;
81 radialWaterRadius = 0.0f;
82
83 // Some member variable init
84 waterPlanePosition = Ogre::Vector3::ZERO;
85 wavesAnimationSpeed = 1.0f;
86 cachedWindDirection = Ogre::Vector2::ZERO;
87
88 // Configure water color
89 baseColour = Ogre::ColourValue(0.025, .2, 0.35);
90 RefreshWaterColourGradient();
91
92 // Configure perlin noise
93 perlinNoiseOptions.Octaves = 8;
94 perlinNoiseOptions.Scale = 0.85f;
95 perlinNoiseOptions.Falloff = 0.49f;
96 perlinNoiseOptions.Animspeed = 1.4f;
97 perlinNoiseOptions.Timemulti = 1.27f;
98 perlinNoiseOptions.GPU_Strength = 0.20f;
99 perlinNoiseOptions.GPU_LODParameters = Ogre::Vector3(0.5f, 50, 150000);
100
101 // Configure fft noise
102 fftNoiseOptions.Resolution = 128;
103 fftNoiseOptions.PhysicalResolution = 32.0f;
104 fftNoiseOptions.Scale = 0.25f;
105 fftNoiseOptions.WindDirection = Ogre::Vector2(4,5);
106 fftNoiseOptions.AnimationSpeed = .1;
107 fftNoiseOptions.KwPower = 6.0f;
108 fftNoiseOptions.Amplitude = 1.0f;
109 fftNoiseOptions.GPU_Strength = .20f;
110 fftNoiseOptions.GPU_LODParameters = Ogre::Vector3(0.5f, 50, 150000);
111
112 // Create our components class instances (that do not enable the component!)
113 godRaysComponent = new WaterComponentGodRays(this);
114 underwaterReflectionsComponent = new WaterComponentUnderwaterReflections(this);
115 underwaterComponent = new WaterComponentUnderwater(this);
116 causticsComponent = new WaterComponentCaustics(this);
117 smoothComponent = new WaterComponentSmooth(this);
118 depthComponent = new WaterComponentDepth(this);
119 foamComponent = new WaterComponentFoam(this);
120 sunComponent = new WaterComponentSun(this);
121
122 // Enabling all components by default
123 sunComponent->SetEnabled(true);
124 foamComponent->SetEnabled(true);
125 depthComponent->SetEnabled(true);
126 smoothComponent->SetEnabled(true);
127 causticsComponent->SetEnabled(true);
128 underwaterComponent->SetEnabled(true);
129 underwaterReflectionsComponent->SetEnabled(true);
130 godRaysComponent->SetEnabled(true);
131
132 // Set up geometry options
133 progGridOptions.Strength = 0.35f;
134 progGridOptions.Elevation = 1.0f; // It's very important to set a little value here, cause max tesselation of the water plane is reached when the camera is at least to this height.
135 progGridOptions.ChoppyStrength = 0.0375f;
136 progGridOptions.Complexity = 256;
137 progGridOptions.ForceRecalculateGeometry = false;
138}
139
141{
142 Cleanup();
143 SO3_SAFE_DELETE(sunComponent);
144 SO3_SAFE_DELETE(foamComponent);
145 SO3_SAFE_DELETE(depthComponent);
146 SO3_SAFE_DELETE(smoothComponent);
147 SO3_SAFE_DELETE(causticsComponent);
148 SO3_SAFE_DELETE(underwaterComponent);
149 SO3_SAFE_DELETE(underwaterReflectionsComponent);
150 SO3_SAFE_DELETE(godRaysComponent);
151 SO3_SAFE_DELETE(hydraxManager);
152 SO3_SAFE_DELETE(hydraxGeometry);
153 SO3_SAFE_DELETE(hydraxNoise);
154 SO3_SAFE_DELETE(hydraxManager);
155}
156
157bool SWater::Initialize()
158{
159 // Create Hydrax object
160 if (renderingViewport == 0)
161 return false;
162
163 Ogre::Viewport* ogreViewport = const_cast<Ogre::Viewport*> (renderingViewport->GetOgreViewPortPointer());
164 hydraxManager = new Hydrax::Hydrax(parentScene->GetOgreScenePointer(), ogreViewport);
165 hydraxManager->setRttVisibilityMask(SO3_VISIBILITY_MASK_VISIBLE_WATER_RTT);
166
167 // For the moment, only perlin noise is supported by SO3 (random noise).
168 hydraxNoise = CreatePerlinNoise();
169 //(static_cast<Hydrax::Noise::Real*> (hydraxNoise))->addWave(parentEnvironment->GetWindDirection(), 0.01, parentEnvironment->GetWindSpeed(), 0.5);
170
171 // Create geometry
172 if(hydraxGeometry == 0)
173 {
174 switch(actualGeometryType)
175 {
177 CreateInfinitePlaneGeometry();
178 break;
180 CreateFinitePlaneGeometry(finitePlaneWaterSizeX, finitePlaneWaterSizeY);
181 break;
183 CreateRadialPlaneGeometry(radialWaterRadius);
184 break;
185 }
186 }
187
188 // Load main options
189 hydraxManager->setPlanesError(GetInfinitePlaneStrength() * 0.5 + 0.02f);
190 hydraxManager->setUnderwaterCameraSwitchDelta(0.0f);
191 hydraxManager->setGlobalTransparency(0.05f);
192 hydraxManager->setFullReflectionDistance(99999997952.0);
193
194 //hydraxManager->setShaderMode(Hydrax::MaterialManager::SM_CG);
195
196 // Applying Hydrax parameters
197 hydraxManager->setPosition(waterPlanePosition);
198
199 // Applying components state (it also applies components parameters).
200 sunComponent->ApplyEnable();
201 foamComponent->ApplyEnable();
202 depthComponent->ApplyEnable();
203 smoothComponent->ApplyEnable();
204 causticsComponent->ApplyEnable();
205 underwaterComponent->ApplyEnable();
206 underwaterReflectionsComponent->ApplyEnable();
207 godRaysComponent->ApplyEnable();
208
209 // Load rtt settings. Let Hydrax autodetect texture size as a default (window size is taken).
210 // TODO, manage LOW/MEDIUM/HIGH parameters.
211#ifdef ANDROID
212 ScolWindowHandle awindow = (ScolWindowHandle)SCgetExtra("hscol");
213 AConfiguration* config = AConfiguration_new();
214 if (awindow)
215 {
216 int nwidth = (int)ANativeWindow_getWidth(awindow) / 2;
217 int nheight = (int)ANativeWindow_getHeight(awindow) / 2;
218
219 // portrait mode
220 if (nheight > nwidth)
221 {
222 nwidth = (int)ANativeWindow_getHeight(awindow) / 2;
223 nheight = (int)ANativeWindow_getWidth(awindow) / 2;
224 }
225
226 hydraxManager->getRttManager()->setTextureSize(Hydrax::RttManager::RTT_REFLECTION, Hydrax::Size(nwidth, nheight));
227 hydraxManager->getRttManager()->setTextureSize(Hydrax::RttManager::RTT_REFRACTION, Hydrax::Size(nwidth, nheight));
228 hydraxManager->getRttManager()->setTextureSize(Hydrax::RttManager::RTT_DEPTH, Hydrax::Size(nwidth, nheight));
229 hydraxManager->getRttManager()->setTextureSize(Hydrax::RttManager::RTT_DEPTH_REFLECTION, Hydrax::Size(nwidth, nheight));
230 hydraxManager->getRttManager()->setTextureSize(Hydrax::RttManager::RTT_GPU_NORMAL_MAP, Hydrax::Size(nwidth, nheight));
231 }
232#endif
233
234 return true;
235}
236
237void SWater::SetEnableImpl(const bool& enableComponent)
238{
239 if(enableComponent)
240 {
241 if(hydraxManager)
242 return;
243
244 if(!Initialize())
245 return;
246
247 if(!hydraxManager->isCreated())
248 {
249 hydraxManager->create();
250 if (hydraxManager->getMesh() && hydraxManager->getMesh()->getEntity())
251 hydraxManager->getMesh()->getEntity()->setVisibilityFlags(SO3_VISIBILITY_FLAG_INVISIBLE_ENVIRONMENT);
252
253 // Skyx/Hydrax synchro listener.
254 hydraxManager->getRttManager()->addRttListener(this);
255
256 // Add render target listener
257 if(renderingViewport != 0)
258 {
259 bool hasStereo = renderingViewport->IsStereoViewportRegistered();
260 if (hasStereo)
261 renderingViewport->UnregisterStereoViewport();
262
263 Ogre::Viewport* ogreViewport = renderingViewport->GetOgreViewPortPointer();
264 ogreViewport->getTarget()->removeListener(this);
265 ogreViewport->getTarget()->addListener(this);
267
268 if (hasStereo)
269 renderingViewport->RegisterStereoViewport();
270 }
271 }
272 }
273 else
274 {
275 if(hydraxManager == 0)
276 return;
277
278 if(hydraxManager->isCreated())
279 {
280 // Remove render target listener
281 if(renderingViewport != 0)
282 {
283 bool hasStereo = renderingViewport->IsStereoViewportRegistered();
284 if (hasStereo)
285 renderingViewport->UnregisterStereoViewport();
286
287 Ogre::Viewport* ogreViewport = renderingViewport->GetOgreViewPortPointer();
288 if(ogreViewport != 0)
289 {
290 Ogre::RenderTarget* ogreRenderTarget = ogreViewport->getTarget();
291 if(ogreRenderTarget)
292 ogreRenderTarget->removeListener(this);
293 }
294
295 if (hasStereo)
296 renderingViewport->RegisterStereoViewport();
297 }
298
299 hydraxManager->getRttManager()->removeRttListener(this, false);
300 }
301
302 // Delete Hydrax
303 SO3_SAFE_DELETE(hydraxManager);
304 hydraxGeometry = 0; // hydraxGeometry & hydraxNoise are deleted by hydraxManager->remove();
305 hydraxNoise = 0;
306 }
307}
308
309void SWater::AddViewport(Ogre::Viewport* viewport)
310{
311 if(hydraxManager)
312 hydraxManager->registerViewport(viewport);
313}
314
315void SWater::RemoveViewport(Ogre::Viewport* viewport)
316{
317 if(hydraxManager)
318 hydraxManager->unregisterViewport(viewport);
319}
320
322{
323 SetEnableImpl(false);
324 renderingViewport = viewport;
326}
327
329{
330 if(hydraxManager)
331 {
332 if(viewport == renderingViewport)
333 {
334 // Stop rendering
335 SetEnableImpl(false);
336 renderingViewport = 0;
337 }
338 }
339}
340
341Hydrax::Hydrax* SWater::GetHydrax()
342{
343 return hydraxManager;
344}
345
347{
348 SWater::WaterComponent* component = 0;
349 switch(componentType)
350 {
352 component = sunComponent;
353 break;
355 component = foamComponent;
356 break;
358 component = depthComponent;
359 break;
361 component = smoothComponent;
362 break;
364 component = causticsComponent;
365 break;
367 component = underwaterComponent;
368 break;
370 component = underwaterReflectionsComponent;
371 break;
373 component = godRaysComponent;
374 break;
375 default:
376 OGRE_EXCEPT(Ogre::Exception::ERR_INVALIDPARAMS, "Invalid water component type requested!", "SWater::GetComponent");
377 break;
378 }
379 return component;
380}
381
383{
384 return sunComponent;
385}
386
388{
389 return foamComponent;
390}
391
393{
394 return depthComponent;
395}
396
398{
399 return smoothComponent;
400}
401
403{
404 return causticsComponent;
405}
406
408{
409 return underwaterComponent;
410}
411
413{
414 return underwaterReflectionsComponent;
415}
416
418{
419 return godRaysComponent;
420}
421
422Hydrax::Noise::Perlin::Options SWater::GetPerlinOptions()
423{
424 return perlinNoiseOptions;
425}
426
427void SWater::SetPerlinOptions(const Hydrax::Noise::Perlin::Options& newOptions)
428{
429 perlinNoiseOptions = newOptions;
430 if(hydraxNoise)
431 if(hydraxNoise->getName() == "Perlin")
432 try
433 {
434 (static_cast<Hydrax::Noise::Perlin*> (hydraxNoise))->setOptions(perlinNoiseOptions);
435 }
436 catch(Ogre::Exception)
437 {
438 }
439}
440
441Hydrax::Noise::FFT::Options SWater::GetFFTOptions()
442{
443 return fftNoiseOptions;
444}
445
446void SWater::SetFFTOptions(const Hydrax::Noise::FFT::Options& newOptions)
447{
448 fftNoiseOptions = newOptions;
449 if(hydraxNoise)
450 if(hydraxNoise->getName() == "FFT")
451 try
452 {
453 (static_cast<Hydrax::Noise::FFT*> (hydraxNoise))->setOptions(fftNoiseOptions);
454 }
455 catch(Ogre::Exception)
456 {
457 }
458}
459
461{
462 return actualGeometryType;
463}
464
466{
467 CreateInfinitePlaneGeometry();
468}
469
471{
472 return progGridOptions.Strength;
473}
474
475void SWater::SetInfinitePlaneStrength(const float& value)
476{
477 progGridOptions.Strength = value;
478
479 if((hydraxGeometry == 0) || (actualGeometryType != SO3_WATER_GEOM_INFINITE_PLANE))
480 return;
481
482 try
483 {
484 //update plane error
485 hydraxManager->setPlanesError(value * 0.5 + 0.02f);
486 static_cast<Hydrax::Module::ProjectedGrid*>(hydraxGeometry)->setOptions(progGridOptions);
487 }
488 catch(Ogre::Exception)
489 {
490 }
491}
492
494{
495 return progGridOptions.Elevation;
496}
497
498void SWater::SetInfinitePlaneElevation(const float& value)
499{
500 progGridOptions.Elevation = value;
501
502 if((hydraxGeometry == 0) || (actualGeometryType != SO3_WATER_GEOM_INFINITE_PLANE))
503 return;
504
505 try
506 {
507 static_cast<Hydrax::Module::ProjectedGrid*>(hydraxGeometry)->setOptions(progGridOptions);
508 }
509 catch(Ogre::Exception)
510 {
511 }
512}
513
515{
516 return progGridOptions.Complexity;
517}
518
520{
521 progGridOptions.Complexity = value;
522
523 if((hydraxGeometry == 0) || (actualGeometryType != SO3_WATER_GEOM_INFINITE_PLANE))
524 return;
525
526 try
527 {
528 static_cast<Hydrax::Module::ProjectedGrid*>(hydraxGeometry)->setOptions(progGridOptions);
529 }
530 catch(Ogre::Exception)
531 {
532 }
533}
534
536{
537 return progGridOptions.ChoppyStrength;
538}
539
541{
542 progGridOptions.ChoppyStrength = value;
543
544 if((hydraxGeometry == 0) || (actualGeometryType != SO3_WATER_GEOM_INFINITE_PLANE))
545 return;
546
547 try
548 {
549 static_cast<Hydrax::Module::ProjectedGrid*>(hydraxGeometry)->setOptions(progGridOptions);
550 }
551 catch(Ogre::Exception)
552 {
553 }
554}
555
556void SWater::SetGeometryTypeFinitePlane(const int& planeSizeX, const int& planeSizeY)
557{
558 CreateFinitePlaneGeometry(planeSizeX, planeSizeY);
559}
560
561void SWater::SetGeometryTypeRadialPlane(const float& waterRadius)
562{
563 CreateRadialPlaneGeometry(waterRadius);
564}
565
566void SWater::CreateInfinitePlaneGeometry()
567{
568 // Create geometry module
569 Hydrax::Module::ProjectedGrid* newHydraxGeometry;
570 newHydraxGeometry = new Hydrax::Module::ProjectedGrid(hydraxManager,
571 hydraxNoise,
572 Ogre::Plane(Ogre::Vector3(0,1,0), Ogre::Vector3(0,0,0)),
573 Hydrax::MaterialManager::NM_VERTEX,
574 progGridOptions);
575
576 // Hydrax can handle the destruction of the existing geometry module.
577 hydraxManager->setModule(newHydraxGeometry, true);
578
579 // Updating internal data.
580 hydraxGeometry = newHydraxGeometry;
581 actualGeometryType = SO3_WATER_GEOM_INFINITE_PLANE;
582}
583
584void SWater::CreateFinitePlaneGeometry(const int& planeSizeX, const int& planeSizeY)
585{
586 // Set up geometry options
587 Hydrax::Module::SimpleGrid::Options geometryOptions;
588 geometryOptions.MeshSize = Hydrax::Size(planeSizeX, planeSizeY);
589
590 // Create geometry module
591 Hydrax::Module::SimpleGrid* newHydraxGeometry;
592 newHydraxGeometry = new Hydrax::Module::SimpleGrid(hydraxManager,
593 hydraxNoise,
594 Hydrax::MaterialManager::NM_VERTEX,
595 geometryOptions);
596
597 // Hydrax can handle the destruction of the existing geometry module.
598 hydraxManager->setModule(newHydraxGeometry, true);
599
600 // Updating internal data.
601 hydraxGeometry = newHydraxGeometry;
602 actualGeometryType = SO3_WATER_GEOM_FINITE_PLANE;
603 finitePlaneWaterSizeX = planeSizeX;
604 finitePlaneWaterSizeY = planeSizeY;
605}
606
607void SWater::CreateRadialPlaneGeometry(const float& waterRadius)
608{
609 // Set up geometry options
610 Hydrax::Module::RadialGrid::Options geometryOptions;
611 geometryOptions.Radius = waterRadius;
612
613 // Create geometry module
614 Hydrax::Module::RadialGrid* newHydraxGeometry;
615 newHydraxGeometry = new Hydrax::Module::RadialGrid(hydraxManager,
616 hydraxNoise,
617 Hydrax::MaterialManager::NM_VERTEX,
618 geometryOptions);
619
620 // Hydrax can handle the destruction of the existing geometry module.
621 hydraxManager->setModule(newHydraxGeometry, true);
622
623 // Updating internal data.
624 hydraxGeometry = newHydraxGeometry;
625 actualGeometryType = SO3_WATER_GEOM_RADIAL;
626 radialWaterRadius = waterRadius;
627}
628
629void SWater::RefreshWaterColourGradient()
630{
631 // Alpha is not managed by Hydrax, which only use a Ogre::Vector3 for rgb values, so do not care about alpha that will be less than 1 after those multiplications.
632 waterColourGradient.Clear();
633 waterColourGradient.AddColourFrame(1.0, baseColour);
634 waterColourGradient.AddColourFrame(0.8, baseColour * 0.75);
635 waterColourGradient.AddColourFrame(0.6, baseColour * 0.625);
636 waterColourGradient.AddColourFrame(0.5, baseColour * 0.5);
637 waterColourGradient.AddColourFrame(0.0, baseColour * 0.4);
638}
640{
641 // Hydrax remove not compatible components so we should use
642 // the SWater configuration to be sure that the components are correctly added when needed
643 if (hydraxManager)
644 {
645 Hydrax::HydraxComponent components = Hydrax::HYDRAX_COMPONENTS_NONE;
646 if (godRaysComponent && godRaysComponent->GetEnabled())
647 components = static_cast<Hydrax::HydraxComponent> (components|Hydrax::HYDRAX_COMPONENT_UNDERWATER_GODRAYS);
648
649 if (underwaterReflectionsComponent && underwaterReflectionsComponent->GetEnabled())
650 components = static_cast<Hydrax::HydraxComponent> (components|Hydrax::HYDRAX_COMPONENT_UNDERWATER_REFLECTIONS);
651
652 if (underwaterComponent && underwaterComponent->GetEnabled())
653 components = static_cast<Hydrax::HydraxComponent> (components|Hydrax::HYDRAX_COMPONENT_UNDERWATER);
654
655 if (causticsComponent && causticsComponent->GetEnabled())
656 components = static_cast<Hydrax::HydraxComponent> (components|Hydrax::HYDRAX_COMPONENT_CAUSTICS);
657
658 if (smoothComponent && smoothComponent->GetEnabled())
659 components = static_cast<Hydrax::HydraxComponent> (components|Hydrax::HYDRAX_COMPONENT_SMOOTH);
660
661#if !defined(ANDROID) && !defined(APPLE_IOS) && !defined(RPI)
662 if (depthComponent && depthComponent->GetEnabled())
663 components = static_cast<Hydrax::HydraxComponent> (components|Hydrax::HYDRAX_COMPONENT_DEPTH);
664#endif
665
666 if (foamComponent && foamComponent->GetEnabled())
667 components = static_cast<Hydrax::HydraxComponent> (components|Hydrax::HYDRAX_COMPONENT_FOAM);
668
669 if (sunComponent && sunComponent->GetEnabled())
670 components = static_cast<Hydrax::HydraxComponent> (components|Hydrax::HYDRAX_COMPONENT_SUN);
671
672 hydraxManager->setComponents(components);
673 }
674}
675
676/**********************************/
677/* Base component class. */
678/* Do not use directly, must be */
679/* derivated. */
680/**********************************/
681SWater::WaterComponent::WaterComponent(SWater* parentWaterInstance, const SWater::WaterComponentType& component, const Hydrax::HydraxComponent& hydraxComponent) : componentType(component),
682 hydraxComponentType(hydraxComponent)
683{
684 parentWater = parentWaterInstance;
685 waterComponentEnable = false;
686}
687
688SWater::WaterComponent::WaterComponent() : componentType(SWater::SO3_WATER_COMPONENT_NONE),
689 hydraxComponentType(Hydrax::HYDRAX_COMPONENTS_NONE)
690{
691 // Forbiden constructor (private).
692 parentWater = 0;
693 waterComponentEnable = false;
694}
695
697{
698 SetEnabled(false);
699 parentWater = 0;
700}
701
703{
704 return waterComponentEnable;
705}
706
708{
709 if(waterComponentEnable != enable)
710 {
711 waterComponentEnable = enable;
712 ApplyEnable();
713 }
714}
715
717{
718 Hydrax::Hydrax* hydraxManager = parentWater->GetHydrax();
719 if(hydraxManager != 0)
720 {
721 // Apply components parameters too.
722 if(waterComponentEnable)
723 ApplyParameters();
724
725 parentWater->ApplyHydraxComponentTypes();
726 }
727}
728
733
734/**********************************/
735/* Sun component functions */
736/**********************************/
737SWater::WaterComponentSun::WaterComponentSun(SWater* parentWaterInstance) : SWater::WaterComponent(parentWaterInstance, SWater::SO3_WATER_COMPONENT_SUN, Hydrax::HYDRAX_COMPONENT_SUN)
738{
739 horizonPlane = Ogre::Plane(Ogre::Vector3::UNIT_Y, 0);
740 SetParameters(Ogre::Vector3(0.0f, 10000.0f, 0.0f), 1.75f, 1500.0f, Ogre::ColourValue(1.0f, 0.9f, 0.6f));
741}
742
743SWater::WaterComponentSun::WaterComponentSun() : SWater::WaterComponent(0, SWater::SO3_WATER_COMPONENT_NONE, Hydrax::HYDRAX_COMPONENTS_NONE)
744{
745 // Forbiden constructor (private).
746}
747
748void SWater::WaterComponentSun::SetParameters(const Ogre::Vector3& position, const float& strength, const float& area, const Ogre::ColourValue& color)
749{
750 sunPosition = position;
751 sunStrength = strength;
752 sunArea = area;
753 sunColor = color;
754 ApplyParameters();
755}
756
758{
759 Hydrax::Hydrax* hydraxManager = parentWater->GetHydrax();
760 if(hydraxManager != 0)
761 sunPosition = hydraxManager->getSunPosition();
762
763 return sunPosition;
764}
765
766void SWater::WaterComponentSun::SetPosition(const Ogre::Vector3& position)
767{
768 sunPosition = position;
769 Hydrax::Hydrax* hydraxManager = parentWater->GetHydrax();
770 if(hydraxManager != 0)
771 hydraxManager->setSunPosition(sunPosition);
772}
773
775{
776 Hydrax::Hydrax* hydraxManager = parentWater->GetHydrax();
777 if(hydraxManager != 0)
778 sunStrength = hydraxManager->getSunStrength();
779
780 return sunStrength;
781}
782
783void SWater::WaterComponentSun::SetStrength(const float& strength)
784{
785 sunStrength = strength;
786 Hydrax::Hydrax* hydraxManager = parentWater->GetHydrax();
787 if(hydraxManager != 0)
788 hydraxManager->setSunStrength(sunStrength);
789}
790
792{
793 Hydrax::Hydrax* hydraxManager = parentWater->GetHydrax();
794 if(hydraxManager != 0)
795 sunArea = hydraxManager->getSunArea();
796
797 return sunArea;
798}
799
801{
802 sunArea = area;
803 Hydrax::Hydrax* hydraxManager = parentWater->GetHydrax();
804 if(hydraxManager != 0)
805 hydraxManager->setSunArea(sunArea);
806}
807
809{
810 Hydrax::Hydrax* hydraxManager = parentWater->GetHydrax();
811 if(hydraxManager != 0)
812 {
813 Ogre::Vector3 sunColourAsVector = hydraxManager->getSunColor();
814 sunColor = Ogre::ColourValue(sunColourAsVector.x, sunColourAsVector.y, sunColourAsVector.z);
815 }
816
817 return sunColor;
818}
819
820void SWater::WaterComponentSun::SetColor(const Ogre::ColourValue& color)
821{
822 sunColor = color;
823 Hydrax::Hydrax* hydraxManager = parentWater->GetHydrax();
824 if(hydraxManager != 0)
825 {
826 Ogre::Vector3 sunColourAsVector(sunColor.r, sunColor.g, sunColor.b);
827 hydraxManager->setSunColor(sunColourAsVector);
828 }
829}
830
831void SWater::WaterComponentSun::Update(const Ogre::Real& updateTime)
832{
833 Hydrax::Hydrax* hydraxManager = parentWater->GetHydrax();
834 if(hydraxManager != 0 && hydraxManager->isCreated())
835 {
836 // Get the hydrax internal component state
837 bool hydraxComponentState = hydraxManager->isComponent(hydraxComponentType);
838
839 // Get sun light direction
840 Ogre::Vector3 sunLightDirecton = parentWater->GetEnvironment()->GetSun()->GetLightDirection();
841
842 // Get sun colour
843 Ogre::Vector3 sunColourAsVector(0.0f, 0.0f, 0.0f);
844 if(sunLightDirecton.y > -0.07)
845 {
846 // If the sun is above, get the sun light color, if below the horizon, set as black
847 Ogre::ColourValue tmpSunColour = parentWater->GetEnvironment()->GetSun()->GetLightColour();
848 sunColourAsVector = Ogre::Vector3(tmpSunColour.r, tmpSunColour.g, tmpSunColour.b);
849 }
850
851 if(hydraxComponentState == true)
852 {
853 // Update sun position
854 hydraxManager->setSunPosition(sunLightDirecton * 10000.0f);
855
856 // Update sun color
857 hydraxManager->setSunColor(sunColourAsVector);
858 }
859 }
860}
861
863{
864 Hydrax::Hydrax* hydraxManager = parentWater->GetHydrax();
865 if(hydraxManager != 0)
866 {
867 hydraxManager->setSunPosition(sunPosition);
868 hydraxManager->setSunStrength(sunStrength);
869 hydraxManager->setSunArea(sunArea);
870 Ogre::Vector3 sunColourAsVector(sunColor.r, sunColor.g, sunColor.b);
871 hydraxManager->setSunColor(sunColourAsVector);
872 }
873}
874
875/**********************************/
876/* Foam component functions */
877/**********************************/
878SWater::WaterComponentFoam::WaterComponentFoam(SWater* parentWaterInstance) : SWater::WaterComponent(parentWaterInstance, SWater::SO3_WATER_COMPONENT_FOAM, Hydrax::HYDRAX_COMPONENT_FOAM)
879{
880 SetParameters(75000000.0f, 0.075f, 0.0f, 1.0f);
881}
882
883SWater::WaterComponentFoam::WaterComponentFoam() : SWater::WaterComponent(0, SWater::SO3_WATER_COMPONENT_NONE, Hydrax::HYDRAX_COMPONENTS_NONE)
884{
885 // Forbiden constructor (private).
886}
887
888void SWater::WaterComponentFoam::SetParameters(const float& maxDistance, const float& scale, const float& start, const float& transparency)
889{
890 foamMaxDistance = maxDistance;
891 foamScale = scale;
892 foamStart = start;
893 foamTransparency = transparency;
894 ApplyParameters();
895}
896
898{
899 Hydrax::Hydrax* hydraxManager = parentWater->GetHydrax();
900 if(hydraxManager != 0)
901 foamMaxDistance = hydraxManager->getFoamMaxDistance();
902
903 return foamMaxDistance;
904}
905
906void SWater::WaterComponentFoam::SetMaxDistance(const float& maxDistance)
907{
908 foamMaxDistance = maxDistance;
909 Hydrax::Hydrax* hydraxManager = parentWater->GetHydrax();
910 if(hydraxManager != 0)
911 hydraxManager->setFoamMaxDistance(foamMaxDistance);
912}
913
915{
916 Hydrax::Hydrax* hydraxManager = parentWater->GetHydrax();
917 if(hydraxManager != 0)
918 foamScale = hydraxManager->getFoamScale();
919
920 return foamScale;
921}
922
924{
925 foamScale = scale;
926 Hydrax::Hydrax* hydraxManager = parentWater->GetHydrax();
927 if(hydraxManager != 0)
928 hydraxManager->setFoamScale(foamScale);
929}
930
932{
933 Hydrax::Hydrax* hydraxManager = parentWater->GetHydrax();
934 if(hydraxManager != 0)
935 foamStart = hydraxManager->getFoamStart();
936
937 return foamStart;
938}
939
941{
942 foamStart = start;
943 Hydrax::Hydrax* hydraxManager = parentWater->GetHydrax();
944 if(hydraxManager != 0)
945 hydraxManager->setFoamStart(foamStart);
946}
947
949{
950 Hydrax::Hydrax* hydraxManager = parentWater->GetHydrax();
951 if(hydraxManager != 0)
952 foamTransparency = hydraxManager->getFoamTransparency();
953
954 return foamTransparency;
955}
956
957void SWater::WaterComponentFoam::SetTransparency(const float& transparency)
958{
959 foamTransparency = transparency;
960 Hydrax::Hydrax* hydraxManager = parentWater->GetHydrax();
961 if(hydraxManager != 0)
962 hydraxManager->setFoamTransparency(foamTransparency);
963}
964
965void SWater::WaterComponentFoam::Update(const Ogre::Real& updateTime)
966{
968}
969
971{
972 Hydrax::Hydrax* hydraxManager = parentWater->GetHydrax();
973 if(hydraxManager != 0)
974 {
975 hydraxManager->setFoamMaxDistance(foamMaxDistance);
976 hydraxManager->setFoamScale(foamScale);
977 hydraxManager->setFoamStart(foamStart);
978 hydraxManager->setFoamTransparency(foamTransparency);
979 }
980}
981
982/**********************************/
983/* Depth component functions */
984/**********************************/
985SWater::WaterComponentDepth::WaterComponentDepth(SWater* parentWaterInstance) : SWater::WaterComponent(parentWaterInstance, SWater::SO3_WATER_COMPONENT_DEPTH, Hydrax::HYDRAX_COMPONENT_DEPTH)
986{
987 SetParameters(9.0f, 9.0f);
988}
989
990SWater::WaterComponentDepth::WaterComponentDepth() : SWater::WaterComponent(0, SWater::SO3_WATER_COMPONENT_NONE, Hydrax::HYDRAX_COMPONENTS_NONE)
991{
992 // Forbiden constructor (private).
993}
994
995void SWater::WaterComponentDepth::SetParameters(const float& depthLimit, const float& distanceLimit)
996{
997 depthLimitation = depthLimit;
998 distanceLimitation = distanceLimit;
999 ApplyParameters();
1000}
1001
1003{
1004 Hydrax::Hydrax* hydraxManager = parentWater->GetHydrax();
1005 if(hydraxManager != 0)
1006 depthLimitation = hydraxManager->getDepthLimit();
1007
1008 return depthLimitation;
1009}
1010
1012{
1013 depthLimitation = depthLimit;
1014 Hydrax::Hydrax* hydraxManager = parentWater->GetHydrax();
1015 if(hydraxManager != 0)
1016 hydraxManager->setDepthLimit(depthLimitation);
1017}
1018
1020{
1021 Hydrax::Hydrax* hydraxManager = parentWater->GetHydrax();
1022 if(hydraxManager != 0)
1023 distanceLimitation = hydraxManager->getDistLimit();
1024
1025 return distanceLimitation;
1026}
1027
1029{
1030 distanceLimitation = distanceLimit;
1031 Hydrax::Hydrax* hydraxManager = parentWater->GetHydrax();
1032 if(hydraxManager != 0)
1033 hydraxManager->setDistLimit(distanceLimitation);
1034}
1035
1036void SWater::WaterComponentDepth::Update(const Ogre::Real& updateTime)
1037{
1038 // TODO Depth should vary a little depending day or night.
1039}
1040
1042{
1043 Hydrax::Hydrax* hydraxManager = parentWater->GetHydrax();
1044 if(hydraxManager != 0)
1045 {
1046 hydraxManager->setDepthLimit(depthLimitation);
1047 hydraxManager->setDistLimit(distanceLimitation);
1048 }
1049
1050 // Smooth transitions and caustics components need depth component, so force the reactivation of those components if needed.
1051 parentWater->GetSmooth()->ApplyEnable();
1052 parentWater->GetCaustics()->ApplyEnable();
1053}
1054
1055/**********************************/
1056/* Smoothing component functions */
1057/**********************************/
1058SWater::WaterComponentSmooth::WaterComponentSmooth(SWater* parentWaterInstance) : SWater::WaterComponent(parentWaterInstance, SWater::SO3_WATER_COMPONENT_SMOOTH, Hydrax::HYDRAX_COMPONENT_SMOOTH)
1059{
1060 SetPower(5.0f);
1061}
1062
1063SWater::WaterComponentSmooth::WaterComponentSmooth() : SWater::WaterComponent(0, SWater::SO3_WATER_COMPONENT_NONE, Hydrax::HYDRAX_COMPONENTS_NONE)
1064{
1065 // Forbiden constructor (private).
1066}
1067
1069{
1070 Hydrax::Hydrax* hydraxManager = parentWater->GetHydrax();
1071 if(hydraxManager != 0)
1072 smoothPower = hydraxManager->getSmoothPower();
1073
1074 return smoothPower;
1075}
1076
1078{
1079 smoothPower = power;
1080 ApplyParameters();
1081}
1082
1083void SWater::WaterComponentSmooth::Update(const Ogre::Real& updateTime)
1084{
1085 // Nothing to do
1086}
1087
1089{
1090 Hydrax::Hydrax* hydraxManager = parentWater->GetHydrax();
1091 if(hydraxManager != 0)
1092 hydraxManager->setSmoothPower(smoothPower);
1093}
1094
1095/**********************************/
1096/* Caustics component functions */
1097/**********************************/
1098SWater::WaterComponentCaustics::WaterComponentCaustics(SWater* parentWaterInstance) : SWater::WaterComponent(parentWaterInstance, SWater::SO3_WATER_COMPONENT_CAUSTICS, Hydrax::HYDRAX_COMPONENT_CAUSTICS)
1099{
1100 SetParameters(2.35f, 5.0f, 0.55f);
1101}
1102
1103SWater::WaterComponentCaustics::WaterComponentCaustics() : SWater::WaterComponent(0, SWater::SO3_WATER_COMPONENT_NONE, Hydrax::HYDRAX_COMPONENTS_NONE)
1104{
1105 // Forbiden constructor (private).
1106}
1107
1108void SWater::WaterComponentCaustics::SetParameters(const float& scale, const float& power, const float& end)
1109{
1110 causticsScale = scale;
1111 causticsPower = power;
1112 causticsEnd = end;
1113 ApplyParameters();
1114}
1115
1117{
1118 Hydrax::Hydrax* hydraxManager = parentWater->GetHydrax();
1119 if(hydraxManager != 0)
1120 causticsScale = hydraxManager->getCausticsScale();
1121
1122 return causticsScale;
1123}
1124
1126{
1127 causticsScale = scale;
1128 Hydrax::Hydrax* hydraxManager = parentWater->GetHydrax();
1129 if(hydraxManager != 0)
1130 hydraxManager->setCausticsScale(causticsScale);
1131}
1132
1134{
1135 Hydrax::Hydrax* hydraxManager = parentWater->GetHydrax();
1136 if(hydraxManager != 0)
1137 causticsPower = hydraxManager->getCausticsPower();
1138
1139 return causticsPower;
1140}
1141
1143{
1144 causticsPower = power;
1145 Hydrax::Hydrax* hydraxManager = parentWater->GetHydrax();
1146 if(hydraxManager != 0)
1147 hydraxManager->setCausticsPower(causticsPower);
1148}
1149
1151{
1152 Hydrax::Hydrax* hydraxManager = parentWater->GetHydrax();
1153 if(hydraxManager != 0)
1154 causticsEnd = hydraxManager->getCausticsEnd();
1155
1156 return causticsEnd;
1157}
1158
1160{
1161 causticsEnd = end;
1162 Hydrax::Hydrax* hydraxManager = parentWater->GetHydrax();
1163 if(hydraxManager != 0)
1164 hydraxManager->setCausticsEnd(causticsEnd);
1165}
1166
1167void SWater::WaterComponentCaustics::Update(const Ogre::Real& updateTime)
1168{
1169 // TODO Darker caustics (lower intensity) at night.
1170}
1171
1173{
1174 Hydrax::Hydrax* hydraxManager = parentWater->GetHydrax();
1175 if(hydraxManager != 0)
1176 {
1177 hydraxManager->setCausticsScale(causticsScale);
1178 hydraxManager->setCausticsPower(causticsPower);
1179 hydraxManager->setCausticsEnd(causticsEnd);
1180 }
1181}
1182
1183/**********************************/
1184/* Underwater component functions */
1185/**********************************/
1186SWater::WaterComponentUnderwater::WaterComponentUnderwater(SWater* parentWaterInstance) : SWater::WaterComponent(parentWaterInstance, SWater::SO3_WATER_COMPONENT_UNDERWATER, Hydrax::HYDRAX_COMPONENT_UNDERWATER)
1187{
1188}
1189
1190SWater::WaterComponentUnderwater::WaterComponentUnderwater() : SWater::WaterComponent(0, SWater::SO3_WATER_COMPONENT_NONE, Hydrax::HYDRAX_COMPONENTS_NONE)
1191{
1192 // Forbiden constructor (private).
1193}
1194
1195void SWater::WaterComponentUnderwater::Update(const Ogre::Real& updateTime)
1196{
1197 // Nothing to do.
1198}
1199
1201{
1202 // Underwater reflections and god rays need underwater component, so force the reactivation of those components if needed.
1203 parentWater->GetUnderwaterReflections()->ApplyEnable();
1204 parentWater->GetGodRays()->ApplyEnable();
1205}
1206
1207/**********************************************/
1208/* Underwater reflections component functions */
1209/**********************************************/
1210SWater::WaterComponentUnderwaterReflections::WaterComponentUnderwaterReflections(SWater* parentWaterInstance) : SWater::WaterComponent(parentWaterInstance, SWater::SO3_WATER_COMPONENT_UNDERWATER_REFLECTIONS, Hydrax::HYDRAX_COMPONENT_UNDERWATER_REFLECTIONS)
1211{
1212}
1213
1214SWater::WaterComponentUnderwaterReflections::WaterComponentUnderwaterReflections() : SWater::WaterComponent(0, SWater::SO3_WATER_COMPONENT_NONE, Hydrax::HYDRAX_COMPONENTS_NONE)
1215{
1216 // Forbiden constructor (private).
1217}
1218
1220{
1221 // Nothing to do.
1222}
1223
1228
1229/**********************************/
1230/* God rays component functions */
1231/**********************************/
1232SWater::WaterComponentGodRays::WaterComponentGodRays(SWater* parentWaterInstance) : SWater::WaterComponent(parentWaterInstance, SWater::SO3_WATER_COMPONENT_GODRAYS, Hydrax::HYDRAX_COMPONENT_UNDERWATER_GODRAYS)
1233{
1234 // Init default params.
1235 SetParameters(Ogre::Vector3(0.76f, 12.46f, 12.29f), 0.015f, 1.0f, 100, 0.0254f, true);
1236}
1237
1238SWater::WaterComponentGodRays::WaterComponentGodRays() : SWater::WaterComponent(0, SWater::SO3_WATER_COMPONENT_NONE, Hydrax::HYDRAX_COMPONENTS_NONE)
1239{
1240 // Forbiden constructor (private).
1241}
1242
1243void SWater::WaterComponentGodRays::SetParameters(const Ogre::Vector3& exposure, const float& intensity, const float& speed, const int& numberOfRays, const float& raysSize, const bool& raysIntersections)
1244{
1245 godRaysExposure = exposure;
1246 godRaysIntensity = intensity;
1247 godRaysSpeed = speed;
1248 godRaysNumberOfRays = numberOfRays;
1249 godRaysRaysSize = raysSize;
1250 godRaysRaysIntersections = raysIntersections;
1251 ApplyParameters();
1252}
1253
1255{
1256 Hydrax::Hydrax* hydraxManager = parentWater->GetHydrax();
1257 if(hydraxManager != 0)
1258 {
1259 hydraxManager->setGodRaysExposure(godRaysExposure);
1260 hydraxManager->setGodRaysIntensity(godRaysIntensity);
1261 hydraxManager->getGodRaysManager()->setSimulationSpeed(godRaysSpeed);
1262 hydraxManager->getGodRaysManager()->setNumberOfRays(godRaysNumberOfRays);
1263 hydraxManager->getGodRaysManager()->setRaysSize(godRaysRaysSize);
1264 hydraxManager->getGodRaysManager()->setObjectIntersectionsEnabled(godRaysRaysIntersections);
1265 }
1266}
1267
1269{
1270 Hydrax::Hydrax* hydraxManager = parentWater->GetHydrax();
1271 if(hydraxManager != 0)
1272 godRaysExposure = hydraxManager->getGodRaysExposure();
1273
1274 return godRaysExposure;
1275}
1276
1277void SWater::WaterComponentGodRays::SetExposure(const Ogre::Vector3& exposure)
1278{
1279 godRaysExposure = exposure;
1280 Hydrax::Hydrax* hydraxManager = parentWater->GetHydrax();
1281 if(hydraxManager != 0)
1282 hydraxManager->setGodRaysExposure(godRaysExposure);
1283}
1284
1286{
1287 Hydrax::Hydrax* hydraxManager = parentWater->GetHydrax();
1288 if(hydraxManager != 0)
1289 godRaysIntensity = hydraxManager->getGodRaysIntensity();
1290
1291 return godRaysIntensity;
1292}
1293
1295{
1296 godRaysIntensity = intensity;
1297 Hydrax::Hydrax* hydraxManager = parentWater->GetHydrax();
1298 if(hydraxManager != 0)
1299 hydraxManager->setGodRaysIntensity(godRaysIntensity);
1300}
1301
1303{
1304 Hydrax::Hydrax* hydraxManager = parentWater->GetHydrax();
1305 if(hydraxManager != 0)
1306 godRaysSpeed = hydraxManager->getGodRaysManager()->getSimulationSpeed();
1307
1308 return godRaysSpeed;
1309}
1310
1312{
1313 godRaysSpeed = speed;
1314 Hydrax::Hydrax* hydraxManager = parentWater->GetHydrax();
1315 if(hydraxManager != 0)
1316 hydraxManager->getGodRaysManager()->setSimulationSpeed(godRaysSpeed);
1317}
1318
1320{
1321 Hydrax::Hydrax* hydraxManager = parentWater->GetHydrax();
1322 if(hydraxManager != 0)
1323 godRaysNumberOfRays = hydraxManager->getGodRaysManager()->getNumberOfRays();
1324
1325 return godRaysNumberOfRays;
1326}
1327
1329{
1330 godRaysNumberOfRays = numberOfRays;
1331 Hydrax::Hydrax* hydraxManager = parentWater->GetHydrax();
1332 if(hydraxManager != 0)
1333 hydraxManager->getGodRaysManager()->setNumberOfRays(godRaysNumberOfRays);
1334}
1335
1337{
1338 Hydrax::Hydrax* hydraxManager = parentWater->GetHydrax();
1339 if(hydraxManager != 0)
1340 godRaysRaysSize = hydraxManager->getGodRaysManager()->getRaysSize();
1341
1342 return godRaysRaysSize;
1343}
1344
1346{
1347 godRaysRaysSize = raysSize;
1348 Hydrax::Hydrax* hydraxManager = parentWater->GetHydrax();
1349 if(hydraxManager != 0)
1350 hydraxManager->getGodRaysManager()->setRaysSize(godRaysRaysSize);
1351}
1352
1354{
1355 Hydrax::Hydrax* hydraxManager = parentWater->GetHydrax();
1356 if(hydraxManager != 0)
1357 godRaysRaysIntersections = hydraxManager->getGodRaysManager()->areObjectsIntersectionsEnabled();
1358
1359 return godRaysRaysIntersections;
1360}
1361
1363{
1364 godRaysRaysIntersections = raysIntersections;
1365 Hydrax::Hydrax* hydraxManager = parentWater->GetHydrax();
1366 if(hydraxManager != 0)
1367 hydraxManager->getGodRaysManager()->setObjectIntersectionsEnabled(godRaysRaysIntersections);
1368}
1369
1370void SWater::WaterComponentGodRays::Update(const Ogre::Real& updateTime)
1371{
1372 // Nothing to do.
1373}
1374
1376{
1377 if(viewport != renderingViewport)
1378 return;
1379
1380 // Deactivate Hydrax if needed.
1381 SetEnableImpl(false);
1382
1383 // Enable Hydrax if needeed
1385}
1386
1387void SWater::Update(const Ogre::Real& updateTime)
1388{
1389 // Update Hydrax
1390 if(hydraxManager != 0 && hydraxManager->isCreated())
1391 {
1392 // First, give the elapsed time to hydrax:
1393 hydraxManager->update(updateTime);
1394
1395 // Update water color
1396 Ogre::ColourValue ogreColourValue = waterColourGradient.GetColour(std::max(parentEnvironment->GetSun()->GetLightDirection().y, 0.0f));
1397 hydraxManager->setWaterColor(Ogre::Vector3(ogreColourValue.r, ogreColourValue.g, ogreColourValue.b));
1398
1399 // Pause the water rendering?
1401 hydraxManager->setTimeMultiplier(0.0f);
1402 else
1403 hydraxManager->setTimeMultiplier(wavesAnimationSpeed);
1404
1405 // Change hydrax noise module if necessary
1406 float newWindSpeed = parentEnvironment->GetWindSpeed();
1407 /*if((newWindSpeed == 0.0f) && (hydraxNoise->getName() != "Perlin"))
1408 {
1409 // Old Hydrax noise module is automatically deleted.
1410 Hydrax::Noise::Noise* newHydraxNoise = CreatePerlinNoise();
1411 hydraxGeometry->setNoise(newHydraxNoise, hydraxManager->getGPUNormalMapManager());
1412 hydraxNoise = newHydraxNoise;
1413 }
1414 else
1415 {
1416 if((newWindSpeed > 0.0f) && (hydraxNoise->getName() != "FFT"))
1417 {
1418 Hydrax::Noise::Noise* newHydraxNoise = CreateFftNoise();
1419 hydraxGeometry->setNoise(newHydraxNoise, hydraxManager->getGPUNormalMapManager());
1420 hydraxNoise = newHydraxNoise;
1421 }
1422 }*/
1423
1424 // TODO Change wave rendering
1425 /*if(newWindSpeed > 0.0f)
1426 {
1427 fftNoiseOptions.Amplitude = ?;
1428 fftNoiseOptions.AnimationSpeed = ?
1429 fftNoiseOptions.Amplitude ? We 'may' use windDirection.y to modify amplitude...
1430 }*/
1431
1432 // Apply noise options
1433 Ogre::Vector2 newWindDirection = parentEnvironment->GetWindDirection() * parentEnvironment->GetWindSpeed();
1434 if(cachedWindDirection != newWindDirection)
1435 {
1436 if(hydraxNoise->getName() == "REAL")
1437 (static_cast<Hydrax::Noise::Real*> (hydraxNoise))->modifyWave(0, parentEnvironment->GetWindDirection(), 0.01, 4.0, 0.5);
1438
1439 fftNoiseOptions.WindDirection = newWindDirection;
1440 cachedWindDirection = newWindDirection;
1441
1442 if(hydraxNoise->getName() == "FFT")
1443 {
1444 try
1445 {
1446 (static_cast<Hydrax::Noise::FFT*> (hydraxNoise))->setOptions(fftNoiseOptions);
1447 }
1448 catch(Ogre::Exception)
1449 {
1450 }
1451 }
1452 }
1453
1454 // No wind direction
1455 //(static_cast<Hydrax::Noise::Perlin*> (hydraxNoise))->setOptions(perlinNoiseOptions);
1456
1457 // Update all active water components. Order is important!!!
1458 if(sunComponent->GetEnabled())
1459 sunComponent->Update(updateTime);
1460
1461 if(foamComponent->GetEnabled())
1462 foamComponent->Update(updateTime);
1463
1464 if(depthComponent->GetEnabled())
1465 depthComponent->Update(updateTime);
1466
1467 if(smoothComponent->GetEnabled())
1468 smoothComponent->Update(updateTime);
1469
1470 if(causticsComponent->GetEnabled())
1471 causticsComponent->Update(updateTime);
1472
1473 if(underwaterComponent->GetEnabled())
1474 underwaterComponent->Update(updateTime);
1475
1476 if(godRaysComponent->GetEnabled())
1477 godRaysComponent->Update(updateTime);
1478 }
1479}
1480
1481Ogre::Vector3 SWater::GetPosition()
1482{
1483 if(hydraxManager != 0)
1484 waterPlanePosition = hydraxManager->getPosition();
1485
1486 return waterPlanePosition;
1487}
1488
1489void SWater::SetPosition(const Ogre::Vector3& newSeaLevel)
1490{
1491 // avoid the projection grid bug with the same level
1492 if (waterPlanePosition != newSeaLevel)
1493 {
1494 waterPlanePosition = newSeaLevel;
1495 if(hydraxManager != 0)
1496 hydraxManager->setPosition(newSeaLevel);
1497 }
1498}
1499
1500Ogre::ColourValue SWater::GetColor()
1501{
1502 return baseColour;
1503}
1504
1505void SWater::SetColor(const Ogre::ColourValue& color)
1506{
1507 baseColour = color;
1508 RefreshWaterColourGradient();
1509}
1510
1512{
1513 if(hydraxManager)
1514 wavesAnimationSpeed = hydraxManager->getTimeMultiplier();
1515
1516 return wavesAnimationSpeed;
1517}
1518
1519void SWater::SetAnimationSpeed(const float& animationSpeed)
1520{
1521 wavesAnimationSpeed = animationSpeed;
1522 if(hydraxManager != 0)
1523 hydraxManager->setTimeMultiplier(wavesAnimationSpeed);
1524}
1525
1526Hydrax::Noise::Noise* SWater::CreatePerlinNoise()
1527{
1528 return new Hydrax::Noise::Perlin(perlinNoiseOptions);
1529}
1530
1531Hydrax::Noise::Noise* SWater::CreateFftNoise()
1532{
1533 return new Hydrax::Noise::FFT(fftNoiseOptions);
1534}
1535
1536Hydrax::Noise::Noise* SWater::CreateRealNoise()
1537{
1538 return new Hydrax::Noise::Real();
1539}
1540
1541void SWater::preRenderTargetUpdate(const Hydrax::RttManager::RttType& Rtt)
1542{
1543 SSky* sky = parentEnvironment->GetSky();
1544 if(sky)
1545 {
1546 SkyX::SkyX* skyxManager = sky->GetSkyX();
1547 if(skyxManager != 0)
1548 {
1549
1550 switch (Rtt)
1551 {
1552 case Hydrax::RttManager::RTT_REFLECTION:
1553 {
1554 // No stars in the reflection map
1555 skyxManager->setStarfieldEnabled(false);
1556 }
1557 break;
1558
1559 case Hydrax::RttManager::RTT_REFRACTION:
1560 {
1561 }
1562 break;
1563
1564 case Hydrax::RttManager::RTT_DEPTH:
1565 case Hydrax::RttManager::RTT_DEPTH_REFLECTION:
1566 {
1567 // Hide SkyX components in depth maps
1568 if (hydraxManager && !hydraxManager->_isCurrentFrameUnderwater())
1569 {
1570 skyxManager->getMeshManager()->getEntity()->setVisible(false);
1571 skyxManager->getMoonManager()->getMoonBillboard()->setVisible(false);
1572 }
1573 }
1574 break;
1575 }
1576 }
1577 }
1578}
1579
1580void SWater::postRenderTargetUpdate(const Hydrax::RttManager::RttType& Rtt)
1581{
1582 SSky* sky = parentEnvironment->GetSky();
1583 if(sky)
1584 {
1585 SkyX::SkyX* skyxManager = sky->GetSkyX();
1586 if(skyxManager != 0)
1587 {
1588 switch (Rtt)
1589 {
1590 case Hydrax::RttManager::RTT_REFLECTION:
1591 {
1592 skyxManager->setStarfieldEnabled(true);
1593 }
1594 break;
1595
1596 case Hydrax::RttManager::RTT_REFRACTION:
1597 {
1598 }
1599 break;
1600
1601 case Hydrax::RttManager::RTT_DEPTH:
1602 case Hydrax::RttManager::RTT_DEPTH_REFLECTION:
1603 {
1604 if (hydraxManager && !hydraxManager->_isCurrentFrameUnderwater())
1605 {
1606 skyxManager->getMeshManager()->getEntity()->setVisible(true);
1607 skyxManager->getMoonManager()->getMoonBillboard()->setVisible(true);
1608 }
1609 }
1610 break;
1611 }
1612 }
1613 }
1614}
1615
1616void SWater::preViewportUpdate(const Ogre::RenderTargetViewportEvent& evt)
1617{
1618}
1619
1620}
int nheight
Definition SO3SCOL.cpp:5095
int nwidth
Definition SO3SCOL.cpp:5094
void AddColourFrame(const ColourFrame &colourFrame)
const Ogre::ColourValue GetColour(const float &gradientPosition) const
void _NotifyEnvironmentComponentRegisterRenderTarget(Ogre::Viewport *targetViewport)
Ogre::Vector2 GetWindDirection()
Ogre::SceneManager * GetOgreScenePointer()
Definition SO3Scene.cpp:449
SkyX::SkyX * GetSkyX()
Definition SO3Sky.cpp:230
const Ogre::Vector3 GetLightDirection() const
void RegisterStereoViewport()
void UnregisterStereoViewport()
bool IsStereoViewportRegistered()
Ogre::Viewport * GetOgreViewPortPointer()
void SetScale(const float &scale)
void SetPower(const float &power)
void SetEnd(const float &end)
virtual void Update(const Ogre::Real &updateTime)
void SetParameters(const float &scale, const float &power, const float &end)
virtual void Update(const Ogre::Real &updateTime)
void SetDistanceLimit(const float &distanceLimit)
void SetParameters(const float &depthLimit, const float &distanceLimit)
Definition SO3Water.cpp:995
void SetDepthLimit(const float &depthLimit)
void SetScale(const float &scale)
Definition SO3Water.cpp:923
virtual void Update(const Ogre::Real &updateTime)
Definition SO3Water.cpp:965
void SetStart(const float &start)
Definition SO3Water.cpp:940
void SetMaxDistance(const float &maxDistance)
Definition SO3Water.cpp:906
void SetTransparency(const float &transparency)
Definition SO3Water.cpp:957
void SetParameters(const float &maxDistance, const float &scale, const float &start, const float &transparency)
Definition SO3Water.cpp:888
void SetRaysIntersectionEnable(const bool &raysIntersections)
void SetSpeed(const float &speed)
void SetNumberOfRays(const int &numberOfRays)
void SetRaysSize(const float &raysSize)
void SetParameters(const Ogre::Vector3 &exposure, const float &intensity, const float &speed, const int &numberOfRays, const float &raysSize, const bool &raysIntersections)
virtual void Update(const Ogre::Real &updateTime)
void SetExposure(const Ogre::Vector3 &exposure)
void SetIntensity(const float &intensity)
void SetEnabled(const bool &enable)
Definition SO3Water.cpp:707
SWater::WaterComponentType GetType()
Definition SO3Water.cpp:729
virtual void Update(const Ogre::Real &updateTime)
void SetPower(const float &power)
void SetArea(const float &area)
Definition SO3Water.cpp:800
void SetStrength(const float &strength)
Definition SO3Water.cpp:783
Ogre::ColourValue GetColor()
Definition SO3Water.cpp:808
void SetPosition(const Ogre::Vector3 &position)
Definition SO3Water.cpp:766
virtual void Update(const Ogre::Real &updateTime)
Definition SO3Water.cpp:831
void SetParameters(const Ogre::Vector3 &position, const float &strength, const float &area, const Ogre::ColourValue &color)
Definition SO3Water.cpp:748
void SetColor(const Ogre::ColourValue &color)
Definition SO3Water.cpp:820
virtual void Update(const Ogre::Real &updateTime)
virtual void Update(const Ogre::Real &updateTime)
Hydrax::Hydrax * GetHydrax()
Definition SO3Water.cpp:341
void SetGeometryTypeFinitePlane(const int &planeSizeX, const int &planeSizeY)
Definition SO3Water.cpp:556
virtual void SetEnableImpl(const bool &enableComponent)
Definition SO3Water.cpp:237
void SetInfinitePlaneChoppyStrength(const float &value)
Definition SO3Water.cpp:540
virtual void UpdateCamera(SViewPort *viewport)
WaterComponentSun * GetSun()
Definition SO3Water.cpp:382
virtual void preRenderTargetUpdate(const Hydrax::RttManager::RttType &Rtt)
WaterComponentDepth * GetDepth()
Definition SO3Water.cpp:392
@ SO3_WATER_GEOM_FINITE_PLANE
Definition SO3Water.h:59
@ SO3_WATER_GEOM_RADIAL
Definition SO3Water.h:60
@ SO3_WATER_GEOM_INFINITE_PLANE
Definition SO3Water.h:58
WaterComponentGodRays * GetGodRays()
Definition SO3Water.cpp:417
WaterComponentCaustics * GetCaustics()
Definition SO3Water.cpp:402
void AddViewport(Ogre::Viewport *viewport)
Definition SO3Water.cpp:309
float GetInfinitePlaneChoppyStrength()
Definition SO3Water.cpp:535
float GetAnimationSpeed()
void SetAnimationSpeed(const float &animationSpeed)
void RemoveViewport(Ogre::Viewport *viewport)
Definition SO3Water.cpp:315
Ogre::Vector3 GetPosition()
void ApplyHydraxComponentTypes()
Definition SO3Water.cpp:639
float GetInfinitePlaneComplexity()
Definition SO3Water.cpp:514
WaterComponent * GetComponent(const SWater::WaterComponentType &componentType)
Definition SO3Water.cpp:346
void SetColor(const Ogre::ColourValue &color)
virtual void RegisterViewportImpl(SViewPort *viewport)
Definition SO3Water.cpp:321
virtual void postRenderTargetUpdate(const Hydrax::RttManager::RttType &Rtt)
Hydrax::Noise::FFT::Options GetFFTOptions()
Definition SO3Water.cpp:441
void SetInfinitePlaneComplexity(const float &value)
Definition SO3Water.cpp:519
Ogre::ColourValue GetColor()
virtual void UnregisterViewportImpl(SViewPort *viewport)
Definition SO3Water.cpp:328
void SetGeometryTypeRadialPlane(const float &waterRadius)
Definition SO3Water.cpp:561
float GetInfinitePlaneStrength()
Definition SO3Water.cpp:470
void SetInfinitePlaneElevation(const float &value)
Definition SO3Water.cpp:498
WaterComponentFoam * GetFoam()
Definition SO3Water.cpp:387
void SetFFTOptions(const Hydrax::Noise::FFT::Options &newOptions)
Definition SO3Water.cpp:446
WaterComponentUnderwaterReflections * GetUnderwaterReflections()
Definition SO3Water.cpp:412
void SetGeometryTypeInfinitePlane()
Definition SO3Water.cpp:465
float GetInfinitePlaneElevation()
Definition SO3Water.cpp:493
WaterGeometryType GetGeometryType()
Definition SO3Water.cpp:460
void SetPosition(const Ogre::Vector3 &newSeaLevel)
virtual void Update(const Ogre::Real &updateTime)
void SetInfinitePlaneStrength(const float &value)
Definition SO3Water.cpp:475
WaterComponentSmooth * GetSmooth()
Definition SO3Water.cpp:397
virtual void preViewportUpdate(const Ogre::RenderTargetViewportEvent &evt)
Hydrax::Noise::Perlin::Options GetPerlinOptions()
Definition SO3Water.cpp:422
void SetPerlinOptions(const Hydrax::Noise::Perlin::Options &newOptions)
Definition SO3Water.cpp:427
WaterComponentUnderwater * GetUnderwater()
Definition SO3Water.cpp:407
@ SO3_WATER_COMPONENT_UNDERWATER
Definition SO3Water.h:73
@ SO3_WATER_COMPONENT_CAUSTICS
Definition SO3Water.h:72
@ SO3_WATER_COMPONENT_DEPTH
Definition SO3Water.h:70
@ SO3_WATER_COMPONENT_SMOOTH
Definition SO3Water.h:71
@ SO3_WATER_COMPONENT_GODRAYS
Definition SO3Water.h:75
@ SO3_WATER_COMPONENT_NONE
Definition SO3Water.h:67
@ SO3_WATER_COMPONENT_FOAM
Definition SO3Water.h:69
@ SO3_WATER_COMPONENT_SUN
Definition SO3Water.h:68
@ SO3_WATER_COMPONENT_UNDERWATER_REFLECTIONS
Definition SO3Water.h:74