summaryrefslogtreecommitdiff
path: root/src/ocean
diff options
context:
space:
mode:
Diffstat (limited to 'src/ocean')
-rw-r--r--src/ocean/halftone.cpp47
-rw-r--r--src/ocean/halftone.h19
-rw-r--r--src/ocean/ocean_alt.cpp60
-rw-r--r--src/ocean/ocean_alt.h43
4 files changed, 156 insertions, 13 deletions
diff --git a/src/ocean/halftone.cpp b/src/ocean/halftone.cpp
new file mode 100644
index 0000000..6aa59cb
--- /dev/null
+++ b/src/ocean/halftone.cpp
@@ -0,0 +1,47 @@
+#include "halftone.h"
+#include <cmath>
+#include <vector>
+
+halftone::halftone()
+{
+
+}
+
+//void halftone::init(int n, int m, float density){
+// N = n;
+// M = m;
+// // std::vector<std::vector<int>> m_halftone;
+// // 1. intiialize pattern array with density
+// for (int i=0; i<N; i++){
+// for (int j=0; j<M; j++){
+// // determine whether to place a 1 or 0 here based on density
+
+// // generate random number 0-1
+// float r = ((float) rand() / (float) RAND_MAX);
+// if (r < density){
+// m_halftone[i][j] = 1;
+// } else {
+// m_halftone[i][j] = 0;
+// }
+// }
+// }
+
+//}
+
+//void halftone::apply_gaussian(){
+// for (int i=0; i<N; i++){
+// for (int j=0; j<M; j++){
+// m_halftone[i][j] = radial_gaussian(i, j);
+// }
+// }
+
+//}
+
+//float halftone::radial_gaussian(int i, int j){
+// float r = sqrt((i-.5*N)*(i-.5*N) + (j-.5*M)*(j-.5*M));
+// float result = exp(-(r*r) / (2.f*m_sigma*m_sigma));
+
+// return result;
+
+//}
+
diff --git a/src/ocean/halftone.h b/src/ocean/halftone.h
new file mode 100644
index 0000000..e913eac
--- /dev/null
+++ b/src/ocean/halftone.h
@@ -0,0 +1,19 @@
+#ifndef HALFTONE_H
+#define HALFTONE_H
+
+
+#include <vector>
+class halftone
+{
+public:
+ halftone();
+
+private:
+ int N = 0;
+ int M = 0;
+ float m_sigma = 24.f;
+ std::vector<std::vector<int>> m_halftone;
+
+};
+
+#endif // HALFTONE_H
diff --git a/src/ocean/ocean_alt.cpp b/src/ocean/ocean_alt.cpp
index 025e89b..20c663c 100644
--- a/src/ocean/ocean_alt.cpp
+++ b/src/ocean/ocean_alt.cpp
@@ -12,6 +12,7 @@ ocean_alt::ocean_alt()
// initializes static constants (aka they are not time dependent)
void ocean_alt::init_wave_index_constants(){
+ float tex_step = 1.f/num_rows;
for (int i=0; i<N; i++){
Eigen::Vector2i m_n = index_1d_to_2d(i);
@@ -22,6 +23,23 @@ void ocean_alt::init_wave_index_constants(){
Eigen::Vector2d k_conj = get_k_vector(-n_prime, m_prime);
+// Eigen::Vector3f v = Eigen::Vector3f(0,0,1);
+// Eigen::Vector3f norm = Eigen::Vector3f(0,1,0);
+// if (abs(norm[1]) < 1.f){
+// v = (Eigen::Vector3f(0,1,0) - norm[1]*norm).normalized();
+// }
+// Eigen::Vector3f u = norm.cross(v).normalized();
+
+// float u_coord = u.dot(Eigen::Vector3f(n_prime, 0, m_prime)) / 64.f;
+// float v_coord = v.dot(Eigen::Vector3f(n_prime, 0, m_prime)) / 64.f;
+
+// //std::cout << u_coord << ", " << v_coord << std::endl;
+
+
+ // texture coord:
+ Eigen::Vector2f texCoord = Eigen::Vector2f(1, 1);
+
+
// store h0'(n,m) and w'(n,m) for every index, to be used for later
Eigen::Vector2d h0_prime = h_0_prime(k);
@@ -36,7 +54,6 @@ void ocean_alt::init_wave_index_constants(){
wave_const.h0_prime = h0_prime;
wave_const.h0_prime_conj = h0_prime_conj;
wave_const.w_prime = w_prime;
- wave_const.w_prime = w_prime;
wave_const.base_horiz_pos = get_horiz_pos(i);
wave_const.k_vector = k;
@@ -48,6 +65,13 @@ void ocean_alt::init_wave_index_constants(){
m_slopes.push_back(Eigen::Vector2d(0.0, 0.0));
m_normals.push_back(Eigen::Vector3f(0.0, 1.0, 0.0));
+ // initialize foam constant vectors
+ m_foam_constants.k_vectors.push_back(Eigen::Vector2f(k[0], k[1]));
+ m_foam_constants.positions.push_back(Eigen::Vector3f(0,0,0));
+ m_foam_constants.wavelengths.push_back(0);
+ // m_foam_constants.texCoords.push_back(texCoord);
+
+
}
}
@@ -195,7 +219,7 @@ Eigen::Vector2d ocean_alt::get_k_vector(int n_prime, int m_prime){
double M_ = (double)num_cols;
double k_x = (2*M_PI*n_ - M_PI*N_)/Lx;
- double k_z = (2*M_PI*m_ - M_PI*M_)/Lz;
+ double k_z = (2*M_PI*m_ - M_PI*M_)/Lz;
return Eigen::Vector2d(k_x, k_z);
}
@@ -256,6 +280,17 @@ Eigen::Vector2d ocean_alt::complex_exp(double exponent){
std::vector<Eigen::Vector3f> ocean_alt::get_vertices()
{
std::vector<Eigen::Vector3f> vertices = std::vector<Eigen::Vector3f>();
+ if (iterations < 10){
+ for (int i = 0; i < N; i++){
+ Eigen::Vector2d amplitude = m_current_h[i];
+ float height = amplitude[0];
+
+ if (height < min) min = height;
+ if (height > max) max = height;
+
+ }
+ iterations ++;
+ }
for (int i = 0; i < N; i++){
Eigen::Vector2d horiz_pos = spacing*m_waveIndexConstants[i].base_horiz_pos;
Eigen::Vector2d amplitude = m_current_h[i];
@@ -293,7 +328,26 @@ std::vector<Eigen::Vector3f> ocean_alt::get_vertices()
vertices.push_back(Eigen::Vector3f(horiz_pos[0] + disp[0], height, horiz_pos[1] + disp[1]));
m_normals[i] = norm.normalized();//Eigen::Vector3f(-slope[0], 1.0, -slope[1]).normalized();
//std::cout << "normal: " << m_normals[i] << std::endl
+ Eigen::Vector2i m_n = index_1d_to_2d(i);
+
+
+ // m_foam_constants.wavelengths[i] = 2.f* M_PI * m_slopes[i].dot(m_slopes[i]) / Lx;
+ float h_0 = m_waveIndexConstants[i].h0_prime[0]; // min*.2f;
+ float h_max = max*.01f; // the smaller the constant, the more foam there is
+ m_foam_constants.wavelengths[i] = (height - h_0 ) / (h_max - h_0);
+
+// if (i < 5){
+// std::cout << h_0 << ", " << h_max << std::endl;
+// std::cout << m_foam_constants.wavelengths[i] << std::endl;
+// }
+
+
+
}
+
+ // populate foam constants
+ m_foam_constants.positions = vertices;
+
return vertices;
}
@@ -450,4 +504,4 @@ std::vector<Eigen::Vector2d> ocean_alt::fast_fft
}
return h;
-} \ No newline at end of file
+}
diff --git a/src/ocean/ocean_alt.h b/src/ocean/ocean_alt.h
index 4bb1d54..219ad60 100644
--- a/src/ocean/ocean_alt.h
+++ b/src/ocean/ocean_alt.h
@@ -20,6 +20,13 @@ struct WaveIndexConstant{
Eigen::Vector2d k_vector = Eigen::Vector2d(0.f, 0.f); // static horiz pos with no displacement
};
+struct FoamConstants{
+ std::vector<Eigen::Vector3f> positions;
+ std::vector<Eigen::Vector2f> k_vectors;
+ std::vector<float> wavelengths;
+ std::vector<Eigen::Vector2f> texCoords;
+};
+
class ocean_alt
{
public:
@@ -30,6 +37,10 @@ public:
void fft_prime(double t);
std::vector<Eigen::Vector3f> getNormals();
+ FoamConstants getFoamConstants(){
+ return m_foam_constants;
+ }
+
@@ -49,6 +60,9 @@ private:
std::pair<double, double> sample_complex_gaussian();
+ // FOAM
+ std::vector<float> m_saturation;
+
@@ -56,22 +70,22 @@ private:
- std::map<int, WaveIndexConstant> m_waveIndexConstants; // stores constants that only need to be calculate once for each grid constant
+ std::map<int, WaveIndexConstant> m_waveIndexConstants; // stores constants that only need to be calculate once for each grid constant
- const double Lx = 512.0;
- const double Lz = 512.0;
- const int num_rows = 256;
- const int num_cols = 256;
+ const double Lx = 1024.0;
+ const double Lz = 1024.0;
+ const int num_rows = 256;
+ const int num_cols = 256;
const int N = num_rows*num_cols; // total number of grid points
- const double lambda = 0; // how much displacement matters
- const double spacing = 35.0; // spacing between grid points
+ const double lambda = 2.5; // how much displacement matters
+ const double spacing = 25.0; // spacing between grid points
- const double A = 100; // numeric constant for the Phillips spectrum
- const double V = 50; // wind speed
+ const double A = 200; // numeric constant for the Phillips spectrum
+ const double V = 200; // wind speed
const double gravity = 9.81;
const double L = V*V/gravity;
const Eigen::Vector2d omega_wind = Eigen::Vector2d(1.0, 0.0); // wind direction, used in Phillips equation
@@ -81,7 +95,16 @@ private:
std::vector<Eigen::Vector2d> m_slopes; // current displacement vector for each K
//std::vector<Eigen::Vector3f> m_slope_vectors; // current displacement vector for each K
- std::vector<Eigen::Vector3f> m_normals; // current displacement vector for each K
+ std::vector<Eigen::Vector3f> m_normals; // normal calculations
+
+ // FOR FOAM:
+ FoamConstants m_foam_constants;
+
+
+ float max = 0;
+ float min = 0;
+ int iterations = 0;
+