Rigs of Rods 2023.09
Soft-body Physics Simulation
Loading...
Searching...
No Matches
SkyXManager.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-2014 Petr Ohlidal
6
7 For more information, see http://www.rigsofrods.com/
8
9 Rigs of Rods is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License version 3, as
11 published by the Free Software Foundation.
12
13 Rigs of Rods is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
20*/
21
22#include "SkyXManager.h"
23
24#include "Actor.h"
25#include "AppContext.h"
26#include "CameraManager.h"
27#include "GameContext.h"
28#include "GfxScene.h"
29#include "HydraxWater.h"
30#include "Terrain.h"
32
33using namespace Ogre;
34using namespace RoR;
35
36SkyXManager::SkyXManager(Ogre::String configFile)
37{
38 InitLight();
39
40 //Ogre::ResourceGroupManager::getSingleton().addResourceLocation("..\\resource\\SkyX\\","FileSystem", "SkyX",true); //Temp
41
43 mSkyX = new SkyX::SkyX(App::GetGfxScene()->GetSceneManager(), mBasicController);
44
46 mCfgFileManager->load(configFile);
47
48 mSkyX->create();
49
50 RoR::App::GetAppContext()->GetOgreRoot()->addFrameListener(mSkyX);
52}
53
55{
56 RoR::App::GetAppContext()->GetRenderWindow()->removeListener(mSkyX);
57 mSkyX->remove();
58
59 mSkyX = nullptr;
60
61 delete mBasicController;
62 mBasicController = nullptr;
63}
64
66{
67 if (mBasicController != nullptr)
69 return Ogre::Vector3(0.0,0.0,0.0);
70}
71
73{
74 return mLight1;
75}
76
77bool SkyXManager::update(float dt)
78{
80 mSkyX->update(dt);
81 return true;
82}
83
84
86{
87 Ogre::Vector3 lightDir = -getMainLightDirection();
88 const Ogre::Vector3 camPos = App::GetCameraManager()->GetCameraNode()->_getDerivedPosition();
89 Ogre::Vector3 sunPos = camPos - lightDir*mSkyX->getMeshManager()->getSkydomeRadius(App::GetCameraManager()->GetCamera());
90
91 // Calculate current color gradients point
92 float point = (-lightDir.y + 1.0f) / 2.0f;
93
95 {
98 }
99
100
101 mLight0 = App::GetGfxScene()->GetSceneManager()->getLight("Light0");
102 mLight1 = App::GetGfxScene()->GetSceneManager()->getLight("Light1");
103
104 mLight0->setPosition(sunPos*0.02);
105 mLight1->setDirection(lightDir);
106 if (App::GetGameContext()->GetTerrain()->getWater())
107 {
109 }
110
111 //setFadeColour was removed with https://github.com/RigsOfRods/rigs-of-rods/pull/1459
112/* Ogre::Vector3 sunCol = mSunGradient.getColor(point);
113 mLight0->setSpecularColour(sunCol.x, sunCol.y, sunCol.z);
114 if (App::GetGameContext()->GetTerrain()->getWater()) App::GetGameContext()->GetTerrain()->getWater()->setFadeColour(Ogre::ColourValue(sunCol.x, sunCol.y, sunCol.z));
115 */
116 Ogre::Vector3 ambientCol = mAmbientGradient.getColor(point);
117 mLight1->setDiffuseColour(ambientCol.x, ambientCol.y, ambientCol.z);
118 mLight1->setPosition(100,100,100);
119
120 if (mBasicController->getTime().x > 12)
121 {
123 mLight0->setVisible(false);
124 else
125 mLight0->setVisible(true);
126 }
127 else
128 {
130 mLight0->setVisible (false);
131 else
132 mLight0->setVisible (true);
133 }
134
135 if (round (mBasicController->getTime ().x) != mLastHour)
136 {
138 if (gm)
139 gm->updateLightMap ();
140
141 mLastHour = round (mBasicController->getTime ().x);
142 }
143
144 return true;
145}
146
148{
149 // Water
151 mWaterGradient.addCFrame(SkyX::ColorGradient::ColorFrame(Ogre::Vector3(0.058209,0.535822,0.779105)*0.4, 1));
152 mWaterGradient.addCFrame(SkyX::ColorGradient::ColorFrame(Ogre::Vector3(0.058209,0.535822,0.729105)*0.3, 0.8));
153 mWaterGradient.addCFrame(SkyX::ColorGradient::ColorFrame(Ogre::Vector3(0.058209,0.535822,0.679105)*0.25, 0.6));
154 mWaterGradient.addCFrame(SkyX::ColorGradient::ColorFrame(Ogre::Vector3(0.058209,0.535822,0.679105)*0.2, 0.5));
155 mWaterGradient.addCFrame(SkyX::ColorGradient::ColorFrame(Ogre::Vector3(0.058209,0.535822,0.679105)*0.1, 0.45));
156 mWaterGradient.addCFrame(SkyX::ColorGradient::ColorFrame(Ogre::Vector3(0.058209,0.535822,0.679105)*0.025, 0));
157 // Sun
159 mSunGradient.addCFrame(SkyX::ColorGradient::ColorFrame(Ogre::Vector3(0.8,0.75,0.55)*1.5, 1.0f));
160 mSunGradient.addCFrame(SkyX::ColorGradient::ColorFrame(Ogre::Vector3(0.8,0.75,0.55)*1.4, 0.75f));
161 mSunGradient.addCFrame(SkyX::ColorGradient::ColorFrame(Ogre::Vector3(0.8,0.75,0.55)*1.3, 0.5625f));
162 mSunGradient.addCFrame(SkyX::ColorGradient::ColorFrame(Ogre::Vector3(0.6,0.5,0.2)*1.5, 0.5f));
163 mSunGradient.addCFrame(SkyX::ColorGradient::ColorFrame(Ogre::Vector3(0.5,0.5,0.5)*0.25, 0.45f));
164 mSunGradient.addCFrame(SkyX::ColorGradient::ColorFrame(Ogre::Vector3(0.5,0.5,0.5)*0.01, 0.0f));
165 // Ambient
167 mAmbientGradient.addCFrame(SkyX::ColorGradient::ColorFrame(Ogre::Vector3(1,1,1)*1, 1.0f));
168 mAmbientGradient.addCFrame(SkyX::ColorGradient::ColorFrame(Ogre::Vector3(1,1,1)*1, 0.6f));
169 mAmbientGradient.addCFrame(SkyX::ColorGradient::ColorFrame(Ogre::Vector3(1,1,1)*0.6, 0.5f));
170 mAmbientGradient.addCFrame(SkyX::ColorGradient::ColorFrame(Ogre::Vector3(1,1,1)*0.3, 0.45f));
171 mAmbientGradient.addCFrame(SkyX::ColorGradient::ColorFrame(Ogre::Vector3(1,1,1)*0.1, 0.35f));
172 mAmbientGradient.addCFrame(SkyX::ColorGradient::ColorFrame(Ogre::Vector3(1,1,1)*0.05, 0.0f));
173
174 App::GetGfxScene()->GetSceneManager()->setAmbientLight(ColourValue(0.35,0.35,0.35)); //Not needed because terrn2 has ambientlight settings
175
176 // Light
177 mLight0 = App::GetGfxScene()->GetSceneManager()->createLight("Light0");
178 mLight0->setDiffuseColour(1, 1, 1);
179 mLight0->setCastShadows(false);
180
181 mLight1 = App::GetGfxScene()->GetSceneManager()->createLight("Light1");
182 mLight1->setType(Ogre::Light::LT_DIRECTIONAL);
183
184 return true;
185}
186
188{
189 //TODO
190 return 0;
191}
192
194{
195 //TODO
196}
System integration layer; inspired by OgreBites::ApplicationContext.
Game state manager and message-queue provider.
void setSunPosition(const Ogre::Vector3 &SunPosition)
Set sun position.
Definition Hydrax.cpp:884
void setWaterColor(const Ogre::Vector3 &WaterColor)
Definition Hydrax.cpp:815
Ogre::Root * GetOgreRoot()
Definition AppContext.h:65
Ogre::RenderWindow * GetRenderWindow()
Definition AppContext.h:67
Ogre::SceneNode * GetCameraNode()
const TerrainPtr & GetTerrain()
Ogre::SceneManager * GetSceneManager()
Definition GfxScene.h:83
Hydrax::Hydrax * GetHydrax()
Definition HydraxWater.h:46
virtual void WaterSetSunPosition(Ogre::Vector3)
Definition IGfxWater.h:45
SkyX::ColorGradient mAmbientGradient
Definition SkyXManager.h:63
bool update(float dt)
Ogre::Light * mLight1
Definition SkyXManager.h:56
SkyX::CfgFileManager * mCfgFileManager
Definition SkyXManager.h:65
SkyX::ColorGradient mWaterGradient
Definition SkyXManager.h:61
Ogre::Light * getMainLight()
SkyXManager(Ogre::String configFile)
SkyX::ColorGradient mSunGradient
Definition SkyXManager.h:62
size_t getMemoryUsage()
SkyX::BasicController * mBasicController
Definition SkyXManager.h:59
Ogre::Light * mLight0
Definition SkyXManager.h:55
Ogre::Vector3 getMainLightDirection()
SkyX::SkyX * mSkyX
Definition SkyXManager.h:58
this class handles all interactions with the Ogre Terrain system
TerrainGeometryManager * getGeometryManager()
Definition Terrain.h:79
IGfxWater * getGfxWater()
Definition Terrain.h:88
HydraxWater * getHydraxManager()
Definition Terrain.h:81
Basic controller class
Ogre::Vector3 getSunDirection()
Get sun direction.
const Ogre::Vector3 & getTime() const
Get time.
Config file manager.
const bool load(const Ogre::String &File) const
Load hydrax cfg file.
const Ogre::Vector3 getColor(const Ogre::Real &p) const
Get color value.
std::pair< Ogre::Vector3, Ogre::Real > ColorFrame
Color frame type definition ColorFrame.first: Colour value ColorFrame.second: Position in the gradien...
void addCFrame(const ColorFrame &CFrame)
Add color frame.
const float getSkydomeRadius(Ogre::Camera *c) const
Get skydome radius.
SkyX class Create simple and beautiful skies!
Definition SkyX.h:62
void create()
Create SkyX.
Definition SkyX.cpp:76
MeshManager * getMeshManager()
Get mesh manager.
Definition SkyX.h:183
void update(const Ogre::Real &timeSinceLastFrame)
Update (to be invoked per frame)
Definition SkyX.cpp:125
void remove()
Remove SkyX (free resources)
Definition SkyX.cpp:108
AppContext * GetAppContext()
CameraManager * GetCameraManager()
GameContext * GetGameContext()
GfxScene * GetGfxScene()