RigsofRods
Soft-body Physics Simulation
VCloudsManager.cpp
Go to the documentation of this file.
1 /*
2 --------------------------------------------------------------------------------
3 This source file is part of SkyX.
4 Visit http://www.paradise-studios.net/products/skyx/
5 
6 Copyright (C) 2009-2012 Xavier Verguín González <xavyiy@gmail.com>
7 
8 This program is free software; you can redistribute it and/or modify it under
9 the terms of the GNU Lesser General Public License as published by the Free Software
10 Foundation; either version 2 of the License, or (at your option) any later
11 version.
12 
13 This program is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16 
17 You should have received a copy of the GNU Lesser General Public License along with
18 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
20 http://www.gnu.org/copyleft/lesser.txt.
21 --------------------------------------------------------------------------------
22 */
23 
24 #include "VCloudsManager.h"
25 
26 #include "SkyX.h"
27 
28 namespace 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 }
SkyX::ColorGradient
Definition: ColorGradient.h:31
SkyX::SkyX::getRenderQueueGroups
const RenderQueueGroups & getRenderQueueGroups() const
Get render queue groups.
Definition: SkyX.h:257
SkyX::VCloudsManager::mSkyX
SkyX * mSkyX
SkyX parent pointer.
Definition: VCloudsManager.h:200
SkyX::VCloudsManager::notifyCameraRender
void notifyCameraRender(Ogre::Camera *c)
Notify camera render, to be invoked per-camera and per-frame.
Definition: VCloudsManager.cpp:106
SkyX::VClouds::VClouds::update
void update(const Ogre::Real &timeSinceLastFrame)
Update, to be invoked per frame.
Definition: VClouds.cpp:147
VCloudsManager.h
SkyX::VCloudsManager::_updateWindSpeedConfig
void _updateWindSpeedConfig()
Update wind speed config.
Definition: VCloudsManager.cpp:146
SkyX::VClouds::VClouds::GeometrySettings::Radius
float Radius
Radius.
Definition: VClouds.h:69
SkyX::ColorGradient::getColor
const Ogre::Vector3 getColor(const Ogre::Real &p) const
Get color value.
Definition: ColorGradient.cpp:37
SkyX::SkyX::getController
Controller * getController() const
Get current controller.
Definition: SkyX.h:244
SkyX::VClouds::VClouds::create
void create()
Create.
Definition: VClouds.cpp:68
SkyX::SkyX::getSceneManager
Ogre::SceneManager * getSceneManager()
Get scene manager.
Definition: SkyX.h:315
SkyX
Definition: AtmosphereManager.cpp:30
SkyX::VClouds::VClouds::RenderQueueGroups
Render queue groups.
Definition: VClouds.h:40
SkyX::VClouds::VClouds::setRenderQueueGroups
void setRenderQueueGroups(const RenderQueueGroups &rqg)
Set render queue groups.
Definition: VClouds.cpp:245
SkyX::VCloudsManager::mAmbientGradient
ColorGradient mAmbientGradient
Ambient and Sun color gradients.
Definition: VCloudsManager.h:179
SkyX::Controller::getMoonDirection
virtual Ogre::Vector3 getMoonDirection()=0
Get moon direction.
SkyX::SkyX::RenderQueueGroups::vcloudsLightningsUnder
Ogre::uint8 vcloudsLightningsUnder
VClouds lightnings render queue group (when the camera is under the cloud field)
Definition: SkyX.h:84
SkyX::VCloudsManager::mHeight
Ogre::Vector2 mHeight
Height parameters, x = Cloud field y-coord start, y: Field height (both in world coordinates)
Definition: VCloudsManager.h:186
SkyX::VCloudsManager::update
void update(const Ogre::Real &timeSinceLastFrame)
Update.
Definition: VCloudsManager.cpp:92
SkyX.h
SkyX::VCloudsManager::mSunGradient
ColorGradient mSunGradient
Definition: VCloudsManager.h:180
SkyX::VClouds::VClouds::notifyCameraRender
void notifyCameraRender(Ogre::Camera *c, const Ogre::Real &timeSinceLastCameraFrame)
Notify camera render, to be invoked per-camera and per-frame.
Definition: VClouds.cpp:174
SkyX::VClouds::VClouds::setWindSpeed
void setWindSpeed(const float &WindSpeed)
Set wind speed.
Definition: VClouds.h:292
SkyX::VClouds::VClouds::getGeometrySettings
const GeometrySettings & getGeometrySettings() const
Get geometry settings.
Definition: VClouds.h:217
SkyX::ColorGradient::addCFrame
void addCFrame(const ColorFrame &CFrame)
Add color frame.
Definition: ColorGradient.h:51
SkyX::VClouds::VClouds::setSunColor
void setSunColor(const Ogre::Vector3 &SunColor)
Set sun color.
Definition: VClouds.cpp:257
SkyX::SkyX::getTimeMultiplier
const Ogre::Real & getTimeMultiplier() const
Get time multiplier.
Definition: SkyX.h:175
SkyX::VCloudsManager::VCloudsManager
VCloudsManager(SkyX *s)
Constructor.
Definition: VCloudsManager.cpp:30
SkyX::VCloudsManager::~VCloudsManager
~VCloudsManager()
Destructor.
Definition: VCloudsManager.cpp:64
SkyX::ColorGradient::ColorFrame
std::pair< Ogre::Vector3, Ogre::Real > ColorFrame
Color frame type definition ColorFrame.first: Colour value ColorFrame.second: Position in the gradien...
Definition: ColorGradient.h:38
SkyX::VClouds::VClouds
Definition: VClouds.h:35
SkyX::VCloudsManager::mWindSpeed
Ogre::Real mWindSpeed
Wind speed.
Definition: VCloudsManager.h:191
SkyX::VCloudsManager::create
void create(const Ogre::Real &radius=-1)
Create all resources.
Definition: VCloudsManager.cpp:71
SkyX::VCloudsManager::mVClouds
VClouds::VClouds * mVClouds
VClouds pointer.
Definition: VCloudsManager.h:183
SkyX::VClouds::VClouds::setSunDirection
void setSunDirection(const Ogre::Vector3 &SunDirection)
Set sun direction.
Definition: VClouds.h:308
Ogre
Definition: ExtinguishableFireAffector.cpp:35
SkyX::VCloudsManager::remove
void remove()
Remove all resources.
Definition: VCloudsManager.cpp:116
SkyX::Controller::getSunDirection
virtual Ogre::Vector3 getSunDirection()=0
Get sun direction.
SkyX::VCloudsManager::mCurrentTimeSinceLastFrame
Ogre::Real mCurrentTimeSinceLastFrame
Current time since last frame.
Definition: VCloudsManager.h:197
SkyX::VCloudsManager::mCreated
bool mCreated
Is vclouds manager created?
Definition: VCloudsManager.h:194
SkyX::SkyX::RenderQueueGroups::vcloudsLightningsOver
Ogre::uint8 vcloudsLightningsOver
VClouds lightnings render queue group (when the camera is over the cloud field)
Definition: SkyX.h:86
SkyX::VCloudsManager::mAutoupdate
bool mAutoupdate
Autoupdate wind speed depending of skyx time multiplier?
Definition: VCloudsManager.h:189
SkyX::VClouds::VClouds::remove
void remove()
Remove.
Definition: VClouds.cpp:127
SkyX::VClouds::VClouds::setAmbientColor
void setAmbientColor(const Ogre::Vector3 &AmbientColor)
Set ambient color.
Definition: VClouds.cpp:272
SkyX::SkyX::RenderQueueGroups::vclouds
Ogre::uint8 vclouds
VClouds render queue group.
Definition: SkyX.h:82
SkyX::VCloudsManager::_setLightParameters
void _setLightParameters()
Set light parameters.
Definition: VCloudsManager.cpp:128