Rigs of Rods 2023.09
Soft-body Physics Simulation
Loading...
Searching...
No Matches
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
35using namespace Ogre;
36using namespace RoR;
37
38// HydraxWater
39HydraxWater::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
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
92{
93#ifdef USE_CAELUM
94 if (RoR::App::GetGameContext()->GetTerrain()->getSkyManager() != nullptr)
95 {
96 SkyManager* sky = RoR::App::GetGameContext()->GetTerrain()->getSkyManager();
97 Ogre::Vector3 sunPosition = App::GetCameraManager()->GetCameraNode()->_getDerivedPosition();
98 sunPosition -= sky->GetCaelumSys()->getSun()->getLightDirection() * 80000;
99 mHydrax->setSunPosition(sunPosition);
100 mHydrax->setSunColor(Ogre::Vector3(sky->GetCaelumSys()->getSun()->getBodyColour().r, sky->GetCaelumSys()->getSun()->getBodyColour().g, sky->GetCaelumSys()->getSun()->getBodyColour().b));
101 }
102#endif // USE_CAELUM
103}
104
106{
107 if (mHydrax)
108 mHydrax->setVisible(value);
109}
110
111void HydraxWater::WaterSetSunPosition(Ogre::Vector3 pos)
112{
113 if (mHydrax)
115}
116
118{
119 const float curWaterHeight = App::GetGameContext()->GetTerrain()->getWater()->GetStaticWaterHeight();
120 if (waterHeight != curWaterHeight)
121 {
122 waterHeight = curWaterHeight;
123 }
124 if (mHydrax)
125 {
126 mHydrax->update(dt);
127 }
128 this->UpdateWater();
129}
130
System integration layer; inspired by OgreBites::ApplicationContext.
Game state manager and message-queue provider.
Main Hydrax class.
Definition Hydrax.h:57
void remove()
Remove hydrax, you can call this method to remove Hydrax from the scene or release (secondary) Hydrax...
Definition Hydrax.cpp:177
const bool loadCfg(const Ogre::String &File) const
Load config from file.
Definition Hydrax.h:142
void setShaderMode(const MaterialManager::ShaderMode &ShaderMode)
Set shader mode.
Definition Hydrax.cpp:279
void setPosition(const Ogre::Vector3 &Position)
Set water position.
Definition Hydrax.cpp:720
void setVisible(const bool &Visible)
Show/Hide hydrax water.
Definition Hydrax.cpp:197
void setModule(Module::Module *Module, const bool &DeleteOldModule=true)
Set Hydrax module.
Definition Hydrax.cpp:527
void setSunPosition(const Ogre::Vector3 &SunPosition)
Set sun position.
Definition Hydrax.cpp:884
void create()
Create all resources according with current Hydrax components and add Hydrax to the scene.
Definition Hydrax.cpp:103
void update(const Ogre::Real &timeSinceLastFrame)
Call every frame.
Definition Hydrax.cpp:291
void setSunColor(const Ogre::Vector3 &SunColor)
Set sun color.
Definition Hydrax.cpp:947
Base module class, Override it for create different ways of create water noise.
Definition Module.h:47
Hydrax projected grid module.
Perlin noise module class.
Definition Perlin.h:74
Ogre::SceneNode * GetCameraNode()
Ogre::Camera * GetCamera()
const TerrainPtr & GetTerrain()
Hydrax::Hydrax * mHydrax
Definition HydraxWater.h:51
Ogre::String CurrentConfigFile
Definition HydraxWater.h:56
HydraxWater(float waterHeight, Ogre::String configFile="HydraxDefault.hdx")
void WaterSetSunPosition(Ogre::Vector3) override
void FrameStepWater(float dt) override
void UpdateWater() override
Hydrax::Module::ProjectedGrid * mModule
Definition HydraxWater.h:55
Hydrax::Noise::Perlin * waternoise
Definition HydraxWater.h:54
void SetWaterVisible(bool value) override
SkyManager * getSkyManager()
Definition Terrain.cpp:522
Wavefield * getWater()
Definition Terrain.h:87
float GetStaticWaterHeight()
Returns static water level configured in 'terrn2'.
Definition Wavefield.cpp:75
AppContext * GetAppContext()
CameraManager * GetCameraManager()
GameContext * GetGameContext()
GfxScene * GetGfxScene()
Struct wich contains Hydrax projected grid module options.