Physics based Animation--Cloth
2019-12-13
Cloth simulation
This project is to implemente physics based animation, cloth-like object interactive with other objects.
Ball interacts with the mesh.
- Implemented RK4 to solve physics result per frame.
- Generate the grid mesh. Grid mesh is generated by code, that will add more information to each vertex: the closest 8 vertexes, the max distance of each vertexes. This special data structure will used to resolve the spring force inside of the mesh.
- Resolve collision. I defined an struct ‘Point’ to represent all objects that will do collision detection. Each Point contains all the information that will be used to do collision detection and RK4: force, mass, velocity, moment, radius and so on. The grid will have n*n points. I created a sphere in the scene as the model to interact with mesh, the radius and position of the sphere can be changed. I used friction = -unit(V) * dot(V,V) * k, it likes air friction.
For each frame, I do the collision resolve firstly, then calculate the spring force onto a vertex. Next, add friction, finally do RK4 to update position, rotation, velocity and all the physics information of the vertexes.