diff options
author | sotech117 <michael_foiani@brown.edu> | 2024-05-09 20:21:38 -0400 |
---|---|---|
committer | sotech117 <michael_foiani@brown.edu> | 2024-05-09 20:21:38 -0400 |
commit | ac3f1e423e696392ea0a50c2652b829e5c5734b6 (patch) | |
tree | b6ecb80019dae822619079ce34336d34a033f2df /src | |
parent | f846ddba00aee29675f0bd4f5dbc87a94a422368 (diff) | |
parent | 14684344d553dee4b3cc252709716bff927e85b8 (diff) |
resolve merge conflicts and attempt to fix local paths
Diffstat (limited to 'src')
-rw-r--r-- | src/arap.cpp | 41 | ||||
-rwxr-xr-x | src/glwidget.cpp | 108 | ||||
-rw-r--r-- | src/graphics/shape.cpp | 6 | ||||
-rw-r--r-- | src/ocean/ocean_alt.cpp | 212 | ||||
-rw-r--r-- | src/ocean/ocean_alt.h | 42 | ||||
-rw-r--r-- | src/skybox.cpp | 10 | ||||
-rw-r--r-- | src/skybox.h | 12 |
7 files changed, 281 insertions, 150 deletions
diff --git a/src/arap.cpp b/src/arap.cpp index 9bfbd27..6239f83 100644 --- a/src/arap.cpp +++ b/src/arap.cpp @@ -34,7 +34,7 @@ void ARAP::init // if (MeshLoader::loadTriMesh(m_mesh_path, vertices, triangles)) { // m_shape.init(vertices, triangles); // } - + m_ocean.update_ocean(); vertices = m_ocean.get_vertices(); triangles = m_ocean.get_faces(); m_shape.init(vertices, triangles); @@ -51,8 +51,20 @@ void ARAP::init coeffMin = all_vertices.colwise().minCoeff(); coeffMax = all_vertices.colwise().maxCoeff(); - minCorner = coeffMin; - maxCorner = coeffMax; +// minCorner = coeffMin; +// maxCorner = coeffMax; +// + std::cout << "minCorner: " << minCorner << std::endl; + std::cout << "maxCorner: " << maxCorner << std::endl; +// +// minCorner = Vector3f(0.0f, 0.0f, 0.0f); +// maxCorner = Vector3f(1.0f, 0.0f, 1.0f); +// +// std::cout << "minCorner: " << minCorner << std::endl; +// std::cout << "maxCorner: " << maxCorner << std::endl; +// +// minCorner = Vector3f(-1.0f, -1.0f, -1.0f); +// maxCorner = Vector3f(1.0f, 1.0f, 1.0f); // m_shape.initGroundPlane("cornell_box_full_lighting.png") @@ -104,13 +116,24 @@ void ARAP::update(double seconds) // Note that the "seconds" parameter represents the amount of time that has passed since // the last update + m_ocean.fft_prime(m_time); + m_ocean.update_ocean(); + m_shape.setVertices_and_Normals(m_ocean.get_vertices(), m_ocean.getNormals()); + // m_shape.setVertices(m_ocean.get_vertices()); + + auto tmp = m_ocean.get_vertices(); + // print the min and max of the vertices + Vector3f min = Vector3f::Ones() * 1000000; + Vector3f max = Vector3f::Ones() * -1000000; + for (int i = 0; i < tmp.size(); i++) { + min = min.cwiseMin(tmp[i]); + max = max.cwiseMax(tmp[i]); + } + std::cout << "min: " << min << std::endl; +std::cout << "max: " << max << std::endl; - m_ocean.fft_prime(m_time); - // m_shape.setVertices_and_Normals(m_ocean.get_vertices(), m_ocean.getNormals()); - m_shape.setVertices(m_ocean.get_vertices()); - - FoamConstants foam = m_ocean.getFoamConstants(); - m_foam_shape.setFoamInputs(m_shape.getVertices(), foam.wavelengths, foam.k_vectors, foam.texCoords); + FoamConstants foam = m_ocean.getFoamConstants(); + m_foam_shape.setFoamInputs(m_shape.getVertices(), foam.wavelengths, foam.k_vectors, foam.texCoords); m_time += m_timestep; diff --git a/src/glwidget.cpp b/src/glwidget.cpp index f9bedc9..91d38bc 100755 --- a/src/glwidget.cpp +++ b/src/glwidget.cpp @@ -85,8 +85,8 @@ void GLWidget::initializeGL() // // Enable depth-testing and backface culling glEnable(GL_DEPTH_TEST); - glEnable(GL_CULL_FACE); - glCullFace(GL_BACK); +// glEnable(GL_CULL_FACE); +// glCullFace(GL_BACK); // glShadeModel(GL_SMOOTH); @@ -106,8 +106,8 @@ void GLWidget::initializeGL() // m_skyboxShader->unbind(); - m_halftone_tex = loadTextureFromFile("/Users/jesswan/Desktop/cs2240/ocean-simulation/resources/images/halftone.png").textureID; - m_foam_tex = loadTextureFromFile("/Users/jesswan/Desktop/cs2240/ocean-simulation/resources/images/foam3.png").textureID; + m_halftone_tex = loadTextureFromFile(":resources/images/halftone.png").textureID; + m_foam_tex = loadTextureFromFile(":resources/images/foam3.png").textureID; @@ -198,7 +198,7 @@ void GLWidget::initializeGL() m_camera.setPerspective(120, width() / static_cast<float>(height()), nearPlane, farPlane); m_camera.setPosition(Eigen::Vector3f( 0, 0, - -70289.5)); + 0)); m_deltaTimeProvider.start(); m_intervalTimer.start(1000 / 60); @@ -206,29 +206,39 @@ void GLWidget::initializeGL() } void GLWidget::paintCaustics() { - glBindFramebuffer(GL_FRAMEBUFFER, m_fbo); + glClearColor(0.68f, 0.58f, 0.38f, 1); +// glClearColor(0., 0., 0., 1); - // Task 15: Clear the screen here + glBindFramebuffer(GL_FRAMEBUFFER, m_fbo); +// glBindFramebuffer(GL_FRAMEBUFFER, m_defaultFBO); - // TA SOLUTION + // Clear Screen glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnable( GL_BLEND ); - // Bind the shader - m_colorShader->bind(); - - // Task 16: Bind your VAO here - - // TA SOLUTION - glBindVertexArray(m_floor_vao); +// // Bind the shader +// m_colorShader->bind(); - // Task 17: Draw your VAO here +//// m_colorShader->setUniform("asdf", m_arap.minCorner[0], m_arap.maxCorner[0]); +//// // Bind VAO +// glBindVertexArray(m_floor_vao); - // TA SOLUTION - glDrawArrays(GL_TRIANGLES, 0, 3); +//// // Draw the VAO +// glDrawArrays(GL_TRIANGLES, 0, 3); - // Task 18: Unbind your VAO here + m_colorShader->bind(); + // + m_colorShader->setUniform("proj", m_camera.getProjection()); + m_colorShader->setUniform("view", m_camera.getView()); + Eigen::Matrix4f inverseView = m_camera.getView().inverse(); + m_colorShader->setUniform("inverseView", inverseView); + // + m_colorShader->setUniform("widthBounds", m_arap.minCorner[0], m_arap.maxCorner[0]); + m_colorShader->setUniform("lengthBounds", m_arap.minCorner[2], m_arap.maxCorner[2]); + m_arap.draw(m_colorShader, GL_TRIANGLES); - // TA SOLUTION + // Unbind the VAO glBindVertexArray(0); // Unbind the shader @@ -341,6 +351,7 @@ void GLWidget::makeFBO() { void GLWidget::paintGL() { paintCaustics(); + glClearColor(0.56f, 0.69f, 0.74f, 1); glBindFramebuffer(GL_FRAMEBUFFER, m_defaultFBO); // return; // paintTexture(m_ground_texture, false); @@ -356,6 +367,7 @@ void GLWidget::paintGL() m_defaultShader->setUniform("widthBounds", m_arap.minCorner[0], m_arap.maxCorner[0]); m_defaultShader->setUniform("lengthBounds", m_arap.minCorner[2], m_arap.maxCorner[2]); + // Set the ocean floor to the painted caustics glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_2D, m_fbo_texture); glUniform1i(glGetUniformLocation(m_defaultShader->id(), "groundSampler"), 2); @@ -374,36 +386,36 @@ void GLWidget::paintGL() // m_arap.draw(m_pointShader, GL_POINTS); // m_pointShader->unbind(); - m_foamShader->bind(); - m_foamShader->setUniform("proj", m_camera.getProjection()); - m_foamShader->setUniform("view", m_camera.getView()); -// m_foamShader->setUniform("vSize", m_vSize); -// m_foamShader->setUniform("width", width()); -// m_foamShader->setUniform("height", height()); - glUniform1f(glGetUniformLocation(m_foamShader->id(), "time"), m_arap.getTime()); - glUniform1f(glGetUniformLocation(m_foamShader->id(), "phaseC"), 1.f); - m_foamShader->setUniform("widthBounds", m_arap.minCorner[0], m_arap.maxCorner[0]); - m_foamShader->setUniform("lengthBounds", m_arap.minCorner[2], m_arap.maxCorner[2]); - - glActiveTexture(GL_TEXTURE5); - glBindTexture(GL_TEXTURE_2D, m_halftone_tex); - glUniform1i(glGetUniformLocation(m_foamShader->id(), "halftone_texture"), 5); - - glActiveTexture(GL_TEXTURE6); - glBindTexture(GL_TEXTURE_2D, m_foam_tex); - glUniform1i(glGetUniformLocation(m_foamShader->id(), "foam_texture"), 6); +// m_foamShader->bind(); +// m_foamShader->setUniform("proj", m_camera.getProjection()); +// m_foamShader->setUniform("view", m_camera.getView()); +//// m_foamShader->setUniform("vSize", m_vSize); +//// m_foamShader->setUniform("width", width()); +//// m_foamShader->setUniform("height", height()); +// glUniform1f(glGetUniformLocation(m_foamShader->id(), "time"), m_arap.getTime()); +// glUniform1f(glGetUniformLocation(m_foamShader->id(), "phaseC"), 1.f); +// m_foamShader->setUniform("widthBounds", m_arap.minCorner[0], m_arap.maxCorner[0]); +// m_foamShader->setUniform("lengthBounds", m_arap.minCorner[2], m_arap.maxCorner[2]); +// +// glActiveTexture(GL_TEXTURE5); +// glBindTexture(GL_TEXTURE_2D, m_halftone_tex); +// glUniform1i(glGetUniformLocation(m_foamShader->id(), "halftone_texture"), 5); +// +// glActiveTexture(GL_TEXTURE6); +// glBindTexture(GL_TEXTURE_2D, m_foam_tex); +// glUniform1i(glGetUniformLocation(m_foamShader->id(), "foam_texture"), 6); - m_arap.drawFoam(m_foamShader, GL_TRIANGLES); - m_foamShader->unbind(); - - // skybox - - - - m_skybox.draw(m_skyboxShader, m_camera); +// m_arap.drawFoam(m_foamShader, GL_TRIANGLES); +// m_foamShader->unbind(); +// +// // skybox +// +// +// +// m_skybox.draw(m_skyboxShader, m_camera); @@ -502,6 +514,10 @@ void GLWidget::resizeGL(int w, int h) { glViewport(0, 0, w, h); m_camera.setAspect(static_cast<float>(w) / h); + glDeleteTextures(1, &m_fbo_texture); + glDeleteRenderbuffers(1, &m_fbo_renderbuffer); + glDeleteFramebuffers(1, &m_fbo); + makeFBO(); } // ================== Event Listeners diff --git a/src/graphics/shape.cpp b/src/graphics/shape.cpp index e0afb83..1baa233 100644 --- a/src/graphics/shape.cpp +++ b/src/graphics/shape.cpp @@ -161,13 +161,13 @@ void Shape::draw(Shader *shader, GLenum mode) // Not that one texture is overwriting the other, because if we just load sky it doesn't work // Draws whatever is bound to texture0 no matter what. // Drawing the ground texture. - /* // When ground is being rendered dynamically, don't use static ground image. +/* // When ground is being rendered dynamically, don't use static ground image. glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, m_ground_texture); // glBindTexture(GL_TEXTURE_2D, 0); shader->setUniform("groundSampler", 0); - glUniform1i(glGetUniformLocation(shader->id(), "groundSampler"), 0); - */ + glUniform1i(glGetUniformLocation(shader->id(), "groundSampler"), 0);*/ + // https://stackoverflow.com/questions/67277087/opengl-glsl-multiple-texture-binding-not-working // FIGURED OUT THE PROBLEM. it was that SAMPLERS WERE DEFAULTING TO SLOT 0 AND SETUNIFORM WASN'T WORKING diff --git a/src/ocean/ocean_alt.cpp b/src/ocean/ocean_alt.cpp index 20c663c..0e44d9c 100644 --- a/src/ocean/ocean_alt.cpp +++ b/src/ocean/ocean_alt.cpp @@ -60,9 +60,10 @@ void ocean_alt::init_wave_index_constants(){ m_waveIndexConstants[i] = wave_const; // initialize m_current_h to be h0 for now - m_current_h.push_back(h0_prime); - m_displacements.push_back(Eigen::Vector2d(0.0, 0.0)); - m_slopes.push_back(Eigen::Vector2d(0.0, 0.0)); +// m_current_h.push_back(h0_prime); + m_current_h.push_back(Eigen::Vector2d(0.0, 0.0)); + // m_displacements.push_back(Eigen::Vector2d(0.0, 0.0)); + // 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 @@ -72,6 +73,13 @@ void ocean_alt::init_wave_index_constants(){ // 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)); + + m_displacements_x.push_back(Eigen::Vector2d(0.0, 0.0)); + m_displacements_z.push_back(Eigen::Vector2d(0.0, 0.0)); + + m_vertices.push_back(Eigen::Vector3f(0.0, 0.0, 0.0)); } } @@ -80,8 +88,14 @@ void ocean_alt::fft_prime(double t){ // FFT std::vector<Eigen::Vector2d> h_tildas = std::vector<Eigen::Vector2d>(); - std::vector<Eigen::Vector2d> ikh = std::vector<Eigen::Vector2d>(); - std::vector<Eigen::Vector2d> neg_ik_hat_h = std::vector<Eigen::Vector2d>(); + // std::vector<Eigen::Vector2d> ikh = std::vector<Eigen::Vector2d>(); +// std::vector<Eigen::Vector2d> neg_ik_hat_h = std::vector<Eigen::Vector2d>(); + + std::vector<Eigen::Vector2d> ikhx = std::vector<Eigen::Vector2d>(); + std::vector<Eigen::Vector2d> ikhz = std::vector<Eigen::Vector2d>(); + + std::vector<Eigen::Vector2d> neg_ik_hat_h_x = std::vector<Eigen::Vector2d>(); + std::vector<Eigen::Vector2d> neg_ik_hat_h_z = std::vector<Eigen::Vector2d>(); // find each h_tilda at each index, to be used for next for loop for (int i=0; i<N; i++){ @@ -90,25 +104,47 @@ void ocean_alt::fft_prime(double t){ h_tildas.emplace_back(h_t_prime); Eigen::Vector2d k_vector = m_waveIndexConstants[i].k_vector; - ikh.emplace_back(-h_t_prime[1] * k_vector[0], -h_t_prime[1] * k_vector[1]); + // ikh.emplace_back(-h_t_prime[1] * k_vector[0], -h_t_prime[1] * k_vector[1]); + ikhx.emplace_back(-h_t_prime[1] * k_vector[0], -h_t_prime[1] * k_vector[0]); + ikhz.emplace_back(-h_t_prime[1] * k_vector[1], -h_t_prime[1] * k_vector[1]); + - Eigen::Vector2d k_normalized = k_vector.normalized(); - Eigen::Vector2d neg_ik_hat_h_val = - Eigen::Vector2d(k_normalized[1] * h_t_prime[1], k_normalized[0] * h_t_prime[1]); - neg_ik_hat_h.emplace_back(neg_ik_hat_h_val); +// Eigen::Vector2d neg_ik_hat_h_val = +// Eigen::Vector2d(k_normalized[1] * h_t_prime[1], k_normalized[0] * h_t_prime[1]); +// neg_ik_hat_h.emplace_back(neg_ik_hat_h_val); + double len = k_vector.norm(); + if (len < .000001) + { + neg_ik_hat_h_x.emplace_back(0.0, 0.0); + neg_ik_hat_h_z.emplace_back(0.0, 0.0); + } + else + { + Eigen::Vector2d k_normalized = k_vector.normalized(); + neg_ik_hat_h_x.emplace_back(k_normalized[0] * h_t_prime[1], k_normalized[0] * h_t_prime[1]); + neg_ik_hat_h_z.emplace_back(k_normalized[1] * h_t_prime[1], k_normalized[1] * h_t_prime[1]); + } } bool fast = true; if (fast) { std::vector<Eigen::Vector2d> tmp = fast_fft(h_tildas); - std::vector<Eigen::Vector2d> tmp2 = fast_fft(ikh); - std::vector<Eigen::Vector2d> tmp3 = fast_fft(neg_ik_hat_h); +// std::vector<Eigen::Vector2d> tmp2 = fast_fft(ikh); + // std::vector<Eigen::Vector2d> tmp3 = fast_fft(neg_ik_hat_h); + std::vector<Eigen::Vector2d> tmp4 = fast_fft(ikhx); + std::vector<Eigen::Vector2d> tmp5 = fast_fft(ikhz); + std::vector<Eigen::Vector2d> tmp6 = fast_fft(neg_ik_hat_h_x); + std::vector<Eigen::Vector2d> tmp7 = fast_fft(neg_ik_hat_h_z); for (int i = 0; i < N; i++) { m_current_h[i] = tmp[i]; - m_slopes[i] = tmp2[i]; - m_displacements[i] = tmp3[i]; + // m_slopes[i] = tmp2[i]; + // m_displacements[i] = tmp3[i]; + m_slopes_x[i] = tmp4[i]; + m_slopes_z[i] = tmp5[i]; + m_displacements_x[i] = tmp6[i]; + m_displacements_z[i] = tmp7[i]; } return; @@ -118,8 +154,8 @@ void ocean_alt::fft_prime(double t){ for (int i=0; i<N; i++){ Eigen::Vector2d x_vector = m_waveIndexConstants[i].base_horiz_pos; m_current_h[i] = Eigen::Vector2d(0.0, 0.0); - m_displacements[i] = Eigen::Vector2d(0.0, 0.0); - m_slopes[i] = Eigen::Vector2d(0.0, 0.0); + // m_displacements[i] = Eigen::Vector2d(0.0, 0.0); + // m_slopes[i] = Eigen::Vector2d(0.0, 0.0); @@ -139,8 +175,8 @@ void ocean_alt::fft_prime(double t){ Eigen::Vector2d k_normalized = k_vector.normalized(); - m_displacements[i] += k_normalized*imag_comp; - m_slopes[i] += -k_vector*imag_comp; + // m_displacements[i] += k_normalized*imag_comp; + // m_slopes[i] += -k_vector*imag_comp; } } @@ -277,7 +313,7 @@ Eigen::Vector2d ocean_alt::complex_exp(double exponent){ return Eigen::Vector2d(real, imag); } -std::vector<Eigen::Vector3f> ocean_alt::get_vertices() +void ocean_alt::update_ocean() { std::vector<Eigen::Vector3f> vertices = std::vector<Eigen::Vector3f>(); if (iterations < 10){ @@ -291,41 +327,39 @@ std::vector<Eigen::Vector3f> ocean_alt::get_vertices() } iterations ++; } + // reset normals & vertices arrays for the single tile + m_vertices = std::vector<Eigen::Vector3f>(N); + m_normals = std::vector<Eigen::Vector3f>(N); 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]; float height = amplitude[0]; - Eigen::Vector2d slope = m_slopes[i] * .3f; - Eigen::Vector3f s = Eigen::Vector3f(-slope[0], 0.0, -slope[1]); - Eigen::Vector3f y = Eigen::Vector3f(0.0, 1.0, 0.0); - - float xs = 1.f + s[0]*s[0]; - float ys = 1.f + s[1]*s[1]; - float zs = 1.f + s[2]*s[2]; + // Eigen::Vector2d slope = m_slopes[i] * .3f; + // Eigen::Vector3f s = Eigen::Vector3f(-slope[0], 0.0, -slope[1]); + // Eigen::Vector3f y = Eigen::Vector3f(0.0, 1.0, 0.0); +// float xs = 1.f + s[0]*s[0]; +// float ys = 1.f + s[1]*s[1]; +// float zs = 1.f + s[2]*s[2]; +// // Eigen::Vector3f diff = y - s; -// Eigen::Vector3f norm = Eigen::Vector3f(diff[0]/ sqrt(xs), diff[1]/ sqrt(ys), diff[2]/sqrt(zs)); +// Eigen::Vector3f Eigen::Vector3f(diff[0]/ sqrt(xs), diff[1]/ sqrt(ys), diff[2]/sqrt(zs)); // NEW - Eigen::Vector3f norm = Eigen::Vector3f(-slope[0], 1.0, -slope[1]); - norm.normalize(); - //NEW - - - - + Eigen::Vector3f norm = Eigen::Vector3f(-m_slopes_x[i][0], 1.0, -m_slopes_z[i][0]); + norm = norm.normalized(); // FIXME: why do I have to be inverted? //if (i==6) std::cout << amplitude[0] << std::endl; // calculate displacement - Eigen::Vector2d disp = lambda*m_displacements[i]; - - // + // Eigen::Vector2d disp = lambda*m_displacements[i]; + Eigen::Vector2d disp = lambda*Eigen::Vector2d(m_displacements_x[i][0], m_displacements_z[i][0]) + + Eigen::Vector2d(vertex_displacement, vertex_displacement); // set corner at 0,0 for retiling // for final vertex position, use the real number component of amplitude vector - vertices.push_back(Eigen::Vector3f(horiz_pos[0] + disp[0], height, horiz_pos[1] + disp[1])); + 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); @@ -347,38 +381,98 @@ std::vector<Eigen::Vector3f> ocean_alt::get_vertices() // populate foam constants m_foam_constants.positions = vertices; +} - return vertices; +std::vector<Eigen::Vector3f> ocean_alt::get_vertices(){ + // extend the returned array based on the tilecount + std::vector<Eigen::Vector3f> vertices = std::vector<Eigen::Vector3f>(); + for (int i = 0; i < num_tiles_x; i++) + { + for (int j = 0; j < num_tiles_z; j++) + { + for (int k = 0; k < N; k++) + { + double c = Lx - 2 / (num_rows / Lx); + Eigen::Vector3f vertex = m_vertices[k] + Eigen::Vector3f(i*(c), 0.0, (j)*(c)); + vertices.push_back(vertex); + } + } + } + + return vertices; } std::vector<Eigen::Vector3f> ocean_alt::getNormals(){ - return m_normals; + // based on the tile count, add more to the normals + std::vector<Eigen::Vector3f> normals = std::vector<Eigen::Vector3f>(); + // do the x 1D direction first + for (int i = 0; i < num_tiles_x; i++) + { + for (int j = 0; j < num_tiles_z; j++) + { + for (int k = 0; k < N; k++) + { + normals.push_back(m_normals[k]); + } + } + } + + + return normals; } std::vector<Eigen::Vector3i> ocean_alt::get_faces() { // connect the vertices into faces std::vector<Eigen::Vector3i> faces = std::vector<Eigen::Vector3i>(); - for (int i = 0; i < N; i++) - { - int x = i / num_rows; - int z = i % num_rows; + for (int i = 0; i < num_tiles_x; i++) + { + for (int j = 0; j < num_tiles_z; j++) + { + for (int k = 0; k < N; k++) + { + int x = k % num_rows; + int z = k / num_rows; - // connect the vertices into faces - if (x < num_rows - 1 && z < num_cols - 1) - { - int i1 = i; - int i2 = i + 1; - int i3 = i + num_rows; - int i4 = i + num_rows + 1; + // connect the vertices into faces + if (x < num_rows - 1 && z < num_cols - 1) + { + int tile_index_offset = (j + num_tiles_z * i) * N; + int i1 = k + tile_index_offset; + int i2 = k + 1 + tile_index_offset; + int i3 = k + num_rows + tile_index_offset; + int i4 = k + num_rows + 1 + tile_index_offset; + + faces.emplace_back(i2, i1, i3); + faces.emplace_back(i2, i3, i4); + } + } + } + } + return faces; + + +// for (int i = 0; i < N; i++) +// { +// int x = i / num_rows; +// int z = i % num_rows; +// +// // connect the vertices into faces +// if (x < num_rows - 1 && z < num_cols - 1) +// { +// int i1 = i; +// int i2 = i + 1; +// int i3 = i + num_rows; +// int i4 = i + num_rows + 1; +// // faces.emplace_back(i2, i1, i3); // faces.emplace_back(i2, i3, i4); - faces.emplace_back(i1, i2, i3); - faces.emplace_back(i3, i2, i4); - } - } - return faces; +// faces.emplace_back(i1, i2, i3); +// faces.emplace_back(i3, i2, i4); +// } +// } +// return faces; } Eigen::Vector2d muliply_complex(Eigen::Vector2d a, Eigen::Vector2d b) @@ -495,11 +589,11 @@ std::vector<Eigen::Vector2d> ocean_alt::fast_fft } // divide by N*N and add the signs based on the indices - double sign[] = {1, -1}; + double sign[] = {1.0, -1.0}; for (int i = 0; i < N; i++) { - // h[i] /= N; - h[i] /= sqrt(N); + h[i] /= N; + // h[i] /= sqrt(N); h[i] *= sign[(i / num_rows + i % num_cols) % 2]; } diff --git a/src/ocean/ocean_alt.h b/src/ocean/ocean_alt.h index 219ad60..dc8888d 100644 --- a/src/ocean/ocean_alt.h +++ b/src/ocean/ocean_alt.h @@ -32,6 +32,7 @@ class ocean_alt public: ocean_alt(); void updateVertexAmplitudes(double t); + void update_ocean(); std::vector<Eigen::Vector3f> get_vertices(); std::vector<Eigen::Vector3i> get_faces(); void fft_prime(double t); @@ -59,40 +60,39 @@ private: Eigen::Vector2d get_horiz_pos(int i); std::pair<double, double> sample_complex_gaussian(); - // FOAM std::vector<float> m_saturation; - - - - - - - - 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 int num_tiles_x = 2; + const int num_tiles_z = 2; - const double Lx = 1024.0; - const double Lz = 1024.0; + const double vertex_displacement = Lx / 2; - 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 = 2.5; // how much displacement matters - const double spacing = 25.0; // spacing between grid points + const double lambda = .5; // how much displacement matters + const double spacing = 1.0; // spacing between grid points - const double A = 200; // numeric constant for the Phillips spectrum - const double V = 200; // wind speed + const double A = 10000; // numeric constant for the Phillips spectrum + const double V = 500; // 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 std::vector<Eigen::Vector2d> m_current_h; // current height fields for each K - std::vector<Eigen::Vector2d> m_displacements; // current displacement vector for each K - std::vector<Eigen::Vector2d> m_slopes; // current displacement vector for each K + // std::vector<Eigen::Vector2d> m_displacements; // current displacement vector for each K + // std::vector<Eigen::Vector2d> m_slopes; // current displacement vector for each K + std::vector<Eigen::Vector2d> m_slopes_x; + std::vector<Eigen::Vector2d> m_slopes_z; + std::vector<Eigen::Vector2d> m_displacements_x; + std::vector<Eigen::Vector2d> m_displacements_z; //std::vector<Eigen::Vector3f> m_slope_vectors; // current displacement vector for each K std::vector<Eigen::Vector3f> m_normals; // normal calculations @@ -106,9 +106,7 @@ private: int iterations = 0; - - - + std::vector<Eigen::Vector3f> m_vertices; // current displacement vector for each K const double D = 1.0; // Depth below mean water level (for dispersion relation) diff --git a/src/skybox.cpp b/src/skybox.cpp index 3f6abd7..3b894bd 100644 --- a/src/skybox.cpp +++ b/src/skybox.cpp @@ -18,7 +18,7 @@ skybox::skybox() void skybox::initializeVAO(){ sky_shape.init(m_vertices_eigen, m_faces); - std::cout << "hehee" << std::endl; + // std::cout << "hehee" << std::endl; skybox_tex = loadCubeMap(m_skyboxTextureFiles); glGenVertexArrays(1, &VAO); @@ -84,7 +84,7 @@ void skybox::draw(Shader *skybox_shader, Camera m_camera){ /// /// - std::cout << m_camera.getPosition() << std::endl; + // std::cout << m_camera.getPosition() << std::endl; // sky_shape.draw(skybox_shader, GL_TRIANGLES); @@ -132,7 +132,7 @@ GLuint skybox::loadCubeMap(std::vector<const char*> textureFiles){ GLuint textureID; glGenTextures(1, &textureID); - std::cout << "hello fssd" << std::endl; + // std::cout << "hello fssd" << std::endl; //glActiveTexture(GL_TEXTURE3); @@ -144,7 +144,7 @@ GLuint skybox::loadCubeMap(std::vector<const char*> textureFiles){ glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); - std::cout << "hello fssd" << std::endl; + // std::cout << "hello fssd" << std::endl; GLuint target = GL_TEXTURE_CUBE_MAP_POSITIVE_X; for (int i=0; i<6; i++){ @@ -158,7 +158,7 @@ GLuint skybox::loadCubeMap(std::vector<const char*> textureFiles){ stbi_image_free(data); } else { - std::cout << "Texture failed to load at path: " << textureFiles[i] << std::endl; + // std::cout << "Texture failed to load at path: " << textureFiles[i] << std::endl; stbi_image_free(data); } } diff --git a/src/skybox.h b/src/skybox.h index 94d1354..d9995ba 100644 --- a/src/skybox.h +++ b/src/skybox.h @@ -202,12 +202,12 @@ public: - {"/Users/jesswan/Desktop/cs2240/ocean-simulation/resources/images/cupertin-lake_rt.png", - "/Users/jesswan/Desktop/cs2240/ocean-simulation/resources/images/cupertin-lake_lf.png", - "/Users/jesswan/Desktop/cs2240/ocean-simulation/resources/images/cupertin-lake_up.png", - "/Users/jesswan/Desktop/cs2240/ocean-simulation/resources/images/cupertin-lake_dn.png", - "/Users/jesswan/Desktop/cs2240/ocean-simulation/resources/images/cupertin-lake_bk.png", - "/Users/jesswan/Desktop/cs2240/ocean-simulation/resources/images/cupertin-lake_ft.png", + {":resources/images/cupertin-lake_rt.png", + ":resources/images/cupertin-lake_lf.png", + ":resources/images/cupertin-lake_up.png", + ":resources/images/cupertin-lake_dn.png", + ":resources/images/cupertin-lake_bk.png", + ":resources/images/cupertin-lake_ft.png", }; float ROTATE_SPEED = .01f; // 1 degree per sec |