diff --git a/budget-idea/prototypes/soft-body/mass-spring-pressure/script.js b/budget-idea/prototypes/soft-body/mass-spring-pressure/script.js index 67bbe61..580b7aa 100644 --- a/budget-idea/prototypes/soft-body/mass-spring-pressure/script.js +++ b/budget-idea/prototypes/soft-body/mass-spring-pressure/script.js @@ -50,7 +50,7 @@ const params = { "GRAVITY": 0, "VECTOR_SIZE": 20, "PRESSURE_FACTOR": 300, - "RESTITUTION_COEFFICIENT" : 0.8, + "RESTITUTION_COEFFICIENT" : 0.6, "PARTICLE_RADIUS" : 16, "DISPLAY_VECTORS": false, 'DISPLAY_SPRING_VECTORS': false, @@ -138,6 +138,13 @@ blobs.push( // populate all particles array blobs.forEach(blob => all_particles.push(...blob.particles)); + +// fazer uma classe pra isso; +/*const interaction_particle = new Particle(new Vec(0,0)); +interaction_particle.r = 50; +all_particles.push(interaction_particle); +*/ + function clearCanvas() { ctx.clearRect(0, 0, W, H); } @@ -323,10 +330,23 @@ function edges_constraints() { // vertical borders - if ( (pos.y + r) > H ) { - //const g_ = new Vec(0, -1 * params.GRAVITY); - //p.add_force(Vec.mult( N_TOP, params.MASS )); - p.vel.selfMult(-1 * params.RESTITUTION_COEFFICIENT * params.VEL_DAMPING / 2); + if ( (pos.y + r) >= H ) { + const g_ = new Vec(0, -1 * params.GRAVITY); + p.add_force(Vec.mult( g_, params.MASS)); + const v_caused_by_one_step_of_acc = Math.abs(Vec.dot( p.acc, N_BOTTOM) * 1)//20 / params.TIMESTEP); + //console.log(p.vel.mod(), v_caused_by_one_step_of_acc); + if ( p.vel.mod() <= v_caused_by_one_step_of_acc ) { + + //console.log(p.vel.mod(), v_caused_by_one_step_of_acc); + + p.vel = NULL_VEC; + + } else { + + p.vel.selfMult(-1 * params.RESTITUTION_COEFFICIENT); + + } + p.pos.y = H - r; } else if ( (pos.y - r) < 0 ) { @@ -396,8 +416,9 @@ function loop(t) { accumulate_forces(); integrate(dt/params.TIMESTEP); - satisfy_constraints(); collision_system.update_collisions(all_particles); + satisfy_constraints(); + diff --git a/budget-idea/prototypes/soft-body/notes.md b/budget-idea/prototypes/soft-body/notes.md index 0344381..5809948 100644 --- a/budget-idea/prototypes/soft-body/notes.md +++ b/budget-idea/prototypes/soft-body/notes.md @@ -129,4 +129,6 @@ https://x.com/JuhaniHalkomaki/status/1624761948402319360 Escrevi pro Juhani. +Tentando evitar microvibrações. Aplicando esse conceito de "RESTING CONTACTS", do Millington (7.2.3). Calculando a velocidade da partícula devido à aplicação da aceleração em um frame, se for maior do que a velocidade atual, é por causa desse problema de resting contacts. Mas não está elegante, melhorar. +