summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsotech117 <michael_foiani@brown.edu>2024-05-10 01:48:02 -0400
committersotech117 <michael_foiani@brown.edu>2024-05-10 01:48:02 -0400
commit6aab43ffd2c29a66f71b0684974abd5b2685341c (patch)
treeec1a0df0b1fdd056e70297d2078406553140125b /src
parent70ba0f4c20f8dd89f7f922f2177150258a61c546 (diff)
better sea foam
Diffstat (limited to 'src')
-rw-r--r--src/arap.cpp4
-rw-r--r--src/graphics/shape.cpp2
-rw-r--r--src/ocean/ocean_alt.cpp121
3 files changed, 64 insertions, 63 deletions
diff --git a/src/arap.cpp b/src/arap.cpp
index 8d81337..2d952ae 100644
--- a/src/arap.cpp
+++ b/src/arap.cpp
@@ -85,7 +85,7 @@ void ARAP::update(double seconds)
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());
+// m_shape.setVertices(m_ocean.get_vertices());
// auto tmp = m_ocean.get_vertices();
// print the min and max of the vertices
@@ -94,7 +94,7 @@ void ARAP::update(double seconds)
// for (int i = 0; i < tmp.size(); i++) {
// min = min.cwiseMin(tmp[i]);
// max = max.cwiseMax(tmp[i]);
-// }
+// }w
// std::cout << "min: " << min << std::endl;
//std::cout << "max: " << max << std::endl;
diff --git a/src/graphics/shape.cpp b/src/graphics/shape.cpp
index 1baa233..7073a7f 100644
--- a/src/graphics/shape.cpp
+++ b/src/graphics/shape.cpp
@@ -336,7 +336,7 @@ void Shape::updateMesh(const std::vector<Eigen::Vector3i> &faces,
Vector3f n = getNormal(face);
for (auto& v: {face[0], face[1], face[2]}) {
- normals.push_back(Eigen::Vector3f(1,1,1));
+ normals.push_back(n);
verts.push_back(vertices[v]);
if (m_anchors.find(v) == m_anchors.end()) {
diff --git a/src/ocean/ocean_alt.cpp b/src/ocean/ocean_alt.cpp
index dcc3e42..7523c94 100644
--- a/src/ocean/ocean_alt.cpp
+++ b/src/ocean/ocean_alt.cpp
@@ -316,17 +316,6 @@ 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);
@@ -335,7 +324,18 @@ void ocean_alt::update_ocean()
Eigen::Vector2d amplitude = m_current_h[i];
float height = amplitude[0];
- // Eigen::Vector2d slope = m_slopes[i] * .3f;
+ if (iterations++ > 1)
+ {
+ if (height < min) min = height;
+ if (height > max)
+ {
+ max = height;
+// std::cout << "changed!! max: " << max << std::endl;
+ }
+ }
+
+
+ // 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);
@@ -366,8 +366,8 @@ void ocean_alt::update_ocean()
// 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
+ float h_0 = 0; // min*.2f;
+ float h_max = max*.35f; // the smaller the constant, the more foam there is
m_foam_constants.wavelengths[i] = (height - h_0 ) / (h_max - h_0);
// if (i < 5){
@@ -379,6 +379,7 @@ void ocean_alt::update_ocean()
}
+
// populate foam constants
m_foam_constants.positions = vertices;
}
@@ -425,54 +426,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 < 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);
-// faces.emplace_back(i1, i2, i3);
-// faces.emplace_back(i3, i2, i4);
-// }
-// }
-// return faces;
+// 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;
}
Eigen::Vector2d muliply_complex(Eigen::Vector2d a, Eigen::Vector2d b)