diff options
author | sotech117 <michael_foiani@brown.edu> | 2024-05-10 06:41:07 -0400 |
---|---|---|
committer | sotech117 <michael_foiani@brown.edu> | 2024-05-10 06:42:45 -0400 |
commit | 949907125f6f05937f3357c5ddc85a2e7380cf91 (patch) | |
tree | f65548a276314f540265ace695dd74f8ab050a3a /src | |
parent | bbcfd7f0ff4415e26bf05e0b8660f94bfca94103 (diff) |
tile fix and lighting fix
Diffstat (limited to 'src')
-rw-r--r-- | src/arap.cpp | 4 | ||||
-rw-r--r-- | src/graphics/shape.cpp | 3 | ||||
-rw-r--r-- | src/ocean/ocean_alt.cpp | 130 | ||||
-rw-r--r-- | src/ocean/ocean_alt.h | 18 |
4 files changed, 90 insertions, 65 deletions
diff --git a/src/arap.cpp b/src/arap.cpp index 2d952ae..d1af7b5 100644 --- a/src/arap.cpp +++ b/src/arap.cpp @@ -99,7 +99,9 @@ void ARAP::update(double seconds) //std::cout << "max: " << max << std::endl; FoamConstants foam = m_ocean.getFoamConstants(); - m_foam_shape.setFoamInputs(m_ocean.m_vertices, foam.wavelengths, foam.k_vectors, foam.texCoords); + std::vector<float> tiled_wavelengths = m_ocean.get_tiled_wavelengths(); + std::vector<Eigen::Vector2f> tiled_k_vectors = m_ocean.get_tiled_k_vectors(); + m_foam_shape.setFoamInputs(m_ocean.get_vertices(), tiled_wavelengths, tiled_k_vectors, foam.texCoords); m_time += m_timestep; diff --git a/src/graphics/shape.cpp b/src/graphics/shape.cpp index e5849fb..874a9e6 100644 --- a/src/graphics/shape.cpp +++ b/src/graphics/shape.cpp @@ -359,10 +359,7 @@ void Shape::updateMeshFoam(const std::vector<Eigen::Vector3i> &faces, verts.reserve(faces.size() * 3); normals.reserve(faces.size() * 3); colors.reserve(faces.size() * 3); - - for (const Eigen::Vector3i& face : faces) { - for (auto& v: {face[0], face[1], face[2]}) { normals.push_back(Eigen::Vector3f(wavelengths[v],0,0)); verts.push_back(vertices[v]); diff --git a/src/ocean/ocean_alt.cpp b/src/ocean/ocean_alt.cpp index 751fca5..503cd4c 100644 --- a/src/ocean/ocean_alt.cpp +++ b/src/ocean/ocean_alt.cpp @@ -399,6 +399,36 @@ void ocean_alt::update_ocean() m_foam_constants.positions = vertices; } +std::vector<float> ocean_alt::get_tiled_wavelengths(){ + std::vector<float> wavelengths = std::vector<float>(); + 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++) + { + wavelengths.push_back(m_foam_constants.wavelengths[k]); + } + } + } + return wavelengths; +} + +std::vector<Eigen::Vector2f> ocean_alt::get_tiled_k_vectors(){ + std::vector<Eigen::Vector2f> k_vectors = std::vector<Eigen::Vector2f>(); + 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++) + { + k_vectors.push_back(m_foam_constants.k_vectors[k]); + } + } + } + return k_vectors; +} + 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>(); @@ -409,8 +439,10 @@ std::vector<Eigen::Vector3f> ocean_alt::get_vertices(){ 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)); + Eigen::Vector3f vertex = m_vertices[k] + Eigen::Vector3f(-i*(c), 0.0, (j)*(c)); vertices.push_back(vertex); + +// std::cout << "vertex: " << vertex << std::endl; } } } @@ -432,8 +464,6 @@ std::vector<Eigen::Vector3f> ocean_alt::getNormals(){ } } } - - return normals; } @@ -441,54 +471,54 @@ 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 < 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 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 < 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 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); + } + } + } + } - 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; + 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; } Eigen::Vector2d muliply_complex(Eigen::Vector2d a, Eigen::Vector2d b) @@ -605,7 +635,7 @@ std::vector<Eigen::Vector2d> ocean_alt::fast_fft } // divide by N*N and add the signs based on the indices - double sign[] = {-1.0, 1.0}; + double sign[] = {1.0, -1.0}; for (int i = 0; i < N; i++) { h[i] /= N; diff --git a/src/ocean/ocean_alt.h b/src/ocean/ocean_alt.h index 7e293f9..6076ab2 100644 --- a/src/ocean/ocean_alt.h +++ b/src/ocean/ocean_alt.h @@ -53,12 +53,8 @@ public: std::vector<OceanSpray> m_heights; // stores height above threshold - - - - - - + std::vector<Eigen::Vector2f> get_tiled_k_vectors(); + std::vector<float> get_tiled_wavelengths(); private: Eigen::Vector2i index_1d_to_2d(int i); @@ -72,7 +68,7 @@ private: Eigen::Vector2d get_horiz_pos(int i); std::pair<double, double> sample_complex_gaussian(); - // FOAM + // 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 @@ -83,17 +79,17 @@ private: const int num_rows = 256; const int num_cols = 256; - const int num_tiles_x = 1; - const int num_tiles_z = 1; + const int num_tiles_x = 2; + const int num_tiles_z = 2; const double vertex_displacement = Lx / 2; const int N = num_rows*num_cols; // total number of grid points - const double lambda = .5; // how much displacement matters + const double lambda = .75; // how much displacement matters const double spacing = 1.0; // spacing between grid points const double A = 10000; // numeric constant for the Phillips spectrum - const double V = 100; // wind speed + const double V = 700; // 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 |