-
Notifications
You must be signed in to change notification settings - Fork 0
/
Waves.h
73 lines (58 loc) · 1.91 KB
/
Waves.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//***************************************************************************************
// Waves.h by Frank Luna (C) 2011 All Rights Reserved.
//
// Performs the calculations for the wave simulation. After the simulation has been
// updated, the client must copy the current solution into vertex buffers for rendering.
// This class only does the calculations, it does not do any drawing.
//***************************************************************************************
#ifndef WAVES_H
#define WAVES_H
#include <vector>
#include <list>
#include <DirectXMath.h>
struct WavePixel
{
float earth = 0.f;
float water = 0.f;
};
class Waves
{
public:
Waves(int m, int n, float dx, float dt, float speed, float damping);
Waves(const Waves& rhs) = delete;
Waves& operator=(const Waves& rhs) = delete;
~Waves();
int RowCount()const;
int ColumnCount()const;
int VertexCount()const;
int TriangleCount()const;
float Width()const;
float Depth()const;
// Returns the solution at the ith grid point.
const DirectX::XMFLOAT3& Position(int i)const {
return mCurrSolution[i];
}
// Returns the solution normal at the ith grid point.
const DirectX::XMFLOAT3& Normal(int i)const { return mNormals[i]; }
// Returns the unit tangent vector at the ith grid point in the local x-axis direction.
const DirectX::XMFLOAT3& TangentX(int i)const { return mTangentX[i]; }
void Update(float dt);
std::vector<float> mEarth;
std::vector<WavePixel> mPrevSolution;
std::vector<DirectX::XMFLOAT3> mCurrSolution;
private:
int wave_h = 0;
int wave_w = 0;
int mVertexCount = 0;
int mTriangleCount = 0;
// Simulation constants we can precompute.
float mK1 = 0.0f;
float mK2 = 0.0f;
float mK3 = 0.0f;
float mTimeStep = 0.0f;
float mSpatialStep = 0.0f;
float mTotalTime = 0.0f;
std::vector<DirectX::XMFLOAT3> mNormals;
std::vector<DirectX::XMFLOAT3> mTangentX;
};
#endif // WAVES_H