I feel like I have the symptoms of stockholm syndrome. OpenGl has taken over my life. All I think about is OpenGl. OpenGl is me, and I am OpenGl.
Anyways, if you didn't notice, I decided to use OpenGl again for this project. Thankfully it wasn't as evil as it was last assignment, however I still had multiple obnoxious hiccups along the way.
I started the assignment with the code for my particle system, and based the ClothParticle and ClothSystem classes around the Particle, and ParticleSystem classes.
I feel like I've been texturing quads ever since I was born. Texturing a simple cloth was by far the easiest task for the whole project.
Originally, I was planning on implementing one of the crazy accurate integrators, like RK4, or some implicit one. However, I never really had a problem with exploding simulations. So to me, a higher order integrater would just slow down the simulation. However, I still had to be careful to use a reasonable time step.
Example of what happened when I used a high dt.
Whenever a particle is within a sphere, it's velocity is reflected upon the surface of the sphere, and is decreased by some bounce constant. This is the same technique done for self collision. No spacial data structure was used, since the simulation was able to consistently run at 30fps, even with self collisions on a 30x30 cloth. (No sphere was rendered here)
The effect of Self Collisions can be seen in one of the videos provided.
Even though it was not mentioned in the requirements, turning an obj file into a cloth was something I really wanted to do. The main issue with loading a cloth from a .obj file that I ran into was that many model files are stored as triangular meshed, and don't have a uniform structure like a square cloth. So after adding in all my springs, I noticed the cloth was extremely flimsy. With the square cloth, you can decrease flimsyness by adding bending springs between every other mass. This is not so trivial for a cloth from a model. I ended up finding a solution online, that involves going through every pair of adjacent triangles, and adding a spring between the two vertices they don't share. One disadvantage to this method, is that it almost adds too many bending springs. It was difficult to deform the cloth with bending springs too much beyond its original shape, due to how many constraints there were.
To make sure the cloth stayed within a reasonable distance of the model, I locked all the top masses, and added a couple small spheres to prevent the bottom of the dress from drifting too far away.
I did not implement a drag force. Instead, I simply added a force proportional to the dot product of the wind direction, and the normal of the mass affected by it. This means masses parallel to the wind will be mostly unaffected by it.
External References and Resources: