RigsofRods
Soft-body Physics Simulation
GodRaysManager.h
Go to the documentation of this file.
1 /*
2 --------------------------------------------------------------------------------
3 This source file is part of Hydrax.
4 Visit ---
5 
6 Copyright (C) 2008 Xavier Verguín González <xavierverguin@hotmail.com>
7  <xavyiy@gmail.com>
8 
9 This program is free software; you can redistribute it and/or modify it under
10 the terms of the GNU Lesser General Public License as published by the Free Software
11 Foundation; either version 2 of the License, or (at your option) any later
12 version.
13 
14 This program is distributed in the hope that it will be useful, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
17 
18 You should have received a copy of the GNU Lesser General Public License along with
19 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
20 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
21 http://www.gnu.org/copyleft/lesser.txt.
22 --------------------------------------------------------------------------------
23 */
24 
25 #ifndef _Hydrax_GodRaysManager_H_
26 #define _Hydrax_GodRaysManager_H_
27 
28 #include "Prerequisites.h"
29 #include "Perlin.h"
30 
31 #include "Enums.h"
32 
35 
38 
39 namespace Hydrax
40 {
41  class Hydrax;
42 
47  {
48  public:
52  {
53  // Material used for god rays
55  // Used for depth mat(for objects intersections)
57  };
58 
63 
67 
71  void create(const HydraxComponent& HC);
72 
75  void remove();
76 
80  void update(const Ogre::Real& timeSinceLastFrame);
81 
85  inline const bool& isCreated() const
86  {
87  return mCreated;
88  }
89 
99  void addDepthTechnique(Ogre::Technique *Technique, const bool& AutoUpdate = true);
100 
104  inline void SetSimulationSpeed(const Ogre::Real& Speed)
105  {
106  mSimulationSpeed = Speed;
107  }
108 
112  inline const Ogre::Real& getSimulationSpeed() const
113  {
114  return mSimulationSpeed;
115  }
116 
120  void setNumberOfRays(const int& NumberOfRays);
121 
125  inline const int& getNumberOfRays() const
126  {
127  return mNumberOfRays;
128  }
129 
133  inline void setRaysSize(const Ogre::Real& Size)
134  {
135  mRaysSize = Size;
136  }
137 
141  inline const Ogre::Real& getRaysSize() const
142  {
143  return mRaysSize;
144  }
145 
150  {
151  return mPerlin;
152  }
153 
157  inline Ogre::SceneNode* getSceneNode()
158  {
159  return mProjectorSN;
160  }
161 
165  inline void setVisible(const bool& Visible)
166  {
167  if (mCreated)
168  {
169  mManualGodRays->setVisible(Visible);
170  }
171  }
172 
176  inline const bool isVisible() const
177  {
178  if (!mCreated)
179  {
180  return false;
181  }
182 
183  return mManualGodRays->isVisible();
184  }
185 
189  void setObjectIntersectionsEnabled(const bool& Enable);
190 
194  inline const bool& areObjectsIntersectionsEnabled() const
195  {
196  return mObjectsIntersections;
197  }
198 
206  inline const Ogre::Vector4 getNoiseParameters() const
207  {
208  return Ogre::Vector4(mNoiseDerivation,
212  }
213 
220  inline void setNoiseParameters(Ogre::Vector4 Params)
221  {
222  mNoiseDerivation = Params.x;
223  mNoisePositionMultiplier = Params.y;
224  mNoiseYNormalMultiplier = Params.z;
225  mNoiseNormalMultiplier = Params.w;
226  }
227 
228  private:
231  class DepthMapListener : public Ogre::RenderTargetListener
232  {
233  public:
236 
238  std::queue<std::string> mMaterials;
239 
244  void preRenderTargetUpdate(const Ogre::RenderTargetEvent& evt);
245 
250  void postRenderTargetUpdate(const Ogre::RenderTargetEvent& evt);
251  };
252 
257  Ogre::Vector2 _calculateRayPosition(const int& RayNumber);
258 
261  void _createGodRays();
262 
266  void _createMaterials(const HydraxComponent& HC);
267 
270  void _updateRays();
271 
275 
278  void _updateProjector();
279 
282  void _createDepthRTT();
283 
289  bool _isComponent(const HydraxComponent &List, const HydraxComponent &ToCheck) const;
290 
292  bool mCreated;
293 
295  Ogre::ManualObject* mManualGodRays;
297  Ogre::Camera *mProjectorCamera;
299  Ogre::SceneNode *mProjectorSN;
300 
303 
306  Ogre::Real mNoiseDerivation;
314 
317  Ogre::MaterialPtr mMaterials[2];
319  std::vector<Ogre::Technique*> mDepthTechniques;
320 
322  Ogre::Real mSimulationSpeed;
326  Ogre::Real mRaysSize;
329 
332  Ogre::TexturePtr mProjectorRTT;
335 
338  };
339 };
340 
343 
344 #endif
Hydrax::GodRaysManager::getRaysSize
const Ogre::Real & getRaysSize() const
Get god rays size.
Definition: GodRaysManager.h:141
Hydrax::GodRaysManager::_updateMaterialsParameters
void _updateMaterialsParameters()
Update materials parameters.
Definition: GodRaysManager.cpp:359
Hydrax::GodRaysManager::_createDepthRTT
void _createDepthRTT()
Create depth RTT.
Definition: GodRaysManager.cpp:841
Hydrax::GodRaysManager::getSimulationSpeed
const Ogre::Real & getSimulationSpeed() const
Get god rays simulation speed.
Definition: GodRaysManager.h:112
Hydrax::GodRaysManager::mProjectorSN
Ogre::SceneNode * mProjectorSN
Projector scene node.
Definition: GodRaysManager.h:299
Hydrax::GodRaysManager::setNoiseParameters
void setNoiseParameters(Ogre::Vector4 Params)
Set noise params.
Definition: GodRaysManager.h:220
Hydrax::GodRaysManager::addDepthTechnique
void addDepthTechnique(Ogre::Technique *Technique, const bool &AutoUpdate=true)
Add god rays depth technique to an especified material.
Definition: GodRaysManager.cpp:785
Hydrax::GodRaysManager::areObjectsIntersectionsEnabled
const bool & areObjectsIntersectionsEnabled() const
Are rays objects intersections enabled?
Definition: GodRaysManager.h:194
Hydrax::GodRaysManager::DepthMapListener::mMaterials
std::queue< std::string > mMaterials
std::string to store entity's original materials name
Definition: GodRaysManager.h:238
Hydrax::GodRaysManager::GodRaysManager
GodRaysManager(Hydrax *h)
Constructor.
Definition: GodRaysManager.cpp:50
Hydrax::GodRaysManager::MaterialType
MaterialType
God rays material enumeration.
Definition: GodRaysManager.h:51
Hydrax::GodRaysManager::mNoiseDerivation
Ogre::Real mNoiseDerivation
Noise parameters (Used in _calculateRayPosition(...))
Definition: GodRaysManager.h:307
Hydrax::GodRaysManager::DepthMapListener
GodRaysManager::DepthMapListener class.
Definition: GodRaysManager.h:231
Hydrax::GodRaysManager::_isComponent
bool _isComponent(const HydraxComponent &List, const HydraxComponent &ToCheck) const
Is component in the given list?
Definition: GodRaysManager.cpp:821
Hydrax
Definition: CfgFileManager.cpp:28
Hydrax::GodRaysManager::mManualGodRays
Ogre::ManualObject * mManualGodRays
Manual object to create god rays.
Definition: GodRaysManager.h:295
Hydrax::GodRaysManager::mNoisePositionMultiplier
Ogre::Real mNoisePositionMultiplier
PositionMultiplier value.
Definition: GodRaysManager.h:309
Hydrax::Size
Struct wich contains an especific width and height value.
Definition: Help.h:40
Hydrax::GodRaysManager::remove
void remove()
Remove.
Definition: GodRaysManager.cpp:151
Hydrax::GodRaysManager::isVisible
const bool isVisible() const
Is visible?
Definition: GodRaysManager.h:176
Hydrax::GodRaysManager::mHydrax
Hydrax * mHydrax
Hydrax parent pointer.
Definition: GodRaysManager.h:337
Hydrax::GodRaysManager::mProjectorRTT
Ogre::TexturePtr mProjectorRTT
For rays intersection with objects we use a depth map based technique Depth RTT texture.
Definition: GodRaysManager.h:332
Hydrax::GodRaysManager::setObjectIntersectionsEnabled
void setObjectIntersectionsEnabled(const bool &Enable)
Set objects intersections enabled.
Definition: GodRaysManager.cpp:350
Hydrax::GodRaysManager::mNumberOfRays
int mNumberOfRays
Number of rays.
Definition: GodRaysManager.h:324
Enums.h
Hydrax::GodRaysManager::_createMaterials
void _createMaterials(const HydraxComponent &HC)
Create materials that we need(God rays depth too if it's needed)
Definition: GodRaysManager.cpp:419
Hydrax::GodRaysManager::MAT_DEPTH
@ MAT_DEPTH
Definition: GodRaysManager.h:56
Perlin.h
Hydrax::GodRaysManager::_createGodRays
void _createGodRays()
Create god rays manual object.
Definition: GodRaysManager.cpp:128
Hydrax::GodRaysManager::mProjectorCamera
Ogre::Camera * mProjectorCamera
Camera used to project rays.
Definition: GodRaysManager.h:297
Hydrax::GodRaysManager::_calculateRayPosition
Ogre::Vector2 _calculateRayPosition(const int &RayNumber)
Calculate the current position of a ray.
Definition: GodRaysManager.cpp:295
Hydrax::GodRaysManager::mNoiseNormalMultiplier
Ogre::Real mNoiseNormalMultiplier
Normal multiplier.
Definition: GodRaysManager.h:313
Hydrax::GodRaysManager::mRaysSize
Ogre::Real mRaysSize
God rays size.
Definition: GodRaysManager.h:326
Hydrax::GodRaysManager::create
void create(const HydraxComponent &HC)
Create.
Definition: GodRaysManager.cpp:77
Hydrax::GodRaysManager::MAT_GODRAYS
@ MAT_GODRAYS
Definition: GodRaysManager.h:54
Hydrax::GodRaysManager::_updateProjector
void _updateProjector()
Update projector.
Definition: GodRaysManager.cpp:404
Hydrax::GodRaysManager::mMaterials
Ogre::MaterialPtr mMaterials[2]
God rays materials 0-God rays, 1-Depth.
Definition: GodRaysManager.h:317
Hydrax::GodRaysManager::_updateRays
void _updateRays()
Update god rays.
Definition: GodRaysManager.cpp:228
Hydrax::GodRaysManager
Underwater god rays manager class God rays.
Definition: GodRaysManager.h:46
Hydrax::GodRaysManager::SetSimulationSpeed
void SetSimulationSpeed(const Ogre::Real &Speed)
Set god rays simulation speed.
Definition: GodRaysManager.h:104
Hydrax::GodRaysManager::getNumberOfRays
const int & getNumberOfRays() const
Get number of god rays.
Definition: GodRaysManager.h:125
Hydrax::GodRaysManager::isCreated
const bool & isCreated() const
Has been create() already called?
Definition: GodRaysManager.h:85
Prerequisites.h
Hydrax::GodRaysManager::mSimulationSpeed
Ogre::Real mSimulationSpeed
God rays simulation speed.
Definition: GodRaysManager.h:322
Hydrax::GodRaysManager::update
void update(const Ogre::Real &timeSinceLastFrame)
Call each frame.
Definition: GodRaysManager.cpp:209
Hydrax::GodRaysManager::getPerlin
Noise::Perlin * getPerlin()
Get perlin noise module.
Definition: GodRaysManager.h:149
Hydrax::GodRaysManager::mCreated
bool mCreated
Has been create() already called?
Definition: GodRaysManager.h:292
Hydrax::GodRaysManager::setNumberOfRays
void setNumberOfRays(const int &NumberOfRays)
Set the number of god rays.
Definition: GodRaysManager.cpp:333
Hydrax::HydraxComponent
HydraxComponent
Hydrax flags to select components wich we want to use.
Definition: Enums.h:57
Hydrax::GodRaysManager::getSceneNode
Ogre::SceneNode * getSceneNode()
Get good rays scene node.
Definition: GodRaysManager.h:157
Hydrax::GodRaysManager::mPerlin
Noise::Perlin * mPerlin
Our Perlin noise module.
Definition: GodRaysManager.h:302
Hydrax::GodRaysManager::DepthMapListener::mGodRaysManager
GodRaysManager * mGodRaysManager
God rays manager pointer.
Definition: GodRaysManager.h:235
Hydrax::GodRaysManager::DepthMapListener::postRenderTargetUpdate
void postRenderTargetUpdate(const Ogre::RenderTargetEvent &evt)
Funtion that is called after the Rtt will render.
Definition: GodRaysManager.cpp:893
Hydrax::GodRaysManager::mObjectsIntersections
bool mObjectsIntersections
Are god rays objects intersections active?
Definition: GodRaysManager.h:328
Hydrax::Noise::Perlin
Perlin noise module class.
Definition: Perlin.h:73
Hydrax::GodRaysManager::getNoiseParameters
const Ogre::Vector4 getNoiseParameters() const
Get noise params.
Definition: GodRaysManager.h:206
Hydrax::GodRaysManager::mNoiseYNormalMultiplier
Ogre::Real mNoiseYNormalMultiplier
Y normal component multiplier.
Definition: GodRaysManager.h:311
Hydrax::GodRaysManager::setVisible
void setVisible(const bool &Visible)
Set visible.
Definition: GodRaysManager.h:165
Hydrax::GodRaysManager::~GodRaysManager
~GodRaysManager()
Destructor.
Definition: GodRaysManager.cpp:72
Hydrax::GodRaysManager::setRaysSize
void setRaysSize(const Ogre::Real &Size)
Set god rays size.
Definition: GodRaysManager.h:133
Hydrax::GodRaysManager::mDepthTechniques
std::vector< Ogre::Technique * > mDepthTechniques
Technique vector for addDepthTechnique(...)
Definition: GodRaysManager.h:319
Hydrax::GodRaysManager::mDepthMapListener
DepthMapListener mDepthMapListener
Depth RTT listener.
Definition: GodRaysManager.h:334
Hydrax::GodRaysManager::DepthMapListener::preRenderTargetUpdate
void preRenderTargetUpdate(const Ogre::RenderTargetEvent &evt)
Funtion that is called before the Rtt will render.
Definition: GodRaysManager.cpp:869