X-Git-Url: http://git.mutantstargoat.com?p=hair;a=blobdiff_plain;f=src%2Fhair.cc;h=0fc026d7b6d5a28f90e3cb6078b0deb1441b58c5;hp=2431f509cf7669331698b5327741f2035d4f6007;hb=6a6b355866e9c227415ed028966362d3760353de;hpb=32d7e487f9b74900081f23bb501b7f2c094160af diff --git a/src/hair.cc b/src/hair.cc index 2431f50..0fc026d 100644 --- a/src/hair.cc +++ b/src/hair.cc @@ -8,6 +8,11 @@ #include "kdtree.h" #include "hair.h" +/* spring constant */ + +#define K_ANC 4.0 +#define DAMPING 1.5 + struct Triangle { Vec3 v[3]; Vec3 n[3]; @@ -122,7 +127,7 @@ bool Hair::init(const Mesh *m, int max_num_spawns, float thresh) for(size_t i=0; ixform = xform; } + +void Hair::update(float dt) +{ + for(size_t i = 0; i < hair.size(); i++) { + /* in local space */ + Vec3 hair_end = hair[i].spawn_pt + hair[i].spawn_dir * hair_length; + Vec3 anchor = xform * hair_end; + + Vec3 force = (anchor - hair[i].pos) * K_ANC; + + Vec3 accel = force; /* mass 1 */ + hair[i].velocity += ((-hair[i].velocity * DAMPING) + accel) * dt; + hair[i].pos += hair[i].velocity * dt; + + dbg_force = force; + } +}