X-Git-Url: http://git.mutantstargoat.com?p=hair;a=blobdiff_plain;f=src%2Fhair.cc;h=de31ed8cdc62b433a2ec46ed20b5896e4b0b09d5;hp=b99d133994ac0028d5fde2b6f13bf7db68f4634e;hb=a8a7d557cf22c2bf16eb333d33a6c7c68f532482;hpb=a65a977df6fa8fee831c91cdc754d62e023b6630 diff --git a/src/hair.cc b/src/hair.cc index b99d133..de31ed8 100644 --- a/src/hair.cc +++ b/src/hair.cc @@ -147,6 +147,7 @@ void Hair::draw() const glVertex3f(p.x, p.y, p.z); Vec3 dir = normalize(hair[i].pos - p) * hair_length; Vec3 end = p + dir; + glColor3f(1, 1, 0); glVertex3f(end.x, end.y, end.z); /* glColor3f(1, 1, 0); @@ -187,6 +188,19 @@ void Hair::update(float dt) hair[i].velocity += ((-hair[i].velocity * DAMPING) + accel) * dt; Vec3 new_pos = hair[i].pos + hair[i].velocity * dt; + /* 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;