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
Wave.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 <Wave.h>
28
29// ----------------------------------------------------------------------------
30// Include Hydrax
31// ----------------------------------------------------------------------------
32#include <Hydrax.h>
33
34#define _def_PackedNoise true
35
36using namespace Hydrax::Noise;
37
38Wave::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
56void Wave::update(const Ogre::Real &timeSinceLastFrame)
57{
58 mTime += timeSinceLastFrame;
59}
60
61float 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}
~Wave()
Destructor.
Definition Wave.cpp:52
float mC
Speed (calculated)
Definition Wave.h:128
Ogre::Vector2 mDir
Direction (must be normalised)
Definition Wave.h:120
void update(const Ogre::Real &timeSinceLastFrame)
Call it each frame.
Definition Wave.cpp:56
float mF
Angular frec.
Definition Wave.h:132
Wave(Ogre::Vector2 dir, float A, float T, float p=0.f)
Default constructor.
Definition Wave.cpp:38
float mA
Amplitude.
Definition Wave.h:122
float mK
Dispersion factor.
Definition Wave.h:134
float mL
Longitude (calculated)
Definition Wave.h:130
double mTime
Elapsed time.
Definition Wave.h:117
float mT
Period.
Definition Wave.h:124
float mP
Phase.
Definition Wave.h:126
float getValue(const float &x, const float &y)
Get the especified x/y noise value.
Definition Wave.cpp:61
#define M_PI