Rigs of Rods 2023.09
Soft-body Physics Simulation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
ProjectedGrid.h
Go to the documentation of this file.
1/*
2--------------------------------------------------------------------------------
3This source file is part of Hydrax.
4Visit ---
5
6Copyright (C) 2008 Xavier Vergu�n Gonz�lez <xavierverguin@hotmail.com>
7 <xavyiy@gmail.com>
8
9This program is free software; you can redistribute it and/or modify it under
10the terms of the GNU Lesser General Public License as published by the Free Software
11Foundation; either version 2 of the License, or (at your option) any later
12version.
13
14This program is distributed in the hope that it will be useful, but WITHOUT
15ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
17
18You should have received a copy of the GNU Lesser General Public License along with
19this program; if not, write to the Free Software Foundation, Inc., 59 Temple
20Place - Suite 330, Boston, MA 02111-1307, USA, or go to
21http://www.gnu.org/copyleft/lesser.txt.
22--------------------------------------------------------------------------------
23
24Based on the Projected Grid concept from Claes Johanson thesis:
25http://graphics.cs.lth.se/theses/projects/projgrid/
26and Ren Cheng Ogre3D implementation:
27http://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
46namespace 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)
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
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
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
NormalMode
Normal generation mode.
Base module class, Override it for create different ways of create water noise.
Definition Module.h:47
Hydrax projected grid module.
Ogre::Quaternion mLastOrientation
void setOptions(const Options &Options)
Set options.
void * mVertices
Vertex pointer (Mesh::POS_NORM_VERTEX or Mesh::POS_VERTEX)
Ogre::Matrix4 mRange
Range matrix.
Ogre::Vector4 t_corners0
For corners.
Hydrax * mHydrax
Our Hydrax pointer.
void _performChoppyWaves()
Perform choppy waves.
void saveCfg(Ogre::String &Data)
Save config.
Options mOptions
Our projected grid options.
const Options & getOptions() const
Get current options.
void _calculeNormals()
Calcule current normals.
void update(const Ogre::Real &timeSinceLastFrame)
Call it each frame.
Ogre::Vector3 mLastPosition
Last camera position, orientation.
bool _getMinMax(Ogre::Matrix4 *range)
Get min/max.
void _setDisplacementAmplitude(const float &Amplitude)
Set displacement amplitude.
float getHeigth(const Ogre::Vector2 &Position)
Get the current heigth at a especified world-space point.
Mesh::POS_NORM_VERTEX * mVerticesChoppyBuffer
Use it to store vertex positions when choppy displacement is enabled.
Ogre::Camera * mProjectingCamera
Cameras.
Ogre::Vector3 mNormal
Normal and position.
Ogre::Plane mBasePlane
Planes.
Ogre::Vector4 _calculeWorldPosition(const Ogre::Vector2 &uv, const Ogre::Matrix4 &m, const Ogre::Matrix4 &_viewMat)
Calcule world position.
bool _renderGeometry(const Ogre::Matrix4 &m, const Ogre::Matrix4 &_viewMat, const Ogre::Vector3 &WorldPos)
Render geometry.
bool loadCfg(Ogre::ConfigFile &CfgFile)
Load config.
Base noise class, Override it for create different ways of create water noise.
Definition Noise.h:43
Vertex struct for position and normals data.
Definition Mesh.h:61
Struct wich contains Hydrax projected grid module options.
float ChoppyStrength
Choppy waves strength.
int Complexity
Projected grid complexity (N*N)
Options(const int &_Complexity, const float &_Strength, const float &_Elevation, const bool &_Smooth, const bool &_ForceRecalculateGeometry, const bool &_ChoppyWaves, const float &_ChoppyStrength)
Constructor.
bool ForceRecalculateGeometry
Force recalculate mesh geometry each frame.
Options(const int &_Complexity)
Constructor.
Options(const int &_Complexity, const float &_Strength, const float &_Elevation, const bool &_Smooth)
Constructor.