diff options
Diffstat (limited to 'src/ocean/ocean_alt.cpp')
-rw-r--r-- | src/ocean/ocean_alt.cpp | 58 |
1 files changed, 56 insertions, 2 deletions
diff --git a/src/ocean/ocean_alt.cpp b/src/ocean/ocean_alt.cpp index 6636e62..0e44d9c 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; @@ -49,6 +66,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); + + m_slopes_x.push_back(Eigen::Vector2d(0.0, 0.0)); m_slopes_z.push_back(Eigen::Vector2d(0.0, 0.0)); @@ -231,7 +255,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); } @@ -291,6 +315,18 @@ Eigen::Vector2d ocean_alt::complex_exp(double exponent){ void ocean_alt::update_ocean() { + 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 ++; + } // reset normals & vertices arrays for the single tile m_vertices = std::vector<Eigen::Vector3f>(N); m_normals = std::vector<Eigen::Vector3f>(N); @@ -326,7 +362,25 @@ void ocean_alt::update_ocean() m_vertices[i] = {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; } std::vector<Eigen::Vector3f> ocean_alt::get_vertices(){ |