X-Git-Url: http://git.mutantstargoat.com?p=hair;a=blobdiff_plain;f=src%2Fhair.cc;h=b99d133994ac0028d5fde2b6f13bf7db68f4634e;hp=0fc026d7b6d5a28f90e3cb6078b0deb1441b58c5;hb=a65a977df6fa8fee831c91cdc754d62e023b6630;hpb=6a6b355866e9c227415ed028966362d3760353de diff --git a/src/hair.cc b/src/hair.cc index 0fc026d..b99d133 100644 --- a/src/hair.cc +++ b/src/hair.cc @@ -127,26 +127,6 @@ bool Hair::init(const Mesh *m, int max_num_spawns, float thresh) for(size_t i=0; i 0.99)) { - vi = Vec3(0, -1, 0); - } - Vec3 vj = normalize(cross(vk, vi)); - vi = cross(vj, vk); - - /* identity when the hair points to the z axis */ - Mat4 basis = Mat4(vi, vj, vk); - - for(int j=0; j<3; j++) { - float angle = (float)j / 3.0 * 2 * M_PI; - /* dir of each anchor relative to hair root */ - Vec3 dir = Vec3(cos(angle), sin(angle), 0); - dir = basis * dir; - hair[i].anchor_dirs[j] = hair[i].pos + dir - hair[i].spawn_pt; - } } return true; } @@ -171,8 +151,8 @@ void Hair::draw() const /* glColor3f(1, 1, 0); glVertex3f(hair[i].pos.x, hair[i].pos.y, hair[i].pos.z); - Vec3 end = hair[i].pos + dbg_force * 2.0; - glVertex3f(end.x, end.y, end.z); + Vec3 fend = hair[i].pos + dbg_force * 2.0; + glVertex3f(fend.x, fend.y, fend.z); */ } glEnd(); @@ -205,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; +}