diff options
author | jjesswan <90643397+jjesswan@users.noreply.github.com> | 2024-05-09 15:13:41 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-09 15:13:41 -0400 |
commit | f846ddba00aee29675f0bd4f5dbc87a94a422368 (patch) | |
tree | 65a857125b91502974bceb40e24c1c7eff4bad59 /src/ocean/ocean_alt.cpp | |
parent | 72bcf6a346dfcaeaac9520d8c524711192e77c3d (diff) | |
parent | 675391d07f50d0067e7bab983433c6d86f5f8256 (diff) |
Merge pull request #3 from Seb-Park/foam2
Foam2 merge -- foam, skybox
Diffstat (limited to 'src/ocean/ocean_alt.cpp')
-rw-r--r-- | src/ocean/ocean_alt.cpp | 60 |
1 files changed, 57 insertions, 3 deletions
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 +} |