Simulating cloth with gravity and wind
CS-116B: Graphics Algorithms
Instructor: Rob Bruce
Spring 2016

SLIDE 1: Data structure

Need to define some fundamental data structures:

typedef struct vec3
{
  float x;
  float y;
  float z;
} vec3;

SLIDE 2: Data structure

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;

SLIDE 3: Data structure

typedef struct constraint_node
{
  particle_node *p1;
  particle_node *p2;
  float rest_distance;
  struct constraint_node *next;
} constraint_node;

SLIDE 4:Computing triangle normal

  • Wind forces act on planes of the cloth
  • A plane is formed from three particles in a triangular pattern.
  • The normal of the plane is then used to compute how much wind forces act on the cloth at the particular plane.
  • The wind force is a vector. It has values in: X direction, Y direction, and Z direction
  • Gravity is a force too but it has only has values in Y direction. (Y is down).

SLIDE 5:Computing triangle normal

Our cloth is comprised of an array of particles:

Illustration of particles constrained to adjacent particles via imaginary springs in a 2-dimensional matrix. This is referred to as a mass spring model.

SLIDE 6:Computing triangle normal

Choose three particles:

Illustration of three particles selected in a 2-dimensional particle matrix.

SLIDE 7:Computing triangle normal

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)

Three particles selected form a plane.

SLIDE 8:Computing triangle normal

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);
}

SLIDE 9:Compute wind force

  • The wind force is a force vector.
  • To compute how much wind force moves the three particles forming a plane:
    Compute the dot product between the wind force (a vector) and the normalized cross product of the three particles (a vector).
  • Apply the dot product (computed above) as a force to each of the three particles (P1, P2, P3) that make up the plane. This will affect how each of the three particles is then displaced by the wind force.

SLIDE 10:Recommended review from course readings

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).