diff options
author | jjesswan <jessica_wan@brown.edu> | 2024-05-10 03:02:42 -0400 |
---|---|---|
committer | jjesswan <jessica_wan@brown.edu> | 2024-05-10 03:02:42 -0400 |
commit | c5ff8ed6e95b7de0876dc5e97a9cb606fd84be85 (patch) | |
tree | aa8976dedbb6664ca068a7c7b479e483c357c61a /src | |
parent | c93b28613dd9c33de29152f987aeec3ca8340f8d (diff) |
progress parti
Diffstat (limited to 'src')
-rw-r--r-- | src/ocean/ocean_alt.cpp | 7 | ||||
-rw-r--r-- | src/ocean/ocean_alt.h | 10 | ||||
-rw-r--r-- | src/particlesystem.cpp | 36 | ||||
-rw-r--r-- | src/particlesystem.h | 13 |
4 files changed, 45 insertions, 21 deletions
diff --git a/src/ocean/ocean_alt.cpp b/src/ocean/ocean_alt.cpp index 1c9306b..9ead324 100644 --- a/src/ocean/ocean_alt.cpp +++ b/src/ocean/ocean_alt.cpp @@ -381,9 +381,12 @@ void ocean_alt::update_ocean() // std::cout << m_foam_constants.wavelengths[i] << std::endl; // } - if (waveheight >= height_threshold){ + if (m_foam_constants.wavelengths[i] >= height_threshold){ //std::cout << "push" << std::endl; - m_heights.push_back(v); + OceanSpray s; + s.height = v; + s.slope = norm; + m_heights.push_back(s); } diff --git a/src/ocean/ocean_alt.h b/src/ocean/ocean_alt.h index a5bcd12..bbfce9a 100644 --- a/src/ocean/ocean_alt.h +++ b/src/ocean/ocean_alt.h @@ -27,6 +27,12 @@ struct FoamConstants{ std::vector<Eigen::Vector2f> texCoords; }; +struct OceanSpray{ + Eigen::Vector3f height; + Eigen::Vector3f slope; + +}; + class ocean_alt { public: @@ -43,7 +49,7 @@ public: } std::vector<Eigen::Vector3f> m_vertices; // current displacement vector for each K - std::vector<Eigen::Vector3f> m_heights; // stores height above threshold + std::vector<OceanSpray> m_heights; // stores height above threshold @@ -86,7 +92,7 @@ private: const double spacing = 1.0; // spacing between grid points const double A = 100; // numeric constant for the Phillips spectrum - const double V = 50; // wind speed + const double V = 100; // 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 diff --git a/src/particlesystem.cpp b/src/particlesystem.cpp index 104b449..b645929 100644 --- a/src/particlesystem.cpp +++ b/src/particlesystem.cpp @@ -32,23 +32,29 @@ float getRandomInRange(float max, float min){ } +float getRandomY(){ + return getRandomInRange(.001,.2); +} Eigen::Vector3f particlesystem::getRandomInitialVel(){ std::pair<float, float> r = sample_complex_gaussian(); - return factor*Eigen::Vector3f(r.first, getRandomInRange(1.f, 10.f), r.second); + return factor*Eigen::Vector3f(r.first, getRandomY(), r.second); } -void particlesystem::init(std::vector<Eigen::Vector3f> verts){ +void particlesystem::init(std::vector<OceanSpray> verts){ // make sure to set m_verts setVerts(verts); m_particles.reserve(4000); - for (Eigen::Vector3f v : m_verts){ + for (auto v : m_verts){ Particle p; - p.pos = Eigen::Vector3f(v); - p.vel = getRandomInitialVel(); + p.pos = Eigen::Vector3f(v.height); + p.vel = v.slope*factor; + //p.vel = getRandomInitialVel(); + p.vel = getRandomInitialVel().asDiagonal() * v.slope; + p.vel[1] = 0.1; m_particles.push_back(p); @@ -85,15 +91,19 @@ void particlesystem::update(double deltaTime){ float dt = deltaTime; // update all particles values for (Particle &p : m_particles){ - p.life -= deltaTime * getRandomInRange(.01f, .5f); + p.life -= deltaTime * getRandomInRange(.1f, .5f); // if particle is still alive, update pos if (p.life >= 0.f){ - p.vel += gravity*dt; + float r = getRandomInRange(.5, 1.f); + p.vel += gravity*dt*r; p.pos += p.vel * dt * 10.f; - +// p.vel[1] -= (p.vel.dot(p.vel) / 2 + gravity[0]) * dt; +// p.pos += p.vel * dt * 10.f; } + if (p.pos[1] < 0.f) p.life = 0.f; + } } @@ -124,10 +134,14 @@ int particlesystem::getUnusedParticleIndex(){ return -1; } -void particlesystem::respawn_particle(Particle &p, Eigen::Vector3f new_pos){ +void particlesystem::respawn_particle(Particle &p, OceanSpray new_pos){ + + p.pos = Eigen::Vector3f(new_pos.height); + p.vel = new_pos.slope*factor; + //p.vel = getRandomInitialVel(); + p.vel = getRandomInitialVel().asDiagonal() * new_pos.slope; + p.vel[1] = .01; - p.pos = new_pos; - p.vel = getRandomInitialVel(); // TODO: change to more accurate vel // reset life p.life = 1.f; diff --git a/src/particlesystem.h b/src/particlesystem.h index 9744153..e2874dd 100644 --- a/src/particlesystem.h +++ b/src/particlesystem.h @@ -2,6 +2,7 @@ #ifndef PARTICLESYSTEM_H #define PARTICLESYSTEM_H +#include "ocean/ocean_alt.h" #include <iostream> #define EIGEN_DISABLE_UNALIGNED_ARRAY_ASSERT #define EIGEN_DONT_VECTORIZE @@ -31,9 +32,9 @@ public: void draw(Shader *skybox_shader, Camera m_camera); void draw(Shader *shader, Camera m_camera, std::vector<Eigen::Vector3f> verts, Eigen::Matrix4f model); - void init(std::vector<Eigen::Vector3f> verts); + void init(std::vector<OceanSpray> verts); - void setVerts(std::vector<Eigen::Vector3f> verts){ + void setVerts(std::vector<OceanSpray> verts){ std::cout << "VERTS SIZE:" << verts.size() << std::endl; m_verts = verts; @@ -46,18 +47,18 @@ private: int m_new_amount = 100; // new particles per frame int lastUsedIndex = 0; Eigen::Vector3f gravity = Eigen::Vector3f(0,-9.81f,0); - float factor = 10.f; // velocity multiplier + float factor = 40.f; // velocity multiplier - void respawn_particle(Particle &p, Eigen::Vector3f new_pos); + void respawn_particle(Particle &p, OceanSpray new_pos); int getUnusedParticleIndex(); Eigen::Vector3f getRandomInitialVel(); - float d = 5.f; + float d = 2.f; std::vector<float> m_vertices = { -d, d, d,d, @@ -76,7 +77,7 @@ private: std::vector<Particle> m_particles; - std::vector<Eigen::Vector3f> m_verts; + std::vector<OceanSpray> m_verts; }; |