Friday, 6 March 2009

Verlet Integration and the Start of Hair Physics

I finally have a good start on the physics for the hair the Verlet integration was fairly simple to integrate into the application. The first force I applied to it, which is the only force that'll be almost constant, was gravity and the result was infinitely falling hair which was amusing. There were some odd issues though to do with variable time stepping. I narrowed it down to the time in the equation for drag/air resistance:

m_vecForceAccumulator[iMember] -=
m_fDrag * (vPosition - m_vecOldPositions[iMember]) / APPROX_DELTA_TIME;

and found that as has been previously noted that fixed time stepping prevents the problem occurring in the first place. There was another serious problem to note with the fixed time stepping too and this was due to the need to recalculate normals and re-Map the vertex buffer to update all the vertex information, in short the frame rate dropped from approx 2000fps to 50 fps. Locking APPROX_DELTA_TIME at 10 milliseconds (0.01 seconds) and only running the physics when the APPROX_DELTA_TIME has passed and only doing the normals and vertex buffer work if physics has been recalculated in the current loop seems to have solved some problems.

Besides adding the Verlet Integration and decreasing the amount of simulated hair strands (a.k.a. the Keyhairs that will do the work for the rest of the hair) I also added in the Mass Spring Model mainly because infinitely falling objects aren't of much use to anyone. This is a simple system based on the each strips starting position and it suspends the hairs from the starting position using springs rather than letting them fall. Also important is that the elasticity of the spring decreases the further away it is from the "root" of the hair.

No Gravity...
With Gravity

No comments: