Rigs of Rods 2023.09
Soft-body Physics Simulation
Loading...
Searching...
No Matches
VCloudsManager.cpp
Go to the documentation of this file.
1/*
2--------------------------------------------------------------------------------
3This source file is part of SkyX.
4Visit http://www.paradise-studios.net/products/skyx/
5
6Copyright (C) 2009-2012 Xavier Verguín González <xavyiy@gmail.com>
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#include "VCloudsManager.h"
25
26#include "SkyX.h"
27
28namespace SkyX
29{
31 : mSkyX(s)
32 , mVClouds(0)
33 , mHeight(Ogre::Vector2(-1, -1))
34 , mWindSpeed(800.0f)
35 , mAutoupdate(true)
36 , mCreated(false)
37 , mCurrentTimeSinceLastFrame(0)
38 {
42
44 mAmbientGradient.addCFrame(ColorGradient::ColorFrame(Ogre::Vector3(1,1,1)*0.9f, 1.0f));
45 mAmbientGradient.addCFrame(ColorGradient::ColorFrame(Ogre::Vector3(0.7,0.7,0.65), 0.625f));
46 mAmbientGradient.addCFrame(ColorGradient::ColorFrame(Ogre::Vector3(0.6,0.55,0.4)*0.5, 0.5625f));
47 mAmbientGradient.addCFrame(ColorGradient::ColorFrame(Ogre::Vector3(0.6,0.55,0.4)*0.25, 0.475f));
48 mAmbientGradient.addCFrame(ColorGradient::ColorFrame(Ogre::Vector3(0.6,0.45,0.3)*0.2, 0.4f));
49 mAmbientGradient.addCFrame(ColorGradient::ColorFrame(Ogre::Vector3(0.2,0.2,0.3)*0.2, 0.325f));
50 mAmbientGradient.addCFrame(ColorGradient::ColorFrame(Ogre::Vector3(0.2,0.2,0.3)*0.15, 0));
51
53 mSunGradient.addCFrame(ColorGradient::ColorFrame(Ogre::Vector3(1,1,1)*0.9f, 1.0f));
54 mSunGradient.addCFrame(ColorGradient::ColorFrame(Ogre::Vector3(1,1,1)*0.8, 0.75f));
55 mSunGradient.addCFrame(ColorGradient::ColorFrame(Ogre::Vector3(0.8,0.75,0.55)*1.3, 0.5625f));
56 mSunGradient.addCFrame(ColorGradient::ColorFrame(Ogre::Vector3(0.6,0.5,0.2)*1.5, 0.5f));
57 mSunGradient.addCFrame(ColorGradient::ColorFrame(Ogre::Vector3(0.6,0.5,0.2)*0.6, 0.4725f));
58 mSunGradient.addCFrame(ColorGradient::ColorFrame(Ogre::Vector3(0.6,0.5,0.2)*0.4, 0.45f));
59 mSunGradient.addCFrame(ColorGradient::ColorFrame(Ogre::Vector3(0.0,0.0,0.0), 0.4125f)); // Sun-Moon threshold
60 mSunGradient.addCFrame(ColorGradient::ColorFrame(Ogre::Vector3(0.25,0.25,0.25), 0.25f));
61 mSunGradient.addCFrame(ColorGradient::ColorFrame(Ogre::Vector3(0.4,0.4,0.4), 0.0f));
62 }
63
65 {
66 remove();
67
68 delete mVClouds;
69 }
70
71 void VCloudsManager::create(const Ogre::Real& radius)
72 {
73 if (mCreated)
74 {
75 return;
76 }
77
78 Ogre::Real selectedRadius = radius < 0 ? mVClouds->getGeometrySettings().Radius : radius;
79
80 // Use default options if the user haven't set any specific Height parameters
81 Ogre::Vector2 defaultheight = Ogre::Vector2(selectedRadius*0.025f, selectedRadius*0.1f);
82 Ogre::Vector2 height = (mHeight.x == -1 || mHeight.y == -1) ? defaultheight : mHeight;
83
85 mVClouds->create(height, selectedRadius);
86
87 mCreated = true;
88
90 }
91
92 void VCloudsManager::update(const Ogre::Real& timeSinceLastFrame)
93 {
94 if (!mCreated)
95 {
96 return;
97 }
98
99 mCurrentTimeSinceLastFrame = timeSinceLastFrame;
100
102
103 mVClouds->update(timeSinceLastFrame);
104 }
105
107 {
108 if (!mCreated)
109 {
110 return;
111 }
112
114 }
115
117 {
118 if (!mCreated)
119 {
120 return;
121 }
122
123 mVClouds->remove();
124
125 mCreated = false;
126 }
127
129 {
130 Ogre::Vector3 SunDir = -mSkyX->getController()->getSunDirection();
131
132 // Moon
133 if (SunDir.y > 0.175f)
134 {
135 SunDir = -mSkyX->getController()->getMoonDirection();
136 }
137
138 mVClouds->setSunDirection(SunDir);
139
140 float point = (mSkyX->getController()->getSunDirection().y + 1.0f) / 2.0f;
141
144 }
145
147 {
148 if (!mCreated)
149 {
150 return;
151 }
152
153 if (mAutoupdate)
154 {
156 }
157 else
158 {
160 }
161 }
162}
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.
virtual Ogre::Vector3 getMoonDirection()=0
Get moon direction.
virtual Ogre::Vector3 getSunDirection()=0
Get sun direction.
const Ogre::Real & getTimeMultiplier() const
Get time multiplier.
Definition SkyX.h:175
Ogre::SceneManager * getSceneManager()
Get scene manager.
Definition SkyX.h:315
const RenderQueueGroups & getRenderQueueGroups() const
Get render queue groups.
Definition SkyX.h:257
Controller * getController() const
Get current controller.
Definition SkyX.h:244
void setAmbientColor(const Ogre::Vector3 &AmbientColor)
Set ambient color.
Definition VClouds.cpp:272
void setRenderQueueGroups(const RenderQueueGroups &rqg)
Set render queue groups.
Definition VClouds.cpp:245
void create()
Create.
Definition VClouds.cpp:68
void setWindSpeed(const float &WindSpeed)
Set wind speed.
Definition VClouds.h:292
void notifyCameraRender(Ogre::Camera *c, const Ogre::Real &timeSinceLastCameraFrame)
Notify camera render, to be invoked per-camera and per-frame.
Definition VClouds.cpp:174
void remove()
Remove.
Definition VClouds.cpp:127
void setSunDirection(const Ogre::Vector3 &SunDirection)
Set sun direction.
Definition VClouds.h:308
void update(const Ogre::Real &timeSinceLastFrame)
Update, to be invoked per frame.
Definition VClouds.cpp:147
void setSunColor(const Ogre::Vector3 &SunColor)
Set sun color.
Definition VClouds.cpp:257
const GeometrySettings & getGeometrySettings() const
Get geometry settings.
Definition VClouds.h:217
Ogre::Vector2 mHeight
Height parameters, x = Cloud field y-coord start, y: Field height (both in world coordinates)
bool mCreated
Is vclouds manager created?
ColorGradient mAmbientGradient
Ambient and Sun color gradients.
void remove()
Remove all resources.
VCloudsManager(SkyX *s)
Constructor.
SkyX * mSkyX
SkyX parent pointer.
Ogre::Real mCurrentTimeSinceLastFrame
Current time since last frame.
bool mAutoupdate
Autoupdate wind speed depending of skyx time multiplier?
void create(const Ogre::Real &radius=-1)
Create all resources.
void _updateWindSpeedConfig()
Update wind speed config.
void update(const Ogre::Real &timeSinceLastFrame)
Update.
void notifyCameraRender(Ogre::Camera *c)
Notify camera render, to be invoked per-camera and per-frame.
~VCloudsManager()
Destructor.
ColorGradient mSunGradient
Ogre::Real mWindSpeed
Wind speed.
VClouds::VClouds * mVClouds
VClouds pointer.
void _setLightParameters()
Set light parameters.
Ogre::uint8 vclouds
VClouds render queue group.
Definition SkyX.h:82
Ogre::uint8 vcloudsLightningsOver
VClouds lightnings render queue group (when the camera is over the cloud field)
Definition SkyX.h:86
Ogre::uint8 vcloudsLightningsUnder
VClouds lightnings render queue group (when the camera is under the cloud field)
Definition SkyX.h:84