RigsofRods
Soft-body Physics Simulation
ProjectedGrid.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 Based on the Projected Grid concept from Claes Johanson thesis:
25 http://graphics.cs.lth.se/theses/projects/projgrid/
26 and Ren Cheng Ogre3D implementation:
27 http://www.cnblogs.com/ArenAK/archive/2007/11/07/951713.html
28 --------------------------------------------------------------------------------
29 */
30 
31 #ifndef _Hydrax_Modules_ProjectedGrid_H_
32 #define _Hydrax_Modules_ProjectedGrid_H_
33 
34 
35 
36 #include "Hydrax.h"
37 #include "Mesh.h"
38 #include "Module.h"
39 
42 
45 
46 namespace Hydrax{ namespace Module
47 {
50  class ProjectedGrid : public Module
51  {
52  public:
55  struct Options
56  {
60  float Strength;
62  float Elevation;
64  bool Smooth;
71 
75  : Complexity(256)
76  , Strength(35.0f)
77  , Elevation(50.0f)
78  , Smooth(false)
80  , ChoppyWaves(true)
81  , ChoppyStrength(3.75f)
82  {
83  }
84 
88  Options(const int &_Complexity)
89  : Complexity(_Complexity)
90  , Strength(35.0f)
91  , Elevation(50.0f)
92  , Smooth(false)
94  , ChoppyWaves(true)
95  , ChoppyStrength(3.75f)
96  {
97  }
98 
105  Options(const int &_Complexity,
106  const float &_Strength,
107  const float &_Elevation,
108  const bool &_Smooth)
109  : Complexity(_Complexity)
110  , Strength(_Strength)
111  , Elevation(_Elevation)
112  , Smooth(_Smooth)
113  , ForceRecalculateGeometry(false)
114  , ChoppyWaves(true)
115  , ChoppyStrength(3.75f)
116  {
117  }
118 
128  Options(const int &_Complexity,
129  const float &_Strength,
130  const float &_Elevation,
131  const bool &_Smooth,
132  const bool &_ForceRecalculateGeometry,
133  const bool &_ChoppyWaves,
134  const float &_ChoppyStrength)
135  : Complexity(_Complexity)
136  , Strength(_Strength)
137  , Elevation(_Elevation)
138  , Smooth(_Smooth)
139  , ForceRecalculateGeometry(_ForceRecalculateGeometry)
140  , ChoppyWaves(_ChoppyWaves)
141  , ChoppyStrength(_ChoppyStrength)
142  {
143  }
144  };
145 
152  ProjectedGrid(Hydrax *h, Noise::Noise *n, const Ogre::Plane &BasePlane, const MaterialManager::NormalMode& NormalMode);
153 
161  ProjectedGrid(Hydrax *h, Noise::Noise *n, const Ogre::Plane &BasePlane, const MaterialManager::NormalMode& NormalMode, const Options &Options);
162 
165  ~ProjectedGrid();
166 
169  void create();
170 
173  void remove();
174 
178  void update(const Ogre::Real &timeSinceLastFrame);
179 
183  void setOptions(const Options &Options);
184 
188  void saveCfg(Ogre::String &Data);
189 
193  bool loadCfg(Ogre::ConfigFile &CfgFile);
194 
199  float getHeigth(const Ogre::Vector2 &Position);
200 
204  inline const Options& getOptions() const
205  {
206  return mOptions;
207  }
208 
209  private:
212  void _calculeNormals();
213 
216  void _performChoppyWaves();
217 
224  bool _renderGeometry(const Ogre::Matrix4& m,const Ogre::Matrix4& _viewMat, const Ogre::Vector3& WorldPos);
225 
232  Ogre::Vector4 _calculeWorldPosition(const Ogre::Vector2 &uv, const Ogre::Matrix4& m,const Ogre::Matrix4& _viewMat);
233 
238  bool _getMinMax(Ogre::Matrix4 *range);
239 
243  void _setDisplacementAmplitude(const float &Amplitude);
244 
246  void *mVertices;
247 
250 
253 
255  Ogre::Matrix4 mRange;
256 
258  Ogre::Plane mBasePlane,
261 
263  Ogre::Camera *mProjectingCamera, // The camera that does the actual projection
264  *mRenderingCamera, // The camera whose frustum the projection is created for
265  *mTmpRndrngCamera; // Used to allow cameras with any inherited from a node or nodes
266 
268  Ogre::Vector3 mNormal, mPos;
269 
271  Ogre::Vector3 mLastPosition;
272  Ogre::Quaternion mLastOrientation;
274 
277 
280  };
281 }}
282 
285 
286 #endif
Hydrax::Module::ProjectedGrid::_calculeNormals
void _calculeNormals()
Calcule current normals.
Definition: ProjectedGrid.cpp:507
Hydrax::Module::ProjectedGrid::Options::Elevation
float Elevation
Elevation.
Definition: ProjectedGrid.h:62
Hydrax::Module::ProjectedGrid::mHydrax
Hydrax * mHydrax
Our Hydrax pointer.
Definition: ProjectedGrid.h:279
Hydrax::Module::ProjectedGrid::t_corners3
Ogre::Vector4 t_corners3
Definition: ProjectedGrid.h:252
Hydrax::Module::ProjectedGrid::getHeigth
float getHeigth(const Ogre::Vector2 &Position)
Get the current heigth at a especified world-space point.
Definition: ProjectedGrid.cpp:838
Hydrax::Module::ProjectedGrid::t_corners1
Ogre::Vector4 t_corners1
Definition: ProjectedGrid.h:252
Hydrax
Definition: CfgFileManager.cpp:28
Hydrax::Module::ProjectedGrid::Options::Options
Options()
Default constructor.
Definition: ProjectedGrid.h:74
Hydrax::Module::ProjectedGrid::ProjectedGrid
ProjectedGrid(Hydrax *h, Noise::Noise *n, const Ogre::Plane &BasePlane, const MaterialManager::NormalMode &NormalMode)
Constructor.
Definition: ProjectedGrid.cpp:58
Hydrax::Module::ProjectedGrid::t_corners2
Ogre::Vector4 t_corners2
Definition: ProjectedGrid.h:252
Hydrax.h
Hydrax::Module::ProjectedGrid::t_corners0
Ogre::Vector4 t_corners0
For corners.
Definition: ProjectedGrid.h:252
Hydrax::Module::ProjectedGrid::mRenderingCamera
Ogre::Camera * mRenderingCamera
Definition: ProjectedGrid.h:264
Hydrax::Module::ProjectedGrid::_setDisplacementAmplitude
void _setDisplacementAmplitude(const float &Amplitude)
Set displacement amplitude.
Definition: ProjectedGrid.cpp:832
Hydrax::Module::ProjectedGrid::mVertices
void * mVertices
Vertex pointer (Mesh::POS_NORM_VERTEX or Mesh::POS_VERTEX)
Definition: ProjectedGrid.h:246
Hydrax::Module::ProjectedGrid::Options::Strength
float Strength
Strength.
Definition: ProjectedGrid.h:60
Hydrax::Module::ProjectedGrid::_calculeWorldPosition
Ogre::Vector4 _calculeWorldPosition(const Ogre::Vector2 &uv, const Ogre::Matrix4 &m, const Ogre::Matrix4 &_viewMat)
Calcule world position.
Definition: ProjectedGrid.cpp:620
Hydrax::Module::ProjectedGrid::Options::Options
Options(const int &_Complexity, const float &_Strength, const float &_Elevation, const bool &_Smooth, const bool &_ForceRecalculateGeometry, const bool &_ChoppyWaves, const float &_ChoppyStrength)
Constructor.
Definition: ProjectedGrid.h:128
Hydrax::Module::ProjectedGrid::mTmpRndrngCamera
Ogre::Camera * mTmpRndrngCamera
Definition: ProjectedGrid.h:265
Hydrax::Module::ProjectedGrid::Options::ForceRecalculateGeometry
bool ForceRecalculateGeometry
Force recalculate mesh geometry each frame.
Definition: ProjectedGrid.h:66
Hydrax::Module::ProjectedGrid::mLastPosition
Ogre::Vector3 mLastPosition
Last camera position, orientation.
Definition: ProjectedGrid.h:271
Hydrax::Noise::Noise
Base noise class, Override it for create different ways of create water noise.
Definition: Noise.h:42
Hydrax::Module::ProjectedGrid::mNormal
Ogre::Vector3 mNormal
Normal and position.
Definition: ProjectedGrid.h:268
Hydrax::Module::ProjectedGrid::saveCfg
void saveCfg(Ogre::String &Data)
Save config.
Definition: ProjectedGrid.cpp:209
Hydrax::MaterialManager::NormalMode
NormalMode
Normal generation mode.
Definition: MaterialManager.h:100
Hydrax::Module::ProjectedGrid::mLastOrientation
Ogre::Quaternion mLastOrientation
Definition: ProjectedGrid.h:272
Hydrax::Module::ProjectedGrid::mBasePlane
Ogre::Plane mBasePlane
Planes.
Definition: ProjectedGrid.h:258
Hydrax::Module::Module
Base module class, Override it for create different ways of create water noise.
Definition: Module.h:46
Hydrax::Module::ProjectedGrid::_renderGeometry
bool _renderGeometry(const Ogre::Matrix4 &m, const Ogre::Matrix4 &_viewMat, const Ogre::Vector3 &WorldPos)
Render geometry.
Definition: ProjectedGrid.cpp:372
Hydrax::Module::ProjectedGrid
Hydrax projected grid module.
Definition: ProjectedGrid.h:50
Hydrax::Module::ProjectedGrid::mRange
Ogre::Matrix4 mRange
Range matrix.
Definition: ProjectedGrid.h:255
Hydrax::Module::ProjectedGrid::~ProjectedGrid
~ProjectedGrid()
Destructor.
Definition: ProjectedGrid.cpp:89
Hydrax::Module::ProjectedGrid::Options
Struct wich contains Hydrax projected grid module options.
Definition: ProjectedGrid.h:55
Hydrax::Module::ProjectedGrid::Options::Options
Options(const int &_Complexity, const float &_Strength, const float &_Elevation, const bool &_Smooth)
Constructor.
Definition: ProjectedGrid.h:105
Hydrax::Module::ProjectedGrid::create
void create()
Create.
Definition: ProjectedGrid.cpp:137
Hydrax::Module::ProjectedGrid::mLastMinMax
bool mLastMinMax
Definition: ProjectedGrid.h:273
Hydrax::Module::ProjectedGrid::mVerticesChoppyBuffer
Mesh::POS_NORM_VERTEX * mVerticesChoppyBuffer
Use it to store vertex positions when choppy displacement is enabled.
Definition: ProjectedGrid.h:249
Mesh.h
Hydrax::Module::ProjectedGrid::getOptions
const Options & getOptions() const
Get current options.
Definition: ProjectedGrid.h:204
Hydrax::Module::ProjectedGrid::Options::ChoppyWaves
bool ChoppyWaves
Choppy waves.
Definition: ProjectedGrid.h:68
Hydrax::Mesh::POS_NORM_VERTEX
Vertex struct for position and normals data.
Definition: Mesh.h:60
Hydrax::Module::ProjectedGrid::mLowerBoundPlane
Ogre::Plane mLowerBoundPlane
Definition: ProjectedGrid.h:260
Hydrax::Module::ProjectedGrid::_getMinMax
bool _getMinMax(Ogre::Matrix4 *range)
Get min/max.
Definition: ProjectedGrid.cpp:645
Hydrax::Module::ProjectedGrid::mOptions
Options mOptions
Our projected grid options.
Definition: ProjectedGrid.h:276
Module.h
Hydrax::Module::ProjectedGrid::Options::Options
Options(const int &_Complexity)
Constructor.
Definition: ProjectedGrid.h:88
Hydrax::Module::ProjectedGrid::loadCfg
bool loadCfg(Ogre::ConfigFile &CfgFile)
Load config.
Definition: ProjectedGrid.cpp:222
Hydrax::Module::ProjectedGrid::_performChoppyWaves
void _performChoppyWaves()
Perform choppy waves.
Definition: ProjectedGrid.cpp:542
Hydrax::Module::ProjectedGrid::mProjectingCamera
Ogre::Camera * mProjectingCamera
Cameras.
Definition: ProjectedGrid.h:263
Hydrax::Module::ProjectedGrid::Options::ChoppyStrength
float ChoppyStrength
Choppy waves strength.
Definition: ProjectedGrid.h:70
Hydrax::Module::ProjectedGrid::Options::Complexity
int Complexity
Projected grid complexity (N*N)
Definition: ProjectedGrid.h:58
Hydrax::Module::ProjectedGrid::setOptions
void setOptions(const Options &Options)
Set options.
Definition: ProjectedGrid.cpp:96
Hydrax::Module::ProjectedGrid::mUpperBoundPlane
Ogre::Plane mUpperBoundPlane
Definition: ProjectedGrid.h:259
Hydrax::Module::ProjectedGrid::remove
void remove()
Remove.
Definition: ProjectedGrid.cpp:171
Hydrax::Module::ProjectedGrid::update
void update(const Ogre::Real &timeSinceLastFrame)
Call it each frame.
Definition: ProjectedGrid.cpp:244
Hydrax::Module::ProjectedGrid::Options::Smooth
bool Smooth
Smooth.
Definition: ProjectedGrid.h:64
Hydrax::Module::ProjectedGrid::mPos
Ogre::Vector3 mPos
Definition: ProjectedGrid.h:268