Project

General

Profile

SO3Engine
SO3Water.h
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#ifndef __SO3WATER_H__
33#define __SO3WATER_H__
34
38#include "Hydrax.h"
39#include "Modules/ProjectedGrid/HydraxProjectedGrid.h"
40#include "Modules/RadialGrid/HydraxRadialGrid.h"
41#include "Modules/SimpleGrid/HydraxSimpleGrid.h"
42#include "Noise/Perlin/HydraxPerlin.h"
43#include "Noise/FFT/HydraxFFT.h"
44#include "Noise/Real/HydraxReal.h"
45
46namespace SO3
47{
48
49class _SO3_Export SWater : public SEnvironmentComponent,
50 public Hydrax::RttManager::RttListener,
51 public Ogre::RenderTargetListener
52{
53public:
57 {
58 SO3_WATER_GEOM_INFINITE_PLANE, //<! Infinite plane surface
59 SO3_WATER_GEOM_FINITE_PLANE, //<! Sized plane surface
60 SO3_WATER_GEOM_RADIAL //<! Radial surface (circle)
61 };
62
77
82 {
83 public:
84 protected:
86 const Hydrax::HydraxComponent hydraxComponentType;
88 private:
89 bool waterComponentEnable;
90
91 public:
94 WaterComponent(SWater* parentWaterInstance, const SWater::WaterComponentType& component, const Hydrax::HydraxComponent& hydraxComponent);
95
98 virtual ~WaterComponent();
99
103 bool GetEnabled();
104
108 void SetEnabled(const bool& enable);
109
112 void ApplyEnable();
113
117
120 virtual void Update(const Ogre::Real& updateTime)=0;
121 protected:
124 virtual void ApplyParameters()=0;
125 private:
130 };
131
136 {
137 public:
138 protected:
139 private:
140 Ogre::Plane horizonPlane;
141 Ogre::Vector3 sunPosition;
142 float sunStrength;
143 float sunArea;
144 Ogre::ColourValue sunColor;
145
146 public:
149 WaterComponentSun(SWater* parentWaterInstance);
150
153 void SetParameters(const Ogre::Vector3& position, const float& strength, const float& area, const Ogre::ColourValue& color);
154
157 Ogre::Vector3 GetPosition();
158
161 void SetPosition(const Ogre::Vector3& position);
162
165 float GetStrength();
166
169 void SetStrength(const float& strength);
170
173 float GetArea();
174
177 void SetArea(const float& area);
178
181 Ogre::ColourValue GetColor();
182
185 void SetColor(const Ogre::ColourValue& color);
186
189 virtual void Update(const Ogre::Real& updateTime);
190 protected:
193 virtual void ApplyParameters();
194 private:
199 };
200
205 {
206 public:
207 protected:
208 private:
209 float foamMaxDistance;
210 float foamScale;
211 float foamStart;
212 float foamTransparency;
213
214 public:
217 WaterComponentFoam(SWater* parentWaterInstance);
218
221 void SetParameters(const float& maxDistance, const float& scale, const float& start, const float& transparency);
222
225 float GetMaxDistance();
226
229 void SetMaxDistance(const float& maxDistance);
230
233 float GetScale();
234
237 void SetScale(const float& scale);
238
241 float GetStart();
242
245 void SetStart(const float& start);
246
249 float GetTransparency();
250
253 void SetTransparency(const float& transparency);
254
257 virtual void Update(const Ogre::Real& updateTime);
258 protected:
261 virtual void ApplyParameters();
262 private:
267 };
268
273 {
274 public:
275 protected:
276 private:
277 float depthLimitation;
278 float distanceLimitation;
279
280 public:
283 WaterComponentDepth(SWater* parentWaterInstance);
284
287 void SetParameters(const float& depthLimit, const float& distanceLimit);
288
291 float GetDepthLimit();
292
295 void SetDepthLimit(const float& depthLimit);
296
299 void SetDistanceLimit(const float& distanceLimit);
300
303 float GetDistanceLimit();
304
307 virtual void Update(const Ogre::Real& updateTime);
308 protected:
311 virtual void ApplyParameters();
312 private:
317 };
318
323 {
324 public:
325 protected:
326 private:
327 float smoothPower;
328
329 public:
332 WaterComponentSmooth(SWater* parentWaterInstance);
333
336 float GetPower();
337
340 void SetPower(const float& power);
341
344 virtual void Update(const Ogre::Real& updateTime);
345 protected:
348 virtual void ApplyParameters();
349 private:
354 };
355
360 {
361 public:
362 protected:
363 private:
364 float causticsScale;
365 float causticsPower;
366 float causticsEnd;
367
368 public:
371 WaterComponentCaustics(SWater* parentWaterInstance);
372
375 void SetParameters(const float& scale, const float& power, const float& end);
376
379 float GetScale();
380
383 void SetScale(const float& scale);
384
387 float GetPower();
388
391 void SetPower(const float& power);
392
395 float GetEnd();
396
399 void SetEnd(const float& end);
400
403 virtual void Update(const Ogre::Real& updateTime);
404 protected:
407 virtual void ApplyParameters();
408 private:
413 };
414
419 {
420 public:
421 protected:
422 private:
423
424 public:
427 WaterComponentUnderwater(SWater* parentWaterInstance);
428
431 virtual void Update(const Ogre::Real& updateTime);
432 protected:
435 virtual void ApplyParameters();
436 private:
441 };
442
447 {
448 public:
449 protected:
450 private:
451
452 public:
455 WaterComponentUnderwaterReflections(SWater* parentWaterInstance);
456
459 virtual void Update(const Ogre::Real& updateTime);
460 protected:
463 virtual void ApplyParameters();
464 private:
469 };
470
475 {
476 public:
477 protected:
478 private:
479 Ogre::Vector3 godRaysExposure;
480 float godRaysIntensity;
481 float godRaysSpeed;
482 int godRaysNumberOfRays;
483 float godRaysRaysSize;
484 bool godRaysRaysIntersections;
485
486 public:
489 WaterComponentGodRays(SWater* parentWaterInstance);
490
493 void SetParameters(const Ogre::Vector3& exposure, const float& intensity, const float& speed, const int& numberOfRays, const float& raysSize, const bool& raysIntersections);
494
497 Ogre::Vector3 GetExposure();
498
501 void SetExposure(const Ogre::Vector3& exposure);
502
505 float GetIntensity();
506
509 void SetIntensity(const float& intensity);
510
513 float GetSpeed();
514
517 void SetSpeed(const float& speed);
518
521 int GetNumberOfRays();
522
525 void SetNumberOfRays(const int& numberOfRays);
526
529 float GetRaysSize();
530
533 void SetRaysSize(const float& raysSize);
534
537 bool GetRaysIntersectionEnable();
538
541 void SetRaysIntersectionEnable(const bool& raysIntersections);
542
545 virtual void Update(const Ogre::Real& updateTime);
546
547 protected:
550 virtual void ApplyParameters();
551 private:
556 };
557protected:
558private:
559 SScene* parentScene;
560 WaterComponentSun* sunComponent;
561 WaterComponentFoam* foamComponent;
562 WaterComponentDepth* depthComponent;
563 WaterComponentSmooth* smoothComponent;
564 WaterComponentCaustics* causticsComponent;
565 WaterComponentUnderwater* underwaterComponent;
566 WaterComponentUnderwaterReflections* underwaterReflectionsComponent;
567 WaterComponentGodRays* godRaysComponent;
568 WaterGeometryType actualGeometryType;
569 Hydrax::Hydrax* hydraxManager;
570 Hydrax::Module::Module* hydraxGeometry;
571 Hydrax::Module::ProjectedGrid::Options progGridOptions;
572
573 Hydrax::Noise::Noise* hydraxNoise;
574 Hydrax::Noise::Perlin::Options perlinNoiseOptions;
575 Hydrax::Noise::FFT::Options fftNoiseOptions;
576 SViewPort* renderingViewport;
577 Ogre::ColourValue baseColour;
578 SColourGradient waterColourGradient;
579 int finitePlaneWaterSizeX;
580 int finitePlaneWaterSizeY;
581 Ogre::Real radialWaterRadius;
582 Ogre::Vector3 waterPlanePosition;
583 float wavesAnimationSpeed;
584 Ogre::Vector2 cachedWindDirection;
585 bool IslastUnderWater;
586
587public:
591 SWater(SEnvironment* parent, const std::string& waterName);
592
596 SWater(SEnvironment* parent, const std::string& waterName, const int& planeSizeX, const int& planeSizeY);
597
601 SWater(SEnvironment* parent, const std::string& waterName, const float& waterRadius);
602
606 ~SWater();
607
611 Hydrax::Hydrax* GetHydrax();
612
616 WaterGeometryType GetGeometryType();
617
621 void SetGeometryTypeInfinitePlane();
622
625 float GetInfinitePlaneStrength();
626
629 void SetInfinitePlaneStrength(const float& value);
630
633 float GetInfinitePlaneElevation();
634
637 void SetInfinitePlaneElevation(const float& value);
638
641 float GetInfinitePlaneComplexity();
642
645 void SetInfinitePlaneComplexity(const float& value);
646
649 float GetInfinitePlaneChoppyStrength();
650
653 void SetInfinitePlaneChoppyStrength(const float& value);
654
658 void SetGeometryTypeFinitePlane(const int& planeSizeX, const int& planeSizeY);
659
663 void SetGeometryTypeRadialPlane(const float& waterRadius);
664
667 WaterComponent* GetComponent(const SWater::WaterComponentType& componentType);
668
671 WaterComponentSun* GetSun();
672
675 WaterComponentFoam* GetFoam();
676
679 WaterComponentDepth* GetDepth();
680
683 WaterComponentSmooth* GetSmooth();
684
687 WaterComponentCaustics* GetCaustics();
688
691 WaterComponentUnderwater* GetUnderwater();
692
695 WaterComponentUnderwaterReflections* GetUnderwaterReflections();
696
699 WaterComponentGodRays* GetGodRays();
700
704 Ogre::Vector3 GetPosition();
705
709 void SetPosition(const Ogre::Vector3& newSeaLevel);
710
713 Ogre::ColourValue GetColor();
714
717 void SetColor(const Ogre::ColourValue& color);
718
721 virtual void Update(const Ogre::Real& updateTime);
722
726 float GetAnimationSpeed();
727
731 void SetAnimationSpeed(const float& animationSpeed);
732
736 Hydrax::Noise::Perlin::Options GetPerlinOptions();
737
741 void SetPerlinOptions(const Hydrax::Noise::Perlin::Options& newOptions);
742
746 Hydrax::Noise::FFT::Options GetFFTOptions();
747
751 void SetFFTOptions(const Hydrax::Noise::FFT::Options& newOptions);
752
755 void ApplyHydraxComponentTypes();
756
759 virtual void preRenderTargetUpdate(const Hydrax::RttManager::RttType& Rtt);
760
763 virtual void postRenderTargetUpdate(const Hydrax::RttManager::RttType& Rtt);
764
768 virtual void preViewportUpdate(const Ogre::RenderTargetViewportEvent& evt);
769
772 virtual void UpdateCamera(SViewPort* viewport);
773
774 void AddViewport(Ogre::Viewport* viewport);
775
776 void RemoveViewport(Ogre::Viewport* viewport);
777
778protected:
782 virtual void SetEnableImpl(const bool& enableComponent);
783
787 virtual void RegisterViewportImpl(SViewPort* viewport);
788
792 virtual void UnregisterViewportImpl(SViewPort* viewport);
793
794private:
798 SWater();
799
803 void CommonConstructorsSequence(const WaterGeometryType& selectedWaterGeometryType);
804
807 bool Initialize();
808
811 void CreateInfinitePlaneGeometry();
812
815 void CreateFinitePlaneGeometry(const int& planeSizeX, const int& planeSizeY);
816
817 /*
818 */
819 void CreateRadialPlaneGeometry(const float& waterRadius);
820
823 Hydrax::Noise::Noise* CreatePerlinNoise();
824
827 Hydrax::Noise::Noise* CreateFftNoise();
828
831 Hydrax::Noise::Noise* CreateRealNoise();
832
835 void RefreshWaterColourGradient();
836};
837
838}
839
840#endif
const Hydrax::HydraxComponent hydraxComponentType
Definition SO3Water.h:86
const SWater::WaterComponentType componentType
Definition SO3Water.h:87
virtual void Update(const Ogre::Real &updateTime)=0
virtual void ApplyParameters()=0
@ SO3_WATER_GEOM_FINITE_PLANE
Definition SO3Water.h:59
@ SO3_WATER_GEOM_INFINITE_PLANE
Definition SO3Water.h:58
@ 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_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