Need to define some fundamental data structures:
typedef struct vec3
{
float x;
float y;
float z;
} vec3;
typedef struct particle_node
{
int index_x;
int index_y;
int movable;
float mass;
vec3 pos;
vec3 old_pos;
vec3 acceleration;
vec3 accumulated_normal;
struct particle_node *next;
} particle_node;
typedef struct constraint_node
{
particle_node *p1;
particle_node *p2;
float rest_distance;
struct constraint_node *next;
} constraint_node;
Our cloth is comprised of an array of particles:
Choose three particles:
Compute the normal vector of the triangle defined by the position of the particles P1, P2, and P3:
Vector V1 = (P2 - P1)x + (P2 - P1)y + (P2 - P1)z
Vector V2 = (P3 - P1)x + (P3 - P1)y + (P3 - P1)z
cross product of V1 and V2 = V1 × V2
Normalized V1 × V2 = (V1 × V2) / (magnitude of V1 × V2)
vec3 compute_triangle_normal (particle_node *p1, particle_node *p2, particle_node *p3)
{
vec3 v1, v2;
v1.x = p2->pos.x - p1->pos.x;
v1.y = p2->pos.y - p1->pos.y;
v1.z = p2->pos.z - p1->pos.z;
v2.x = p3->pos.x - p1->pos.x;
v2.y = p3->pos.y - p1->pos.y;
v2.z = p3->pos.z - p1->pos.z;
return compute_cross_product (v1, v2);
}
Advanced Character Physics by Thomas Jakobsen. This article is one of your readings. In it, there are code samples and notes on how to implement a cloth simulation. Review pages 2 through 9 (vertlet integration).
Spring 2016, CS-116B:
Lectures:
Assignments: