RigsofRods
Soft-body Physics Simulation
DataManager.h
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 #ifndef _SkyX_VClouds_DataManager_H_
25 #define _SkyX_VClouds_DataManager_H_
26 
27 #include "Prerequisites.h"
28 
29 #include "FastFakeRandom.h"
30 
31 namespace SkyX { namespace VClouds{
32 
33  class VClouds;
34  class Ellipsoid;
35 
36  class DataManager
37  {
38  public:
41  struct Cell
42  {
44  bool hum, act, cld;
45 
47  float phum, pext, pact;
48 
50  float dens;
51 
53  float light;
54  };
55 
59  {
60  VOL_TEX0 = 0,
62  };
63 
67  DataManager(VClouds *vc);
68 
71  ~DataManager();
72 
78  void create(const int& nx, const int& ny, const int& nz);
79 
83  void update(const Ogre::Real &timeSinceLastFrame);
84 
87  void remove();
88 
92  inline const bool& isCreated() const
93  {
94  return mCreated;
95  }
96 
100  inline void setUpdateTime(const float& UpdateTime)
101  {
102  mUpdateTime = UpdateTime;
103  }
104 
108  inline const Ogre::Real& getUpdateTime() const
109  {
110  return mUpdateTime;
111  }
112 
117  inline const Ogre::Real _getInterpolation() const
118  {
120  }
121 
130  void setWheater(const float& Humidity, const float& AverageCloudsSize, const bool& delayedResponse = true);
131 
137  void addEllipsoid(Ellipsoid *e, const bool& UpdateProbabilities = true);
138 
141  void forceToUpdateData();
142 
143  private:
144 
150  void _initData(const int& nx, const int& ny, const int& nz);
151 
159  Cell *** _create3DCellArray(const int& nx, const int& ny, const int& nz, const bool& init = true);
160 
166  void _delete3DCellArray(Cell ***c, const int& nx, const int& ny);
167 
175  void _copy3DCellArraysData(Cell ***src, Cell ***dest, const int& nx, const int& ny, const int& nz);
176 
185  void _performCalculations(const int& nx, const int& ny, const int& nz, const int& step, const int& xStart, const int& xEnd);
186 
194  void _updateVolTextureData(Cell ***c, const VolTextureId& TexId, const int& nx, const int& ny, const int& nz);
195 
207  const float _getDensityAt(Cell ***c, const int& nx, const int& ny, const int& nz, const int& x, const int& y, const int& z, const int& r, const float& strength) const;
208 
215  const float _getDensityAt(Cell ***c, const int& x, const int& y, const int& z) const;
216 
226  const bool _fact(Cell ***c, const int& nx, const int& ny, const int& nz, const int& x, const int& y, const int& z) const;
227 
235  void _clearProbabilities(Cell*** c, const int& nx, const int& ny, const int& nz, const bool& clearData);
236 
244  void _updateProbabilities(Cell*** c, const int& nx, const int& ny, const int& nz, const bool& delayedResponse);
245 
257  const Ogre::Real _getLightAbsorcionAt(Cell*** c, const int& nx, const int& ny, const int& nz, const int& x, const int& y, const int& z, const Ogre::Vector3& d, const float& att) const;
258 
265  void _createVolTexture(const VolTextureId& TexId, const int& nx, const int& ny, const int& nz);
266 
270 
274  float mUpdateTime;
277 
279  int mNx, mNy, mNz;
280 
282  Ogre::TexturePtr mVolTextures[2];
285 
287  bool mCreated;
288 
291 
295  std::vector<Ellipsoid*> mEllipsoids;
296 
299  };
300 
301 }}
302 
303 #endif
SkyX::VClouds::DataManager::_createVolTexture
void _createVolTexture(const VolTextureId &TexId, const int &nx, const int &ny, const int &nz)
Create volumetric texture.
Definition: DataManager.cpp:573
SkyX::VClouds::DataManager
Definition: DataManager.h:36
SkyX::VClouds::DataManager::isCreated
const bool & isCreated() const
Has been create(...) already called?
Definition: DataManager.h:92
y
float y
Definition: (ValueTypes) quaternion.h:6
SkyX::VClouds::DataManager::create
void create(const int &nx, const int &ny, const int &nz)
Create.
Definition: DataManager.cpp:158
SkyX::VClouds::FastFakeRandom
Definition: FastFakeRandom.h:31
SkyX::VClouds::DataManager::_delete3DCellArray
void _delete3DCellArray(Cell ***c, const int &nx, const int &ny)
Delete tridimensional cell array.
Definition: DataManager.cpp:253
FastFakeRandom.h
SkyX::VClouds::DataManager::remove
void remove()
Remove.
Definition: DataManager.cpp:55
SkyX::VClouds::DataManager::mVolTexToUpdate
bool mVolTexToUpdate
Current texture.
Definition: DataManager.h:284
z
float z
Definition: (ValueTypes) quaternion.h:7
SkyX::VClouds::DataManager::_performCalculations
void _performCalculations(const int &nx, const int &ny, const int &nz, const int &step, const int &xStart, const int &xEnd)
Perform celullar automata simulation.
Definition: DataManager.cpp:439
SkyX::VClouds::DataManager::Cell::dens
float dens
Continous density.
Definition: DataManager.h:50
SkyX::VClouds::DataManager::Cell::phum
float phum
Probabilities.
Definition: DataManager.h:47
SkyX::VClouds::DataManager::setUpdateTime
void setUpdateTime(const float &UpdateTime)
Set update time.
Definition: DataManager.h:100
SkyX::VClouds::DataManager::getUpdateTime
const Ogre::Real & getUpdateTime() const
Get update time.
Definition: DataManager.h:108
SkyX
Definition: AtmosphereManager.cpp:30
SkyX::VClouds::DataManager::_getInterpolation
const Ogre::Real _getInterpolation() const
Get current interpolation factor.
Definition: DataManager.h:117
SkyX::VClouds::DataManager::Cell::pact
float pact
Definition: DataManager.h:47
SkyX::VClouds::DataManager::_updateVolTextureData
void _updateVolTextureData(Cell ***c, const VolTextureId &TexId, const int &nx, const int &ny, const int &nz)
Update volumetric texture data.
Definition: DataManager.cpp:595
SkyX::VClouds::DataManager::Cell::hum
bool hum
Humidity, phase and cloud.
Definition: DataManager.h:44
SkyX::VClouds::DataManager::mUpdateTime
float mUpdateTime
Update time.
Definition: DataManager.h:274
SkyX::VClouds::DataManager::mCreated
bool mCreated
Has been create(...) already called?
Definition: DataManager.h:287
SkyX::VClouds::DataManager::mCellsTmp
Cell *** mCellsTmp
Definition: DataManager.h:269
SkyX::VClouds::DataManager::DataManager
DataManager(VClouds *vc)
Constructor.
Definition: DataManager.cpp:31
SkyX::VClouds::DataManager::mXEnd
int mXEnd
Definition: DataManager.h:276
SkyX::VClouds::DataManager::mMaxNumberOfClouds
int mMaxNumberOfClouds
Max number of clouds(Ellipsoids)
Definition: DataManager.h:293
SkyX::VClouds::DataManager::_getLightAbsorcionAt
const Ogre::Real _getLightAbsorcionAt(Cell ***c, const int &nx, const int &ny, const int &nz, const int &x, const int &y, const int &z, const Ogre::Vector3 &d, const float &att) const
Get light absorcion factor at a point.
Definition: DataManager.cpp:408
SkyX::VClouds::DataManager::mCellsCurrent
Cell *** mCellsCurrent
Simulation data.
Definition: DataManager.h:268
SkyX::VClouds::DataManager::mNy
int mNy
Definition: DataManager.h:279
SkyX::VClouds::DataManager::_create3DCellArray
Cell *** _create3DCellArray(const int &nx, const int &ny, const int &nz, const bool &init=true)
Create tridimensional cell array.
Definition: DataManager.cpp:209
SkyX::VClouds::DataManager::VolTextureId
VolTextureId
Volumetric textures enumeration.
Definition: DataManager.h:58
SkyX::VClouds::DataManager::forceToUpdateData
void forceToUpdateData()
Forces the data manager to calculate the next step right now.
Definition: DataManager.cpp:179
SkyX::VClouds::DataManager::_updateProbabilities
void _updateProbabilities(Cell ***c, const int &nx, const int &ny, const int &nz, const bool &delayedResponse)
Update probabilities based from the Ellipsoid vector.
Definition: DataManager.cpp:396
SkyX::VClouds::DataManager::_clearProbabilities
void _clearProbabilities(Cell ***c, const int &nx, const int &ny, const int &nz, const bool &clearData)
Clear probabilities.
Definition: DataManager.cpp:368
SkyX::VClouds::DataManager::mStep
int mStep
Current calculation state.
Definition: DataManager.h:276
SkyX::VClouds::DataManager::_getDensityAt
const float _getDensityAt(Cell ***c, const int &nx, const int &ny, const int &nz, const int &x, const int &y, const int &z, const int &r, const float &strength) const
Get continous density at a point.
Definition: DataManager.cpp:542
SkyX::VClouds::DataManager::mXStart
int mXStart
Definition: DataManager.h:276
SkyX::VClouds::DataManager::Cell
Cell struct.
Definition: DataManager.h:41
SkyX::VClouds::DataManager::mNx
int mNx
Complexities.
Definition: DataManager.h:279
SkyX::VClouds::DataManager::VOL_TEX1
@ VOL_TEX1
Definition: DataManager.h:61
SkyX::VClouds::VClouds
Definition: VClouds.h:35
SkyX::VClouds::DataManager::addEllipsoid
void addEllipsoid(Ellipsoid *e, const bool &UpdateProbabilities=true)
Add ellipsoid: clouds are modelled as ellipsoids in our simulation approach, so.
Definition: DataManager.cpp:358
SkyX::VClouds::DataManager::_initData
void _initData(const int &nx, const int &ny, const int &nz)
Initialize data.
Definition: DataManager.cpp:203
SkyX::VClouds::DataManager::Cell::light
float light
Light absorcion.
Definition: DataManager.h:53
SkyX::VClouds::DataManager::Cell::act
bool act
Definition: DataManager.h:44
SkyX::VClouds::DataManager::mEllipsoids
std::vector< Ellipsoid * > mEllipsoids
Ellipsoids.
Definition: DataManager.h:295
SkyX::VClouds::DataManager::mFFRandom
FastFakeRandom * mFFRandom
Fast fake random.
Definition: DataManager.h:290
SkyX::VClouds::DataManager::mVClouds
VClouds * mVClouds
SkyX parent pointer.
Definition: DataManager.h:298
SkyX::VClouds::DataManager::mNz
int mNz
Definition: DataManager.h:279
SkyX::VClouds::DataManager::Cell::cld
bool cld
Definition: DataManager.h:44
SkyX::VClouds::DataManager::_fact
const bool _fact(Cell ***c, const int &nx, const int &ny, const int &nz, const int &x, const int &y, const int &z) const
Fact funtion.
Definition: DataManager.cpp:518
SkyX::VClouds::DataManager::setWheater
void setWheater(const float &Humidity, const float &AverageCloudsSize, const bool &delayedResponse=true)
Set wheater parameters Use this funtion to update the cloud field parameters, you'll get a smart and ...
Definition: DataManager.cpp:295
SkyX::VClouds::Ellipsoid
Ellipsoid class x^2 y^2 z^2 / + / + / = 1 a^2 b^2 c^2.
Definition: Ellipsoid.h:38
SkyX::VClouds::DataManager::mVolTextures
Ogre::TexturePtr mVolTextures[2]
Volumetric textures array.
Definition: DataManager.h:282
SkyX::VClouds::DataManager::~DataManager
~DataManager()
Destructor.
Definition: DataManager.cpp:50
SkyX::VClouds::DataManager::_copy3DCellArraysData
void _copy3DCellArraysData(Cell ***src, Cell ***dest, const int &nx, const int &ny, const int &nz)
Copy 3d cells arrays data.
Definition: DataManager.cpp:270
x
float x
Definition: (ValueTypes) quaternion.h:5
SkyX::VClouds::DataManager::mCurrentTransition
float mCurrentTransition
Current transition.
Definition: DataManager.h:272
SkyX::VClouds::DataManager::Cell::pext
float pext
Definition: DataManager.h:47
SkyX::VClouds::DataManager::update
void update(const Ogre::Real &timeSinceLastFrame)
Update.
Definition: DataManager.cpp:78
SkyX::VClouds::DataManager::VOL_TEX0
@ VOL_TEX0
Definition: DataManager.h:60