From d2f792c6fee2a6e78dcf2fff77f43ef036c58877 Mon Sep 17 00:00:00 2001 From: jjesswan Date: Fri, 10 May 2024 01:49:32 -0400 Subject: saving parts --- src/arap.h | 4 +- src/glwidget.cpp | 11 +++ src/glwidget.h | 4 ++ src/ocean/ocean_alt.cpp | 18 ++--- src/ocean/ocean_alt.h | 12 ++-- src/particlesystem.cpp | 176 ++++++++++++++++++++++++++++++++++++++++++++++++ src/particlesystem.h | 83 +++++++++++++++++++++++ 7 files changed, 295 insertions(+), 13 deletions(-) create mode 100644 src/particlesystem.cpp create mode 100644 src/particlesystem.h (limited to 'src') diff --git a/src/arap.h b/src/arap.h index 39b2076..f9dd81e 100644 --- a/src/arap.h +++ b/src/arap.h @@ -32,6 +32,9 @@ public: void move(int vertex, Eigen::Vector3f pos); void update(double seconds); + ocean_alt m_ocean; + + // ================== Students, If You Choose To Modify The Code Below, It's On You @@ -96,7 +99,6 @@ public: int m_num_iterations; const char * m_mesh_path; - ocean_alt m_ocean; double m_time = 0.00; double m_timestep = 0.3; diff --git a/src/glwidget.cpp b/src/glwidget.cpp index 57b4468..8f3c0c1 100755 --- a/src/glwidget.cpp +++ b/src/glwidget.cpp @@ -97,6 +97,8 @@ void GLWidget::initializeGL() m_colorShader = new Shader(":resources/shaders/color.vert", ":resources/shaders/color.frag"); m_foamShader = new Shader(":resources/shaders/foam.vert", ":resources/shaders/foam.frag"); m_skyboxShader = new Shader(":resources/shaders/skybox.vert", ":resources/shaders/skybox.frag"); + m_particleShader = new Shader(":resources/shaders/particles.vert", ":resources/shaders/particles.frag"); + m_halftone_tex = loadTextureFromFile(":resources/images/halftone.png").textureID; @@ -198,6 +200,10 @@ void GLWidget::initializeGL() m_deltaTimeProvider.start(); m_intervalTimer.start(1000 / 60); + // OCEAN SPRAY + m_arap.update(0); // important to get initial heights + m_particles.init(m_arap.m_ocean.m_heights); + } void GLWidget::paintCaustics() { @@ -458,6 +464,8 @@ void GLWidget::paintGL() m_skybox.draw(m_skyboxShader, m_camera); + m_particles.draw(m_particleShader, m_camera); + @@ -684,7 +692,10 @@ void GLWidget::tick() float deltaSeconds = m_deltaTimeProvider.restart() / 1000.f; m_arap.update(deltaSeconds); // rotate skybox + m_particles.setVerts(m_arap.m_ocean.m_heights); m_skybox.update(deltaSeconds); + m_particles.update(deltaSeconds); + // Move camera auto look = m_camera.getLook(); diff --git a/src/glwidget.h b/src/glwidget.h index 60cca66..50d6347 100755 --- a/src/glwidget.h +++ b/src/glwidget.h @@ -1,6 +1,8 @@ #pragma once #include "skybox.h" +#include "particlesystem.h" + #include @@ -70,6 +72,7 @@ private: Shader *m_colorShader; Shader *m_foamShader; Shader *m_skyboxShader; + Shader *m_particleShader; @@ -122,4 +125,5 @@ private: int m_lastSelectedVertex = -1; skybox m_skybox; + particlesystem m_particles; }; diff --git a/src/ocean/ocean_alt.cpp b/src/ocean/ocean_alt.cpp index dcc3e42..58e76f8 100644 --- a/src/ocean/ocean_alt.cpp +++ b/src/ocean/ocean_alt.cpp @@ -330,6 +330,7 @@ void ocean_alt::update_ocean() // reset normals & vertices arrays for the single tile m_vertices = std::vector(N); m_normals = std::vector(N); + m_heights.clear(); 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]; @@ -357,9 +358,10 @@ void ocean_alt::update_ocean() 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 + Eigen::Vector3f v = Eigen::Vector3f(horiz_pos[0] + disp[0], height, horiz_pos[1] + disp[1]); // for final vertex position, use the real number component of amplitude vector - m_vertices[i] = {horiz_pos[0] + disp[0], height, horiz_pos[1] + disp[1]}; + m_vertices[i] = v; 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); @@ -367,14 +369,14 @@ 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 - m_foam_constants.wavelengths[i] = (height - h_0 ) / (h_max - h_0); - -// if (i < 5){ -// std::cout << h_0 << ", " << h_max << std::endl; -// std::cout << m_foam_constants.wavelengths[i] << std::endl; -// } + float h_max = max*.001f; // the smaller the constant, the more foam there is + float waveheight = (height - h_0 ) / (h_max - h_0); + m_foam_constants.wavelengths[i] = waveheight; + if (waveheight >= height_threshold){ + //std::cout << "push" << std::endl; + m_heights.push_back(v); + } } diff --git a/src/ocean/ocean_alt.h b/src/ocean/ocean_alt.h index 9c5e4e2..a5bcd12 100644 --- a/src/ocean/ocean_alt.h +++ b/src/ocean/ocean_alt.h @@ -43,6 +43,8 @@ public: } std::vector m_vertices; // current displacement vector for each K + std::vector m_heights; // stores height above threshold + @@ -71,8 +73,8 @@ private: const double Lx = 512.0; const double Lz = 512.0; - const int num_rows = 256; - const int num_cols = 256; + const int num_rows = 128; + const int num_cols = 128; const int num_tiles_x = 1; const int num_tiles_z = 1; @@ -83,8 +85,8 @@ private: const double lambda = .5; // 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 = 500; // wind speed + const double A = 100; // numeric constant for the Phillips spectrum + const double V = 50; // 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 @@ -102,6 +104,8 @@ private: // FOR FOAM: FoamConstants m_foam_constants; + float height_threshold = 2.f; + float max = 0; diff --git a/src/particlesystem.cpp b/src/particlesystem.cpp new file mode 100644 index 0000000..104b449 --- /dev/null +++ b/src/particlesystem.cpp @@ -0,0 +1,176 @@ +#include "particlesystem.h" +#include + +particlesystem::particlesystem() +{ + +} + +std::pair sample_complex_gaussian(){ + double uniform_1 = (double)rand() / (RAND_MAX); + double uniform_2 = (double)rand() / (RAND_MAX); + + // set a lower bound on zero to avoid undefined log(0) + if (uniform_1 == 0) + { + uniform_1 = 1e-10; + } + if (uniform_2 == 0) + { + uniform_2 = 1e-10; + } + + // real and imaginary parts of the complex number + double real = sqrt(-2*log(uniform_1)) * cos(2*M_PI*uniform_2); + double imag = sqrt(-2*log(uniform_1)) * sin(2*M_PI*uniform_2); + + return std::make_pair(real, imag); +} + +float getRandomInRange(float max, float min){ + return min + static_cast (rand()) /( static_cast (RAND_MAX/(max-min))); + +} + +Eigen::Vector3f particlesystem::getRandomInitialVel(){ + + + std::pair r = sample_complex_gaussian(); + return factor*Eigen::Vector3f(r.first, getRandomInRange(1.f, 10.f), r.second); +} + +void particlesystem::init(std::vector verts){ + // make sure to set m_verts + setVerts(verts); + + m_particles.reserve(4000); + + for (Eigen::Vector3f v : m_verts){ + Particle p; + p.pos = Eigen::Vector3f(v); + p.vel = getRandomInitialVel(); + + + m_particles.push_back(p); + } + + + glGenVertexArrays(1, &VAO); + glGenBuffers(1, &VBO); + glBindVertexArray(VAO); + + glBindBuffer(GL_ARRAY_BUFFER, VBO); + glBufferData(GL_ARRAY_BUFFER, m_vertices.size()*sizeof(float), m_vertices.data(), GL_STATIC_DRAW); + + glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2*sizeof(float), (void*)0); + + // unbind + glEnableVertexAttribArray(0); + glBindBuffer(GL_ARRAY_BUFFER, 0); +} + + +void particlesystem::update(double deltaTime){ + + // add new particles + for (int i=0; i= m_particles.size() - 1 || particle_index >= m_verts.size() - 1) continue; + respawn_particle(m_particles[particle_index], m_verts[particle_index]); + + } + + + float dt = deltaTime; + // update all particles values + for (Particle &p : m_particles){ + p.life -= deltaTime * getRandomInRange(.01f, .5f); + + // if particle is still alive, update pos + if (p.life >= 0.f){ + p.vel += gravity*dt; + p.pos += p.vel * dt * 10.f; + + } + + } +} + + + +// finds the first instance of a particle that is dead, and returns its index so it can be replaced +int particlesystem::getUnusedParticleIndex(){ + + // search from last used index + for (int i=lastUsedIndex; ibind(); + + glBlendFunc(GL_SRC_ALPHA, GL_ONE); + + + // activate texture +// glActiveTexture(GL_TEXTURE10); +// glBindTexture(GL_TEXTURE_CUBE_MAP, skybox_tex); +// glUniform1i(glGetUniformLocation(shader->id(), "cubeMap"), 9); // bind texture at slot 9 + + + // manually set view and projection, for non-translating view + Eigen::Matrix4f projection = m_camera.getProjection(); + Eigen::Matrix4f view = m_camera.getView(); + // view.col(3) = Eigen::Vector4f(0, 0, 0, 0); + + glUniformMatrix4fv(glGetUniformLocation(shader->id(), "view"), 1, GL_FALSE, view.data()); + glUniformMatrix4fv(glGetUniformLocation(shader->id(), "projection"), 1, GL_FALSE, projection.data()); + // shader->setUniform("model", model); + + int i = 0; + for (Particle p : m_particles){ + if (p.life >= 0.f){ + shader->setUniform("offset", p.pos); + shader->setUniform("alpha", p.life); + + glBindVertexArray(VAO); + glDrawArrays(GL_TRIANGLES, 0, m_vertices.size()); + glBindVertexArray(0); + i++; + } + } + shader->unbind(); + + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + +} diff --git a/src/particlesystem.h b/src/particlesystem.h new file mode 100644 index 0000000..9744153 --- /dev/null +++ b/src/particlesystem.h @@ -0,0 +1,83 @@ + +#ifndef PARTICLESYSTEM_H +#define PARTICLESYSTEM_H + +#include +#define EIGEN_DISABLE_UNALIGNED_ARRAY_ASSERT +#define EIGEN_DONT_VECTORIZE +#include "graphics/shader.h" +#include "graphics/camera.h" + +#include +#include +#include +#include + +struct Particle{ + Eigen::Vector3f pos = Eigen::Vector3f(0,0,0); + Eigen::Vector3f vel = Eigen::Vector3f(0,2000,0); + + Eigen::Vector4f color = Eigen::Vector4f(1,1,1,1); + float life = 1.f; + +}; + +class particlesystem +{ +public: + particlesystem(); + + void update(double deltaTime); + void draw(Shader *skybox_shader, Camera m_camera); + void draw(Shader *shader, Camera m_camera, std::vector verts, Eigen::Matrix4f model); + + void init(std::vector verts); + + void setVerts(std::vector verts){ + std::cout << "VERTS SIZE:" << verts.size() << std::endl; + m_verts = verts; + + } + + + +private: + int m_amount = 500; + 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 + + + + void respawn_particle(Particle &p, Eigen::Vector3f new_pos); + int getUnusedParticleIndex(); + Eigen::Vector3f getRandomInitialVel(); + + + + + float d = 5.f; + std::vector m_vertices = { + -d, d, + d,d, + -d, -d, + d, d, + d, -d, + -d, -d + }; + + GLuint VAO, VBO; // holds quad shape + + + + + + + std::vector m_particles; + + std::vector m_verts; + +}; + +#endif // PARTICLESYSTEM_H -- cgit v1.2.3-70-g09d2 From c5ff8ed6e95b7de0876dc5e97a9cb606fd84be85 Mon Sep 17 00:00:00 2001 From: jjesswan Date: Fri, 10 May 2024 03:02:42 -0400 Subject: progress parti --- src/ocean/ocean_alt.cpp | 7 +++++-- src/ocean/ocean_alt.h | 10 ++++++++-- src/particlesystem.cpp | 36 +++++++++++++++++++++++++----------- src/particlesystem.h | 13 +++++++------ 4 files changed, 45 insertions(+), 21 deletions(-) (limited to 'src') 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 texCoords; }; +struct OceanSpray{ + Eigen::Vector3f height; + Eigen::Vector3f slope; + +}; + class ocean_alt { public: @@ -43,7 +49,7 @@ public: } std::vector m_vertices; // current displacement vector for each K - std::vector m_heights; // stores height above threshold + std::vector 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 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; 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 #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 verts, Eigen::Matrix4f model); - void init(std::vector verts); + void init(std::vector verts); - void setVerts(std::vector verts){ + void setVerts(std::vector 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 m_vertices = { -d, d, d,d, @@ -76,7 +77,7 @@ private: std::vector m_particles; - std::vector m_verts; + std::vector m_verts; }; -- cgit v1.2.3-70-g09d2 From 7c0cd109b098b24279fb17b9a05ab846405d169b Mon Sep 17 00:00:00 2001 From: jjesswan Date: Fri, 10 May 2024 03:41:20 -0400 Subject: particlesss --- resources/shaders/particles.frag | 2 +- resources/shaders/particles.vert | 4 +++- src/ocean/ocean_alt.cpp | 2 ++ src/ocean/ocean_alt.h | 7 ++++--- src/particlesystem.cpp | 29 +++++++++++++++++++---------- src/particlesystem.h | 2 +- 6 files changed, 30 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/resources/shaders/particles.frag b/resources/shaders/particles.frag index 73a4eb4..99373e7 100644 --- a/resources/shaders/particles.frag +++ b/resources/shaders/particles.frag @@ -11,5 +11,5 @@ uniform float alpha; void main() { // color = (texture(sprite, TexCoords) * ParticleColor); - fragColor = vec4(0,1,0,alpha); + fragColor = vec4(1,1,1,alpha); } diff --git a/resources/shaders/particles.vert b/resources/shaders/particles.vert index 0905514..7b49a46 100644 --- a/resources/shaders/particles.vert +++ b/resources/shaders/particles.vert @@ -7,6 +7,8 @@ out vec4 ParticleColor; uniform mat4 view, projection, model; uniform vec3 offset; uniform vec4 color; +uniform float alpha; + void main() { @@ -14,6 +16,6 @@ void main() //TexCoords = vertex.zw; ParticleColor = color; // gl_Position = projection *view* vec4((pos * scale) + vec2(offset), 0.0, 1.0); - gl_Position = (vec4(pos.x, pos.y, 0, 1) + projection*view*vec4(vec3(offset), 1))*scale; + gl_Position = (vec4(pos.x*alpha, pos.y*alpha, 0, 1) + projection*view*vec4(vec3(offset), 1))*scale; } diff --git a/src/ocean/ocean_alt.cpp b/src/ocean/ocean_alt.cpp index 9ead324..751fca5 100644 --- a/src/ocean/ocean_alt.cpp +++ b/src/ocean/ocean_alt.cpp @@ -386,6 +386,8 @@ void ocean_alt::update_ocean() OceanSpray s; s.height = v; s.slope = norm; + s.slope_vector = Eigen::Vector2f(m_slopes_x[i][0], m_slopes_z[i][0]); + //std::cout << s.slope_vector << std::endl; m_heights.push_back(s); } diff --git a/src/ocean/ocean_alt.h b/src/ocean/ocean_alt.h index bbfce9a..7e293f9 100644 --- a/src/ocean/ocean_alt.h +++ b/src/ocean/ocean_alt.h @@ -30,6 +30,7 @@ struct FoamConstants{ struct OceanSpray{ Eigen::Vector3f height; Eigen::Vector3f slope; + Eigen::Vector2f slope_vector; }; @@ -79,8 +80,8 @@ private: const double Lx = 512.0; const double Lz = 512.0; - const int num_rows = 128; - const int num_cols = 128; + const int num_rows = 256; + const int num_cols = 256; const int num_tiles_x = 1; const int num_tiles_z = 1; @@ -91,7 +92,7 @@ private: const double lambda = .5; // how much displacement matters const double spacing = 1.0; // spacing between grid points - const double A = 100; // numeric constant for the Phillips spectrum + const double A = 10000; // numeric constant for the Phillips spectrum const double V = 100; // wind speed const double gravity = 9.81; const double L = V*V/gravity; diff --git a/src/particlesystem.cpp b/src/particlesystem.cpp index b645929..566667f 100644 --- a/src/particlesystem.cpp +++ b/src/particlesystem.cpp @@ -35,6 +35,8 @@ float getRandomInRange(float max, float min){ float getRandomY(){ return getRandomInRange(.001,.2); } + + Eigen::Vector3f particlesystem::getRandomInitialVel(){ @@ -42,6 +44,16 @@ Eigen::Vector3f particlesystem::getRandomInitialVel(){ return factor*Eigen::Vector3f(r.first, getRandomY(), r.second); } +Eigen::Vector3f getInitVel(OceanSpray s){ + float x = getRandomInRange(0,1); + float y = getRandomInRange(0.1, .9); + Eigen::Vector3f v = Eigen::Vector3f(s.slope_vector[0], y, s.slope_vector[1]) + Eigen::Vector3f(x,0,0); + return v*10.f; + //p.vel[1] = 0.1; + + +} + void particlesystem::init(std::vector verts){ // make sure to set m_verts setVerts(verts); @@ -51,10 +63,10 @@ void particlesystem::init(std::vector verts){ for (auto v : m_verts){ Particle p; p.pos = Eigen::Vector3f(v.height); - p.vel = v.slope*factor; + p.life = getRandomInRange(.1,1); + // p.vel = v.slope*factor; //p.vel = getRandomInitialVel(); - p.vel = getRandomInitialVel().asDiagonal() * v.slope; - p.vel[1] = 0.1; + p.vel = getInitVel(v); m_particles.push_back(p); @@ -95,7 +107,7 @@ void particlesystem::update(double deltaTime){ // if particle is still alive, update pos if (p.life >= 0.f){ - float r = getRandomInRange(.5, 1.f); + float r = getRandomInRange(.5, 1.6f); p.vel += gravity*dt*r; p.pos += p.vel * dt * 10.f; // p.vel[1] -= (p.vel.dot(p.vel) / 2 + gravity[0]) * dt; @@ -134,13 +146,10 @@ int particlesystem::getUnusedParticleIndex(){ return -1; } -void particlesystem::respawn_particle(Particle &p, OceanSpray new_pos){ +void particlesystem::respawn_particle(Particle &p, OceanSpray s){ - 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 = Eigen::Vector3f(s.height); + p.vel = getInitVel(s); // reset life diff --git a/src/particlesystem.h b/src/particlesystem.h index e2874dd..d3b0b8f 100644 --- a/src/particlesystem.h +++ b/src/particlesystem.h @@ -35,7 +35,7 @@ public: void init(std::vector verts); void setVerts(std::vector verts){ - std::cout << "VERTS SIZE:" << verts.size() << std::endl; + //std::cout << "VERTS SIZE:" << verts.size() << std::endl; m_verts = verts; } -- cgit v1.2.3-70-g09d2