summaryrefslogtreecommitdiff
path: root/src/ocean
diff options
context:
space:
mode:
authorjjesswan <90643397+jjesswan@users.noreply.github.com>2024-04-09 22:19:19 -0400
committerGitHub <noreply@github.com>2024-04-09 22:19:19 -0400
commit8d27ce5bd6902ba515a1e3bad5f2e4d5abd825d3 (patch)
treec6c3ecf092310b242d5df5245c43b347ebba242e /src/ocean
parent7a8d0d8bc2572707c9d35006f30ea835c86954b0 (diff)
parent33da3ed6ca5d92e9a29935150b01b62daef75a04 (diff)
Merge pull request #1 from Seb-Park/jess
add update loop/wave animation
Diffstat (limited to 'src/ocean')
-rw-r--r--src/ocean/ocean.cpp36
-rw-r--r--src/ocean/ocean.h18
2 files changed, 36 insertions, 18 deletions
diff --git a/src/ocean/ocean.cpp b/src/ocean/ocean.cpp
index f70a553..1b0e23c 100644
--- a/src/ocean/ocean.cpp
+++ b/src/ocean/ocean.cpp
@@ -10,18 +10,24 @@
ocean::ocean()
{
initial_h = std::vector<std::pair<double, double>>();
+ current_h = std::vector<std::pair<double, double>>();
+
// initialize the initial height fields
for (int i = 0; i < N; i++)
{
initial_h.push_back(amplitude_0(i));
+ current_h.push_back(initial_h[i]);
}
}
+void ocean::updateVertexAmplitudes(double t){
+ for (int i = 0; i < N; i++){
+ current_h[i] = amplitude_t(t, i);
+ }
+}
+
/* Maps the 1D k-index into it's 2D waveform vector */
-std::pair<double, double> ocean::k_index_to_k_vector
- (
- int k_index
- )
+std::pair<double, double> ocean::k_index_to_k_vector(int k_index)
{
// get the x and z indices
int x = k_index % length;
@@ -200,11 +206,12 @@ std::pair<double, double> ocean::amplitude_t
// add the real and imaginary part together from both h_0 and h_0_conjugate
double real =
// h+0 real
- h_0.first * exp_positive.first
- - h_0.second * exp_positive.second
+ (h_0.first * exp_positive.first)
+ - (h_0.second * exp_positive.second)
// h_0_conjugate real
- + h_0_conjugate.first * exp_negative.first
- - h_0_conjugate.second * exp_negative.second;
+ + (h_0_conjugate.first * exp_negative.first)
+ - (h_0_conjugate.second * exp_negative.second);
+
double imag =
// h_0 imaginary
h_0.first * exp_positive.second
@@ -225,9 +232,14 @@ std::vector<Eigen::Vector3f> ocean::get_vertices()
double k_x = k.first;
double k_z = k.second;
- double amplitude = initial_h[i].first;
+ //if (i < length)
+ double amplitude = current_h[i].first;
+ if (i < length) amplitude = initial_h[i].first;
+
+
+ //if (i==2) std::cout << amplitude << std::endl;
- std::cout << "k_x: " << k_x << " k_z: " << k_z << " amplitude: " << amplitude << std::endl;
+ //std::cout << "k_x: " << k_x << " k_z: " << k_z << " amplitude: " << amplitude << std::endl;
vertices.emplace_back(k_x, amplitude, k_z);
}
@@ -251,8 +263,8 @@ std::vector<Eigen::Vector3i> ocean::get_faces()
int i3 = i + length;
int i4 = i + length + 1;
- faces.emplace_back(i1, i2, i3);
- faces.emplace_back(i2, i3, i4);
+ faces.emplace_back(i2, i1, i3);
+ faces.emplace_back(i2, i3, i4);
}
}
return faces;
diff --git a/src/ocean/ocean.h b/src/ocean/ocean.h
index 7e436cf..faa0fb2 100644
--- a/src/ocean/ocean.h
+++ b/src/ocean/ocean.h
@@ -14,9 +14,17 @@ class ocean
{
public:
ocean();
+ void updateVertexAmplitudes(double t);
+ std::vector<Eigen::Vector3f> get_vertices();
+ std::vector<Eigen::Vector3i> get_faces();
- const int length = 16; // length of grid
- const int width = 16; // width of grid
+
+
+
+private:
+
+ const int length = 32; // length of grid
+ const int width = 32; // width of grid
const int N = length * width; // total number of grid points
const double A = 100; // numeric constant for the Phillips spectrum
@@ -25,13 +33,11 @@ public:
= std::make_pair(1.0, 0.0); // wind direction
std::vector<std::pair<double, double>> initial_h; // initial height fields for each K
+ std::vector<std::pair<double, double>> current_h; // current height fields for each K
+
const double D = 1; // Depth below mean water level (for dispersion relation)
- std::vector<Eigen::Vector3f> get_vertices
- ();
- std::vector<Eigen::Vector3i> get_faces
- ();
std::pair<double, double> k_index_to_k_vector
(