From c5ff8ed6e95b7de0876dc5e97a9cb606fd84be85 Mon Sep 17 00:00:00 2001 From: jjesswan Date: Fri, 10 May 2024 03:02:42 -0400 Subject: progress parti --- src/particlesystem.cpp | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) (limited to 'src/particlesystem.cpp') 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 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 verts){ +void particlesystem::init(std::vector 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; -- cgit v1.2.3-70-g09d2