X-Git-Url: https://eleni.mutantstargoat.com/git/?p=hair;a=blobdiff_plain;f=src%2Fhair.cc;fp=src%2Fhair.cc;h=b2eb4a058f2731d3ffa216ec7dbc1f3d7000a6cb;hp=ef93f2c7b463ce462f257499a6e9a7fd44878d9f;hb=8efb44efc8830ffc5ae8eb387926f8b4fd00fb6e;hpb=c595e4a5c4d54f24af1357816a1baecfdeb7d25e diff --git a/src/hair.cc b/src/hair.cc index ef93f2c..b2eb4a0 100644 --- a/src/hair.cc +++ b/src/hair.cc @@ -187,7 +187,20 @@ void Hair::update(float dt) hair[i].velocity += ((-hair[i].velocity * DAMPING) + accel) * dt; Vec3 new_pos = hair[i].pos + hair[i].velocity * dt; - hair[i].pos = new_pos; //= handle_collision(new_pos); + /* collision detection with the head */ + Vec3 normal = xform.upper3x3() * hair[i].spawn_dir; + Vec3 root = xform * hair[i].spawn_pt; + Vec3 dir = new_pos - root; + + normal.normalize(); + + /* angle that will cause the hair to be rendered inside the head */ + float d = dot(dir, normal); + if(d < 0) { + new_pos += -d * normal; + } + + hair[i].pos = handle_collision(new_pos); dbg_force = force; }