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
PressurePoint.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 <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
45using namespace Hydrax::Noise;
46
47PressurePoint::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
63
64bool 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
77float 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
96 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
111 return mK1*mK2*mA*sin(mW*mTime - mK*r);
112}
#define _LN001_
#define _HydraxGravity_
#define _HydraxDensity_
float mK1
Time decay term.
bool update(const Ogre::Real &timeSinceLastFrame)
Call it each frame.
double mTime
Elapsed time.
float mK2
Distance decay term.
PressurePoint(Ogre::Vector2 Orig, float p, float T, float L)
Default constructor.
Ogre::Vector2 mPos
Direction (must be normalised)
float getValue(const float &x, const float &y)
Get the especified x/y noise value.
float mC
Speed (calculated)
float mK
Dispersion factor.
#define M_PI