RigsofRods
Soft-body Physics Simulation
HydraxWater.cpp
Go to the documentation of this file.
1 /*
2  This source file is part of Rigs of Rods
3  Copyright 2005-2012 Pierre-Michel Ricordel
4  Copyright 2007-2012 Thomas Fischer
5  Copyright 2013-2016 Petr Ohlidal
6 
7  For more information, see http://www.rigsofrods.org/
8  Rigs of Rods is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License version 3, as
10  published by the Free Software Foundation.
11 
12  Rigs of Rods is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 #include "HydraxWater.h"
22 
23 #include "Actor.h"
24 #include "AppContext.h"
25 #include "CameraManager.h"
26 #include "GameContext.h"
27 #include "GfxScene.h"
28 #include "SkyManager.h"
29 #include "Terrain.h"
30 
31 #ifdef USE_CAELUM
32 #include <Caelum.h>
33 #endif // USE_CAELUM
34 
35 using namespace Ogre;
36 using namespace RoR;
37 
38 // HydraxWater
39 HydraxWater::HydraxWater(float water_height, Ogre::String conf_file):
40  waternoise(0)
41  , mHydrax(0)
42  , waterHeight(water_height)
43  , waveHeight(water_height)
44  , CurrentConfigFile(conf_file)
45 {
46  App::GetCameraManager()->GetCamera()->setNearClipDistance(0.1f);
47 
48  InitHydrax();
49 }
50 
52 {
53  mHydrax->remove();
54  mHydrax = nullptr;
55 }
56 
58 {
59  mHydrax = new Hydrax::Hydrax(App::GetGfxScene()->GetSceneManager(), App::GetCameraManager()->GetCamera(), RoR::App::GetAppContext()->GetViewport());
60 
62  mModule = new Hydrax::Module::ProjectedGrid(// Hydrax parent pointer
63  mHydrax,
64  // Noise module
65  waternoise,
66  // Base plane
67  Ogre::Plane(Ogre::Vector3::UNIT_Y, 0),
68  // Normal mode
70  // Projected grid options
72 
74 
76 
77  // Choose shader language based on renderer (HLSL=0, CG=1, GLSL=2)
78  if (Root::getSingleton().getRenderSystem()->getName() == "Direct3D9 Rendering Subsystem" || Root::getSingleton().getRenderSystem()->getName() == "Direct3D11 Rendering Subsystem")
79  {
81  }
82  else
83  {
85  }
86 
87  mHydrax->create();
88  mHydrax->setPosition(Ogre::Vector3(0, waterHeight, 0));
89 }
90 
91 bool HydraxWater::IsUnderWater(Ogre::Vector3 pos)
92 {
93  if (pos.y < CalcWavesHeight(Ogre::Vector3(pos.x, pos.y, pos.z)))
94  return true;
95  return false;
96 }
97 
99 {
100 #ifdef USE_CAELUM
101  if (RoR::App::GetGameContext()->GetTerrain()->getSkyManager() != nullptr)
102  {
103  SkyManager* sky = RoR::App::GetGameContext()->GetTerrain()->getSkyManager();
104  Ogre::Vector3 sunPosition = App::GetCameraManager()->GetCameraNode()->_getDerivedPosition();
105  sunPosition -= sky->GetCaelumSys()->getSun()->getLightDirection() * 80000;
106  mHydrax->setSunPosition(sunPosition);
107  mHydrax->setSunColor(Ogre::Vector3(sky->GetCaelumSys()->getSun()->getBodyColour().r, sky->GetCaelumSys()->getSun()->getBodyColour().g, sky->GetCaelumSys()->getSun()->getBodyColour().b));
108  }
109 #endif // USE_CAELUM
110 }
111 
113 {
114  return waterHeight;
115 }
116 
118 {
119  waterHeight = value;
120 }
121 
123 {
124  if (mHydrax)
125  mHydrax->setVisible(value);
126 }
127 
129 {
130  if (!RoR::App::gfx_water_waves->getBool())
131  {
132  return waterHeight;
133  }
134  waveHeight = mHydrax->getHeigth(pos);
135  return waveHeight;
136 }
137 
138 Vector3 HydraxWater::CalcWavesVelocity(Vector3 pos)
139 {
140  if (!RoR::App::gfx_water_waves->getBool())
141  return Vector3(0, 0, 0);
142 
143  return Vector3(0, 0, 0); //TODO
144 }
145 
146 void HydraxWater::WaterSetSunPosition(Ogre::Vector3 pos)
147 {
148  if (mHydrax)
149  mHydrax->setSunPosition(pos);
150 }
151 
153 {
154  if (mHydrax)
155  {
156  mHydrax->update(dt);
157  }
158  this->UpdateWater();
159 }
160 
GameContext.h
Game state manager and message-queue provider.
Hydrax::Hydrax::setSunColor
void setSunColor(const Ogre::Vector3 &SunColor)
Set sun color.
Definition: Hydrax.cpp:946
RoR::HydraxWater::CalcWavesVelocity
Ogre::Vector3 CalcWavesVelocity(Ogre::Vector3 pos) override
Definition: HydraxWater.cpp:138
RoR::App::GetCameraManager
CameraManager * GetCameraManager()
Definition: Application.cpp:275
Hydrax::Hydrax::update
void update(const Ogre::Real &timeSinceLastFrame)
Call every frame.
Definition: Hydrax.cpp:291
SkyManager.h
RoR::HydraxWater::WaterSetSunPosition
void WaterSetSunPosition(Ogre::Vector3) override
Definition: HydraxWater.cpp:146
RoR::App::GetAppContext
AppContext * GetAppContext()
Definition: Application.cpp:266
Hydrax::Hydrax::setSunPosition
void setSunPosition(const Ogre::Vector3 &SunPosition)
Set sun position.
Definition: Hydrax.cpp:883
RoR::Terrain::getSkyManager
SkyManager * getSkyManager()
Definition: Terrain.cpp:513
CameraManager.h
RoR::HydraxWater::SetWaterVisible
void SetWaterVisible(bool value) override
Definition: HydraxWater.cpp:122
AppContext.h
System integration layer; inspired by OgreBites::ApplicationContext.
RoR::CameraManager::GetCameraNode
Ogre::SceneNode * GetCameraNode()
Definition: CameraManager.h:63
Hydrax::Hydrax::create
void create()
Create all resources according with current Hydrax components and add Hydrax to the scene.
Definition: Hydrax.cpp:103
RoR::HydraxWater::IsUnderWater
bool IsUnderWater(Ogre::Vector3 pos) override
Definition: HydraxWater.cpp:91
Actor.h
RoR::HydraxWater::~HydraxWater
~HydraxWater()
Definition: HydraxWater.cpp:51
RoR::HydraxWater::waternoise
Hydrax::Noise::Perlin * waternoise
Definition: HydraxWater.h:60
RoR::HydraxWater::mHydrax
Hydrax::Hydrax * mHydrax
Definition: HydraxWater.h:57
RoR::HydraxWater::waveHeight
float waveHeight
Definition: HydraxWater.h:58
RoR::HydraxWater::SetStaticWaterHeight
void SetStaticWaterHeight(float value) override
Definition: HydraxWater.cpp:117
RoR::CameraManager::GetCamera
Ogre::Camera * GetCamera()
Definition: CameraManager.h:64
RoR::HydraxWater::GetStaticWaterHeight
float GetStaticWaterHeight() override
Returns static water level configured in 'terrn2'.
Definition: HydraxWater.cpp:112
Hydrax::Hydrax::setModule
void setModule(Module::Module *Module, const bool &DeleteOldModule=true)
Set Hydrax module.
Definition: Hydrax.cpp:526
GfxScene.h
RoR::HydraxWater::UpdateWater
void UpdateWater() override
Definition: HydraxWater.cpp:98
Hydrax::Module::Module
Base module class, Override it for create different ways of create water noise.
Definition: Module.h:46
RoR::App::GetGameContext
GameContext * GetGameContext()
Definition: Application.cpp:280
Hydrax::Module::ProjectedGrid
Hydrax projected grid module.
Definition: ProjectedGrid.h:50
Hydrax::Hydrax::loadCfg
const bool loadCfg(const Ogre::String &File) const
Load config from file.
Definition: Hydrax.h:142
Hydrax::Hydrax::remove
void remove()
Remove hydrax, you can call this method to remove Hydrax from the scene or release (secondary) Hydrax...
Definition: Hydrax.cpp:177
RoR::HydraxWater::CurrentConfigFile
Ogre::String CurrentConfigFile
Definition: HydraxWater.h:62
Hydrax::Hydrax::setPosition
void setPosition(const Ogre::Vector3 &Position)
Set water position.
Definition: Hydrax.cpp:719
Hydrax::Hydrax
Main Hydrax class.
Definition: Hydrax.h:56
Hydrax::Module::ProjectedGrid::Options
Struct wich contains Hydrax projected grid module options.
Definition: ProjectedGrid.h:55
RoR::App::gfx_water_waves
CVar * gfx_water_waves
Definition: Application.cpp:226
RoR::HydraxWater::waterHeight
float waterHeight
Definition: HydraxWater.h:59
Hydrax::Hydrax::setVisible
void setVisible(const bool &Visible)
Show/Hide hydrax water.
Definition: Hydrax.cpp:197
Terrain.h
Ogre
Definition: ExtinguishableFireAffector.cpp:35
RoR::HydraxWater::CalcWavesHeight
float CalcWavesHeight(Ogre::Vector3 pos) override
Definition: HydraxWater.cpp:128
RoR::HydraxWater::mModule
Hydrax::Module::ProjectedGrid * mModule
Definition: HydraxWater.h:61
Hydrax::Hydrax::setShaderMode
void setShaderMode(const MaterialManager::ShaderMode &ShaderMode)
Set shader mode.
Definition: Hydrax.cpp:279
Hydrax::MaterialManager::ShaderMode
ShaderMode
Shader mode.
Definition: MaterialManager.h:88
Hydrax::Noise::Perlin
Perlin noise module class.
Definition: Perlin.h:73
RoR
Definition: AppContext.h:36
RoR::HydraxWater::FrameStepWater
void FrameStepWater(float dt) override
Definition: HydraxWater.cpp:152
RoR::App::GetGfxScene
GfxScene * GetGfxScene()
Definition: Application.cpp:276
Hydrax::Hydrax::getHeigth
float getHeigth(const Ogre::Vector2 &Position)
Get the current heigth at a especified world-space point.
Definition: Hydrax.h:430
HydraxWater.h
RoR::HydraxWater::InitHydrax
void InitHydrax()
Definition: HydraxWater.cpp:57
RoR::GameContext::GetTerrain
const TerrainPtr & GetTerrain()
Definition: GameContext.h:117
Hydrax::MaterialManager::NM_VERTEX
@ NM_VERTEX
Definition: MaterialManager.h:105