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
Real.cpp
Go to the documentation of this file.
1/*
2--------------------------------------------------------------------------------
3This source file is part of Hydrax.
4Visit http://www.ogre3d.org/tikiwiki/Hydrax
5
6Copyright (C) 2011 Jose Luis Cercós Pita <jlcercos@gmail.com>
7
8This program is free software; you can redistribute it and/or modify it under
9the terms of the GNU Lesser General Public License as published by the Free Software
10Foundation; either version 2 of the License, or (at your option) any later
11version.
12
13This program is distributed in the hope that it will be useful, but WITHOUT
14ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public License along with
18this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19Place - Suite 330, Boston, MA 02111-1307, USA, or go to
20http://www.gnu.org/copyleft/lesser.txt.
21--------------------------------------------------------------------------------
22*/
23
24// ----------------------------------------------------------------------------
25// Include the main header
26// ----------------------------------------------------------------------------
27#include <Real.h>
28
29// ----------------------------------------------------------------------------
30// Include Hydrax
31// ----------------------------------------------------------------------------
32#include <Hydrax.h>
33
34#define _def_PackedNoise true
35
36namespace Hydrax{ namespace Noise{
37
39 : Noise("Real", true)
40 , mTime(0)
41 , mPerlinNoise(0)
42 , mGPUNormalMapManager(0)
43{
44 mPerlinNoise = new Perlin(/*Generic one*/);
45}
46
48{
49 remove();
50 delete mPerlinNoise;
51
52 HydraxLOG(getName() + " destroyed.");
53}
54
56{
57 if (isCreated())
58 {
59 return;
60 }
61
64}
65
67{
69 {
71 }
72
73 if (!isCreated())
74 {
75 return;
76 }
77
78 mTime = 0;
79
81 mWaves.clear();
82 mPressurePoints.clear();
84}
85
86int Real::addWave(Ogre::Vector2 dir, float A, float T, float p)
87{
88 mWaves.push_back(Wave(dir,A,T,p));
89 return static_cast<int>(mWaves.size());
90}
91
92int Real::addPressurePoint(Ogre::Vector2 Orig, float p, float T, float L)
93{
94 mPressurePoints.push_back(PressurePoint(Orig,p,T,L));
95 return static_cast<int>(mPressurePoints.size());
96}
97
98Wave Real::getWave(int id) const
99{
100 return mWaves.at(id);
101}
102
103bool Real::eraseWave(int id)
104{
105 if( (id < 0) || (id >= (int)mWaves.size()) ){
106 HydraxLOG("Error (Real::eraseWave):\tCan't delete the wave.");
107 HydraxLOG("\tIdentifier exceed the waves vector dimensions.");
108 return false;
109 }
110 size_t Size = mWaves.size();
111 mWaves.erase(mWaves.begin() + id);
112 if(mWaves.size() == Size){
113 HydraxLOG("Error (Real::eraseWave):\tCan't delete the wave.");
114 HydraxLOG("\tThe size before deletion matchs with the size after the operation.");
115 return false;
116 }
117 return true;
118}
119
120bool Real::modifyWave(int id,Ogre::Vector2 dir, float A, float T, float p)
121{
122 if( (id < 0) || (id >= (int)mWaves.size()) ){
123 HydraxLOG("Error (Real::eraseWave):\tCan't delete the wave.");
124 HydraxLOG("\tIdentifier exceed the waves vector dimensions.");
125 return false;
126 }
127 mWaves.at(id) = Wave(dir,A,T,p);
128 return true;
129}
130
132{
134 return false;
135}
136
137void Real::saveCfg(Ogre::String &Data)
138{
139 mPerlinNoise->saveCfg(Data);
140}
141
142bool Real::loadCfg(Ogre::ConfigFile &CfgFile)
143{
144 if (!Noise::loadCfg(CfgFile))
145 {
146 return false;
147 }
148
149 HydraxLOG("\tReading options...");
151 Perlin::Options(CfgFileManager::_getIntValue(CfgFile,"Perlin_Octaves"),
152 CfgFileManager::_getFloatValue(CfgFile,"Perlin_Scale"),
153 CfgFileManager::_getFloatValue(CfgFile,"Perlin_Falloff"),
154 CfgFileManager::_getFloatValue(CfgFile,"Perlin_Animspeed"),
155 CfgFileManager::_getFloatValue(CfgFile,"Perlin_Timemulti"),
156 CfgFileManager::_getFloatValue(CfgFile,"Perlin_GPU_Strength"),
157 CfgFileManager::_getVector3Value(CfgFile,"Perlin_GPU_LODParameters")));
158 HydraxLOG("\tOptions readed.");
159
160 return true;
161}
162
163void Real::update(const Ogre::Real &timeSinceLastFrame)
164{
165 int i;
166 mTime += timeSinceLastFrame;
167 mPerlinNoise->update(timeSinceLastFrame);
168 for(i=(int)mWaves.size()-1;i>=0;i--) {
169 mWaves.at(i).update(timeSinceLastFrame);
170 }
171 for(i=(int)mPressurePoints.size()-1;i>=0;i--) {
172 if(!mPressurePoints.at(i).update(timeSinceLastFrame)) {
173 mPressurePoints.erase(mPressurePoints.begin() + i);
174 }
175 }
176}
177
178float Real::getValue(const float &x, const float &y)
179{
180 int i;
182 float H = mPerlinNoise->getValue(x,y);
184 for(i=0;i<(int)mWaves.size();i++) {
185 H += mWaves.at(i).getValue(x,y);
186 }
188 for(i=0;i<(int)mPressurePoints.size();i++) {
189 H += mPressurePoints.at(i).getValue(x,y);
190 }
191 return H;
192}
193
194}} // namespace Hydrax::Noise
#define HydraxLOG(msg)
Definition Application.h:60
static Ogre::Vector3 _getVector3Value(Ogre::ConfigFile &CfgFile, const Ogre::String Name)
Get vector3 value.
static Ogre::Real _getFloatValue(Ogre::ConfigFile &CfgFile, const Ogre::String Name)
Get float value.
static int _getIntValue(Ogre::ConfigFile &CfgFile, const Ogre::String Name)
Get int value.
Class to manager GPU normal maps.
Base noise class, Override it for create different ways of create water noise.
Definition Noise.h:43
virtual void remove()
Remove.
Definition Noise.cpp:47
const Ogre::String & getName() const
Get noise name.
Definition Noise.h:92
const bool & areGPUNormalMapResourcesCreated() const
Are GPU normal map resources created?
Definition Noise.h:116
virtual bool loadCfg(Ogre::ConfigFile &CfgFile)
Load config.
Definition Noise.cpp:87
virtual void removeGPUNormalMapResources(GPUNormalMapManager *g)
Remove GPUNormalMap resources.
Definition Noise.cpp:71
virtual void create()
Create.
Definition Noise.cpp:42
const bool & isCreated() const
Is created() called?
Definition Noise.h:100
Perlin noise module class.
Definition Perlin.h:74
void update(const Ogre::Real &timeSinceLastFrame)
Call it each frame.
Definition Perlin.cpp:367
void create()
Create.
Definition Perlin.cpp:63
void saveCfg(Ogre::String &Data)
Save config.
Definition Perlin.cpp:335
float getValue(const float &x, const float &y)
Get the especified x/y noise value.
Definition Perlin.cpp:403
void remove()
Remove.
Definition Perlin.cpp:74
void setOptions(const Options &Options)
Set/Update perlin noise options.
Definition Perlin.cpp:91
A PressurePoint defined by the origen, pressure pulse, Maximum time of perturbation and wave longitud...
GPUNormalMapManager * mGPUNormalMapManager
GPUNormalMapManager pointer.
Definition Real.h:179
void remove()
Remove.
Definition Real.cpp:66
void update(const Ogre::Real &timeSinceLastFrame)
Call it each frame.
Definition Real.cpp:163
int addWave(Ogre::Vector2 dir, float A, float T, float p=0.f)
Adds a wave to the system.
Definition Real.cpp:86
double mTime
Elapsed time.
Definition Real.h:173
bool eraseWave(int id)
Removes a wave from the system.
Definition Real.cpp:103
~Real()
Destructor.
Definition Real.cpp:47
void saveCfg(Ogre::String &Data)
Save config.
Definition Real.cpp:137
bool createGPUNormalMapResources(GPUNormalMapManager *g)
Create GPUNormalMap resources.
Definition Real.cpp:131
std::vector< PressurePoint > mPressurePoints
Vector of pressure points.
Definition Real.h:185
std::vector< Wave > mWaves
Vector of waves.
Definition Real.h:182
Perlin * mPerlinNoise
Perlin noise.
Definition Real.h:176
float getValue(const float &x, const float &y)
Get the especified x/y noise value.
Definition Real.cpp:178
void create()
Create.
Definition Real.cpp:55
int addPressurePoint(Ogre::Vector2 Orig, float p, float T, float L)
Adds a pressure point to the system.
Definition Real.cpp:92
Real()
Default constructor.
Definition Real.cpp:38
Wave getWave(int id) const
Returns a wave to the system.
Definition Real.cpp:98
bool modifyWave(int id, Ogre::Vector2 dir, float A, float T, float p=0.f)
Modify a wave from the system.
Definition Real.cpp:120
bool loadCfg(Ogre::ConfigFile &CfgFile)
Load config.
Definition Real.cpp:142
A wave defined by the direction, amplitude, period, and optionally phase.
Definition Wave.h:60
Struct wich contains Perlin noise module options.
Definition Perlin.h:79
Struct wich contains an especific width and height value.
Definition Help.h:41