RigsofRods
Soft-body Physics Simulation
Wave.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 <Wave.h>
28 
29 // ----------------------------------------------------------------------------
30 // Include Hydrax
31 // ----------------------------------------------------------------------------
32 #include <Hydrax.h>
33 
34 #define _def_PackedNoise true
35 
36 using namespace Hydrax::Noise;
37 
38 Wave::Wave(Ogre::Vector2 dir, float A, float T, float p)
39  : mTime(0)
40  , mDir(dir)
41  , mA(A)
42  , mT(T)
43  , mP(p)
44 {
45  mDir.normalise();
46  mL = 1.5625f*mT*mT;
47  mC = 1.25f*sqrt(mL);
48  mF = 2.f*M_PI/mT;
49  mK = 2.f*M_PI/mL;
50 }
51 
53 {
54 }
55 
56 void Wave::update(const Ogre::Real &timeSinceLastFrame)
57 {
58  mTime += timeSinceLastFrame;
59 }
60 
61 float Wave::getValue(const float &x, const float &y)
62 {
63  float X = mDir.x*x + mDir.y*y;
64  return mA * sin(mF*mTime - mK*X + mP);
65 }
y
float y
Definition: (ValueTypes) quaternion.h:6
Hydrax::Noise::Wave::mP
float mP
Phase.
Definition: Wave.h:126
Hydrax::Noise::Wave::mA
float mA
Amplitude.
Definition: Wave.h:122
Hydrax.h
Hydrax::Noise::Wave::mK
float mK
Dispersion factor.
Definition: Wave.h:134
M_PI
#define M_PI
Definition: Prerequisites.h:41
Hydrax::Noise::Wave::getValue
float getValue(const float &x, const float &y)
Get the especified x/y noise value.
Definition: Wave.cpp:61
Hydrax::Noise::Wave::mF
float mF
Angular frec.
Definition: Wave.h:132
Hydrax::Noise::Wave::mL
float mL
Longitude (calculated)
Definition: Wave.h:130
Hydrax::Noise::Wave::mDir
Ogre::Vector2 mDir
Direction (must be normalised)
Definition: Wave.h:120
Hydrax::Noise::Wave::update
void update(const Ogre::Real &timeSinceLastFrame)
Call it each frame.
Definition: Wave.cpp:56
Hydrax::Noise
Definition: FFT.cpp:30
Hydrax::Noise::Wave::Wave
Wave(Ogre::Vector2 dir, float A, float T, float p=0.f)
Default constructor.
Definition: Wave.cpp:38
Hydrax::Noise::Wave::mC
float mC
Speed (calculated)
Definition: Wave.h:128
Hydrax::Noise::Wave::mT
float mT
Period.
Definition: Wave.h:124
Hydrax::Noise::Wave::~Wave
~Wave()
Destructor.
Definition: Wave.cpp:52
Wave.h
x
float x
Definition: (ValueTypes) quaternion.h:5
Hydrax::Noise::Wave::mTime
double mTime
Elapsed time.
Definition: Wave.h:117