X-Git-Url: http://git.mutantstargoat.com?p=hair;a=blobdiff_plain;f=src%2Fhair.cc;h=b99d133994ac0028d5fde2b6f13bf7db68f4634e;hp=c86044b56494737809c461e475635c47e3fb7239;hb=a65a977df6fa8fee831c91cdc754d62e023b6630;hpb=b07896ffc92093a3e8adb4953d22927a5874e43d diff --git a/src/hair.cc b/src/hair.cc index c86044b..b99d133 100644 --- a/src/hair.cc +++ b/src/hair.cc @@ -185,8 +185,30 @@ void Hair::update(float dt) Vec3 accel = force; /* mass 1 */ hair[i].velocity += ((-hair[i].velocity * DAMPING) + accel) * dt; - hair[i].pos += hair[i].velocity * dt; + Vec3 new_pos = hair[i].pos + hair[i].velocity * dt; + + hair[i].pos = handle_collision(new_pos); dbg_force = force; } } + +void Hair::add_collider(CollSphere *cobj) { + colliders.push_back(cobj); +} + +Vec3 Hair::handle_collision(const Vec3 &v) const +{ + /* if we transform the center and the radius of the collider sphere + * we might end up with a spheroid, so better just multiply the + * position with the inverse transform before check for collisions :*/ + + Vec3 new_v = inverse(xform) * v; + + for(size_t i=0; icontains(new_v)) { + new_v = colliders[i]->project_surf(new_v); + } + } + return xform * new_v; +}