RigsofRods
Soft-body Physics Simulation
PressurePoint.cpp
Go to the documentation of this file.
1 /*
2 --------------------------------------------------------------------------------
3 This source file is part of Hydrax.
4 Visit http://www.ogre3d.org/tikiwiki/Hydrax
5 
6 Copyright (C) 2011 Jose Luis Cercós Pita <jlcercos@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 // ----------------------------------------------------------------------------
25 // Include the main header
26 // ----------------------------------------------------------------------------
27 #include <PressurePoint.h>
28 
29 // ----------------------------------------------------------------------------
30 // Include Hydrax
31 // ----------------------------------------------------------------------------
32 #include <Hydrax.h>
33 
34 #define _def_PackedNoise true
35 
36 #ifndef _LN001_
37  #define _LN001_ -4.605170186
38 #endif
39 
40 // 0 = linear decay function
41 // 1 = exponential decay function
42 // 2 = cuadratic decay function
43 #define _DECAYFUNCTION_ 2
44 
45 using namespace Hydrax::Noise;
46 
47 PressurePoint::PressurePoint(Ogre::Vector2 Orig, float p, float T, float L)
48  : mTime(0)
49  , mPos(Orig)
50  , mP(p)
51  , mT(T)
52  , mL(L)
53 {
55  mK = 2.f * M_PI / mL;
56  mC = 5.f*sqrt(mL);
57  mW = mC*mK;
58 }
59 
61 {
62 }
63 
64 bool PressurePoint::update(const Ogre::Real &timeSinceLastFrame)
65 {
66  mTime += timeSinceLastFrame;
67  if(mTime >= mT) {
68  mK1 = 0.f;
69  return false;
70  }
71 
72  mK1 = exp(_LN001_/mT*mTime) - 0.01f;
73 
74  return true;
75 }
76 
77 float PressurePoint::getValue(const float &x, const float &y)
78 {
80  float R = mC*mTime;
81  float dx = x - mPos.x;
82  if(dx > R)
83  return 0.f;
84  float dy = y - mPos.y;
85  if(dy > R)
86  return 0.f;
87  #if _DECAYFUNCTION_ == 0
88  float r = sqrt(dx*dx + dy*dy);
89  #elif _DECAYFUNCTION_ == 1
90  float r = sqrt(dx*dx + dy*dy);
91  #elif _DECAYFUNCTION_ == 2
92  float r = dx*dx + dy*dy;
93  float R2 = R*R;
94  #endif
95  if(mTime >= mT)
97  return 0.f;
99  if(r >= R)
100  return 0.f;
101  #if _DECAYFUNCTION_ == 0
102  mK2 = 1.f - r/R;
103  #elif _DECAYFUNCTION_ == 1
104  mK2 = exp(_LN001_*r/R) - 0.01f;
105  #elif _DECAYFUNCTION_ == 2
106  float f = r/R2;
107  mK2 = 1.f - f;
108  r = f*R;
109  #endif
110  return mK1*mK2*mA*sin(mW*mTime - mK*r);
112 }
Hydrax::Noise::PressurePoint::mPos
Ogre::Vector2 mPos
Direction (must be normalised)
Definition: PressurePoint.h:134
y
float y
Definition: (ValueTypes) quaternion.h:6
Hydrax::Noise::PressurePoint::mT
float mT
Period.
Definition: PressurePoint.h:138
Hydrax.h
PressurePoint.h
_LN001_
#define _LN001_
Definition: PressurePoint.cpp:37
Hydrax::Noise::PressurePoint::update
bool update(const Ogre::Real &timeSinceLastFrame)
Call it each frame.
Definition: PressurePoint.cpp:64
Hydrax::Noise::PressurePoint::getValue
float getValue(const float &x, const float &y)
Get the especified x/y noise value.
Definition: PressurePoint.cpp:77
M_PI
#define M_PI
Definition: Prerequisites.h:41
Hydrax::Noise::PressurePoint::mK1
float mK1
Time decay term.
Definition: PressurePoint.h:150
Hydrax::Noise::PressurePoint::mW
float mW
Angular frec.
Definition: PressurePoint.h:148
Hydrax::Noise::PressurePoint::PressurePoint
PressurePoint(Ogre::Vector2 Orig, float p, float T, float L)
Default constructor.
Definition: PressurePoint.cpp:47
Hydrax::Noise::PressurePoint::mK2
float mK2
Distance decay term.
Definition: PressurePoint.h:152
Hydrax::Noise::PressurePoint::mP
float mP
Pressure.
Definition: PressurePoint.h:136
_HydraxGravity_
#define _HydraxGravity_
Definition: PressurePoint.h:51
Hydrax::Noise
Definition: FFT.cpp:30
_HydraxDensity_
#define _HydraxDensity_
Definition: PressurePoint.h:48
Hydrax::Noise::PressurePoint::mL
float mL
Lenght.
Definition: PressurePoint.h:140
Hydrax::Noise::PressurePoint::mTime
double mTime
Elapsed time.
Definition: PressurePoint.h:131
Hydrax::Noise::PressurePoint::mC
float mC
Speed (calculated)
Definition: PressurePoint.h:146
Hydrax::Noise::PressurePoint::~PressurePoint
~PressurePoint()
Destructor.
Definition: PressurePoint.cpp:60
x
float x
Definition: (ValueTypes) quaternion.h:5
Hydrax::Noise::PressurePoint::mA
float mA
Ampliutde.
Definition: PressurePoint.h:142
Hydrax::Noise::PressurePoint::mK
float mK
Dispersion factor.
Definition: PressurePoint.h:144